Skip to content

Commit

Permalink
rebuilding readme
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertASmith committed Jan 1, 2024
1 parent ca905ae commit 9171e27
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 16 deletions.
4 changes: 2 additions & 2 deletions R/check_trans_probs.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ check_array_names_complete <- function(a_P, stop_if_not = F){
#' diag(a_P[,,x]) <- 1 - rowSums(a_P[,,x])
#' }
#'
#' check_trans_prob_array(a_P = a_P, confirm_ok = F)
#' check_trans_prob_array(a_P = a_P, stop_if_not = F)
#' # introduce error
#' a_P["H", "S", 1:10] <- 0
#'
#' check_trans_prob_array(a_P = a_P, confirm_ok = F)
#' check_trans_prob_array(a_P = a_P, stop_if_not = F)
#'
#' }
#'
Expand Down
64 changes: 56 additions & 8 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

<!--
<!-- README.md is generated from README.Rmd. Please edit that file
You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date. `devtools::build_readme()` is handy for this.
-->

```{r, include = FALSE}
Expand All @@ -23,6 +19,7 @@ knitr::opts_chunk$set(

<!-- badges: start -->
[![R-CMD-check](https://github.com/dark-peak-analytics/assertHE/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/dark-peak-analytics/assertHE/actions/workflows/R-CMD-check.yaml)

<!-- badges: end -->

The goal of assertHE is to identify errors and bugs in health economic evaluation models early in the development process.
Expand All @@ -42,13 +39,64 @@ library(assertHE)

This is a basic example which shows you how to solve a common problem:

```{r example}
```{r example, eval = FALSE}
library(assertHE)
# create a transition probability array
n_t <- 1000 # number of cycles
v_hs_names <- c("H", "S", "D") # health states
n_hs <- length(v_hs_names)
## basic example code
# create array of transition probabilities
a_P <- array(
data = 0,
dim = c(n_hs, n_hs, n_t),
dimnames = list(v_hs_names, v_hs_names, 1:n_t)
)
# fill in transition probabilities for main transitions.
a_P["H", "S",] <- 0.3
a_P["H", "D",] <- 0.01
a_P["S", "D",] <- 0.1
a_P["S", "H",] <- 0.5
# Fill in the proportion remaining in health state in each slice.
# This is the remainder after all other transitions are accounted for.
for(x in 1:n_t){
diag(a_P[,,x]) <- 1 - rowSums(a_P[,,x])
}
# Use the function from the package.
# This check should return no error, the array is symmetric, numeric, values
# are between 0 and 1 and all rows sum to 1.
# Note: stop_if_not = F returns warnings, stop_if_not = T returns errors.
check_trans_prob_array(a_P = a_P,
stop_if_not = T)
# We can introduce an error to see the output
# In this case, we set the first 10 cycles of transition from H to S to 0.
# This means that the rows don't sum to 1 for the H row for 1:10 cycle.
a_P["H", "S", 1:10] <- 0
check_trans_prob_array(a_P = a_P,
stop_if_not = F)
# The output looks like this:
# Warning message:
# In check_array_rows_balanced(a_P, stop_if_not = stop_if_not) :
# Not valid transition probabilities
# Transition probabilities not valid from Health States:
# 1 H; at cycle 1
# 2 H; at cycle 2
# 3 H; at cycle 3
# 4 H; at cycle 4
# 5 H; at cycle 5
# 6 H; at cycle 6
# 7 H; at cycle 7
# 8 H; at cycle 8
# 9 H; at cycle 9
# 10 H; at cycle 10
```

Expand Down
65 changes: 59 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->
<!--
&#10;You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date. `devtools::build_readme()` is handy for this.
&#10;-->
<!-- README.md is generated from README.Rmd. Please edit that file
You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date. `devtools::build_readme()` is handy for this.
-->

# assertHE

<!-- badges: start -->

[![R-CMD-check](https://github.com/dark-peak-analytics/assertHE/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/dark-peak-analytics/assertHE/actions/workflows/R-CMD-check.yaml)

<!-- badges: end -->

The goal of assertHE is to identify errors and bugs in health economic
Expand All @@ -33,8 +33,61 @@ This is a basic example which shows you how to solve a common problem:
``` r
library(assertHE)


## basic example code
# create a transition probability array
n_t <- 1000 # number of cycles
v_hs_names <- c("H", "S", "D") # health states
n_hs <- length(v_hs_names)

# create array of transition probabilities
a_P <- array(
data = 0,
dim = c(n_hs, n_hs, n_t),
dimnames = list(v_hs_names, v_hs_names, 1:n_t)
)

# fill in transition probabilities for main transitions.
a_P["H", "S",] <- 0.3
a_P["H", "D",] <- 0.01
a_P["S", "D",] <- 0.1
a_P["S", "H",] <- 0.5

# Fill in the proportion remaining in health state in each slice.
# This is the remainder after all other transitions are accounted for.
for(x in 1:n_t){
diag(a_P[,,x]) <- 1 - rowSums(a_P[,,x])
}

# Use the function from the package.
# This check should return no error, the array is symmetric, numeric, values
# are between 0 and 1 and all rows sum to 1.
# Note: stop_if_not = F returns warnings, stop_if_not = T returns errors.
check_trans_prob_array(a_P = a_P,
stop_if_not = T)

# We can introduce an error to see the output
# In this case, we set the first 10 cycles of transition from H to S to 0.
# This means that the rows don't sum to 1 for the H row for 1:10 cycle.
a_P["H", "S", 1:10] <- 0

check_trans_prob_array(a_P = a_P,
stop_if_not = F)

# The output looks like this:

# Warning message:
# In check_array_rows_balanced(a_P, stop_if_not = stop_if_not) :
# Not valid transition probabilities
# Transition probabilities not valid from Health States:
# 1 H; at cycle 1
# 2 H; at cycle 2
# 3 H; at cycle 3
# 4 H; at cycle 4
# 5 H; at cycle 5
# 6 H; at cycle 6
# 7 H; at cycle 7
# 8 H; at cycle 8
# 9 H; at cycle 9
# 10 H; at cycle 10
```

[Robert Smith](https://www.linkedin.com/in/robert-smith-53b28438) <sup>
Expand Down

0 comments on commit 9171e27

Please sign in to comment.