Strange behaviour of geom_smooth and splines::ns

26 views
Skip to first unread message

Glenn Stone

unread,
Jan 24, 2018, 8:21:08 PM1/24/18
to ggplot2
Can anyone explain to me why the following example produces two different smooths. (This is a simulation based on a rather larger real data set)

The only difference in the geom_smooth is the use of splines::ns versus ns

If using R 3.4.3 on windows and ggplot2 version 2.2.1

require(splines)
require(ggplot2)

set.seed(12345)
dat = data.frame(claim=rbinom(1000,1,0.5))
mns = c(3.4,3.6)
sds = c(0.24, 0.35)
dat$wind = exp(rnorm(nrow(dat), mean=mns[dat$claim+1], sd=sds[dat$claim+1]))
dat = dat[order(dat$wind),]

ggplot(dat, aes(wind,claim))+geom_point()+
  geom_smooth(method = "glm",
              method.args = list(family = binomial), 
              formula = y ~ splines::ns(x, df=5))+
  geom_smooth(method = "glm",
              method.args = list(family = binomial), 
              formula = y ~ ns(x, df=5))

Hadley Wickham

unread,
Jan 25, 2018, 8:59:07 AM1/25/18
to Glenn Stone, ggplot2
I can't.  Can you please file an issue on github? I'm not sure what's going on here.
Hadley

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+unsubscribe@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages