Skip to content

Commit

Permalink
Merge pull request #84 from fasrc/release_v_0.2.5
Browse files Browse the repository at this point in the history
Release v 0.2.5
  • Loading branch information
Naeemkh authored Jul 23, 2021
2 parents 3b42660 + 53ac520 commit 42a939e
Show file tree
Hide file tree
Showing 113 changed files with 718 additions and 8,250 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
index.md
^doc$
^Meta$
^CRAN-RELEASE$
^cran-comments\.md$
2 changes: 2 additions & 0 deletions CRAN-RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This package was submitted to CRAN on 2021-07-22.
Once it is accepted, delete this file and tag the release (commit 6e9691a).
15 changes: 7 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: CausalGPS
Type: Package
Title: Matching on generalized propensity scores with continuous exposures
Version: 0.2.4
Title: Matching on Generalized Propensity Scores with Continuous Exposures
Version: 0.2.5
Authors@R: c(
person("Naeem", "Khoshnevis", email = "nkhoshnevis@g.harvard.edu",
role=c("aut","cre"),
Expand All @@ -13,14 +13,14 @@ Authors@R: c(
role=c("aut"),
comment = c(ORCID = "0000-0002-5177-8598", AFFILIATION="HSPH")))
Maintainer: Naeem Khoshnevis <nkhoshnevis@g.harvard.edu>
Description: An R package for implementing matching on generalized propensity
scores with continuous exposures. We developed an innovative approach for
estimating causal effects using observational data in settings with
continuous exposures, and introduce a new framework for GPS caliper matching.
Description: Provides a framework for estimating causal effects of a continuous
exposure using observational data, and implementing matching and weighting
on the generalized propensity score.
Wu, X., Mealli, F., Kioumourtzoglou, M.A., Dominici, F. and Braun, D.,
2018. Matching on generalized propensity scores with continuous exposures.
arXiv preprint arXiv:1812.06575.
arXiv preprint <arXiv:1812.06575>.
License: GPL-3
Language: en-US
URL: https://github.com/fasrc/CausalGPS
BugReports: https://github.com/fasrc/CausalGPS/issues
Copyright: Harvard University
Expand All @@ -45,7 +45,6 @@ Imports:
gnm,
tidyr
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.1
Suggests:
knitr,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export(estimate_pmetric_erf)
export(estimate_semipmetric_erf)
export(generate_pseudo_pop)
export(generate_syn_data)
export(get_logger)
export(set_logger)
import(KernSmooth)
import(SuperLearner)
Expand All @@ -27,6 +28,7 @@ import(gam)
import(parallel)
import(polycor)
import(ranger)
import(wCorr)
import(xgboost)
importFrom(Rcpp,sourceCpp)
importFrom(ggplot2,autoplot)
Expand Down
14 changes: 9 additions & 5 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@

## CausalGPS (devloping version)
## CausalGPS 0.2.5 (2021-07-09)

### Added

### Changed

* User needs to activate the logger

### Fixed

* CRAN package URLs are in canonical forms.

### Removed

## CausalGPS 0.2.4 (2021-07-11)
Expand Down Expand Up @@ -40,7 +44,7 @@

### Fixed

* RCpp parLapply worker processors arguments
* Rcpp parLapply worker processors arguments

### Removed

Expand Down Expand Up @@ -85,7 +89,7 @@
* create_weighting.R
* Steps for adding test data into 'sysdata.rda'.
* `weighting` option as causal inference approach.
* absoulte_weighted_corr_fun.R
* absolute_weighted_corr_fun.R
* Testing and running example guidelines for developers
* Customized wrapper for xgboost package.
* `param` as an argument to accept hyperparameters from users.
Expand All @@ -97,8 +101,8 @@
* mclapply --> parLapply
* estimate_erf output returns S3 object.
* test-Covariate_balance.R --> test-absolute_corr_fun.R
* covarate_balance.R --> absolute_corr_fun.R
* User needs to pass `m_xgboost` instead of `SL.xgboost` to use XGBoost package for prediciton purposes.
* covariate_balance.R --> absolute_corr_fun.R
* User needs to pass `m_xgboost` instead of `SL.xgboost` to use XGBoost package for prediction purposes.

### Fixed

Expand Down
3 changes: 2 additions & 1 deletion R/causalgps_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#' @import gam
#' @import KernSmooth
#' @import polycor
#' @import wCorr
#' @importFrom Rcpp sourceCpp
#' @useDynLib CausalGPS, .registration = TRUE
#'
Expand All @@ -33,7 +34,7 @@
#' Matching on generalized propensity scores with continuous exposures.
#' arXiv preprint arXiv:1812.06575.
#'
#' Kennedy, E.H., Ma, Z., McHugh, M.D. and Small, D.S., 2017. Nonparametric
#' Kennedy, E.H., Ma, Z., McHugh, M.D. and Small, D.S., 2017. Non-parametric
#' methods for doubly robust estimation of continuous treatment effects.
#' Journal of the Royal Statistical Society: Series B (Statistical Methodology),
#' 79(4), pp.1229-1245.
Expand Down
11 changes: 6 additions & 5 deletions R/create_matching.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,17 @@ create_matching <- function(dataset, bin_seq = NULL, gps_model = "parametric",

}

logger::log_debug(used_bin, "bin seq is used. Min: {min(bin_num)} ",
"Max: {max(bin_num)}, count: {length(bin_num)}.")
logger::log_debug(used_bin, "bin seq is used. Min: {min(bin_num)} ",
"Max: {max(bin_num)}, count: {length(bin_num)}.")

logger::log_debug("Started generating matched set ...")
st_t_m <- proc.time()
logger::log_debug("Started generating matched set ...")
st_t_m <- proc.time()

lfp <- get_options("logger_file_path")

p_c_t_s <- proc.time()
cl <- parallel::makeCluster(nthread, type="PSOCK",
outfile="CausalGPS.log")
outfile= lfp)


