【问题标题】:GLM regression prediction- understanding which factor level is successGLM回归预测——了解哪个因素水平是成功的
【发布时间】:2017-12-06 17:09:59
【问题描述】:

我已经建立了一个二项式 glm 模型。该模型预测两个潜在类别之间的输出:AD 或 Control。这些变量是具有水平的因子:{AD, Control}。我使用这个模型来预测并获得每个样本的概率,但我不清楚超过 0.5 的概率是表示 AD 还是 Control。

这是我的数据集:

> head(example)
          cleaned_mayo$Diagnosis pca_results$x[, 1]
1052_TCX                      AD          0.9613241
1104_TCX                      AD         -0.9327390
742_TCX                       AD          1.6908874
1945_TCX                 Control          0.6819104
134_TCX                       AD          0.5184748
11386_TCX                Control          0.4669661

这是我计算模型和进行预测的代码:

# Randomize rows of top performer
example<- example[sample(nrow(example)),]

# Subset data for training and testing
N_train<- round(nrow(example)*0.75)
train<- example[1:N_train,]
test<- example[(N_train+1):nrow(example),]
colnames(train)[1:2]<- c("Diagnosis", "Eigen_gene")
colnames(test)[1:2]<- c("Diagnosis", "Eigen_gene")

# Build model and predict   
model_IFGyel<- glm(Diagnosis ~ Eigen_gene, data = train, family = binomial())
pred<- predict(model_IFGyel, newdata= test, type= "response")

# Convert predictions to accuracy metric
pred[which(pred<0.5)]<- "AD"
pred[which(pred!="AD")]<- "Control"
test$Diagnosis<- as.character(test$Diagnosis)
example_acc<- sum(test$Diagnosis==pred, na.rm = T)/nrow(test)

感谢任何帮助澄清这些预测概率所指示的内容。

【问题讨论】:

    标签: r regression prediction glm


    【解决方案1】:

    来自?glm 我们注意到:

    详情:

    一个典型的预测器具有“响应~术语”的形式,其中 “response”是(数字)响应向量,“terms”是 一系列术语,指定“响应”的线性预测器。 对于“二项式”和“准二项式”族,响应也可以 被指定为“因素”(当第一级表示失败时 和所有其他成功)或作为具有列的两列矩阵 给出成功和失败的次数。

    关键部分被突出显示。假设您没有指定级别(即发生 R 的默认分配),那么 AD 将失败,Control 将成功。因此,系数/模型将根据观察属于Control 类的概率。

    如果要更改此设置,请使用 factor(...., levels = c('Control', 'AD')) 或仅执行 1 - prob(Control)(1 - 预测值)以根据 AD 获取它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-21
      • 1970-01-01
      • 2019-08-25
      • 1970-01-01
      相关资源
      最近更新 更多