Skip to content

Commit e4d6f6d

Browse files
committed
train_gps --> estimate_gps
1 parent 0f26cbe commit e4d6f6d

33 files changed

+156
-195
lines changed

NAMESPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ export(compute_rl_deriv_nn)
1313
export(compute_w_corr)
1414
export(estimate_cerf_gp)
1515
export(estimate_cerf_nngp)
16+
export(estimate_gps)
1617
export(generate_synthetic_data)
1718
export(get_logger)
1819
export(set_logger)
19-
export(train_gps)
2020
import(MASS)
2121
import(Rcpp)
2222
import(RcppArmadillo)

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# GPCERF (developing)
22

33
## Changed
4+
- `estimate_gps` now returns the used exposure level, too.
5+
- `train_gps` --> `estimate_gps`
46
- The nearest neighbor approach does not get `expand` as an input parameter (`n_neighbor` * `expand` --> `n_neighbor`).
57
- The weighted covariate balance now is computed using the wCorr package.
68

R/compute_rl_deriv_gp.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
#' \donttest{
3030
#' set.seed(847)
3131
#' data <- generate_synthetic_data(sample_size = 100)
32-
#' GPS_m <- train_gps(cov_mt = data[,-(1:2)],
33-
#' w_all = data$treat,
34-
#' sl_lib = c("SL.xgboost"),
35-
#' dnorm_log = FALSE)
32+
#' GPS_m <- estimate_gps(cov_mt = data[,-(1:2)],
33+
#' w_all = data$treat,
34+
#' sl_lib = c("SL.xgboost"),
35+
#' dnorm_log = FALSE)
3636
#'
3737
#' wi <- 8.6
3838
#'

R/compute_rl_deriv_nn.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
#' \donttest{
3838
#' set.seed(325)
3939
#' data <- generate_synthetic_data(sample_size = 200)
40-
#' GPS_m <- train_gps(cov_mt = data[,-(1:2)],
41-
#' w_all = data$treat,
42-
#' sl_lib = c("SL.xgboost"),
43-
#' dnorm_log = FALSE)
40+
#' GPS_m <- estimate_gps(cov_mt = data[,-(1:2)],
41+
#' w_all = data$treat,
42+
#' sl_lib = c("SL.xgboost"),
43+
#' dnorm_log = FALSE)
4444
#'
4545
#' wi <- 12.2
4646
#'

R/estimate_cerf_gp.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@
4646
#'
4747
#'
4848
#' # Estimate GPS function
49-
#' GPS_m <- train_gps(cov_mt = data[,-(1:2)],
50-
#' w_all = data$treat,
51-
#' sl_lib = c("SL.xgboost"),
52-
#' dnorm_log = FALSE)
49+
#' GPS_m <- estimate_gps(cov_mt = data[,-(1:2)],
50+
#' w_all = data$treat,
51+
#' sl_lib = c("SL.xgboost"),
52+
#' dnorm_log = FALSE)
5353
#'
5454
#' # exposure values
5555
#' w_all <- seq(0,10,1)

R/estimate_cerf_nngp.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@
5252
#' set.seed(19)
5353
#' data <- generate_synthetic_data(sample_size = 120, gps_spec = 3)
5454
#' # Estimate GPS function
55-
#' GPS_m <- train_gps(cov_mt = data[,-(1:2)],
56-
#' w_all = data$treat,
57-
#' sl_lib = c("SL.xgboost"),
58-
#' dnorm_log = FALSE)
55+
#' GPS_m <- estimate_gps(cov_mt = data[,-(1:2)],
56+
#' w_all = data$treat,
57+
#' sl_lib = c("SL.xgboost"),
58+
#' dnorm_log = FALSE)
5959
#' # exposure values
6060
#' w.all <- seq(0,20,2)
6161
#' cerf_nngp_obj <- estimate_cerf_nngp(data,

