Skip to content

Commit

Permalink
renamed the package (again!) from ModStanR to outstandR
Browse files Browse the repository at this point in the history
  • Loading branch information
n8thangreen committed Jul 29, 2024
1 parent 899470b commit a617ecf
Show file tree
Hide file tree
Showing 69 changed files with 382 additions and 382 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Package: ModStanR
Package: outstandR
Title: Model-based Standardisation
Version: 0.0.0.9000
Authors@R: c(
Expand Down Expand Up @@ -39,5 +39,5 @@ Suggests:
VignetteBuilder: knitr
Config/testthat/edition: 3
RdMacros: Rdpack
URL: https://github.com/StatisticsHealthEconomics/ModStanR/
BugReports: https://github.com/StatisticsHealthEconomics/ModStanR/issues/
URL: https://github.com/StatisticsHealthEconomics/outstandR/
BugReports: https://github.com/StatisticsHealthEconomics/outstandR/issues/
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ S3method(IPD_stats,maic)
S3method(IPD_stats,stc)
export(ALD_stats)
export(IPD_stats)
export(ModStanR)
export(marginal_treatment_effect)
export(marginal_variance)
export(new_strategy)
export(outstandR)
export(strategy_gcomp_ml)
export(strategy_gcomp_stan)
export(strategy_maic)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# ModStanR (development version)
# outstandR (development version)

* Initial CRAN submission.
36 changes: 18 additions & 18 deletions R/ModStanR.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
#' @title Calculate the difference between treatments using all evidence
#'
#' @description
#' This is the main, top-level wrapper for `{ModStanR}`.
#' This is the main, top-level wrapper for `{outstandR}`.
#' Methods taken from
#' \insertCite{RemiroAzocar2022}{ModStanR}.
#' \insertCite{RemiroAzocar2022}{outstandR}.
#'
#' @param AC.IPD Individual-level patient data. Suppose between studies _A_ and _C_.
#' @param BC.ALD Aggregate-level data. Suppose between studies _B_ and _C_.
#' @param strategy Computation strategy function. These can be
#' `strategy_maic()`, `strategy_stc()`, `strategy_gcomp_ml()` and `strategy_gcomp_stan()`
#' @param CI Confidence interval; between 0,1
#' @param ... Additional arguments
#' @return List of length 3 of statistics as a `ModStanR` class object.
#' @return List of length 3 of statistics as a `outstandR` class object.
#' Containing statistics between each pair of treatments.
#' These are the mean contrasts, variances and confidence intervals,
#' respectively.
#' @importFrom Rdpack reprompt
#'
#' @references
#' \insertRef{RemiroAzocar2022}{ModStanR}
#' \insertRef{RemiroAzocar2022}{outstandR}
#'
#' @export
#' @examples
Expand All @@ -29,18 +29,18 @@
#' lin_form <- as.formula("y ~ X3 + X4 + trt*X1 + trt*X2")
#'
#' # matching-adjusted indirect comparison
#' ModStanR_maic <- ModStanR(AC_IPD, BC_ALD, strategy = strategy_maic(formula = lin_form))
#' outstandR_maic <- outstandR(AC_IPD, BC_ALD, strategy = strategy_maic(formula = lin_form))
#'
#' # simulated treatment comparison
#' ModStanR_stc <- ModStanR(AC_IPD, BC_ALD, strategy = strategy_stc(lin_form))
#' outstandR_stc <- outstandR(AC_IPD, BC_ALD, strategy = strategy_stc(lin_form))
#'
#' # G-computation with maximum likelihood
#' # ModStanR_gcomp_ml <- ModStanR(AC_IPD, BC_ALD, strategy = strategy_gcomp_ml(lin_form))
#' # outstandR_gcomp_ml <- outstandR(AC_IPD, BC_ALD, strategy = strategy_gcomp_ml(lin_form))
#'
#' # G-computation with Bayesian inference
#' ModStanR_gcomp_stan <- ModStanR(AC_IPD, BC_ALD, strategy = strategy_gcomp_stan(lin_form))
#' outstandR_gcomp_stan <- outstandR(AC_IPD, BC_ALD, strategy = strategy_gcomp_stan(lin_form))
#'
ModStanR <- function(AC.IPD, BC.ALD, strategy, CI = 0.95, ...) {
outstandR <- function(AC.IPD, BC.ALD, strategy, CI = 0.95, ...) {

if (CI <= 0 || CI >= 1) stop("CI argument must be between 0 and 1.")
##TODO: as method instead?
Expand All @@ -67,21 +67,21 @@ ModStanR <- function(AC.IPD, BC.ALD, strategy, CI = 0.95, ...) {

ald <- BC.ALD[keep_names]

AC_ModStanR <- IPD_stats(strategy, ipd = ipd, ald = ald, ...)
BC_ModStanR <- ALD_stats(ald = ald)
AC_outstandR <- IPD_stats(strategy, ipd = ipd, ald = ald, ...)
BC_outstandR <- ALD_stats(ald = ald)

upper <- 0.5 + CI/2
ci_range <- c(1-upper, upper)

contrasts <- list(
AB = AC_ModStanR$mean - BC_ModStanR$mean,
AC = AC_ModStanR$mean,
BC = BC_ModStanR$mean)
AB = AC_outstandR$mean - BC_outstandR$mean,
AC = AC_outstandR$mean,
BC = BC_outstandR$mean)

contrast_variances <- list(
AB = AC_ModStanR$var + BC_ModStanR$var,
AC = AC_ModStanR$var,
BC = BC_ModStanR$var)
AB = AC_outstandR$var + BC_outstandR$var,
AC = AC_outstandR$var,
BC = BC_outstandR$var)

contrast_ci <- list(
AB = contrasts$AB + qnorm(ci_range)*as.vector(sqrt(contrast_variances$AB)),
Expand All @@ -94,5 +94,5 @@ ModStanR <- function(AC.IPD, BC.ALD, strategy, CI = 0.95, ...) {

structure(stats,
CI = CI,
class = c("ModStanR", class(stats)))
class = c("outstandR", class(stats)))
}
4 changes: 2 additions & 2 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#'
#' @name AC_IPD
#' @docType data
#' @format A data list including the variables needed for the ModStanR basic example. The variables are as follows:
#' @format A data list including the variables needed for the outstandR basic example. The variables are as follows:
#' \describe{
#' \item{list("X1")}{Numeric covariate}
#' \item{list("X2")}{Numeric covariate}
Expand All @@ -25,7 +25,7 @@ NULL
#'
#' @name BC_ALD
#' @docType data
#' @format A data list including the variables needed for the ModStanR basic example. The variables are as follows:
#' @format A data list including the variables needed for the outstandR basic example. The variables are as follows:
#' \describe{
#' \item{list("mean.X1")}{Numeric value}
#' \item{list("mean.X2")}{Numeric value}
Expand Down
4 changes: 2 additions & 2 deletions R/maic.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
#'
#' Matching-adjusted indirect comparison weights.
#' Method is taken from
#' \insertCite{Signorovitch2010}{ModStanR}.
#' \insertCite{Signorovitch2010}{outstandR}.
#'
#' @param X_EM Centred \eqn{S=1} effect modifiers; matrix or data frame
#' @return Estimated weights for each individual; vector
#'
#' @references
#' \insertRef{Signorovitch2010}{ModStanR}
#' \insertRef{Signorovitch2010}{outstandR}
#' @keywords internal
#'
maic_weights <- function(X_EM) {
Expand Down
4 changes: 2 additions & 2 deletions R/performance_measures.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ var.ratio <- function(theta.hat, std.err) {
#' Variability ratio MCSE
#'
#' Approximation of ratio variance based on independence of avg. se and emp.se
#' see \insertCite{wolter2007}{ModStanR}
#' see \insertCite{wolter2007}{outstandR}
#'
#' @param avg.se Average SE
#' @param emp.se Emp SE
#' @param var.avg.se Variance of average SE
#' @param var.emp.se Variance of Emp SE
#'
#' @references
#' \insertRef{wolter2007}{ModStanR}
#' \insertRef{wolter2007}{outstandR}
#'
#' @keywords internal
#'
Expand Down
2 changes: 1 addition & 1 deletion R/print.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#'
print.ModStanR <- function(x, newline = TRUE) {
print.outstandR <- function(x, newline = TRUE) {

cat("\nContrasts:", x$contrasts, "\n")
cat("\nVariances:", x$contrasts_variances, "\n")
Expand Down
4 changes: 2 additions & 2 deletions R/summary.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

#
summary.ModStanR <- function(object, ...) {
summary.outstandR <- function(object, ...) {

ans <- NULL
class(ans) <- "summary.ModStanR"
class(ans) <- "summary.outstandR"
ans
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<!-- badges: start -->

[![R-CMD-check](https://github.com/StatisticsHealthEconomics/ModStanR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/StatisticsHealthEconomics/ModStanR/actions/workflows/R-CMD-check.yaml)
[![R-CMD-check](https://github.com/StatisticsHealthEconomics/outstandR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/StatisticsHealthEconomics/outstandR/actions/workflows/R-CMD-check.yaml)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->

Expand All @@ -24,7 +24,7 @@ and
Install the [development version from GitHub](https://github.com/StatisticsHealthEconomics/) using `remotes`:

```r
remotes::install_github("StatisticsHealthEconomics/ModStanR")
remotes::install_github("StatisticsHealthEconomics/outstandR")
```

## License
Expand All @@ -33,6 +33,6 @@ remotes::install_github("StatisticsHealthEconomics/ModStanR")
## Contributing
Please submit contributions through `Pull Requests`, following the [contributing guidelines](https://github.com/n8thangreen/BCEA/blob/dev/CONTRIBUTING.md).
To report issues and/or seek support, please file a new ticket in the
[issue](https://github.com/StatisticsHealthEconomics/ModStanR/issues) tracker.
[issue](https://github.com/StatisticsHealthEconomics/outstandR/issues) tracker.

Please note that this project is released with a [Contributor Code of Conduct](https://github.com/n8thangreen/BCEA/blob/dev/CONDUCT.md). By participating in this project you agree to abide by its terms.
8 changes: 4 additions & 4 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
url: https://StatisticsHealthEconomics.github.io/ModStanR/
url: https://StatisticsHealthEconomics.github.io/outstandR/

news:
cran_dates: false
Expand All @@ -18,8 +18,8 @@ reference:
- title: "Main"
desc: "Main analysis functions."
contents:
# - ModStanR-package
- starts_with("ModStanR")
# - outstandR-package
- starts_with("outstandR")
- strategy
- title: "Constituent statistics"
desc: "Helper functions used by the main functions."
Expand All @@ -34,4 +34,4 @@ reference:
contents:
- AC_IPD
- BC_ALD


26 changes: 13 additions & 13 deletions doc/Basic_example.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ knitr::opts_chunk$set(
library(boot) # non-parametric bootstrap in MAIC and ML G-computation
library(copula) # simulating BC covariates from Gaussian copula
library(rstanarm) # fit outcome regression, draw outcomes in Bayesian G-computation
library(ModStanR)
library(outstandR)

## ----load-data----------------------------------------------------------------
set.seed(555)
Expand All @@ -25,20 +25,20 @@ BC.ALD
## -----------------------------------------------------------------------------
lin_form <- as.formula("y ~ X3 + X4 + trt*X1 + trt*X2")

## ----ModStanR_maic------------------------------------------------------------
ModStanR_maic <- ModStanR(AC.IPD, BC.ALD, strategy = strategy_maic(formula = lin_form))
## ----outstandR_maic------------------------------------------------------------
outstandR_maic <- outstandR(AC.IPD, BC.ALD, strategy = strategy_maic(formula = lin_form))

## ----ModStanR_maic-print------------------------------------------------------
ModStanR_maic
## ----outstandR_maic-print------------------------------------------------------
outstandR_maic

## ----ModStanR_stc-------------------------------------------------------------
ModStanR_stc <- ModStanR(AC.IPD, BC.ALD, strategy = strategy_stc(formula = lin_form))
ModStanR_stc
## ----outstandR_stc-------------------------------------------------------------
outstandR_stc <- outstandR(AC.IPD, BC.ALD, strategy = strategy_stc(formula = lin_form))
outstandR_stc

## ----ModStanR_gcomp_ml--------------------------------------------------------
# ModStanR_gcomp_ml <- ModStanR(AC.IPD, BC.ALD, strategy = strategy_gcomp_ml(formula = lin_form))
## ----outstandR_gcomp_ml--------------------------------------------------------
# outstandR_gcomp_ml <- outstandR(AC.IPD, BC.ALD, strategy = strategy_gcomp_ml(formula = lin_form))

## ----ModStanR_gcomp_stan------------------------------------------------------
ModStanR_gcomp_stan <- ModStanR(AC.IPD, BC.ALD, strategy = strategy_gcomp_stan(formula = lin_form))
ModStanR_gcomp_stan
## ----outstandR_gcomp_stan------------------------------------------------------
outstandR_gcomp_stan <- outstandR(AC.IPD, BC.ALD, strategy = strategy_gcomp_stan(formula = lin_form))
outstandR_gcomp_stan

38 changes: 19 additions & 19 deletions doc/Basic_example.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ First, let us load necessary packages.
library(boot) # non-parametric bootstrap in MAIC and ML G-computation
library(copula) # simulating BC covariates from Gaussian copula
library(rstanarm) # fit outcome regression, draw outcomes in Bayesian G-computation
library(ModStanR)
library(outstandR)
```

### Data
Expand Down Expand Up @@ -110,10 +110,10 @@ where $\bar{C}$ is the compliment of $C$ so e.g. $n_{\bar{C}} = N_C - n_c$.

## Model fitting in R

The `{ModStanR}` package has been written to be easy to use and essential consists of a single function, `ModStanR()`.
This can be used to run all of the different types of model, which we will call _strategies_. The first two arguments of `ModStanR()` are the individual and aggregate-level data, respectively.
The `{outstandR}` package has been written to be easy to use and essential consists of a single function, `outstandR()`.
This can be used to run all of the different types of model, which we will call _strategies_. The first two arguments of `outstandR()` are the individual and aggregate-level data, respectively.

A `strategy` argument of `ModStanR` takes functions called `strategy_*()`, where the wildcard `*` is replaced by the name of the particular method required, e.g. `strategy_maic()` for MAIC. Each specific example is provided below.
A `strategy` argument of `outstandR` takes functions called `strategy_*()`, where the wildcard `*` is replaced by the name of the particular method required, e.g. `strategy_maic()` for MAIC. Each specific example is provided below.


### MAIC
Expand All @@ -133,20 +133,20 @@ lin_form <- as.formula("y ~ X3 + X4 + trt*X1 + trt*X2")
```


```{r ModStanR_maic}
ModStanR_maic <- ModStanR(AC.IPD, BC.ALD, strategy = strategy_maic(formula = lin_form))
```{r outstandR_maic}
outstandR_maic <- outstandR(AC.IPD, BC.ALD, strategy = strategy_maic(formula = lin_form))
```

The returned object is of class `ModStanR`.
The returned object is of class `outstandR`.

<!-- Wald-type normal distribution-based 95\% confidence interval are also returned. -->

```{r ModStanR_maic-print}
ModStanR_maic
```{r outstandR_maic-print}
outstandR_maic
```

We see that this is a list object with 3 parts, each containing statistics between each pair of treatments. These are the mean contrasts, variances and confidence intervals (CI), respectively.
The default CI is for 95% but can be altered in `ModStanR` with the `CI` argument.
The default CI is for 95% but can be altered in `outstandR` with the `CI` argument.


### STC
Expand All @@ -166,11 +166,11 @@ As already mentioned, running the STC analysis is almost identical to the previo
$$
y = X_3 + X_4 + \beta_t(X_1 - \bar{X_1}) + \beta_t(X_2 - \bar{X_2})
$$
However, `ModStanR()` knows how to handle this so we can simply pass the same (uncentred) formula as before.
However, `outstandR()` knows how to handle this so we can simply pass the same (uncentred) formula as before.

```{r ModStanR_stc}
ModStanR_stc <- ModStanR(AC.IPD, BC.ALD, strategy = strategy_stc(formula = lin_form))
ModStanR_stc
```{r outstandR_stc}
outstandR_stc <- outstandR(AC.IPD, BC.ALD, strategy = strategy_stc(formula = lin_form))
outstandR_stc
```

For the last two approaches, we perform G-computation firstly with a frequentist MLE approach and then a Bayesian approach.
Expand Down Expand Up @@ -199,8 +199,8 @@ $$
$$


```{r ModStanR_gcomp_ml}
# ModStanR_gcomp_ml <- ModStanR(AC.IPD, BC.ALD, strategy = strategy_gcomp_ml(formula = lin_form))
```{r outstandR_gcomp_ml}
# outstandR_gcomp_ml <- outstandR(AC.IPD, BC.ALD, strategy = strategy_gcomp_ml(formula = lin_form))
```


Expand All @@ -223,8 +223,8 @@ The average, variance and interval estimates of the marginal treatment effect ca

We can draw a vector of size $N^*$ of predicted outcomes $y^*_z$ under each set intervention $z^*$ from its posterior predictive distribution under the specific treatment.

```{r ModStanR_gcomp_stan}
ModStanR_gcomp_stan <- ModStanR(AC.IPD, BC.ALD, strategy = strategy_gcomp_stan(formula = lin_form))
ModStanR_gcomp_stan
```{r outstandR_gcomp_stan}
outstandR_gcomp_stan <- outstandR(AC.IPD, BC.ALD, strategy = strategy_gcomp_stan(formula = lin_form))
outstandR_gcomp_stan
```

Loading

0 comments on commit a617ecf

Please sign in to comment.