34 of 40 focal problems use RatMath for a calculation or a substantive step.
Direct calculation
30 · 75%
Assisted
4 · 10%
Worked by hand
6 · 15%
Using the packages
Finite-sample tests are particularly useful when a discrete p-value is awkward by hand. The library cannot judge a study design from an array of measurements, and a result should state the null, alternative and sampling unit.
Calculator interface
Start with the sampling unit and design, then expose the chosen reference distribution, test statistic, effect estimate and interval together. Offer exact integer sample-size output and an explicit power curve.
Each of the 40 focal problems has equal weight. Direct means the displayed package calculation answers the computational question after the inputs are set up. Assisted means it contributes a step and the worked solution supplies essential reasoning, interpretation or selection. Worked by hand means the guide relies on a construction, argument or judgment for that task. The helpful share combines direct and assisted days. Courses and instructors assign different mixes of problems. The percentages describe this syllabus.
Classroom inputs and practical limits
34 of 40 days include a checked executable example. On 11 days the measured size sweep exercises a named API used in the lesson. Each day identifies its tested inputs and the mathematical property checked. Hand-worked days give the input scale and the argument to verify.
Ranges across the five units
Days 1–8 · Estimation. One or two parameters and about 5–200 observations for sample likelihoods; include boundary parameter values.
Unit benchmark · stats.mean, observations. Largest passing sample 100,000 (129 ms, 142.2 MiB peak process RSS). The first sampled passing call above 100 ms used 100,000 (129 ms). The runs did not locate a ceiling for this family.
Days 9–16 · Intervals and tests. One- and two-sample tests, paired observations or small contingency tables; n often 5–100 per group.
Unit benchmark · stats.tTest, observations per sample. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 17–24 · Regression and group comparisons. Typically 1–5 predictors and tens to hundreds of rows, or 2–5 groups. Rank and residual degrees of freedom constrain the fit.
Unit benchmark · stats.leastSquares, observations. Largest passing sample 20,000 (276 ms, 132.4 MiB peak process RSS). The first sampled passing call above 100 ms used 20,000 (276 ms). The runs did not locate a ceiling for this family.
Days 25–32 · Ranks and exact inference. Small ordinal or categorical samples, commonly at most a few dozen per group for exact enumeration; ties change the null law.
Unit benchmark · stats.tTest, observations per sample. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 33–40 · Design, power and Bayesian inference. Powers and confidence levels commonly 0.8–0.99, nonzero effects and positive target margins; sample size can explode as precision tightens.
Unit benchmark · stats.sampleSize, decimal places in margin. Largest passing sample 10 (117 ms, 89.1 MiB peak process RSS). The first sampled passing call above 100 ms used 10 (117 ms). The runs did not locate a ceiling for this family.
Accuracy notes (3)
Fixed · Large sample sizes preserve the exact ceiling. At margin 10⁻⁹, σ=1 and 95% confidence, n and the ceilings of both bound endpoints now equal 3841458820694125959. The large result is a BigInt. Preserve that type during further calculations.
Fixed · Power at the null is handled explicitly. For μ=μ₀, σ=1 and α=0.05, the continuous known-σ test has power 0.05 for every positive sample size. The planner returns the minimum n=1 for a target of 0.04.
Open · Two distinct categorical tuples can merge. A uniform table on the two arrays [‘a,sb’,‘c’] and [‘a’,‘b,sc’] should give each probability 1/2. The table reports one outcome with probability 1 because the composite string keys collide. Use unambiguous scalar IDs for such labels. Ordinary numeric dice faces have distinct keys.
The waiting times 2, 3, 1, 4, 5 come from an exponential distribution with rate . Find the maximum likelihood estimate of .
Worked solution
, so .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as stats from "@ratmath/stats";
console.log(String(stats.fit([2, 3, 1, 4, 5], "exponential").params.rate));
Checked output
1/3
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One or two parameters and about 5–200 observations for sample likelihoods; include boundary parameter values.
Focal example. The code above passed its displayed check in 0.339 ms on Node.
Related workload in this unit.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.fit · 3 passing test cases, 8 distinct argument descriptions
Counts 2, 0, 3, 1, 4 come from a Poisson distribution. Find the maximum likelihood estimate of its mean.
Worked solution
.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as stats from "@ratmath/stats";
console.log(String(stats.fit([2, 0, 3, 1, 4], "poisson").params.lambda));
Checked output
2
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One or two parameters and about 5–200 observations for sample likelihoods; include boundary parameter values.
Focal example. The code above passed its displayed check in 0.104 ms on Node.
Related workload in this unit.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.fit · 3 passing test cases, 8 distinct argument descriptions
Find the sample variance (divisor ) of 3, 5, 7, 9, 11.
Worked solution
Deviations ; ; .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as stats from "@ratmath/stats";
console.log(String(stats.variance([3, 5, 7, 9, 11])));
Checked output
10
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One or two parameters and about 5–200 observations for sample likelihoods; include boundary parameter values.
For this problem type. Use lists of about 4–30 values by hand and tens to hundreds on a calculator. Include ties, fractions and even or odd sample sizes as appropriate.
Focal example. The code above passed its displayed check in 0.130 ms on Node.
Related workload in this unit.stats.mean · observations. Baseline test points across courses 2, 5, 20, 100. Mean of integers 1 through n is (n+1)/2.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 100,000 (129 ms, 142.2 MiB peak process RSS). The first sampled passing call above 100 ms used 100,000 (129 ms). The runs did not locate a ceiling for this family. Exact sums take at least one visit per observation. Unrelated denominators can make the running sum much larger than in this integer sample.
Measured times, memory and outcomes
observations · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.796
75.5
5
Baseline
Passed
0.231
74.8
20
Baseline
Passed
0.656
75.1
100
Baseline
Passed
0.370
74.4
1,000
Stretch
Passed
2.29
75.2
10,000
Stretch
Passed
10.14
83.6
100,000
Stretch
Passed
129
142.2
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.variance · 4 passing test cases, 11 distinct argument descriptions
For the data 2, 4, 4, 4, 5, 5, 7, 9 find the mean, the sample standard deviation and the population standard deviation.
Worked solution
Mean 5; squared deviations sum to 32; ; .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as stats from "@ratmath/stats";
const d = [2, 4, 4, 4, 5, 5, 7, 9];
console.log([stats.mean(d), stats.variance(d), stats.sd(d), stats.sd(d, { population: true })]);
Checked output
[5, 32/7, 2.1380899352993950774[7:8], 2]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One or two parameters and about 5–200 observations for sample likelihoods; include boundary parameter values.
For this problem type. Use lists of about 4–30 values by hand and tens to hundreds on a calculator. Include ties, fractions and even or odd sample sizes as appropriate.
Focal example. The code above passed its displayed check in 0.496 ms on Node.
Same API, measured input family.stats.mean · observations. Baseline test points across courses 2, 5, 20, 100. Mean of integers 1 through n is (n+1)/2.
Practical limit. Largest passing sample 100,000 (129 ms, 142.2 MiB peak process RSS). The first sampled passing call above 100 ms used 100,000 (129 ms). The runs did not locate a ceiling for this family. Exact sums take at least one visit per observation. Unrelated denominators can make the running sum much larger than in this integer sample.
Measured times, memory and outcomes
observations · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.796
75.5
5
Baseline
Passed
0.231
74.8
20
Baseline
Passed
0.656
75.1
100
Baseline
Passed
0.370
74.4
1,000
Stretch
Passed
2.29
75.2
10,000
Stretch
Passed
10.14
83.6
100,000
Stretch
Passed
129
142.2
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.mean · 4 passing test cases, 10 distinct argument descriptions
The MGF of a Poisson() variable is . Use it to find .
Worked solution
.
Using RatMath
Enter the expression in the form given. Expand or factor the result in reverse to check that it represents the original expression.
JavaScript module
import * as symbolic from "@ratmath/symbolic";
const M = symbolic.sym("exp(l*(exp(t) - 1))");
console.log(String(symbolic.expand(M.diff("t").diff("t").subs({ t: 0 }).simplify())));
Checked output
l^2 + l
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One or two parameters and about 5–200 observations for sample likelihoods; include boundary parameter values.
For this problem type. Use one or two variables and polynomial degrees roughly 2–6. Rational expressions often have two or three denominator factors.
Focal example. The code above passed its displayed check in 0.835 ms on Node.
Same API, measured input family.symbolic.sym.diff · degree. Baseline test points across courses 1, 2, 4, 8. Derivative of x^n at 2 is n·2^(n−1).
Practical limit. Largest passing sample 1,024 (0.459 ms, 74.4 MiB peak process RSS). The runs did not locate a ceiling for this family. A monomial differentiates to one term. Products, repeated derivatives and expression expansion can make intermediate expressions much larger.
Measured times, memory and outcomes
degree · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.157
75.7
2
Baseline
Passed
0.192
75.7
4
Baseline
Passed
0.276
75.2
8
Baseline
Passed
0.642
75.5
16
Stretch
Passed
18.83
74.7
64
Stretch
Passed
0.406
75
256
Stretch
Passed
0.241
75.3
1,024
Stretch
Passed
0.459
74.4
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
symbolic.sym · 14 passing test cases, 44 distinct argument descriptions
"sin(x)^2 + cos(x)^2", undefined or "tan(x)*cos(x)", undefined · trigonometry
Day 06 / 40 · Estimation
A likelihood boundary
Worked by hand
Problem
Ten independent Bernoulli trials all succeed. Where is the likelihood maximized on [0,1]?
Worked solution
L(p)=p¹⁰ increases to its maximum at 1. Searching only for interior stationary points would miss the estimate.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. One or two parameters and about 5–200 observations for sample likelihoods; include boundary parameter values.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.
Day 07 / 40 · Estimation
Squared-error loss
Direct calculation@ratmath/core
Problem
An estimator has bias 2 and variance 5. Find its MSE.
Worked solution
Add squared bias and variance.
Using RatMath
Put the arithmetic inside the R tag so RatMath parses the literals. Keep fractions as ratios throughout the calculation and attach the units from the problem to the result.
JavaScript module
import { R } from "@ratmath/core";
console.log(String(R`5+2^2`));
Checked output
9
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One or two parameters and about 5–200 observations for sample likelihoods; include boundary parameter values.
Focal example. The code above passed its displayed check in 0.063 ms on Node.
Same arithmetic expression. Replaced its first numeral 5 with 0, 1, 2, 7, 12, 100, 1000, -3, 1/2. All 9 defined variants agreed exactly with Python’s rational arithmetic. This varies the arithmetic operation while holding the rest of the expression fixed.
Related workload in this unit.core.Rational.multiply · operand bits. Baseline test points across courses 8, 32, 64, 256. Cross-multiply the unreduced integer products; operands have unlike denominators.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 131,072 (1.53 ms, 75.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Intermediate products can have twice the bit length of their factors. Repeated squaring can exhaust the engine’s BigInt allocation limit in a small number of steps.
Measured times, memory and outcomes
operand bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
8
Baseline
Passed
0.317
74.6
32
Baseline
Passed
0.035
75.5
64
Baseline
Passed
0.045
75.1
256
Baseline
Passed
0.106
74
1,024
Stretch
Passed
0.035
75.3
8,192
Stretch
Passed
0.075
75.8
32,768
Stretch
Passed
0.245
75
131,072
Stretch
Passed
1.53
75.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
core.R · 2 passing test cases, 10 distinct argument descriptions
Which statistic contains the sample dependence in the likelihood of n iid Bernoulli(p) observations?
Worked solution
The likelihood is pˢ(1−p)ⁿ⁻ˢ with s the number of successes. The factorization theorem makes s sufficient.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. One or two parameters and about 5–200 observations for sample likelihoods; include boundary parameter values.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.
Day 09 / 40 · Intervals and tests
Two-sample t test
Direct calculation@ratmath/stats
Problem
Group A: 12, 15, 11, 14, 13. Group B: 16, 18, 15, 17, 19. Test equal means with the pooled two-sample test. Give , the degrees of freedom and the two-sided -value.
Worked solution
, , both , pooled . , 8 df, .
Using RatMath
Enter the observations or count table in the order specified. Match the alternative and test options to the question before interpreting the statistic and tail probability.
JavaScript module
import * as stats from "@ratmath/stats";
const r = stats.tTest([12, 15, 11, 14, 13], [16, 18, 15, 17, 19], { equalVariance: true });
console.log([r.statistic, r.df, r.pValue]);
Checked output
[-4, 8, 0.0039497728034453258[1:2]]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One- and two-sample tests, paired observations or small contingency tables; n often 5–100 per group.
For this problem type. Typical exercises use 5–100 observations per group, or small count tables; confidence levels commonly run from 90% to 99%. The admissible data depend on the named procedure.
Focal example. The code above passed its displayed check in 10.06 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Same API, measured input family.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.tTest · 5 passing test cases, 15 distinct argument descriptions
Blood pressure before: 200, 210, 190, 220, 205; after: 195, 200, 192, 210, 198. Test for a change with a paired test (two-sided).
Worked solution
Differences 5, 10, , 10, 7: , . , 4 df, : not significant at 5%.
Using RatMath
Preserve the order of the before and after observations so each difference concerns the same patient. Interpret the two-sided test of the mean difference.
JavaScript module
import * as stats from "@ratmath/stats";
const r = stats.tTest([200, 210, 190, 220, 205], [195, 200, 192, 210, 198], { paired: true });
console.log([r.statistic, r.pValue]);
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One- and two-sample tests, paired observations or small contingency tables; n often 5–100 per group.
For this problem type. Typical exercises use 5–100 observations per group, or small count tables; confidence levels commonly run from 90% to 99%. The admissible data depend on the named procedure.
Focal example. The code above passed its displayed check in 8.51 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Same API, measured input family.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.tTest · 5 passing test cases, 15 distinct argument descriptions
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One- and two-sample tests, paired observations or small contingency tables; n often 5–100 per group.
For this problem type. Typical exercises use 5–100 observations per group, or small count tables; confidence levels commonly run from 90% to 99%. The admissible data depend on the named procedure.
Focal example. The code above passed its displayed check in 73.95 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Related workload in this unit.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.varianceInterval · 3 passing test cases, 5 distinct argument descriptions
In two samples of 100, 45 and 30 people agree. Give a 95% confidence interval for .
Worked solution
.
Using RatMath
Enter the observations or count table in the order specified. Match the alternative and test options to the question before interpreting the statistic and tail probability.
JavaScript module
import * as stats from "@ratmath/stats";
const I = stats.proportionTest([45, 30], [100, 100]).interval();
console.log([I.low, I.high]);
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One- and two-sample tests, paired observations or small contingency tables; n often 5–100 per group.
For this problem type. Typical exercises use 5–100 observations per group, or small count tables; confidence levels commonly run from 90% to 99%. The admissible data depend on the named procedure.
Focal example. The code above passed its displayed check in 23.46 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Related workload in this unit.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.proportionTest · 1 passing test case, 3 distinct argument descriptions
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One- and two-sample tests, paired observations or small contingency tables; n often 5–100 per group.
For this problem type. Typical exercises use 5–100 observations per group, or small count tables; confidence levels commonly run from 90% to 99%. The admissible data depend on the named procedure.
Focal example. The code above passed its displayed check in 123 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Related workload in this unit.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.meanInterval · 4 passing test cases, 13 distinct argument descriptions
Test against for the data 5.1, 4.9, 5.6, 5.8, 6.0, 5.3, 5.5, 5.9.
Worked solution
, , on 7 df, .
Using RatMath
Use the two-sided one-sample model; interpret its p-value under the null and check the independence and distribution assumptions for these eight observations.
JavaScript module
import * as stats from "@ratmath/stats";
const r = stats.tTest(["5.1", "4.9", "5.6", "5.8", "6.0", "5.3", "5.5", "5.9"], { mu: 5 });
console.log([r.statistic, r.pValue]);
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One- and two-sample tests, paired observations or small contingency tables; n often 5–100 per group.
For this problem type. Typical exercises use 5–100 observations per group, or small count tables; confidence levels commonly run from 90% to 99%. The admissible data depend on the named procedure.
Focal example. The code above passed its displayed check in 15.26 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Same API, measured input family.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.tTest · 5 passing test cases, 15 distinct argument descriptions
Which interval includes variation of a new observation as well as uncertainty about its conditional mean?
Worked solution
A prediction interval. State whether the target is one future response or its mean at that predictor value.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. One- and two-sample tests, paired observations or small contingency tables; n often 5–100 per group.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.
Day 16 / 40 · Intervals and tests
Multiple testing
Direct calculation@ratmath/core
Problem
With five tests at familywise level .05, what Bonferroni threshold applies to each?
Worked solution
Allocate the error budget equally and apply the union bound.
Using RatMath
Put the arithmetic inside the R tag so RatMath parses the literals. Keep fractions as ratios throughout the calculation and attach the units from the problem to the result.
JavaScript module
import { R } from "@ratmath/core";
console.log(String(R`0.05/5`));
Checked output
1/100
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One- and two-sample tests, paired observations or small contingency tables; n often 5–100 per group.
Focal example. The code above passed its displayed check in 0.145 ms on Node.
Same arithmetic expression. Replaced its first numeral 0.05 with 0, 1, 2, 7, 12, 100, 1000, -3, 1/2. All 9 defined variants agreed exactly with Python’s rational arithmetic. This varies the arithmetic operation while holding the rest of the expression fixed.
Related workload in this unit.core.Rational.add · denominator. Baseline test points across courses 1, 2, 3, 12, 100, 1,000. Cross-multiply 1/n + 1/(n+1) against (2n+1)/(n(n+1)).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000,000,007 (0.038 ms, 76.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Exact work depends on the bit lengths of both numerator and denominator. A long sum of relatively prime fractions can build a large common denominator.
Measured times, memory and outcomes
denominator · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.034
74.9
2
Baseline
Passed
0.036
75.6
3
Baseline
Passed
0.040
75.9
12
Baseline
Passed
0.039
75.2
100
Baseline
Passed
0.041
75
1,000
Baseline
Passed
0.035
75.8
1,000,003
Stretch
Passed
0.044
75
1,000,000,007
Stretch
Passed
0.038
76.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
core.R · 2 passing test cases, 10 distinct argument descriptions
Three groups: , , . Compute the ANOVA statistic and its -value.
Worked solution
Means 5, 7, 10, grand mean . , . on (2, 6) df, .
Using RatMath
Enter the observations or count table in the order specified. Match the alternative and test options to the question before interpreting the statistic and tail probability.
JavaScript module
import * as stats from "@ratmath/stats";
const r = stats.anova([[4, 5, 6], [6, 7, 8], [9, 10, 11]]);
console.log([r.statistic, r.pValue]);
Checked output
[19, 0.0025356874530428249[4:5]]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Typically 1–5 predictors and tens to hundreds of rows, or 2–5 groups. Rank and residual degrees of freedom constrain the fit.
For this problem type. Typical exercises use 5–100 observations per group, or small count tables; confidence levels commonly run from 90% to 99%. The admissible data depend on the named procedure.
Focal example. The code above passed its displayed check in 6.77 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Related workload in this unit.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.anova · 3 passing test cases, 4 distinct argument descriptions
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Typically 1–5 predictors and tens to hundreds of rows, or 2–5 groups. Rank and residual degrees of freedom constrain the fit.
For this problem type. Hand fits use about 4–12 paired observations. A classroom dataset can have tens to hundreds of rows and one to five predictors. Include a nonconstant predictor.
Focal example. The code above passed its displayed check in 8.11 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Same API, measured input family.stats.linearModel · observations; one predictor. Baseline test points across courses 4, 5, 10, 50. Check recovery of intercept 3 and slope 2 from exact data y=3+2x.
Practical limit. Largest passing sample 5,000 (106 ms, 124.9 MiB peak process RSS). The first sampled passing call above 100 ms used 5,000 (106 ms). The runs did not locate a ceiling for this family. The number of predictors and matrix rank matter independently of row count. A perfect fit can make standard-error or inference formulas degenerate.
Measured times, memory and outcomes
observations; one predictor · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
4
Baseline
Passed
1.01
76.4
5
Baseline
Passed
0.941
74.6
10
Baseline
Passed
5.18
74.7
50
Baseline
Passed
20.91
75.7
200
Stretch
Passed
10.07
80.1
1,000
Stretch
Passed
33.39
89.1
5,000
Stretch
Passed
106
124.9
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.linearModel · 6 passing test cases, 13 distinct argument descriptions
For the regression of on with an intercept, find .
Worked solution
, … more simply .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as stats from "@ratmath/stats";
console.log(String(stats.linearModel([1, 2, 3, 4, 5], [2, 4, 5, 4, 6]).rSquared));
Checked output
8/11
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Typically 1–5 predictors and tens to hundreds of rows, or 2–5 groups. Rank and residual degrees of freedom constrain the fit.
For this problem type. Hand fits use about 4–12 paired observations. A classroom dataset can have tens to hundreds of rows and one to five predictors. Include a nonconstant predictor.
Focal example. The code above passed its displayed check in 0.297 ms on Node.
Same API, measured input family.stats.linearModel · observations; one predictor. Baseline test points across courses 4, 5, 10, 50. Check recovery of intercept 3 and slope 2 from exact data y=3+2x.
Practical limit. Largest passing sample 5,000 (106 ms, 124.9 MiB peak process RSS). The first sampled passing call above 100 ms used 5,000 (106 ms). The runs did not locate a ceiling for this family. The number of predictors and matrix rank matter independently of row count. A perfect fit can make standard-error or inference formulas degenerate.
Measured times, memory and outcomes
observations; one predictor · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
4
Baseline
Passed
1.01
76.4
5
Baseline
Passed
0.941
74.6
10
Baseline
Passed
5.18
74.7
50
Baseline
Passed
20.91
75.7
200
Stretch
Passed
10.07
80.1
1,000
Stretch
Passed
33.39
89.1
5,000
Stretch
Passed
106
124.9
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.linearModel · 6 passing test cases, 13 distinct argument descriptions
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Typically 1–5 predictors and tens to hundreds of rows, or 2–5 groups. Rank and residual degrees of freedom constrain the fit.
For this problem type. Hand fits use about 4–12 paired observations. A classroom dataset can have tens to hundreds of rows and one to five predictors. Include a nonconstant predictor.
Focal example. The code above passed its displayed check in 0.366 ms on Node.
Same API, measured input family.stats.linearModel · observations; one predictor. Baseline test points across courses 4, 5, 10, 50. Check recovery of intercept 3 and slope 2 from exact data y=3+2x.
Practical limit. Largest passing sample 5,000 (106 ms, 124.9 MiB peak process RSS). The first sampled passing call above 100 ms used 5,000 (106 ms). The runs did not locate a ceiling for this family. The number of predictors and matrix rank matter independently of row count. A perfect fit can make standard-error or inference formulas degenerate.
Measured times, memory and outcomes
observations; one predictor · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
4
Baseline
Passed
1.01
76.4
5
Baseline
Passed
0.941
74.6
10
Baseline
Passed
5.18
74.7
50
Baseline
Passed
20.91
75.7
200
Stretch
Passed
10.07
80.1
1,000
Stretch
Passed
33.39
89.1
5,000
Stretch
Passed
106
124.9
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.linearModel · 6 passing test cases, 13 distinct argument descriptions
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as stats from "@ratmath/stats";
console.log(stats.correlation([1, 2, 3, 4, 5], [2, 4, 5, 4, 6]));
Checked output
0.85280286542244173719:0.8528028654224417372
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Typically 1–5 predictors and tens to hundreds of rows, or 2–5 groups. Rank and residual degrees of freedom constrain the fit.
For this problem type. Hand fits use about 4–12 paired observations. A classroom dataset can have tens to hundreds of rows and one to five predictors. Include a nonconstant predictor.
Focal example. The code above passed its displayed check in 0.433 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Related workload in this unit.stats.mean · observations. Baseline test points across courses 2, 5, 20, 100. Mean of integers 1 through n is (n+1)/2.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 100,000 (129 ms, 142.2 MiB peak process RSS). The first sampled passing call above 100 ms used 100,000 (129 ms). The runs did not locate a ceiling for this family. Exact sums take at least one visit per observation. Unrelated denominators can make the running sum much larger than in this integer sample.
Measured times, memory and outcomes
observations · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.796
75.5
5
Baseline
Passed
0.231
74.8
20
Baseline
Passed
0.656
75.1
100
Baseline
Passed
0.370
74.4
1,000
Stretch
Passed
2.29
75.2
10,000
Stretch
Passed
10.14
83.6
100,000
Stretch
Passed
129
142.2
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.correlation · 2 passing test cases, 5 distinct argument descriptions
For the fitted line , find the residual of the observation .
Worked solution
; residual .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as stats from "@ratmath/stats";
console.log(String(stats.leastSquares([1, 2, 3, 4, 5], [2, 4, 5, 4, 6]).residuals[2]));
Checked output
4/5
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Typically 1–5 predictors and tens to hundreds of rows, or 2–5 groups. Rank and residual degrees of freedom constrain the fit.
For this problem type. Hand fits use about 4–12 paired observations. A classroom dataset can have tens to hundreds of rows and one to five predictors. Include a nonconstant predictor.
Focal example. The code above passed its displayed check in 0.222 ms on Node.
Same API, measured input family.stats.leastSquares · observations. Baseline test points across courses 2, 4, 10, 50. All residuals must vanish on the exact line y=2x+3.
Practical limit. Largest passing sample 20,000 (276 ms, 132.4 MiB peak process RSS). The first sampled passing call above 100 ms used 20,000 (276 ms). The runs did not locate a ceiling for this family. Rows, predictors and coefficient bit lengths all affect cost. A perfect line tests arithmetic, while noisy, singular or nearly collinear data require different diagnostics.
Measured times, memory and outcomes
observations · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
3.11
74.8
4
Baseline
Passed
0.578
75.9
10
Baseline
Passed
1.74
76
50
Baseline
Passed
2.62
75
200
Stretch
Passed
4.21
76.8
2,000
Stretch
Passed
36.00
88.2
20,000
Stretch
Passed
276
132.4
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.leastSquares · 4 passing test cases, 5 distinct argument descriptions
Why might fitting outcome on treatment in an observational study give a misleading treatment effect?
Worked solution
A variable associated with assignment and outcome may explain the association. Specify a causal design or defensible adjustment set.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. Typically 1–5 predictors and tens to hundreds of rows, or 2–5 groups. Rank and residual degrees of freedom constrain the fit.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.
Day 24 / 40 · Regression and group comparisons
Residual degrees of freedom
Direct calculation@ratmath/core
Problem
An intercept-plus-two-slope model has full rank on 20 observations. Find residual degrees of freedom.
Worked solution
Three coefficients use three independent directions.
Using RatMath
Put the arithmetic inside the R tag so RatMath parses the literals. Keep fractions as ratios throughout the calculation and attach the units from the problem to the result.
JavaScript module
import { R } from "@ratmath/core";
console.log(String(R`20-3`));
Checked output
17
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Typically 1–5 predictors and tens to hundreds of rows, or 2–5 groups. Rank and residual degrees of freedom constrain the fit.
Focal example. The code above passed its displayed check in 0.097 ms on Node.
Same arithmetic expression. Replaced its first numeral 20 with 0, 1, 2, 7, 12, 100, 1000, -3, 1/2. All 9 defined variants agreed exactly with Python’s rational arithmetic. This varies the arithmetic operation while holding the rest of the expression fixed.
Related workload in this unit.core.R · whole-number operand. Baseline test points across courses 0, 1, 10, 20, 100, 1,000, 1,000,000. (n+7)(n−3) by independent BigInt arithmetic.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 9,007,199,254,740,991 (1.67 ms, 75.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Exact integer arithmetic grows with operand bit length. Enter large integers as decimal strings or BigInts before any JavaScript Number conversion.
Measured times, memory and outcomes
whole-number operand · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
0
Baseline
Passed
1.75
75
1
Baseline
Passed
1.70
75.7
10
Baseline
Passed
1.78
75.1
20
Baseline
Passed
1.88
75.4
100
Baseline
Passed
1.55
75.4
1,000
Baseline
Passed
1.36
75.3
1,000,000
Baseline
Passed
1.39
74.8
1,000,000,000
Stretch
Passed
1.69
76.3
9,007,199,254,740,991
Stretch
Passed
1.67
75.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
core.R · 2 passing test cases, 10 distinct argument descriptions
Compare with by the Mann–Whitney (Wilcoxon rank-sum) test. Give and the exact two-sided -value.
Worked solution
Every value in the first sample is below every value in the second, so . Only 1 of the arrangements is that extreme on each side: .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as stats from "@ratmath/stats";
const r = stats.mannWhitneyTest([1.1, 2.3, 3.0], [3.5, 4.1, 5.2, 6.0]);
console.log([r.statistic, r.pValue]);
Checked output
[0, 2/35]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small ordinal or categorical samples, commonly at most a few dozen per group for exact enumeration; ties change the null law.
For this problem type. Typical exercises use 5–100 observations per group, or small count tables; confidence levels commonly run from 90% to 99%. The admissible data depend on the named procedure.
Focal example. The code above passed its displayed check in 1.07 ms on Node.
Related workload in this unit.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.mannWhitneyTest · 2 passing test cases, 4 distinct argument descriptions
Implementation limit. Automatic mode uses exact counting when each group has at most 50 observations and both together have at most 80. Larger cases switch to a normal approximation. Source at the tested revision
Day 26 / 40 · Ranks and exact inference
Sign test
Direct calculation@ratmath/stats
Problem
Of 10 paired differences, 9 are positive and 1 negative. Find the two-sided sign-test -value.
Worked solution
.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as stats from "@ratmath/stats";
console.log(String(stats.signTest([1, 1, 1, 1, 1, 1, 1, 1, 1, -1]).pValue));
Checked output
11/512
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small ordinal or categorical samples, commonly at most a few dozen per group for exact enumeration; ties change the null law.
For this problem type. Typical exercises use 5–100 observations per group, or small count tables; confidence levels commonly run from 90% to 99%. The admissible data depend on the named procedure.
Focal example. The code above passed its displayed check in 0.874 ms on Node.
Related workload in this unit.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.signTest · 1 passing test case, 2 distinct argument descriptions
Find the two-sided Fisher exact -value for the table .
Worked solution
Hypergeometric probabilities for the top-left cell : . Tables at most as likely as the observed one: .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as stats from "@ratmath/stats";
console.log(String(stats.fisherTest([[3, 1], [1, 3]]).pValue));
Checked output
17/35
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small ordinal or categorical samples, commonly at most a few dozen per group for exact enumeration; ties change the null law.
For this problem type. Typical exercises use 5–100 observations per group, or small count tables; confidence levels commonly run from 90% to 99%. The admissible data depend on the named procedure.
Focal example. The code above passed its displayed check in 0.215 ms on Node.
Related workload in this unit.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.fisherTest · 1 passing test case, 6 distinct argument descriptions
[[3, 1] (n=2), [1, 3] (n=2)] (2×2) or [[8, 2] (n=2), [1, 5] (n=2)] (2×2) · Fisher's test
Day 28 / 40 · Ranks and exact inference
Kolmogorov–Smirnov statistic
Direct calculation@ratmath/stats
Problem
Find the Kolmogorov–Smirnov statistic for the sample 0.1, 0.4, 0.7 against the uniform distribution on .
Worked solution
Compare with the step function: at 0.1 the gaps are 0.1 and 0.233, at 0.4 they are 0.267 and 0.067, at 0.7 they are 0.3 and 0.033. .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as stats from "@ratmath/stats";
console.log(String(stats.ksTest([0.1, 0.4, 0.7], stats.uniform(0, 1)).statistic));
Checked output
3/10
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small ordinal or categorical samples, commonly at most a few dozen per group for exact enumeration; ties change the null law.
For this problem type. Use a scalar random variable, one or two parameters, and one or two probability bounds. Normal-table exercises tend to stay within about 3 standard deviations.
Focal example. The code above passed its displayed check in 0.720 ms on Node.
Related workload in this unit.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.ksTest · 2 passing test cases, 3 distinct argument descriptions
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as stats from "@ratmath/stats";
console.log(String(stats.spearmanTest([1, 2, 3, 4, 5], [2, 1, 4, 3, 5]).statistic));
Checked output
4/5
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small ordinal or categorical samples, commonly at most a few dozen per group for exact enumeration; ties change the null law.
For this problem type. Hand fits use about 4–12 paired observations. A classroom dataset can have tens to hundreds of rows and one to five predictors. Include a nonconstant predictor.
Focal example. The code above passed its displayed check in 0.969 ms on Node.
Related workload in this unit.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.spearmanTest · 1 passing test case, 2 distinct argument descriptions
[86, 97, 99, 100, …] (n=10), [2, 20, 28, 27, …] (n=10) or [1, 2, 3, 4, …] (n=5), [2, 1, 4, 3, …] (n=5) · Spearman and Kendall on R's example
Day 30 / 40 · Ranks and exact inference
Kruskal–Wallis test
Direct calculation@ratmath/stats
Problem
Find the Kruskal–Wallis for , , .
Worked solution
Rank sums 6, 15, 24. .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as stats from "@ratmath/stats";
console.log(String(stats.kruskalWallisTest([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).statistic));
Checked output
36/5
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small ordinal or categorical samples, commonly at most a few dozen per group for exact enumeration; ties change the null law.
For this problem type. Typical exercises use 5–100 observations per group, or small count tables; confidence levels commonly run from 90% to 99%. The admissible data depend on the named procedure.
Focal example. The code above passed its displayed check in 1.60 ms on Node.
Related workload in this unit.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.kruskalWallisTest · 1 passing test case, 1 distinct argument description
A die rolled 60 times gives counts 8, 12, 9, 11, 6, 14. Is it fair? Give and the P-value.
Worked solution
Expected 10 each: , 5 df, . No evidence of unfairness.
Using RatMath
Each face has expected count ten under fairness. Interpret the tail probability as evidence about this model. A large p-value does not establish fairness.
JavaScript module
import * as stats from "@ratmath/stats";
const r = stats.chiSquareTest([8, 12, 9, 11, 6, 14]);
console.log([r.statistic, r.pValue]);
Checked output
[21/5, 0.5209949534314049879[2:3]]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small ordinal or categorical samples, commonly at most a few dozen per group for exact enumeration; ties change the null law.
For this problem type. Typical exercises use 5–100 observations per group, or small count tables; confidence levels commonly run from 90% to 99%. The admissible data depend on the named procedure.
Focal example. The code above passed its displayed check in 12.03 ms on Node.
Related workload in this unit.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.chiSquareTest · 3 passing test cases, 11 distinct argument descriptions
When is it defensible to shuffle treatment labels in a randomization test?
Worked solution
The shuffle must follow the actual assignment mechanism under the null. Paired or blocked assignments constrain which shuffles are legal.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. Small ordinal or categorical samples, commonly at most a few dozen per group for exact enumeration; ties change the null law.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.
Day 33 / 40 · Design, power and Bayesian inference
Power of a z test
Direct calculation@ratmath/stats
Problem
Test against with , , . What is the power when the true mean is 106?
Worked solution
Reject when . Power .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as stats from "@ratmath/stats";
console.log(stats.power({ mu0: 100, mu: 106, sigma: 15, n: 25, alternative: "greater" }).power);
Checked output
0.6387600313123350643[1:4]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Powers and confidence levels commonly 0.8–0.99, nonzero effects and positive target margins; sample size can explode as precision tightens.
For this problem type. Use common confidence or power levels of 80–99%, margins around 0.01–0.1 on a unit scale, and a stated nonzero effect for a power calculation.
Focal example. The code above passed its displayed check in 13.80 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Related workload in this unit.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.power · 6 passing test cases, 12 distinct argument descriptions
Day 34 / 40 · Design, power and Bayesian inference
Sample size
Direct calculation@ratmath/stats
Problem
How large a sample gives a margin of error of at most 3 percentage points for a proportion at 95% confidence (use )?
Worked solution
, so .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as stats from "@ratmath/stats";
console.log(stats.sampleSize({ margin: "0.03", p: "1/2" }).n);
Checked output
1068
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Powers and confidence levels commonly 0.8–0.99, nonzero effects and positive target margins; sample size can explode as precision tightens.
For this problem type. Use common confidence or power levels of 80–99%, margins around 0.01–0.1 on a unit scale, and a stated nonzero effect for a power calculation.
Focal example. The code above passed its displayed check in 22.70 ms on Node.
Same API, measured input family.stats.sampleSize · decimal places in margin. Baseline test points across courses 1, 2, 3, 4. For the 95% known-σ mean interval, both bound endpoints must have the same ceiling and the returned n must equal that exact integer.
Practical limit. Largest passing sample 10 (117 ms, 89.1 MiB peak process RSS). The first sampled passing call above 100 ms used 10 (117 ms). The runs did not locate a ceiling for this family. Required size grows roughly as the inverse square of the margin. Check the exact ceiling of both returned bound endpoints before trusting a large integer n.
Measured times, memory and outcomes
decimal places in margin · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
57.47
88.6
2
Baseline
Passed
41.24
87.9
3
Baseline
Passed
34.93
88.9
4
Baseline
Passed
36.85
88.8
6
Stretch
Passed
55.53
89.2
8
Stretch
Passed
43.76
88.7
9
Stretch
Passed
45.04
88.3
10
Stretch
Passed
117
89.1
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.sampleSize · 4 passing test cases, 10 distinct argument descriptions
Fixed · Large sample sizes preserve the exact ceiling. At margin 10⁻⁹, σ=1 and 95% confidence, n and the ceilings of both bound endpoints now equal 3841458820694125959. The large result is a BigInt. Preserve that type during further calculations.
Fixed · Power at the null is handled explicitly. For μ=μ₀, σ=1 and α=0.05, the continuous known-σ test has power 0.05 for every positive sample size. The planner returns the minimum n=1 for a target of 0.04.
Day 35 / 40 · Design, power and Bayesian inference
Conjugate prior
Direct calculation@ratmath/stats
Problem
With a uniform Beta(1, 1) prior on a success probability, 7 successes are seen in 10 trials. Give the posterior and its mean.
Worked solution
Beta(8, 4), with mean .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as stats from "@ratmath/stats";
const post = stats.betaPrior(1, 1).update({ successes: 7, trials: 10 });
console.log([post.params, post.mean]);
Checked output
[{ a: 8, b: 4 }, 2/3]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Powers and confidence levels commonly 0.8–0.99, nonzero effects and positive target margins; sample size can explode as precision tightens.
Focal example. The code above passed its displayed check in 0.432 ms on Node.
Related workload in this unit.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.betaPrior · 1 passing test case, 2 distinct argument descriptions
Day 36 / 40 · Design, power and Bayesian inference
Bayes with urns
Direct calculation@ratmath/stats
Problem
Urn 1 has 3 red and 2 blue balls, urn 2 has 1 red and 4 blue. An urn is chosen at random and a red ball drawn. What is the probability it came from urn 1?
Worked solution
.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as stats from "@ratmath/stats";
console.log(
String(stats.bayes({ one: "1/2", two: "1/2" }, { one: "3/5", two: "1/5" }).posterior.p("one"))
);
Checked output
3/4
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Powers and confidence levels commonly 0.8–0.99, nonzero effects and positive target margins; sample size can explode as precision tightens.
For this problem type. Use a few events or a table of roughly 2–36 elementary outcomes. Two to four independent dice are common; verify whether the question needs ordered tuples or a sum.
Focal example. The code above passed its displayed check in 0.139 ms on Node.
Related workload in this unit.stats.sampleSize · decimal places in margin. Baseline test points across courses 1, 2, 3, 4. For the 95% known-σ mean interval, both bound endpoints must have the same ceiling and the returned n must equal that exact integer.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10 (117 ms, 89.1 MiB peak process RSS). The first sampled passing call above 100 ms used 10 (117 ms). The runs did not locate a ceiling for this family. Required size grows roughly as the inverse square of the margin. Check the exact ceiling of both returned bound endpoints before trusting a large integer n.
Measured times, memory and outcomes
decimal places in margin · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
57.47
88.6
2
Baseline
Passed
41.24
87.9
3
Baseline
Passed
34.93
88.9
4
Baseline
Passed
36.85
88.8
6
Stretch
Passed
55.53
89.2
8
Stretch
Passed
43.76
88.7
9
Stretch
Passed
45.04
88.3
10
Stretch
Passed
117
89.1
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.bayes · 1 passing test case, 3 distinct argument descriptions
{sick="1/100", well="99/100"}, {sick="95/100", well="5/100"} or Finite, function · Bayes' rule
Day 37 / 40 · Design, power and Bayesian inference
Central limit theorem
Assisted@ratmath/stats · @ratmath/core
Problem
100 fair dice are rolled. Estimate with the normal approximation, and give the exact value.
Worked solution
Mean 350, SD . With continuity correction . Exactly (by convolution in Python) 0.126948.
Using RatMath
The convolution gives the exact tail. For the normal estimate use mean 350, variance 100×35/12 and the continuity-corrected cutoff 369.5.
JavaScript module
import * as stats from "@ratmath/stats";
import { R } from "@ratmath/core";
const S = stats.die().sumOf(100);
console.log(R`1`.subtract(S.cdf(369)));
Checked output
0.126947761041731454742050…
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Powers and confidence levels commonly 0.8–0.99, nonzero effects and positive target margins; sample size can explode as precision tightens.
For this problem type. Use a few events or a table of roughly 2–36 elementary outcomes. Two to four independent dice are common; verify whether the question needs ordered tuples or a sum.
Focal example. The code above passed its displayed check in 1,874 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Same API, measured input family.stats.die.sumOf · six-sided dice. Baseline test points across courses 1, 2, 5, 10, 30. For a sum of n fair dice, E[X]=7n/2 and Var[X]=35n/12.
Practical limit. Largest passing sample 100 (1,985 ms, 215.1 MiB peak process RSS). Time cutoff at 250, 500. The first sampled passing call above one second used 100 (1,985 ms). A sum of dice has only 5n+1 totals. Exact convolution still slows as support and rational weights grow. Enumerating ordered tuples grows as 6ⁿ.
Measured times, memory and outcomes
six-sided dice · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
3.94
75.1
2
Baseline
Passed
1.63
75.2
5
Baseline
Passed
3.03
77.2
10
Baseline
Passed
10.19
79.1
30
Baseline
Passed
67.18
89.7
100
Stretch
Passed
1,985
215.1
250
Stretch
Time cutoff
—
250.2
500
Stretch
Time cutoff
—
274.8
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.die · 4 passing test cases, 2 distinct argument descriptions
Seven ordered dice. The current product represents 279,936 outcomes in 0.34 ms and streams the order-sensitive probability check in 33.46 ms. Accessing .entries materializes all tuples. For the sum, stats.die().sumOf(7) needs only 36 totals. Compare the representations and their measured costs
Accuracy notes (1)
Open · Two distinct categorical tuples can merge. A uniform table on the two arrays [‘a,sb’,‘c’] and [‘a’,‘b,sc’] should give each probability 1/2. The table reports one outcome with probability 1 because the composite string keys collide. Use unambiguous scalar IDs for such labels. Ordinary numeric dice faces have distinct keys.
Day 38 / 40 · Design, power and Bayesian inference
Confidence interval for a proportion
Direct calculation@ratmath/stats
Problem
In a poll, 540 of 900 people say yes. Give a 95% confidence interval for the proportion.
Worked solution
, SE ; : .
Using RatMath
Identify the parameter, enter the sample information and select the interval method. Read the two returned bounds using the units of that parameter.
JavaScript module
import * as stats from "@ratmath/stats";
const ci = stats.proportionInterval(540, 900, { method: "wald" });
console.log([ci.low, ci.high]);
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Powers and confidence levels commonly 0.8–0.99, nonzero effects and positive target margins; sample size can explode as precision tightens.
For this problem type. Typical exercises use 5–100 observations per group, or small count tables; confidence levels commonly run from 90% to 99%. The admissible data depend on the named procedure.
Focal example. The code above passed its displayed check in 69.67 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Related workload in this unit.stats.tTest · observations per sample. Baseline test points across courses 3, 8, 20, 50. A symmetric sample centered at its hypothesized mean has t=0 and a two-sided p-value of 1.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (83.32 ms, 88.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Tail probability, degrees of freedom, ties and variance assumptions matter. A larger sample cannot repair an inappropriate test or model.
Measured times, memory and outcomes
observations per sample · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
1.62
75.7
8
Baseline
Passed
1.77
75
20
Baseline
Passed
1.68
75.4
50
Baseline
Passed
1.28
75.1
200
Stretch
Passed
3.24
75
1,000
Stretch
Passed
5.50
78.8
10,000
Stretch
Passed
83.32
88.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.proportionInterval · 2 passing test cases, 12 distinct argument descriptions
Day 39 / 40 · Design, power and Bayesian inference
Posterior predictive probability
Direct calculation@ratmath/core
Problem
Under a Beta(2,3) prior observe four successes and one failure. Find the next-trial success probability.
Worked solution
Update to Beta(6,4) and use its mean.
Using RatMath
Put the arithmetic inside the R tag so RatMath parses the literals. Keep fractions as ratios throughout the calculation and attach the units from the problem to the result.
JavaScript module
import { R } from "@ratmath/core";
console.log(String(R`(2+4)/(2+3+5)`));
Checked output
3/5
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Powers and confidence levels commonly 0.8–0.99, nonzero effects and positive target margins; sample size can explode as precision tightens.
Focal example. The code above passed its displayed check in 0.135 ms on Node.
Same arithmetic expression. Replaced its first numeral 2 with 0, 1, 2, 7, 12, 100, 1000, -3, 1/2. All 9 defined variants agreed exactly with Python’s rational arithmetic. This varies the arithmetic operation while holding the rest of the expression fixed.
Related workload in this unit.core.Rational.add · denominator. Baseline test points across courses 1, 2, 3, 12, 100, 1,000. Cross-multiply 1/n + 1/(n+1) against (2n+1)/(n(n+1)).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000,000,007 (0.038 ms, 76.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Exact work depends on the bit lengths of both numerator and denominator. A long sum of relatively prime fractions can build a large common denominator.
Measured times, memory and outcomes
denominator · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.034
74.9
2
Baseline
Passed
0.036
75.6
3
Baseline
Passed
0.040
75.9
12
Baseline
Passed
0.039
75.2
100
Baseline
Passed
0.041
75
1,000
Baseline
Passed
0.035
75.8
1,000,003
Stretch
Passed
0.044
75
1,000,000,007
Stretch
Passed
0.038
76.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
core.R · 2 passing test cases, 10 distinct argument descriptions
Day 40 / 40 · Design, power and Bayesian inference
Power at the null
Worked by hand
Problem
A continuous level-.05 z-test is applied when the null is exactly true. What is its rejection probability?
Worked solution
It is .05 under the calibrated reference model. A request for power below .05 already holds at n=1.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. Powers and confidence levels commonly 0.8–0.99, nonzero effects and positive target margins; sample size can explode as precision tightens.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.