Skip to contents

Computes the matrix of pairwise expectations \(E(n_i n_j)\) for a with-replacement sampling design, where \(n_k\) is the number of times unit \(k\) is selected.

Usage

joint_expected_hits(x, ...)

# S3 method for class 'wr'
joint_expected_hits(x, sampled_only = FALSE, nsim = 10000L, ...)

# S3 method for class 'wor'
joint_expected_hits(x, ...)

# Default S3 method
joint_expected_hits(x, ...)

Arguments

x

A with-replacement design object (class "wr").

...

Additional arguments passed to methods (e.g., nsim for simulation-based methods).

sampled_only

If TRUE, return only the submatrix for units selected at least once (requires nrep = 1). Useful when N is large but the number of distinct selected units is manageable. Default FALSE.

nsim

Number of simulations for Chromy's pairwise expectations (default 10000).

Value

A symmetric N x N matrix (or n_s x n_s if sampled_only = TRUE, where n_s is the number of distinct selected units). Diagonal entries are \(E(n_i^2)\) and off-diagonal entries are \(E(n_i n_j)\). When the stored probability vector is named, those names are used as row and column names. An otherwise unnamed sampled-only matrix is labelled with the selected population indices.

Details

The computation depends on the method:

Exact

multinomial (\(E(n_i n_j) = n(n-1) p_i p_j\)) and srs (\(E(n_i n_j) = n(n-1)/N^2\)).

Simulation

chromy: estimated by Monte Carlo (controlled by nsim, default 10 000).

When sampled_only = TRUE, only the submatrix for units with hits > 0 is returned. All methods compute it directly without allocating the full N x N matrix.

For method = "chromy", sampled_only = TRUE reduces memory (the n_s x n_s accumulator replaces an N x N one) but not simulation cost. Each of nsim draws still covers the full population.

See also

joint_inclusion_prob() for the without-replacement analogue, sampling_cov() for the covariance matrix.

Examples

x <- c(40, 80, 50, 60, 70)
hits <- expected_hits(x, n = 3)
s <- unequal_prob_wr(hits, method = "chromy")
joint_expected_hits(s)
#>        [,1]   [,2]   [,3]   [,4]   [,5]
#> [1,] 0.3959 0.2585 0.1695 0.2028 0.1610
#> [2,] 0.2585 0.7972 0.3372 0.4525 0.5462
#> [3,] 0.1695 0.3372 0.5044 0.1719 0.3302
#> [4,] 0.2028 0.4525 0.1719 0.5987 0.3702
#> [5,] 0.1610 0.5462 0.3302 0.3702 0.7038

# Only the submatrix for selected units
joint_expected_hits(s, sampled_only = TRUE)
#>        2      4      5
#> 2 0.7978 0.4533 0.5390
#> 4 0.4533 0.5999 0.3631
#> 5 0.5390 0.3631 0.6975