% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data_setup.R
\name{set_agd}
\alias{set_agd}
\title{Set up aggregate data (AgD)}
\usage{
set_agd(
  data,
  treatment,
  family = c("binomial", "normal", "poisson"),
  outcome_n = NULL,
  outcome_r = NULL,
  outcome_mean = NULL,
  outcome_se = NULL,
  outcome_E = NULL,
  cov_means,
  cov_sds = NULL,
  cov_types = NULL,
  study = NULL
)
}
\arguments{
\item{data}{Data frame containing AgD summary statistics}

\item{treatment}{Column name for treatment variable}

\item{family}{Outcome family: \code{"binomial"}, \code{"normal"}, or \code{"poisson"}}

\item{outcome_n}{Column name for sample size (required for binomial,
optional for normal)}

\item{outcome_r}{Column name for number of events (required for binomial
and poisson)}

\item{outcome_mean}{Column name for mean outcome (required for normal)}

\item{outcome_se}{Column name for standard error of outcome (required for
normal)}

\item{outcome_E}{Column name for total exposure (required for poisson)}

\item{cov_means}{Character vector of column names for covariate means/proportions}

\item{cov_sds}{Character vector of column names for covariate SDs
(\code{NA} for binary covariates)}

\item{cov_types}{Character vector specifying \code{"continuous"} or \code{"binary"} for
each covariate. If \code{NULL}, inferred from presence of SD.}

\item{study}{Column name for study identifier (optional)}
}
\value{
An object of class \code{mlumr_agd}
}
\description{
Prepare AgD from the comparator treatment for an unanchored indirect
comparison.
}
\details{
\strong{Scale assumptions for \code{family = "normal"}.} The AgD likelihood is
\code{y_agd ~ normal(E[exp(eta)], se_agd)} under \code{link = "log"} and
\code{y_agd ~ normal(E[eta], se_agd)} under \code{link = "identity"}. In both
cases \code{outcome_mean} and \code{outcome_se} must be on the \strong{arithmetic
(original, untransformed) scale}. If a publication reports only a
log-scale mean / SD or a geometric mean, back-transform before
calling \code{set_agd()} and propagate uncertainty via the delta method;
passing log-scale or geometric summaries silently misspecifies the
likelihood and biases the posterior.

\strong{Scale assumptions for \code{family = "poisson"}.} \code{outcome_r} is the
total count in each AgD row and \code{outcome_E} is the total
person-time (or other exposure). The Stan likelihood uses
\code{log(E_agd)} as an offset, so rates are modeled on the log scale
regardless of how \code{outcome_r} is tabulated.

\strong{Scale assumptions for \code{family = "binomial"}.} \code{outcome_r} /
\code{outcome_n} are counts of events and trials. The log-odds (or
probit / cloglog under alternative links) are formed from
\code{outcome_r / outcome_n}, so no scale conversion is required.
}
\examples{
\dontrun{
# Binary outcome
agd <- set_agd(
  data = trial_b,
  treatment = "trt",
  outcome_n = "n_total",
  outcome_r = "n_events",
  cov_means = c("age_mean", "sex_prop"),
  cov_sds = c("age_sd", NA),
  cov_types = c("continuous", "binary")
)

# Continuous outcome
agd <- set_agd(
  data = trial_b,
  treatment = "trt",
  family = "normal",
  outcome_mean = "mean_score",
  outcome_se = "se_score",
  outcome_n = "n_total",
  cov_means = c("age_mean", "sex_prop")
)

# Count outcome
agd <- set_agd(
  data = trial_b,
  treatment = "trt",
  family = "poisson",
  outcome_r = "n_events",
  outcome_E = "person_years",
  cov_means = c("age_mean", "sex_prop")
)
}
}
