% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/estpw_s2_auto_pfml.R
\name{p_formula_construction}
\alias{p_formula_construction}
\title{Auto-build a default participation model formula}
\usage{
p_formula_construction(sc, sp, weight)
}
\arguments{
\item{sc}{A data frame. The nonprobability sample.}

\item{sp}{A data frame (one-reference case) or a named list of data frames
(multi-reference case). Each data frame contains the analysis variables
of one reference survey, with design variables removed and a sampling
weight column appended (as produced by `extract_analysis_data()`).}

\item{weight}{A single character string (one-reference case) or a
character vector of the same length as `sp` (multi-reference case)
giving the name of the sampling weight column in each reference survey
data frame. This column is excluded from the candidate covariate set.}
}
\value{
A list with two elements:
\describe{
  \item{`p_formula`}{A one-sided formula (one-reference case) or a named
    list of one-sided formulas (multi-reference case).}
  \item{`log_messages`}{A character vector of messages describing the
    auto-generated formula(s), used for downstream printing when
    `verbose = TRUE`.}
}
}
\description{
Constructs a one-sided participation model formula from the variables
shared between the nonprobability sample (`sc`) and each reference
survey, excluding the sampling weight column. Called by `est_pw()` when
`p_formula = NULL`.
}
\details{
For each reference survey, the candidate covariates are the column names
present in both `sc` and the reference survey data frame after dropping
the sampling weight column named by `weight`. A one-sided formula of the
form `~ var1 + var2 + ...` is built from the remaining shared variables.
An error is raised if no shared covariates remain after excluding the
weight column.

The function distinguishes the one-reference case from the multi-reference
case by the type of `sp`: a plain data frame triggers the one-reference
path; a list of data frames triggers the multi-reference path. Note that
in R a `data.frame` is also a `list`, so the `is.data.frame()` check is
performed first.
}
\keyword{internal}
