This file contains hidden or 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
################ | |
# Markov model # | |
################ | |
## Model set-up ---- | |
t_names <- c("without_drug", "with_drug") | |
n_treatments <- length(t_names) | |
s_names <- c("Asymptomatic_disease", "Progressive_disease", "Dead") |
This file contains hidden or 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
ce_res <- ce_markov(start_pop = c(0, 1), | |
p_matrix, | |
c_matrix, | |
q_matrix) | |
# | |
ce_markov <- function(start_pop, | |
p_matrix, | |
c_matrix, | |
q_matrix, |
This file contains hidden or 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
R: Presenting outputs | |
======================================================== | |
author: Dr N Green | |
date: March 2018 | |
autosize: false | |
width: 2440 | |
height: 1200 | |
css: custom.css | |
This file contains hidden or 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
#' Decision Tree Expected Values | |
#' | |
#' \deqn{C_i = \sum p_{ij} (C_{ij} + C_j)} | |
#' | |
#' @param vals Values on each edge (array) e.g. costs or QALYs | |
#' @param p Transition probabilities (array) | |
#' | |
#' @return expected value at each node (list) | |
#' @export |
This file contains hidden or 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
#' Branch Joint Probability | |
#' | |
#' @param probs Branch conditional probabilities (array) | |
#' | |
#' @return | |
#' @export | |
#' | |
#' @examples | |
#' branch_joint_probs(probs) * cost | |
#' |
This file contains hidden or 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
library(Rfast) | |
library(utils) | |
prob_test_outcome_combination <- function(prob, | |
n_choose) { | |
p_comb <- combn(x = prob, m = n_choose) | |
n_comb <- combn(x = 1 - prob, m = length(prob) - n_choose) | |
This file contains hidden or 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
two_test_parallel_AND <- function(sens, spec) { | |
list( | |
sensitivity = sens*sens, | |
specificity = spec + spec - spec*spec) | |
} | |
three_test_parallel_AND_2 <- function(sens, spec) { | |
list( |
This file contains hidden or 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
## ----setup, include=FALSE------------------------------------------------ | |
knitr::opts_chunk$set(echo = TRUE) | |
## ---- eval=T,echo=T------------------------------------------------------ | |
a <- 1 | |
b <- 2 | |
c <- -1 | |
d <- 2 | |
# Check if two values are the same. Note the difference between |
This file contains hidden or 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
## ----setup, include=FALSE------------------------------------------------ | |
knitr::opts_chunk$set(echo = TRUE) | |
## ---- echo=T, eval=T----------------------------------------------------- | |
2 + 2 | |
## ---- echo=T, eval=T----------------------------------------------------- | |
a <- 2 + 2 | |
## ---- echo=T,eval=T------------------------------------------------------ |
This file contains hidden or 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
#--run in the old version of R | |
setwd("C:/Temp/") | |
packages <- installed.packages()[,"Package"] | |
save(packages, file="Rpackages") | |
Followed by this in the new version: | |
#--run in the new version | |
setwd("C:/Temp/") | |
load("Rpackages") | |
for (p in setdiff(packages, installed.packages()[,"Package"])) |
NewerOlder