Are the values counts (= positive integers)? In that case a poisson regression is more suitable as smoother. E.g. geom_smooth(method = 'glm', family = 'poisson')
set.seed(12345)
library(ggplot2)
library(mgcv)
Dataset <- data.frame(A = seq(-10, 10, length = 1001))
Dataset$B <- rpois(nrow(Dataset), exp(2 + 0.1 * Dataset$A - 0.1 * Dataset$A ^ 2))
ggplot(Dataset, aes(x = A, y = B)) + geom_point() + geom_smooth()
ggplot(Dataset, aes(x = A, y = B)) + geom_point() + geom_smooth(method = "glm", family = "poisson")
ggplot(Dataset, aes(x = A, y = B)) + geom_point() + geom_smooth(method = "glm", family = "poisson", formula = y ~ poly(x, 2))
ggplot(Dataset, aes(x = A, y = B)) + geom_point() + geom_smooth(method = "gam", family = "poisson")
ggplot(Dataset, aes(x = A, y = B)) + geom_point() + geom_smooth(method = "gam", family = "poisson", formula = y ~ s(x))
ggplot(Dataset, aes(x = A, y = B)) + geom_smooth(method = "gam", family = "poisson", formula = y ~ s(x)) + coord_cartesian(ylim = (c(-0.1, 1))) #note that even the confidence intervals are non-negative
Best regards,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
Thierry....@inbo.be
www.inbo.be
To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
-----Oorspronkelijk bericht-----
Van:
ggp...@googlegroups.com [mailto:
ggp...@googlegroups.com] Namens Henri-Paul Indiogine
Verzonden: woensdag 17 oktober 2012 19:31
Aan:
ggp...@googlegroups.com
Onderwerp: geom_smooth()
* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document.
The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.