replicate.weights {svyVarSel} | R Documentation |
This function allows calculating replicate weights.
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
)
data |
A data frame with information on (at least) cluster and strata indicators, and sampling weights. It could be |
method |
A character string indicating the method to be applied to define replicate weights. Choose between one of these: |
cluster |
A character string indicating the name of the column with cluster identifiers in the data frame indicated in |
strata |
A character string indicating the name of the column with strata identifiers in the data frame indicated in |
weights |
A character string indicating the name of the column with sampling weights in the data frame indicated in |
design |
An object of class |
k |
A numeric value indicating the number of folds to be defined. Default is |
R |
A numeric value indicating the number of times the sample is partitioned. Default is |
B |
A numeric value indicating the number of bootstrap resamples. Default is |
train.prob |
A numeric value between 0 and 1, indicating the proportion of clusters (for the method |
method.split |
A character string indicating the way in which replicate weights should be defined in the |
rw.test |
A logical value. If |
dCV.sw.test |
A logical value. If |
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.
This function returns a new data frame with new columns, each of them indicating replicate weights for different subsets.
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)