?interp in akima for f: R^2 -> R.
url: www.econ.uiuc.edu/~roger Roger Koenker email [EMAIL PROTECTED] Department of Economics vox: 217-333-4558 University of Illinois fax: 217-244-6678 Champaign, IL 61820
On Oct 14, 2004, at 8:09 PM, Vadim Ogranovich wrote:
Hi,
I am looking for a function that generalizes 'approx' to two (or more)
dimensions. The references on the approx help page point toward splines,
but a) splines is what I am trying to avoid in the first place and b)
splines (except for mgcv splines) seem to be one dimensional.
Here is a more detailed account. Using mgcv:gam I fit an additive model
xy.gam according to the formula y ~ s(x), which is a spline under the
hood. If I now wish to compute model prediction for new data I could use
predict.gam(xy.gam, newdata). However newdata will first be expanded
into a large matrix of coefficients with respect to the spline basis
functions. For example if the length of newdata is 1e6 and the size of
the basis is 100 than the matrix of coefficients is 100*1e6, i.e. huge.
The predict.gam recognizes the problem and works around it by doing a
piece-meal prediction, but this turns out to be too slow for my needs.
One way around is to tabulate s(x) on a fine enough grid and use approx for prediction. Something like this (pseudo-code)
x.grid <- seq(min(newdata), max(newdata), length=1000) y.grid <- predict.gam(xy.gam, x.grid)
y.newdata <- approx(x.grid, y.grid, newdata)$y
I didn't test this, but I expect it to be dramatically faster than predict.gam.
Unfortunately I don't know how to extend it into 2D. Your suggestions are very welcome!
Thanks, Vadim
[[alternative HTML version deleted]]
______________________________________________
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
______________________________________________ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
