I have estimated a multiple nonparametric regression using the loess command in R. I have also estimated an additive version of the model using the gam function. Is there a way of using the output of these two models to test the restrictions imposed by the additive model?
You can use the LRT (although I think that it assumes the df to be fixed). For instance the package mgcv by Simon Wood has an anova method to compare models fitted by the relevant gam() function, and the print.summary() itself returns such information.. best, vito set.seed(123) n<-100 sig<-2 x0 <- runif(n, 0, 1) x1 <- runif(n, 0, 1) y <- sin(2*pi*x0) + .5*x1 +sig*rnorm(n) library(mgcv) obj<-gam(y~s(x0)+s(x1)) obj1<-gam(y~s(x0)+x1) anova(obj1,obj,test="F") #also see the "Approximate significance of smooth terms" summary(obj) Donal O'Neill wrote:> I have estimated a multiple nonparametric regression using the loess > command in R. I have also estimated an additive version of the model using > the gam function. Is there a way of using the output of these two models to > test the restrictions imposed by the additive model? > > ______________________________________________ > 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. > >-- ===================================Vito M.R. Muggeo Dip.to Sc Statist e Matem `Vianelli' Universit? di Palermo viale delle Scienze, edificio 13 90128 Palermo - ITALY tel: 091 6626240 fax: 091 485726/485612
Dear Vito, Thank you for your prompt reply. Perhaps I am missing something but as I understand it the procedure you suggest would allow me to test for nonlinearities in one of the control variables. However my objective is to nonparametrically test whether the nature of the nonlinearity in one variable is constant across all values of a second conditioning variable. That is I want to test y=f(x1,x2)+e against y=f1(x1)+f2(x2) + u I tried library(mgcv) mod.1<-gam(y~s(x1)+s(x2)) mod.2<-loess(y~x1+x2, f=**, iter=**), lwd=**) anova(mod.1, mod.2) but got the following error message Error in s^2 : non-numeric argument to binary operator Any suggestions would be welcome. Donal. At 11:43 03/04/2007 +0200, vito muggeo wrote: You can use the LRT (although I think that it assumes the df to be fixed). For instance the package mgcv by Simon Wood has an anova method to compare models fitted by the relevant gam() function, and the print.summary() itself returns such information.. best, vito set.seed(123) n<-100 sig<-2 x0 <- runif(n, 0, 1) x1 <- runif(n, 0, 1) y <- sin(2*pi*x0) + .5*x1 +sig*rnorm(n) library(mgcv) obj<-gam(y~s(x0)+s(x1)) obj1<-gam(y~s(x0)+x1) anova(obj1,obj,test="F") #also see the "Approximate significance of smooth terms" summary(obj) Donal O'Neill wrote: I have estimated a multiple nonparametric regression using the loess command in R. I have also estimated an additive version of the model using the gam function. Is there a way of using the output of these two models to test the restrictions imposed by the additive model? ______________________________________________ R-help at stat.math.ethz.ch mailing list [1]https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide [2]http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- =================================== Vito M.R. Muggeo Dip.to Sc Statist e Matem `Vianelli' Universit? di Palermo viale delle Scienze, edificio 13 90128 Palermo - ITALY tel: 091 6626240 fax: 091 485726/485612 =================================== References 1. https://stat.ethz.ch/mailman/listinfo/r-help 2. http://www.r-project.org/posting-guide.html
I'd use mgcv::gam to fit a 2D smooth, rather than loess, and then do an *approximate* likelihood ratio/ F test. For example.... library(mgcv) ## fake some data.... set.seed(0) n<-400;sig2<-4 x0 <- runif(n, 0, 1);x2 <- runif(n, 0, 1) f <- 2 * sin(pi * x0) f <- f + 0.2 * x2^11 * (10 * (1 - x2))^6 + 10 * (10 * x2)^3 * (1 - x2)^10 e <- rnorm(n, 0, sqrt(abs(sig2))) y <- f + e ## now fit models and compare... b0 <- gam(y~s(x0)+s(x2)) ### fit additive model b1 <- gam(y~te(x0,x2,k=10)) ### fit interaction model anova(b0,b1,test="F") The above uses a scale invariant tensor product smooth as the bivariate smooth. To get something more like loess, you could rescale your predictors into the unit square, say, and then use something like `y~s(x0,x2,k=100)' but in that case you sacrifice proper nesting of the models. There's more information in e.g. section 5.2 of my book (see ?gam for ref.) Another alternative would be to use Chong Gu's `gss' package which is set up to do `smoothing spline anova' modelling: this is quite a natural way to address your problem.... best, Simon On Tuesday 03 April 2007 09:36, Donal O'Neill wrote:> I have estimated a multiple nonparametric regression using the loess > command in R. I have also estimated an additive version of the model using > the gam function. Is there a way of using the output of these two models to > test the restrictions imposed by the additive model? > > ______________________________________________ > 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.--> Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK > +44 1225 386603 www.maths.bath.ac.uk/~sw283