data(memory_exp)
memory_exp$x <- as.numeric(memory_exp$x)-1 # manually creating dummy codes
endVar <- c('x', 'repetition', 'imagery', 'recall')
manifests <- c('x', 'repetition', 'imagery', 'recall')
full_model <- mxModel(
"memory_example",
type = "RAM",
manifestVars = manifests,
mxPath(
from = "x",
to = endVar,
arrows = 1,
free = TRUE,
values = .2,
labels = c("a1", "a2", "cp")
),
mxPath(
from = 'repetition',
to = 'recall',
arrows = 1,
free = TRUE,
values = .2,
labels = 'b1'
),
mxPath(
from = 'imagery',
to = 'recall',
arrows = 1,
free = TRUE,
values = .2,
labels = "b2"
),
mxPath(
from = manifests,
arrows = 2,
free = TRUE,
values = .8
),
mxPath(
from = "one",
to = endVar,
arrows = 1,
free = TRUE,
values = .1
),
mxAlgebra(a1 * b1, name = "ind1"),
mxAlgebra(a2 * b2, name = "ind2"),
mxCI("ind1", type = "both"),
mxCI("ind2", type = "both"),
mxData(observed = memory_exp, type = "raw")
)
## Reduced Model for indirect effect: a1*b1
null_model1 <- mxModel(
model= full_model,
name = "Null Model 1",
mxConstraint(ind1 == 0, name = "ind1_eq0_constr")
)
full_model <- mxTryHard(full_model, checkHess=FALSE, silent = TRUE )
null_model1 <- mxTryHard(null_model1, checkHess=FALSE, silent = TRUE )
mbco(null_model1,full_model)
Run the code above in your browser using DataLab