Skip to content

Commit

Permalink
Merge pull request #80 from fasrc/polish_doc
Browse files Browse the repository at this point in the history
make compile_pseudo_population public.
  • Loading branch information
Naeemkh authored Jul 11, 2021
2 parents a06c1b2 + 38b5ee8 commit 9d70b1d
Show file tree
Hide file tree
Showing 65 changed files with 334 additions and 163 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ S3method(summary,gpsm_pspop)
export(absolute_corr_fun)
export(absolute_weighted_corr_fun)
export(check_covar_balance)
export(compile_pseudo_pop)
export(estimate_gps)
export(estimate_npmetric_erf)
export(estimate_pmetric_erf)
Expand Down
28 changes: 22 additions & 6 deletions R/check_arguments.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@ check_args <- function(pred_model, ci_appr,

# ------------------------------------------------------

required_args <- NULL
required_args <- max_attempt <- NULL

dot_args <- list(...)
arg_names <- names(dot_args)

for (i in arg_names){
assign(i,unlist(dot_args[i],use.names = FALSE))
}

check_args_estimate_gps(pred_model, gps_model, ...)
check_args_generate_pseudo_pop(max_attempt = max_attempt)
check_args_compile_pseudo_pop(ci_appr, use_cov_transform,
transformers, trim_quantiles,
optimized_compile, ...)
Expand Down Expand Up @@ -93,6 +101,17 @@ check_args_estimate_gps <- function(pred_model, gps_model, ...){
invisible(TRUE)
}

check_args_generate_pseudo_pop <- function(max_attempt){

if (!is.numeric(max_attempt)){
stop(paste(max_attempt, " is not acceptible for max_attempt. Should be a
numeric value."))
}

invisible(TRUE)
}



#' @title
#' Check compile_pseudo_pop function arguments
Expand Down Expand Up @@ -146,7 +165,7 @@ check_args_compile_pseudo_pop <- function(ci_appr, use_cov_transform,
# checkpoint 2 ------------------------------------------
if (ci_appr == 'matching'){
required_args <- c(required_args, 'covar_bl_method', 'covar_bl_trs',
'max_attempt', 'matching_fun', 'delta_n', 'scale')
'matching_fun', 'delta_n', 'scale')
}

# checkpoint 3 ------------------------------------------
Expand Down Expand Up @@ -182,10 +201,7 @@ check_args_compile_pseudo_pop <- function(ci_appr, use_cov_transform,
scale))
}

if (!is.numeric(max_attempt)){
stop(paste(max_attempt, " is not acceptible for max_attempt. Should be a
numeric value."))
}

}
invisible(TRUE)
}
Expand Down
51 changes: 48 additions & 3 deletions R/compile_pseudo_pop.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' @title
#' Compile pseudo population
#' Compile Pseudo Population
#'
#' @description
#' Compiles pseudo population based on the original population and estimated GPS
Expand All @@ -13,13 +13,58 @@
#' - gps_mx (min and max of gps)
#' - w_mx (min and max of w).
#' @param ci_appr Causal inference approach.
#' @param gps_model Model type which is used for estimating GPS value, including
#' parametric and non-parametric.
#' @param bin_seq Sequence of w (treatment) to generate pseudo population. If
#' NULL is passed the default value will be used, which is
#' `seq(min(w)+delta_n/2,max(w), by=delta_n)`.
#' @param nthread An integer value that represents the number of threads to be
#' used by internal packages.
#' @param trim_quantiles A numerical vector of two. Represents the trim quantile
#' level. Both numbers should be in the range of \[0,1] and in increasing order
#' (default: c(0.01,0.99)).
#' @param optimized_compile If TRUE, uses counts to keep track of number of
#' replicated pseudo population.
#' @param ... Additional parameters.
#'
#' @keywords internal
#' @note
#' The input data set should be output of estimate_gps function with
#' internal_use flag activated.
#'
#' @export
#'
#' @return
#' `compile_pseudo_pop` returns the pseudo population data that is compiled based
#' on selected causal inference approach.
#' on the selected causal inference approach.
#'
#' @examples
#'
#' m_d <- generate_syn_data(sample_size = 100)
#' data_with_gps <- estimate_gps(m_d$Y,
#' m_d$treat,
#' m_d[c("cf1","cf2","cf3","cf4","cf5","cf6")],
#' pred_model = "sl",
#' gps_model = "parametric",
#' internal_use = TRUE,
#' params = list(xgb_max_depth = c(3,4,5),
#' xgb_nrounds=c(10,20,30,40,50,60)),
#' nthread = 1,
#' sl_lib = c("m_xgboost")
#' )
#'
#'
#' pd <- compile_pseudo_pop(dataset = data_with_gps,
#' ci_appr = "matching",
#' gps_model = "parametric",
#' bin_seq = NULL,
#' nthread = 1,
#' trim_quantiles = c(0.01, 0.99),
#' optimized_compile=TRUE,
#' matching_fun = "matching_l1",
#' covar_bl_method = 'absolute',
#' covar_bl_trs = 0.1,
#' delta_n = 0.5,
#' scale = 1)
#'
compile_pseudo_pop <- function(dataset, ci_appr, gps_model = "parametric",
bin_seq = NULL, nthread = 1, trim_quantiles,
Expand Down
4 changes: 2 additions & 2 deletions R/generate_pseudo_pop.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
#' file will be detected by the file name extension.
#' @param params Includes list of params that is used internally. Unrelated
#' parameters will be ignored.
#' @param nthread An integer value that represents then number threads to use by
#' internal packages.
#' @param nthread An integer value that represents the number of threads to be
#' used by internal packages.
#' @param ... Additional arguments passed to different models.
#' @details
#' ## Additional parameters
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ reference:
- title: Generate pseudo population
contents:
- generate_pseudo_pop
- compile_pseudo_pop
- check_covar_balance
- title: Outcome models
contents:
Expand Down
4 changes: 2 additions & 2 deletions docs/404.html

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

7 changes: 3 additions & 4 deletions docs/articles/CausalGPS.html

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

7 changes: 3 additions & 4 deletions docs/articles/contribution.html

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

7 changes: 3 additions & 4 deletions docs/articles/estimating_gps.html

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

7 changes: 3 additions & 4 deletions docs/articles/faq.html

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

7 changes: 3 additions & 4 deletions docs/articles/generate_synthetic_data.html

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

7 changes: 3 additions & 4 deletions docs/articles/generating_pseudo_population.html

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

4 changes: 2 additions & 2 deletions docs/articles/index.html

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

7 changes: 3 additions & 4 deletions docs/articles/notes_on_sl_wrapper.html

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

Loading

0 comments on commit 9d70b1d

Please sign in to comment.