[R] Plotting a smooth curve from predict
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Jul 31 13:21:45 CEST 2007
You are using fitted() implicitly here, so you are not plotting a smooth
curve but a set of fitted values.
You need to really predict at a suitable range of data points, e.g.
xx <- seq(1, 10, len=500)
plot(xx, predict(w, list(x=xx)), type="l")
BTW, why are you not using poly()?
On Tue, 31 Jul 2007, Wilson, Andrew wrote:
> Probably a very simple query:
> When I try to plot a curve from a fitted polynomial, it comes out rather
> jagged, not smooth like fitted curves in other stats software. Is there
> a way of getting a smooth curve in R?
> What I'm doing at the moment (for the sake of example) is:
>> x <- c(1,2,3,4,5,6,7,8,9,10)
>> y <- c(10,9,8,7,6,6.5,7,8,9,10)
>> b <- data.frame(cbind(x,y))
>> w <- gls(y ~ I(x)+I(x^2),correlation=corARMA(p=1),method="ML",data=b)
> Many thanks,
> Andrew Wilson
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help