可能很简单,但我想知道,在使用zeroinfl命令时如何获取系数?
treatment <- factor(rep(c(1, 2), c(43, 41)),
levels = c(1, 2),labels = c("placebo", "treated"))
improved <- factor(rep(c(1, 2, 3, 1, 2, 3), c(29, 7, 7, 13, 7, 21)),
levels = c(1, 2, 3),labels = c("none", "some", "marked"))
numberofdrugs <- rpois(84, 2)
healthvalue <- rpois(84,0.5)
y <- data.frame(healthvalue,numberofdrugs, treatment, improved)
require(pscl)
ZIP<-zeroinfl(healthvalue~numberofdrugs+treatment+improved, y)
summary(ZIP)
Run Code Online (Sandbox Code Playgroud)
我通常ZIP$coef[1]用来获取系数,但遗憾的是你在这里抓了一大堆.那么如何从ZIP模型中获取单个系数呢?
使用coef提取函数列出一个长向量中的所有系数,然后您可以使用单个索引表示法来选择它们:
coef(ZIP)[1]
count_(Intercept)
0.1128742
Run Code Online (Sandbox Code Playgroud)
或者,您需要选择首先获得系数的模型:
ZIP$coef$count[1]
(Intercept)
0.1128742
ZIP$coef[[1]][1]
(Intercept)
0.1128742
Run Code Online (Sandbox Code Playgroud)