-
Notifications
You must be signed in to change notification settings - Fork 0
/
trial.r
executable file
·131 lines (111 loc) · 3.58 KB
/
trial.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/RScript
# ----------------------------------------------------
# Setup:
# Set working directory in R shell to 'trialsim'.
#
# Command line:
# > source("./trial.r")
# > runtrial()
#
# To plot the response distributions:
# > getDensities()
# > getBoxplot()
#
# Shiny (shiny library loaded in .rProfile):
# library(shiny)
# > runApp()
# ----------------------------------------------------
# # ----------------------------------------------------
# # Reset environment and initialize path.
# rm(list=ls())
# base_path <- getwd()
# engine_path <- "/engine/"
# # ----------------------------------------------------
# ----------------------------------------------------
# Load directly.
source("./utils.R")
source("./generateData.R")
source("./metaManagement.R")
source("./createTreatments.R")
source("./initialChar.R")
source("./operators.R")
source("./parseCharInput.R")
source("./validNames.R")
source("./createCovariates.R")
source("./allocateTreatments.R")
source("./createParameters.R")
source("./ectdStop.R")
source("./createNormalParameters.R")
source("./parseCovMatrix.R")
source("./checkSymmetricPDMatrix.R")
# Added separately.
source("./mvrnorm.R")
source("./createResponse.R")
source("./createResponseVariable.R")
source("./addResidualError.R")
# ----------------------------------------------------
# ----------------------------------------------------
# Load engine.
# setwd(paste(base_path, engine_path, sep=""))
# lapply(list.files(pattern = "[.][Rr]$", recursive = TRUE), source)
#
# # Return to simulation.
# setwd(base_path)
#
# # Required for 'mvrnorm' in 'createNmParSamples.R'.
# # library(MASS)
# library(ggplot2)
# ----------------------------------------------------
# ----------------------------------------------------
# Dose-response equation:
# E(dose) = E0 + ((dose * Emax)/(dose + ed50))
# ----------------------------------------------------
replicateN <- 1
e0 <- 0
ed50 <- 4
emax <- 10
patients <- 50
d1 <- 0
d2 <- 4
d3 <- 10
d4 <- 40
d5 <- 80
treatDoses <- c(d1, d2, d3, d4, d5)
genParNames <- "E0,ED50,EMAX"
genParMean <- c(e0, ed50, emax)
genParVCov <- c(.5, 1, 1)
respEqn <- "E0 + ((DOSE * EMAX)/(DOSE + ED50))"
respVCov <- 2
interimSubj <- ".3, .7"
n <- patients
gen_par_mean <- genParMean
treat_doses <- treatDoses
o <- generateData(replicateN, subjects=n, treatDoses=treat_doses,
genParNames=genParNames, genParMean=genParMean,
genParVCov=genParVCov, respEqn=respEqn,
respVCov=respVCov, interimSubj=interimSubj)
print("Data returned as variable 'o'")
return(o)
# ----------------------------------------------------
# ----------------------------------------------------
# Visualization.
# Data has to be reloaded for visualization because otherwise
# new data resulting from a new simulation is not updated.
getDensities <- function(r=o) {
#r <- read.csv("./ReplicateData/replicate0001.csv", header=T)
g <- ggplot(r, aes(RESP, fill=as.factor(DOSE))) + geom_density(alpha=0.2)
g
}
getBoxplots <- function(r=o) {
#r <- read.csv("./ReplicateData/replicate0001.csv", header=T)
g <- ggplot(r, aes(as.factor(DOSE), y=RESP)) + geom_boxplot()
g
}
# ----------------------------------------------------
# ----------------------------------------------------
# 'emaxCode' is executed as 'analysisCode' on each replicate.
# source("./00_analysis.r")
# analyzeData(analysisCode=emaxCode,
# macroCode=macroCode,
# interimCode=interimCode)
# ----------------------------------------------------