Thank you ver much. Is there is a function in R which is doing penalized cubic regression, say spl.plr(), that if I have weeks = 1:9 I can use somthing like pp <- spl.plr(weeks,c(1,3,5,7)) and for 8 and 9 will be linear? Is rcs() library(Design) doing this?
Many thanks, Samuel --- On Tue, 22/6/10, Joris Meys <jorism...@gmail.com> wrote: From: Joris Meys <jorism...@gmail.com> Subject: Re: [R] glm To: "Samuel Okoye" <samu...@yahoo.com> Cc: r-help@r-project.org Date: Tuesday, 22 June, 2010, 9:50 On Tue, Jun 22, 2010 at 1:00 AM, Samuel Okoye <samu...@yahoo.com> wrote: > Hi, > > I have the following data > > data1 <- data.frame(count = c(0,1,1,2,4,5,13,16,14), weeks = 1:9, > treat=c(rep("1mg",3),rep("5mg",3),rep("10mg",3))) > and I am using > > library(splines) > > to fit > > glm.m <- glm(count~weeks)+as.factor(treat),family=poisson,data=data1) > > and I am interested in predicting the count variale for the weeks 10, 11 and > 12 with treat 10mg and 15mg. bad luck for you. newdat <-data.frame( weeks=rep(10:12,each=2), treat=rep(c("5mg","10mg"),times=3) ) preds <- predict(glm.m,type="response",newdata=newdat,se.fit=T) cbind(newdat,preds) gives as expected : Warning message: In bs(weeks, degree = 3L, knots = numeric(0), Boundary.knots = c(1L, : some 'x' values beyond boundary knots may cause ill-conditioned bases weeks treat fit se.fit residual.scale 1 10 5mg 5.934881 5.205426 1 2 10 10mg 12.041639 9.514347 1 3 11 5mg 4.345165 6.924663 1 4 11 10mg 8.816168 15.805171 1 5 12 5mg 2.781063 8.123436 1 6 12 10mg 5.642667 18.221007 1 Watch the standard errors on the predicted values. No, you shouldn't predict outside your data space, especially when using splines. And when interested in 15mg, well, you shouldn't put treatment as a factor to start with. Cheers Joris -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be ------------------------------- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php [[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.