-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All methods accessible via causens API (#54)
- Loading branch information
1 parent
f36a45c
commit 53dfdf9
Showing
13 changed files
with
111 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#' @title Bayesian Estimation of ATE Subject to Unmeasured Confounding | ||
#' | ||
#' @description This function provides an estimate of the Average Treatment | ||
#' Effect (ATE) using Bayesian modelling. | ||
#' | ||
#' @param fitted_model The treatment model object as a glm. | ||
#' @param exposure The name of the exposure variable. | ||
#' @param outcome The name of the outcome variable. | ||
#' @param data A data frame containing the exposure, outcome, and confounder variables. | ||
#' @param ... Additional arguments to be passed to the sensitivity function. | ||
#' | ||
#' @return A point estimate of the corrected ATE. | ||
#' @export | ||
causens_sf <- function(fitted_model, exposure, outcome, data, ...) { | ||
y <- data[[outcome]] | ||
z <- data[[exposure]] | ||
|
||
e <- predict(fitted_model, type = "response") | ||
|
||
c1 <- sf(z = 1, e = e, ...) | ||
c0 <- sf(z = 0, e = 1 - e, ...) | ||
|
||
# Calculate the Average Treatment Effect | ||
weights <- 1 / ifelse(z == 1, e, 1 - e) | ||
|
||
if (all(y %in% c(0, 1))) { | ||
Y_sf <- y * (abs(1 - z - e) + exp((-1)**(z == 1) * ifelse(z, c1, c0) * abs(z - e))) | ||
} else { | ||
Y_sf <- y + (-1)**(z == 1) * abs(z - e) * ifelse(z, c1, c0) | ||
} | ||
|
||
# Potential outcomes corrected w.r.t. sensitivity function | ||
Y1_sf <- sum((Y_sf * weights)[z == 1]) / sum(weights[z == 1]) | ||
Y0_sf <- sum((Y_sf * weights)[z == 0]) / sum(weights[z == 0]) | ||
|
||
estimated_ate <- Y1_sf - Y0_sf | ||
|
||
return(estimated_ate) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters