Convenience wrapper that fits a Hierarchical Bayesian Small Area
Estimation model with a lognormal likelihood. Internally
delegates to hbm_flex with
family_key = "lognormal".
Usage
hbm_lnln(
response,
auxiliary = NULL,
data,
area_var = NULL,
area_re_structure = c("nested", "crossed"),
spatial_var = NULL,
spatial_model = NULL,
car_type = NULL,
sar_type = NULL,
M = NULL,
sampling_variance = NULL,
fixed_params = NULL,
predictors = NULL,
sampling_var = NULL,
group = NULL,
sre = NULL,
sre_type = NULL,
...
)Arguments
- response
Character. Name of the response column (must be strictly positive).
- auxiliary
Character vector of auxiliary (fixed-effect) variable names; corresponds to area-level covariates in SAE literature (see Rao & Molina 2015 Ch. 4).
- data
A
data.frame.- area_var
Optional character vector. Name(s) of a column (or columns) in
dataidentifying the small area / domain. Length 1 adds an IID area-level random intercept(1 | area_var); length \(\geq\) 2 supports hierarchical areas – see?hbm_flexfor the nested vs.\ crossed structures. Default:NULL.- area_re_structure
Either
"nested"(default) or"crossed". Controls how multiple area columns combine. See?hbm_flex.- spatial_var
Optional character. Name of a column in
dataidentifying the spatial cluster (e.g. province). Must be supplied together withspatial_modelandM. Default:NULL.- spatial_model
Optional character. Type of spatial dependence:
"car"(conditional autoregressive) or"sar"(simultaneous autoregressive). Default:NULL.- car_type
Optional character. CAR sub-type passed to brms:
"escar","esicar","icar"(intrinsic CAR; default whenspatial_model = "car"), or"bym2".- sar_type
Optional character. SAR sub-type:
"lag"(spatial-lag, default whenspatial_model = "sar") or"error"(spatial-error).- M
Optional numeric matrix. Spatial weight matrix. Required when
spatial_modelis supplied.- sampling_variance
Optional character. Name of a column in
datacontaining the known per-area sampling variance \(\psi_i\) on the log scale, i.e.\ the variance of \(\log(\hat y_i)\). When supplied, \(\sigma_i = \sqrt{\psi_i}\) is pinned via offset, recovering the Fay–Herriot lognormal model. If your survey software produces \(\mathrm{Var}(\hat y_i)\) on the original scale, convert with the delta-method approximation \(\psi_i \approx \mathrm{Var}(\hat y_i) / \hat y_i^2\) before passing. Default:NULL(sigma is random).- fixed_params
Optional named list pinning distributional parameters to known values. See
hbmfor the spec format. Allows power-user access to the same machinery used bysampling_variance.- predictors
Deprecated. Use
auxiliaryinstead. Kept for backward compatibility; will be removed in v2.0.0.- sampling_var
Deprecated. Use
sampling_varianceinstead. Kept for backward compatibility; will be removed in v2.0.0.- group
Deprecated. Use
area_varinstead.- sre
Deprecated. Use
spatial_varinstead.- sre_type
Deprecated. Use
spatial_modelinstead.- ...
Additional arguments forwarded to
hbm_flex(e.g.\prior_type,nonlinear,handle_missing, sampler controls such aschains,iter,cores,seed).
Details
The response \(y_i\) in area \(i\) is assumed to follow $$y_i \mid \theta_i \sim \mathrm{Lognormal}(\theta_i, \sigma^2),$$ with the log-mean linked to auxiliary variables via $$\log(\theta_i) = x_i^\top \boldsymbol{\beta} + u_i, \quad u_i \sim \mathcal{N}(0, \sigma_v^2).$$
When the user supplies sampling_variance = "psi_i" (the column name of
the known per-area sampling variance \(\psi_i\)), \(\sigma_i =
\sqrt{\psi_i}\) is pinned for each area via an offset. This recovers
the Fay-Herriot-style lognormal model in which residual variability is
fully determined by the survey design.
Conflict policy
When the residual standard deviation \(\sigma_i = \sqrt{\psi_i}\)
is pinned via sampling_variance (or via
fixed_params$sigma), the function refuses any additional
specification that would also set \(\sigma\). Specifically, all
of the following are rejected with an informative error at
construction time:
sampling_varianceandfixed_params$sigma.sampling_varianceand a userprioronclass = "sigma".sampling_varianceand astanvarssampling statement involvingsigma.auxiliaryand the deprecatedpredictorsin the same call.
Examples
# \donttest{
library(hbsaems)
data("data_lnln")
# -- 1. Standard lognormal SAE with area random effect ----------------------
fit1 <- hbm_lnln(
response = "y_obs",
auxiliary = c("x1", "x2", "x3"),
area_var = "district",
data = data_lnln,
chains = 4, iter = 2000, warmup = 1000, refresh = 0
)
#> Warning: Area column 'district' has 100 unique levels for 100 rows -- looks more like a continuous covariate than a grouping factor. Did you mean to put this in `auxiliary` instead?
#> Compiling Stan program...
#> Error in .fun(model_code = .x1): Boost not found; call install.packages('BH')
# -- 2. Fay-Herriot style with known sampling variance ----------------------
# (assumes psi_i column is available)
fit2 <- hbm_lnln(
response = "y_obs",
auxiliary = c("x1", "x2", "x3"),
area_var = "district",
sampling_variance = "psi_i",
data = data_lnln,
chains = 4, iter = 2000, warmup = 1000, refresh = 0
)
#> Warning: Area column 'district' has 100 unique levels for 100 rows -- looks more like a continuous covariate than a grouping factor. Did you mean to put this in `auxiliary` instead?
#> Compiling Stan program...
#> Error in .fun(model_code = .x1): Boost not found; call install.packages('BH')
# }