ComeçarComece de graça

Deviance and linear transformation

As you have seen in previous exercises the deviance decreased as you added a variable that improves the model fit. In this exercise you will consider the well switch data example and the model you fitted with distance variable, but you will assess what happens when there is a linear transformation of the variable.

Note that the variable distance100 is the original variable distance divided by 100 to make for more meaningful representation and interpretation of the results. You can inspect the data with wells.head() to view the first 5 rows of data.

The wells dataset and the model 'swicth ~ distance100' has been preloaded as model_dist.

Este exercício faz parte do curso

Generalized Linear Models in Python

Ver curso

Instruções do exercício

  • Import statsmodels as sm and the glm() function.
  • Fit a logistic regression model with distance as the explanatory variable and switch as the response and save as model_dist_1.
  • Check and print the difference in deviance of the current model and the model with distance100 as the explanatory variable.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Import functions
import ____.api as ____
from ____.____.api import ____

# Fit logistic regression model as save as model_dist_1
model_dist_1 = ____('____ ~ ____', data = ____, family = ____).____

# Check the difference in deviance of model_dist_1 and model_dist
print('Difference in deviance is: ', round(____.____ - ____.____,3))
Editar e executar o código