parallel::clusterEvalQ(cl, {library("CausalGPS")})
Expand Down
2 changes: 1 addition & 1 deletion R/create_weighting.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' - counter
#' - row_index
#' - ipw
#' - covaraites
#' - covariates
#'
#' @keywords internal
#'
Expand Down
23 changes: 3 additions & 20 deletions R/generate_pseudo_pop.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' - "matching": Matching by GPS
#' - "weighting": Weighting by GPS
#' - "adjusting": Adjusting by GPS
#' @param pred_model a prediction model
#' @param pred_model a prediction model (use "sl" for SuperLearner)
#' @param gps_model Model type which is used for estimating GPS value, including
#' parametric (default) and non-parametric.
#' @param use_cov_transform If TRUE, the function uses transformer to meet the
Expand All @@ -33,10 +33,6 @@
#' (default: c(0.01,0.99)).
#' @param optimized_compile If TRUE, uses counts to keep track of number of
#' replicated pseudo population.
#' @param save_output If TRUE, output results will be stored at the save.path.
#' Default is FALSE.
#' @param save_path location for storing the final results, format of the saved
#' 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 the number of threads to be
Expand All @@ -57,7 +53,7 @@
#' - *max_attempt*: maximum number of attempt to satisfy covariate balance.
#' - See [create_matching()] for more details about the parameters and default
#' values.
#' - if ci.appr = 'weightig':
#' - if ci.appr = 'weighting':
#' - *covar_bl_method*: Covariate balance method.
#' - *covar_bl_trs*: Covariate balance threshold
#' - *max_attempt*: Maximum number of attempt to satisfy covariate balance.
Expand Down Expand Up @@ -113,8 +109,6 @@ generate_pseudo_pop <- function(Y,
bin_seq = NULL,
trim_quantiles = c(0.01,0.99),
optimized_compile = FALSE,
save_output = FALSE,
save_path = NULL,
params = list(),
nthread = 1,
...){
Expand Down Expand Up @@ -309,17 +303,6 @@ generate_pseudo_pop <- function(Y,
message(paste("Best Mean absolute correlation: ", best_ach_covar_balance,
"| Covariate balance threshold: ", covar_bl_trs))

## Store output ---------------------------------

if (save_output){
if (!missing(save_path)){
#TODO: Implement a function to write the output into disk or database.
message('Saving data on disk is not implemented.')
} else {
warning('The output for storing data is not provided. This command is
ignored.')
}
}
result <- list()
class(result) <- "gpsm_pspop"

Expand Down Expand Up @@ -360,7 +343,7 @@ pow3 <- function(x) {x^3}
#'
#' @param c_name column (attribute) name.
#' @param c_val column value
#' @param transformer transformer funciton.
#' @param transformer transformer function.
#'
#' @keywords internal
#'
Expand Down
5 changes: 5 additions & 0 deletions R/generate_wrap_sl_lib.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#'
#' @keywords internal
#'
#' @return
#' Returns A Boolean value. TRUE if the modified library for the given library is
#' implemented; otherwise, it returns FALSE. This function is called for side
#' effects.
#'
gen_wrap_sl_lib <- function(lib_name, params, nthread){

# ------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion R/matching_l1.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' Matching function using L1 distance on single exposure level w
#'
#' @param dataset a completed observational data frame or matrix containing
#' (Y, w, gps, couner, row_index, c).
#' (Y, w, gps, counter, row_index, c).
#' @param e_gps_pred a vector of predicted gps values obtained by Machine
#' learning methods.
#' @param e_gps_std_pred a vector of predicted std of gps obtained by
Expand Down
8 changes: 7 additions & 1 deletion R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ autoplot.gpsm_erf <- function(object, ...){
#' @param x A gpsm_erf object.
#' @param ... Additional arguments passed to customize the plot.
#'
#' @return
#' Returns a ggplot2 object, invisibly. This function is called for side effects.
#'
#' @export
#'
plot.gpsm_erf <- function(x, ...){
Expand Down Expand Up @@ -156,10 +159,13 @@ autoplot.gpsm_pspop <- function(object, ...){
#' @param x A gpsm_erf object.
#' @param ... Additional arguments passed to customize the plot.
#'
#' @return
#' Returns a ggplot2 object, invisibly. This function is called for side effects.
#'
#' @export
#'
plot.gpsm_pspop <- function(x, ...){
g <- ggplot2::autoplot(x, ...)
print(g)
invisible(g)
}
}
6 changes: 4 additions & 2 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#' @param ... Additional arguments passed to customize the results.
#'
#' @return
#' NULL
#' No return value. This function is called for side effects.
#'
#' @export
#'
print.gpsm_erf <- function(x, ...){
Expand Down Expand Up @@ -67,7 +68,8 @@ summary.gpsm_erf <- function(object, ...){
#' @param ... Additional arguments passed to customize the results.
#'
#' @return
#' NULL
#' No return value. This function is called for side effects.
#'
#' @export
#'
print.gpsm_pspop <- function(x, ...){
Expand Down
52 changes: 46 additions & 6 deletions R/set_logger.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,44 @@
#' Updates logger settings, including log level and location of the file.
#'
#' @param logger_file_path A path (including file name) to log the messages.
#' (Default: CausalGPS.log)
#' @param logger_level The log level. Available levels include:
#' - TRACE
#' - DEBUG
#' - INFO
#' - INFO (Default)
#' - SUCESS
#' - WARN
#' - ERROR
#' - FATAL
#'
#' @export
#'
#' @return
#' No return value. This function is called for side effects.
#'
#' @examples
#'
#' set_logger("Debug")
#'
set_logger <- function(logger_file_path=NULL, logger_level=NULL){
set_logger <- function(logger_file_path= "CausalGPS.log", logger_level="INFO"){

available_levels <- c("TRACE", "DEBUG", "INFO", "SUCCESS", "WARN",
"ERROR", "FATAL")

if (!is.element(logger_level, available_levels)){
stop(paste("logger_level: ", logger_level, " is not valid."))
}

#assign("logger_file_path", logger_file_path, envir = log_env)

logger::log_appender(appender = logger::appender_file(logger_file_path),
index = 1)

set_options("logger_file_path", logger_file_path)
set_options("logger_level", logger_level)

#create_matching$logger_file_path <- logger_file_path

if (!is.null(logger_level)){
if (is.element(logger_level, available_levels)){

Expand All @@ -33,10 +51,32 @@ set_logger <- function(logger_file_path=NULL, logger_level=NULL){
} else {
stop(paste("Logger level is not valid. Available levels: ", paste(available_levels, collapse = " ")))
}
} else {
logger::log_threshold(logger::INFO,index = 1)
}
}

if (!is.null(logger_file_path)){
logger::log_appender(appender = logger::appender_file(logger_file_path),
index = 2)
}
#' @title
#' Get Logger Settings
#'
#' @description
#' Returns current logger settings.
#'
#'
#' @return
#' Returns a list that includes **logger_file_path** and **logger_level**.
#'
#' @export
#'
#' @examples
#'
#' set_logger("mylogger.log", "INFO")
#' log_meta <- get_logger()
#'
get_logger <- function(){

return(list(logger_file_path = get_options("logger_file_path"),
logger_level = get_options("logger_level")))
}


6 changes: 5 additions & 1 deletion R/train_it.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#' Funtction to develop prediction model based on user's preferences.
#' @title
#' Generate Prediction Model
#'
#' @description
#' Function to develop prediction model based on user's preferences.
#'
#' @param target A vector of target data.
#' @param input A vector, matrix, or dataframe of input data.
Expand Down
Loading

0 comments on commit 42a939e

Please sign in to comment.