具有lme和gls的协方差模型

时间:2012-03-06 06:49:20

标签: r model statistics covariance

我正在尝试使用gls和lme来拟合几个协方差模型。我的目标是确定哪种协方差模型更适合我的数据。但是,我担心我没有正确指定代码。有人可以看看我的代码,并帮我弄清楚我是否正确地追求一切?

# Unstructured covariance matrix
UN <- gls(y ~ ses + time, data, corr=corSymm(form=~1|id), weights=varIdent(form=~1|time), method="REML", control=lmeControl(msMaxIter = 500, msVerbose = TRUE), na.action=na.omit)

# Independence covariance matrix
IN <- gls(y ~ ses + time, data, corr=NULL, weights=NULL, method="REML", control=lmeControl(msMaxIter = 500, msVerbose = TRUE))

# Fit Random Intercept Model (RI)
RI <- lme(y ~ ses + time, data, na.action=na.omit, method="REML", random=~1|id, control=lmeControl(msMaxIter = 200, msVerbose = TRUE))

# Fit Random Intercept and Slopes Model (RIAS)
RIAS <- lme(y ~ ses + time, data, na.action=na.omit, method="REML", random=~time | id, control=lmeControl(msMaxIter = 200, msVerbose = TRUE))

# Fit Compound Symmetry Error Covariance Matrix
CS <- gls(y ~ ses + time, data, na.action=na.omit, method="REML", correlation=corCompSymm(,form=~1|id), control=lmeControl(msMaxIter = 500, msVerbose = TRUE))

# Fit Heterogeneous Compound Symmetry Error Covariance Matrix
CSH <- gls(y ~ ses + time, data, na.action=na.omit, method="REML", correlation=corCompSymm(,form=~1|id), weights=varIdent(form=~1|time), control=lmeControl(msMaxIter = 500, msVerbose = TRUE))

# AR(1)
AR1 <- gls(y ~ ses + time, data, na.action=na.omit, method="REML", correlation=corAR1(,form=~1|id), control=lmeControl(msMaxIter = 200, msVerbose = TRUE))

# AR(1) under heterocedasticity
ARH1 <- gls(y ~ ses + time, data, na.action=na.omit, method="REML", correlation=corAR1(,form=~1|id), weights=varIdent(form=~1|time), control=lmeControl(msMaxIter = 200, msVerbose = TRUE))

# RI plus AR(1) 
RIAR1 <- lme(y ~ ses + time, data, na.action=na.omit, method="REML", random=~1|id, correlation=corAR1(form=~1|id), control=lmeControl(msMaxIter = 200, msVerbose = TRUE))

# RI plus AR(1) under heterocedasticity
RIARH1 <- lme(y ~ ses + time, data, na.action=na.omit, method="REML", random=~1|id, correlation=corAR1(form=~1|id), weights=varIdent(form=~1|time), control=lmeControl(msMaxIter = 200, msVerbose = TRUE))

# RIAS plus AR(1)  
RIASAR1<- lme(y ~ ses + time, data, na.action=na.omit, method="REML", random=~time|id, correlation=corAR1(form=~1|id), control=lmeControl(msMaxIter = 200, msVerbose = TRUE)) 

# ARMA(1,1)
ARMA11 <- gls(y ~ ses + time, data, na.action=na.omit, method="REML", correlation=corARMA(,form=~time|id, p=1, q=1), control=lmeControl(msMaxIter = 200, msVerbose = TRUE))

# ARMA(1,1) under heterocedasticity
ARMA11HE <- gls(y ~ ses + time, data, na.action=na.omit, method="REML", correlation=corARMA(,form=~time|id, p=1, q=1), weights=varIdent(form=~1|time),  control = lmeControl(msMaxIter = 200, msVerbose = TRUE))

# Fit Toeplitz Error Covariance Matrix
TOEP <- gls(y ~ ses + time, data, na.action=na.omit, method="REML", correlation=corARMA(,form=~1|id, p=3, q=0))

# RIAQS plus AR(1) allow for heterocedasticity
RIAQSAR1 <- lme(y ~ ses + time, data, na.action=na.omit, method="REML", weights=varPower(form=~time), random=~time + I(time^2)|id, correlation=corAR1(form=~time), control=lmeControl(msMaxIter = 200, msVerbose = TRUE))

感谢

0 个答案:

没有答案