【问题标题】:Calculating confusion matrix for fixed effect logit计算固定效应 logit 的混淆矩阵
【发布时间】:2020-05-17 12:48:27
【问题描述】:

想问一下固定效应logit模型如何计算混淆矩阵(bife包)

使用基本的logit模型(glm)没有问题,但使用固定效应logit有问题。

由于某种原因,logit 和固定效应 logit 的预测数量不同。

例子:

library(bife)
library(tidyverse)
library(caret)

dataset <- psid

logit <- glm(LFP ~ AGE + I(AGE^2) + log(INCH) + KID1 + KID2 + KID3, data = dataset, family = "binomial")
mod <- bife(LFP ~AGE +  I(AGE^2) + log(INCH) + KID1 + KID2 + KID3| ID, dataset)

summary(mod)
summary(logit)

predict(logit)
predict(mod)

Y <- factor(dataset$LFP)
PRE <- factor(round(predict(logit, type = "response")))
PRE_FIX <- factor(round(predict(mod, type = "response")))

confusionMatrix(Y, PRE)

# Not working
confusionMatrix(Y, PRE_FIX)

【问题讨论】:

  • bife 的帮助页面上说它“放弃了对横截面单位(个体)的所有观察,但响应不变。”

标签: r statistics logistic-regression confusion-matrix


【解决方案1】:

可以计算confusionMatrix:

confusionMatrix<-table(true=Y , pred = round(fitted(PRE_FIX)))

然后,将混淆矩阵转换为表格形状。

  0             1
0 TruePositive  FalseNegative
1 FalsePositive TrueNegative

【讨论】:

  • 你应该解释一下代码是如何工作的,即使只是简短的。没有解释的代码帖子不受欢迎:)
猜你喜欢
  • 2018-04-01
  • 2017-02-25
  • 2020-04-26
  • 2020-07-09
  • 2018-11-09
  • 1970-01-01
  • 2020-03-23
  • 2022-06-15
相关资源
最近更新 更多