Adding a covariate

3 replies [Last post]
ebejer's picture
Offline
Joined: 03/18/2010

Hi,

I have been learning how to structure the analyses and scripts for examining twin data and I am having some trouble with 'adding a covariate'. When I run the following code.(which I didn't write)...............

mxModel("Sibs",
mxMatrix( type="Lower", nrow=ntv, ncol=ntv, free=TRUE, values=1, name="Chol" ),
mxAlgebra( expression=Chol %*% t(Chol), name="expCov" ),

#regressing out covariate
mxMatrix( type="Full", nrow=1, ncol=ntv, free=TRUE, values=0, labels="intercept", name="grandMean" ),
# adding a beta x covariate to full mean
mxMatrix(type="Full", nrow=cov, ncol=nv, free=TRUE, labels="betaSes", name="regBetas"),

........it will not run past the last line, and I receive the following error message..........

dding a beta x covariate to full mean
> mxMatrix(type="Full", nrow=cov, ncol=nv, free=TRUE, labels="betaSes", name="regBetas")
Error in matrix(values, nrow, ncol, byrow = byrow) :
non-numeric matrix extent
In addition: Warning messages:
1: In is.na(nrow) :
is.na() applied to non-(list or vector) of type 'closure'
2: In is.na(nrow) :
is.na() applied to non-(list or vector) of type 'closure'
3: In is.na(nrow) :
is.na() applied to non-(list or vector) of type 'closure'

Help or suggestions to improve the 'functionality' of the code will be greatly appreciated.

Best wishes
jane

ebejer's picture
Offline
Joined: 03/18/2010
Thankyou. I had added some

Thankyou. I had added some comments in and there were a couple of typos. Comments were helpful and greatly appreciated.

regards
jane

tbates's picture
Offline
Joined: 07/31/2009
mxMatrix(type="Full",

mxMatrix(type="Full", nrow=cov, ncol=nv, free=TRUE, labels="betaSes", name="regBetas")

The parameter nrow takes a number, but instead it is being passed "cov" which by default is the function for computing covariance.

Likely it is a typo for "nCov"or some similar variable name in which the script writer has stored the number of covariates.

mspiegel's picture
Offline
Joined: 07/31/2009
The variable 'cov' is bound

The variable 'cov' is bound to the built-in function that yields the covariance of a vector, matrix, or data.frame. So either (a) the original writer of the script bound some numeric value to the variable 'cov'. Or (b) passing the value 'cov' to the function parameter 'nrow' is a typo. I'll fix the error messages for this particular scenario.