# [R] predict with logistic regression

From: Jan Sabee <jan.sabee_at_gmail.com>
Date: Fri 15 Sep 2006 - 08:22:04 GMT

I am learning about using logistic regression with glm. Suppose I have dataset:
duration <- c(45,15,40,83,90,25,35,65,95,35,75,45,50,75,30,25,20,60,70,30,60,61,65,15,20,45,15,25,15,30,40,15,135,20,40)

```type <- c(0,0,0,1,1,1,rep(0,5),1,1,1,0,0,1,1,1,rep(0,4),1,1,0,1,0,1,0,0,rep(1,4))
sore <- factor(rep(c("M", "F"), c(16, 19)))
sore.fr <- data.frame(duration, type, sore)
```
str(sore.fr)

then with glm I have the result.
sorethroat.lg <- glm(sore ~ type+duration, family=binomial, data=sore.fr) summary(sorethroat.lg, cor=TRUE)

```If I have a new dataset then predict it, the result:
new.sore <- data.frame(duration=c(35,25,41,33,30,55,35,62,93,34),
type=c(0,1,0,1,0,1,1,1,0,1))
```
predict(sorethroat.lg, new.sore, type="response")
> predict(sorethroat.lg, new.sore, type="response")

1 2 3 4 5 6 0.5176877150 0.2750893421 0.5407418590 0.3003664211 0.4984140283 0.3760831903

7 8 9 10 0.3068890332 0.4017370393 0.7242061280 0.3036178483
>

Sincerelly,
JS

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 and provide commented, minimal, self-contained, reproducible code. Received on Fri Sep 15 18:23:53 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 19 Sep 2006 - 18:30:05 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.