Skip to contents

Aggregates weighted scores to the stratum–PSU level and computes the Taylor linearisation variance estimator with finite population correction (FPC) at the stratum level.

Usage

compute_J_cluster(scores, hbb_data)

Arguments

scores

Numeric matrix of dimension \(N \times D\). The posterior mean score matrix from compute_score_matrix().

hbb_data

An S3 object of class "hbb_data" (from prepare_stan_data()) or a list containing the fields stratum_idx, psu_idx, w_tilde, and N.

Value

Numeric matrix of dimension \(D \times D\). The cluster-robust meat matrix (positive semi-definite).

Details

Algorithm

For each stratum \(h\) with \(C_h\) PSUs:

  1. Compute weighted score totals per PSU: \(s_{hc} = \sum_{i \in \mathrm{PSU}(h,c)} \tilde{w}_i s_i\)

  2. Compute stratum mean: \(\bar{s}_h = C_h^{-1} \sum_c s_{hc}\)

  3. Center: \(\delta_{hc} = s_{hc} - \bar{s}_h\)

  4. Accumulate with FPC: \(J_h = \frac{C_h}{C_h - 1} \sum_c \delta_{hc} \delta_{hc}^\top\)

Uses rowsum() for efficient PSU-level aggregation. Singleton strata (\(C_h = 1\)) are skipped with a warning.