GLM回归预测-了解哪个因素水平是成功的

3

我已经构建了一个二项式glm模型。该模型预测两个可能类别(AD或控制)之间的输出。这些变量是具有水平的因子:{AD,控制}。我使用该模型来预测并获取每个样本的概率,但我不确定大于0.5的概率表示AD还是控制。

以下是我的数据集:

> 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)

任何有助于澄清这些预测概率含义的帮助都会受到赞赏。
1个回答

5

?glm我们可以得知:

详情:

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

重点部分已经突出显示。 假设您没有指定级别(即R的默认赋值已经发生),则AD将是失败,Control将是成功。 因此,系数/模型将是关于观察是否在Control类中的概率。

如果要更改此设置,请使用factor(...., levels = c('Control', 'AD'))或仅使用1- prob(Control)(1-预测值)以获得关于AD的结果。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接