-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
119 lines (95 loc) · 4.64 KB
/
README.Rmd
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
---
output: github_document
bibliography: inst/REFERENCES.bib
---
# bayesianmasem
```{r include=FALSE}
devtools::load_all()
```
[![Project Status: Active The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
![GitHub](https://img.shields.io/github/license/jamesuanhoro/bayesianmasem)
[![Codecov test coverage](https://codecov.io/gh/jamesuanhoro/bayesianmasem/branch/main/graph/badge.svg)](https://app.codecov.io/gh/jamesuanhoro/bayesianmasem?branch=main)
[![minimal R version](https://img.shields.io/badge/R%3E%3D-`r .minimum_r_version()`-6666ff.svg)](https://cran.r-project.org/)
![GitHub R package version](https://img.shields.io/github/r-package/v/jamesuanhoro/bayesianmasem)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/bayesianmasem)](https://cran.r-project.org/package=bayesianmasem)
![GitHub last commit](https://img.shields.io/github/last-commit/jamesuanhoro/bayesianmasem)
[![R-CMD-check](https://github.com/jamesuanhoro/bayesianmasem/actions/workflows/check-standard.yaml/badge.svg)](https://github.com/jamesuanhoro/bayesianmasem/actions/workflows/check-standard.yaml)
[![bayesianmasem status badge](https://jamesuanhoro.r-universe.dev/badges/bayesianmasem)](https://jamesuanhoro.r-universe.dev)
#### Table of Contents
- [Package overview](#package-overview)
- [Features](#features)
- [Installation](#installation)
- [An example](#an-example)
- [Citations](#citations)
## Package overview
This is a package for Bayesian meta-analytic structural equation models
[MASEM, @cheung_two-stage_2009],
specifically meta-analysis of confirmatory factor models.
The package fits fixed-, random- and dependent-samples MASEMs.
## Features
Features of `bayesianmasem` include:
- Uses lavaan-style syntax for model specification
- Fits fixed-effects, random-effects and **dependent-samples** MASEM
- Allows fixing loadings to known values or constraining loadings equal
- Estimates minor factor influences [@uanhoro_modeling_2023],
i.e. full residual correlation
matrix reflecting misspecification in the true shared correlation matrix
- Ability to relax simple-structure, i.e. allow for estimation of all
cross-loadings using shrinkage-to-zero priors leading to more accurate
estimates of interfactor correlations.
- Built atop [Stan](https://mc-stan.org/) (an efficient Bayesian sampler).
## Installation
`bayesianmasem` is hosted on GitHub, so we need the `remotes` package to
install it. We also need to install the `cmdstanr` package and CmdStan
in order to use Stan.
Instructions:
``` r
install.packages("remotes") # install remotes
# next install cmdstanr and CmdStan:
install.packages(
"cmdstanr",
repos = c("https://mc-stan.org/r-packages/", getOption("repos"))
)
cmdstanr::check_cmdstan_toolchain(fix = TRUE)
cmdstanr::install_cmdstan()
# Then finally bayesianmasem:
remotes::install_github("jamesuanhoro/bayesianmasem")
```
## An example
We use the example in the Norton data [@norton_hospital_2013].
Let's fit the Zigmond-Snaith anxiety-depression model to the HADS assuming
a positive factor on select items.
```r
model_syntax <- "
anxiety =~ x1 + x3 + x5 + x7 + x9 + x11 + x13
depression =~ x2 + x4 + x6 + x8 + x10 + x12 + x14
pos =~ a * x2 + a * x4 + a * x6 + a * x7 + a * x12 + a * x14
pos =~ 0 * x1 + 0 * x3 + 0 * x5 + 0 * x8 + 0 * x9 + 0 * x10 + 0 * x11 + 0 * x13
pos ~~ 0 * anxiety + 0 * depression
"
```
There are 14 items. The model assumes odd-numbered items load onto anxiety,
even-numbered item load on depression. Items 2, 4, 6, 7, 12, and 14 load on
a positive-wording factor, i.e. a method effect. We assume the loadings on this
positive factor to be equal, and this factor assumed uncorrelated to the
substantive factors. We also specify that other items have a fixed loading of 0
on this positive factor -- this helps when we relax simple structure, we want
to ensure the positive method factor has 0 loading on other items.
We can fit a random-effects model to the input correlation matrices and
provide sample size information.
The `Norton13` data come from the
[metaSEM package](https://cran.r-project.org/package=metaSEM) [@Cheung-metaSEM]:
```r
fit_ad <- bmasem(
model_syntax,
sample_cov = Norton13$data, sample_nobs = Norton13$n,
method = "normal", simple_struc = FALSE
)
```
Setting `method = "normal"` implies the true correlation matrix underlying
the data differs from the structured correlation matrix due to minor factors.
Setting `simple_struc = FALSE` allows for all cross-loadings to be estimated
using priors that attempt to shrink the cross-loadings to 0.
Parameters for all functions including `bmasem()` are documented:
`?bmasem`.
## Citations