Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Formulas

A formula computes numbers from other numbers in the same table. You type it after an =, either for a whole column (the formula bar above a column header) or for a single cell.

Two places a formula can live

A column formula fills every row of a column. = log10(A) in column B means “for each row, B is the base-10 log of A in that row”. One formula, a million rows, no dragging.

A cell formula fills one cell, the way a spreadsheet does. Type =A3 * 2 into cell B3. Fill-down (Ctrl-D) copies it to the rows below and moves the row numbers along: B4 gets =A4 * 2. A column holds either a column formula or cell formulas, not both.

Computed cells show a small corner mark. Change the data and every formula that depends on it is recomputed the next time you look. A formula that would depend on itself, directly or through other columns, is refused when you type it, with the loop spelled out: Circular reference: C → D → C.

Naming columns

You writeIt means
A, B, … Z, AAdata set A, B, … (its first subcolumn)
A.2data set A, subcolumn 2 (replicate 2, or the SD in a mean/SD/N data set)
Xthe X column of an XY or survival table
`Dose (nM)`the data set (or X column) with that header, in backticks
`Dose (nM)`.3its third subcolumn
A3one cell: data set A, row 3 (rows count from 1)
A[3]the same cell
A[2:5]rows 2 to 5 of A, both ends included
A[:5], A[2:]from the first row to row 5; from row 2 to the end
[1, 2, 3]a list of numbers you type yourself

The letter X always means the X column, so the twenty-fourth data set is reached by its name in backticks.

Values

A formula works with numbers, text ("mg/dL"), true/false, and missing. An empty cell is missing. An excluded cell is missing too: it stays in the table, struck through, but no formula or analysis uses it. NA (or na()) writes missing on purpose.

Missing spreads: A + 1 is missing wherever A is missing. Summaries such as mean skip missing values instead, because that is almost always what you want from “the mean of A”.

A problem in one row does not stop the column. sqrt(A) on a row where A is −4 shows an error in that cell (hover to read “sqrt: negative number”) and computes every other row. Text in a numeric column (“<LOD”) is kept and shown; arithmetic on it gives an error in that row, never a silent zero.

Arithmetic and logic

From tightest to loosest binding:

OperatorsMeaningExample
A[…]pick rowsA[1:3]
^power (right to left: 2^3^2 is 2^9)B ^ 2
-x, +xsign (-2^2 is −4)-A
*, /, %multiply, divide, remainder (floored, like MOD)A % 2
+, -add, subtractA - B
== (or =), != (or <>), <, <=, >, >=compare; gives true/falseA > 0
not x, !xnotnot isna(A)
&&, andbothA > 0 && B > 0
||, oreitherA < 0 or B < 0

True counts as 1 and false as 0 when stored in a column, which is how you make an event code: = if(A > 30, 1, 0). Logic with a missing value follows common sense: false && NA is false, true || NA is true, true && NA is missing.

A single number combines with a whole column row by row: A * 2, A - mean(A). Two columns combine row by row. A list of a different length than the table cannot combine with a column; that is an error, not a guess.

Row-by-row functions

FunctionWhat it givesExample
abs(x)absolute valueabs(A - B)
sqrt(x)square root (error below 0)sqrt(A)
exp(x)e to the power xexp(-0.693 * X)
ln(x)natural log (error at or below 0)ln(A)
log(x)natural log, same as ln (not base 10, unlike Excel)log(A)
log(x, b)log in base blog(A, 2)
log10(x)base-10 loglog10(A)
log2(x)base-2 loglog2(B / A)
pow(x, y)x to the power ypow(10, A)
sin, cos, tantrigonometry, radianssin(X * pi() / 180)
asin, acos, ataninverse trigonometry, radiansatan(A)
sinh, cosh, tanhhyperbolic functionstanh(A)
floor(x), ceil(x)round down, round upfloor(A)
round(x), round(x, n)round to n decimals, halves away from zero (2.675 → 2.68)round(A, 2)
trunc(x)drop the fractiontrunc(A)
sign(x)−1, 0 or 1sign(B - A)
if(c, a, b)a where c is true, b where false, missing where c is missingif(A > 0, A, NA)
isna(x)true where x is missing (or excluded)if(isna(A), 0, A)
na()a missing valueif(A < 0, na(), A)
coalesce(a, b, …)the first argument that is not missingcoalesce(A, B, 0)
clamp(x, lo, hi)x limited to the range lo to hiclamp(A, 0, 100)
pct(x, ref)100 × x / refpct(A, A1)
normalize(x, lo, hi)maps lo to 0 and hi to 1normalize(A, A1, max(A)) * 100
convert(x, "from", "to")unit conversion (see below)convert(A, "nM", "µM")
convert(x, "from", "to", "substance")mass ↔ molar conversionconvert(A, "mg/dL", "mmol/L", "glucose")
row()the row number, from 1if(row() <= 3, NA, A)
pi()π2 * pi() * X

