Skip to content

Commit

Permalink
support the extended population
Browse files Browse the repository at this point in the history
  • Loading branch information
YukiAtsusaka committed Nov 28, 2024
1 parent 3b6bb88 commit 2dfb3e8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
9 changes: 9 additions & 0 deletions R/imprr_weights.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#' looks for `app_identity_1`, `app_identity_2`, `app_identity_3`, and so on,
#' with an underbar separator followed by numbers.
#' @param anc_correct Indicator for passing the anchor question.
#' @param population Choice of the target population out of
#' non-random respondents (default) or all respondents.
#' @param assumption Choice of the identifying assumption if `population` is set to all
#' @param seed Seed for \code{set.seed} for reproducibility.
#' @param weight A vector of weights. Defaults to NULL.
#' @param ranking The name of the column that will store the full ranking
Expand All @@ -35,6 +38,8 @@ imprr_weights <- function(data,
J = NULL,
main_q,
anc_correct,
population = "non-random",
assumption = "contaminated",
seed = 123456,
weight = NULL,
ranking = "ranking") {
Expand All @@ -59,6 +64,10 @@ imprr_weights <- function(data,
weight <- rep(1, N)
}

if (population == "all" & assumption == "uniform"){
data[[anc_correct]] <- rep(1, N) # get naive estimate for theta
}

# Check the validity of the input arguments ==================================
## Main ranking only

Expand Down
7 changes: 7 additions & 0 deletions man/imprr_weights.Rd

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

32 changes: 31 additions & 1 deletion vignettes/v2-bias-correction.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ out_direct_uniform <- imprr_direct(
Similarly, the contaminated sampling assumption can be specified as follows:

```{r}
# Perform bias correction for the entire population with the uniform preference assumption
# Perform bias correction for the entire population with the contaminated sampling assumption
out_direct_contaminated <- imprr_direct(
data = identity,
Expand Down Expand Up @@ -166,6 +166,36 @@ out_weights <- imprr_weights(
)
```


By default, `imprr_weights` assumes that the target population is a set of non-random respondents. When researchers wish to study the entire population as a target group, additional arguments must be specified, including `population` and `assumption`. For example, the uniform preference assumption can be specified as follows:

```{r}
# Perform bias correction with the uniform preference assumption
out_weights_uniform <- imprr_weights(
data = identity,
J = 4,
main_q = "app_identity",
anc_correct = "anc_correct_identity",
population = "all",
assumption = "uniform"
)
```

Similarly, the contaminated sampling assumption can be specified as follows:

```{r}
# Perform bias correction with the uniform preference assumption
out_weights_contaminated <- imprr_weights(
data = identity,
J = 4,
main_q = "app_identity",
anc_correct = "anc_correct_identity",
population = "all",
assumption = "contaminated"
)
```


### Results: Estimated Weights

The output of `imprr_weights` contains the set of weights for all possible ranking profiles with `J` items. For example, when `J = 4`, the set has `{1234, 1243, ..., 4321}` and each profile now has an estimated weight.
Expand Down

0 comments on commit 2dfb3e8

Please sign in to comment.