% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/api-plotting.R
\name{plot_marginal_fit}
\alias{plot_marginal_fit}
\title{Plot strict marginal-fit follow-up cells using base R}
\usage{
plot_marginal_fit(
  x,
  diagnostics = NULL,
  plot_type = c("std_residual", "prop_diff"),
  top_n = 20,
  facet = NULL,
  main = NULL,
  palette = NULL,
  label_angle = 45,
  preset = c("standard", "publication", "compact", "monochrome"),
  draw = TRUE
)
}
\arguments{
\item{x}{Output from \code{\link[=fit_mfrm]{fit_mfrm()}} or \code{\link[=diagnose_mfrm]{diagnose_mfrm()}}.}

\item{diagnostics}{Optional output from \code{\link[=diagnose_mfrm]{diagnose_mfrm()}} when \code{x} is \code{mfrm_fit}.}

\item{plot_type}{\code{"std_residual"} or \code{"prop_diff"}.}

\item{top_n}{Maximum cells shown.}

\item{facet}{Optional facet name used to keep only matching facet-level rows.
When \code{NULL}, the plot uses the mixed top-cell table returned by the strict
marginal screen.}

\item{main}{Optional custom plot title.}

\item{palette}{Optional named color overrides. Recognized names:
\code{positive}, \code{negative}, \code{flag}.}

\item{label_angle}{X-axis label angle.}

\item{preset}{Visual preset (\code{"standard"}, \code{"publication"}, \code{"compact"},
or \code{"monochrome"}).}

\item{draw}{If \code{TRUE}, draw with base graphics.}
}
\value{
A plotting-data object of class \code{mfrm_plot_data}.
}
\description{
Plot strict marginal-fit follow-up cells using base R
}
\details{
This helper visualizes the largest first-order strict marginal-fit cells from
\code{diagnose_mfrm(..., diagnostic_mode = "both")} or
\code{diagnostic_mode = "marginal_fit"}.

The \code{"std_residual"} view ranks cells by the absolute standardized residual
from posterior-integrated expected category counts. The \code{"prop_diff"} view
ranks the same cells by the signed observed-minus-expected proportion gap.

Use this plot after \code{summary(diagnostics)} indicates strict marginal flags.
The display is exploratory: it highlights which facet/category cells deserve
follow-up, but it is not a standalone inferential test.
}
\section{Interpreting output}{

\itemize{
\item Positive bars mean the observed category usage exceeded the posterior-
expected marginal usage for that cell.
\item Negative bars mean the observed usage fell below the posterior-expected
marginal usage.
\item Red bars indicate the current strict marginal warning rule was triggered by
\verb{|StdResidual| >= abs_z_warn}.
}
}

\section{Typical workflow}{

\enumerate{
\item Fit with \code{\link[=fit_mfrm]{fit_mfrm()}} using \code{method = "MML"} for \code{RSM} / \code{PCM}.
\item Run \code{\link[=diagnose_mfrm]{diagnose_mfrm()}} with \code{diagnostic_mode = "both"}.
\item Use \code{plot_marginal_fit()} to inspect the largest strict marginal cells.
\item Follow up with \code{\link[=rating_scale_table]{rating_scale_table()}} or substantive design review.
}
}

\section{Further guidance}{

For a plot-selection guide and a longer walkthrough, see
\link{mfrmr_visual_diagnostics} and
\code{vignette("mfrmr-visual-diagnostics", package = "mfrmr")}.
}

\examples{
\donttest{
toy <- load_mfrmr_data("example_core")
fit <- fit_mfrm(
  toy,
  "Person",
  c("Rater", "Criterion"),
  "Score",
  method = "MML",
  quad_points = 7,
  maxit = 30
)
diag <- diagnose_mfrm(fit, residual_pca = "none", diagnostic_mode = "both")
p <- plot_marginal_fit(diag, draw = FALSE, preset = "publication")
p$data$preset
if (interactive()) {
  plot_marginal_fit(
    diag,
    plot_type = "prop_diff",
    draw = TRUE,
    preset = "publication"
  )
}
}
}
\seealso{
\code{\link[=diagnose_mfrm]{diagnose_mfrm()}}, \code{\link[=rating_scale_table]{rating_scale_table()}}, \code{\link[=plot_marginal_pairwise]{plot_marginal_pairwise()}},
\link{mfrmr_visual_diagnostics}
}
