我使用MuMIn来计算模型平均过程中的参数估计值。现在我想比较条件与收缩的参数估计。我想比较两种方法的参数估计值和标准误差,但我遇到了问题。我运行下面的代码来获得一个总结表,看起来很棒。我想要摘要表中的内容。但是当我尝试从汇总表中选择收缩表时,它只给出了参数估计值,而不是完整的表格。
我的数据样本为here。
这是我的代码。它改编自先前版本的一系列因变量。
data <- read.csv(sample)
xvar <- colnames(data)[2:11]
yvar <- colnames(data)[1]
formlist <- list()
for(i in yvar){
formlist[[paste(i)]] <- as.formula(paste(i, "~ ", paste(xvar, collapse="+")))
}
library("MuMIn")
options(na.action = "na.fail")
name <- names(formlist)[1]
fm1 <- lm(formlist[[1]], data=data)
ms1 <- dredge(fm1)
modav <- model.avg(ms1, subset = delta < 4)
options(na.action = "na.pass")
modname <- paste0("Y", rep(1, 10))
relimp <- summary(modav)$importance[1:10]
parameter <- as.data.frame(cbind(names(relimp), modname))
names(parameter) <- c("Parameter", "Dependent.var")
parest <- coefficients(modav)[2:11]
antm[[paste(name)]] <- cbind(parameter,relimp, parest)
coeff <- modav[3]
shrink <- modav[4]
}
我被困在最后两行。如果我运行summary(modav)
,我会得到下表:
Call:
model.avg.model.selection(object = ms1, subset = delta < 4)
Component models:
df logLik AICc Delta Weight
4/5 4 -800.73 1609.63 0.00 0.04
5 3 -802.12 1610.34 0.70 0.03
3/4/5 5 -800.10 1610.45 0.82 0.03
4/5/9 5 -800.21 1610.68 1.05 0.03
4/5/10 5 -800.41 1611.07 1.44 0.02
2/5 4 -801.47 1611.11 1.48 0.02
4 3 -802.55 1611.21 1.57 0.02
1/4/5 5 -800.48 1611.22 1.59 0.02
4/9 4 -801.54 1611.25 1.62 0.02
5/6 4 -801.58 1611.34 1.70 0.02
3/4 4 -801.62 1611.42 1.78 0.02
5/10 4 -801.63 1611.44 1.80 0.02
4/5/6 5 -800.61 1611.47 1.84 0.02
3/4/5/10 6 -799.58 1611.52 1.88 0.02
2/4/5 5 -800.67 1611.60 1.97 0.02
4/5/8 5 -800.67 1611.60 1.97 0.02
4/5/7 5 -800.73 1611.72 2.08 0.02
5/9 4 -801.79 1611.74 2.11 0.01
1/3/4/5 6 -799.77 1611.90 2.27 0.01
3/4/10 5 -800.87 1612.00 2.37 0.01
3/4/5/9 6 -799.87 1612.10 2.47 0.01
1/5 4 -801.99 1612.14 2.51 0.01
3/4/5/6 6 -799.90 1612.15 2.52 0.01
1/4/5/9 6 -799.90 1612.16 2.53 0.01
4/5/9/10 6 -799.94 1612.24 2.60 0.01
4/10 4 -802.07 1612.30 2.67 0.01
3/5 4 -802.07 1612.31 2.68 0.01
2/5/10 5 -801.03 1612.32 2.69 0.01
5/7 4 -802.10 1612.36 2.73 0.01
3/4/5/8 6 -800.01 1612.37 2.74 0.01
5/8 4 -802.12 1612.40 2.77 0.01
3/4/9 5 -801.13 1612.51 2.88 0.01
2/3/4/5 6 -800.08 1612.52 2.88 0.01
2/5/6 5 -801.14 1612.54 2.90 0.01
3/4/5/7 6 -800.10 1612.55 2.92 0.01
4/9/10 5 -801.16 1612.58 2.95 0.01
1/5/6 5 -801.18 1612.61 2.98 0.01
5/6/10 5 -801.18 1612.61 2.98 0.01
4/5/8/9 6 -800.14 1612.64 3.01 0.01
2/5/9 5 -801.24 1612.72 3.09 0.01
4/5/6/9 6 -800.20 1612.75 3.12 0.01
1/4/5/6 6 -800.20 1612.76 3.12 0.01
4/5/7/9 6 -800.20 1612.76 3.13 0.01
1/4/9 5 -801.26 1612.76 3.13 0.01
2/4/5/9 6 -800.20 1612.76 3.13 0.01
4/7 4 -802.32 1612.80 3.17 0.01
1/2/5 5 -801.30 1612.85 3.22 0.01
4/7/9 5 -801.30 1612.86 3.23 0.01
1/4/5/10 6 -800.26 1612.87 3.24 0.01
1/4 4 -802.35 1612.88 3.24 0.01
1/3/4 5 -801.34 1612.92 3.29 0.01
5/9/10 5 -801.34 1612.94 3.30 0.01
4/5/6/10 6 -800.30 1612.97 3.33 0.01
2/5/7 5 -801.36 1612.98 3.35 0.01
2/3/5 5 -801.37 1613.00 3.37 0.01
1/4/5/8 6 -800.33 1613.02 3.39 0.01
2/4/5/10 6 -800.35 1613.05 3.42 0.01
4/6/9 5 -801.40 1613.06 3.43 0.01
4/8 4 -802.45 1613.06 3.43 0.01
2/5/8 5 -801.41 1613.08 3.45 0.01
3/5/6 5 -801.42 1613.09 3.46 0.01
4/8/9 5 -801.43 1613.10 3.47 0.01
5/6/9 5 -801.43 1613.11 3.47 0.01
1/3/4/5/6 7 -799.32 1613.12 3.49 0.01
2/4 4 -802.49 1613.15 3.52 0.01
3/4/7 5 -801.46 1613.18 3.54 0.01
4/5/7/10 6 -800.41 1613.18 3.54 0.01
4/5/8/10 6 -800.41 1613.18 3.54 0.01
3/4/8 5 -801.47 1613.19 3.56 0.01
1/2/4/5 6 -800.42 1613.20 3.57 0.01
4/6 4 -802.53 1613.23 3.60 0.01
1/3/4/5/10 7 -799.38 1613.24 3.61 0.01
3/5/10 5 -801.50 1613.25 3.61 0.01
3/4/5/6/10 7 -799.39 1613.27 3.63 0.01
1/4/5/7 6 -800.48 1613.33 3.69 0.01
2/4/9 5 -801.54 1613.33 3.70 0.01
5/8/10 5 -801.54 1613.34 3.70 0.01
3/4/5/9/10 7 -799.43 1613.35 3.72 0.01
5/6/8 5 -801.58 1613.41 3.77 0.01
1/5/10 5 -801.58 1613.41 3.77 0.01
5/6/7 5 -801.58 1613.42 3.79 0.01
4/5/6/8 6 -800.54 1613.44 3.81 0.01
3/4/9/10 6 -800.54 1613.44 3.81 0.01
2/4/5/6 6 -800.56 1613.47 3.84 0.01
5/7/10 5 -801.61 1613.47 3.84 0.01
2/3/4 5 -801.61 1613.47 3.84 0.01
3/4/6 5 -801.62 1613.50 3.87 0.01
1/5/9 5 -801.62 1613.50 3.87 0.01
1/3/4/5/9 7 -799.52 1613.51 3.88 0.01
4/5/6/7 6 -800.59 1613.54 3.91 0.01
1/3/4/5/8 7 -799.54 1613.56 3.93 0.01
2/3/4/5/10 7 -799.56 1613.60 3.97 0.01
2/4/5/7 6 -800.63 1613.63 3.99 0.01
Term codes:
x1 x10 x11 x12 x13 x3 x6 x7 x8 x9
1 2 3 4 5 6 7 8 9 10
Model-averaged coefficients:
Estimate Std. Error Adjusted SE z value Pr(>|z|)
(Intercept) 21.726148 10.349691 10.385920 2.092 0.0364 *
x12 -0.060303 0.033535 0.033677 1.791 0.0734 .
x13 0.049389 0.025342 0.025455 1.940 0.0523 .
x11 0.375891 0.353959 0.355619 1.057 0.2905
x8 -0.009888 0.010048 0.010097 0.979 0.3274
x9 0.066302 0.073081 0.073449 0.903 0.3667
x10 -0.134885 0.224293 0.225290 0.599 0.5494
x1 0.391017 0.548170 0.550904 0.710 0.4778
x3 1.258309 2.114061 2.123291 0.593 0.5534
x7 -0.053482 0.218217 0.219239 0.244 0.8073
x6 0.167158 0.959226 0.963771 0.173 0.8623
Full model-averaged coefficients (with shrinkage):
Estimate Std. Error Adjusted SE z value Pr(>|z|)
(Intercept) 21.726148 10.349691 10.385920 2.092 0.0364 *
x12 -0.042489 0.039361 0.039446 1.077 0.2814
x13 0.038541 0.030319 0.030393 1.268 0.2048
x11 0.103503 0.250382 0.251029 0.412 0.6801
x8 -0.002376 0.006489 0.006507 0.365 0.7150
x9 0.015042 0.044529 0.044666 0.337 0.7363
x10 -0.022982 0.105561 0.105922 0.217 0.8282
x1 0.069971 0.276107 0.277079 0.253 0.8006
x3 0.231713 1.029987 1.033478 0.224 0.8226
x7 -0.006275 0.076700 0.077041 0.081 0.9351
x6 0.019317 0.330433 0.331957 0.058 0.9536
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Relative variable importance:
x13 x12 x11 x8 x9 x3 x1 x10 x7 x6
Importance: 0.78 0.70 0.28 0.24 0.23 0.18 0.18 0.17 0.12 0.12
N containing models: 70 65 28 24 24 21 20 19 14 14
看起来不错!如果我运行summary(modav)[3]
,我会得到:
$avg.model
Estimate Std. Error Adjusted SE Lower CI Upper CI
(Intercept) 21.726148149 10.34969082 10.38592000 1.3701190119 42.082177286
x12 -0.060303493 0.03353455 0.03367710 -0.1263093944 0.005702409
x13 0.049389493 0.02534158 0.02545464 -0.0005006826 0.099279669
x11 0.375891126 0.35395924 0.35561886 -0.3211090361 1.072891288
x8 -0.009887984 0.01004840 0.01009655 -0.0296768586 0.009900890
x9 0.066302224 0.07308107 0.07344873 -0.0776546368 0.210259085
x10 -0.134884710 0.22429287 0.22529036 -0.5764456948 0.306676276
x1 0.391016656 0.54817001 0.55090396 -0.6887352705 1.470768583
x3 1.258309004 2.11406084 2.12329116 -2.9032652035 5.419883211
x7 -0.053481971 0.21821694 0.21923860 -0.4831817329 0.376217790
x6 0.167158391 0.95922641 0.96377088 -1.7217978265 2.056114609
这正是我想要的。如果我运行summary(modav)[4]
而不是获得类似的表格,我只会得到参数估计值。
> summary(modav)[4]
$coef.shrinkage
(Intercept) x12 x13 x11 x8 x9 x10 x1 x3 x7 x6
21.726148149 -0.042488773 0.038540747 0.103502707 -0.002375575 0.015042454 -0.022981800 0.069970584 0.231713307 -0.006274563 0.019317072
我真正想要的是:
Full model-averaged coefficients (with shrinkage):
Estimate Std. Error Adjusted SE z value Pr(>|z|)
(Intercept) 21.726148 10.349691 10.385920 2.092 0.0364 *
x12 -0.042489 0.039361 0.039446 1.077 0.2814
x13 0.038541 0.030319 0.030393 1.268 0.2048
x11 0.103503 0.250382 0.251029 0.412 0.6801
x8 -0.002376 0.006489 0.006507 0.365 0.7150
x9 0.015042 0.044529 0.044666 0.337 0.7363
x10 -0.022982 0.105561 0.105922 0.217 0.8282
x1 0.069971 0.276107 0.277079 0.253 0.8006
x3 0.231713 1.029987 1.033478 0.224 0.8226
x7 -0.006275 0.076700 0.077041 0.081 0.9351
x6 0.019317 0.330433 0.331957 0.058 0.9536
任何人都有关于如何获得这个的想法?我不能每次都复制和粘贴,我有60个因变量来运行它。我真的需要每个因变量的每个估计的标准误差。
答案 0 :(得分:1)
coefTable(modav, full=TRUE) # full=FALSE for "subset" coefficients