在 SPSS 输出中,当您执行逻辑回归时,有一个非常小的分类表可用,R 是否也可能如此?如果是这样,怎么做?

在 SPSS 输出中,当您执行逻辑回归时,有一个非常小的分类表可用,R 是否也可能如此?如果是这样,怎么做?

我不知道具体的命令,但这可能是一个开始:
# generate some data
> N <- 100
> X <- rnorm(N, 175, 7)
> Y <- 0.4*X + 10 + rnorm(N, 0, 3)
# dichotomize Y
> Yfac <- cut(Y, breaks=c(-Inf, median(Y), Inf), labels=c("lo", "hi"))
# logistic regression
> glmFit <- glm(Yfac ~ X, family=binomial(link="logit"))
# predicted probabilities
> Yhat <- fitted(glmFit)
# choose a threshold for dichotomizing according to predicted probability
> thresh <- 0.5
> YhatFac <- cut(Yhat, breaks=c(-Inf, thresh, Inf), labels=c("lo", "hi"))
# contingency table and marginal sums
> cTab <- table(Yfac, YhatFac)
> addmargins(cTab)
YhatFac
Yfac lo hi Sum
lo 36 14 50
hi 12 38 50
Sum 48 52 100
# percentage correct for training data
> sum(diag(cTab)) / sum(cTab)
[1] 0.74
Thomas D. Fletcher 在他的QuantPsyc包中有一个名为ClassLog()(用于“逻辑回归模型的分类分析”)的函数。但是,我喜欢@caracal 的回复,因为它是自制的并且易于定制。