tbates / umx

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

Make possible to use umx sketch mode with umxTwinMaker #180

Open lf-araujo opened 2 years ago

lf-araujo commented 2 years ago

While modifying the function for DoC I found out umxTwinMaker, which is such a handy tool when you already have data.

But if you are exploring and don't have data to match a twin model that is complex enough so that it would be easier to generate the paths for one person and get the supermodel with TwinMaker, you have no luck:

mtwin <- umxTwinMaker(
  paths = paths, sep = "_T",
  t1_t2links = list("A1" = c(1, .5), "C1" = c(1, 1), "E1" = c(0, 0), "A3" = c(1, .5), "C3" = c(1, 1), "E3" = c(0, 0))
)

Errs with:

Error: In umxRAM, you must set 'data = '. If you're building a model with no data, use mxModel

My attempt:

I edited TwinMaker so it now reads:

    MZ = umxRAM("MZ", c(Twin1Paths, Twin2Paths), data = vars,
        autoRun = FALSE)
    DZ = umxRAM("DZ", c(Twin1Paths, Twin2Paths), data = vars,
        autoRun = FALSE)

so I can pass a list of observed (vars), and:

    model = umxSuperModel(name, MZ, DZ, autoRun = F)

And it runs as expected, but later on when I then try to generate data for the supermodel with:

mtwin <- mxGenerateData(model = mtwin, 1000, empirical = T, returnModel = T)

I get Error in eigen(Sigma, symmetric = TRUE) : 0 x 0 matrix, but I can't find where in the code the function loses track of the sigma matrix.

tbates commented 2 years ago

The problem is that for this to be useful, the user then needs to set all the parameter values. Easier said than done with a complex model. But still …easier if umxTwinMaker could at least press on when no data are provided and give the user a model they can take to the final stage for inputting to umxGenerate data.

I'll mull it over over the weekend.

Thanks for all your engagement and the excellent need-driven suggestions - they are lovely to receive!

T