How can a Wald Test be performed in R?

How can a Wald Test be performed in R?

A Wald Test is a statistical test used to determine the significance of a single parameter in a regression model. To perform a Wald Test in R, one must first create a regression model using the “lm” function and specify the dependent and independent variables. Then, the “wald.test” function can be used to perform the test, providing the model object and the name of the parameter to be tested. The result of the test will include the estimated value of the parameter, its standard error, and the p-value. If the p-value is below a chosen significance level, the null hypothesis can be rejected, indicating that the parameter is significant in the model.

Perform a Wald Test in R


A Wald test can be used to test if one or more parameters in a model are equal to certain values.

This test is often used to determine if one or more predictor variables in a are equal to zero.

We use the following null and alternative for this test:

  • H0: Some set of predictor variables are all equal to zero.
  • HA: Not all predictor variables in the set are equal to zero.

If we fail to reject the null hypothesis, then we can drop the specified set of predictor variables from the model because they don’t offer a statistically significant improvement in the fit of the model.

The following example shows how to perform a Wald test in R.

Example: Wald Test in R

For this example, we’ll use the built-in dataset in R to fit the following multiple linear regression model:

mpg  = β0 + β1disp + β2carb + β3hp + β4cyl

The following code shows how to fit this regression model and view the model summary:

#fit regression model
model <- lm(mpg ~ disp + carb + hp + cyl, data = mtcars)

#view model summary
summary(model)

Call:
lm(formula = mpg ~ disp + carb + hp + cyl, data = mtcars)

Residuals:
    Min      1Q  Median      3Q     Max 
-5.0761 -1.5752 -0.2051  1.0745  6.3047 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) 34.021595   2.523397  13.482 1.65e-13 ***
disp        -0.026906   0.011309  -2.379   0.0247 *  
carb        -0.926863   0.578882  -1.601   0.1210    
hp           0.009349   0.020701   0.452   0.6551    
cyl         -1.048523   0.783910  -1.338   0.1922    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 2.973 on 27 degrees of freedom
Multiple R-squared:  0.788,	Adjusted R-squared:  0.7566 
F-statistic: 25.09 on 4 and 27 DF,  p-value: 9.354e-09

Next, we can use the wald.test() function from the aod package to test if the regression coefficients for the predictor variables “hp” and “cyl” are both equal to zero.

This function uses the following basic syntax:

wald.test(Sigma, b, Terms)

where:

  • Sigma: The variance-covariance matrix of the regression model
  • b: A vector of regression coefficients from the model
  • Terms: A vector that specifies which coefficients to test

The following code shows how to use this function in practice:

library(aod)

#perform Wald Test to determine if 3rd and 4th predictor variables are both zero
wald.test(Sigma = vcov(model), b = coef(model), Terms = 3:4)

Wald test:
----------

Chi-squared test:
X2 = 3.6, df = 2, P(> X2) = 0.16

From the output we can see that the of the test is 0.16.

Since this p-value is not less than .05, we fail to reject the null hypothesis of the Wald test.

This means we can assume the regression coefficients for the predictor variables “hp” and “cyl” are both equal to zero.

We can drop these terms from the model since they don’t statistically significantly improve the overall fit of the model.

Additional Resources

Cite this article

stats writer (2024). How can a Wald Test be performed in R?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-a-wald-test-be-performed-in-r/

stats writer. "How can a Wald Test be performed in R?." PSYCHOLOGICAL SCALES, 1 Jul. 2024, https://scales.arabpsychology.com/stats/how-can-a-wald-test-be-performed-in-r/.

stats writer. "How can a Wald Test be performed in R?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-a-wald-test-be-performed-in-r/.

stats writer (2024) 'How can a Wald Test be performed in R?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-a-wald-test-be-performed-in-r/.

[1] stats writer, "How can a Wald Test be performed in R?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, July, 2024.

stats writer. How can a Wald Test be performed in R?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top