[R] Plotting a smooth curve from predict

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Tue Jul 31 13:37:49 CEST 2007


What you need is

b <- data.frame(x = 1:10, y = c(10,9,8,7,6,6.5,7,8,9,10))
w <- gls(y ~ I(x)+I(x^2),correlation=corARMA(p=1),method="ML",data=b)
Newdata <- data.frame(x = seq(1, 10, length = 41))
plot(predict(w, newdata = Newdata), type="l")

------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be
www.inbo.be 

Do not put your faith in what statistics say until you have carefully
considered what they do not say.  ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney

 

> -----Oorspronkelijk bericht-----
> Van: r-help-bounces op stat.math.ethz.ch 
> [mailto:r-help-bounces op stat.math.ethz.ch] Namens Wilson, Andrew
> Verzonden: dinsdag 31 juli 2007 12:22
> Aan: r-help op stat.math.ethz.ch
> Onderwerp: [R] Plotting a smooth curve from predict
> 
> 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)
> 
> > plot(predict(w),type="l")
> 
> Many thanks,
> 
> Andrew Wilson
> 
> ______________________________________________
> R-help op stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list