cfd.semipar.mean {cfdecomp} | R Documentation |

## Mean Decomposition: semiparametric version

### Description

Decompose the mean difference in outcome Y between groups. In this semiparametric version, we do not assume a parametric model for the mediator: instead, we sample from the distribution of the mediator in the reference group; this can be done within strata of one or more third variables.

### Usage

```
cfd.semipar.mean(
formula,
mediator,
group,
strata = NA,
nbin = 5,
data,
family = "binomial",
bs.size = 1000,
mc.size = 50,
alpha = 0.05,
print.iteration = FALSE
)
```

### Arguments

`formula` |
the |

`mediator` |
the column name of the mediator M. |

`group` |
column name of the variable containing the group identifier. |

`strata` |
the name of a variable containing the strata of a third variable (or set of variables) within which we equalize mediator values. Ideally this is a factor variable. |

`nbin` |
if a numeric (i.e. non-factor or character) strata variable is defined, how many bins should be made from it within which we equalize the mediator distribution? |

`data` |
a data frame containing the variables in the model. |

`family` |
a description of the error distribution to be used in the model, see |

`bs.size` |
the number of bootstrap iterations to be performed. |

`mc.size` |
the number of Monte Carlo iterations to be performed (more = more MC error reduction). |

`alpha` |
the alpha level used to construct confidence intervals (0.05 = 95 percent confidence interval). |

`print.iteration` |
print the bootstrap iteration |

### Value

`out_nc`

returns the mean level of the outcome under the natural course, which is a value that should be close to the empirically observed value of the outcome for each group. `out_nc_quantile`

provides the `alpha/2`

and `1-alpha/2`

bootstrap quantiles for this mean (AKA bootstrap percentile confidence intervals).Similarly, `out_cf`

, `out_cf_quantile`

,provide the corresponding values for the counterfactual scenario where the mediators of the groups are equalized. `mediation`

returns the proportion mediated by setting the intervened on mediator to be equal in level to the reference group and `mediation_quantile`

returns the 1-alpha confidence interval.

### Examples

```
set.seed(100)
# the decomposition functions in our package are computationally intensive
# to make the example run quick, I perform it on a subsample (n=250) of the data:
cfd.example.sample <- cfd.example.data[sample(250),]
mean.semipar.results.1 <- cfd.semipar.mean(formula='out.gauss ~ SES + med.gauss + med.binom + age',
mediator='med.gauss',
group='SES',
strata='age',
nbin=5,
data=cfd.example.sample,
family='gaussian',
bs.size=50,
mc.size=10,
alpha=0.05)
# also note that normally we would recommend an bs.size of 250+
# and an mc.size of 50+
# see README.md for a more detailed description of the functions in this package.
```

*cfdecomp*version 0.4.0 Index]