This function provides ggplot2-based counterparts to the plots produced by plot.mixpoissonreg. Currently there are six plots available. They contain residual analysis and global influence diagnostics. The plots are selectable by the which argument. The plots are: Residuals vs. obs. numbers; Normal Q-Q plots, which may contain simulated envelopes, if the fitted object has simulated envelopes; Cook's distances vs. obs. numbers; Generalized Cook's distances vs. obs. numbers; Cook's distances vs. Generalized Cook's distances; Response variables vs. fitted means. By default, the first two plots and the last two plots are provided.

If both ncol and nrow are NULL, the plots will be placed one at a time. To place multiple plots, set the values for nrow or ncol.

# S3 method for mixpoissonreg
autoplot(
object,
which = c(1, 2, 5, 6),
title = list("Residuals vs Obs. number", "Normal Q-Q", "Cook's distance",
"Generalized Cook's distance", "Cook's dist vs Generalized Cook's dist",
"Response vs Fitted means"),
title.bold = FALSE,
title.size = NULL,
title.colour = NULL,
label.repel = TRUE,
x.axis.col = NULL,
y.axis.col = NULL,
x.axis.size = NULL,
y.axis.size = NULL,
cook.plot.type = "linerange",
cook.plot.pointshape = NULL,
nrow = NULL,
ncol = NULL,
qqline = TRUE,
ask = prod(graphics::par("mfcol")) < length(which) && grDevices::dev.interactive(),
include.modeltype = TRUE,
include.residualtype = FALSE,
sub.caption = NULL,
sub.caption.col = NULL,
sub.caption.size = NULL,
sub.caption.face = NULL,
sub.caption.hjust = 0.5,
env_alpha = 0.5,
env_fill = "grey70",
gpar_sub.caption = list(fontface = "bold"),
colour = "#444444",
size = NULL,
linetype = NULL,
alpha = NULL,
fill = NULL,
shape = NULL,
label = TRUE,
label.label = NULL,
label.colour = "#000000",
label.alpha = NULL,
label.size = NULL,
label.angle = NULL,
label.family = NULL,
label.fontface = NULL,
label.lineheight = NULL,
label.hjust = NULL,
label.vjust = NULL,
label.n = 3,
...
)

## Arguments

object A mixpoissonreg object. a list or vector indicating which plots should be displayed. If a subset of the plots is required, specify a subset of the numbers 1:6, see title below for the different kinds. In plot number 2, 'Normal Q-Q', if the mixpoissonreg object was fitted with envelopes, a quantile-quantile plot with simulated envelopes will be displayed. titles to appear above the plots; character vector or list of valid graphics annotations. Can be set to "" to suppress all titles. logical indicating whether the titles should be bold. The default is FALSE. numerical indicating the size of the titles. title colour. Logical flag indicating whether to use ggrepel to place the labels. colour of the x axis title. colour of the y axis title. size of the x axis title. size of the y axis title. character indicating the type of plot for Cook's distance and generalized Cook's distance. Default is "linerange". The options are "linerange" and "points". the shape of points if "cook.plot.type" is set to "points". Number of facet/subplot rows. If both nrow and ncol are NULL, the plots will be placed one at a time. For multiple plots, set values for nrow or ncol. Number of facet/subplot columns. If both nrow and ncol are NULL, the plots will be placed one at a time. For multiple plots, set values for nrow or ncol. logical; if TRUE and the fit does not contain simulated envelopes, a qqline passing through the first and third quartiles of a standard normal distribution will be added to the normal Q-Q plot. logical; if TRUE, the user is asked before each plot. logical. Indicates whether the model type ('NB' or 'PIG') should be displayed on the titles. local. Indicates whether the name of the residual ('Pearson' or 'Score') should be displayed on the title of plot 1 (Residuals vs. Index). common title-above the figures if there are more than one. If NULL, as by default, a possible abbreviated version of deparse(x\$call) is used. color of subcaption (when one figure at a time). size of subcaption (when one figure at a time). font face for subcaption, options are: "plain", "bold", "italic" and "bold.italic". indicates the position of the subcaption (when one figure at a time). The default is 0.5, which indicates that the subcaption is centered, a value 0 places the subcaption at the left side of the plot whereas a value of 1 places the subcaption at the right side of the plot. alpha of the envelope region (when the fitted model has envelopes) the colour of the filling in the envelopes. list of gpar parameters to be used as common title in the case of multiple plots. The title will be given in sub.caption argument. See the help of gpar function from the grid package for all the available options. line colour. point size. line type. alpha of the plot. fill colour. point shape. Logical value whether to display labels. vector of labels. If NULL, rownames will be used as labels. Colour for text labels. Alpha for text labels. Size for text labels. Angle for text labels. Font family for text labels. Fontface for text labels. Lineheight for text labels. Horizontal adjustment for text labels. Vertical adjustment for text labels. Number of points to be laeled in each plot, starting with the most extreme. Line colour for additional lines. Line type for additional lines. Fill colour for additional lines. other arguments passed to methods.

## Value

Called for its side effects.

## Details

Based on autoplot.lm from the excellent ggfortify package, ggfortify.

sub.caption - by default the function call - is shown as a subtitle (under the x-axis title) on each plot when plots are on separate pages, or as a subtitle in the outer margin when there are multiple plots per page.

## Examples

# \donttest{
data("Attendance", package = "mixpoissonreg")

daysabs_fit <- mixpoissonreg(daysabs ~ gender + math +
prog | gender + math + prog, data = Attendance)
autoplot(daysabs_fit, which = 1:6)

autoplot(daysabs_fit, nrow = 2)

daysabs_fit_ml <- mixpoissonregML(daysabs ~ gender + math +
prog | gender + math + prog, data = Attendance, envelope = 100)
autoplot(daysabs_fit_ml, which = 2)
# }

daysabs_prog <- mixpoissonregML(daysabs ~ prog, data = Attendance)
autoplot(daysabs_prog)