Summaries (one number from many)

These skip missing, excluded and text cells. Give them a column, a slice, a list, or several of these at once: max(A, B) is the largest value in A and B together. (For a row-by-row limit use clamp, not min/max.)

FunctionWhat it givesExample
mean(x)arithmetic meanA - mean(A[1:3])
median(x)middle valueA / median(A)
sd(x)sample standard deviation (n − 1)(A - mean(A)) / sd(A)
sem(x)standard error of the mean, sd/√nsem(A)
var(x)sample variance (n − 1)var(A)
sum(x)totalA / sum(A)
count(x)how many numberscount(A)
min(x), max(x)smallest, largest(A - min(A)) / (max(A) - min(A))
range(x)max − minrange(A)
quantile(x, q)the q-quantile, q from 0 to 1, by linear interpolation (Excel’s PERCENTILE.INC)quantile(A, 0.9)
geomean(x)geometric mean (all values must be positive)A / geomean(A)
cv(x)coefficient of variation, in percent: 100 × sd / meancv(A)
first(x), last(x)first and last non-missing valueA - first(A)

The descriptive-statistics analysis computes quartiles by the (n + 1)p rule, as Prism does; quantile uses the spreadsheet rule. For small samples the two can differ slightly.

Series (whole-column operations that give a column back)

FunctionWhat it givesExample
lag(x), lag(x, k)the value k rows above (missing for the first k rows)A - lag(A)
lead(x), lead(x, k)the value k rows belowlead(A) - A
diff(x)x minus the row abovediff(X)
cumsum(x)running total; a missing row stays missing and is skipped in the totalcumsum(A)
rank(x)rank from smallest (1), ties share the average rankrank(A)
zscore(x)(x − mean) / sdzscore(A)
normalize(x)(x − min) / (max − min)normalize(A) * 100
baseline(x, r1, r2, …)x minus the mean of x at the listed rowsbaseline(A, 1, 2, 3)
seq(a, b), seq(a, b, step)the list a, a + step, …, bbaseline(A, seq(1, 5))

Units

convert(x, "from", "to") knows these units. Metric prefixes work on every base unit: k (kilo), d (deci), c (centi), m (milli), µ or u or mc (micro), n (nano), p (pico), f (femto).

QuantityUnits
massg, kg, mg, µg, ng, pg
volumeL (or l), dL, mL, µL, nL, cc
amountmol, mmol, µmol, nmol, pmol
concentrationM, mM, µM, nM, pM; or any mass or amount over a volume: mg/dL, g/L, mmol/L, µg/mL
times, ms, µs, min, h, d, wk
lengthm, km, cm, mm, µm, nm
pressurePa, kPa, hPa, mmHg, atm, bar
temperatureC, F, K (or °C, °F)

Mass and molar concentrations convert through a substance’s molar mass, so you must name the substance; Dioptra will not guess:

SubstanceConversion
"glucose"mg/dL ÷ 18.016 = mmol/L
"cholesterol"mg/dL ÷ 38.67 = mmol/L
"triglycerides"mg/dL ÷ 88.57 = mmol/L
"creatinine"mg/dL × 88.42 = µmol/L
"urea"molar mass 60.06 g/mol

Where formulas are also used

Filter rows takes a formula that is true for the rows to keep: A > 0 && !isna(B).

Differences from a spreadsheet

  • log(x) is the natural log. Use log10(x) for base 10.
  • Slices are inclusive and count from 1: A[1:3] is three rows.
  • % is the remainder, not “per cent”.
  • There are no $ absolute references; a column formula already means “this column, every row”, and fill-down moves only single-cell references such as A3.
  • Function names are case-insensitive (MEAN(A) works); column letters are capitals.