Rohit Pandey
2012-Jan-15 23:51 UTC
[R] Need help interpreting the logit regression function
Hello R community, I have a question about the logistic regression function. Specifically, when the predictor variable has not just 0's and 1's, but also fractional values (between zero and one). I get a warning when I use the "glm(formula = ... , family = binomial(link "logit"))" which says: "In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!" I looked this up on a few forums and got the impression that I could go ahead and ignore this warning. If that is not so, please suggest another function that can be used (and no need to read further). But if this is usable, then the numbers are not making sense for me. What I am seeing is best explained through an example: #Setting up the data:>c(1,1,0,0,1,1,0,1,1,0,0,0,0,1,1,0,0,0,0,1)->resp >indep<-rep(2:3,10)#Running the logistic regression:>glm(formula = resp~as.factor(indep) , family = binomial(link = "logit"),na.action = na.pass)#Gives me: Coefficients: (Intercept) as.factor(indep)3 -1.692e-16 -4.055e-01>table(indep,resp)resp indep 0 1 2 5 5 3 6 4 Meaning that the odds for '2' to have a favorable outcome are 5/5 =1; and the odds for 3 are 4/6 = 0.6666 And indeed, exp( -1.692e-16) = 1 and exp( -1.692e-16+-4.055e-01) = 0.66. But when I change all the 1's of the independent variable to 0.5, the odds should both be half of what they were before (right?). However, when I run the logistic function after doing this,>resp[resp==1]=0.5 >glm(formula = resp~as.factor(indep) , family = binomial(link = "logit"),na.action = na.pass)(Intercept) as.factor(indep)3 -1.0986 -0.2877 Now, exp(-1.0986) = 0.3333 and exp(-1.0986-0.2877) = 0.25. These are nothing like the previous odds halved. So, either I am using the function wrong or interpreting it wrong. Can some one please point me in the right direction.. -- Thanks in advance, Rohit
cberry at tajo.ucsd.edu
2012-Jan-16 00:54 UTC
[R] Need help interpreting the logit regression function
Rohit Pandey <rohitpandey576 at gmail.com> writes:> Hello R community, > > I have a question about the logistic regression function. > Specifically, when the predictor variable has not just 0's and 1's, > but also fractional values (between zero and one). I get a warning > when I use the "glm(formula = ... , family = binomial(link > "logit"))" which says: > > "In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!" > > I looked this up on a few forums and got the impression that I could > go ahead and ignore this warning. If that is not so, please suggest > another function that can be used (and no need to read further). > > But if this is usable, then the numbers are not making sense for me. > > What I am seeing is best explained through an example: > > #Setting up the data: >>c(1,1,0,0,1,1,0,1,1,0,0,0,0,1,1,0,0,0,0,1)->resp >>indep<-rep(2:3,10) > #Running the logistic regression: >>glm(formula = resp~as.factor(indep) , family = binomial(link = "logit"),na.action = na.pass) > #Gives me: > Coefficients: > (Intercept) as.factor(indep)3 > -1.692e-16 -4.055e-01 >>table(indep,resp) > resp > indep 0 1 > 2 5 5 > 3 6 4 > > Meaning that the odds for '2' to have a favorable outcome are 5/5 =1; > and the odds for 3 are 4/6 = 0.6666 > > And indeed, exp( -1.692e-16) = 1 and exp( -1.692e-16+-4.055e-01) = 0.66. > > But when I change all the 1's of the independent variable to 0.5, the > odds should both be half of what they were before (right?).No. Reducing the number of successes (but not the number of trials) by 1/2 reduces the relative frequencies by 1/2. And the fitted probabilities reflect that. Try predict( glm( ... ), type = "response" ) under each setup to see. HTH, Chuck> > However, when I run the logistic function after doing this, > >>resp[resp==1]=0.5 >>glm(formula = resp~as.factor(indep) , family = binomial(link = "logit"),na.action = na.pass) > (Intercept) as.factor(indep)3 > -1.0986 -0.2877 > > Now, exp(-1.0986) = 0.3333 and exp(-1.0986-0.2877) = 0.25. > > These are nothing like the previous odds halved. So, either I am using > the function wrong or interpreting it wrong. Can some one please point > me in the right direction..-- Charles C. Berry Dept of Family/Preventive Medicine cberry at ucsd edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901