我使用R中的betamix
包来拟合beta回归的混合。如果我使用包中给出的示例代码:
data("ReadingSkills", package = "betareg")
set.seed(4040)
rs_mix <- betamix(accuracy ~ iq, data = ReadingSkills, k = 3,
nstart = 10, extra_components = extraComponent(type = "uniform",
coef = 0.99, delta = 0.01))
summary(rs_mix)
运行拟合betamix
对象的摘要会得到结果:
> summary(rs_mix)
$Comp.1
$Comp.1$mean
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.40342 0.26332 5.3296 9.84e-08 ***
iq 0.82502 0.21630 3.8142 0.0001366 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
$Comp.1$precision
Estimate Std. Error z value Pr(>|z|)
(Intercept) 2.68509 0.45435 5.9097 3.427e-09 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
$Comp.2
$Comp.2$mean
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.502523 0.082476 6.0930 1.108e-09 ***
iq -0.048415 0.112923 -0.4287 0.6681
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
$Comp.2$precision
Estimate Std. Error z value Pr(>|z|)
(Intercept) 4.25160 0.74737 5.6888 1.279e-08 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Component 2
结果显示变量iq
不重要。有没有办法从摘要结果中删除此变量?我尝试过使用summary(rs_mix)$Comp.1
,它给了我错误:
Error in summary(rs_mix)$Comp.1 :
$ operator not defined for this S4 class
答案 0 :(得分:2)
您可以使用@
符号访问S4对象。对于S3对象,它的工作方式类似于$
。
smr = summary(rs_mix)
comps = smr@components[[1]]
significance_level = 0.05
lapply(comps, function(x) {
bool = x[['mean']][,4] < significance_level
x[['mean']][bool, ]
})
$Comp.1
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.4034184 0.2633230 5.329647 9.840410e-08
iq 0.8250193 0.2163036 3.814172 1.366404e-04
$Comp.2
Estimate Std. Error z value Pr(>|z|)
5.025226e-01 8.247566e-02 6.092981e+00 1.108272e-09