3

I have done a Logistic regression in r with 3 variables involving 1 interation:

lm(predicthead~vol+weekday*head, mydata)

weekday is a factor - 7 days of the week.

The coef values are :

    Estimate
(Intercept) -14.81119721
Vol 0.118819705
weekday2    -24.30795615
weekday3    -4.634180612
weekday4    -21.64229775
weekday5    0.607492058
weekday6    42.80131468
weekday7    19.16098601
heads   0.059934818
weekday2:heads  0.026481088
weekday3:heads  0.006665015
weekday4:heads  0.022825105
weekday5:heads  0.005045576
weekday6:heads  -0.041724212
weekday7:heads  -0.019254475

From my Understanding below is what I do in excel:

intercept +
(coef of vol * vol)+
(coef of corresponding week days) + #there no is value for weekday 1
(coef * head)+
(coef of corresponding weekday:head * head) #no value for weekday1 so it will be zero.

The sum of the above should be equal to predict() value - but I am not able to match it. Could you please explain where I have done wrong in calculating predicthead value using excel?

surpavan
  • 145
  • 6

1 Answers1

1

By running a logistic regression model, the objective is to get the chance of a binary outcome based on the different predictor variables. Since the result is a chance, what is modeled is actually:

$$ log \left(\frac{P_{+}}{1 - P_{+}}\right) = \beta_{0} + \beta_{1}x_{1} + ... + \beta_{n}x_{n} $$

So the coefficients you get from R are the $\beta$ values. The function you have so far in Excel computes correctly the right hand side (RHS) of the above equation, but to get the probability $P_{+}$, you need to solve the equation for it. Let's call the RHS, $\mathbf{Bx}$

$$ log \left(\frac{P_{+}}{1 - P_{+}}\right) = \mathbf{Bx} \\ \frac{P_{+}}{1 - P_{+}} = e^{\mathbf{Bx}} \\ \frac{1}{e^{\mathbf{Bx}}} = \frac{1}{P_{+}} - 1 \\ \frac{e^{\mathbf{Bx}} + 1}{e^{\mathbf{Bx}}} = \frac{1}{P_{+}} \\ P_{+} = \frac{1}{1 + e^{-\mathbf{Bx}}} $$

To your results, apply this transformation and you should get the same results as the predict function in R.

gchaks
  • 401
  • 2
  • 3