cdriveraus / ctsemOMX

Original functionality of ctsem, based around OpenMx / structrual equation modelling.
1 stars 0 forks source link

Stumped Re: warning #1

Open dberry77 opened 2 years ago

dberry77 commented 2 years ago

Dear Dr. Driver. Thanks for both your didactic work on CTSEM, as well as this package. I've tried getting the following model to fit ~1000 different ways and, for the life of me I can't figure out why its throwing this error. Was hoping that it was something obvious that I'm missing... any thoughts would be really appreciated.

If I'm using a wide file (created via your long-to-wide function), I have 60 columns (that look just like the example in Driver et al. (2017) JSS). It reflects 2 time-varying manifest variables (t = 20), and then the 20 time-interval variables (time is balanced across individuals). There are NAs, but I’ve tried it w/out. Doesn’t fix anything.

The code is as follows:

the model

number of latents

F <- 2

number of manifests

I <- F

drift matrix

A <- matrix( c("a_C","a_C}M","a_M}C","a_M"), nrow=F, ncol=F )

diffusion covariance matrix

Q <- matrix( c("var_C","cov_C_M",0,"var_M"), nrow=F, ncol=F )

continuous-time intercepts

b <- matrix( c("b_C","b_M"), nrow=F, ncol=1 )

Random Person means

Sigmab.lr <- matrix( c("varblr_C","covblr_C_M",0,"varblr_M"), nrow=F, ncol=F )

set all intercepts of manifest variables to 0

manifestmeans <- matrix( 0, nrow=I, ncol=1 )

set measurement error covariance matrix to 0

manifestvar <- matrix( 0, nrow=I, ncol=I )

loading matrix: each item loads on one latent variable

Lambda <- diag( I )

set up model

m <- ctModel( n.latent = F, latentNames = c("C_Pos","M_Pos"), # set names of latent variables n.manifest = I, manifestNames = c("cpos_wpz","mpos_wpz"), # names of manifest variables

as in data set

          DRIFT = A,
          DIFFUSION = Q,
          CINT = b,
          TRAITVAR = Sigmab.lr,           
          LAMBDA = Lambda,
          MANIFESTMEANS = manifestmeans,
          MANIFESTVAR = manifestvar,
          Tpoints = 20, # number of measurement occasions as in data set
          type = "omx" ) # for frequentist estimation

Fit the model

set.seed( 1234 ) r <- ctFit( dat = wideexample2, ctmodelobj = m, dataform = "wide", stationary = "all" ) # stationary assumption

smr <- summary( r ) print( smr$ctparameters )

The error is: “Error in ctFit(dat = wide_pos, ctmodelobj = m, dataform = "wide", stationary = "all") : Number of columns in data (60) do not match model (59)”

I’ve had the same issue if I opt for a long datafile. “Error in ctFit(dat = play_cpmp, ctmodelobj = m, dataform = "long", stationary = "all") : Tpoints in ctmodelobj = 20, not equal to 1, the maximum number of rows of any subject in dat.

I'm sure I'm just doing something dumb... but I'm at a bit of a loss.

Thanks again for any thoughts. Best regards, -dan berry

cdriveraus commented 2 years ago

Hi Dan, very quick suggestion before I take the time going through script etc -- try setting type='stanct' when calling ctModel, then fit using ctStanFit, and a long data structure. That should hopefully give better diagnostics as to what is wrong, but don't agonize over it, if doesn't work tell me I'll look a little more when I've more time!

dberry77 commented 2 years ago

Thanks for your super quick response, Charles! I appreciate it.

After some tweaks, I got it running w/ ctstanfit. It worked w/ a short, toy dataset. I added some more variables (5 total), and it's been running for ~ 12 hours. I'm guessing that this is just this is a normal part of the Bayesian estimation (i.e., it's not far off from the time it takes to estimate comparably complex models using WinBugs or Mplus). But please tell me if this seems inordinate. Need to figure out some parallel processing if this is going to be a tractable approach, I'm afraid. Yowzah. :)

In any case, thank you again. It's a fantastic contribution... I just need a faster computer.

Best. -dan

-- Daniel Berry Associate Professor Institute of Child Development University of Minnesota 51 E River Road Minneapolis, MN 55455 Pronouns: he/him/his

On Wed, Mar 23, 2022 at 2:04 AM Charles Driver @.***> wrote:

Hi Dan, very quick suggestion before I take the time going through script etc -- try setting type='stanct' when calling ctModel, then fit using ctStanFit, and a long data structure. That should hopefully give better diagnostics as to what is wrong, but don't agonize over it, if doesn't work tell me I'll look a little more when I've more time!

— Reply to this email directly, view it on GitHub https://github.com/cdriveraus/ctsemOMX/issues/1#issuecomment-1075994816, or unsubscribe https://github.com/notifications/unsubscribe-auth/AU3DRLBJ6Z6FC4KQK2FPPYTVBK663ANCNFSM5RMHWDHA . You are receiving this because you authored the thread.Message ID: @.***>

-- Daniel Berry Associate Professor Institute of Child Development University of Minnesota 51 E River Road Minneapolis, MN 55455 Pronouns: he/him/his

cdriveraus commented 2 years ago

The default is just frequentist, with more flexibility than the old ctsemOmx. Should only take a few minutes i suspect a data structure problem... Can you set the observed variables to NA and post the full code maybe?