[R] Multivariate spline regression and predicted values
Max Farrell
maxhf at umich.edu
Tue Sep 20 16:11:23 CEST 2011
Hello,
I am trying to estimate a multivariate regression of Y on X with
regression splines. Y is (nx1), and X is (nxd), with d>1. I assume the
data is generated by some unknown regression function f(X), as in Y =
f(X) + u, where u is some well-behaved regression error. I want to
estimate f(X) via regression splines (tensor product splines). Then, I
want to get the predicted values for some new points W.
To be concrete, here is an example of what I want:
#dimensions of the model
d=2
n=1000
#some random data
X <- matrix(runif(d*n,-2,2),n,d)
U <- rnorm(n)
Y <- X[,1] + X[,2] + U
# a new point for prediction
W <- matrix(rep(0),1,d)
Now if I wanted to use local polynomials instead of splines, I could
load the 'locfit' package and run (something like):
lp.results <- smooth.lf(X,Y,kern="epan",kt="prod",deg=1,alpha=c(0,0.25,0),xev=W,direct=TRUE)$y
Or, if X was univariate (ie d=1), I could use (something like):
spl.results <- predict(smooth.spline(X,Y, nknots=6),W)
But smooth.spline only works for univariate data. I looked at the
"crs" package, and it at least will fit the multivariate spline, but I
don't see how to predict the new data from this. That is, I run a
command like:
spl.fit <- crs(Y~X[,1] + X[,2],basis="tensor",
degree=c(3,3),segments=c(4,4),degree.min=3,degree.max=3, kernel=FALSE,
cv="none",knots="uniform",prune=FALSE)
Then what?
What I really want is the spline version of the smooth.lf command
above, or the multivariate version of smooth.spline. Any ideas/help?
Thanks,
Max
More information about the R-help
mailing list