具有分类和连续自变量的逻辑回归。ROC曲线与混淆矩阵

具有分类和连续自变量的逻辑回归。ROC曲线与混淆矩阵,r,glm,R,Glm,我尝试使用以下语法执行逻辑回归 logregmodel <- glm(Y ~., data = quant, family = binomial() ) logregmodel如果在quant中,分类变量是非数字的,glm将它们作为分类变量正确处理 要获得混淆矩阵,请使用predict功能: # This will give you probabilities. fitted <- predict(logregmodel, quant, type="response") # Us

我尝试使用以下语法执行逻辑回归

logregmodel <- glm(Y ~., data = quant, family = binomial() )

logregmodel如果在
quant
中,分类变量是非数字的,
glm
将它们作为分类变量正确处理

要获得混淆矩阵,请使用
predict
功能:

# This will give you probabilities.
fitted <- predict(logregmodel, quant, type="response")

# Use a cut point to divide into classes
cutpoint <- 0.5
estimated.class <- ifelse(fitted > cutpoint, 'Class 1', 'Class 2')

# Calculate the confusion matrix
table(estimated.class, actual.class)
#这将为您提供概率。

您可以使用例如
sappy(quant,is.numeric)
sappy(quant,class)
来检查变量类型,并且
quantsub感谢christopher和luke的指导。这是非常有用的信息