[R] predicting glm on a new dataset
Chuck Cleland
ccleland at optonline.net
Fri Feb 24 16:03:55 CET 2006
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
More information about the R-help
mailing list