[R] predict with logistic regression
Jan Sabee
jan.sabee at gmail.com
Fri Sep 15 10:22:04 CEST 2006
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
>
I know that is probability of predict for new dataset.
My question is how can I know each probability according to class (sore).
I mean that I need the result of predit something like (M=1, F=0):
1 2 3 4 5 6 7 8 9 10
1 0 0 0 1 0 1 1 0 1
Sincerelly,
JS
More information about the R-help
mailing list