I am trying to derive the covariance of two sample sums.
Some notation and details:
$x_i$ and $y_i$ are numeric values of two characteristics corresponding to member i of a finite population of N members.
$w_i$ is a random indicator variable taking a value of 1 with a probability of n/N, and is otherwise 0. All of the N $w_i$ values sum to n.
So essentially, I’m taking a sample of size n from a population of size N, and I’m separately summing up the x and the y values for that sample. I want to find the covariance of these two sums, and I think I’m close but could use some help.
$$ Cov\left(\sum_{i=1}^{N}{w_ix_i},\sum_{i=1}^{N}{w_iy_i}\right) $$
*** Edit Following is my original post (with incorrect derivation) but scroll down for the correct answer including some R code confirming the answer. For a derivation of the answer, see the extremely helpful post by whuber below.
$$ =\ E\left[\left(\sum_{i=1}^{N}{w_ix_i}-E\left(\sum_{i=1}^{N}{w_ix_i}\right)\right)\left(\sum_{i=1}^{N}{w_iy_i}-E\left(\sum_{i=1}^{N}{w_iy_i}\right)\right)\right] $$ $$ =\ E\left[\left(\sum_{i=1}^{N}{w_ix_i}-\sum_{i=1}^{N}{x_iE\left(w_i\right)}\right)\left(\sum_{i=1}^{N}{w_iy_i}-\sum_{i=1}^{N}{y_iE\left(w_i\right)}\right)\right] $$ $$ =\ E\left[\left(\sum_{i=1}^{N}{w_ix_i}-\frac{n}{N}\sum_{i=1}^{N}x_i\right)\left(\sum_{i=1}^{N}{w_iy_i}-\frac{n}{N}\sum_{i=1}^{N}y_i\right)\right] $$$$ =\ E\left[\left(\sum_{i=1}^{N}{w_ix_i}-n\mu_x\right)\left(\sum_{i=1}^{N}{w_iy_i}-n\mu_y\right)\right]$$$$ =\ E\left[\sum_{i=1}^{N}{w_ix_i}\sum_{i=1}^{N}{w_iy_i}-\ n\mu_y\sum_{i=1}^{N}{w_ix_i}-\ n\mu_x\sum_{i=1}^{N}{w_iy_i}+n^2\mu_x\mu_y\right]$$$$ =\ E\left[\sum_{i=1}^{N}{w_ix_iw_iy_i}\right]+E\left[\sum_{i=1}^{N}\sum_{j\neq i}^{N}{w_ix_iw_jy_j}\right]-\ n\mu_y\frac{n}{N}\sum_{i=1}^{N}x_i-\ n\mu_x\frac{n}{N}\sum_{i=1}^{N}y_i+n^2\mu_x\mu_y$$$$ =\ \left(\sum_{i=1}^{N}{x_iy_i}\right)\left(\frac{n}{N}\right)+\left(\sum_{i=1}^{N}\sum_{j\neq i}^{N}{x_iy_j}\right)\left(\frac{n}{N}\right)\left(\frac{n-1}{N-1}\right)-\ n^2\mu_y\mu_x-\ n^2\mu_x\mu_y+n^2\mu_x\mu_y$$$$ =\ n\mu_{xy\left(i=j\right)}+n\left(n-1\right)\mu_{xy\left(i\neq j\right)}-\ n^2\mu_y\mu_x$$$$ =\ n^2\left(\frac{\mu_{xy\left(i=j\right)}+\left(n-1\right)\mu_{xy\left(i\neq j\right)}}{n}-\mu_x\mu_y\right)$$$$ =\ n^2(\mu_{xy}-\mu_x\mu_y)$$ $$=\ n^2Cov(x_i,y_i)$$
The above looks right to me, but I must be doing something wrong. When I simulate the covariance in R, I find that it is not the equation above. However, it seems (consistent with simulation) I can obtain the correct covariance by applying a finite population correction and by adding an n to the denominator of my result, as shown below.
$$\frac{N-n}{N}nCov(x_i,y_i)$$
*** End of original post: Following is the answer and some R code that "confirms" it.
$$\frac{n(N-n)}{N-1}Cov(x_i,y_i)$$ (where Cov() represents the population covariance)
R Code with results that are consistent with this answer:
library(mvtnorm)
library(tidyverse)
N <- 5
n <- 3
val1 <- rmvnorm(n = N, mean = c(50, 100), sigma = matrix(c(15^2, 12^2, 12^2, 15^2), nrow = 2))
colnames(val1) <- c("var1","var2")
set.seed(83442)
numSims <- 100000
covList1 <- as.list(1:numSims)
for(i in 1L:numSims) {
covList1[[i]] <- val1[sample.int(N, n),] %>%
as_tibble() %>%
summarize(var1 = sum(var1), var2 = sum(var2))
}
covDF1 <- do.call("bind_rows", args = covList1)
(cov1 <- cov(covDF1$var1, covDF1$var2)) # Covariance from simulations: 195.7401
((N-n)/(N-1))*n*cov(val1[, 1], val1[, 2])*(N-1)/N # Covariance with N-1 denominator: 196.2536
# Note that the (N-1)/N at the end adjusts for the fact that we need a population (not sample) covariance.
The results of this comparison improve with more simulations.