我已经构建了一个二项式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)
任何有助于澄清这些预测概率含义的帮助都会受到赞赏。