Memra

R is read, not written

◈ 7 cards

The printed output is on the paper; every number on it has a hand formula — and three reasons the hand answer differs from R.

What the paper prints

A question may hand you a fragment of an R console session — a summary(), a t.test(), a pnorm() — and ask you to read a number off it, or to say what the number is. You never type R under exam conditions. The skill is mapping each printed line to the hand quantity it represents, then knowing when your hand answer should differ from R's and by how much.

R prints a result with [1] in front (the index of the first element on that line) and, by default, seven significant digits.

Worked example — three transcripts, annotated

Transcript 1 — the z-table as a function.

> pnorm(1.28)
[1] 0.8997274
> pnorm(-2.05)
[1] 0.02018222
> 1 - pnorm(0.67)
[1] 0.2514289

pnorm(z) is , the cumulative table cell — 0.8997 in the table, 0.8997274 in R. The negative argument needs no symmetry trick; R has the whole curve. 1 - pnorm(0.67) is the right tail you computed as .

Transcript 2 — the table read backwards.

> qnorm(0.95)
[1] 1.644854
> qnorm(0.975)
[1] 1.959964
> qt(0.975, 12)
[1] 2.178813

qnorm(p) inverts : the with area to its left. So qnorm(0.95) is , which the table gives as 1.645 (the midpoint of the 0.9495 and 0.9505 cells) and R gives as 1.644854. qt(0.975, 12) is — note that R's argument is the left area 0.975 and its second argument is the df; the table's 2.179 is R's 2.178813 rounded.

Transcript 3 — a sample of eight.

> late <- c(3, 7, 2, 12, 5, 9, 4, 30)
> mean(late)
[1] 9
> sd(late)
[1] 9.10259

Eight late-payment counts (days past due). mean is . sd is the sample standard deviation with in the denominator — . R's sd() never divides by ; if a hand answer comes out as 8.515, the divisor was .

The three reasons a hand answer differs from R's

  1. Table rounding. The table has four decimals of area and three of ; R has seven significant digits. 1.645 versus 1.644854. The paper accepts the table's version — that is what the tolerance is for.
  2. The df convention. For two independent samples, the course's hand rule is ; R uses the Welch–Satterthwaite formula, which gives a larger, fractional df. A larger df means a thinner tail, so R's p-value is smaller than the hand bracket — the hand method is deliberately conservative. Likewise for the hand rule reads the ∞ row (1.96) while R prints qt(0.975, 44) = 2.015368.
  3. The continuity correction. When the normal approximates a binomial, the course applies ±0.5; R's prop.test() applies its own version by default and pnorm() applies none. Two answers to "P(X ≤ 60)" can legitimately differ in the second decimal.

When the paper asks "why does your answer differ from the R output?", one of these three is the mark.

NORMAL ~/memra/learn/afm-113/r-is-read-not-written utf-8 LF