[R] predict.glm predicted prob above 1?

Simon Blomberg s.blomberg1 at uq.edu.au
Mon Mar 9 07:49:50 CET 2009


There is a bug in your code: Try

reg2<-predict.glm(reg1, se.fit=T, data.frame(male=1, edu=1,
married=1,inc=1, relig=1, YEAR=seq(1,33,1)), type="response")

You put type="response" into your newdata frame, so it wasn't visible to
predict.glm. So predict.glm assumed the default type, which is "link".

Cheers,

Simon.


On Sun, 2009-03-08 at 23:39 -0700, Kitty Lee wrote:
> I have a puzzle....
> 
> When I include an interaction in the model, many predicted probabilities are above 1. Is that a problem with my model? I thought the predicted prob can't be bigger than 1...
> 
> Any help would be really appreciated! Thanks!
> 
> K.
> 
> reg1<-glm(pyea~male+edu+married+inc+relig+factor(time)+
>     factor(time)*male, data=mydata, family=binomial(link="logit"))
> 
> reg2<-predict.glm(reg1, se.fit=T, data.frame(male=1, edu=1, married=1,inc=1, relig=1, type='response', YEAR=seq(1,33,1))
> 
> reg2$fit
> 
> $fit
>         1         2         3         4         5         6         7         8         9        10        11 
> 0.6105101 0.5249279 0.4717028 0.5525786 0.5622492 0.3387205 0.3010051 0.5836462 0.6478388 0.9158862 0.9849557 
>        12        13        14        15        16        17        18        19        20        21        22 
> 1.1208788 1.1440165 1.2053129 1.0169487 1.1832429 1.4162309 1.0612279 1.2038962 1.1274700 1.0876280 0.9704570 
>        23        24        25        26        27        28        29        30        31        32        33 
> 1.0160205 1.0410419 0.9526990 1.0043029 1.1337670 1.2502910 0.9927158 1.0924190 0.8315262 1.0530386 1.5727090
> 
> ______________________________________________
> 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.
-- 
Simon Blomberg, BSc (Hons), PhD, MAppStat. 
Lecturer and Consultant Statistician 
School of Biological Sciences
The University of Queensland 
St. Lucia Queensland 4072 
Australia
Room 320 Goddard Building (8)
T: +61 7 3365 2506
http://www.uq.edu.au/~uqsblomb
email: S.Blomberg1_at_uq.edu.au

Policies:
1.  I will NOT analyse your data for you.
2.  Your deadline is your problem.

The combination of some data and an aching desire for 
an answer does not ensure that a reasonable answer can 
be extracted from a given body of data. - John Tukey.




More information about the R-help mailing list