在 R 中确定 Logistic 模型的解释方向
Determining Interpretation Direction of Logistic Model in R
我正在尝试 运行 逻辑回归来预测一个名为 has_sed 的变量(二进制,描述样本是否有沉积物,编码为 0 = 没有沉积物和 1 =有沉淀)。请参阅下面此模型的摘要输出:
Call:
glm(formula = has_sed ~ vw + ws_avg + s, family = binomial(link = "logit"),
data = spdata_ss)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.4665 -0.8659 -0.6325 1.1374 2.3407
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.851966 0.667291 1.277 0.201689
vw -0.118140 0.031092 -3.800 0.000145 ***
ws_avg -0.015815 0.008276 -1.911 0.055994 .
s 0.034471 0.019216 1.794 0.072827 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 296.33 on 241 degrees of freedom
Residual deviance: 269.91 on 238 degrees of freedom
AIC: 277.91
Number of Fisher Scoring iterations: 4
现在,我了解了如何解释一般这样的逻辑模型输出,但我不了解 R 如何选择我的因变量的方向(可能是一个更好的词)。我如何知道 vw 的单位增加是否会增加具有沉积物的样本的对数几率,或增加没有沉积物的样本的对数几率(即 has_sed = 0 与 has_sed = 1) ?
我用箱线图绘制出了这些关系中的每一个,逻辑模型输出中估计值的符号看起来与我在箱线图中看到的相反。那么,R 是计算 has_sed 为 0 的对数几率,还是计算它为 1 的对数几率?
最好用一个例子来说明,
我将使用虹膜数据和两个 类
data(iris)
iris2 = iris[iris$Species!="setosa",]
iris2$Species = factor(iris2$Species)
levels(iris2$Species)
#output[1] "versicolor" "virginica"
让我们做一个glm
model = glm(Species ~ Petal.Length, data = iris2, family = binomial(link = "logit"))
summary(model)
#truncated output
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -43.781 11.110 -3.941 8.12e-05 ***
Petal.Length 9.002 2.283 3.943 8.04e-05 ***
library(ggplot2)
ggplot(iris2)+
geom_boxplot(aes(x = Species, y = Petal.Length))
成为"virginica"的机会随着Petal.Length的增加而增加,参考水平是"versicolor"——我们做levels(iris2$Species)
时的第一个水平。
让我们改变它
iris2$Species = relevel(iris2$Species, ref = "virginica")
levels(iris2$Species)
#output
[1] "virginica" "versicolor"
model2 = glm(Species ~ Petal.Length, data = iris2, family = binomial(link = "logit"))
summary(model2)
#truncated output
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 43.781 11.110 3.941 8.12e-05 ***
Petal.Length -9.002 2.283 -3.943 8.04e-05 ***
现在参考级别是"virginica"levels(iris2$Species)
中的第一个级别。 "versicolor" 的几率随着 Petal.Length 的增加而下降。
简而言之,响应变量中水平的顺序决定了治疗对比的参考水平。
我正在尝试 运行 逻辑回归来预测一个名为 has_sed 的变量(二进制,描述样本是否有沉积物,编码为 0 = 没有沉积物和 1 =有沉淀)。请参阅下面此模型的摘要输出:
Call:
glm(formula = has_sed ~ vw + ws_avg + s, family = binomial(link = "logit"),
data = spdata_ss)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.4665 -0.8659 -0.6325 1.1374 2.3407
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.851966 0.667291 1.277 0.201689
vw -0.118140 0.031092 -3.800 0.000145 ***
ws_avg -0.015815 0.008276 -1.911 0.055994 .
s 0.034471 0.019216 1.794 0.072827 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 296.33 on 241 degrees of freedom
Residual deviance: 269.91 on 238 degrees of freedom
AIC: 277.91
Number of Fisher Scoring iterations: 4
现在,我了解了如何解释一般这样的逻辑模型输出,但我不了解 R 如何选择我的因变量的方向(可能是一个更好的词)。我如何知道 vw 的单位增加是否会增加具有沉积物的样本的对数几率,或增加没有沉积物的样本的对数几率(即 has_sed = 0 与 has_sed = 1) ?
我用箱线图绘制出了这些关系中的每一个,逻辑模型输出中估计值的符号看起来与我在箱线图中看到的相反。那么,R 是计算 has_sed 为 0 的对数几率,还是计算它为 1 的对数几率?
最好用一个例子来说明, 我将使用虹膜数据和两个 类
data(iris)
iris2 = iris[iris$Species!="setosa",]
iris2$Species = factor(iris2$Species)
levels(iris2$Species)
#output[1] "versicolor" "virginica"
让我们做一个glm
model = glm(Species ~ Petal.Length, data = iris2, family = binomial(link = "logit"))
summary(model)
#truncated output
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -43.781 11.110 -3.941 8.12e-05 ***
Petal.Length 9.002 2.283 3.943 8.04e-05 ***
library(ggplot2)
ggplot(iris2)+
geom_boxplot(aes(x = Species, y = Petal.Length))
成为"virginica"的机会随着Petal.Length的增加而增加,参考水平是"versicolor"——我们做levels(iris2$Species)
时的第一个水平。
让我们改变它
iris2$Species = relevel(iris2$Species, ref = "virginica")
levels(iris2$Species)
#output
[1] "virginica" "versicolor"
model2 = glm(Species ~ Petal.Length, data = iris2, family = binomial(link = "logit"))
summary(model2)
#truncated output
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 43.781 11.110 3.941 8.12e-05 ***
Petal.Length -9.002 2.283 -3.943 8.04e-05 ***
现在参考级别是"virginica"levels(iris2$Species)
中的第一个级别。 "versicolor" 的几率随着 Petal.Length 的增加而下降。
简而言之,响应变量中水平的顺序决定了治疗对比的参考水平。