Another approach would be to use the "weights" argument. So, for example, you can use a weight of 100 for the point (0,0), and weights of 1 for the rest of the data.
However, I would be wary of this, as I am not sure why you want to do this. Here is an example: set.seed(123) x <- sort(runif(100)) y <- 1.2 * x^2 - 0.5 * x + rnorm(100, sd=0.1) y.new <- c(0, y) x.new <- c(0, x) obj <- loess(y ~ x, span=0.3) plot(x, y) lines(x, predict(obj), col=2, lty=2) obj.new <- loess(y.new ~ x.new, span=0.3, weights=c(100, rep(1, 100))) lines(x.new, predict(obj.new), col=4, lty=3) Note that the constraint does "significantly" alter the loess smooth close to the origin, as it should. Ravi. ---------------------------------------------------------------------------- ------- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvarad...@jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html ---------------------------------------------------------------------------- -------- -----Original Message----- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Stavros Macrakis Sent: Tuesday, April 14, 2009 2:15 PM To: jimm-pa...@gmx.de Cc: r-help@r-project.org Subject: Re: [R] Forcing the extrapolation of loess through the origin On Tue, Apr 14, 2009 at 1:08 PM, <jimm-pa...@gmx.de> wrote: > I'm fitting a line to my dataset. Later I want to predict missing values that exceed the [min,max] interval of my empirical data, therefore I choose surface="direct" for extrapolation. > > l1<-loess(y1~x1,span=0.1,data.frame(x=x1,y=y1),control=loess.control(s > urface="direct")) > > In my application it is highly important that the fitted line intercepts at the point of origin. Is it possible to do this in R? Well, you could always add lots of artificial data points x=0, y=0 ..., like this: l1<-loess(y1~x1,span=0.1,data.frame(x=c(rep(0,100),x1),y=c(rep(0,100),y1)),c ontrol=loess.control(surface="direct")) which will eventually drive f(0) to near 0, but surely that will create fitting artifacts. -s ______________________________________________ R-help@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. ______________________________________________ R-help@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.