![](/img/trans.png)
[英]How to determine if a linear mixed model is overdetermined in lme4/nlme?
[英]different linear mixed model coefficients in lme4 vs nlme
我正在嘗試比較lme4
與nlme
中相同線性混合 model 的系數,請參閱使用penguins
數據集的此示例。
我無法弄清楚為什么它們不同? 為什么使用nlme
時 3 組的截距相同?
library(tidyverse)
library(palmerpenguins)
library(lme4)
library(nlme)
db <- penguins %>%
filter(!is.na(flipper_length_mm), !is.na(bill_length_mm), !is.na(body_mass_g))
lme4_fit <- lme4::lmer(
body_mass_g ~ flipper_length_mm + bill_length_mm + (1+flipper_length_mm|species),
REML = TRUE,
data = db
)
nlme_fit <- nlme::lme(
body_mass_g ~ flipper_length_mm + bill_length_mm,
random = ~ 1+flipper_length_mm|species,
method = "REML",
data = db
)
coef(lme4_fit)
coef(nlme_fit)
好的,所以在仔細查看模型之后,問題是使用 nlme 擬合的 model 具有奇異擬合。 隨機截距的 SD 估計值很小,這就是為什么當您調用coef(nlme_fit)
時,數據中的每個組都會返回幾乎相同的數字。
請參閱這篇文章和評論: nlme 估計隨機效應的方差接近零
在這個具體的例子中,如果我們調用summary()
而不是coef()
並查看那里報告的 model 的所有部分。 這就是我看到隨機效應中的截距是 322.54 在 model 適合lme4
,而在一個適合 nlme 它是 4.042139e-04。 我已經在每個 model 摘要中注釋了此信息所在的行。
如果您有任何其他問題,請告訴我們。
summary(lme4_fit)
Linear mixed model fit by REML ['lmerMod']
Formula: body_mass_g ~ flipper_length_mm + bill_length_mm + (1 + flipper_length_mm | species)
Data: db
REML criterion at convergence: 4946.3
Scaled residuals:
Min 1Q Median 3Q Max
-2.46124 -0.66304 -0.09222 0.61054 3.12864
Random effects:
Groups Name Variance Std.Dev. Corr
species (Intercept) 104030.92 322.54 # ESTIMATE LME4 HERE
flipper_length_mm 14.59 3.82 -0.98
Residual 115095.78 339.26
Number of obs: 342, groups: species, 3
Fixed effects:
Estimate Std. Error t value
(Intercept) -3943.198 577.935 -6.823
flipper_length_mm 26.749 3.835 6.975
bill_length_mm 60.460 7.097 8.520
Correlation of Fixed Effects:
(Intr) flpp__
flppr_lngt_ -0.850
bll_lngth_m -0.018 -0.401
optimizer (nloptwrap) convergence code: 0 (OK)
unable to evaluate scaled gradient
Model failed to converge: degenerate Hessian with 1 negative eigenvalues
summary(nlme_fit)
Linear mixed-effects model fit by REML
Data: db
AIC BIC logLik
4960.718 4987.5 -2473.359
Random effects:
Formula: ~1 + flipper_length_mm | species
Structure: General positive-definite, Log-Cholesky parametrization
StdDev Corr
(Intercept) 4.042139e-04 (Intr) # ESTIMATE NLME HERE
flipper_length_mm 2.308314e+00 0.941
Residual 3.394369e+02
Fixed effects: body_mass_g ~ flipper_length_mm + bill_length_mm
Value Std.Error DF t-value p-value
(Intercept) -4025.568 550.7142 337 -7.309723 0
flipper_length_mm 27.117 3.4150 337 7.940672 0
bill_length_mm 60.773 7.0958 337 8.564632 0
Correlation:
(Intr) flpp__
flipper_length_mm -0.794
bill_length_mm -0.022 -0.448
Standardized Within-Group Residuals:
Min Q1 Med Q3 Max
-2.43161474 -0.67327147 -0.08989753 0.62206892 3.11662877
Number of Observations: 342
Number of Groups: 3
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.