llo_lrt {BRcal} | R Documentation |
Likelihood Ratio Test for Calibration
Description
Perform a likelihood ratio test for if calibration a set of probability
predictions, x
, are well-calibrated given a corresponding set of binary
event outcomes, y
. See Guthrie and Franck (2024).
Usage
llo_lrt(
x,
y,
event = 1,
optim_details = TRUE,
epsilon = .Machine$double.eps,
...
)
Arguments
x |
a numeric vector of predicted probabilities of an event. Must only contain values in [0,1]. |
y |
a vector of outcomes corresponding to probabilities in |
event |
Value in |
optim_details |
Logical. If |
epsilon |
Amount by which probabilities are pushed away from 0 or 1
boundary for numerical stability. If a value in |
... |
Additional arguments to be passed to optim. |
Details
This likelihood ratio test is based on the following likelihood
where is the Linear in Log Odds
(LLO) function,
is the shift parameter on the
logs odds scale, and
is the scale parameter on
the log odds scale.
As corresponds to no shift or scaling of
probabilities, i.e.
x
is well calibrated given corresponding outcomes y
.
Thus the hypotheses for this test are as follows:
The likelihood ratio test statistics for is
where
asymptotically under the null hypothesis
, and
and
are the maximum
likelihood estimates for
and
.
Value
A list with the following attributes:
test_stat |
The
test statistic |
pval |
The p-value from the likelihood ratio test. |
MLEs |
Maximum likelihood estimates for |
optim_details |
If |
References
Guthrie, A. P., and Franck, C. T. (2024) Boldness-Recalibration for Binary Event Predictions, The American Statistician 1-17.
Examples
# Simulate 100 predicted probabilities
x <- runif(100)
# Simulated 100 binary event outcomes using `x`
y <- rbinom(100, 1, x) # By construction, `x` is well calibrated.
# Run the likelihood ratio test on `x` and `y`
llo_lrt(x, y, optim_details=FALSE)
# Use optim_details = TRUE to see returned info from call to optim(),
# details useful for checking convergence
llo_lrt(x, y, optim_details=TRUE) # no convergence problems in this example
# Use different start value in `optim()` call, start at delta = 5, gamma = 5
llo_lrt(x, y, optim_details=TRUE, par=c(5,5))
# Use `L-BFGS-B` instead of `Nelder-Mead`
llo_lrt(x, y, optim_details=TRUE, method = "L-BFGS-B") # same result
# What if events are defined by text instead of 0 or 1?
y2 <- ifelse(y==0, "Loss", "Win")
llo_lrt(x, y2, event="Win", optim_details=FALSE) # same result
# What if we're interested in the probability of loss instead of win?
x2 <- 1 - x
llo_lrt(x2, y2, event="Loss", optim_details=FALSE)
# Push probabilities away from bounds by 0.000001
x3 <- c(runif(50, 0, 0.0001), runif(50, .9999, 1))
y3 <- rbinom(100, 1, 0.5)
llo_lrt(x3, y3, epsilon=0.000001)