[R] Plotting a smooth curve from predict

Chuck Cleland ccleland at optonline.net
Tue Jul 31 13:15:16 CEST 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)
> 
>> plot(predict(w),type="l")

  Make predictions for more than 10 values of x:

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))

library(nlme)

w <- gls(y ~ I(x)+I(x^2), correlation=corARMA(p=1), method="ML", data=b)

plot(seq(1,10,len=100),
     predict(w, data.frame(x = seq(1,10, len=100))),
     xlab="x", ylab="Predicted y",
     type="l")

> Many thanks,
> 
> Andrew Wilson
> 
> ______________________________________________
> R-help at 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. 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894



More information about the R-help mailing list