0

I got data from wikipedia.

Hours show the number of hours each student spent studying, and Pass shows passed (1) or failed (0).

Hours=[0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0, 3.25, 3.5, 4.0, 4.25, 4.5, 4.75, 5.0, 5.5]

Pass = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

I wanna find logistic regression coefficients -> [−4.0777,1.5046]

I used python pingouin

import pingouin
pingouin.logistic_regression(Hours, Pass,
                             remove_na=True)
    names        coef       se          z           pval        CI[2.5%]    CI[97.5%]
0   Intercept   -4.077713   1.760994.  -2.315574    0.020582.  -7.529199.  -0.626228
1   x1           1.504645   0.628721    2.393185    0.016703    0.272375    2.736916

For Linear regression I can easily get coefficients using formula.

How do I get coefficients manually by writing a user defined function in logistic regression ?

  • There is no closed-form formula for logistic regression coefficients, but you can code the algorithm `pingouin.logistic_regression` uses. Would that be sufficient? – Noah Nov 08 '21 at 14:26
  • Thanks a lot. Actually I wonder which algorithm behind logistic regression that find coefficients ? Is there a way you know ? I am newbie. Sorry. – python123321 Nov 08 '21 at 14:46
  • The method is called "maximum likelihood estimation" and may be implemented using one of several algorithms. – Noah Nov 08 '21 at 14:54

1 Answers1

1

You can't. Logistic regression does not have an analytical or a closed form solution When is logistic regression solved in closed form?

rep_ho
  • 6,036
  • 1
  • 22
  • 44