plot.chandwich: Plot diagnostics for a chandwich object

View source: R/plot_summary_print.R

plot.chandwichR Documentation

Plot diagnostics for a chandwich object

Description

plot method for class "chandwich". Only applicable to an object x for which attr(x, "p_current") = 1, i.e. a model with one free parameter.

Usage

## S3 method for class 'chandwich'
plot(x, y, type = 1, legend = length(type) > 1, legend_pos = "topleft", ...)

Arguments

x

an object of class "chandwich", a result of a call to adjust_loglik.

y

Not used.

type

An integer vector, a subset of the numbers 1:4. Indicates which loglikelihoods to plot: 1 for "vertical" adjustment; 2 for "cholesky" (horizontal adjustment); 3 for "spectral" (horizontal adjustment); 4 for no adjustment, i.e. based on the independence loglikelihood.

legend

A logical scalar or a character vector. If this is supplied then a legend is added to the plot. If legend is a character vector then it is used as the argument legend to legend. Otherwise, i.e. if legend = TRUE then the argument type is used.

legend_pos

The position of the legend (if required) specified using the argument x in legend.

...

Additional arguments passed to matplot or legend. The arguments col, lty and lwd will be used (in a consistent way) by both matplot and legend.

If the argument xlim to matplot is not supplied then the MLE minus (for lower) or plus (for upper) standard errors is used. If type does not include 4 then adjusted standard errors are used. Otherwise, the larger of the adjusted and unadjusted standard errors are used.

Value

Nothing is returned.

See Also

adjust_loglik to adjust a user-supplied loglikelihood function.

summary.chandwich for maximum likelihood estimates and unadjusted and adjusted standard errors.

conf_intervals and plot.confint to plot confidence intervals for individual parameters.

conf_region and plot.confreg to plot a confidence region for a pair of parameters.

Examples

# ------------------------- Binomial model, rats data ----------------------

# Contributions to the independence loglikelihood
binom_loglik <- function(prob, data) {
  if (prob < 0 || prob > 1) {
    return(-Inf)
  }
  return(dbinom(data[, "y"], data[, "n"], prob, log = TRUE))
}
rat_res <- adjust_loglik(loglik = binom_loglik, data = rats, par_names = "p")

# Vertically adjusted loglikelihood only
plot(rat_res)
# Three adjusted loglikelihoods and the independence loglikelihood
plot(rat_res, type = 1:4)
# Plot over (0,1) and reposition the legend
plot(rat_res, type = 1:4, xlim = c(0, 1), legend_pos = "bottom")

chandwich documentation built on Aug. 26, 2023, 1:07 a.m.