% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fit.R
\name{fit}
\alias{fit}
\alias{fit.PStrataModel}
\title{Fit a Principal Stratification Model}
\usage{
fit(model, ...)

\method{fit}{PStrataModel}(
  model,
  data,
  chains = 4,
  iter = 2000,
  warmup = floor(iter/2),
  cores = 1,
  seed = NULL,
  .debug = FALSE,
  ...
)
}
\arguments{
\item{model}{A \code{\link{PStrataModel}} object.}

\item{...}{Additional arguments passed to \code{\link[rstan]{stan}}.}

\item{data}{A data frame containing all variables referenced in the model.}

\item{chains, iter, warmup, cores, seed}{MCMC settings passed to
\code{\link[rstan]{stan}}.}

\item{.debug}{Logical. If TRUE, read Stan helper files from \code{inst/}
rather than installed package data. Useful during development.}
}
\value{
An object of class \code{PStrataFit}
  (or \code{PStrataFitSurvival}).
}
\description{
Estimate a principal stratification model by running MCMC via Stan.
The model specification (a \code{\link{PStrataModel}}) is combined with
observed data to produce posterior samples.
}
\examples{
\donttest{
data(sim_data_normal)
model <- PStrataModel(
  S.formula = Z + D ~ 1,
  Y.formula = Y ~ 1,
  Y.family  = gaussian(),
  strata    = c(n = "00", c = "01", a = "11"),
  ER        = c("n", "a")
)
ps_fit <- fit(model, data = sim_data_normal, chains = 2, iter = 500)
summary(ps_fit)
diagnostics(ps_fit)
plot(ps_fit)
cat(ps_fit$stancode)
}
}
