oneplot | R Documentation |
Generates a bar plot of observed count data and overlays predicted values
from one or more models fitted using oneinfl
or truncreg
.
oneplot(
model1,
model2 = NULL,
model3 = NULL,
model4 = NULL,
df,
maxpred = NULL,
ylimit = NULL,
ccex = 1.5
)
model1 |
The first fitted model object, either a one-inflated model (class |
model2 |
Optional. A second fitted model object, structured similarly to |
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 |
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.
A plot is generated but no values are returned.
oneinfl
for fitting one-inflated models.
truncreg
for fitting truncated models.
pred
for generating predictions used in the plot.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.