Skip to contents

Splits each variable into its group mean (between part) and the residual (within part). Covariances and variances decompose exactly (Research.P12.cov_decomp, var_decomp); when the within-group covariance is zero the group-level (ecological) correlation is at least as large in magnitude as the individual one (ecological_ge). When the within-group covariance is not zero the ecological correlation can be smaller, or of the opposite sign (Robinson 1950), so a neighbourhood-level regression of crime on composition constrains individual behaviour only through the within term, which this function reports.

Usage

morie_ecological_decompose(x, y, group)

Arguments

x, y

Numeric vectors, one entry per individual.

group

Group label per individual.

Value

A list with cov (individual, between, within), var_x, var_y (same split), corr_individual, corr_ecological (correlation of the group means, weighted by group size), within_share_of_cov, bound_applies (whether the within covariance is zero, in which case the proved inequality holds), sign_reversed and theorems. Population (divide by n) conventions throughout, matching the Lean definitions.

Examples

# Robinson's reversal: group means anti-aligned, individuals positively related
x <- c(0, 2, 1, 3); y <- c(1, 3, 0, 2); g <- c("a", "a", "b", "b")
morie_ecological_decompose(x, y, g)[c("corr_individual", "corr_ecological", "sign_reversed")]
#> $corr_individual
#> [1] 0.6
#> 
#> $corr_ecological
#> [1] -1
#> 
#> $sign_reversed
#> [1] TRUE
#>