重要なことは、nlme::lmList
はlist
オブジェクトを返します。そのため、リストメソッドを使用する必要があります。 iris
データ上に作られたモデルを使用して、これを行うには
二つの方法。最初の方法は各グループの別々のモデルを推定し、2番目の方法は複数レベルのモデルに適合し、グループ内にネストされた観察を行います。
library(nlme)
# run the models and store them
modlist <- lmList(object = Petal.Length ~ Sepal.Length | Species, data = iris)
# see the results
summary(modlist)
これが返されます:base
Rからnlme
からlmList
とcooks.distance
を使用してまず
、
Call:
Model: Petal.Length ~ Sepal.Length | Species
Data: iris
Coefficients:
(Intercept)
Estimate Std. Error t value Pr(>|t|)
setosa 0.8030518 0.5310388 1.5122280 0.1326674
versicolor 0.1851155 0.4305590 0.4299423 0.6678803
virginica 0.6104680 0.3882233 1.5724662 0.1180371
Sepal.Length
Estimate Std. Error t value Pr(>|t|)
setosa 0.1316317 0.10582369 1.243877 2.155658e-01
versicolor 0.6864698 0.07226626 9.499174 6.483105e-17
virginica 0.7500808 0.05866167 12.786556 1.714921e-25
Residual standard error: 0.2611123 on 144 degrees of freedom
今クックの距離を取得:
cooks1 <- lapply(modlist, cooks.distance)
第二に、lmList
を使用してからlme4
とCookD
predictmeans
から:
library(predictmeans)
# this loads lme4 as a required package
# run the models and store them
modlist2 <- lmer(Petal.Length ~ Sepal.Length + (1 | Species), data = iris)
# see the results
summary(modlist2)
これが返されます。
Linear mixed model fit by REML ['lmerMod']
Formula: Petal.Length ~ Sepal.Length + (1 | Species)
Data: iris
REML criterion at convergence: 69.3
Scaled residuals:
Min 1Q Median 3Q Max
-2.71305 -0.62672 0.02935 0.61922 2.83011
Random effects:
Groups Name Variance Std.Dev.
Species (Intercept) 2.52912 1.5903
Residual 0.07984 0.2826
Number of obs: 150, groups: Species, 3
Fixed effects:
Estimate Std. Error t value
(Intercept) 0.05252 0.95576 0.055
Sepal.Length 0.63414 0.04525 14.014
Correlation of Fixed Effects:
(Intr)
Sepal.Lngth -0.277
をクックの距離と関連するプロットを取得:
cooks2 <- CookD(model = modlist2)
CookD
もここに警告を収束するために何らかの障害をスローしますが、プロットは大丈夫と思われ、影響力のある点がはっきりと目立ちます。
あなたにすべての私の答えは役に立ちましたか?あるいは、あなたの質問にもっと助けが必要ですか? – meenaparam