Fit smoothing curves to residuals/innovations across posterior draws to detect systematic trends. Returns both fitted values and summary metrics.
Usage
residual_model_check(
res_data,
predictor = "level_prop",
n_draws = 500,
n_grid_points = 100,
quantile_range = c(0.05, 0.95)
)Arguments
- res_data
Data frame with columns: draw, residual, sd_y, and the predictor column
- predictor
Name of the predictor column (default: "level_prop")
- n_draws
Number of posterior draws to subsample (default: 500)
- n_grid_points
Number of points in prediction grid (default: 100)
- quantile_range
Quantile range for prediction grid (default: c(0.05, 0.95))
Value
List with components:
- fits
Data frame with draw-level smoothing fits at grid points
- summary
Data frame with median and 95% CI of fits
- evidence
Data frame with summary metric at each grid point
- min_evidence
Minimum summary metric across grid (scalar)
- predictor
Name of the predictor used
Details
The function fits smoothing splines to the residuals, weighted by the inverse variance (1/sd_y^2). Predictions are made on a grid of predictor values. The summary metric is the probability that the residual trend does not deviate from zero, calculated as 2*min(P(fitted > 0), P(fitted < 0)):
Values close to 0 indicate strong evidence of a trend
Values close to 1 indicate no evidence of trend (fits centered around 0)