diff --git a/R/check_balance.R b/R/check_balance.R index a571887..925bc47 100644 --- a/R/check_balance.R +++ b/R/check_balance.R @@ -1,8 +1,8 @@ #' @title Check the variable balance between the probability and non-probability samples #' -#' @param x Formula specifying variables to check -#' @param object Object of `nonprobsvy` class -#' @param dig Number of digits for rounding (default = 2) +#' @param x formula specifying variables to check +#' @param object object of `nonprob` class +#' @param dig number of digits for rounding (default = 2) #' #' @importFrom stats aggregate #' @importFrom survey svytotal @@ -51,8 +51,8 @@ check_balance.nonprob <- function(x, object, dig = 2) { stop("The `x` argument must be a formula.") } - if (missing(object) || is.null(object)) { - stop("The `object` argument is required.") + if (missing(object) || is.null(object) || !inherits(object, "nonprob")) { + stop("The `object` argument of class `nonprob` is required.") } if (object$estimator == "mi") { diff --git a/README.Rmd b/README.Rmd index 2587395..9e42cc4 100644 --- a/README.Rmd +++ b/README.Rmd @@ -406,7 +406,7 @@ p2 <- exp(-0.5+0.5*(x2-2)^2)/(1+exp(-0.5+0.5*(x2-2)^2)) flag_bd1 <- rbinom(n = N, size = 1, prob = p1) flag_srs <- as.numeric(1:N %in% sample(1:N, size = n)) base_w_srs <- N/n -population <- data.frame(x1,x2,y1,y2,p1,p2,base_w_srs, flag_bd1, flag_srs) +population <- data.frame(x1,x2,y1,y2,p1,p2,base_w_srs, flag_bd1, flag_srs, pop_size = N) base_w_bd <- N/sum(population$flag_bd1) ``` @@ -414,7 +414,8 @@ Declare `svydesign` object with `survey` package ```{r} sample_prob <- svydesign(ids= ~1, weights = ~ base_w_srs, - data = subset(population, flag_srs == 1)) + data = subset(population, flag_srs == 1), + fpc = ~ pop_size) sample_prob ``` diff --git a/man/check_balance.Rd b/man/check_balance.Rd index e51069e..e947315 100644 --- a/man/check_balance.Rd +++ b/man/check_balance.Rd @@ -7,11 +7,11 @@ check_balance(x, object, dig) } \arguments{ -\item{x}{Formula specifying variables to check} +\item{x}{formula specifying variables to check} -\item{object}{Object of \code{nonprobsvy} class} +\item{object}{object of \code{nonprob} class} -\item{dig}{Number of digits for rounding (default = 2)} +\item{dig}{number of digits for rounding (default = 2)} } \value{ A \code{list} containing nonprobability totals, probability totals, and their differences