-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorials.html
More file actions
738 lines (683 loc) · 27.5 KB
/
tutorials.html
File metadata and controls
738 lines (683 loc) · 27.5 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="date" content="2026-01-24" />
<title>Tutorials | fastrerandomize</title>
<link rel="icon" type="image/png" href="figures/FRR_logo.png" />
<!-- Font Awesome Icons (optional - if using icons) -->
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"
/>
<!-- Pandoc header-attribute fix -->
<script>
document.addEventListener('DOMContentLoaded', function() {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
for (var i = 0; i < hs.length; i++) {
var h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue;
while (h.attributes.length > 0) {
h.removeAttribute(h.attributes[0].name);
}
}
});
</script>
<link rel="stylesheet" href="styles.css"/>
<!-- Dynamically load MathJax (if needed) -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</head>
<body>
<!-- Background Canvas (raining vectors) -->
<canvas id="background-canvas"></canvas>
<!-- Header + Navigation -->
<header>
<nav>
<div class="logo">
<a href="index.html" aria-label="FastRerandomize home">
<img src="figures/FRR_logo.png" alt="FastRerandomize" />
</a>
</div>
<!-- HAMBURGER BUTTON -->
<button class="menu-toggle" aria-label="Toggle Menu">
<span class="hamburger-line"></span>
<span class="hamburger-line"></span>
<span class="hamburger-line"></span>
</button>
<!-- /HAMBURGER BUTTON -->
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="install.html">Install</a></li>
<li><a href="tutorials.html" class="active" aria-current="page">Tutorials</a></li>
<li>
<a href="https://github.com/cjerzak/fastrerandomize-software/blob/main/fastrerandomize.pdf?raw=true">
Documentation
</a>
</li>
<li><a href="aboutus.html">About</a></li>
</ul>
<!-- Search Container (Same logic as index) -->
<div class="search-container">
<form onsubmit="return false;">
<i class="fas fa-search search-icon"></i>
<input
type="text"
class="search-input"
placeholder="Search docs..."
aria-label="Search documentation"
/>
</form>
<!-- The search results will be inserted by JavaScript -->
<div class="search-results"></div>
</div>
</nav>
</header>
<!-- Main Content -->
<main>
<div class="tutorial-content animate-fade-in">
<!-- Pandoc-generated Title & Date -->
<h1 class="title toc-ignore">FastRerandomize Package Tutorial</h1>
<h4 class="date">2026-01-24</h4>
<div class="share-container">
<button id="share-button">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="18" cy="5" r="3"></circle>
<circle cx="6" cy="12" r="3"></circle>
<circle cx="18" cy="19" r="3"></circle>
<line x1="8.59" y1="13.51" x2="15.42" y2="17.49"></line>
<line x1="15.41" y1="6.51" x2="8.59" y2="10.49"></line>
</svg>
Share
</button>
</div>
<script>
(function() {
const shareBtn = document.getElementById('share-button');
function showCopyNotification() {
const notification = document.createElement('div');
notification.className = 'copy-notification';
notification.innerText = 'Copied to clipboard';
document.body.appendChild(notification);
setTimeout(() => {
notification.remove();
}, 2000);
}
shareBtn.addEventListener('click', function() {
const currentURL = window.location.href;
const pageTitle = document.title || 'Check this out!';
// If browser supports Web Share API
if (navigator.share) {
navigator.share({
title: pageTitle,
text: '',
url: currentURL
})
.catch((error) => {
console.log('Sharing failed', error);
});
} else {
// Fallback to copy the URL to the clipboard:
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(currentURL).then(() => {
showCopyNotification();
}, (err) => {
console.error('Could not copy text: ', err);
});
} else {
const textArea = document.createElement('textarea');
textArea.value = currentURL;
document.body.appendChild(textArea);
textArea.select();
try {
document.execCommand('copy');
showCopyNotification();
} catch (err) {
alert('Please copy this link:\n' + currentURL);
}
document.body.removeChild(textArea);
}
}
});
})();
</script>
<!-- END: Insanely Great Native Share Button -->
<!-- Introduction -->
<div id="introduction" class="section level2">
<h2>Introduction</h2>
<p>
This vignette demonstrates how to use the fastrerandomize package for
generating and testing experimental designs in an agricultural study
setting based on:
</p>
<ul>
<li>
Burchardi, K.B., Gulesci, S., Lerva, B. and Sulaiman, M., 2019.
Moral hazard: Experimental Evidence from Tenancy Contracts. The
Quarterly Journal of Economics, 134(1), pp.281-347.
</li>
</ul>
<p>We will walk through:</p>
<ul>
<li>Generating synthetic covariate data</li>
<li>Creating candidate randomizations</li>
<li>
Exploring the S3 methods for printing, summarizing, and plotting
randomization objects
</li>
<li>Conducting a randomization-based inference test</li>
</ul>
<div id="key-concepts" class="concept-box">
<h3>Key Concepts</h3>
<ul>
<li><strong>Balance statistic M:</strong> Mahalanobis distance between treatment and control covariate mean vectors. Smaller M = better balance.</li>
<li><strong>Acceptance rule:</strong> keep an assignment if <code>M ≤ a</code> for a chosen cutoff a.</li>
<li><strong>Acceptance probability q:</strong> q = P(M ≤ a) under complete randomization. Smaller q = stricter balance.</li>
<li><strong>Accepted set:</strong> assignments that pass the rule; inference resamples from this set.</li>
<li><strong>Shrinkage factor:</strong> how much rerandomization reduces covariate imbalance variance; larger reduction yields more precision when covariates predict outcomes.</li>
</ul>
</div>
<p>
Stringency refers to how selective the acceptance rule is, typically expressed by the acceptance
probability q (lower q means more stringent). The shrinkage factor is the scalar reduction in covariate
imbalance variance when conditioning on acceptance. In the paper's diagnostics, acceptance at q = 1%
yields a shrinkage factor of about 0.45 at d = 30 but about 0.88 at d = 1000, so stringency has
diminishing returns in very high-dimensional settings. In the
same illustrative setup (n<sub>T</sub> = n<sub>C</sub> = 500, R² = 0.5), that corresponds to about 15% RMSE reduction at
d = 30 versus about 3% at d = 1000.
</p>
<p>
Note: This tutorial assumes you have installed the fastrerandomize
package, either from source or via GitHub:
</p>
<div class="sourceCode" id="cb1">
<pre class="sourceCode r"><code class="sourceCode r">
# If you haven't installed or set up the package:
# devtools::install_github("cjerzak/fastrerandomize-software", subdir = "fastrerandomize")
# (Done once) Optionally build the JAX backend if needed
# fastrerandomize::build_backend()
# note that this vignette can be found like so:
# vignette(package = "fastrerandomize")
</code></pre>
</div>
</div>
<!-- Covariate Data -->
<div id="obtain-pre-treatment-covariate-data" class="section level2">
<h2>1. Obtain Pre-treatment Covariate Data</h2>
<div class="checklist">
<h4>Covariate prep checklist</h4>
<ul>
<li>Use pre-treatment covariates only—never condition on post-treatment variables</li>
<li>Standardize/scale when appropriate (especially if covariates have very different units)</li>
<li>Avoid severe collinearity (Mahalanobis distance relies on the covariance matrix being invertible)</li>
</ul>
</div>
<p>
For illustration, we use several pre-treatment covariates from the
original experiment.
</p>
<div class="sourceCode" id="cb2">
<pre class="sourceCode r"><code class="sourceCode r">
library(fastrerandomize)
# Obtain pre-treatment covariates
data(QJEData, package = "fastrerandomize")
myCovariates <- c("children","married","hh_size","hh_sexrat")
QJEData <- QJEData[!is.na(rowSums(QJEData[,myCovariates])),]
X <- QJEData[,myCovariates]
# Analysis parameters
n_units <- nrow(X)
n_treated <- round(nrow(X)/2)
</code></pre>
</div>
</div>
<!-- Generate Randomizations -->
<div id="generate-randomizations" class="section level2">
<h2>2. Generate Randomizations</h2>
<p>
We now create our candidate randomizations using the function
<code>generate_randomizations()</code> from fastrerandomize. Depending
on the scale and complexity of your experiment, you may choose either
exact enumeration ("exact") or Monte Carlo ("monte_carlo")
randomization.
</p>
<div class="guidance-box">
<h4>Choosing stringency (q) in practice</h4>
<ul>
<li>Start with a target acceptance probability (common: <code>q = 0.01</code> for moderate, <code>q = 0.001</code> for high stringency).</li>
<li>Use <code>diagnose_rerandomization()</code> to check implied balance improvement and computational implications.</li>
<li>Plan candidate draws for a sufficiently large accepted pool (aim for thousands of accepted assignments for stable inference).</li>
<li>Remember: smaller q → better balance, but more draws needed and diminishing returns in high dimensions.</li>
</ul>
</div>
<p>
In this example, we'll use the Monte Carlo approach. Note that
<code>randomization_accept_prob</code> is set very low (0.0001) purely
for demonstration.
</p>
<p>
In high-dimensional planning, diagnostics can recommend extremely small q values. For example, in the
paper's illustrative case (d = 1000, n<sub>T</sub> = n<sub>C</sub> = 500, R² = 0.4, σ = 1, |τ| = 0.2), the diagnostic
inversion implies q* ≈ 0.000012 (about 1.2e-5), or roughly 81,226 draws per accepted assignment. Holding
q fixed, more draws mainly increase the accepted pool (lowering the minimum attainable p-value) without
changing expected balance.
</p>
<div class="sourceCode" id="cb3">
<pre class="sourceCode r"><code class="sourceCode r">
RunMainAnalysis <- (!is.null(check_jax_availability()))
# if FALSE, consider calling build_backend()
if(RunMainAnalysis){
CandRandomizations <- generate_randomizations(
n_units = n_units,
n_treated = n_treated,
X = X,
randomization_type = "monte_carlo",
max_draws = 100000L,
batch_size = 1000L,
randomization_accept_prob = 0.0001
)
}
</code></pre>
</div>
<pre><code>## Using monte carlo randomization</code></pre>
<pre><code>## Starting batch processing with 100 batches.</code></pre>
<pre><code>## On batch 100 of 100</code></pre>
<pre><code>## MC Loop Time (s): 1.2409</code></pre>
</div>
<!-- S3 Methods -->
<div id="s3-methods-print-summary-and-plot" class="section level2">
<h2>4. S3 Methods: Print, Summary, and Plot</h2>
<p>
<code>generate_randomizations()</code> returns an S3 object of class
<code>fastrerandomize_randomizations</code>. We can use its associated
print, summary, and plot methods to inspect the candidate
randomizations.
</p>
<div class="sourceCode" id="cb107">
<pre class="sourceCode r"><code class="sourceCode r">
if(RunMainAnalysis){
# 4a. Print the object
print(CandRandomizations)
# 4b. Summary
summary(CandRandomizations)
# 4c. Plot the balance distribution
plot(CandRandomizations)
}
</code></pre>
</div>
<pre><code>## Object of class 'fastrerandomize_randomizations'
##
## Call:
## generate_randomizations(n_units = n_units, n_treated = n_treated,
## X = X, randomization_accept_prob = 1e-04, max_draws = 100000L,
## batch_size = 1000L, randomization_type = "monte_carlo")
##
## Number of candidate randomizations: 10
## Number of units (columns): 302
## Balance statistics available for each randomization.
## Summary of 'fastrerandomize_randomizations' object:
##
## Balance statistics (summary):
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.003574 0.008231 0.008746 0.009835 0.013152 0.017181</code></pre>
</div>
<!-- Randomization Test -->
<div id="randomization-test" class="section level2">
<h2>3. Randomization Test</h2>
<p>
Next, we showcase a randomization-based inference procedure using
fastrerandomize.
</p>
<div class="note-box">
<h4>Why the randomization test conditions on acceptance</h4>
<p>Under rerandomization, treatment was assigned from the subset of assignments that passed the balance rule. To keep p-values calibrated, the randomization test must resample only from assignments that would also pass the same rule. This is what "design-respecting inference" means.</p>
</div>
<p>
Randomization tests are conditioned on the accepted assignments: the observed statistic is compared to
its distribution over the accepted pool. As a result, p-values are lower-bounded by 1 / M_accept, and
optional fiducial intervals are available by inverting the test.
</p>
<div id="a.-setup-simulated-outcomes" class="section level3">
<h3>3a. Setup Simulated Outcomes</h3>
<p>
We simulate an outcome <code>Y</code> that depends on our covariates
<code>X</code>, the chosen randomization, and some true treatment
effect τ. We pick the first acceptable randomization from our set as
our “observed” assignment <code>Wobs</code>.
</p>
<div class="sourceCode" id="cb109">
<pre class="sourceCode r"><code class="sourceCode r">
if(RunMainAnalysis){
CoefY <- rnorm(ncol(X)) # Coefficients for outcome model
Wobs <- CandRandomizations$randomizations[1, ] # 1st acceptable randomization
tau_true <- 1 # true treatment effect
# Generate Y = X * Coef + W*tau + noise
Yobs <- as.numeric(as.matrix(X) %*% as.matrix(CoefY) +
Wobs * tau_true + rnorm(n_units, sd = 0.1))
}
</code></pre>
</div>
</div>
<div id="b.-run-the-randomization-test" class="section level3">
<h3>3b. Run the Randomization Test</h3>
<p>
We pass our observed treatment assignment (<code>obsW</code>),
observed outcomes (<code>obsY</code>), and the full matrix of
candidate randomizations
(<code>candidate_randomizations</code>) to
<code>randomization_test()</code>. This test:
</p>
<ul>
<li>Computes the observed difference in means</li>
<li>Permutes the treatment assignment across our candidate
randomizations</li>
<li>
Estimates the p-value by comparing the observed statistic to its
permutation distribution
</li>
</ul>
<div class="sourceCode" id="cb110">
<pre class="sourceCode r"><code class="sourceCode r">
if(RunMainAnalysis){
randomization_test_results <- randomization_test(
obsW = Wobs,
obsY = Yobs,
candidate_randomizations = CandRandomizations$randomizations,
findFI = TRUE
)
# Inspect results
print(randomization_test_results)
summary(randomization_test_results)
plot(randomization_test_results)
}
</code></pre>
</div>
<pre><code>## Object of class 'fastrerandomize_test'
##
## Call:
## randomization_test(obsW = Wobs, obsY = Yobs, candidate_randomizations = CandRandomizations$randomizations,
## findFI = TRUE)
##
## P-value: 0.1
## Observed effect (tau_obs): 0.9888765
## Fiducial interval: [-547.2352, 498.731]
## Summary of 'fastrerandomize_test' object:
##
## Call:
## randomization_test(obsW = Wobs, obsY = Yobs, candidate_randomizations = CandRandomizations$randomizations,
## findFI = TRUE)
##
## P-value:
## 0.1
##
## Observed effect (tau_obs):
## 0.9888765
##
## Fiducial Interval:
## [-547.2352, 498.731]</code></pre>
<p>
The <code>findFI = TRUE</code> flag attempts to locate a fiducial
interval (FI) for the treatment effect.
</p>
</div>
</div>
<!-- What to Report -->
<div id="what-to-report" class="section level2">
<h2>5. What to Report</h2>
<div class="reporting-guide">
<h4>Recommended reporting checklist</h4>
<ul>
<li><strong>Covariates used</strong> in the balance check and balance statistic (e.g., Mahalanobis M)</li>
<li><strong>Acceptance rule</strong> (M ≤ a) and either a or the implied acceptance probability q</li>
<li><strong>Number of candidate draws</strong> and the resulting accepted pool size</li>
<li><strong>That inference was conducted conditional on the acceptance rule</strong> (design-respecting inference)</li>
</ul>
</div>
<p>
Transparent reporting helps readers understand how the design affects inference and enables replication.
</p>
</div>
<!-- Conclusion -->
<div id="conclusion" class="section level2">
<h2>Conclusion</h2>
<p>
This tutorial demonstrated a basic workflow with fastrerandomize:
</p>
<ul>
<li>Generating synthetic or real covariate data</li>
<li>
Producing a set of acceptable treatment assignments via
randomization
</li>
<li>Visualizing and summarizing these assignments</li>
<li>
Testing for treatment effects with a randomization-based approach
</li>
</ul>
<p>
We encourage you to consult the package documentation for more
advanced functionalities, including GPU-accelerated computations via
JAX and flexible definitions of balance criteria.
</p>
</div>
<div class="section-card animate-fade-in">
<p class="eyebrow">Citation</p>
<p>
Connor T. Jerzak, Rebecca Goldstein, Aniket Kamat, and Fucheng Warren Zhu.
FastRerandomize: An R Package for Fast Rerandomization Using Accelerated Computing.
SoftwareX, 2026.
</p>
<div class="citation-card">
<pre><code>@article{jerzak2025fastrerandomize,
title={FastRerandomize: An R Package for Fast Rerandomization Using Accelerated Computing},
author={Jerzak, Connor T. and Rebecca Goldstein and Aniket Kamat and Fucheng Warren Zhu},
journal={SoftwareX},
year={2026}
}</code></pre>
</div>
</div>
</div> <!-- .tutorial-content -->
</main>
<!-- Footer -->
<footer>
<p>© 2026 fastrerandomize developers</p>
</footer>
<!-- Scripts -->
<script>
// 1) MENU TOGGLE LOGIC
const menuToggle = document.querySelector('.menu-toggle');
const nav = document.querySelector('nav');
menuToggle.addEventListener('click', () => {
nav.classList.toggle('open');
});
// 2) "Raining Vectors" background (same as index)
const canvas = document.getElementById('background-canvas');
const ctx = canvas.getContext('2d');
const symbols = [
'∂','∇','λ','α','δ','θ','Σ','∫','×','→','±','β','μ','Ω','σ','Φ',
'∞','π','ξ','ζ','γ','ε','∛','∝','∠','∧','∨','∩','∪','≈','≠','≤','≥',
'≡','∈','∉','⊂','⊃','⊆','⊇','⊕','⊗','⊥','Z','P','R','N'
];
const prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
let width, height, columns;
let drops = [], sizes = [], speeds = [], opacities = [], hues = [];
function resizeCanvas() {
width = window.innerWidth;
height = window.innerHeight;
canvas.width = width;
canvas.height = height;
columns = Math.floor(width / 20);
drops = [];
sizes = [];
speeds = [];
opacities = [];
hues = [];
for (let i = 0; i < columns; i++) {
drops[i] = Math.random() * -100;
sizes[i] = 10 + Math.floor(Math.random() * 10);
speeds[i] = 0.05 + Math.random() * 0.2;
opacities[i] = 0.04 + Math.random() * 0.1;
hues[i] = 210 + Math.random() * 20;
}
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
function draw() {
ctx.fillStyle = prefersDark ? 'rgba(12, 13, 16, 0.12)' : 'rgba(247, 246, 242, 0.08)';
ctx.fillRect(0, 0, width, height);
for (let i = 0; i < drops.length; i++) {
const text = symbols[Math.floor(Math.random() * symbols.length)];
const x = i * 20;
const y = drops[i] * 20;
ctx.font = `${sizes[i]}px monospace`;
const lightness = prefersDark ? 70 : 30;
ctx.fillStyle = `hsla(${hues[i]}, 40%, ${lightness}%, ${opacities[i]})`;
ctx.fillText(text, x, y);
drops[i] += speeds[i];
if (y > height && Math.random() > 0.99) {
drops[i] = -1;
speeds[i] = 0.05 + Math.random() * 0.2;
opacities[i] = 0.04 + Math.random() * 0.1;
}
}
}
setInterval(draw, 60);
// 3) SEARCH FUNCTIONALITY
(function() {
const searchableContent = [
{
title: "Installation Guide",
description: "How to install and set up fastrerandomize package",
url: "install.html"
},
{
title: "Documentation",
description: "API reference and comprehensive documentation",
url: "https://github.com/cjerzak/fastrerandomize-software/blob/main/fastrerandomize.pdf?raw=true"
},
{
title: "Tutorials",
description: "Step-by-step guides for using fastrerandomize",
url: "tutorials.html"
},
{
title: "About",
description: "Information about the developers and contributors",
url: "aboutus.html"
},
{
title: "GitHub Repository",
description: "Source code and development resources",
url: "https://github.com/cjerzak/fastrerandomize-software"
},
{
title: "CRAN Package",
description: "Official R package distribution",
url: "https://cran.r-project.org/package=fastrerandomize"
},
{
title: "Performance",
description: "CPU vs GPU benchmarks and scaling results",
url: "index.html#performance"
},
{
title: "Citation",
description: "SoftwareX reference and BibTeX entry",
url: "index.html#citation"
}
];
const searchContainer = document.querySelector('.search-container');
const searchInput = document.querySelector('.search-input');
const searchResults = searchContainer.querySelector('.search-results');
function performSearch(query) {
searchResults.innerHTML = '';
if (!query.trim()) {
searchResults.style.display = 'none';
return;
}
const lowercaseQuery = query.toLowerCase();
const filteredResults = searchableContent.filter(item => {
return (
item.title.toLowerCase().includes(lowercaseQuery) ||
item.description.toLowerCase().includes(lowercaseQuery)
);
});
if (filteredResults.length > 0) {
searchResults.style.display = 'block';
filteredResults.forEach(result => {
const resultItem = document.createElement('a');
resultItem.href = result.url;
resultItem.className = 'search-result-item';
resultItem.innerHTML = `
<div class="search-result-title">${result.title}</div>
<div class="search-result-desc">${result.description}</div>
`;
searchResults.appendChild(resultItem);
});
} else {
searchResults.style.display = 'block';
searchResults.innerHTML = `
<div class="search-empty">No results found for "${query}"</div>
`;
}
}
searchInput.addEventListener('input', (e) => {
performSearch(e.target.value);
});
searchInput.addEventListener('focus', () => {
if (searchInput.value.trim()) {
performSearch(searchInput.value);
}
});
document.addEventListener('click', (e) => {
if (!searchContainer.contains(e.target)) {
searchResults.style.display = 'none';
}
});
const searchForm = searchInput.closest('form');
if (searchForm) {
searchForm.addEventListener('submit', (e) => {
e.preventDefault();
performSearch(searchInput.value);
});
}
searchInput.addEventListener('keydown', (e) => {
const results = searchResults.querySelectorAll('.search-result-item');
if (results.length === 0) return;
const activeElement = document.activeElement;
const isResultFocused = activeElement.classList.contains('search-result-item');
const currentIndex = isResultFocused
? Array.from(results).indexOf(activeElement)
: -1;
if (e.key === 'ArrowDown') {
e.preventDefault();
if (currentIndex < results.length - 1) {
results[currentIndex + 1].focus();
} else {
results[0].focus();
}
} else if (e.key === 'ArrowUp') {
e.preventDefault();
if (currentIndex > 0) {
results[currentIndex - 1].focus();
} else {
results[results.length - 1].focus();
}
} else if (e.key === 'Escape') {
searchResults.style.display = 'none';
searchInput.blur();
}
});
})();
</script>
</body>
</html>