Get Started

Computing Wald statistic

In the previous exercise you fitted a model with width variable and assessed the relationship of the explanatory and response variable. In this exercise you will assess the significance of the width variable by computing the Wald statistic.

Also note that in the model summary the Wald statistic is presented by the letter z which means that the value of a statistic follows a standard normal distribution. Recall the formula for the Wald statistic:

$$ z=\frac{\hat\beta}{SE} $$

where \(\hat\beta\) is the estimated coefficient and \(SE\) its standard error.

The fitted model crab_GLM and crab dataset have been preloaded in the workspace.

This is a part of the course

“Generalized Linear Models in Python”

View Course

Exercise instructions

  • Using .params extract and print model coefficients and save as intercept and slope.
  • Save and print covariance matrix as crab_cov.
  • Compute and print the standard error std_error by extracting the relevant element using the covariance matrix.
  • Compute and print the Wald statistic.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Extract coefficients
intercept, slope = ____.____

# Estimated covariance matrix: crab_cov
____ = crab_GLM.____
print(____)

# Compute standard error (SE): std_error
____ = np.____(____.loc['width', 'width'])
print('SE: ', round(____, 4))

# Compute Wald statistic
wald_stat = ____/____
print('Wald statistic: ', round(____,4))
Edit and Run Code

This exercise is part of the course

Generalized Linear Models in Python

AdvancedSkill Level
5.0+
3 reviews

Extend your regression toolbox with the logistic and Poisson models and learn to train, understand, and validate them, as well as to make predictions.

This chapter focuses on logistic regression. You'll learn about the structure of binary data, the logit link function, model fitting, as well as how to interpret model coefficients, model inference, and how to assess model performance.

Exercise 1: Binary data and logistic regressionExercise 2: Compute odds and probabilitiesExercise 3: Fit logistic regressionExercise 4: Interpreting coefficientsExercise 5: Coefficients in terms of oddsExercise 6: Model formulaExercise 7: Interpreting logistic modelExercise 8: Rate of change in probabilityExercise 9: Interpreting model inferenceExercise 10: Statistical significanceExercise 11: Computing Wald statistic
Exercise 12: Confidence intervalsExercise 13: Computing and describing predictionsExercise 14: Visualize model fit using regplot()Exercise 15: Compute predictionsExercise 16: Compute confusion matrix

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free