Skip to content

Commit

Permalink
Merge pull request #97 from NSAPH-Software/release_ver0.2.3
Browse files Browse the repository at this point in the history
Release ver0.2.3
  • Loading branch information
Naeemkh authored Mar 2, 2024
2 parents 324519b + 1cd2e7f commit 6918cf7
Show file tree
Hide file tree
Showing 127 changed files with 3,124 additions and 939 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ index.md
^CRAN-RELEASE$
^cran-comments\.md$
^CRAN-SUBMISSION$
^CODE_OF_CONDUCT\.md$
^paper/*$
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
matrix:
config:
- {os: windows-latest, r: 'release'}
#- {os: macOS-latest, r: 'release'} #deactivate until snprintf issue resolves.
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
#- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/draft-pdf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on: [push]

jobs:
paper:
runs-on: ubuntu-latest
name: Paper Draft
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build draft PDF
uses: openjournals/openjournals-draft-action@master
with:
journal: joss
# This should be the path to the paper within your repo.
paper-path: paper/paper.md
- name: Upload
uses: actions/upload-artifact@v1
with:
name: paper
# This is the output path where Pandoc will write the compiled
# PDF. Note, this should be the same directory as the input
# paper.md
path: paper/paper.pdf
126 changes: 126 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall
community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or advances of
any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address,
without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.

Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at nkhoshnevis@g.harvard.edu.
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series of
actions.

**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or permanent
ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within the
community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.1, available at
<https://www.contributor-covenant.org/version/2/1/code_of_conduct.html>.

Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder][https://github.com/mozilla/inclusion].

For answers to common questions about this code of conduct, see the FAQ at
<https://www.contributor-covenant.org/faq>. Translations are available at <https://www.contributor-covenant.org/translations>.

[homepage]: https://www.contributor-covenant.org
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: GPCERF
Title: Gaussian Processes for Estimating Causal Exposure Response Curves
Version: 0.2.2
Version: 0.2.3
Authors@R: c(
person("Naeem", "Khoshnevis", email = "nkhoshnevis@g.harvard.edu",
role=c("aut","cre"),
Expand Down
13 changes: 13 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# GPCERF 0.2.3 (2024-03-02)

## Changed

- `estimate_cerf_nngp` takes `outcome_col`, `treatment_col`, and `covariates_col` names as inputs.
- `estimate_cerf_gp` takes `outcome_col`, `treatment_col`, and `covariates_col` names as inputs.

## Added

- `estimate_cerf_gp` and `estimate_cerf_nngp` have notes on selecting `w`.



# GPCERF 0.2.2 (2024-02-16)

## Changed
Expand Down
2 changes: 1 addition & 1 deletion R/compute_deriv_weights_gp.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' (e_gps_pred).
#' - Column 3: Standard deviation of e_gps (e_gps_std)
#' used_params:
#' - dnorm_log: TRUE or FLASE
#' - dnorm_log: TRUE or FALSE
#' @param hyperparam A vector of hyper-parameters in the GP model.
#' @param kernel_fn The covariance function.
#' @param kernel_deriv_fn The partial derivative of the covariance function.
Expand Down
40 changes: 25 additions & 15 deletions R/compute_m_sigma.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
#' - First element: alpha
#' - Second element: beta
#' - Third element: g_sigma (gamma / sigma)
#' @param data A data.frame containing all data including outcome, exposure
#' and covariates. In the following order:
#' - Column 1: Outcome (Y)
#' - Column 2: Exposure or treatment (w)
#' - Column 3~m: Confounders (C)
#' @param outcome_data A vector of outcome data.
#' @param treatment_data A vector of treatment data.
#' @param covariates_data A data frame of covariates data.
#' @param w A vector of exposure levels at which the CERF is estimated.
#' @param gps_m An S3 gps object including:
#' gps: A data.frame of GPS vectors.
Expand All @@ -37,7 +35,8 @@
#'
#' @keywords internal
#'
compute_m_sigma <- function(hyperparam, data, w, gps_m, tuning,
compute_m_sigma <- function(hyperparam, outcome_data, treatment_data,
covariates_data, w, gps_m, tuning,
kernel_fn = function(x) exp(-x ^ 2)) {

param <- unlist(hyperparam)
Expand All @@ -57,7 +56,7 @@ compute_m_sigma <- function(hyperparam, data, w, gps_m, tuning,
logger::log_trace("Running for tune parameters: ",
"alpha: {alpha}, beta: {beta}, g_sigma: {g_sigma} ...")

w_obs <- data[[2]]
w_obs <- treatment_data

#TODO: Following the paper and alpha beta convention, first column should be
# GPS scaled with alpha, and second column should be w scaled with beta.
Expand All @@ -80,7 +79,7 @@ compute_m_sigma <- function(hyperparam, data, w, gps_m, tuning,

# Estimate noise
if (!tuning) {
noise_est <- estimate_noise_gp(data = data,
noise_est <- estimate_noise_gp(data = outcome_data,
sigma_obs = sigma_obs,
inv_sigma_obs = inv_sigma_obs)
logger::log_debug("Estimated noise: {noise_est} ")
Expand Down Expand Up @@ -112,16 +111,16 @@ compute_m_sigma <- function(hyperparam, data, w, gps_m, tuning,
# est is the same as m in the paper.

if (!tuning) {
est <- data$Y %*% weights_final
est <- outcome_data %*% weights_final
pst_sd <- noise_est * weights_res$sd_scaled
logger::log_trace("Posterior for w = {w_instance} ==> ",
"mu: {est}, var:{pst_sd}")
} else {
est <- NA
pst_sd <- NA
}
cov_balance_obj <- compute_w_corr(w = data[[2]],
covariate = data[, 3:ncol(data)],
cov_balance_obj <- compute_w_corr(w = treatment_data,
covariate = covariates_data,
weight = weights_final)
covariate_balance <- as.vector(cov_balance_obj$absolute_corr)
c(covariate_balance, est, pst_sd)
Expand All @@ -141,17 +140,28 @@ compute_m_sigma <- function(hyperparam, data, w, gps_m, tuning,

# compute original covariate balance of data
if (!tuning) {
cov_balance_obj_org <- compute_w_corr(w = data[[2]],
covariate = data[, 3:ncol(data)],
weight = rep(1, nrow(data)))
cov_balance_obj_org <- compute_w_corr(w = treatment_data,
covariate = covariates_data,
weight = rep(1, nrow(covariates_data)))
cb_org <- cov_balance_obj_org$absolute_corr
} else {
cb_org <- NA
}

if (!is.matrix(col_all)){
# in case of one covariate col_all returns vector instead of matrix
row_name <- names(col_all)[1]
col_all <- matrix(col_all, nrow = 1)
rownames(col_all) <- row_name
}

col_all_w_average <- rowMeans(col_all, na.rm = TRUE)

if (nrow(col_all) == 1){
col_all_w_average <- mean(col_all, na.rm = TRUE)
names(col_all_w_average) <- rownames(col_all)
} else {
col_all_w_average <- rowMeans(col_all, na.rm = TRUE)
}

list(cb = col_all_w_average,
cb_org = cb_org,
Expand Down
Loading

0 comments on commit 6918cf7

Please sign in to comment.