Skip to contents

This function generates a Cumulative Residuals (CURE) plot for count models, including those with random parameters, estimated using the flexCountReg package.

Usage

cureplot(
  model,
  data = NULL,
  indvar = NULL,
  method = NULL,
  n_resamples = 0,
  ...
)

Arguments

model

A model object estimated using this R package.

data

Optional dataframe. If not provided, the rows used to fit the model are used. Rows with missing values in the outcome, the predictors or indvar are left out.

indvar

Optional independent variable name (character string). This is the continuous independent variable to plot the cumulative residuals against. If not provided, the plot will be against the predicted values.

method

Optional prediction method passed to predict() for random-parameter models (e.g. "Simulated", "Exact" or "Individual") and negative multinomial models ("Standard" or "EB"). The default (NULL) uses the estimator's default. For further details, see predict.flexCountReg.

n_resamples

Number of curves of randomly reordered residuals drawn in grey for comparison. Default is 0 (none). The red limits (\(\pm 1.96\) times the standard deviation of the cumulative residuals computed by cureplots) are drawn whatever the value of n_resamples; they are a descriptive reference, not a calibrated simultaneous band.

...

Additional arguments passed to cure_plot.

Value

A CURE plot generated with cureplots.

Examples

# \donttest{
## Example using a Negative Binomial model
data("washington_roads")
washington_roads$AADTover10k <- ifelse(washington_roads$AADT>10000,1,0)

nb_model <- countreg(Total_crashes ~ lnaadt + lnlength + speed50 + 
                            ShouldWidth04 + AADTover10k,
                            data = washington_roads, family = 'nb2', 
                            method = 'NM', max.iters = 500)
                            
# 1. Plot against fitted values (default) with confidence bands
cureplot(nb_model, n_resamples = 20)


# 2. Plot against a specific covariate (e.g., lnlength)
cureplot(nb_model, indvar = "lnlength", n_resamples = 20)

# }