
Calculate spatial correlation between two locations
Source:R/calc_spatial_correlation.R
calc_spatial_correlation.RdComputes the Pearson spatial–correlation coefficient \(\mathcal{C}_{ij}\) (Keeling & Rohani 2002) for a pair of locations i and j from single infection time-series per location.
Arguments
- I_i
Numeric vector. Total infections in location i at each reporting time.
- I_j
Numeric vector. Total infections in location j at each reporting time. Must be the same length as
I_i.- N_i
Numeric scalar or vector. Population size(s) of location i.
If a scalar, the value is recycled across all time points.
If a vector, it must be the same length as the infection series and supplies time-varying population sizes.
Default is
1, implying that infection counts are already expressed as prevalences.
- N_j
Numeric scalar or vector. Population size(s) of location j. Recycling and length rules mirror those of
N_i. Default1.
Value
Numeric scalar in the interval [-1, 1] giving the spatial
correlation between the two locations, or NA_real_ if the calculation is
not possible (e.g. all values NA, zero variance).
Details
The prevalence series are \(y_{it} = I_{it} / N_{i,t}\) and \(y_{jt} = I_{jt} / N_{j,t}\), where the population sizes \(N_{i,t}\) and \(N_{j,t}\) may be either scalars (constant over time) or vectors the same length as the infection series (time-varying).
Rows containing NA in either prevalence series are removed
automatically. If fewer than two paired observations remain, the function
returns NA_real_.
A consistency check stops execution if any computed prevalence exceeds 1.