3

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?

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
Alex Holcombe
  • 2,453
  • 4
  • 24
  • 34

1 Answers1

3

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().

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
hadley
  • 102,019
  • 32
  • 183
  • 245
  • 3
    Is there a chance we could see how this is done with plyr? I have the same question, but no idea where to start. Thanks! – Atticus29 Jul 23 '12 at 03:20