Interpreting model fit

Generalized Linear Models in Python

Ita Cirovic Donev

Data Science Consultant

Parameter estimation

  • Maximum likelihood estimation (MLE)
  • Iteratively reweighted least squares (IRLS)
Generalized Linear Models in Python

The response function

  • Poisson regression model $$ log(\lambda)=\beta_0+\beta_1x_1 $$

  • The response function: $$ \lambda=exp(\beta_0 + \beta_1x_1) $$                                                  or $$ \lambda=exp(\beta_0) \times exp(\beta_1x_1) $$

Generalized Linear Models in Python

The response function

  • Poisson regression model $$ log(\lambda)=\beta_0+\beta_1x_1 $$

  • The response function: $$ \lambda=exp(\beta_0 + \beta_1x_1) $$                                                  or $$ \lambda=exp(\beta_0) \color{red}{\times} exp(\beta_1x_1) $$

Generalized Linear Models in Python

Interpretation of parameters

  • $exp(\beta_0)$

    • The effect on the mean $\lambda$ when $x=0$
  • $exp(\beta_1)$

    • The multiplicative effect on the mean $\lambda$ for a 1-unit increase in $x$
Generalized Linear Models in Python

Interpreting coefficient effect

  • If $\color{#FF550D}{\beta_1 > 0}$
    • $exp(\beta_1)>1$
    • $\lambda$ is $\color{#FF550D}{exp(\beta_1)\text{ times larger}}$ than when $x=0$
  • If $\color{#D04A73}{\beta<0}$
    • $exp(\beta_1)<1$
    • $\lambda$ is $\color{#D04A73}{exp(\beta_1) \text{ times smaller}}$ than when $x=0$
  • If $\color{#0099FF}{\beta_1 = 0}$
    • $exp(\beta_1)=1$
    • $\lambda=exp(\beta_0)$
    • Multiplicative factor is 1
    • $y$ and $x$ are $\text{\color{#0099FF}{not related}}$
Generalized Linear Models in Python

Example

model = glm('sat ~ weight', data = crab, 
            family = sm.families.Poisson()).fit()
                 Generalized Linear Model Regression Results (print cut)                 
=============================================================================
                 coef    std err          z      P>|z|      [0.025     0.975]
-----------------------------------------------------------------------------
Intercept     -0.4284      0.179     -2.394      0.017      -0.779     -0.078
weight         0.5893      0.065      9.064      0.000       0.462      0.717
=============================================================================
Generalized Linear Models in Python

Example - interpretation of beta

  • Extract model coefficients
    model.params
    
Intercept   -0.428405
weight       0.589304
  • Compute the effect
    np.exp(0.589304)
    
1.803
Generalized Linear Models in Python

Confidence interval for ...

  • $\beta_1$
print(model.conf_int())
                  0         1
Intercept -0.779112 -0.077699
weight     0.461873  0.716735
  • The multiplicative effect on mean
print(np.exp(crab_fit.conf_int()))
                  0         1
Intercept  0.458813  0.925243
weight     1.587044  2.047737
Generalized Linear Models in Python

Let's practice!

Generalized Linear Models in Python

Preparing Video For Download...