0

I am trying to attempt an interval validation with the R package rms. In doing this comnand:

fit.glm<-glm(y.0 ~ x1 + rcs(x2, 3) + rcs(x4, 3) + log(x5) + x7 + x9 + rcs(x2,3):log(x5) + rcs(x2, 3):x7 + rcs(x4, 3)*log(x5), x = TRUE, y = TRUE)
summary(fit.glm)
summary(fitted(fit.glm))

The later command gives me

> summary(fitted(fit.glm))
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-0.27450  0.02072  0.04557  0.07351  0.08772  1.00600 

Why is it a negative value..., can it be an R bug, or I am missing something...?

  • Well, linear predictions are from -inf to +inf, but when we applied the logistic function, can predicted values be negative. I was under the impression that results were from of 0 to 1. – user3128162 Feb 28 '15 at 15:10
  • 2
    Where exactly have you "applied the logistic function"? You've just done a ordinary linear regression (with a bunch of data we know nothing about...). – Spacedman Feb 28 '15 at 15:13
  • fitted.values(fit.glm) is supposed to do that, in the context of a logistic regession..., Best! – user3128162 Feb 28 '15 at 15:17
  • As it turned out, I forget to put family=binomial to the glm function. Thanks so much for all your help! – user3128162 Feb 28 '15 at 15:20

1 Answers1

0

If you perform logistic regression in R, the fitted.values should range from 0 to 1. In the example you provided, however, you just performed ordinary linear regression. To perform logistic regression, you need to specify the error distribution within the glm function, in your case, family=binomial. For example:

glm.fit <- glm(y~var1+var2,data=data,family=binomial)
Ben F
  • 126
  • 3