plot.mcglm: Diagnostic Plots for mcglm Objects

View source: R/mc_S3_methods.R

plot.mcglmR Documentation

Diagnostic Plots for mcglm Objects

Description

Produces diagnostic plots for fitted mcglm objects and returns the data used to generate the plots. Available diagnostics include:

  • "residuals": plots of fitted values vs. Pearson residuals and Q-Q plots of residuals;

  • "algorithm": plots of regression and covariance parameters and quasi-score iterations to inspect algorithm convergence;

  • "partial_residuals": partial residual plots for each covariate in the model.

Usage

## S3 method for class 'mcglm'
plot(
  x,
  type = c("residuals", "algorithm", "partial_residuals"),
  plot_graphics = TRUE,
  ...
)

Arguments

x

A fitted object of class mcglm.

type

Character string specifying the type of diagnostic plot to produce. One of "residuals", "algorithm", or "partial_residuals".

plot_graphics

Logical; if TRUE (default), the function produces the plots. If FALSE, the function only returns the data used for plotting, which can be used to produce custom plots.

...

Additional arguments; currently ignored. Included for compatibility with the generic plot function.

Value

A list containing the data used to generate the plots:

  • For "residuals": fitted values and residuals.

  • For "algorithm": IterationRegression, IterationCovariance, ScoreRegression, ScoreCovariance.

  • For "partial_residuals": residuals, list_beta, and partial_residuals containing x and y values for each covariate.

Author(s)

Wagner Hugo Bonat, wbonat@ufpr.br

See Also

residuals, fitted, plot

Examples

library(mcglm)
set.seed(123)
mydata <- data.frame(y = rnorm(10), x1 = rnorm(10),
                    x2 = rbinom(10, size = 1, prob = 0.5))
Z0 <- mc_id(mydata)
fit <- mcglm(c(y ~ x1 + x2), matrix_pred = list(Z0), data = mydata)
# Produce plots and get data
diag_data <- plot(fit, type = "residuals")
# Only get data without plotting
diag_data <- plot(fit, type = "partial_residuals", plot_graphics = FALSE)


mcglm documentation built on Jan. 9, 2026, 1:07 a.m.