library(semtree)
library(OpenMx)
set.seed(23)
<- 1000
N <- 5
M <- rnorm(N, 10, sd = 4)
icept <- rnorm(N, 3, sd = 1.2)
slope <- sample(c(0,1),size=N,replace=TRUE)
p1 <- 0:4
loadings <- (slope+p1*5) %*% t(loadings)+matrix(rep(icept, each=M),byrow=TRUE,ncol=M)+rnorm(N*M, sd=.08)
x <- data.frame(x,p1)
growth.data names(growth.data) <- c(paste0("X",1:M),"P1")
<- names(growth.data)[1:5]
manifests <- mxModel("Linear Growth Curve Model Path Specification",
growthCurveModel type="RAM",
manifestVars=manifests,
latentVars=c("intercept","slope"),
mxData(growth.data, type="raw"),
# residual variances
mxPath(
from=manifests,
arrows=2,
free=TRUE,
values = c(.1, .1, .1, .1, .1),
labels=c("residual","residual","residual","residual","residual")
),# latent variances and covariance
mxPath(
from=c("intercept","slope"),
arrows=2,
connect="unique.pairs",
free=TRUE,
values=c(2, 0, 1),
labels=c("vari", "cov", "vars")
),# intercept loadings
mxPath(
from="intercept",
to=manifests,
arrows=1,
free=FALSE,
values=c(1, 1, 1, 1, 1)
),# slope loadings
mxPath(
from="slope",
to=manifests,
arrows=1,
free=FALSE,
values=c(0, 1, 2, 3, 4)
),# manifest means
mxPath(
from="one",
to=manifests,
arrows=1,
free=FALSE,
values=c(0, 0, 0, 0, 0)
),# latent means
mxPath(
from="one",
to=c("intercept", "slope"),
arrows=1,
free=TRUE,
values=c(1, 1),
labels=c("meani", "means")
)# close model )
<- semtree(model = growthCurveModel, data = growth.data)
tree #> <U+2716> Variable P1 is numeric but has only few unique values. Consider recoding as ordered factor.
#> <U+2714> Tree construction finished [took 2s].
plot(tree)