replicate.weights {svyVarSel}R Documentation

Replicate weights

Description

This function allows calculating replicate weights.

Usage

replicate.weights(
  data,
  method = c("JKn", "dCV", "bootstrap", "subbootstrap", "BRR", "split", "extrapolation"),
  cluster = NULL,
  strata = NULL,
  weights = NULL,
  design = NULL,
  k = 10,
  R = 1,
  B = 200,
  train.prob = 0.7,
  method.split = c("dCV", "bootstrap", "subbootstrap"),
  rw.test = FALSE,
  dCV.sw.test = FALSE
)

Arguments

data

A data frame with information on (at least) cluster and strata indicators, and sampling weights. It could be NULL if the sampling design is indicated in the design argument (see design).

method

A character string indicating the method to be applied to define replicate weights. Choose between one of these: JKn, dCV, bootstrap, subbootstrap, BRR, split, extrapolation.

cluster

A character string indicating the name of the column with cluster identifiers in the data frame indicated in data. It could be NULL if the sampling design is indicated in the design argument (see design).

strata

A character string indicating the name of the column with strata identifiers in the data frame indicated in data. It could be NULL if the sampling design is indicated in the design argument (see design).

weights

A character string indicating the name of the column with sampling weights in the data frame indicated in data. It could be NULL if the sampling design is indicated in the design argument (see design).

design

An object of class survey.design generated by survey::svydesign(). It could be NULL if information about cluster, strata, weights and data are given.

k

A numeric value indicating the number of folds to be defined. Default is k=10. Only applies for the dCV method.

R

A numeric value indicating the number of times the sample is partitioned. Default is R=1. Only applies for dCV, split or extrapolation methods.

B

A numeric value indicating the number of bootstrap resamples. Default is B=200. Only applies for bootstrap and subbootstrap methods.

train.prob

A numeric value between 0 and 1, indicating the proportion of clusters (for the method split) or strata (for the method extrapolation) to be set in the training sets. Default is train.prob=0.7. Only applies for split and extrapolation methods.

method.split

A character string indicating the way in which replicate weights should be defined in the split method. Choose one of the following: dCV, bootstrap or subbootstrap. Only applies for split method.

rw.test

A logical value. If TRUE, the function returns in the output object the replicate weights to the corresponding test sets. If FALSE, only the replicate weights of the training sets are returned. Default is rw.test = FALSE.

dCV.sw.test

A logical value. If TRUE original sampling weights for the units in the test sets are returned instead of the replicate weights. Default is dCV.sw.test = FALSE. Only applies for dCV method.

Details

Some of these methods (specifically JKn, bootstrap, subbootstrap and BRR), were previously implemented in the survey R-package, to which we can access by means of the function as.svrepdesign() (the names of the methods are kept as in as.svrepdesign()). Thus, the function replicate.weights() depends on this function to define replicate weights based on these options. In contrast, dCV, split and extrapolation have been expressly defined to be incorporated into this function.

Selecting any of the above-mentioned methods, the object returned by this function is a new data frame, which includes new columns into the original data set, each of them indicating replicate weights for different training (always) and test (optionally, controlled by the argument rw.test) subsets. The number of new columns and the way in which they are denoted depend on the values set for the arguments, in general, and on the replicate weights method selected, in particular. The new columns indicating training and test sets follow a similar structure for any of the selected methods. Specifically, the structure of the names of the training sets is the following: rw_r_x_train_t where x=1,...,R indicates the x-th partition of the sample and t=1,...,T the t-th training set. Similarly, the structure of the new columns indicating the test sets is the following: rw_r_x_test_t or sw_r_x_test_t, where x indicates the partition and t the number of the test set. In addition, for some of the methods we also indicate the fold or set to which each unit in the data set has been included in each partition. This information is included as fold_t or set_t, depending on the method. See more detailed information below.

Value

This function returns a new data frame with new columns, each of them indicating replicate weights for different subsets.

Examples

data(simdata_lasso_binomial)

# JKn ---------------------------------------------------------------------
newdata <- replicate.weights(data = simdata_lasso_binomial,
                             method = "JKn",
                             cluster = "cluster",
                             strata = "strata",
                             weights = "weights",
                             rw.test = TRUE)

# dCV ---------------------------------------------------------------------
newdata <- replicate.weights(data = simdata_lasso_binomial,
                             method = "dCV",
                             cluster = "cluster",
                             strata = "strata",
                             weights = "weights",
                             k = 10, R = 20,
                             rw.test = TRUE)

# subbootstrap ------------------------------------------------------------
newdata <- replicate.weights(data = simdata_lasso_binomial,
                             method = "subbootstrap",
                             cluster = "cluster",
                             strata = "strata",
                             weights = "weights",
                             B = 100)

# BRR ---------------------------------------------------------------------
newdata <- replicate.weights(data = simdata_lasso_binomial,
                             method = "BRR",
                             cluster = "cluster",
                             strata = "strata",
                             weights = "weights",
                             rw.test = TRUE)

# split ---------------------------------------------------------------------
newdata <- replicate.weights(data = simdata_lasso_binomial,
                             method = "split",
                             cluster = "cluster",
                             strata = "strata",
                             weights = "weights",
                             R=20,
                             train.prob = 0.5,
                             method.split = "subbootstrap",
                             rw.test = TRUE)

# extrapolation -------------------------------------------------------------
newdata <- replicate.weights(data = simdata_lasso_binomial,
                            method = "extrapolation",
                            cluster = "cluster",
                            strata = "strata",
                            weights = "weights",
                            R=20,
                            train.prob = 0.5,
                            rw.test = TRUE)

[Package svyVarSel version 1.0.1 Index]