2024-04-17
Use the Wald test to test the significance of an estimated coefficient through confidence intervals.
Articulate how the Wald test, Score test, and likelihood ratio test (LRT) calculates a test statistic using the likelihood function.
Use the Likelihood ratio test to test the significance of estimated coefficients through formal hypothesis testing.
Understand when and how to use each test: Wald, Score, and Likelihood ratio
In linear regression, we used ordinary least squares (OLS) to find the best fit model, so we could use the following tests:
These tests hinge on the Mean Squared Error (MSE) which we minimized in OLS and the LINE assumptions
In GLMs, when we use maximum likelihood estimation (MLE), we cannot use t-tests or F-tests
But we have parallel tests in MLE!!
t-test ⟶ Wald test
F-test ⟶ Likelihood ratio test
Likelihood function: expresses the probability of the observed data as a function of the unknown parameters
We often compare likelihoods to see what estimates are more likely given our data
Plot to right is a simplistic view of likelihood
I use \(L\) to represent the log-likelihood and \(l\) to represent the likelihood
To introduce these three tests, we will work on a single coefficient
Let’s say we fit a GLM using MLE
Now we want to run a hypothesis test for an individual coefficient \(j\):
Three potential tests that we use with a Likelihood function are:
Don’t forget: \(\pi(Age) = P(Y=1 | Age)\)
Call:
glm(formula = Late_stage_diag ~ Age_c, family = binomial, data = bc)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.989422 0.023205 -42.64 <2e-16 ***
Age_c 0.056965 0.003204 17.78 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 11861 on 9999 degrees of freedom
Residual deviance: 11510 on 9998 degrees of freedom
AIC: 11514
Number of Fisher Scoring iterations: 4
Use the Wald test to test the significance of an estimated coefficient through confidence intervals.
Articulate how the Wald test, Score test, and likelihood ratio test (LRT) calculates a test statistic using the likelihood function.
Use the Likelihood ratio test to test the significance of estimated coefficients through formal hypothesis testing.
Understand when and how to use each test: Wald, Score, and Likelihood ratio
Very similar to a t-test!
Assumes test statistic W follows a standard normal distribution under the null hypothesis
Test statistic: \[W=\frac{{\hat{\beta}}_j}{se({\hat{\beta}}_j)}\sim N(0,1)\]
95% Wald confidence interval: \[{\hat{\beta}}_1\pm1.96 \cdot SE_{{\hat{\beta}}_j}\]
The Wald test is a routine output in R (summary()
of glm()
output)
tidy()
Set the level of significance \(\alpha\)
Specify the null ( \(H_0\) ) and alternative ( \(H_A\) ) hypotheses
Calculate the confidence interval and determine if it overlaps with null
Write a conclusion to the hypothesis test
Wald test for age coefficient
Interpret the coefficient for age in our model of late stage breast cancer diagnosis.
Needed steps:
Note
I don’t want us to get fixated on this interpretation. This is more to introduce the process, BUT it’s MUCH better to interpret the coefficient in terms of OR (next class).
Wald test for age coefficient
Interpret the coefficient for age in our model of late stage breast cancer diagnosis.
\[\begin{aligned} H_0 &: \beta_{Age} = 0 \\ H_1 &: \beta_{Age} \neq 0 \\ \end{aligned}\]
Wald test for age coefficient
Interpret the coefficient for age in our model of late stage breast cancer diagnosis.
library(epiDisplay)
bc_reg = glm(Late_stage_diag ~ Age_c, data = bc, family = binomial)
tidy(bc_reg, conf.int=T) %>% gt() %>% tab_options(table.font.size = 35) %>%
fmt_number(decimals = 3)
term | estimate | std.error | statistic | p.value | conf.low | conf.high |
---|---|---|---|---|---|---|
(Intercept) | −0.989 | 0.023 | −42.637 | 0.000 | −1.035 | −0.944 |
Age_c | 0.057 | 0.003 | 17.780 | 0.000 | 0.051 | 0.063 |
Wald test for age coefficient
Interpret the coefficient for age in our model of late stage breast cancer diagnosis.
For every one year increase in age, the log-odds of late stage breast cancer diagnosis increases 0.057 (95% CI: 0.051, 0.063).
There is sufficient evidence that age an breast cancer diagnosis are associated.
Note
I don’t want us to get fixated on this interpretation. This is more to introduce the process, BUT it’s MUCH better to interpret the coefficient in terms of OR (next class).
Use the Likelihood ratio test to test the significance of estimated coefficients through formal hypothesis testing.
Understand when and how to use each test: Wald, Score, and Likelihood ratio
Score test does not require the computation of MLE for \(\beta_1\), while both likelihood test and Wald test does
Score test is based on the first and second derivatives of the log-likelihood under the null hypothesis: \[S=\frac{\sum_{i=1}^{n}{x_i(y_i-\bar{y})}}{\sqrt{\bar{y}(1-\bar{y})\sum_{i=1}^{n}\left(x_i-\bar{x}\right)^2}} \sim N(0,1)\]
Articulate how the Wald test, Score test, and likelihood ratio test (LRT) calculates a test statistic using the likelihood function.
Use the Likelihood ratio test to test the significance of estimated coefficients through formal hypothesis testing.
Likelihood ratio test answers the question:
Test a single coefficient by comparing different models
Important: LRT can be used conduct hypothesis tests for multiple coefficients
For a continuous or binary variable, this is equivalent to test: \(H_0: \beta_j = 0\) vs. \(H_1: \beta_j \neq 0\)
Test statistic for LRT: \[G=-2ln\left[\frac{\text{likelihood without } x}{\text{likelihood with } x}\right]=2ln\left[\frac{l\left({\hat{\beta}}_0,{\hat{\beta}}_1\right)}{l({\hat{\beta}}_0)}\right]\]
For a continuous or binary variable, this is equivalent to test: \(H_0: \beta_j = 0\) vs. \(H_1: \beta_j \neq 0\)
Test statistic for LRT: \[G=-2ln\left[\frac{\text{likelihood without } x}{\text{likelihood with } x}\right]=2ln\left[\frac{l\left({\hat{\beta}}_0,{\hat{\beta}}_1\right)}{l({\hat{\beta}}_0)}\right]\]
Deviance: quantifies the difference in likelihoods between a fitted and saturated model
Fitted model:
Saturated model:
The deviance is mathematically defined as: \[D=-2[L_{\text{fitted}}-L_{\text{saturated}}]\]
An alternative way to write it is: \[D=-2ln\left[\frac{\text{likelihood of the fitted model}}{\text{likelihood of the saturated model}}\right]\]
Using ‘-2’ is to make the deviance follow a chi-square distribution
We ARE comparing the Deviance of the model with x and the model without x
\[ \begin{aligned} G&=D\left(\text{model without } x\right)-D\left(\text{model with }x\right) \\ G&=-2ln\left[\frac{\text{likelihood of model without } x}{\text{likelihood of saturated model}}\right]-\left(-2ln\left[\frac{\text{likelihood of model with } x}{\text{likelihood of saturated model}}\right]\right) \\ G&=-2ln\left[\frac{\text{likelihood of model without } x}{\text{likelihood of saturated model}}\times\frac{\text{likelihood of saturated model}}{\text{likelihood of model with } x}\right] \\ G&=-2ln\left[\frac{\text{likelihood of model without } x}{\text{likelihood of model with }}\right] \\ G&=2ln\left[\frac{l\left({\hat{\beta}}_0,{\hat{\beta}}_1\right)}{l({\hat{\beta}}_0)}\right] \end{aligned}\]
For a continuous or binary variable, this is equivalent to test: \(H_0: \beta_j = 0\) vs. \(H_1: \beta_j \neq 0\)
Test statistic for LRT: \[G=-2ln\left[\frac{\text{likelihood without } x}{\text{likelihood with } x}\right]=2ln\left[\frac{l\left({\hat{\beta}}_0,{\hat{\beta}}_1\right)}{l({\hat{\beta}}_0)}\right]\]
Under the null hypothesis, with adequate sample size, LRT statistic follows a chi-square distribution: \[G \sim \chi^2(df)\]
Set the level of significance \(\alpha\)
Specify the null ( \(H_0\) ) and alternative ( \(H_A\) ) hypotheses
Calculate the test statistic and p-value
Write a conclusion to the hypothesis test
LRT
Determine if the model including age is more likely than model without age. Aka: Is age associated with late stage breast cancer diagnosis?
Needed steps:
LRT
Determine if the model including age is more likely than model without age. Aka: Is age associated with late stage breast cancer diagnosis?
\[\begin{aligned} H_0 &: \beta_{Age} = 0 \\ H_1 &: \beta_{Age} \neq 0 \\ \end{aligned}\]
LRT
Determine if the model including age is more likely than model without age. Aka: Is age associated with late stage breast cancer diagnosis?
library(lmtest)
bc_age = glm(Late_stage_diag ~ Age_c, data = bc, family = binomial)
bc_int = glm(Late_stage_diag ~ 1, data = bc, family = binomial)
lmtest::lrtest(bc_age, bc_int)
Likelihood ratio test
Model 1: Late_stage_diag ~ Age_c
Model 2: Late_stage_diag ~ 1
#Df LogLik Df Chisq Pr(>Chisq)
1 2 -5754.8
2 1 -5930.5 -1 351.27 < 2.2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
LRT
Determine if the model including age is more likely than model without age. Aka: Is age associated with late stage breast cancer diagnosis?
We reject the null hypothesis that the coefficient corresponding to age is 0 (\(p-value << 0.05\)). There is sufficient evidence that there is an association between age and late stage breast cancer diagnosis.
Use the Wald test to test the significance of an estimated coefficient through confidence intervals.
Articulate how the Wald test, Score test, and likelihood ratio test (LRT) calculates a test statistic using the likelihood function.
Use the Likelihood ratio test to test the significance of estimated coefficients through formal hypothesis testing.
All three tests are asymptotically equivalent
For testing significance of single covariate coefficient:
LRT
Wald test is very convenient
Score test
Wald test | Score test | LRT | |
---|---|---|---|
Used to test significance of single coefficient | |||
Can be used to report confidence interval for a single coefficient | |||
Confidence interval reported by R for a single coefficient (and most commonly used) | |||
Use to test significance/contribution to outcome prediction of multi-level categorical covariate | |||
Used for comparing two models with different (but nested) covariates |
Wald test
Often used when reporting estimates
Generally presented using a forest plot or table of ORs or RRs
LRT
Often when performing model selection and comparing two models
Often does not show up explicitly in our reports, but is essential to get to our final model!!
Lesson 6: Tests for GLMs using Likelihood function