Re: [R] glm

From: Samuel Okoye <samuoko_at_yahoo.com>
Date: Wed, 23 Jun 2010 11:30:18 +0000 (GMT)


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

From: Joris Meys <jorismeys_at_gmail.com>
Subject: Re: [R] glm
To: "Samuel Okoye" <samuoko_at_yahoo.com>
Cc: r-help_at_r-project.org
Date: Tuesday, 22 June, 2010, 9:50

On Tue, Jun 22, 2010 at 1:00 AM, Samuel Okoye <samuoko_at_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.Meys_at_Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php



      
	[[alternative HTML version deleted]]


______________________________________________ R-help_at_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.

Received on Wed 23 Jun 2010 - 11:34:17 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 23 Jun 2010 - 13:30:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive