我想拟合一个混合效应模型,让我能够解释不同地理位置的不相等差异。具体来说,我想预测response
为固定效应的函数和X
随机geo
效应。
以下是数据的样子:
X response geo
1 4 5.521461 other
2 4 5.164786 other
3 4 5.164786 other
4 6 3.401197 other
5 5 4.867534 other
6 4 5.010635 other
geo 列的唯一值:
[1] "other" "Atlanta-Sandy Springs-Marietta, GA" "Chicago-Naperville-Joliet, IL-IN-WI" "Dallas-Fort Worth-Arlington, TX"
[5] "Houston-Sugar Land-Baytown, TX" "Los Angeles-Long Beach-Santa Ana, CA" "Miami-Fort Lauderdale-Pompano Beach, FL" "Phoenix-Mesa-Glendale, AZ"
这是我尝试过的模型:
> lme0 <- lme(response ~ factor(predictor) , random = ~1|factor(geo), data = HC_hired)
> summary(lme0)
Linear mixed-effects model fit by REML
Data: HC_hired
AIC BIC logLik
54770.69 54836.3 -27377.34
Random effects:
Formula: ~1 | factor(geo)
(Intercept) Residual
StdDev: 0.08689381 0.66802
Fixed effects: response ~ factor(predictor)
Value Std.Error DF t-value p-value
(Intercept) 4.255531 0.04410213 26918 96.49264 0.0000
factor(predictor)2 0.022986 0.03336742 26918 0.68889 0.4909
factor(predictor)3 0.166341 0.03221410 26918 5.16361 0.0000
factor(predictor)4 0.299172 0.03194177 26918 9.36618 0.0000
factor(predictor)5 0.378645 0.03249053 26918 11.65402 0.0000
factor(predictor)6 0.472583 0.03664732 26918 12.89543 0.0000
Correlation:
(Intr) fct()2 fct()3 fct()4 fct()5
factor(predictor)2 -0.660
factor(predictor)3 -0.683 0.903
factor(predictor)4 -0.689 0.912 0.945
factor(predictor)5 -0.679 0.897 0.930 0.940
factor(predictor)6 -0.603 0.795 0.824 0.832 0.819
Standardized Within-Group Residuals:
Min Q1 Med Q3 Max
-4.7047458 -0.3424262 0.1883132 0.7045260 2.1949313
Number of Observations: 26931
Number of Groups: 8
我的问题是输出没有为每个地理级别指定随机效果。执行此操作的正确型号规格是什么?我已经尝试了许多公式的排列,但没有运气。也欢迎对整个过程提出任何意见。提前谢谢了!
回应评论(强制地理因素不会改变输出):
HC_hired$geo <- as.factor(HC_hired$geo) lme0 <- lme(response ~ factor(predictor) , random = ~1|factor(geo), data = HC_hired) 摘要(lme0)