Weights carry two records describing the exposure they were built for.
exposure_type() returns the type of exposure the weight function was
given, and density_meta() returns the record left by weights whose value
is a ratio of densities.
Both describe the exposure rather than the units, so neither holds a length
of its own: both survive subsetting, arithmetic, and anything else that
changes the number of weights. Combining two sets of weights that record
either of them differently drops the record they disagree on, with a warning
of class propensity_metadata_conflict_warning. A result that no longer
records an exposure type is not described as continuous, so it drops any
density record along with it.
Details
exposure_type() returns "binary", "categorical", or "continuous". It
returns NULL for weights that were built without an exposure to describe,
such as those written with psw() directly.
density_meta() returns a record of what the ratio was built from, and
NULL for weights that are not a ratio of densities, which is every set of
weights for a binary or categorical exposure:
density, the specification of the conditional density family, as built bydens_normal()and its relatives.numerator, what stabilized the weights:"marginal"for the marginal density of the exposure,"integrated"for the conditional density marginalized over the units,"model"for the conditional density a fitted model supplied tostabilizeestimates,"score"for astabilization_scorethe caller supplied, and"none"for weights that were not stabilized.numerator_model, that fitted model itself, andNULLunder every other numerator. The model is kept whole rather than the numerator it evaluates to, sinceipw()rebuilds that numerator at every value of its parameter vector, which takes the model's design and its coefficients. Two sets of weights stabilized on models that read different terms, or that were fit to different values of the same terms, record different numerators and are combined the way any other disagreeing records are.sigma, where the residual spread of the conditional density came from:"pooled"for the pooled residual root mean square,"mle"for a scale estimated under the family that reads it, whichdens_t()anddens_laplace()take withsigma_method = "mle", and"supplied"for a.sigmathe caller gave. Weights built from a dose model trimmed withps_trim()record where the trim's spread came from.sigma_value, the single spread the weights were read at when it was not estimated by the weight function itself: one the caller supplied, or the spread a dose model trimmed withps_trim()holds in its record, which is recorded whatever its source. It isNULLfor a spread estimated from the residuals, by either estimator, and for one supplied per observation. A spread that is one number is a constant the weights can be rebuilt from, which is whatipw()needs of it; a spread that changes with the observation is not, so the record holds where it came from and nothing more.
Weights that carry a density record print it under their values, as the
lines format() renders: the density family, the numerator, and the spread,
followed by the formula of the model supplied to stabilize when a model
estimated the numerator. Weights that carry none, which is every set of
weights for a binary or categorical exposure, print exactly as they always
have.
Examples
set.seed(1)
ps <- runif(20, 0.2, 0.8)
trt <- rbinom(20, 1, ps)
# A binary exposure is weighted by propensity scores rather than by a
# density, so there is no density to record.
exposure_type(wt_ate(ps, trt))
#> ℹ Treating `.exposure` as binary
#> [1] "binary"
density_meta(wt_ate(ps, trt))
#> ℹ Treating `.exposure` as binary
#> NULL
dose <- rnorm(20)
mu <- 0.3 * ps
w <- wt_ate(mu, dose, exposure_type = "continuous")
exposure_type(w)
#> [1] "continuous"
density_meta(w)
#> density: normal
#> numerator: marginal
#> sigma: pooled
