arrrrRgh
arrrrRgh

Reputation: 307

Running linear growth curve models using MplusAutomation package in R

I am trying to replicate Bolger and Laurenceau's (2013) linear growth curve models (Ch. 4) using the MplusAutomation package in R.

Data are available here: http://www.intensivelongitudinal.com/ch4/ch4index.html

After reading in the data and storing it as df, I am running this syntax:

test <- mplusObject(
  TITLE = "test model;",
  VARIABLE = "NAMES ARE id time time01
  intimacy treatment;
          WITHIN =  time01;
          BETWEEN = treatment;
          CLUSTER = id;",
  ANALYSIS = "TYPE = twolevel random;
  ESTIMATOR=ml;",
  MODEL = "
  %WITHIN% 
    slope | intimacy on time01;         
  %BETWEEN%
    intimacy slope on treatment;
  intimacy with slope;",
  OUTPUT = "cinterval;",
  rdata = df)

res <- mplusModeler(test, modelout = "model1.inp", run = TRUE)
res 

But get the following error:

Duplicate variable on NAMES list: ID

Any assistance integrating these two platforms would be most welcome.

Upvotes: 0

Views: 119

Answers (1)

arrrrRgh
arrrrRgh

Reputation: 307

Seems the trick is specifying variable names as an argument to mplusObject rather than within the Mplus code:

res <- mplusModeler(mplusObject(
  VARIABLE = "
  WITHIN =  time01;
  BETWEEN = treatment;
  CLUSTER = id;",
  ANALYSIS = "
  Type = twolevel random;
  ESTIMATOR = ml;",
  MODEL = "
  %WITHIN% 
  slope | intimacy on time01;
  %BETWEEN%
  intimacy slope on treatment;
  intimacy with slope;",
  rdata = df[,c("id","time01","intimacy","treatment")],
  usevariables = c("id","time01","intimacy","treatment")),"df.dat", run = 1L)
res$results$errors #no errors now
cat( readLines( "df.out" ) , sep = "\n" ) #full output
screenreg(res, single.row=TRUE) #regression output only

Upvotes: 1

Related Questions