I have the coefficients from a glm fitted in R, and I want to predict expected values for a new set of data. If I had the model object this would be simple, using predict(). However, I am now offsite and for data confidentiality reasons I no longer have the model object. I have only the summary object, generated using summary(model), which contains the model coefficients.
It's easy enough to use the coefficients to predict expected values for a simple model. However, I would like to know how to do this when the model includes a cubic spline ns(). Any shortcuts for when the model also includes categorical variables would be appreciated as well.
Here is a simple example.
library(splines)
dat <- data.frame(x=1:500, z=runif(500), k=as.factor(sample(c("a","b"), size=500, replace=TRUE)))
kvals <- data.frame(kn=c("a","b"),kv=c(20,30))
dat$y = dat$x + (40*dat$z)^2 + kvals$kv[match(dat$k,kvals$kn)] + rnorm(500,0,30)
# Fit model
library(splines)
mod <- glm(y ~ x + ns(z,df=2) + k,data=dat)
# Create new dataset
dat.new <- expand.grid(x=1:3,z=seq(0.2,0.4,0.1),k="b")
# Predict expected values in the usual way
predict(mod,newdata=dat.new)
summ <- summary(mod)
rm(mod)
# Now, how do I predict using just the summary object and dat.new?