var_y_HT_RACS: Calculate the variance of the Horvitz-Thompson estimator of...

View source: R/var_y_HT_C.R

var_y_HT_RACSR Documentation

Calculate the variance of the Horvitz-Thompson estimator of the mean using the RACS correction

Description

Calculate the variance of the Horvitz-Thompson estimator of the mean using the RACS correction

Usage

var_y_HT_RACS(N, n1, m_vec, y_total, m_threshold, pi_i_values = NULL)

Arguments

N

Population size.

n1

An integer giving the initial sample size (e.g., a simple random sample).

m_vec

Vector of values m for the set of units in a sample, of length n1. Each m value within the vector m_vec denotes the number of units satisfying the ACS criterion for the network i to which the unit belongs.

y_total

Vector of y total, each corresponding to a unique network.

m_threshold

threshold value above which to calculate pi_i and pi_j differently.

pi_i_values

vector of inclusion probabilities, if not calculated using this function. Default is NULL.

References

\insertRef

saubyadaptiveACSampling

Examples

library(ggplot2)
library(magrittr)
library(dplyr)
# Sampling of population from Figure 1, Thompson (1990)

data(Thompson1990Fig1Pop)
data(Thompson1990Figure1Sample)

# plot sample overlaid onto population
ggplot() +
	geom_point(data=Thompson1990Fig1Pop, aes(x,y, 
	size=factor(y_value),
		shape=factor(y_value))) +
	scale_shape_manual(values=c(1, rep(16, length(2:13)))) +
	geom_point(data=Thompson1990Figure1Sample, aes(x,y), shape=0, size=7)

# INITIATE ACS
Z = createACS(
popdata = Thompson1990Fig1Pop, 
n1 = dim(Thompson1990Figure1Sample)[1], 
initsample = Thompson1990Figure1Sample, 
yvar = "y_value"
)

# CALCULATE var(y_HT)
# create dataframe of network info
#Z_summary <- Z %>% group_by(NetworkID) %>%
#	summarise(
#		m = m[1],
#		y_total = sum(y_value, rm.na=TRUE)
#		) %>%
#		dplyr::filter(NetworkID > 0)
#
#var_y_HT_RACS(
#	N = dim(Thompson1990Fig1Pop)[1], 
#	n1 = dim(Thompson1990Figure1Sample)[1], 
#	m = Z_summary$m, 
#	y_total = Z_summary$y_total,
#	m_threshold=3
#)

ksauby/ACS documentation built on Aug. 18, 2022, 3:33 a.m.