Skip to content

Commit 52d6b75

Browse files
committed
Merge branch 'main' of gh-private:NovoNordisk-OpenSource/carts into dev
2 parents 23e7248 + d4c00f8 commit 52d6b75

5 files changed

Lines changed: 151 additions & 137 deletions

File tree

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
^misc$
2+
^vignettes/figs/Makefile$
3+
^vignettes/figs/trial-class.tex$
24
^.Rprofile$
35
template.Rmd$
46
^LICENSE\.md$

vignettes/figs/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
%.png:
2+
latexmk -pdf $*
3+
magick convert -density 600 -background white -flatten *.pdf $*.png
4+
latexmk -C

vignettes/figs/trial-class.png

355 KB
Loading

vignettes/figs/trial-class.tex

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
\documentclass[tikz,margin=2mm]{standalone}
2+
% \documentclass[border=0mm]{standalone}
3+
\usepackage{tikz}
4+
\usepackage{amsmath}
5+
\usepackage[utf8]{inputenc}
6+
\usepackage[T2A, T1]{fontenc}
7+
8+
9+
10+
\newcommand{\E}{\mathbb{E}}
11+
\newcommand{\var}{\mathbb{V}\!\!\operatorname{ar}}
12+
\newcommand{\pr}{\mathbb{P}}
13+
\newcommand{\distnb}{\operatorname{NB}}
14+
\newcommand{\distpois}{\operatorname{Pois}}
15+
\newcommand{\distbern}{\operatorname{Bernoulli}}
16+
\newcommand{\distgamma}{\Gamma}
17+
18+
\usetikzlibrary{arrows, calc, positioning, shapes.multipart}
19+
\tikzstyle{arrow} = [thick,->,>=stealth]
20+
\tikzstyle{line} = [draw, -latex']
21+
22+
\tikzstyle{proc} =%
23+
rounded corners,
24+
[rectangle split,
25+
rectangle split parts=2,
26+
rectangle split part fill={blue!20, none},
27+
rectangle split part align={center, left},
28+
text width=5cm, text centered,
29+
draw=black]
30+
31+
\tikzstyle{method} =%
32+
rounded corners,
33+
[rectangle split,
34+
rectangle split parts=2,
35+
rectangle split part fill={red!20, none},
36+
rectangle split part align={center, left},
37+
text width=5cm, text centered,
38+
draw=black]
39+
40+
\begin{document}
41+
42+
\begin{tikzpicture}[node distance = 1.5cm and 1.5cm]
43+
44+
\node (trial) [draw=black, rectangle, fill=orange!10, minimum width=5cm, minimum height=2cm] {\texttt{Trial} class};
45+
46+
\node (covar) [proc, below left=of trial] {
47+
\textbf{\texttt{covariates}} \\
48+
\nodepart{two}
49+
\vspace*{-1.2em}
50+
\begin{flushleft}
51+
Function (arguments \texttt{n, ...}) that generates a list of \texttt{data.table}'s with covariates with each element representing a unique time-point.
52+
\end{flushleft}
53+
};
54+
55+
\node (outcome) [proc, above=of trial] {
56+
\textbf{\texttt{outcome}} \\
57+
\nodepart{two}
58+
\vspace*{-1.2em}
59+
\begin{flushleft}
60+
Function (arguments \texttt{x}: covariate data.table, \texttt{...}: additional
61+
arguments defining parameters of the outcome model) that generates the outcome given covariates.
62+
\end{flushleft}
63+
};
64+
65+
\node (exclusion) [proc, above left=of trial] {
66+
\textbf{\texttt{exclusion}} \\
67+
\nodepart{two}
68+
\vspace*{-1.2em}
69+
\begin{flushleft}
70+
Function (arguments \texttt{data}: data.table, \texttt{...}) that defines exclusion / inclusion criterions for the trial.
71+
\end{flushleft}
72+
};
73+
74+
\node (info) [proc, left=of trial] {
75+
\textbf{\texttt{info}} \\
76+
\nodepart{two}
77+
\vspace*{-1.2em}
78+
\begin{flushleft}
79+
Optional string describing the trial simulation.
80+
\end{flushleft}
81+
};
82+
83+
84+
\node (simulate) [method, above right=of trial] {
85+
\textbf{\$\texttt{simulate}} \\
86+
\nodepart{two}
87+
\vspace*{-1.2em}
88+
\begin{flushleft}
89+
\textit{Simulate data from the specified trial design.}
90+
\textbf{Arguments} \texttt{n}: sample size, \text{...}: additional arguments controlling covariate and outcome parameters. \textbf{Returns} `data.table` as defined by the object initialization with default subject identifier `id` and observation period `num`.
91+
\end{flushleft}
92+
};
93+
94+
\node (run) [method, right=of trial] {
95+
\textbf{\$\texttt{run}} \\
96+
\nodepart{two}
97+
\vspace*{-1.2em}
98+
\begin{flushleft}
99+
\textit{Simulate and estimate parameters several times.}
100+
\textbf{Arguments} \texttt{R}: replications, \texttt{estimators}: list of estimators of the trial target parameter, \texttt{...} additional arguments to the simulation routine. \textbf{Returns} an object with the Monte Carlo simulation results which can be analyzed with the \texttt{summary} method.
101+
\end{flushleft}
102+
};
103+
104+
\node (estimatepower) [method, below=of trial] {
105+
\textbf{\$\texttt{estimate\_power}} \\
106+
\nodepart{two}
107+
\vspace*{-1.2em}
108+
\begin{flushleft}
109+
\textit{Estimate the statistical power of an estimator in a given scenario using Monte Carlo simulations.}
110+
\textbf{Arguments} \texttt{R}: number of replications, \texttt{estimators}: estimator to consider,
111+
\texttt{summary.args}: arguments to the summary method that defines the statistical null hypothesis,
112+
\texttt{...} additional arguments to the simulation routine. \textbf{Returns} estimated power for the given trial scenario.
113+
\end{flushleft}
114+
};
115+
116+
\node (estimatesamplesize) [method, below right=of trial] {
117+
\textbf{\$\texttt{estimate\_samplesize}} \\
118+
\nodepart{two}
119+
\vspace*{-1.2em}
120+
\begin{flushleft}
121+
\textit{Estimate the minimum sample size needed to achieve a desired statistical power of an estimator in a given scenario.}
122+
\textbf{Arguments} \texttt{estimator}, \texttt{power}, \texttt{...} \\
123+
\textbf{Returns} an integer with an attribute 'power' with the actual power estimate.
124+
\end{flushleft}
125+
};
126+
127+
128+
129+
\draw [arrow, dashed] (covar) -- (trial);
130+
\draw [arrow, dashed] (info) -- (trial);
131+
\draw [arrow, dashed] (exclusion) -- (trial);
132+
\draw [arrow, dashed] (outcome) -- (trial);
133+
134+
\draw [arrow] (trial) -- (simulate);
135+
\draw [arrow] (trial) -- (run);
136+
\draw [arrow] (trial) -- (estimatepower);
137+
\draw [arrow] (trial) -- (estimatesamplesize);
138+
139+
\end{tikzpicture}
140+
\end{document}

vignettes/gettingstarted.Rmd

Lines changed: 5 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -39,139 +39,7 @@ visualized in Figure 1. To this end, we will consider a two-armed parallel trial
3939
design to introduce the `Trial` class and demonstrate how power and sample size
4040
estimation are carried out conveniently.
4141

42-
\caption{
43-
}
44-
```{tikz ex1}
45-
%| engine: tikz
46-
%| out.width: 100%
47-
%| echo: false
48-
%| fig.ext: png
49-
%| cache: true
50-
%| fig.cap: >
51-
%| The 'Trial' R6 reference class. The blue boxes define the
52-
%| arguments to the constructor, and the red boxes the most
53-
%| important class methods.
54-
\usetikzlibrary{arrows, calc, positioning, shapes.multipart}
55-
\tikzstyle{arrow} = [thick,->,>=stealth]
56-
\tikzstyle{line} = [draw, -latex']
57-
58-
\tikzstyle{proc} =%
59-
rounded corners,
60-
[rectangle split,
61-
rectangle split parts=2,
62-
rectangle split part fill={blue!20, none},
63-
rectangle split part align={center, left},
64-
text width=5cm, text centered,
65-
draw=black]
66-
67-
\tikzstyle{method} =%
68-
rounded corners,
69-
[rectangle split,
70-
rectangle split parts=2,
71-
rectangle split part fill={red!20, none},
72-
rectangle split part align={center, left},
73-
text width=5cm, text centered,
74-
draw=black]
75-
76-
\begin{tikzpicture}[node distance = 1.5cm and 1.5cm]
77-
78-
\node (trial) [draw=black, rectangle, fill=orange!10, minimum width=5cm, minimum height=2cm] {\texttt{Trial} class};
79-
80-
\node (covar) [proc, below left=of trial] {
81-
\textbf{\texttt{covariates}} \\
82-
\nodepart{two}
83-
\vspace*{-1.2em}
84-
\begin{flushleft}
85-
Function (arguments \texttt{n, ...}) that generates a list of \texttt{data.table}'s with covariates with each element representing a unique time-point.
86-
\end{flushleft}
87-
};
88-
89-
\node (outcome) [proc, above=of trial] {
90-
\textbf{\texttt{outcome}} \\
91-
\nodepart{two}
92-
\vspace*{-1.2em}
93-
\begin{flushleft}
94-
Function (arguments \texttt{x}: covariate data.table, \texttt{...}: additional
95-
arguments defining parameters of the outcome model) that generates the outcome given covariates.
96-
\end{flushleft}
97-
};
98-
99-
\node (exclusion) [proc, above left=of trial] {
100-
\textbf{\texttt{exclusion}} \\
101-
\nodepart{two}
102-
\vspace*{-1.2em}
103-
\begin{flushleft}
104-
Function (arguments \texttt{data}: data.table, \texttt{...}) that defines exclusion / inclusion criterions for the trial.
105-
\end{flushleft}
106-
};
107-
108-
\node (info) [proc, left=of trial] {
109-
\textbf{\texttt{info}} \\
110-
\nodepart{two}
111-
\vspace*{-1.2em}
112-
\begin{flushleft}
113-
Optional string describing the trial simulation.
114-
\end{flushleft}
115-
};
116-
117-
118-
\node (simulate) [method, above right=of trial] {
119-
\textbf{\$\texttt{simulate}} \\
120-
\nodepart{two}
121-
\vspace*{-1.2em}
122-
\begin{flushleft}
123-
\textit{Simulate data from the specified trial design.}
124-
\textbf{Arguments} \texttt{n}: sample size, \text{...}: additional arguments controlling covariate and outcome parameters. \textbf{Returns} `data.table` as defined by the object initialization with default subject identifier `id` and observation period `num`.
125-
\end{flushleft}
126-
};
127-
128-
\node (run) [method, right=of trial] {
129-
\textbf{\$\texttt{run}} \\
130-
\nodepart{two}
131-
\vspace*{-1.2em}
132-
\begin{flushleft}
133-
\textit{Simulate and estimate parameters several times.}
134-
\textbf{Arguments} \texttt{R}: replications, \texttt{estimators}: list of estimators of the trial target parameter, \texttt{...} additional arguments to the simulation routine. \textbf{Returns} an object with the Monte Carlo simulation results which can be analyzed with the \texttt{summary} method.
135-
\end{flushleft}
136-
};
137-
138-
\node (estimatepower) [method, below=of trial] {
139-
\textbf{\$\texttt{estimate\_power}} \\
140-
\nodepart{two}
141-
\vspace*{-1.2em}
142-
\begin{flushleft}
143-
\textit{Estimate the statistical power of an estimator in a given scenario using Monte Carlo simulations.}
144-
\textbf{Arguments} \texttt{R}: number of replications, \texttt{estimators}: estimator to consider,
145-
\texttt{summary.args}: arguments to the summary method that defines the statistical null hypothesis,
146-
\texttt{...} additional arguments to the simulation routine. \textbf{Returns} estimated power for the given trial scenario.
147-
\end{flushleft}
148-
};
149-
150-
\node (estimatesamplesize) [method, below right=of trial] {
151-
\textbf{\$\texttt{estimate\_samplesize}} \\
152-
\nodepart{two}
153-
\vspace*{-1.2em}
154-
\begin{flushleft}
155-
\textit{Estimate the minimum sample size needed to achieve a desired statistical power of an estimator in a given scenario.}
156-
\textbf{Arguments} \texttt{estimator}, \texttt{power}, \texttt{...} \\
157-
\textbf{Returns} an integer with an attribute 'power' with the actual power estimate.
158-
\end{flushleft}
159-
};
160-
161-
162-
163-
\draw [arrow, dashed] (covar) -- (trial);
164-
\draw [arrow, dashed] (info) -- (trial);
165-
\draw [arrow, dashed] (exclusion) -- (trial);
166-
\draw [arrow, dashed] (outcome) -- (trial);
167-
168-
\draw [arrow] (trial) -- (simulate);
169-
\draw [arrow] (trial) -- (run);
170-
\draw [arrow] (trial) -- (estimatepower);
171-
\draw [arrow] (trial) -- (estimatesamplesize);
172-
173-
\end{tikzpicture}
174-
```
42+
![The 'Trial' R6 reference class. The blue boxes define the arguments to the constructor, and the red boxes the most important class methods.](figs/trial-class.png){width=100%}
17543

17644
# Preliminaries
17745

@@ -465,10 +333,10 @@ trial$estimate_power(n = 300, R = 500)
465333
Last, we estimate the sample size required to attain 90% power for the specified
466334
trial model and estimator
467335
```{r}
468-
trial$estimate_samplesize(
469-
power = 0.9, # default
470-
estimator = trial$estimators("adjusted")
471-
)
336+
# trial$estimate_samplesize(
337+
# power = 0.9, # default
338+
# estimator = trial$estimators("adjusted")
339+
# )
472340
```
473341
The method optimizes the sample size by internally calling the
474342
`Trial$estimate_power` method. Therefore, the behavior for updating model

0 commit comments

Comments
 (0)