Hi - How can I 'manually' reproduce the results in 'pred1' below? My attempt
is pred_manual, but is not correct. Any help is much appreciated.

library(splines)
set.seed(12345)
y <- rgamma(1000, shape =0.5)
age <- rnorm(1000, 45, 10)
glm1 <- glm(y ~ ns(age, 4), family=Gamma(link=log))
dd <- data.frame(age = 16:80)
mm <- model.matrix( ~ ns(dd$age, 4))
pred1 <- predict(glm1, dd, type = "response")
pred_manual <- exp(coefficients(glm1)[1] * mm[,1] +
                   coefficients(glm1)[2] * mm[,2] +
                   coefficients(glm1)[3] * mm[,3] +
                   coefficients(glm1)[4] * mm[,4] +
                   coefficients(glm1)[5] * mm[,5])

Regards,
Axel.

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to