Skip to content
Prev 174342 / 398506 Next

Difference between gam() and loess().

Good try, Kevin.  But that doesn't seem to do it. 

set.seed(123)

x <- sort(runif(100))

y <- sin(4*pi*x) + rnorm(100, sd=0.2)

ans.lo2 <- loess(y ~ x, degree=2, span=0.75)

ans.gam2 <- gam(y ~ lo(x, degree=2, span=0.75))

summary(ans.lo2$fitted - ans.gam2$fitted) # larger differences, about 10%

ans.lo1 <- loess(y ~ x, degree=1, span=0.75)

ans.gam1 <- gam(y ~ lo(x, degree=1, span=0.75))

summary(ans.lo1$fitted - ans.gam1$fitted) # smaller differences, about 2-5 percent

I also tried a number of other things including changing the "family", and parameters in "loess.control", but to no avail.  I looked at the Fortran codes from both loess and gam.  They are daunting, to say the least. They are dense, and there are absolutely no comments whatsoever.  But one thing is clear - they are using different Fortran codes.

So, the best bet might be to get Trevor Hastie or Bill Cleveland to help you out.  

But, before that:  why is this an issue, Rolf?  Is it important that these two results be identical?

Best,
Ravi.



____________________________________________________________________

Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvaradhan at jhmi.edu


----- Original Message -----
From: "Kevin E. Thorpe" <kevin.thorpe at utoronto.ca>
Date: Thursday, March 19, 2009 8:23 pm
Subject: Re: [R] Difference between gam() and loess().
To: Rolf Turner <r.turner at auckland.ac.nz>
Cc: R-help Forum <r-help at r-project.org>