# NOT RUN {
### Example from the Information and communication technologies (ICT) survey
# The subset of the (simulated) ICT survey has the following features:
# - stratified one-stage sampling design of 650 firms;
# - 612 responding firms, non-response correction through reweighting
# in homogeneous response groups based on economic sub-sector and turnover;
# - calibration on margins (number of firms and turnover broken down
# by economic sub-sector).
# Step 1 : Dummy variance wrapper
# Note : see define_variance_wrapper() for a more
# realistic variance function and examples.
variance_wrapper <- define_variance_wrapper(
variance_function = function(y) abs(colSums(y)),
reference_id = ict_survey$firm_id,
default = list(id = "firm_id", weight = "w_calib")
)
variance_wrapper(ict_survey, total(speed_quanti))
# Step 2 : Redefine the mean linearization wrapper
# The mean() linearization wrapper defined in the gustave
# package is bulit on top of the ratio() linearization wrapper.
variance_wrapper(ict_survey, mean(speed_quanti))
# Let's redefine it directly from the formula found for instance
# in (Caron, Deville, Sautory, 1998) and without handling NA
# values
mean2 <- define_linearization_wrapper(
linearization_function = function(y, weight){
est <- sum(y * weight) / sum(weight)
lin <- (y - est) / sum(weight)
list(
lin = list(lin),
metadata = list(est = est, n = length(y))
)
},
arg_type = list(data = "y", weight = "weight"),
allow_factor = TRUE
)
variance_wrapper(ict_survey, mean(speed_quanti), mean2(speed_quanti))
# }
Run the code above in your browser using DataLab