Skip to content

Commit

Permalink
Updated vignettes and plot_est_box
Browse files Browse the repository at this point in the history
Fixed bugs and descriptions in the vignettes and plot_est_box
  • Loading branch information
XiaoYan-Clarence committed Oct 21, 2024
1 parent cf797b1 commit 61ae225
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
9 changes: 6 additions & 3 deletions R/plot_est_box.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ plot_est_box <- function(input, ...) {
UpperCI = upperbd
)

# Alternate label positions to avoid overlap
label_position <- rep(c(1, -1), length.out = nrow(plot_data))

# ggplot2 visualization
ggplot2::ggplot(plot_data, ggplot2::aes(x = Treatment, y = Mean)) +
ggplot2::geom_point(size = 3) +
ggplot2::geom_errorbar(ggplot2::aes(ymin = LowerCI, ymax = UpperCI), width = 0.2, color = "blue") +
ggplot2::labs(title = "Treatment Effect Estimates", x = "Treatment Level", y = "Effect") +
ggplot2::theme_minimal() +
ggplot2::geom_text(ggplot2::aes(y = UpperCI + 0.05, label = paste0("Mean: ", round(Mean, 2))), vjust = -0.5) +
ggplot2::geom_text(ggplot2::aes(y = UpperCI + 0.25, label = paste0("95% CI: [", round(LowerCI, 2), ", ", round(UpperCI, 2), "]")), vjust = -0.5) +
ggplot2::geom_text(ggplot2::aes(y = UpperCI + 0.2 * label_position, label = paste0("Mean: ", round(Mean, 2))), vjust = -0.5) +
ggplot2::geom_text(ggplot2::aes(y = UpperCI + 0.4 * label_position, label = paste0("95% CI: [", round(LowerCI, 2), ", ", round(UpperCI, 2), "]")), vjust = -0.5) +
ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45, hjust = 1)) +
ggplot2::expand_limits(y = max(plot_data$UpperCI) + 0.15)
ggplot2::expand_limits(y = max(plot_data$UpperCI) + 0.5)
}
6 changes: 4 additions & 2 deletions vignettes/bayesmsm-censoring.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ knitr::opts_chunk$set(
- For Step 1, we estimate treatment weights $w_{ij}$ using posterior samples of the $\alpha$ and $\beta$ via fitting a series of logistic regressions in a Bayesian framework. The package incorporates both Inverse Probability of Treatment Weighting (IPTW) and Inverse Probability of Censoring Weighting (IPCW) to handle longitudinal data without and with right-censoring. For Step 2, $P_n(v_{ij})$ is estimated via non-parametric Bayesian bootstrap with $Dir(1,...,1)$ sampling weights.

- The main functions in this package include:

- `bayesweight`: Calculates Bayesian weights for subject-specific treatment effects.
- `bayesweight_cen`: Calculates Bayesian weights for subject-specific treatment effects with right-censored data.
- `bayesmsm`: Estimates marginal structural models using the calculated Bayesian weights.
- `plot_ATE`: Plots the estimated Average Treatment Effect (ATE).
- `plot_APO`: Plots the estimated Average Potential Outcome (APO).
- `plot_est_box`: Plots the distribution of estimated treatment effects.
- `summary_bayesmsm`: Summarizes the model results from `bayesmsm`.

- Installation

Expand Down Expand Up @@ -141,7 +143,7 @@ head(model$bootdata)

# Visualization functions: `plot_ATE`, `plot_APO`, `plot_est_box`

Similarly, we can use the built-in functions `plot_APO` and `summary_bayesmsm` to visualize and summarize the results.
Similarly, we can use the built-in functions as well as `summary_bayesmsm` to visualize and summarize the results.

- Plotting the Average Treatment Effect (ATE)
- The `plot_ATE` function generates a plot of the estimated ATE with its 95% credible interval.
Expand Down
2 changes: 2 additions & 0 deletions vignettes/bayesmsm-nocensoring.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ knitr::opts_chunk$set(
- The main functions in this package include:

- `bayesweight`: Calculates Bayesian weights for subject-specific treatment effects.
- `bayesweight_cen`: Calculates Bayesian weights for subject-specific treatment effects with right-censored data.
- `bayesmsm`: Estimates marginal structural models using the calculated Bayesian weights.
- `plot_ATE`: Plots the estimated Average Treatment Effect (ATE).
- `plot_APO`: Plots the estimated Average Potential Outcome (APO).
- `plot_est_box`: Plots the distribution of estimated treatment effects.
- `summary_bayesmsm`: Summarizes the model results from `bayesmsm`.

- Installation

Expand Down

0 comments on commit 61ae225

Please sign in to comment.