Course Test · University: first two years
Mathematical statistics: RatMath answers
The same twenty exercises, answered with RatMath Core and the Shelf libraries only. The code below was run when this page was built; its output is shown as printed, and compared with the independent answer.
Agrees 20
Libraries used here: core, stats. In this code each library is in scope under its own name (linalg.det, stats.tTest), and Core's names (R, Rational, …) are in scope directly.
- 1.Maximum likelihood: exponentialAgreesThe waiting times 2, 3, 1, 4, 5 come from an exponential distribution with rate . Find the maximum likelihood estimate of .Independent answer, so .RatMath code
stats.fit([2, 3, 1, 4, 5], "exponential").params.rateOutput1/3
- 2.Maximum likelihood: PoissonAgreesCounts 2, 0, 3, 1, 4 come from a Poisson distribution. Find the maximum likelihood estimate of its mean.Independent answer.RatMath code
stats.fit([2, 0, 3, 1, 4], "poisson").params.lambdaOutput2
- 3.Unbiased varianceAgreesFind the sample variance (divisor ) of 3, 5, 7, 9, 11.Independent answerDeviations ; ; .RatMath code
stats.variance([3, 5, 7, 9, 11])Output10
- 4.Two-sample t testAgreesGroup A: 12, 15, 11, 14, 13. Group B: 16, 18, 15, 17, 19. Test equal means with the pooled two-sample test. Give , the degrees of freedom and the two-sided -value.Independent answer, , both , pooled . , 8 df, .RatMath code
const r = stats.tTest([12, 15, 11, 14, 13], [16, 18, 15, 17, 19], { equalVariance: true }); [r.statistic, r.df, r.pValue]Output[-4, 8, 0.0039497728034453258[1:2]]
- 5.Paired t testAgreesBlood pressure before: 200, 210, 190, 220, 205; after: 195, 200, 192, 210, 198. Test for a change with a paired test (two-sided).Independent answerDifferences 5, 10, , 10, 7: , . , 4 df, : not significant at 5%.RatMath code
const r = stats.tTest([200, 210, 190, 220, 205], [195, 200, 192, 210, 198], { paired: true }); [r.statistic, r.pValue]Output[2.7105237087157537131[3:5], 0.05350829685091812719:0.0535082968509181272]
- 6.Interval for a varianceAgreesA sample of from a normal population has . Give a 95% confidence interval for .Independent answer.RatMath code
const ci = stats.varianceInterval({ n: 10, variance: 4 }); [ci.low, ci.high]Output[1328165573307087716352/701816258310290954905, 10625324586456701730816/797014304087522667905]
varianceIntervaltakes and as a summary.Fix: ratmath/stats#8, summaries inmeanInterval/varianceInterval; closed-formpowerandsampleSize;fromDensity,transformandorderStatistic - 7.One-way ANOVAAgreesThree groups: , , . Compute the ANOVA statistic and its -value.Independent answerMeans 5, 7, 10, grand mean . , . on (2, 6) df, .RatMath code
const r = stats.anova([[4, 5, 6], [6, 7, 8], [9, 10, 11]]); [r.statistic, r.pValue]Output[19, 0.0025356874530428249[4:5]]
- 8.Inference for a slopeAgreesFor and , find the least-squares slope, its standard error, the statistic and the two-sided -value for .Independent answer. , , , , 3 df, .RatMath code
const m = stats.linearModel([1, 2, 3, 4, 5], [2, 4, 5, 4, 6]); const r = m.test(1); [m.coefficients[1], r.standardError, r.statistic, r.pValue]Output[4/5, 0.2828427124746190097[6:7], 2.8284271247461900976:2.82842712474619009761, 0.0662756027415242553[5:6]]
- 9.Coefficient of determinationAgreesFor the same data, find .Independent answer, … more simply .RatMath code
stats.linearModel([1, 2, 3, 4, 5], [2, 4, 5, 4, 6]).rSquaredOutput8/11
- 10.Multiple regressionAgreesFit to , , .Independent answerSolving the normal equations gives .RatMath code
stats.linearModel([[1, 2], [2, 1], [3, 4], [4, 3], [5, 5]], [3, 4, 8, 8, 11]).coefficientsOutput[3/10, 4/3, 5/6]
- 11.Mann–Whitney testAgreesCompare with by the Mann–Whitney (Wilcoxon rank-sum) test. Give and the exact two-sided -value.Independent answerEvery value in the first sample is below every value in the second, so . Only 1 of the arrangements is that extreme on each side: .RatMath code
const r = stats.mannWhitneyTest([1.1, 2.3, 3.0], [3.5, 4.1, 5.2, 6.0]); [r.statistic, r.pValue]Output[0, 2/35]
- 12.Sign testAgreesOf 10 paired differences, 9 are positive and 1 negative. Find the two-sided sign-test -value.Independent answer.RatMath code
stats.signTest([1, 1, 1, 1, 1, 1, 1, 1, 1, -1]).pValueOutput11/512
- 13.Fisher's exact testAgreesFind the two-sided Fisher exact -value for the table .Independent answerHypergeometric probabilities for the top-left cell : . Tables at most as likely as the observed one: .RatMath code
stats.fisherTest([[3, 1], [1, 3]]).pValueOutput17/35
- 14.Power of a z testAgreesTest against with , , . What is the power when the true mean is 106?Independent answerReject when . Power .RatMath code
stats.power({ mu0: 100, mu: 106, sigma: 15, n: 25, alternative: "greater" }).powerOutput0.6387600313123350643[1:4]
poweris the closed form with certified quantiles.Fix: ratmath/stats#8, summaries inmeanInterval/varianceInterval; closed-formpowerandsampleSize;fromDensity,transformandorderStatistic - 15.Sample sizeAgreesHow large a sample gives a margin of error of at most 3 percentage points for a proportion at 95% confidence (use )?Independent answer, so .RatMath code
stats.sampleSize({ margin: "0.03", p: "1/2" }).nOutput1068
sampleSizeencloses and rounds up once the enclosure settles it.Fix: ratmath/stats#8, summaries inmeanInterval/varianceInterval; closed-formpowerandsampleSize;fromDensity,transformandorderStatistic - 16.Conjugate priorAgreesWith a uniform Beta(1, 1) prior on a success probability, 7 successes are seen in 10 trials. Give the posterior and its mean.Independent answerBeta(8, 4), with mean .RatMath code
const post = stats.betaPrior(1, 1).update({ successes: 7, trials: 10 }); [post.params, post.mean]Output[{ a: 8, b: 4 }, 2/3] - 17.Kolmogorov–Smirnov statisticAgreesFind the Kolmogorov–Smirnov statistic for the sample 0.1, 0.4, 0.7 against the uniform distribution on .Independent answerCompare with the step function: at 0.1 the gaps are 0.1 and 0.233, at 0.4 they are 0.267 and 0.067, at 0.7 they are 0.3 and 0.033. .RatMath code
stats.ksTest([0.1, 0.4, 0.7], stats.uniform(0, 1)).statisticOutput3/10
- 18.Spearman's rank correlationAgreesFind Spearman's for and .Independent answerRank differences , : .RatMath code
stats.spearmanTest([1, 2, 3, 4, 5], [2, 1, 4, 3, 5]).statisticOutput4/5
- 19.Kruskal–Wallis testAgreesFind the Kruskal–Wallis for , , .Independent answerRank sums 6, 15, 24. .RatMath code
stats.kruskalWallisTest([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).statisticOutput36/5
- 20.Difference of proportionsAgreesIn two samples of 100, 45 and 30 people agree. Give a 95% confidence interval for .Independent answer.RatMath code
const I = stats.proportionTest([45, 30], [100, 100]).interval(); [I.low, I.high]Output[0.017430493307564781223097…, 0.282569506692435218776902…]