oneplot: Plot Observed Data and Model Predictions

View source: R/oneplot.R

oneplotR Documentation

Plot Observed Data and Model Predictions

Description

Generates a bar plot of observed count data and overlays predicted values from one or more models fitted using oneinfl or truncreg.

Usage

oneplot(
  model1,
  model2 = NULL,
  model3 = NULL,
  model4 = NULL,
  df,
  maxpred = NULL,
  ylimit = NULL,
  ccex = 1.5
)

Arguments

model1

The first fitted model object, either a one-inflated model (class "oneinflmodel") or a truncated model (class "truncmodel").

model2

Optional. A second fitted model object, structured similarly to model1.

model3

Optional. A third fitted model object.

model4

Optional. A fourth fitted model object.

df

A data frame containing the variables used in the models.

maxpred

Optional. The maximum count value to include in the plot. Defaults to the maximum observed count.

ylimit

Optional. The upper limit for the y-axis. Defaults to 1.1 times the highest observed frequency.

ccex

Optional. A numeric value controlling the size of plot points and lines. Defaults to 1.5.

Details

This function visualizes observed count data as a bar plot and overlays predicted values from up to four models. The function automatically detects the type of model (Poisson or negative binomial; one-inflated or truncated) and adjusts the plot accordingly. Predictions are generated using the pred function.

Model types are distinguished by different point and line styles:

  • Poisson (PP): Dark magenta, triangle-down

  • Zero-truncated negative binomial (ZTNB): Red, diamond

  • One-inflated Poisson (OIPP): Green, triangle-up

  • One-inflated zero-truncated negative binomial (OIZTNB): Blue, circle

The legend in the top-right corner of the plot indicates the models displayed.

Value

A plot is generated but no values are returned.

See Also

oneinfl for fitting one-inflated models. truncreg for fitting truncated models. pred for generating predictions used in the plot.

Examples

# Example usage
df <- data.frame(x = rnorm(100), z = rnorm(100), y = rpois(100, lambda = 5) + 1)
model1 <- oneinfl(y ~ x | z, df = df, dist = "Poisson")
model2 <- truncreg(y ~ x, df = df, dist = "Poisson")
oneplot(model1, model2, df = df, maxpred = 10)


oneinfl documentation built on April 4, 2025, 12:05 a.m.