Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #32

Merged
merged 2 commits into from
Dec 7, 2023
Merged

Dev #32

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions R/main_function_documentation.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ NULL
#' \item{\code{output} -- output of the model with information on the estimated population mean and standard errors.}
#' \item{\code{SE} -- standard error of the estimator of the population mean, divided into errors from probability and non-probability samples.}
#' \item{\code{confidence_interval} -- confidence interval of population mean estimator}
#' \item{\code{coeff_selection} -- `data.frame` of the estimated coefficients of the propensity score (inverse probability weighting) model and their standard errors.}
#' \item{\code{coeff_outcome} -- `data.frame` of the estimated coefficients of the outcome (mass imputation) model and their standard errors.}
#' \item{\code{nonprob_size} -- size of non-probability sample}
#' \item{\code{prob_size} -- size of probability sample}
#' \item{\code{pop_size} -- estimated population size derived from estimated weights (non-probability sample) or known design weights (probability sample)}
Expand Down
6 changes: 4 additions & 2 deletions R/nonprobDR.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ nonprobDR <- function(selection,
message("Bootstrap variance only, analytical version during implementation")
control_inference$var_method <- "bootstrap"
}
outcome_init <- outcome
h <- control_selection$h
maxit <- control_selection$maxit
optim_method <- control_selection$optim_method
Expand Down Expand Up @@ -633,7 +634,7 @@ nonprobDR <- function(selection,
} else {
stop("Please, provide only one of svydesign object or pop_totals/pop_means.")
}
ys$k <- as.numeric(y_nons) # TODO name to change
ys[[k]] <- as.numeric(y_nons)

if (se) {
if (var_method == "analytic") { # TODO add estimator variance with model containg pop_totals to internal_varDR function
Expand Down Expand Up @@ -777,6 +778,7 @@ nonprobDR <- function(selection,
names(OutcomeList) <- outcomes$f
if (is.null(pop_size)) pop_size <- N_nons
names(pop_size) <- "pop_size"
names(ys) <- all.vars(outcome_init[[2]])

SelectionList <- list(
coefficients = selection_model$theta_hat,
Expand All @@ -801,7 +803,7 @@ nonprobDR <- function(selection,
structure(
list(
X = if (isTRUE(x)) X else NULL,
y = if (isTRUE(y)) as.numeric(y) else NULL,
y = if (isTRUE(y)) ys else NULL,
prob = prop_scores,
weights = as.vector(weights_nons),
control = list(
Expand Down
5 changes: 3 additions & 2 deletions R/nonprobIPW.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ nonprobIPW <- function(selection,
if (!(target[3] == "NULL()")) stop("ill-defined formula for the target")
# formula for outcome variable if target defined
dependents <- paste(selection, collapse = " ")
outcome <- stats::as.formula(paste(target[2], dependents))
outcome <- outcome_init <- stats::as.formula(paste(target[2], dependents))
outcomes <- ff(outcome)
output <- list()
ys <- list()
Expand Down Expand Up @@ -365,7 +365,7 @@ nonprobIPW <- function(selection,
flag = FALSE
)$y_nons
}
ys$k <- as.numeric(y_nons) # TODO name to change
ys[[k]] <- as.numeric(y_nons)
mu_hat <- mu_hatIPW(
y = y_nons,
weights = weights,
Expand Down Expand Up @@ -503,6 +503,7 @@ nonprobIPW <- function(selection,
rownames(output) <- rownames(confidence_interval) <- rownames(SE_values) <- outcomes$f
if (is.null(pop_size)) pop_size <- N # estimated pop_size
names(pop_size) <- "pop_size"
names(ys) <- all.vars(outcome_init[[2]])

SelectionList <- list(
coefficients = selection_model$theta_hat,
Expand Down
6 changes: 4 additions & 2 deletions R/nonprobMI.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ nonprobMI <- function(outcome,
se,
...) {
var_selection <- control_inference$vars_selection
outcome_init <- outcome
outcomes <- ff(outcome)
output <- list()
ys <- list()
Expand Down Expand Up @@ -210,7 +211,7 @@ nonprobMI <- function(outcome,
} else {
stop("Please, provide svydesign object or pop_totals/pop_means.")
}
ys$k <- as.numeric(y_nons) # TODO name to change
ys[[k]] <- as.numeric(y_nons)
if (se) {
# design based variance estimation based on approximations of the second-order inclusion probabilities
if (control_inference$var_method == "analytic") { # consider move variance implementation to internals
Expand Down Expand Up @@ -317,11 +318,12 @@ nonprobMI <- function(outcome,
rownames(output) <- rownames(confidence_interval) <- rownames(SE_values) <- outcomes$f
names(OutcomeList) <- outcomes$f
names(pop_size) <- "pop_size"
names(ys) <- all.vars(outcome_init[[2]])

structure(
list(
X = if (isTRUE(x)) X else NULL,
y = if (isTRUE(y)) as.numeric(y) else NULL,
y = if (isTRUE(y)) ys else NULL,
control = list(
control_outcome = control_outcome,
control_inference = control_inference
Expand Down
2 changes: 0 additions & 2 deletions man/nonprob.Rd

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