Skip to contents

These functions help calculate the variance matrix of different kinds of samples. var_mean_indep creates an asymptotic covariance matrix for the sample means of a list of independent samples. var_prop_indep creates an asymptotic covariance matrix for the sample proportions of a list of independent samples. var_mean_onesample creates an asymptotic covariance matrix for the sample means of several variables from the same sample.

Usage

var_mean_indep(x_vectors)

var_mean_onesample(df, vars = names(df))

var_prop_indep(pi_hat, nobs)

Arguments

x_vectors

A list of vectors, representing the different independent samples.

df

A data.frame object

vars

A character vector of variable names in df.

pi_hat

A vector of sample proportions.

nobs

The sample size.

Value

A matrix, representing the asymptotic covariance matrix of the sample means.

Examples

# list of independent samples
x_vectors <- list(
  rnorm(1000, mean = 1, sd = 2),
  rnorm(10, mean = 4, sd = 0.5),
  rnorm(1000000, mean = 0, sd = 1)
)
var_mean_indep(x_vectors)
#>             [,1]       [,2]         [,3]
#> [1,] 0.004000005 0.00000000 0.000000e+00
#> [2,] 0.000000000 0.01760705 0.000000e+00
#> [3,] 0.000000000 0.00000000 9.996391e-07

# sample proportions
pi_hat <- c(0.1, 0.6, 0.3)
nobs <- 1000
var_prop_indep(pi_hat, nobs)
#>       [,1]    [,2]    [,3]
#> [1,] 9e-05 0.00000 0.00000
#> [2,] 0e+00 0.00024 0.00000
#> [3,] 0e+00 0.00000 0.00021

# covariance of educ and age in cps dataset
var_mean_onesample(cps, c("educ", "age"))
#>               educ           age
#> educ  0.0015103246 -0.0001510177
#> age  -0.0001510177  0.0201794244