Can one extract model fit parameters after a ggplot stat_smooth call?

北城余情 提交于 2020-01-11 06:33:10

问题


Using stat_smooth, I can fit models to data. E.g.

g=ggplot(tips,aes(x=tip,y=as.numeric(unclass(factor(tips$sex))-1))) +facet_grid(time~.) 
g=g+ stat_summary(fun.y=mean,geom="point") 
g=g+ stat_smooth(method="glm", family="binomial")

I would like to know the coefficients of the glm binomial fits. I could re-do the fit with dlply and get the coefficients with ldply, but I'd like to avoid such duplication.

Calling str(g) reveals the hierarchy of objects that ggplot2 creates, perhaps there's some way to get to the coefficients through that?


回答1:


No, because the models are only created when the plot is rendered. However, it's usually pretty easy to do it yourself with plyr.

Why do you want to convert sex to a number? Using as.numeric should be enough by itself, but if you're going to do the subtraction in the model you'll need to surround it with I().



来源:https://stackoverflow.com/questions/2666805/can-one-extract-model-fit-parameters-after-a-ggplot-stat-smooth-call

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!