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,"score"for astabilization_scorethe caller supplied, and"none"for weights that were not stabilized.sigma, where the residual spread of the conditional density came from:"pooled"for the pooled residual standard deviation, and"supplied"for a.sigmathe caller gave.sigma_value, the single spread the caller supplied, andNULLfor a pooled spread 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.
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
