0

I am running multivariate mixed model in R by using nlme package. Suppose that x and y are responses variables for longitudinal data which assumed that the error within group is correlated. The residual error matrix is presented as: enter image description here

So my question is how to involve the correlation into lme function? I tried commands corr = corComSymm(from =~ 1 | x) or corr = corAR1(from =~ 1 | x) but did not work!

here en example:

# visiting time by months
time = rep(c(0,3,6,9),time = 4, 200)
# subjects 
subject = rep(1:50, each = 4)
# first  response variable "identity"
x = c(rep(0, 100), rep(1,100)) 
# second  response variable "identity"
y = c(rep(1, 100), rep(0,100))
# values of both reponses variables (x_1, x_2)
value = c(rnorm(100,20,1),rnorm(100,48,1))
# variables refer to reponses variables (x_1, x_2)
variable = factor(c(rep(0,150),rep(1,50)), label=c("X","Y"))

df = data.frame(subject , time, x,y,value, variable)

library(nlme)
# fit the model that each response variable has intercept and slope (time) for each random and fixed effects
# as well as fixed effects slopes for sex and lesion, and each response has different variance 
f=  lme(value ~ -1 + x + y + x:time + y:time , random = ~ -1 + (x + y) + time:( x + y)|subject , 
       weights = varIdent(form=~1| x),corr = corAR1(from = ~ 1|x), control=lmeControl(opt="optim"), data =df)
Error in corAR1(from = ~1 | x) : unused argument (from = ~1 | x)

Any suggestions?

alexwhitworth
  • 4,839
  • 5
  • 32
  • 59
R. Saeiti
  • 89
  • 3
  • 11
  • First, you've misspelled `form` as `from`. Second, the `form` argument expects a time covariate as `~ t` or as ~ t |g ` where `g` is the grouping variable (see the help page for `corAR1`. Because you have a random effect you have already defined `g` as subjects and so the time covariate must be a variable that varies within each subject. – aosmith Feb 08 '16 at 23:07
  • Thanks @aosmith! You are right, I spelled wrong. But I am trying to arrive at the correct syntax for the non-fixed part of the 'nlme' call given what I am trying to do. According to 'nlme' function in 'R' is not clear how to set correlation between two response variables. – R. Saeiti Feb 09 '16 at 12:35
  • Sorry @Alex. I believe that 'nlme' and 'lme4' both are used for mixed models, and they give almost similar results. This is the reason why I tag both. – R. Saeiti Feb 09 '16 at 12:40
  • @R.Saeiti Yes, they both **can be** used for mixed models. But they have different code bases and you are only using one of them. Please tag appropriately. – alexwhitworth Feb 09 '16 at 16:36

1 Answers1

0

I found this website (below) which helpful and useful, I posted here in case someone might has this problem in future. https://rpubs.com/bbolker/3336

R. Saeiti
  • 89
  • 3
  • 11