2017-08-16 41 views
0

我有一个包含700个不同帐户的数据集。每个帐户都有多行,包含x和y变量。所以总共有大约26000行数据。我试图找到与具体账户相关的“有影响力”的观点。我已经使用lmlist函数将估计系数获得给GLR。在科目中查找库克的距离R

model3 <- lmList(y ~ x | grp, data = dat)

我曾尝试使用的影响,然后CookD功能,但我认为这是不符合lmList兼容。

我知道,厨师用功能11聚物工作,但罚球11聚物的警告有关的故障与我的数据集收敛:

model1 <- lmer(y ~ x + (x | grp) , data = dat)

我已经阅读这一点,但仍然感到困惑的许多职位。我希望我有更多的专业知识来编写我想要实现的目标。任何帮助将不胜感激。

+0

我的回答对你有帮助吗?或者你需要更多的帮助来解决你的问题? – meenaparam

回答

1

要考虑的主要问题是nlme::lmList返回list对象,所以你必须使用它的列表方法。

两种方法可以使用iris数据上的模型。第一种方法为每个组估计单独的模型,而第二种方法适合多层次模型,观察嵌套在组内。

首先,利用nlmelmListcooks.distancebase R:

library(nlme) 

# run the models and store them 
modlist <- lmList(object = Petal.Length ~ Sepal.Length | Species, data = iris) 

# see the results 
summary(modlist) 

这将返回:

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 

现在得到的Cook距离:

cooks1 <- lapply(modlist, cooks.distance) 

其次,使用lmListlme4CookDpredictmeans

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 

获取Cook距离和相关剧情:

cooks2 <- CookD(model = modlist2) 

CookD也抛出了一些故障在这里汇聚警告,但情节似乎没有问题,有影响的一点很明显。