为什么当我使用一个分类预测变量运行逻辑回归时,我的回归并不显着,而如果我使用相同的变量运行逻辑回归,但它是连续的,逻辑回归会自动变得显着?
逻辑回归:分类预测器与定量预测器
机器算法验证
回归
分类数据
连续数据
分箱
2022-03-30 07:22:35
3个回答
这不是必然的结果,但肯定是合理的。如果你把一个量化的预测器变成一个单一的分类预测器,你会丢失很多信息;使用分类预测器,您只知道观察值是低于还是高于某个阈值(例如平均值或中位数),而使用定量预测器,您还知道观察值低于或高于阈值多少。怀疑如果您为模型提供更多信息(即添加变量作为定量预测器),您将获得更精确的结果,这并非没有道理。
这不一定正确的原因之一是,如果您将变量作为定量变量添加到回归模型中,您会假设该变量的影响是线性的。如果效果是强烈非线性的,那么这可能会抵消添加定量变量的优势。但是,有一些简单的方法可以检查是否是这种情况(针对预测变量的残差图),以及解决它的简单方法(将变量添加为样条曲线或多项式可能是最简单的解决方案)。
这取决于您所说的“相同的变量,除了它是连续的”。如@Maarten 所述,将真正连续的变量分为两个或多个类别会丢失信息。如果您要比较分析处理预测变量值,例如,作为连续或分类,在后一种情况下,您适合九个参数和导致剩余自由度下降会使回归变得不显着,尤其是在较小的数据集中。
正如@MaartenBuis 所写,分类会丢失很多信息。Lagakos 不久前写了一篇关于错误建模解释变量时功率损失的优秀文章。在表 IV 中,您可以看到通过不同模式离散化后丢失了多少信息。您可能还想查看 Frank Harrell关于分类主题的列表。
虽然针对连续预测变量的残差图是检查线性假设的一种简单方法,但我发现 ANOVA 在这里非常方便。R 中的rms-package 允许您直接从 -function 的手册页轻松测试线性度lrm():
#Fit a logistic model containing predictors age, blood.pressure, sex
#and cholesterol, with age fitted with a smooth 5-knot restricted cubic
#spline function and a different shape of the age relationship for males
#and females. As an intermediate step, predict mean cholesterol from
#age using a proportional odds ordinal logistic model
#
n <- 1000 # define sample size
set.seed(17) # so can reproduce the results
age <- rnorm(n, 50, 10)
blood.pressure <- rnorm(n, 120, 15)
cholesterol <- rnorm(n, 200, 25)
sex <- factor(sample(c('female','male'), n,TRUE))
label(age) <- 'Age' # label is in Hmisc
label(cholesterol) <- 'Total Cholesterol'
label(blood.pressure) <- 'Systolic Blood Pressure'
label(sex) <- 'Sex'
units(cholesterol) <- 'mg/dl' # uses units.default in Hmisc
units(blood.pressure) <- 'mmHg'
# Specify population model for log odds that Y=1
L <- .4*(sex=='male') + .045*(age-50) +
(log(cholesterol - 10)-5.2)*(-2*(sex=='female') + 2*(sex=='male'))
# Simulate binary y to have Prob(y=1) = 1/[1+exp(-L)]
y <- ifelse(runif(n) < plogis(L), 1, 0)
cholesterol[1:3] <- NA # 3 missings, at random
ddist <- datadist(age, blood.pressure, cholesterol, sex)
options(datadist='ddist')
fit <- lrm(y ~ blood.pressure + sex * (age + rcs(cholesterol,4)),
x=TRUE, y=TRUE)
# x=TRUE, y=TRUE allows use of resid(), which.influence below
# could define d <- datadist(fit) after lrm(), but data distribution
# summary would not be stored with fit, so later uses of Predict
# or summary.rms would require access to the original dataset or
# d or specifying all variable values to summary, Predict, nomogram
anova(fit)
为您提供方差分析输出:
Wald Statistics Response: y
Factor Chi-Square d.f. P
blood.pressure 0.23 1 0.6315
sex (Factor+Higher Order Factors) 38.17 5 <.0001
All Interactions 26.25 4 <.0001
age (Factor+Higher Order Factors) 30.48 2 <.0001
All Interactions 3.68 1 0.0552
cholesterol (Factor+Higher Order Factors) 24.15 6 0.0005
All Interactions 22.74 3 <.0001
Nonlinear (Factor+Higher Order Factors) 5.11 4 0.2759
sex * age (Factor+Higher Order Factors) 3.68 1 0.0552
sex * cholesterol (Factor+Higher Order Factors) 22.74 3 <.0001
Nonlinear 4.54 2 0.1031
Nonlinear Interaction : f(A,B) vs. AB 4.54 2 0.1031
TOTAL NONLINEAR 5.11 4 0.2759
TOTAL INTERACTION 26.25 4 <.0001
TOTAL NONLINEAR + INTERACTION 26.98 6 0.0001
TOTAL 62.10 10 <.0001
如您所见,此示例中没有强烈支持非线性。我发现以这种方式测试非常复杂的模型非常容易。希望这可以帮助。
其它你可能感兴趣的问题