tbates / umx

Making Structural Equation Modeling (SEM) in R quick & powerful
https://tbates.github.io/
44 stars 17 forks source link

allow user to make twin model from diagram for just 1-individual #118

Closed tbates closed 4 years ago

tbates commented 4 years ago

plot.MxModelTwinMaker

tbates commented 4 years ago

This is really nice for

  1. teaching
  2. prototyping new twin models
  3. For lots of models it's a great solution with full support from plot and std etc. via RAM. e.g. umxDoCp

Clean up the twinData

  1. Add a separator to the twin variable names (with sep = "_T")
  2. Scale the data so it's easier for the optimizer.
data(twinData)
tmp = umx_make_twin_data_nice(data=twinData, sep="", zygosity="zygosity", numbering=1:2)
tmp = umx_scale_wide_twin_data(varsToScale= c("wt", "ht"), sep= "_T", data= tmp)
mzData = subset(tmp, zygosity %in%  c("MZFF", "MZMM"))
dzData = subset(tmp, zygosity %in%  c("DZFF", "DZMM"))

Now make an ACE model, just describing one individual and the link function for A, C, and E, and the MZ and DZ group:

# Define paths: You only need the paths for one person:
paths = c(
umxPath(v1m0 = c("a1", 'c1', "e1")),
umxPath(means = c("wt")),
umxPath(c("a1", 'c1', "e1"), to = "wt", values=.2)
)
m1 = umxTwinMaker("test", paths, mzData = mzData, dzData= dzData)
plot(m1, std= TRUE, means= FALSE)