[R] Predictions with 'missing' variables

Ista Zahn izahn at psych.rochester.edu
Tue Jan 25 21:13:29 CET 2011


See the note in the help page for ?predict.glm

Best,
Ista

On Tue, Jan 25, 2011 at 2:59 PM, Axel Urbiz <axel.urbiz at gmail.com> wrote:
> Dear List,
>
> I think I'm going crazy here...can anyone explain why do I get the same
> predictions in train and test data sets below when the second has a missing
> input?
>
> y <- rnorm(1000)
> x1 <- rnorm(1000)
> x2 <- rnorm(1000)
> train <- data.frame(y,x1,x2)
> test <- data.frame(x1)
>
> myfit <- glm(y ~ x1 + x2, data=train)
> summary(myfit)
> all(predict(myfit, test) == predict(myfit, train))
>
> [1] TRUE
>
>
>
> Thanks,
>
> Axel.
>
>        [[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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



More information about the R-help mailing list