具有分类和连续自变量的逻辑回归。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的指导。这是非常有用的信息