-
Notifications
You must be signed in to change notification settings - Fork 0
/
conditional-scores.Rmd
134 lines (115 loc) · 3.98 KB
/
conditional-scores.Rmd
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
132
133
134
---
title: "Conditional Scores and Constraints"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Conditional Scores and Constraints}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.width = 7,
fig.height = 5
)
```
```{r setup}
library(adoptr)
```
## (Un)conditional Scores in **adoptr**
There are two fundamental ways of scoring a two-stage design:
First, one may assess the performance before observing any data, i.e.,
at the planning stage.
Classical examples for such scores would be power, type-one-error rate,
or expected sample size.
There is, however, a second perspective.
After observing the stage-one outcome,
one might be inclined to consider conditional properties of a design.
The most prominent example being conditional power (probability to reject
the null under the alternative given stage-one outcome).
We consider the following example design
```{r define-design}
design <- TwoStageDesign(
n1 = 100,
c1f = .0,
c1e = 2.0,
n2_pivots = rep(150, 5),
c2_pivots = sapply(1 + adoptr:::GaussLegendreRule(5)$nodes, function(x) -x + 2)
)
plot(design)
```
In adoptr, scores are instances of their respective score class.
The most important ones are: `ConditionalScore`, `UnconditionalScore`, and
`IntegralScore`.
An object of class `ConditionalScore` can evaluate a design for a
particular stage-one outcome.
A `ConditionalScore` is a function $s(\mathcal{D}, x_1)$ evaluating a
design $\mathcal{D}$ at a stage-one outcome $X_1 = x_1$.
Some conditional scores might depend on the data distribution (conditional
power) others do not (conditional sample size).
Conditional score evaluation is completely vectorized:
```{r}
uniform_prior <- ContinuousPrior(
function(x) numeric(length(x)) + 1/.2,
support = c(.3, .5)
)
cp <- ConditionalPower(Normal(), uniform_prior)
css <- ConditionalSampleSize()
x1 <- c(0, .5, 1)
evaluate(cp, design, x1)
evaluate(css, design, x1)
```
Conditional scores can also be plotted directly for a given design by
including them in the `plot()` call.
```{r}
plot(design, "Conditional Power" = cp)
```
Any conditional score can be integrated with respect to a prior and
data distribution to obtain an unconditional score.
Note that for conditional scores which depend on a specification of these
distributions (e.g., conditional power) these arguments must be consistent!
The resulting score is of class `IntegralScore`, a specific subclass of
`UnconditionalScore` and evaluates designs independent of a particular $x_1$,
i.e., unconditionally
```{r}
ep <- expected(cp, Normal(), uniform_prior)
evaluate(ep, design)
```
Power at a point alternative can be obtained by forming the expected
value with respect to a point prior.
For convenience, we include a constructor for power directly, e.g.,
both variants are equivalent and give power at $0.4$.
```{r}
power1 <- expected(
ConditionalPower(Normal(), PointMassPrior(.4, 1.0)),
Normal(), PointMassPrior(.4, 1.0)
)
power2 <- Power(Normal(), PointMassPrior(.4, 1.0))
evaluate(power1, design)
evaluate(power2, design)
```
Similarly, `ExpectedSampleSize` is a shorthand constructor for expected
conditional sample size, i.e., the overall expected sample size:
```{r}
ess1 <- expected(ConditionalSampleSize(), Normal(), uniform_prior)
ess2 <- ExpectedSampleSize(Normal(), uniform_prior)
evaluate(ess1, design)
evaluate(ess2, design)
```
## Conditional Constraints
The same syntax for constraint specification as for unconditional
constraints (power etc.) can be used for conditional scores
(e.g. conditional power) as well.
Currently, these constraints apply to the continuation area only.
E.g.,
```{r}
cp >= 0.7
```
imposes a constraint on the minimal conditional power upon continuation.
Inter-score comparisons are also supported, e.g.
```{r}
cp >= ConditionalPower(Normal(), PointMassPrior(0, 1))
```
Would enforce that conditional power is always larger than conditional
error.