data("kyphosis", package="rpart")
kyphosis$y = as.numeric(kyphosis$Kyphosis)-1
ggplot(
data = kyphosis
, mapping = aes(
x = Age
, y = y
)
)+
layer(
stat = 'smooth'
, stat_params = list(
method="glm"
, family="binomial"
)
)+
coord_trans(y='logit')
--
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University
Looking to arrange a meeting? Check my public calendar:
http://tr.im/mikes_public_calendar
~ Certainty is folly... I think. ~
This helps to show the problem:
kyphosis$y = as.numeric(kyphosis$Kyphosis)-1
ggplot(kyphosis, aes(Age, y)) +
geom_point() +
stat_smooth(method = "glm", family = "binomial")
There are data points at 0 and 1, which become -Inf and Inf under the
logistic transformation.
Hadley
Correct.
> In that case the smoothed values that I'm
> actually plotting do not contain 1 or 0.
Also correct.
> Furthermore, I should be
> able to grab the result of the smooth and plot just that (..y.. it
> seems from the documentation).
Unfortunately it's not that simple. This is pretty subtle and took me
a while to get right, but the scales have to be trained with the raw
data as well as the output of the statistics - this is what enables
(among other things) fullrange = T to work for stat_smooth.
Hadley
It's not hard to calculate the ribbon yourself - see geom_ribbon for
how to plot it.
Hadley
I don't understand what y you are talking about. Could you please
supply a reproducible example?
Hadley
It's a little complicated - y is both an input to and an output from