2016-02-04 46 views
0

我使用nlme軟件包在R中運行多元混合模型。假設x和y是假定組內誤差相關的縱向數據的響應變量。殘差矩陣表示爲: enter image description herer中多元混合模型的相關性

所以我的問題是如何涉及到相關函數lme函數? 我試過命令corr = corComSymm(from =~ 1 | x)corr = corAR1(from =~ 1 | x),但沒有奏效!

這裏設有例如:

# 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) 

有什麼建議?

+0

嘗試添加[最小再現的示例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example),通常包括一個數據集和一些代碼以顯示問題。 – aosmith

+0

我添加了一個可重複的例子。 –

+0

這是我編輯過的用於標記說明的第4或第5篇文章。你正在使用'nlme'軟件包。你沒有使用'lme4'軟件包。請適當地標記你的問題。 –

回答