Hello: I sent this question the other day with the wrong subject heading and couple typos, with no response. So, here I go again, having made those corrections. I would like to estimate, for lack of a better description, a partially additive non-parametric model with the following structure: z~ f(x,y):w1 + g(x,y):w2 + e In other words, I'd like to estimate the marginals with respect to w1 and w2 as nonparametric functions of x and y. I'm not positive, but I think I recall being able to estimate a model like this using Splus gam function a couple years ago (I no longer have Splus). Although, I can see that this would be a bit more difficult to do than a standard gam with univariate partials and no interaction terms. The mgcv gam function doesn't seem to like a function of this form. Is there an R package that can estimate a model like this that someone can point me toward? Many thanks Michael J. Roberts Resource Economics Division Production, Management, and Technology USDA-ERS (202) 694-5557 (phone) (202) 694-5775 (fax) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I don't know of a package that will do this easily, sorry! It's on the mgcv "to do" list, but involves a fair bit of work. In principle you can do it yourself by manipulating the design matrix G$X that you'd get by calling G<-gam.setup(z~s(x,y)+s(x,y)) G<-GAMsetup(G) .. you just need to multiply the columns of the design matrix relating to the first smooth by w1 and the columns relating to the second by w2, then gam.fit() can do the rest... the easiest way to do this would be to modify gam() [just after GAMsetup() is called].... but obviously this is a nuisance (and will hopefully not be necessary in mgcv 0.8!)> I would like to estimate, for lack of a better description, > a partially additive non-parametric model with the following > structure: > > z~ f(x,y):w1 + g(x,y):w2 + e > > In other words, I'd like to estimate the marginals with > respect to w1 and w2 as nonparametric functions of > x and y. > > I'm not positive, but I think I recall being able to estimate > a model like this using Splus gam function a couple years > ago (I no longer have Splus). Although, I can > see that this would be a bit more difficult to do than a standard > gam with univariate partials and no interaction terms. The mgcv > gam function doesn't seem to like a function of this form.Simon ______________________________________________________________________> Simon Wood snw at st-and.ac.uk http://www.ruwpa.st-and.ac.uk/simon.html > The Mathematical Institute, North Haugh, St. Andrews, Fife KY16 9SS UK > Direct telephone: (0)1334 463799 Indirect fax: (0)1334 463748-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I don't think I can solve my problem in this way because w1 and w2 are continuous variables. A second problem is that my f(x,y) is not f(x, df), i.e., I'd like to have a sum of *two* dimensional smoothers interacted with other variables. After my first post I did find a discussion of this problem on the S archive, which suggested the same appraoch as Vito did. S can fit 2-d smooths, but still can't handle the interaction terms. If nothing else is out there I thought I might try the following. (Please let me know if this is a crazy thing to do). It seems to me that I can fit this model by backfitting each smoother, being careful to re-weight each smooth fit according to the interaction term. So estimate ( z - ghat(x,y):w2 )/w1 ~ f(x,y) + e/w1 to get fhat(x,y), then similarly estimate ghat, then fhat, and so on until convergence. The idea was to use smoothers already out there (such as loess in modreg). In principle this doesn't seem like a big job to me. If it is, please let me know, because I'm not a heavy programmer either. And really prefer not to "reinvent the wheel." Thanks for your help! Mike Michael J. Roberts Resource Economics Division Production, Management, and Technology USDA-ERS (202) 694-5557 (phone) (202) 694-5775 (fax)>>> Simon Wood <snw at mcs.st-and.ac.uk> 01/29/02 04:39AM >>> > > > I would like to estimate, for lack of a better description, > > > a partially additive non-parametric model with the following > > > structure: > > > > > > z~ f(x,y):w1 + g(x,y):w2 + e > > > > > > In other words, I'd like to estimate the marginals with > > > respect to w1 and w2 as nonparametric functions of > > > x and y. > > This model should be a "univariate version" to fit interactionbetween a> variate, x and a factor w, say: > z~ f(x, df1):w1 + g(x, df2):w2 + e > To fit this model a possible solution is > > 1)build the variate x in each level of w > xw1<-x*w1 > xw2<-x*w2 > > 2)then fit gam, by: > z~ w1+w2-1+f(xw1, df1)+ g(xw2, df2) > > I am not able to find any theoretical difficulty in this model and > furthermore it seems to work with gam().- This often seems to work quite well, but the problem is that f(0) and g(0) are not equal to zero - so it doesn't do exactly what you would like *and* all those zero covariate values will influence the smoothing parameter selection. [Of course if the model of interest is really this simple then one way to proceed is just to split the dataset up by levels of the single factor and fit smooths to the data for each level]. cheers, Simon -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I probably missed the original problem, but did you try gss? -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I probably missed the posting with the original problem, but are you aware of gss? -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>> Simon Wood <snw at mcs.st-and.ac.uk> 01/30/02 04:28AM >>> > Wouldn't an "interaction" > between a smooth function f(x,y) and a continuous covariate w beanother> smooth function g(x,y,w), say? But in this case: > y~g(x,y,w1)+f(x,y,w2)+e > won't generally be identifiable, without imposing extra structure onthe> model [for example g1(x,y)+g2(w1) is a valid g(x,y,w1), while > f1(x,y)+f2(w2) is a valid f(x,y,w2) - clearly there's anidentifiability> problem with f1 and g1!].- Sorry, this was wrong (Chong Gu is right). The model is identifiable subject only to side conditions on the basis of completely smooth components of f and g - identifiability of the non-smooth components seems to come about because the solution of the smoothing problem involving f(x,y,w) simply cannot have the form f1(x,y)+f2(w). Unfortunately mgcv doesn't impose the necessary side conditions, so you can't use it to estimate y~g(x,y,w1)+f(x,y,w2)+e [...yet] cheers, Simon .... Sorry to drag this out further. This has been a great help. Although I thought that ssanova in gss would solve my problem, now I do not think so. I do not want to estimate y~g(x,y,w1) + f(x,y,w2) + e This would be too expensive besides. I would like to estimate y~g(x,y)*w1 + f(x,y)*w2 + e without any of the expansion terms. w1 and w2 are continuous. I don't see how to specify such a functional form in ssanova This is much more restrictive than the form above and cheap enough to do on my computer (I think). It is also makes good sense for my problem. Right now I see four potential routes: 1) try to augment Simon's mgcv (rework the design matrix) 2) try to augment Chong Gu's (at this point I have no idea if this is doable) 3) try backfitting the smooth terms in conjunction with ssanova or another smooth regression technique. 4) try a "crude" approximation by descretizing w1 and w2 into factor levels and use the technique first suggested by Vito. Any suggestions on the most promissing route would be greatly appreciated. (one of these or something else?) Many thanks, Michael Michael J. Roberts Resource Economics Division Production, Management, and Technology USDA-ERS (202) 694-5557 (phone) (202) 694-5775 (fax) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
You could look at this as a "varying coefficient regression model" of the type econometricians have been interested in. Perhaps a spatial (because you have bivariate coefficient functions) Kalman filter approach could be adapted. I don't know if the spatial R packages do this. Perhaps GeoR? Another possibility is to use a series expansion for the functional coefficients, e.g., tensor product wavelets, or radial basis functions (mixture of Gaussian densities). This would reduce to linear least squares plus choice of regularization/smoothing parameter (eg via CV). Reid Huntsinger -----Original Message----- From: Michael Roberts [mailto:mroberts at ers.usda.gov] Sent: Wednesday, January 30, 2002 10:50 AM To: r-help at stat.math.ethz.ch Subject: Re: [R] Almost a GAM?>>> Simon Wood <snw at mcs.st-and.ac.uk> 01/30/02 04:28AM >>> > Wouldn't an "interaction" > between a smooth function f(x,y) and a continuous covariate w beanother> smooth function g(x,y,w), say? But in this case: > y~g(x,y,w1)+f(x,y,w2)+e > won't generally be identifiable, without imposing extra structure onthe> model [for example g1(x,y)+g2(w1) is a valid g(x,y,w1), while > f1(x,y)+f2(w2) is a valid f(x,y,w2) - clearly there's anidentifiability> problem with f1 and g1!].- Sorry, this was wrong (Chong Gu is right). The model is identifiable subject only to side conditions on the basis of completely smooth components of f and g - identifiability of the non-smooth components seems to come about because the solution of the smoothing problem involving f(x,y,w) simply cannot have the form f1(x,y)+f2(w). Unfortunately mgcv doesn't impose the necessary side conditions, so you can't use it to estimate y~g(x,y,w1)+f(x,y,w2)+e [...yet] cheers, Simon .... Sorry to drag this out further. This has been a great help. Although I thought that ssanova in gss would solve my problem, now I do not think so. I do not want to estimate y~g(x,y,w1) + f(x,y,w2) + e This would be too expensive besides. I would like to estimate y~g(x,y)*w1 + f(x,y)*w2 + e without any of the expansion terms. w1 and w2 are continuous. I don't see how to specify such a functional form in ssanova This is much more restrictive than the form above and cheap enough to do on my computer (I think). It is also makes good sense for my problem. Right now I see four potential routes: 1) try to augment Simon's mgcv (rework the design matrix) 2) try to augment Chong Gu's (at this point I have no idea if this is doable) 3) try backfitting the smooth terms in conjunction with ssanova or another smooth regression technique. 4) try a "crude" approximation by descretizing w1 and w2 into factor levels and use the technique first suggested by Vito. Any suggestions on the most promissing route would be greatly appreciated. (one of these or something else?) Many thanks, Michael Michael J. Roberts Resource Economics Division Production, Management, and Technology USDA-ERS (202) 694-5557 (phone) (202) 694-5775 (fax) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._