I am relatively new to R. I have been using it to estimate structural equation models using OpenMx.

Now I am trying to fit a latent curve model using a script that I have used many times, but now I get an error which I cannot find a solution to!

I don't know whether I should paste the entire script, but I guess in this way it may be easier to understand the error...

THE ERROR IS AT THE BOTTOM OF THE SCRIPT

>

> ############### MODEL

>

> title = "Second order Growth curve model"

>

> obs = mxData(observed = extcov2, type = 'cov', means = extmeans2, numObs = 514)

>

>

> matrixL = mxMatrix(

+ type = 'Full',

+ nrow = 9,

+ ncol = 3,

+ free = c( TRUE,FALSE,FALSE,

+ TRUE,FALSE,FALSE,

+ TRUE,FALSE,FALSE,

+ FALSE,TRUE,FALSE,

+ FALSE,TRUE,FALSE,

+ FALSE,TRUE,FALSE,

+ FALSE,FALSE,TRUE,

+ FALSE,FALSE,TRUE,

+ FALSE,FALSE,TRUE),

+ values = c( 1,0,0,

+ 1,0,0,

+ 1,0,0,

+ 0,1,0,

+ 0,1,0,

+ 0,1,0,

+ 0,0,1,

+ 0,0,1,

+ 0,0,1),

+ labels = c( "L11t1",NA,NA, # Labels all same ACROSS TIME POINTS

+ "L21t1",NA,NA,

+ "L31t1",NA,NA,

+ NA,"L11t1",NA,

+ NA,"L21t1",NA,

+ NA,"L31t1",NA,

+ NA,NA,"L11t1",

+ NA,NA,"L21t1",

+ NA,NA,"L31t1"),

+ byrow = TRUE,

+ name = 'L')

>

> # No matrixF --> it is a function of the second order factors

>

> matrixQ = mxMatrix( # Includes covariances bw residuals of indicators across time

+ type = 'Symm',

+ nrow = 9,

+ ncol = 9,

+ free =

+ c(

+ TRUE,

+ FALSE,TRUE,

+ FALSE,FALSE,TRUE,

+

+ TRUE,FALSE,FALSE,TRUE,

+ FALSE,TRUE,FALSE,FALSE,TRUE,

+ FALSE,FALSE,TRUE,FALSE,FALSE,TRUE,

+

+ TRUE,FALSE,FALSE,TRUE,FALSE,FALSE,TRUE,

+ FALSE,TRUE,FALSE,FALSE,TRUE,FALSE,FALSE,TRUE,

+ FALSE,FALSE,TRUE,FALSE,FALSE,TRUE,FALSE,FALSE,TRUE),

+

+ values =

+

+ c(1,

+ 0,1,

+ 0,0,1,

+

+ .5,0,0,1,

+ 0,.5,0,0,1,

+ 0,0,.5,0,0,1,

+

+ .5,0,0,.5,0,0,1,

+ 0,.5,0,0,.5,0,0,1,

+ 0,0,.5,0,0,.5,0,0,1),

+

+ byrow = TRUE,

+ name = 'Q')

>

> matrixT = mxMatrix(

+

+ type = 'Full',

+ nrow = 9,

+ ncol = 1,

+ free = c(TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE),

+ values = c(10,10,10,10,10,10,10,10,10),

+ labels = c("t11","t22","t23",

+ "t11","t12","t33",

+ "t11","t12","t13"), # t1 - time 1, t2 - time 2, t3 - time 3

+ byrow = TRUE,

+ name = 'T')

>

> # No MatrixK --> it is a function of second order factors

>

>

> ## Second order intercept and slope structure

>

> matrixL2 = mxMatrix(# Fixed loadings intercept and slope

+ type = 'Full',

+ nrow = 3,

+ ncol = 2,

+ free = c(FALSE,FALSE,

+ FALSE,FALSE,

+ FALSE,FALSE),

+

+ values = c( 1,0,

+ 1,1,

+ 1,2),

+ byrow = TRUE,

+ name = 'L2')

>

>

> matrixF2 = mxMatrix(# Variances and covariances intercept and slope

+ type = 'Symm',

+ nrow = 2,

+ ncol = 2,

+ free = c(TRUE,

+ TRUE,TRUE),

+

+ values = c(1,

+ .5,1),

+

+ byrow = TRUE,

+ name = 'F2')

>

> matrixQ2 = mxMatrix( # Variance of time points (no covariance-everything is explained by the growth model?)

+ type = 'Symm',

+ nrow = 3,

+ ncol = 3,

+ free = c(

+ TRUE,

+ FALSE,TRUE,

+ FALSE,FALSE,TRUE),

+

+ values = c(1,

+ 0,1,

+ 0,0,1),

+ byrow = TRUE,

+ name = 'Q2')

>

>

> matrixT2 = mxMatrix(# Mean intercepts of Time points FIXED in order to estimate K2

+ type = 'Full',

+ nrow = 3,

+ ncol = 1,

+ free = c(FALSE,FALSE,FALSE),

+

+ values = c(1,1,1),

+

+ byrow = TRUE,

+ name = 'T2')

>

>

> matrixK2 = mxMatrix(# Mean of intercept and slope

+ type = 'Full',

+ nrow = 2,

+ ncol = 1,

+ free = c(TRUE,TRUE),

+ values = c(0,0),

+ byrow = TRUE,

+ name = 'K2')

>

>

> algebraF = mxAlgebra(expression = L2 %*% F2 %*% t(L2) + Q2, name = 'F')

> algebraK = mxAlgebra(expression = T2 + L2%*%K2, name = 'K')

> algebraS = mxAlgebra(expression = L %*% F %*% t(L) + Q, name = 'S', dimnames = labels2)

> algebraM = mxAlgebra(expression = t(T + L%*%K), name = 'M')

>

>

> growthmodel = mxModel(title,obs,matrixL,matrixQ,matrixT,matrixL2,matrixF2,matrixQ2,matrixT2,matrixK2,algebraF,algebraK,algebraS,algebraM,exp)

**Error in paste("'", x, "'", sep = "") :**

cannot coerce type 'builtin' to vector of type 'character'

cannot coerce type 'builtin' to vector of type 'character'

As I said, I have used this type of script with other data and different models and it has always worked, so I cannot understand why it's not working now.

Any suggestions and help are most welcome!! :yup: