[R] model matrix with a spline

David Hugh-Jones hugh-jones at econ.mpg.de
Sat Dec 19 08:22:09 CET 2009


Hi all

I want to get the design matrix for a model, evaluated at a single value.
For example, if I pass in a data frame with a=2, b=2, y=3, and my
model is y ~ a+b+a:b, then I would like to get
the values 3, 2, 2, 4 out. I can do this with:

tmp <- model.matrix(fit, data=mydata)

or

tmp <- predict(fit, newdata=mydata, type="terms")

However, if the fit had a smoothing spline component, this fails. It
seems like the prediction function is trying to reevaluate the basis
for the spline, and as there is only one row in the new data, it can't
do that.

Is there a way I can get the value of the already-created spline? And
is there a simple way to do this programmatically so I don't need to
check each term of the formula individually?

Cheers,

David Hugh-Jones
Post-doctoral Researcher
Max Planck Institute of Economics, Jena
http://davidhughjones.googlepages.com




More information about the R-help mailing list