Re: [R] predicting glm on a new dataset

From: Chuck Cleland <ccleland_at_optonline.net>
Date: Sat 25 Feb 2006 - 02:03:55 EST

Christian Jones wrote:
>
> Hello together,
>
> I would like to predict my fitted values on a new dataset. The original dataset consists of the variable a and b (data.frame(a,b)). The dataset for prediction consists of the same variables, but variable b has a constant value (x) added towards it (data.frame (a,b+x).
>
> The prediction command returns the identical set of predicted values as for the original dataset yet I would have expected them to change due to b+x.
>
> Were have I gone wrong?
>
> Heres my code:
>
> orig.frame<-data.frame(y,a,b)
>
> pred.frame<-data.frame(a,b+x)
>
> attach(orig.frame)
>
> modela<-glm(y~a+b,binomial)
>
> pr<-predict(modela,newdata=pred.frame,type="response")

Does this work for you?

orig.frame <- data.frame(y, a, b)
pred.frame <- data.frame(a, b = b + x)
modela <- glm(y ~ a + b, family = binomial, data = orig.frame) pr <- predict(modela, newdata = pred.frame, type = "response")

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 452-1424 (M, W, F)
fax: (917) 438-0894

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sat Feb 25 02:29:37 2006

This archive was generated by hypermail 2.1.8 : Sat 25 Feb 2006 - 03:08:48 EST