Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1d55aa6

Browse files
committed
Fix some quarto warnings.
1 parent42067e0 commit1d55aa6

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

‎vignettes/flipr.qmd‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ We can define a proper function to do this, termed the *null specification* func
126126
-`parameters` which is a numeric vector of values for the parameters under investigation (here only $\delta$ and thus`parameters` is of length $1$ with`parameters[1] = delta`).
127127

128128
In our simple example, it boils down to:
129+
129130
```{r}
130131
null_spec <- function(y, parameters) {
131132
purrr::map(y, ~ .x - parameters[1])
@@ -142,20 +143,23 @@ This statistic can be easily computed using `stats::t.test(x, y, var.equal = TRU
142143
-`indices1` which is an integer vector of size $n_x$ storing the indices of the data points belonging to the first sample in the current permuted version of the data.
143144

144145
A[**flipr**](https://permaverse.github.io/flipr/)-compatible version of the t-statistic is already implemented in[**flipr**](https://permaverse.github.io/flipr/) and ready to use as`stat_student` or its alias`stat_t`. Here, we are only going to use the $t$-statistic for this example, but we might be willing to use more than one statistic for a parameter or we might have several parameters under investigation, each one of them requiring a different test statistic. We therefore group all the test statistics that we need into a single list:
146+
145147
```{r}
146148
stat_functions <- list(stat_t)
147149
```
148150

149151
###Statistic assignments
150152

151153
Finally we need to define a named list that tells[**flipr**](https://permaverse.github.io/flipr/) which test statistics among the ones declared in the`stat_functions` list should be used for each parameter under investigation. This is used to determine bounds on each parameter for the plausibility function. This list, often termed`stat_assignments`, should therefore have as many elements as there are parameters under investigation. Each element should be named after a parameter under investigation and should list the indices corresponding to the test statistics that should be used for that parameter in`stat_functions`. In our example, it boils down to:
154+
152155
```{r}
153156
stat_assignments <- list(delta = 1)
154157
```
155158

156159
###Instantiation of the plausibility function
157160

158161
In[**flipr**](https://permaverse.github.io/flipr/), the plausibility function is implemented as an[R6Class](https://r6.r-lib.org/reference/R6Class.html) object. Assume we observed two samples stored in lists`x` and`y`, we therefore instantiate a plausibility function for this data as follows:
162+
159163
```{r, eval=FALSE}
160164
pf <- PlausibilityFunction$new(
161165
null_spec = null_spec,
@@ -170,6 +174,7 @@ Now, assume we want to test the following hypotheses:
170174
$$ H_0: \delta = 0 \quad \mbox{v.s.} \quad H_1: \delta \ne 0.$$
171175

172176
We use the`$get_value()` method for this purpose, which essentially evaluates the permutation $p$-value of a two-sided test by default:
177+
173178
```{r, eval=FALSE}
174179
pf$get_value(0)
175180
```
@@ -183,6 +188,7 @@ By default, the number of sampled permutations is `1000L`. It is accessible thro
183188
###Scenario A
184189

185190
Let us instantiate the plausibility for the data simulated under scenario A:
191+
186192
```{r, eval=FALSE}
187193
pfa <- PlausibilityFunction$new(
188194
null_spec = null_spec,
@@ -194,15 +200,19 @@ pfa$set_nperms(B)
194200
```
195201

196202
We can compute a point estimate of the mean difference and store it inside the plausibility function class via the`$set_point_estimate()` method:
203+
197204
```{r, eval=FALSE}
198205
pfa$set_point_estimate(mean(a2) - mean(a1))
199206
```
200207

201208
The computed value can then be accessed via the`$point_estimate` field:
209+
202210
```{r}
203211
pfa$point_estimate
204212
```
213+
205214
or by displaying the list of parameters under investigation which is stored in the`$parameters` field.
215+
206216
```{r, eval=FALSE}
207217
pfa$parameters
208218
```
@@ -215,6 +225,7 @@ p
215225
```
216226

217227
In this list, one can see that parameters come with an unknown range by default. We can however compute their bounds by defining a maximum confidence level through the`$set_max_conf_level()` method of the`PlausibilityFunction` class. When a plausibility function is instantiated, the default value for the`$max_conf_level` field is $0.99$. To set parameter bounds automatically, use the`$set_parameter_bounds()` method:
228+
218229
```{r, eval=FALSE}
219230
pfa$set_parameter_bounds(
220231
point_estimate = pfa$point_estimate,
@@ -223,11 +234,13 @@ pfa$set_parameter_bounds(
223234
```
224235

225236
We can now inspect again the list of parameters under investigation to see the updated bounds:
237+
226238
```{r}
227239
pfa$parameters
228240
```
229241

230242
Once bounds are known for each parameter, it becomes possible to generate a grid for later evaluating the plausibility function. This is done through the`$set_grid()` method as follows:
243+
231244
```{r, eval=FALSE}
232245
pfa$set_grid(
233246
parameters = pfa$parameters,
@@ -236,6 +249,7 @@ pfa$set_grid(
236249
```
237250

238251
We can then take a look at the newly created grid:
252+
239253
```{r, eval=FALSE}
240254
pfa$grid
241255
```
@@ -245,16 +259,19 @@ select(pfa$grid, -pvalue)
245259
```
246260

247261
We can go a step further and evaluate the plausibility function on that grid using the`$evaluate_grid()` method as follows:
262+
248263
```{r, eval=FALSE}
249264
pfa$evaluate_grid(grid = pfa$grid)
250265
```
251266

252267
Again, we can then take a look at the updated grid:
268+
253269
```{r}
254270
pfa$grid
255271
```
256272

257273
We can add to this grid the p-value computed from the t-test assuming normality of the data:
274+
258275
```{r}
259276
dfa <- pfa$grid %>%
260277
mutate(
@@ -471,11 +488,13 @@ by-product as we will show in the next sections.
471488
One can obtain a point estimate of the parameter under investigation by
472489
searching which value of the parameter reaches the maximum of the
473490
$p$-value function (which is $1$). One can use the`$set_point_estimate()` method to do that:
491+
474492
```{r, eval=FALSE}
475493
pfa$set_point_estimate(overwrite = TRUE)
476494
```
477495

478496
The computed point estimate is then stored in the`$point_estimate` field and can be retrieved as:
497+
479498
```{r}
480499
pfa$point_estimate
481500
```
@@ -486,6 +505,7 @@ One can obtain a confidence interval for the parameter under
486505
investigation by searching for which values of the parameter the
487506
$p$-value function remains above a pre-specified significance level
488507
$\alpha$. This is achieved via the`$set_parameter_bounds()` method:
508+
489509
```{r, eval=FALSE}
490510
pfa$set_parameter_bounds(
491511
point_estimate = pfa$point_estimate,
@@ -504,6 +524,7 @@ hypothesis is $H_0: \delta = \delta_0$ is immediate from the $p$-value
504524
function as it boils down to evaluating the $p$-value function in
505525
$\delta_0$. Hence we can for instance test $H_0: \delta = 3$ against the
506526
alternative $H_1: \delta \ne 3$ using the following piece of code:
527+
507528
```{r}
508529
pfa$set_nperms(1000)
509530
pfa$get_value(3)

‎vignettes/parallelization.qmd‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ vignette: >
1010
%\VignetteEncoding{UTF-8}
1111
---
1212

13-
1413
```{r, include = FALSE}
1514
knitr::opts_chunk$set(
1615
collapse = TRUE,

‎vignettes/plausibility.qmd‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ vignette: >
1111
bibliography:references.bib
1212
---
1313

14-
1514
```{r, include = FALSE}
1615
knitr::opts_chunk$set(
1716
collapse = TRUE,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp