diff --git a/R/data_arrange.R b/R/data_arrange.R index 0cff97bd8..07a7f5f56 100644 --- a/R/data_arrange.R +++ b/R/data_arrange.R @@ -42,7 +42,7 @@ data_arrange.default <- function(data, select = NULL, safe = TRUE) { select <- gsub("^-", "", select) # check for variables that are not in data - dont_exist <- select[which(!select %in% names(data))] + dont_exist <- setdiff(select, colnames(data)) if (length(dont_exist) > 0) { if (safe) { diff --git a/R/rescale_weights.R b/R/rescale_weights.R index dd8ee8af9..77135b14f 100644 --- a/R/rescale_weights.R +++ b/R/rescale_weights.R @@ -140,6 +140,8 @@ rescale_weights <- function(data, probability_weights = NULL, nest = FALSE, method = "carle") { + method <- insight::validate_argument(method, c("carle", "kish")) + if (inherits(by, "formula")) { by <- all.vars(by) } diff --git a/man/rescale_weights.Rd b/man/rescale_weights.Rd index 907f7314d..e467f235b 100644 --- a/man/rescale_weights.Rd +++ b/man/rescale_weights.Rd @@ -45,7 +45,7 @@ allow to specify frequency weights, but not design (i.e. sampling or probability) weights, which should be used when analyzing complex samples and survey data. \code{rescale_weights()} implements two algorithms, one proposed by \cite{Asparouhov (2006)} and \cite{Carle (2009)} and one proposed by -\cite{Kish 1965}, to rescale design weights in survey data to account for the +\cite{Kish (1965)}, to rescale design weights in survey data to account for the grouping structure of multilevel models, which then can be used for multilevel modelling. } diff --git a/tests/testthat/test-rescale_weights.R b/tests/testthat/test-rescale_weights.R index 1a1c1f296..00c20bcdf 100644 --- a/tests/testthat/test-rescale_weights.R +++ b/tests/testthat/test-rescale_weights.R @@ -89,6 +89,14 @@ test_that("rescale_weights errors and warnings", { ), regex = "is not used" ) + expect_warning( + rescale_weights( + data = head(nhanes_sample, n = 30), + probability_weights = "WTINT2YR", + method = "dish" + ), + regex = "Invalid option for argument" + ) nhanes_sample$rescaled_weights_a <- 1 expect_warning(