Implements a comprehensive suite of AI SDK v6 tools across multiple categories: - Research (5): page-brief, compare-pages, source-credibility, claim-checklist, timeline-from-text - Web (10): fetch-text, links-catalog, extract-meta, extract-json-ld, redirect-trace, sitemap-read, rss-read, table-extract, robots-policy, url-normalize - Data (15): csv-parse, csv-stringify, json-repair, json-schema-validate, yaml-parse, yaml-stringify, text-chunk, normalize-whitespace, dedupe-by-key, pivot, rows-filter, rows-sort, rows-group-aggregate, rows-join, schema-infer - Doc (12): toc-generate, glossary-build, faq-from-text, executive-brief, decision-record-adr, prd-outline, acceptance-criteria, style-rewrite - Eng (12): diff-text-unified, env-var-docs-generate, dependency-audit-lite, conventional-commit-suggest, markdown-lint-basic, test-case-generate, stacktrace-parse, release-notes, changelog-entry, release-checklist - Security (7): redact-secrets, secret-scan-text, url-risk-heuristic, csp-compose, hardening-checklist-web, access-control-matrix, data-classification-heuristic - Stats (9): effect-size-suite, bootstrap-ci, permutation-test, multiple-testing-adjust, linear-regression-ols, logistic-regression, time-series-decompose-lite, anomaly-detect-mad - Ops (7): slo-draft, runbook-draft, postmortem-draft, postmortem-action-extractor, error-log-triage, coverage-tracker, monitoring-gap-analysis - Agent (15): prompt-to-workflow-skeleton, workflow-validate-io, workflow-explain, workflow-cost-estimate, tool-call-accuracy-score, eval-fixture-build, guardrail-policy-draft, workflow-auto-repair, tool-selection-plan, novelty-score-workflow, workflow-variant-generate, config-normalize, recipe-* - Utility (8): base64-encode, base64-decode, hash-text, regex-extract, template-render, date-parse, json-path-query, url-parse - HTML (3): html-sanitize, html-to-markdown, markdown-to-html All tools follow AI SDK v6 pattern with tool() and jsonSchema<T>(). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
136 lines
3.9 KiB
Markdown
136 lines
3.9 KiB
Markdown
# @tpmjs/tools-bootstrap-ci
|
|
|
|
Calculate bootstrap confidence intervals for sample statistics using resampling methodology.
|
|
|
|
## Overview
|
|
|
|
The bootstrap is a powerful non-parametric statistical method for estimating confidence intervals without assuming any specific distribution (like normal distribution). It works by repeatedly resampling the data with replacement and calculating the statistic of interest for each resample.
|
|
|
|
This tool implements the **percentile method** for bootstrap confidence intervals, which directly uses the percentiles of the bootstrap distribution.
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
npm install @tpmjs/tools-bootstrap-ci
|
|
```
|
|
|
|
## Usage with AI SDK
|
|
|
|
```typescript
|
|
import { bootstrapCITool } from '@tpmjs/tools-bootstrap-ci';
|
|
import { generateText } from 'ai';
|
|
|
|
const result = await generateText({
|
|
model: yourModel,
|
|
tools: { bootstrapCI: bootstrapCITool },
|
|
toolChoice: 'required',
|
|
prompt: 'Calculate a 95% confidence interval for this sample: [23, 25, 28, 22, 24, 26, 29, 27, 25, 24]',
|
|
});
|
|
```
|
|
|
|
## Direct Usage
|
|
|
|
```typescript
|
|
import { bootstrapCITool } from '@tpmjs/tools-bootstrap-ci';
|
|
|
|
const result = await bootstrapCITool.execute({
|
|
data: [23, 25, 28, 22, 24, 26, 29, 27, 25, 24],
|
|
confidenceLevel: 0.95,
|
|
iterations: 1000,
|
|
});
|
|
|
|
console.log(result);
|
|
// {
|
|
// mean: 25.3,
|
|
// lower: 24.1,
|
|
// upper: 26.5,
|
|
// confidenceLevel: 0.95,
|
|
// iterations: 1000,
|
|
// sampleSize: 10
|
|
// }
|
|
```
|
|
|
|
## Parameters
|
|
|
|
- `data` (required): Array of numeric values to analyze (minimum 2 values)
|
|
- `confidenceLevel` (optional): Confidence level as decimal (default: 0.95 for 95% CI, range: 0.5-0.999)
|
|
- `iterations` (optional): Number of bootstrap resamples (default: 1000, range: 100-100,000)
|
|
|
|
## Returns
|
|
|
|
```typescript
|
|
{
|
|
mean: number; // Original sample mean
|
|
lower: number; // Lower bound of confidence interval
|
|
upper: number; // Upper bound of confidence interval
|
|
confidenceLevel: number; // Confidence level used
|
|
iterations: number; // Number of bootstrap iterations performed
|
|
sampleSize: number; // Size of original sample
|
|
}
|
|
```
|
|
|
|
## When to Use Bootstrap CI
|
|
|
|
The bootstrap method is particularly useful when:
|
|
|
|
- Your sample size is small to moderate
|
|
- You don't know the underlying distribution of your data
|
|
- The traditional parametric methods (t-test) assumptions might be violated
|
|
- You want a robust, assumption-free confidence interval
|
|
|
|
## Algorithm
|
|
|
|
1. Calculate the mean of the original sample
|
|
2. Generate N bootstrap samples by randomly sampling with replacement
|
|
3. Calculate the mean for each bootstrap sample
|
|
4. Sort all bootstrap means
|
|
5. Use percentiles to determine confidence interval bounds
|
|
|
|
For 95% CI: lower bound = 2.5th percentile, upper bound = 97.5th percentile
|
|
|
|
## Example Use Cases
|
|
|
|
**Small sample analysis:**
|
|
```typescript
|
|
const clinicalTrialData = [5.2, 6.1, 4.8, 5.9, 6.3, 5.5];
|
|
const ci = await bootstrapCITool.execute({ data: clinicalTrialData });
|
|
```
|
|
|
|
**Different confidence levels:**
|
|
```typescript
|
|
// 99% confidence interval
|
|
const ci99 = await bootstrapCITool.execute({
|
|
data: measurements,
|
|
confidenceLevel: 0.99,
|
|
});
|
|
|
|
// 90% confidence interval
|
|
const ci90 = await bootstrapCITool.execute({
|
|
data: measurements,
|
|
confidenceLevel: 0.90,
|
|
});
|
|
```
|
|
|
|
**High precision analysis:**
|
|
```typescript
|
|
// Use more iterations for more precise estimates
|
|
const preciseCI = await bootstrapCITool.execute({
|
|
data: sampleData,
|
|
iterations: 10000,
|
|
});
|
|
```
|
|
|
|
## Limitations
|
|
|
|
- Computational intensity increases with iterations (trade-off between precision and speed)
|
|
- Results may vary slightly between runs due to random sampling (use more iterations for stability)
|
|
- Best suited for estimating means; other statistics may require modified approaches
|
|
|
|
## References
|
|
|
|
- Efron, B., & Tibshirani, R. J. (1994). *An Introduction to the Bootstrap*
|
|
- DiCiccio, T. J., & Efron, B. (1996). Bootstrap confidence intervals. *Statistical Science*, 11(3), 189-228
|
|
|
|
## License
|
|
|
|
MIT
|