33 of 40 focal problems use RatMath for a calculation or a substantive step.
Direct calculation
28 · 70%
Assisted
5 · 12.5%
Worked by hand
7 · 17.5%
Using the packages
The packages can calculate a statistic and its reference distribution. Deciding whether randomization, independence and sample size justify the model takes the data-collection story.
Calculator interface
Ask for the design and variable types before offering a test. Display the null model, shaded tail, units, hypotheses and confidence interpretation beside the numeric output.
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
33 of 40 days include a checked executable example. On 12 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 · Data and description. About 5–100 observations by hand or a few hundred in a data exercise. Units and sampling design accompany the 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 · Normal and linear models. Standardized scores ordinarily between −3 and 3, and simple regressions with about 5–50 paired observations.
Unit benchmark · stats.normal.cdf, standard deviations from mean. Largest passing sample 24 (1.25 ms, 75.1 MiB peak process RSS). The first sampled passing call above 100 ms used 8 (112 ms). The runs did not locate a ceiling for this family.
Days 17–24 · Chance and random variables. Two to twenty outcomes or draws in small experiments, binomial n often 5–100 and probabilities between 0 and 1.
Unit benchmark · stats.binomial.pmf, trials. Largest passing sample 10,000 (0.836 ms, 74.4 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 25–32 · Design and estimation. Samples from roughly 10 to 1,000, confidence levels commonly 90%, 95% or 99%; the approximation depends on counts and design.
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 · Tests and decisions. One or two groups, or a small contingency table; check expected cell counts and independence before using an asymptotic test.
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.
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.
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. About 5–100 observations by hand or a few hundred in a data exercise. Units and sampling design accompany the 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
A test has mean 72 and standard deviation 8. What is the z-score of a mark of 86?
Worked solution
.
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`(86 - 72)/8`));
Checked output
7/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. About 5–100 observations by hand or a few hundred in a data exercise. Units and sampling design accompany the values.
Focal example. The code above passed its displayed check in 0.093 ms on Node.
Same arithmetic expression. Replaced its first numeral 86 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
Find the mean, median and mode of 4, 8, 6, 5, 8, 10, 8.
Worked solution
Mean ; sorted 4, 5, 6, 8, 8, 8, 10, so median 8; mode 8.
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 = [4, 8, 6, 5, 8, 10, 8];
console.log([stats.mean(d), stats.median(d), stats.modes(d)]);
Checked output
[7, 8, [8]]
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. About 5–100 observations by hand or a few hundred in a data exercise. Units and sampling design accompany the 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.656 ms on Node.
Same API, measured input family.stats.median · observations. Baseline test points across courses 3, 6, 25, 100. The median of n descending consecutive integers 1…n is (n+1)/2.
Practical limit. Largest passing sample 100,000 (89.20 ms, 116 MiB peak process RSS). The runs did not locate a ceiling for this family. Retaining or ordering the observations costs memory. Even-length and repeated values need the stated convention for the statistic.
Measured times, memory and outcomes
observations · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
0.774
74.4
6
Baseline
Passed
0.685
74.5
25
Baseline
Passed
0.545
76.1
100
Baseline
Passed
0.698
75.3
1,000
Stretch
Passed
1.83
76.2
10,000
Stretch
Passed
9.55
81.4
100,000
Stretch
Passed
89.20
116
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
For the data 3, 7, 8, 12, 13, 14, 18, 21, find the range, the quartiles and the interquartile range.
Worked solution
Range . Lower half 3, 7, 8, 12 has median ; upper half 13, 14, 18, 21 has median . IQR .
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 = [3, 7, 8, 12, 13, 14, 18, 21];
console.log(
[stats.range(d), stats.quartiles(d, { method: "halves" }), stats.iqr(d, { method: "halves" })]
);
Checked output
[18, [15/2, 25/2, 16], 17/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. About 5–100 observations by hand or a few hundred in a data exercise. Units and sampling design accompany the 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 2.15 ms on Node.
Related workload in this unit.core.range · terms. Baseline test points across courses 1, 10, 100, 1,000. Check length and every consecutive integer from 1 through n.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000,000 (141 ms, 277.5 MiB peak process RSS). The first sampled passing call above 100 ms used 1,000,000 (141 ms). The runs did not locate a ceiling for this family. Keeping the entire result requires storage proportional to its length. Shortening the displayed list after construction still pays that cost.
Measured times, memory and outcomes
terms · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.173
75.5
10
Baseline
Passed
0.192
74.9
100
Baseline
Passed
0.269
74.7
1,000
Baseline
Passed
1.52
75.6
10,000
Stretch
Passed
5.29
80.9
100,000
Stretch
Passed
11.57
109.6
1,000,000
Stretch
Passed
141
277.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.range · 2 passing test cases, 3 distinct argument descriptions
Replace the largest of 1,2,3,4,5 by 100. What happens to the median?
Worked solution
It stays 3 because the middle rank is unchanged.
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.median([1,2,3,4,100])));
Checked output
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. About 5–100 observations by hand or a few hundred in a data exercise. Units and sampling design accompany the 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.109 ms on Node.
Same API, measured input family.stats.median · observations. Baseline test points across courses 3, 6, 25, 100. The median of n descending consecutive integers 1…n is (n+1)/2.
Practical limit. Largest passing sample 100,000 (89.20 ms, 116 MiB peak process RSS). The runs did not locate a ceiling for this family. Retaining or ordering the observations costs memory. Even-length and repeated values need the stated convention for the statistic.
Measured times, memory and outcomes
observations · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
0.774
74.4
6
Baseline
Passed
0.685
74.5
25
Baseline
Passed
0.545
76.1
100
Baseline
Passed
0.698
75.3
1,000
Stretch
Passed
1.83
76.2
10,000
Stretch
Passed
9.55
81.4
100,000
Stretch
Passed
89.20
116
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.median · 3 passing test cases, 3 distinct argument descriptions
Is polling the first 50 people to reply to an online invitation a simple random sample?
Worked solution
No. Participation depends on who sees and answers the invitation. A calculator cannot recover the missing selection probabilities.
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. About 5–100 observations by hand or a few hundred in a data exercise. Units and sampling design accompany the 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 · Data and description
Random assignment
Worked by hand
Problem
Two classes choose different teaching methods. Can a difference in scores establish causation?
Worked solution
Prior preparation and class composition may confound the comparison. Design a randomized comparison to support a causal claim.
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. About 5–100 observations by hand or a few hundred in a data exercise. Units and sampling design accompany the 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 08 / 40 · Data and description
Predicting from a sample
Direct calculation@ratmath/core
Problem
In a random sample of 50 of a school's 1200 students, 18 prefer soccer. Predict how many students in the school prefer soccer.
Worked solution
; .
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`18/50 * 1200`));
Checked output
432
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. About 5–100 observations by hand or a few hundred in a data exercise. Units and sampling design accompany the values.
Focal example. The code above passed its displayed check in 0.091 ms on Node.
Same arithmetic expression. Replaced its first numeral 18 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
Set the distribution parameters first. Distinguish a point probability, a lower cumulative probability and its complementary tail when reading the result.
JavaScript module
import * as stats from "@ratmath/stats";
import { R } from "@ratmath/core";
console.log(stats.normal().cdf(R`7/4`));
Checked output
0.9599408431361829095[8: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. Standardized scores ordinarily between −3 and 3, and simple regressions with about 5–50 paired observations.
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 5.02 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Same API, measured input family.stats.normal.cdf · standard deviations from mean. Baseline test points across courses 0, 1, 2, 3. Compare both endpoints against tabulated Φ(z) at 0,1,2,3,5 and symmetry Φ(−z)=1−Φ(z); check nonzero negative tail.
Practical limit. Largest passing sample 24 (1.25 ms, 75.1 MiB peak process RSS). The first sampled passing call above 100 ms used 8 (112 ms). The runs did not locate a ceiling for this family. For extreme tails, rounding a CDF to 1 before subtracting loses information. Inspect a direct tail enclosure and its width at the required precision.
Measured times, memory and outcomes
standard deviations from mean · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
0
Baseline
Passed
1.10
74.6
1
Baseline
Passed
15.84
85.7
2
Baseline
Passed
57.85
87.5
3
Baseline
Passed
37.73
88.1
5
Stretch
Passed
67.28
88.3
8
Stretch
Passed
112
88.6
12
Stretch
Passed
236
89.9
24
Stretch
Passed
1.25
75.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.normal · 20 passing test cases, 9 distinct argument descriptions
Heights are normal with mean 64 in and standard deviation 2.5 in. What proportion lie between 60 and 68 inches?
Worked solution
: .
Using RatMath
Set the distribution parameters first. Distinguish a point probability, a lower cumulative probability and its complementary tail when reading the result.
JavaScript module
import * as stats from "@ratmath/stats";
import { R } from "@ratmath/core";
console.log(stats.normal(64, R`2.5`).prob(60, 68));
Checked output
0.8904014166008840120[7:8]
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. Standardized scores ordinarily between −3 and 3, and simple regressions with about 5–50 paired observations.
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 7.67 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Related workload in this unit.stats.normal.cdf · standard deviations from mean. Baseline test points across courses 0, 1, 2, 3. Compare both endpoints against tabulated Φ(z) at 0,1,2,3,5 and symmetry Φ(−z)=1−Φ(z); check nonzero negative tail.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 24 (1.25 ms, 75.1 MiB peak process RSS). The first sampled passing call above 100 ms used 8 (112 ms). The runs did not locate a ceiling for this family. For extreme tails, rounding a CDF to 1 before subtracting loses information. Inspect a direct tail enclosure and its width at the required precision.
Measured times, memory and outcomes
standard deviations from mean · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
0
Baseline
Passed
1.10
74.6
1
Baseline
Passed
15.84
85.7
2
Baseline
Passed
57.85
87.5
3
Baseline
Passed
37.73
88.1
5
Stretch
Passed
67.28
88.3
8
Stretch
Passed
112
88.6
12
Stretch
Passed
236
89.9
24
Stretch
Passed
1.25
75.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.normal · 20 passing test cases, 9 distinct argument descriptions
Scores are normal with mean 500 and standard deviation 100. What score is the 90th percentile?
Worked solution
.
Using RatMath
Set the distribution parameters first. Distinguish a point probability, a lower cumulative probability and its complementary tail when reading the result.
JavaScript module
import * as stats from "@ratmath/stats";
import { R } from "@ratmath/core";
console.log(stats.normal(500, 100).quantile(R`0.9`));
Checked output
628.15515655446004669367:628.1551565544600466991
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. Standardized scores ordinarily between −3 and 3, and simple regressions with about 5–50 paired observations.
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 42.47 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Related workload in this unit.stats.normal.cdf · standard deviations from mean. Baseline test points across courses 0, 1, 2, 3. Compare both endpoints against tabulated Φ(z) at 0,1,2,3,5 and symmetry Φ(−z)=1−Φ(z); check nonzero negative tail.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 24 (1.25 ms, 75.1 MiB peak process RSS). The first sampled passing call above 100 ms used 8 (112 ms). The runs did not locate a ceiling for this family. For extreme tails, rounding a CDF to 1 before subtracting loses information. Inspect a direct tail enclosure and its width at the required precision.
Measured times, memory and outcomes
standard deviations from mean · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
0
Baseline
Passed
1.10
74.6
1
Baseline
Passed
15.84
85.7
2
Baseline
Passed
57.85
87.5
3
Baseline
Passed
37.73
88.1
5
Stretch
Passed
67.28
88.3
8
Stretch
Passed
112
88.6
12
Stretch
Passed
236
89.9
24
Stretch
Passed
1.25
75.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.normal · 20 passing test cases, 9 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. Standardized scores ordinarily between −3 and 3, and simple regressions with about 5–50 paired observations.
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. Standardized scores ordinarily between −3 and 3, and simple regressions with about 5–50 paired observations.
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
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 fit = stats.leastSquares([1, 2, 3, 4, 5], [2, 4, 5, 4, 6]);
console.log([fit.slope, fit.intercept]);
Checked output
[4/5, 9/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. Standardized scores ordinarily between −3 and 3, and simple regressions with about 5–50 paired observations.
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.530 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
A score is 74 in a distribution with mean 62 and SD 8. Find its z-score.
Worked solution
Subtract the mean and divide by the standard deviation.
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`(74-62)/8`));
Checked output
3/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. Standardized scores ordinarily between −3 and 3, and simple regressions with about 5–50 paired observations.
Focal example. The code above passed its displayed check in 0.118 ms on Node.
Same arithmetic expression. Replaced its first numeral 74 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
A regression fitted on children aged 6–10 predicts height at age 60. Why distrust it?
Worked solution
Sixty is outside the observed range and the growth mechanism changes. A small in-sample residual cannot validate that prediction.
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. Standardized scores ordinarily between −3 and 3, and simple regressions with about 5–50 paired observations.
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 17 / 40 · Chance and random variables
Binomial probability
Direct calculation@ratmath/stats · @ratmath/core
Problem
is binomial with , . Find .
Worked solution
(exactly ).
Using RatMath
Set the distribution parameters first. Distinguish a point probability, a lower cumulative probability and its complementary tail when reading the result.
JavaScript module
import * as stats from "@ratmath/stats";
import { R } from "@ratmath/core";
console.log(stats.binomial(10, R`0.3`).pmf(3).toDecimal());
Checked output
0.266827932
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. Two to twenty outcomes or draws in small experiments, binomial n often 5–100 and probabilities between 0 and 1.
For this problem type. Typical examples use small integer counts, trial or population sizes from a few to about 100, and probabilities strictly between 0 and 1 unless studying an endpoint.
Focal example. The code above passed its displayed check in 0.143 ms on Node.
Same API, measured input family.stats.binomial.pmf · trials. Baseline test points across courses 1, 5, 20, 100. For fair trials, P(exactly one success)=n/2^n.
Practical limit. Largest passing sample 10,000 (0.836 ms, 74.4 MiB peak process RSS). The runs did not locate a ceiling for this family. Very large trial counts create long rational probabilities. Near the tails, converting to floating point can erase small positive probabilities.
Measured times, memory and outcomes
trials · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.527
76.3
5
Baseline
Passed
0.495
74.4
20
Baseline
Passed
0.723
75.1
100
Baseline
Passed
10.61
75.4
500
Stretch
Passed
0.559
75.8
2,000
Stretch
Passed
0.536
75.1
10,000
Stretch
Passed
0.836
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.
stats.binomial · 7 passing test cases, 10 distinct argument descriptions
For a binomial random variable with 10 trials and success probability 0.3, find P(X≤2).
Worked solution
.
Using RatMath
Set the distribution parameters first. Distinguish a point probability, a lower cumulative probability and its complementary tail when reading the result.
JavaScript module
import * as stats from "@ratmath/stats";
import { R } from "@ratmath/core";
console.log(stats.binomial(10, R`0.3`).cdf(2).toDecimal());
Checked output
0.3827827864
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. Two to twenty outcomes or draws in small experiments, binomial n often 5–100 and probabilities between 0 and 1.
For this problem type. Typical examples use small integer counts, trial or population sizes from a few to about 100, and probabilities strictly between 0 and 1 unless studying an endpoint.
Focal example. The code above passed its displayed check in 0.208 ms on Node.
Related workload in this unit.core.Rational.roundTo · decimal places. Baseline test points across courses 0, 1, 2, 4, 10. Round one third toward zero and compare with (10^d−1)/(3×10^d).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000 (0.132 ms, 75.8 MiB peak process RSS). The runs did not locate a ceiling for this family. Extra decimal places require longer integers and more output. Choose rounding mode and decimal places explicitly for money or signed values.
Measured times, memory and outcomes
decimal places · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
0
Baseline
Passed
0.113
75
1
Baseline
Passed
0.151
75
2
Baseline
Passed
0.123
75.6
4
Baseline
Passed
0.119
75.1
10
Baseline
Passed
0.120
76.2
50
Stretch
Passed
0.418
75.2
250
Stretch
Passed
0.124
75.2
1,000
Stretch
Passed
0.132
75.8
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.binomial · 7 passing test cases, 10 distinct argument descriptions
A game costs $1. Roll a die: on a 6 you get $6 back (a $5 gain), otherwise nothing. What is the expected gain?
Worked solution
. A fair game.
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.die().mean((x) => (x === 6 ? 5 : -1))));
Checked output
0
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. Two to twenty outcomes or draws in small experiments, binomial n often 5–100 and probabilities between 0 and 1.
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.132 ms on Node.
Related workload in this unit.stats.die.power · six-sided dice in the ordered sample space. Baseline test points across courses 1, 2, 3, 4. The implicit product has 6^n ordered tuples. Check the exact count and the probability of the all-sixes tuple without listing it.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 100 (2.08 ms, 76.7 MiB peak process RSS). The runs did not locate a ceiling for this family. An independent product stores its factors. Point lookup multiplies one weight per die. An arbitrary predicate may visit 6ⁿ tuples; asking for all entries also consumes exponential space.
Measured times, memory and outcomes
six-sided dice in the ordered sample space · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.650
74.9
2
Baseline
Passed
0.654
75.1
3
Baseline
Passed
0.953
75.2
4
Baseline
Passed
0.755
75.3
7
Stretch
Passed
0.751
75.6
9
Stretch
Passed
0.788
75.6
32
Stretch
Passed
1.68
75.5
100
Stretch
Passed
2.08
76.7
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.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 20 / 40 · Chance and random variables
Conditional probability
Direct calculation@ratmath/stats
Problem
Of 50 students who studied, 45 passed; of 50 who did not, 15 passed. Find and .
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";
const table = stats.finite(new Map([[["S", "P"], 45], [["S", "F"], 5], [["N", "P"], 15], [["N", "F"], 35]]), { normalize: true });
console.log(
[table.prob(([s, r]) => r === "P", ([s]) => s === "S"), table.prob(([s]) => s === "S", ([, r]) => r === "P")]
);
Checked output
[9/10, 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. Two to twenty outcomes or draws in small experiments, binomial n often 5–100 and probabilities between 0 and 1.
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.293 ms on Node.
Related workload in this unit.stats.die.power · six-sided dice in the ordered sample space. Baseline test points across courses 1, 2, 3, 4. The implicit product has 6^n ordered tuples. Check the exact count and the probability of the all-sixes tuple without listing it.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 100 (2.08 ms, 76.7 MiB peak process RSS). The runs did not locate a ceiling for this family. An independent product stores its factors. Point lookup multiplies one weight per die. An arbitrary predicate may visit 6ⁿ tuples; asking for all entries also consumes exponential space.
Measured times, memory and outcomes
six-sided dice in the ordered sample space · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.650
74.9
2
Baseline
Passed
0.654
75.1
3
Baseline
Passed
0.953
75.2
4
Baseline
Passed
0.755
75.3
7
Stretch
Passed
0.751
75.6
9
Stretch
Passed
0.788
75.6
32
Stretch
Passed
1.68
75.5
100
Stretch
Passed
2.08
76.7
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.finite · 7 passing test cases, 14 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 21 / 40 · Chance and random variables
Bayes' rule
Direct calculation@ratmath/stats
Problem
A disease affects 1% of people. A test detects it 95% of the time and gives a false positive 5% of the time. Given a positive test, what is the probability of disease?
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({ sick: "0.01", well: "0.99" }, { sick: "0.95", well: "0.05" }).posterior.p("sick"))
);
Checked output
19/118
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. Two to twenty outcomes or draws in small experiments, binomial n often 5–100 and probabilities between 0 and 1.
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.814 ms on Node.
Related workload in this unit.stats.binomial.pmf · trials. Baseline test points across courses 1, 5, 20, 100. For fair trials, P(exactly one success)=n/2^n.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (0.836 ms, 74.4 MiB peak process RSS). The runs did not locate a ceiling for this family. Very large trial counts create long rational probabilities. Near the tails, converting to floating point can erase small positive probabilities.
Measured times, memory and outcomes
trials · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.527
76.3
5
Baseline
Passed
0.495
74.4
20
Baseline
Passed
0.723
75.1
100
Baseline
Passed
10.61
75.4
500
Stretch
Passed
0.559
75.8
2,000
Stretch
Passed
0.536
75.1
10,000
Stretch
Passed
0.836
74.4
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 22 / 40 · Chance and random variables
Addition rule
Direct calculation@ratmath/core
Problem
, , . Find and .
Worked solution
; .
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([R`0.5 + 0.4 - 0.2`, R`0.2 / 0.4`]);
Checked output
[7/10, 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. Two to twenty outcomes or draws in small experiments, binomial n often 5–100 and probabilities between 0 and 1.
Focal example. The code above passed its displayed check in 0.121 ms on Node.
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
Find the mean and variance of the sum of two fair dice.
Worked solution
Mean 7; variance .
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 S = stats.die().sumOf(2);
console.log([S.mean(), S.variance()]);
Checked output
[7, 35/6]
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. Two to twenty outcomes or draws in small experiments, binomial n often 5–100 and probabilities between 0 and 1.
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.885 ms on Node.
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 24 / 40 · Chance and random variables
At least one
Direct calculation@ratmath/stats
Problem
What is the probability of at least one 6 in four rolls of a die?
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.die().power(4).prob((r) => r.includes(6))));
Checked output
671/1296
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. Two to twenty outcomes or draws in small experiments, binomial n often 5–100 and probabilities between 0 and 1.
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.459 ms on Node.
Same API, measured input family.stats.die.power · six-sided dice in the ordered sample space. Baseline test points across courses 1, 2, 3, 4. The implicit product has 6^n ordered tuples. Check the exact count and the probability of the all-sixes tuple without listing it.
Practical limit. Largest passing sample 100 (2.08 ms, 76.7 MiB peak process RSS). The runs did not locate a ceiling for this family. An independent product stores its factors. Point lookup multiplies one weight per die. An arbitrary predicate may visit 6ⁿ tuples; asking for all entries also consumes exponential space.
Measured times, memory and outcomes
six-sided dice in the ordered sample space · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.650
74.9
2
Baseline
Passed
0.654
75.1
3
Baseline
Passed
0.953
75.2
4
Baseline
Passed
0.755
75.3
7
Stretch
Passed
0.751
75.6
9
Stretch
Passed
0.788
75.6
32
Stretch
Passed
1.68
75.5
100
Stretch
Passed
2.08
76.7
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
Implementation limit. Accessing all entries of an implicit product is capped at 2,000,000 outcomes. Point lookup and streaming work beyond this listing guard. Source at the tested revision
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 25 / 40 · Design and estimation
Sampling distribution of the mean
Direct calculation@ratmath/stats
Problem
A population has mean 50 and standard deviation 12. For samples of 36, find .
Worked solution
SE ; .
Using RatMath
Set the distribution parameters first. Distinguish a point probability, a lower cumulative probability and its complementary tail when reading the result.
JavaScript module
import * as stats from "@ratmath/stats";
console.log(stats.normal(50, 2).sf(53));
Checked output
0.066807201268858066:0.06680720126885806601
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. Samples from roughly 10 to 1,000, confidence levels commonly 90%, 95% or 99%; the approximation depends on counts and design.
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 4.42 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.normal · 20 passing test cases, 9 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. Samples from roughly 10 to 1,000, confidence levels commonly 90%, 95% or 99%; the approximation depends on counts and design.
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
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. Samples from roughly 10 to 1,000, confidence levels commonly 90%, 95% or 99%; the approximation depends on counts and design.
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
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. Samples from roughly 10 to 1,000, confidence levels commonly 90%, 95% or 99%; the approximation depends on counts and design.
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 29 / 40 · Design and estimation
Unbiased variance
Direct calculation@ratmath/stats
Problem
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. Samples from roughly 10 to 1,000, confidence levels commonly 90%, 95% or 99%; the approximation depends on counts and design.
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
If sample size increases from 25 to 100, what happens to the SE of an iid sample mean?
Worked solution
The SE is σ/√n, so its new value is half the old one.
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/10`));
Checked output
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. Samples from roughly 10 to 1,000, confidence levels commonly 90%, 95% or 99%; the approximation depends on counts and design.
Focal example. The code above passed its displayed check in 0.096 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.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
Does a 95% frequentist interval mean there is a 95% chance the fixed parameter lies inside this realized interval?
Worked solution
The coverage statement concerns repeated samples and the procedure. The realized interval either covers the fixed parameter or misses it.
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. Samples from roughly 10 to 1,000, confidence levels commonly 90%, 95% or 99%; the approximation depends on counts and design.
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 32 / 40 · Design and estimation
Matching pairs
Worked by hand
Problem
Eight runners are timed before and after training. Which observations should be compared?
Worked solution
Form one change per runner. A paired analysis retains the within-runner relationship.
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. Samples from roughly 10 to 1,000, confidence levels commonly 90%, 95% or 99%; the approximation depends on counts and design.
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 · Tests and decisions
Test for a proportion
Direct calculation@ratmath/stats · @ratmath/core
Problem
Test against when 62 of 100 trials succeed. Give and the P-value.
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";
import { R } from "@ratmath/core";
const r = stats.proportionTest(62, 100, R`1/2`);
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 or two groups, or a small contingency table; check expected cell counts and independence before using an asymptotic test.
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.30 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.proportionTest · 1 passing test case, 3 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 or two groups, or a small contingency table; check expected cell counts and independence before using an asymptotic test.
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
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. One or two groups, or a small contingency table; check expected cell counts and independence before using an asymptotic test.
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
Use studying as rows and passing as columns. Interpret association in the sample and consider how the students were selected.
JavaScript module
import * as stats from "@ratmath/stats";
const r = stats.chiSquareTest([[45, 5], [15, 35]], { correct: false });
console.log([r.statistic, r.pValue]);
Checked output
[75/2, 0.0000000009141298408[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. One or two groups, or a small contingency table; check expected cell counts and independence before using an asymptotic test.
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.82 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
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 or two groups, or a small contingency table; check expected cell counts and independence before using an asymptotic test.
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
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 or two groups, or a small contingency table; check expected cell counts and independence before using an asymptotic test.
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
A quality test has α = 0.05. Under its null model what does that number control?
Worked solution
It sets the long-run probability or upper bound for rejecting a true null according to the test design.
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 groups, or a small contingency table; check expected cell counts and independence before using an asymptotic test.
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 40 / 40 · Tests and decisions
Practical significance
Worked by hand
Problem
A huge sample gives a small p-value for a 0.01-second saving. Is that enough to adopt the change?
Worked solution
Compare an interval for the saving to a prespecified meaningful effect and the cost. A p-value alone does not price the decision.
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 groups, or a small contingency table; check expected cell counts and independence before using an asymptotic test.
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.