【发布时间】:2020-11-10 06:51:26
【问题描述】:
作为独立研究项目的一部分,我正在使用 R 中的随机森林模型。我已经拟合了我的随机森林模型,并生成了每个预测变量对模型准确性的总体重要性。但是,为了在研究论文中解释我的结果,我需要了解变量对响应变量有正面影响还是负面影响。
有没有办法从随机森林模型中生成这些信息? IE。我希望age 对发生手术并发症的可能性产生积极影响,但对骨关节炎的存在影响不大。
代码:
surgery.bagComp = randomForest(complication~ahrq_ccs+age+asa_status+bmi+baseline_cancer+baseline_cvd+baseline_dementia+baseline_diabetes+baseline_digestive+baseline_osteoart+baseline_psych+baseline_pulmonary,data=surgery,mtry=2,importance=T,cutoff=c(0.90,0.10)) #The cutoff is the probability for each group selection, probs of 10% or higher are classified as 'Complication' occurring
surgery.bagComp #Get stats for random forest model
imp=as.data.frame(importance(surgery.bagComp)) #Analyze the importance of each variable in the model
imp = cbind(vars=rownames(imp), imp)
imp = imp[order(imp$MeanDecreaseAccuracy),]
imp$vars = factor(imp$vars, levels=imp$vars)
dotchart(imp$MeanDecreaseAccuracy, imp$vars,
xlim=c(0,max(imp$MeanDecreaseAccuracy)), pch=16,xlab = "Mean Decrease Accuracy",main = "Complications - Variable Importance Plot",color="black")
任何人都可以提出任何建议/研究领域将不胜感激。
【问题讨论】:
-
您已经绘制了变量重要性,这将向您展示变量的重要性。它不会告诉您该变量将以何种方式影响响应变量。相反,您想要的是部分依赖图。您还应该清楚这是分类问题还是回归问题。
标签: r random-forest