Description Usage Arguments Value Examples

Decompose the mean difference in outcome Y between groups.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |

`formula.y` |
the |

`formula.m` |
the |

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

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

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

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

`family.m` |
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). |

`cluster.sample` |
set to TRUE if data are clustered in the long format (i.e. multiple rows per individual or other cluster). |

`cluster.name` |
the name (as a character) of the column containing the cluster identifiers. |

`sample.resid` |
if the |

`print.iteration` |
print the bootstrap iteration |

`out_nc_m`

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

provides the `alpha/2`

and `1-alpha/2`

bootstrap quantiles for this mean (AKA bootstrap percentile confidence intervals). `out_nc_y`

and `out_nc_quantile_y`

provide the corresponding values, but then for the outcome variable Y. Similarly, `out_cf_m`

, `out_cf_quantile_m`

,`out_cf_y`

, and `out_cf_quantile_y`

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. `mc_conv_info_m`

and `mc_conv_info_y`

provide information that can help determine the number of Monte Carlo and Bootstrap iterations needed to achieve stability. See the `Examples`

for more information.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | ```
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.results.1 <- cfd.mean(formula.y='out.gauss ~ SES + med.gauss + med.binom + age',
formula.m='med.gauss ~ SES + age',
mediator='med.gauss',
group='SES',
data=cfd.example.sample,
family.y='gaussian',
family.m='gaussian',
bs.size=50,
mc.size=10,
alpha=0.05,
cluster.sample=TRUE,
cluster.name='id')
# also note that normally we would recommend a bs.size of 250+
# and an mc.size of 50+
# let's interpret the output of this function:
mean(mean.results.1$out_nc_y[,2] - mean.results.1$out_nc_y[,1])
# and after giving the gaussian mediator of SES group 2 the distribution of the one in group 1
# the difference becomes:
mean(mean.results.1$out_cf_y[,2] - mean.results.1$out_nc_y[,1])
# so the % of the outcome Y that is due to differences between the two SES groups
# in the gaussian mediator is
mean(1-(mean.results.1$out_cf_y[,2] - mean.results.1$out_nc_y[,1]) /
(mean.results.1$out_nc_y[,2] - mean.results.1$out_nc_y[,1]))
# we can also get this number, and the one from the comparison of the other SES group
# with group 1, straight from the object
mean.results.1$mediation
# and we can get the 1-alpha CI for each:
mean.results.1$mediation_quantile
# see README.md for a more detailed description of the functions in this package.
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.