R/train_GPS.R R/estimate_gps.R

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#' @title
2-
#' Train a model for generalized propensity score
2+
#' Estimate a model for generalized propensity score
33
#'
44
#' @description
5-
#' Estimates the conditional mean and sd of exposure level as a function of
6-
#' covariates.
5+
#' Estimates a model for generalized propensity score (GPS) using parametric
6+
#' approach.
77
#'
88
#' @param cov_mt A covariate matrix containing all covariates. Each row is a
99
#' data sample and each column is a covariate.
@@ -23,13 +23,13 @@
2323
#' @examples
2424
#' \donttest{
2525
#' data <- generate_synthetic_data(sample_size = 200)
26-
#' GPS_m <- train_gps(cov_mt = data[,-(1:2)],
27-
#' w_all = data$treat,
28-
#' sl_lib = c("SL.xgboost"),
29-
#' dnorm_log = FALSE)
26+
#' GPS_m <- estimate_gps(cov_mt = data[,-(1:2)],
27+
#' w_all = data$treat,
28+
#' sl_lib = c("SL.xgboost"),
29+
#' dnorm_log = FALSE)
3030
#' }
3131

32-
train_gps <- function(cov_mt, w_all, sl_lib, dnorm_log) {
32+
estimate_gps <- function(cov_mt, w_all, sl_lib, dnorm_log) {
3333

3434
logger::log_info("Started estimating GPS values ... ")
3535
t_1 <- proc.time()

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ library("GPCERF")
2525

2626
# Estimate GPS function
2727
# In the future, CausalGPS gps estimation will be used.
28-
GPS_m <- train_GPS(cov_mt = as.matrix(sim_data[,-(1:2)]),
29-
w_all = as.matrix(sim_data$treat))
28+
GPS_m <- estimate_gps(cov_mt = sim_data[,-(1:2)],
29+
w_all = sim_data$treat,
30+
sl_lib = c("SL.xgboost"),
31+
dnorm_log = FALSE)
3032

3133
# exposure values
3234
w_all <- seq(0,20,0.1)

man/calc_ac.Rd

-23
This file was deleted.

man/compute_rl_deriv_gp.Rd

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/compute_rl_deriv_nn.Rd

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/estimate_cerf_gp.Rd

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/estimate_cerf_nngp.Rd

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/train_gps.Rd man/estimate_gps.Rd

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-calc_ac.R

-20
This file was deleted.

tests/testthat/test-compute_deriv_nn.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ test_that("compute_deriv_nn works as expected!", {
22

33
set.seed(765)
44
data <- generate_synthetic_data(sample_size = 200)
5-
GPS_m <- train_gps(cov_mt = data[,-(1:2)],
6-
w_all = data$treat,
7-
sl_lib = c("SL.xgboost"),
8-
dnorm_log = FALSE)
5+
GPS_m <- estimate_gps(cov_mt = data[,-(1:2)],
6+
w_all = data$treat,
7+
sl_lib = c("SL.xgboost"),
8+
dnorm_log = FALSE)
99

1010
wi <- 4.8
1111

tests/testthat/test-compute_deriv_weights_gp.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ test_that("compute_deriv_weights_gp works as expected!", {
22

33
set.seed(9615)
44
data <- generate_synthetic_data(sample_size = 200)
5-
GPS_m <- train_gps(cov_mt = data[, -(1:2)],
6-
w_all = data$treat,
7-
sl_lib = c("SL.xgboost"),
8-
dnorm_log = FALSE)
5+
GPS_m <- estimate_gps(cov_mt = data[, -(1:2)],
6+
w_all = data$treat,
7+
sl_lib = c("SL.xgboost"),
8+
dnorm_log = FALSE)
99

1010
wi <- 4.2
1111
weights <- compute_deriv_weights_gp(w = wi,

tests/testthat/test-compute_m_sigma.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ test_that("compute_m_sigma works as expected!", {
66
w_all <- seq(0, 20, 0.1)
77

88
#Estimate GPS function
9-
GPS_m <- train_gps(cov_mt = data[, -(1:2)],
10-
w_all = data$treat,
11-
sl_lib = c("SL.xgboost"),
12-
dnorm_log = FALSE)
9+
GPS_m <- estimate_gps(cov_mt = data[, -(1:2)],
10+
w_all = data$treat,
11+
sl_lib = c("SL.xgboost"),
12+
dnorm_log = FALSE)
1313

1414
tune_res <- compute_m_sigma(hyperparam = c(0.09, 0.09, 10),
1515
data = data,

tests/testthat/test-compute_posterior_m_nn.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ test_that("compute_posterior_m_nn works as expected.", {
44
data <- generate_synthetic_data(sample_size = 200, gps_spec = 3)
55

66
# Estimate GPS function
7-
GPS_m <- train_gps(cov_mt = data[,-(1:2)],
8-
w_all = data$treat,
9-
sl_lib = c("SL.xgboost"),
10-
dnorm_log = FALSE)
7+
GPS_m <- estimate_gps(cov_mt = data[,-(1:2)],
8+
w_all = data$treat,
9+
sl_lib = c("SL.xgboost"),
10+
dnorm_log = FALSE)
1111

1212
# Hyperparameter
1313
hyperparam <- c(0.1, 0.2, 1)

tests/testthat/test-compute_posterior_sd_nn.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ test_that("compute_posterior_sd_nn works as expected.", {
44
data <- generate_synthetic_data(sample_size = 200, gps_spec = 3)
55

66
# Estimate GPS function
7-
GPS_m <- train_gps(cov_mt = data[, -(1:2)],
8-
w_all = data$treat,
9-
sl_lib = c("SL.xgboost"),
10-
dnorm_log = FALSE)
7+
GPS_m <- estimate_gps(cov_mt = data[, -(1:2)],
8+
w_all = data$treat,
9+
sl_lib = c("SL.xgboost"),
10+
dnorm_log = FALSE)
1111

1212
# Hyperparameter
1313
hyperparam <- c(0.1, 0.2, 1)

tests/testthat/test-compute_rl_deriv_gp.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ test_that("compute_rl_deriv_gp works as expected!", {
22

33
set.seed(127)
44
data <- generate_synthetic_data(sample_size = 200)
5-
GPS_m <- train_gps(cov_mt = data[, -(1:2)],
6-
w_all = data$treat,
7-
sl_lib = c("SL.xgboost"),
8-
dnorm_log = FALSE)
5+
GPS_m <- estimate_gps(cov_mt = data[, -(1:2)],
6+
w_all = data$treat,
7+
sl_lib = c("SL.xgboost"),
8+
dnorm_log = FALSE)
99

1010
wi <- 8.6
1111

tests/testthat/test-compute_rl_deriv_nn.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ test_that("compute_rl_deriv_nn works as expected!", {
22

33
set.seed(325)
44
data <- generate_synthetic_data(sample_size = 200)
5-
GPS_m <- train_gps(cov_mt = data[, -(1:2)],
6-
w_all = data$treat,
7-
sl_lib = c("SL.xgboost"),
8-
dnorm_log = FALSE)
5+
GPS_m <- estimate_gps(cov_mt = data[, -(1:2)],
6+
w_all = data$treat,
7+
sl_lib = c("SL.xgboost"),
8+
dnorm_log = FALSE)
99

1010
wi <- 12.2
1111

tests/testthat/test-compute_sd_gp.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ test_that("compute_sd_gp works as expected.", {
1111
kernel_fn <- function(x) exp(-x^2)
1212

1313
# Estimate GPS function
14-
GPS_m <- train_gps(cov_mt = data[,-(1:2)],
15-
w_all = data$treat,
16-
sl_lib = c("SL.xgboost"),
17-
dnorm_log = FALSE)
14+
GPS_m <- estimate_gps(cov_mt = data[,-(1:2)],
15+
w_all = data$treat,
16+
sl_lib = c("SL.xgboost"),
17+
dnorm_log = FALSE)
1818

1919
GPS <- GPS_m$gps$GPS
2020

0 commit comments

Comments
 (0)