简体   繁体   English

使用glmulti函数提取p值

[英]Using glmulti function to extract p-value

I am using the package glmulti to find the "best" model for 我正在使用glmulti软件包来查找“最佳”模型

mo <- glm(a ~ x + y + z, data=data, family=binomial)
test <- glmulti(mo, family = binomial, level=1, crit="aicc")

However, I am more interested in the p-values of x in all models (to find the best p-value). 但是,我对所有模型中x的p值更感兴趣(以找到最佳的p值)。 How can I extract them from all models? 如何从所有模型中提取它们?

test outputs the best model, but gmulti allows you to see all the models. 测试输出最佳模型,但是gmulti允许您查看所有模型。 You can see all other models with their weights and aicc values with weightable 你可以看到所有其他机型与它们的权重,并与AICC值weightable

weightable(test)

Here is a loop through the resultset, build glm model with as.formula() and extract the p-values of x (if present) from the summaries. 这是一个遍历结果集的循环,使用as.formula()建立glm模型,并从摘要中提取x的p值(如果存在)。

library(glmulti)

iris2 <- iris
iris2$virginica <- iris$Species == "virginica"

mo = glm(virginica ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width, data=iris2, family="binomial")

test <- glmulti(mo, family = binomial, level=1, crit="aicc")

tbl <- weightable(test)
nrows <- nrow(tbl)

for (i in 1:nrows) {
    formulaTest <- as.character(tbl[i,]$model)
    model = glm(as.formula(formulaTest), data=iris2, family="binomial")

    print(paste("Formula: ", formulaTest))
    print(summary(model)$coefficients[,4])
}

[1] "Formula:  virginica ~ 1 + Sepal.Width + Petal.Length + Petal.Width"
 (Intercept)  Sepal.Width Petal.Length  Petal.Width 
  0.03522621   0.07853563   0.04033382   0.04534974 
[1] "Formula:  virginica ~ 1 + Sepal.Length + Sepal.Width + Petal.Length + Petal.Width"
 (Intercept) Sepal.Length  Sepal.Width Petal.Length  Petal.Width 
  0.09720282   0.30318813   0.13585218   0.04653593   0.06052811 
[1] "Formula:  virginica ~ 1 + Sepal.Length + Petal.Length + Petal.Width"
 (Intercept) Sepal.Length Petal.Length  Petal.Width 
  0.02770914   0.07149206   0.02891997   0.02830069 
...

If you want to employ advanced model selection, you could even combine top models, as described here: http://www.noamross.net/blog/2013/2/20/model-selection-drug.html 如果要使用高级模型选择,甚至可以组合顶级模型,如下所述: http : //www.noamross.net/blog/2013/2/20/model-selection-drug.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM