[R] Loess fit

Liaw, Andy andy_liaw at merck.com
Mon May 17 15:38:30 CEST 2010


I'm just guessing (since as David pointed out, no reproducible example
were given), but this perhaps could be the problem:

R> x <- 1:10
R> y <- rnorm(x)
R> fm <- loess(y ~ x)
R> predict(fm, data.frame(x=5:15))
 [1]  0.1830450  0.2145826 -0.2158466 -0.3051978 -0.2635318 -0.1013985
 [7]         NA         NA         NA         NA         NA

Andy 

From: David Winsemius
> 
> On May 17, 2010, at 4:47 AM, Chintanu wrote:
> 
> > Hi,
> >
> > I wonder why my attempt to extend an existing loess fit to 
> a new data 
> > set is producing error. I was trying the following:
> >
> > dat = read.csv(choose.files())
> > x = dat[,2]; y = dat[,1]
> > x.sort = sort(x)
> 
> That is not needed, furthermore, you don't even use it.
> 
> > y.loess = loess(y~x, span=0.75)
> >
> > # For testing the above fit with a new dataset:
> >
> > test = read.csv(choose.files()) # test data new_x = test 
> [,1]; new_y = 
> > test[,2] new_x.sort = sort(new_x)
> 
> That sort is not needed.
> 
> > predicted <- predict(y.loess, newdata=new_x.sort)
> >
> > Am I doing any mistake ? Please correct me.
> 
> How can we tell when the inputs to these functions are not offered?
> 
> 
> >
> > I could see that though the rest of the values of "predicted" looks 
> > alright, however the first output of it is an NA !!
> 
> Perhaps outside the range of the loess function that was generated?
> 
> dat = matrix(rnorm(100), ncol=2); x = dat[,2]; y = dat[,1] 
> predicted <- predict(y.loess, newdata=x<-1:10 ) predicted
> # [1] 0.1022490 0.2574732        NA        NA        NA         
> NA        NA        NA
> # [9]        NA        NA
> 
> 
> >
> > Many thanks,
> >
> > Chintanu
> -- 
> 
> David Winsemius, MD
> West Hartford, CT
> 
> ______________________________________________
> R-help at r-project.org 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.
> 
Notice:  This e-mail message, together with any attachme...{{dropped:11}}



More information about the R-help mailing list