Change code from Stata to R
Posted: Thu Feb 07, 2019 11:20 am
Dear all,
I have been using "runmlwin" on STATA but I changed to R, and I have some doubts about changing the code to R. I have been reading the forum and the R2MLwiN manual and I think I have been able to adapt it to R properly but I would kindly ask if you could confirm this code in R is correctly.
The model:
*Aim: individual weight growth trajectories with repeated measurements during childhood.
*Statistical method: linear spline model with 3 knot points.
*Model includes: two random levels: 1:) level2 - individual level random effect 2:) level 1- individual-specific occasion-level residuals. Also, I am modelling the complex level 1 variation adding a constant to it.
* I specified a diagonal matrix for the random effects variance-covariance matrix.
My code in stata would be:
runmlwin weight cons s1 s2 s3 s4, ///
level2 (id: cons s1 s2 s3 s4, reset(none) residuals(res_model,var) ) ///
level1 (occ: cons, reset(none) diag) ///
nopause maxiter (150) batch
My variables are: weight (repeated weight measures), cons (constant necessary to develop the model), s1-s4 are the spline variables [s1 (age between birth and 3 months), s2 (age between 3 and 12 months), s3 (age between 12 and 36 months), s4 (age between 36 and 60 month)]
My model in R would be:
# prepare the diagonal covariance matrix
smat <- matrix(, nrow=2, ncol=1)
smat[1, 1] <- 2 # Level of covariance matrix
smat[2, 1] <- 1 # Set matrix type to diagonal
# prepare formula
model1 <- weight ~ 1 + s1 + s2 + s3 + s4 + (1 + s1 + s2 + s3 + s4 | id) + (cons| occ)
# execute the model
run_model1 <- runMLwiN(Formula = model1, data = mydb, estoption = list(resi.store = TRUE, smat = smat))
I appreciate much your time. I am mainly worried about the diagonal covariance matrix.
Thank you.
All the best,
Jeroen de Bont.
I have been using "runmlwin" on STATA but I changed to R, and I have some doubts about changing the code to R. I have been reading the forum and the R2MLwiN manual and I think I have been able to adapt it to R properly but I would kindly ask if you could confirm this code in R is correctly.
The model:
*Aim: individual weight growth trajectories with repeated measurements during childhood.
*Statistical method: linear spline model with 3 knot points.
*Model includes: two random levels: 1:) level2 - individual level random effect 2:) level 1- individual-specific occasion-level residuals. Also, I am modelling the complex level 1 variation adding a constant to it.
* I specified a diagonal matrix for the random effects variance-covariance matrix.
My code in stata would be:
runmlwin weight cons s1 s2 s3 s4, ///
level2 (id: cons s1 s2 s3 s4, reset(none) residuals(res_model,var) ) ///
level1 (occ: cons, reset(none) diag) ///
nopause maxiter (150) batch
My variables are: weight (repeated weight measures), cons (constant necessary to develop the model), s1-s4 are the spline variables [s1 (age between birth and 3 months), s2 (age between 3 and 12 months), s3 (age between 12 and 36 months), s4 (age between 36 and 60 month)]
My model in R would be:
# prepare the diagonal covariance matrix
smat <- matrix(, nrow=2, ncol=1)
smat[1, 1] <- 2 # Level of covariance matrix
smat[2, 1] <- 1 # Set matrix type to diagonal
# prepare formula
model1 <- weight ~ 1 + s1 + s2 + s3 + s4 + (1 + s1 + s2 + s3 + s4 | id) + (cons| occ)
# execute the model
run_model1 <- runMLwiN(Formula = model1, data = mydb, estoption = list(resi.store = TRUE, smat = smat))
I appreciate much your time. I am mainly worried about the diagonal covariance matrix.
Thank you.
All the best,
Jeroen de Bont.