[R] model matrix with a spline
David Winsemius
dwinsemius at comcast.net
Sat Dec 19 14:28:29 CET 2009
On Dec 19, 2009, at 2:22 AM, David Hugh-Jones wrote:
> 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?
Probably.
But you have not given any details about your modeling functions, so
"probably" is about all that can be said. Parametric splines would
have a greater likelihood of having a compact representation which is
what you are probably seeking. Harrell's packages are the ones I have
the most experience with and his Function function gives a very quick
answer.
--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list