Skip to content

Commit

Permalink
version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
BERENZ committed Jan 30, 2025
1 parent 1a40409 commit 76888f0
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 66 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: nonprobsvy
Type: Package
Title: Inference Based on Non-Probability Samples
Version: 0.1.2
Version: 0.2.0
Authors@R:
c(person(given = "Łukasz",
family = "Chrostowski",
Expand Down
12 changes: 7 additions & 5 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# nonprobsvy News and Updates

# nonprobsvy 0.2
## nonprobsvy 0.2

------------------------------------------------------------------------

Expand All @@ -12,8 +12,8 @@
- function `genSimData` removed completely as it is not used anywhere
in the package.
- argument `maxLik_method` renamed to `maxlik_method` in the
`control_sel` function.

`control_sel` function.
### Features

- two additional datasets have been included: `jvs` (Job Vacancy
Expand All @@ -35,13 +35,15 @@
### Other

- more informative error messages added.
- documentation improved.
- switching completely to snake_case.

### Documentation

- annotation has been added that arguments such as `strata`, `subset`
and `na_action` are not supported for the time being.

# nonprobsvy 0.1.1
## nonprobsvy 0.1.1

------------------------------------------------------------------------

Expand Down Expand Up @@ -84,7 +86,7 @@
- added unit tests for variable selection models and mi estimation
with vector of population totals available

# nonprobsvy 0.1.0
## nonprobsvy 0.1.0

------------------------------------------------------------------------

Expand Down
12 changes: 6 additions & 6 deletions R/boot_dr.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bootDR <- function(outcome,
boot_dr <- function(outcome,
data,
svydesign,
SelectionModel,
Expand Down Expand Up @@ -52,7 +52,7 @@ bootDR <- function(outcome,
p <- ncol(X)
y_rand <- vector(mode = "numeric", length = n_rand)
y <- c(y_rand, OutcomeModel$y_nons) # outcome variable for joint model
var_obj <- bootDR_sel(
var_obj <- boot_dr_sel(
X = X,
R = R,
y = y,
Expand Down Expand Up @@ -261,7 +261,7 @@ bootDR <- function(outcome,
#' @importFrom parallel makeCluster
#' @importFrom parallel stopCluster
#' @importFrom doParallel registerDoParallel
bootDR_multicore <- function(outcome,
boot_dr_multicore <- function(outcome,
data,
svydesign,
SelectionModel,
Expand Down Expand Up @@ -316,7 +316,7 @@ bootDR_multicore <- function(outcome,
p <- ncol(X)
y_rand <- vector(mode = "numeric", length = n_rand)
y <- c(y_rand, OutcomeModel$y_nons) # outcome variable for joint model
var_obj <- bootDR_sel_multicore(
var_obj <- boot_dr_sel_multicore(
X = X,
R = R,
y = y,
Expand Down Expand Up @@ -346,9 +346,9 @@ bootDR_multicore <- function(outcome,
doParallel::registerDoParallel(cl)
on.exit(parallel::stopCluster(cl))
parallel::clusterExport(cl = cl, varlist = c(
"internal_selection", "internal_outcome", "logit_model_nonprobsvy", "start_fit", "get_method", "controlSel", "theta_h_estimation",
"internal_selection", "internal_outcome", "logit_model_nonprobsvy", "start_fit", "get_method", "control_sel", "theta_h_estimation",
"mle", "mu_hatDR", "probit_model_nonprobsvy", "cloglog_model_nonprobsvy", "glm_nonprobsvy", "nn_nonprobsvy", "pmm_nonprobsvy",
"gaussian_nonprobsvy", "poisson_nonprobsvy", "binomial_nonprobsvy", "nonprobMI_fit", "controlOut"
"gaussian_nonprobsvy", "poisson_nonprobsvy", "binomial_nonprobsvy", "nonprob_mi_fit", "control_out"
))
if (is.null(pop_totals)) {
N <- sum(weights_rand)
Expand Down
6 changes: 3 additions & 3 deletions R/boot_dr_sel.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bootDR_sel <- function(X,
boot_dr_sel <- function(X,
R,
y,
svydesign,
Expand Down Expand Up @@ -114,7 +114,7 @@ bootDR_sel <- function(X,
#' @importFrom parallel makeCluster
#' @importFrom parallel stopCluster
#' @importFrom doParallel registerDoParallel
bootDR_sel_multicore <- function(X,
boot_dr_sel_multicore <- function(X,
svydesign,
R,
y,
Expand Down Expand Up @@ -147,7 +147,7 @@ bootDR_sel_multicore <- function(X,
doParallel::registerDoParallel(cl)
on.exit(parallel::stopCluster(cl))
parallel::clusterExport(cl = cl, varlist = c(
"internal_selection", "logit_model_nonprobsvy", "start_fit", "get_method", "controlSel", "mle",
"internal_selection", "logit_model_nonprobsvy", "start_fit", "get_method", "control_sel", "mle",
"probit_model_nonprobsvy", "cloglog_model_nonprobsvy", "mm", "u_theta_beta_dr",
"mu_hatDR"
))
Expand Down
6 changes: 3 additions & 3 deletions R/boot_ipw.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bootIPW <- function(X_rand,
boot_ipw <- function(X_rand,
X_nons,
svydesign,
weights,
Expand Down Expand Up @@ -183,7 +183,7 @@ bootIPW <- function(X_rand,
#' @importFrom parallel makeCluster
#' @importFrom parallel stopCluster
#' @importFrom doParallel registerDoParallel
bootIPW_multicore <- function(X_rand,
boot_ipw_multicore <- function(X_rand,
X_nons,
svydesign,
weights,
Expand Down Expand Up @@ -225,7 +225,7 @@ bootIPW_multicore <- function(X_rand,
doParallel::registerDoParallel(cl)
on.exit(parallel::stopCluster(cl))
parallel::clusterExport(cl = cl, varlist = c(
"internal_selection", "logit_model_nonprobsvy", "start_fit", "get_method", "controlSel",
"internal_selection", "logit_model_nonprobsvy", "start_fit", "get_method", "control_sel",
"mle", "mu_hatIPW", "probit_model_nonprobsvy", "cloglog_model_nonprobsvy", "theta_h_estimation"
))

Expand Down
30 changes: 15 additions & 15 deletions R/boot_mi.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @importFrom utils setTxtProgressBar
#' @importFrom utils txtProgressBar

bootMI <- function(X_rand,
boot_mi <- function(X_rand,
X_nons,
weights,
y,
Expand Down Expand Up @@ -125,7 +125,7 @@ bootMI <- function(X_rand,
X_rand_strap <- X_rand[which(rep_weights[, k] != 0), ]
weights_rand_strap <- weights_rand_strap_svy[strap_rand_svy]

model_rand <- nonprobMI_nn(
model_rand <- nonprob_mi_nn(
data = X_nons_strap,
query = X_rand_strap,
k = control_outcome$k,
Expand Down Expand Up @@ -187,7 +187,7 @@ bootMI <- function(X_rand,

model_rand <- switch(control_outcome$predictive_match,
{ # 1
nonprobMI_nn(
nonprob_mi_nn(
data = y_strap,
query = y_rand_strap,
k = control_outcome$k,
Expand All @@ -196,7 +196,7 @@ bootMI <- function(X_rand,
)
},
{ # 2
nonprobMI_nn(
nonprob_mi_nn(
data = y_nons_strap,
query = y_rand_strap,
k = control_outcome$k,
Expand Down Expand Up @@ -291,7 +291,7 @@ bootMI <- function(X_rand,
X_nons_strap <- X_nons[strap, , drop = FALSE]
y_strap <- y[strap]

model_rand <- nonprobMI_nn(
model_rand <- nonprob_mi_nn(
data = X_nons_strap,
query = t(pop_totals / N),
k = control_outcome$k,
Expand Down Expand Up @@ -339,7 +339,7 @@ bootMI <- function(X_rand,

model_rand <- switch(control_outcome$predictive_match,
{ # 1
nonprobMI_nn(
nonprob_mi_nn(
data = y_strap,
query = y_strap_rand,
k = control_outcome$k,
Expand All @@ -348,7 +348,7 @@ bootMI <- function(X_rand,
)
},
{ # 2
nonprobMI_nn(
nonprob_mi_nn(
data = y_strap_nons,
query = y_strap_rand,
k = control_outcome$k,
Expand Down Expand Up @@ -410,7 +410,7 @@ bootMI <- function(X_rand,
#' @importFrom parallel makeCluster
#' @importFrom parallel stopCluster
#' @importFrom doParallel registerDoParallel
bootMI_multicore <- function(X_rand,
boot_mi_multicore <- function(X_rand,
X_nons,
weights,
y,
Expand Down Expand Up @@ -450,8 +450,8 @@ bootMI_multicore <- function(X_rand,
doParallel::registerDoParallel(cl)
on.exit(parallel::stopCluster(cl))
parallel::clusterExport(cl = cl, varlist = c(
"internal_selection", "logit_model_nonprobsvy", "start_fit", "get_method", "controlSel",
"mle", "mu_hatIPW", "probit_model_nonprobsvy", "cloglog_model_nonprobsvy", "nonprobMI_nn"
"internal_selection", "logit_model_nonprobsvy", "start_fit", "get_method", "control_sel",
"mle", "mu_hatIPW", "probit_model_nonprobsvy", "cloglog_model_nonprobsvy", "nonprob_mi_nn"
))

if (is.null(pop_totals)) {
Expand Down Expand Up @@ -508,7 +508,7 @@ bootMI_multicore <- function(X_rand,
X_rand_strap <- X_rand[strap_rand_svy, , drop = FALSE]
weights_strap_rand <- weights_rand_strap_svy[strap_rand_svy]

model_rand <- nonprobMI_nn(
model_rand <- nonprob_mi_nn(
data = X_nons_strap,
query = X_rand_strap,
k = control_outcome$k,
Expand Down Expand Up @@ -556,7 +556,7 @@ bootMI_multicore <- function(X_rand,

model_rand <- switch(control_outcome$predictive_match,
{ # 1
nonprobMI_nn(
nonprob_mi_nn(
data = y_strap,
query = y_rand_strap,
k = control_outcome$k,
Expand All @@ -565,7 +565,7 @@ bootMI_multicore <- function(X_rand,
)
},
{ # 2
nonprobMI_nn(
nonprob_mi_nn(
data = y_nons_strap,
query = y_rand_strap,
k = control_outcome$k,
Expand Down Expand Up @@ -616,7 +616,7 @@ bootMI_multicore <- function(X_rand,
X_nons_strap <- X_nons[strap, , drop = FALSE]
y_strap <- y[strap]

model_rand <- nonprobMI_nn(
model_rand <- nonprob_mi_nn(
data = X_nons_strap,
query = t(pop_totals / N),
k = control_outcome$k,
Expand Down Expand Up @@ -650,7 +650,7 @@ bootMI_multicore <- function(X_rand,
y_strap_nons <- family_nonprobsvy$linkinv(eta_nons)


model_rand <- nonprobMI_nn(
model_rand <- nonprob_mi_nn(
data = y_strap_nons,
query = y_strap_rand,
k = control_outcome$k,
Expand Down
2 changes: 1 addition & 1 deletion R/control_inference.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title Control parameters for inference
#'
#' @description \code{control_inf} constructs a list with all necessary control parameters
#' @description \code{control_inf} constructs a `list` with all necessary control parameters
#' for statistical inference.
#'
#' @param vars_selection If `TRUE`, then the variables selection model is used.
Expand Down
8 changes: 7 additions & 1 deletion R/data_manip.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# create an object with model frames and matrices to preprocess
model_frame <- function(formula, data, weights = NULL, svydesign = NULL, pop_totals = NULL, pop_size = NULL, flag = TRUE) {
model_frame <- function(formula,
data,
weights = NULL,
svydesign = NULL,
pop_totals = NULL,
pop_size = NULL,
flag = TRUE) {
if (!is.null(svydesign)) {
##### Model frame for nonprobability sample #####
model_Frame <- model.frame(formula, data)
Expand Down
4 changes: 2 additions & 2 deletions R/internals.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal_outcome <- function(outcome,
family_outcome,
start_outcome) {
# estimation
model_nons <- nonprobMI_fit(
model_nons <- nonprob_mi_fit(
outcome = outcome,
data = data,
weights = weights,
Expand Down Expand Up @@ -201,7 +201,7 @@ mu_hatIPW <- function(y,
mu_hat
}

nonprobMI_fit <- function(outcome,
nonprob_mi_fit <- function(outcome,
data,
weights,
svydesign = NULL,
Expand Down
1 change: 1 addition & 0 deletions R/bias_correction_ipw.R → R/ipw_bias_correction.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mm <- function(X,
nleqslv_global,
nleqslv_xscalm,
boot = FALSE) {

method_selection_function <- paste(method_selection, "_model_nonprobsvy", sep = "")
method <- get_method(method_selection_function)
inv_link <- method$make_link_inv
Expand Down
10 changes: 5 additions & 5 deletions R/nn.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ nn_nonprobsvy <- function(outcome,
model_frame = NULL,
start_outcome = NULL) { # TODO consider add data standardization before modelling

model_nons <- nonprobMI_nn(
model_nons <- nonprob_mi_nn(
data = X_nons,
query = X_nons,
k = control$k,
treetype = control$treetype,
searchtype = control$searchtype
)
if (is.null(pop_totals)) {
model_rand <- nonprobMI_nn(
model_rand <- nonprob_mi_nn(
data = X_nons,
query = X_rand,
k = control$k,
Expand All @@ -42,7 +42,7 @@ nn_nonprobsvy <- function(outcome,
# FUN=\(x) mean(sample_nonprob$short_[x])
)
} else {
model_rand <- nonprobMI_nn(
model_rand <- nonprob_mi_nn(
data = X_nons,
query = t(as.matrix(pop_totals / pop_totals[1])),
k = control$k,
Expand Down Expand Up @@ -73,7 +73,7 @@ nn_nonprobsvy <- function(outcome,
}


nonprobMI_nn <- function(data,
nonprob_mi_nn <- function(data,
query,
k,
treetype,
Expand Down Expand Up @@ -126,7 +126,7 @@ nn_exact <- function(pi_ij,
y_nons_b <- y[boot_samp]
x_nons_b <- X_nons[boot_samp, , drop = FALSE]

YY <- nonprobMI_nn(
YY <- nonprob_mi_nn(
data = x_nons_b,
query = X_rand,
k = k,
Expand Down
Loading

0 comments on commit 76888f0

Please sign in to comment.