【R言語】ロジスティック回帰モデルをggplotでグラフ化する
ロジスティック回帰モデルをggplotでグラフ化
オライリーのggplot2解説書「Rグラフィックスクックブック」では
ggplotのバージョンが古くて、書籍と同じグラフが書けなかった。
早く更新されることを願う。
#ロジスティック回帰モデルのグラフを書く library(MASS) library(tidyverse) b<-biopsy str(b) #claaを0,1に変換する b$classn[b$class=="benign"]<-0 b$classn[b$class=="malignant"]<-1 #method.argsじゃないと動かない stat_smooth %>% str() args(glm) %>% as.list() %>% names() #gp + geom_smooth(method=glm, method.args=list(family=poisson), se=FALSE) # methodで指定した関数に渡す引数を、method.argsでリストジェクト形式で指定する。 ggplot(b,aes(x=V1,y=classn))+ geom_point(position=position_jitter(width=0.3,height = .06),alpha=0.5,shape=21,size=1.5)+ geom_smooth(method="glm",method.args=list(family="binomial"))