Skip to content

Commit

Permalink
check_balance updated
Browse files Browse the repository at this point in the history
  • Loading branch information
BERENZ committed Mar 6, 2025
1 parent 210bad3 commit 72a806c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
10 changes: 5 additions & 5 deletions R/check_balance.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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") {
Expand Down
5 changes: 3 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,16 @@ 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)
```

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
```
Expand Down
6 changes: 3 additions & 3 deletions man/check_balance.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 72a806c

Please sign in to comment.