R语言作图集锦

一图一码-图表复刻计划
作者

Shalom

发布日期

2023年5月10日

library(tidyverse)
library(pROC)

ROC

lg_model<-glm(am~ wt + mpg + disp,family ="binomial",data=mtcars)

summary(lg_model)

Call:
glm(formula = am ~ wt + mpg + disp, family = "binomial", data = mtcars)

Deviance Residuals: 
     Min        1Q    Median        3Q       Max  
-2.42280  -0.37989  -0.03867   0.22539   2.03390  

Coefficients:
             Estimate Std. Error z value Pr(>|z|)  
(Intercept) 24.824914  12.346263   2.011   0.0444 *
wt          -6.961380   2.848654  -2.444   0.0145 *
mpg         -0.259377   0.268185  -0.967   0.3335  
disp         0.006593   0.011731   0.562   0.5741  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 43.230  on 31  degrees of freedom
Residual deviance: 16.858  on 28  degrees of freedom
AIC: 24.858

Number of Fisher Scoring iterations: 7
data.frame(confint(lg_model))
data.frame(confint.default(lg_model))
mtcars$pred<-predict(lg_model,mtcars,type = 'response')
rocobj<-roc(mtcars$am,mtcars$pred,percent=F, ci=TRUE, print.auc=TRUE)
df<-data.frame(
  sen=rocobj$sensitivities,
  spe=rocobj$specificities
)
ggplot(df,aes(1-spe,sen))+
  geom_path()+
  theme_bw()