STATS_PEARSON – Pearson correlation and correlation matrix function
What it does
Pearson correlation (r).
The colFilter may include more than two columns, for correlation matrix.
Syntax
=STATS_PEARSON(columns, colFilter, ciLevel, alternative)Parameters
columns — required
Cell range with data, e.g., A1:D100 or A:D.
Usually the first row should contain column names.
You can also add labels as the first row and column names as the second row.
Labels should use formats like "male:1,female:2" or "low:1:3,mid:3:5,high:5:7".
Examples:
A1:D100— use 4 columnsA1:C200— use 3 columnsA:F— use 6 columnsA1:D100 where row 1 contains labels and row 2 contains column names— use labels from the sheet
If every non-empty cell of the first row holds at least two label rules ("low:1,high:2"), it is the labels row, and the next row holds the column names; an empty cell there is a column without labels.
One rule in a cell ("yes:1") is read as a name, so a header such as "T:1", "Ratio 1:2" or "Note:" stays the names row. Give such a column a second rule, or pass one label in the labels parameter, where one rule is valid.
If the first row contains ordinary text, it is treated as the column names row as before.
A number, a date or a checkbox in the names row is a name: 2025, 2025-01-01, TRUE.
Column names must be unique: two identical headers are an error "Duplicate column name: x".
Every column with values needs a name: an empty header cell over values is an error "The name of column 2 is empty: a column with values needs a name", even when colFilter does not select that column. A column with neither a name nor values (the empty right edge of a range such as A:Z) is dropped without an error.
Column names that start with "#" are reserved/unsupported in filters, because "#" is used for index-based colFilter rules (for example #1, #2-#5).
What counts as a number (the same in every function):
- A column is numeric when it holds more numbers than text; with as many texts as numbers, or more, it is a text column.
- Every cell is typed by itself: a number written as text ('10', '007') is the number, a checkbox is 1 (checked) or 0 (unchecked). The texts 'TRUE'/'FALSE' stay text.
- A cell that does not match the type of its own column (text in a numeric column, a number in a text column) is missing for calculations and is counted in missing.
- An empty cell is a missing answer; the sign "." means "not applicable" — it is not a missing answer, not a category and not counted in missing.
- A text column with value labels (a labels row above the names) is analysed by the codes of its labels. A text column without labels is not analysed as numbers: lists of columns skip it with a note, tests on a pair of columns and models show an error.
An empty tail of the range (rows below the data) is dropped — only blank cells make it: a row of "." at the end stays and counts as not applicable, as in the middle. A column with neither a name nor values is dropped; a named empty column stays.
colFilter — optional, default "*"
Comma-separated column selector.
Use names ("age,score"), negative rules ("-id,-note"), a regex ("/^q/"), or index rules ("#N", "#A-#B", "-#N", "-#A-#B").
Case-sensitive; flags are not supported.
A name that does not exist is an error: "Column nope does not exist" (excluding it, "-nope", is ignored). Empty — all columns ("*").
Examples:
"age,score"— Names only (include only "age" and "score")"-id,-group"— Exclude some (include all except "id" and "group")"/^q/"— Regex only (all starts with "q")"#1,#3-#5"— Index include rules (first, and range 3..5)"-#1,-#3-#4"— Index exclude rules (drop first and 3..4)"age,#2-#4,-#3"— Mixed name/index rules with deterministic order"age,/^q/,-q5"— Mixed (include age, all starts with "q" except "q5")"/^x1{1,2}$/"— Regex with a comma inside: x1 and x11
Choose which columns from columns to use - a comma-separated string of rules.
⚙️ Four rule types (you can mix them):
- By name - exact header text (case-sensitive)
- "age,score,total"
- Negative rules - exclude by name (prefix with
-)- "-id,-notes" (include all except
idandnotes)
- "-id,-notes" (include all except
- Regex - a regular expression between slashes
/.../- "/^q/" (all headers starting with
q), "/(score|age)/", "/^x1{1,2}$/" (commas inside /.../ do not split the filter) - ❗— case-sensitive
- ❗— flags are not supported.
- "/^q/" (all headers starting with
- Index rules - position-based rules with
#- "#1" (first selected column), "#2-#5" (range), "-#1", "-#2-#4"
"*" alone selects every column; it cannot be combined with other rules ("*,-id" is an error) — write "-id" instead.
Rules are applied in the written order, and the selected columns keep that order ("/^q/,-q5,age" puts age last).
Index rules count the columns of the range: "#1" is its first column.
A name that does not exist is an error: "Column nope does not exist" — also in colName, yName, steps, rowCol, colCol and colNameForSplit. Excluding a name that does not exist ("-nope") is ignored.
A filter that selects no column — a regex without a match ("/^Q/" where the columns are q1, q2), index rules past the end, exclusions that remove every column — is an error that names the filter and the columns of the range: colFilter "/^Q/" selects no columns (columns: q1, q2, t). Empty and "*" select every column.
In STATS_ANALYZE, a regex with brackets or | needs the new syntax: PEARSON('/(score|age)/').
A colFilter saved in Settings applies to every formula without its own filter: on a range without those columns the formula shows the error above.
# prefix is reserved for index syntax and is not treated as a column-name filter token.
colFilter applies to all expressions in query. It does not create separate groups per expression.
ciLevel — optional, default 0.95
Confidence level for intervals in tests/bootstraps: a number strictly between 0 and 1 (0.95, not 95). A number written as text ("0.9") is accepted.
Another value is an error: ciLevel must be between 0 and 1 (e.g. 0.95), got 95. Empty — the level from Settings.
Should be a number between 0 and 1
Examples:
0.90.950.8
alternative — optional, default "two-sided"
Alternative hypothesis for two-sample/one-sample tests and correlations: "two-sided", "greater" or "less"; 1 and -1 (number or text) mean greater and less.
Case and spaces around do not matter ("Greater", " less "). Another value is an error: alternative must be two-sided, greater or less (or 1, -1), got "grater". Empty — the default from Settings.
A one-sided hypothesis gives a one-sided interval: [lower, ∞) for greater, (−∞, upper] for less (for correlations [lower, 1] and [−1, upper]).
Allowed values: "two-sided", "greater", "less"
Examples:
"two-sided""greater""less"
Examples
- — the sample data (50 rows) all examples use
- —
=STATS_PEARSON(Data!A1:T51, "x,y,x1",0.95,"two-sided")
What the result contains
Flat 2D report that spills below the formula cell.
For 2 columns: a Pearson r with CI and p-value; for 3+ columns: a symmetric correlation matrix with labels.
A column without spread, or fewer than two common rows: r, p and the interval are empty (in a matrix, only the pairs with that column).
Each value needs its own number of common rows, below it the cell is empty: r from 2, t and p from 3 (as SPSS prints Sig.), the interval from 4 (the Fisher transform divides by n − 3). The block keeps its layout.
A one-sided alternative gives a one-sided interval: [lower, 1] or [−1, upper].
How to read the result
Start with r: its sign is the direction, its size the strength of the linear relation (0.1 small, 0.3 medium, 0.5 large). r near 0 means no straight-line relation — a curved one can still be there.
Then p: below 0.05 — the relation is unlikely to be chance. In a matrix the stars say the same (* < 0.05, < 0.01, * < 0.001).
The interval shows how precise r is: one that contains 0 means the relation may be nil.
Check df: it is n − 2, and in a matrix every pair can have its own n.
In a report: "Study hours correlated with the score, r(48) = .42, p = .002, 95% CI [.16, .63]."
What each number means
Significance: *<0.05,<0.01,*<0.001— Significance starsWhat the stars in the matrix mean: * p < 0.05, p < 0.01, * p < 0.001. Text columns left out of the matrix are named after it.
Details of every pair
Pair— Pair of columnsEach row of this table is one cell of the matrix above, with its details. For a correlation the order of the two columns does not matter.
df— Degrees of freedom of the correlationWritten in brackets after r in a report: r(48) = .15.
r— Pearson correlation rHow closely two things go together: 0 — no linear relation (a curved one can still exist), 1 — they rise together perfectly along a straight line, −1 — one falls exactly as the other rises. A common guide (Cohen): 0.1 small, 0.3 medium, 0.5 large.
Correlation is not causation: r says that the two go together, not that one causes the other.
In a report: r(48) = .15, p = .293 — the number in brackets is df.
p— p of the correlationBelow 0.05 — the relation is unlikely to be chance. With many rows even a tiny r becomes significant, so read r itself for the strength.
CI 0.95 Lower— Lower bound for rTogether with the other bound: a range of plausible values for the true correlation. If the interval contains 0, the relation may be nil; a wide interval (−0.13 to 0.41) means the sample is too small to tell the strength.
CI 0.95 Upper— Upper bound for rTogether with the other bound: a range of plausible values for the true correlation. If the interval contains 0, the relation may be nil; a wide interval (−0.13 to 0.41) means the sample is too small to tell the strength.
How it is computed
Two columns: the rows where both are filled are used (pairwise). Three or more: a matrix, each pair on its own common rows; text columns are left out of a matrix.
r = covariance / (s_x · s_y), sample formulas (n − 1; population with pop = TRUE in Settings).
The test of r = 0: t = r · √((n − 2) / (1 − r²)) with n − 2 degrees of freedom, two-sided or one-sided by alternative.
The confidence interval by the Fisher z transform: tanh(atanh(r) ± z / √(n − 3)); one-sided with greater or less.
Too few common rows leave cells empty: no r below 2 rows, no p below 3, no interval below 4.
Errors
Fewer than two columns: one cell Pearson Test requires at least 2 columns, got: x; when text columns were skipped, it names them (. Text columns skipped: t, u …). Only text columns: the message about text columns.
A column that does not exist: "Column nope does not exist".
Regex is case-sensitive and has no flags.
About STATS_PEARSON
STATS_PEARSON measures how closely two numeric columns move together in a straight line — for example, study hours and exam score. Pearson's r runs from −1 to 1: the closer to −1 or 1, the stronger the relation. Two columns give r with its p-value and confidence interval; three or more give a symmetric correlation matrix with labels. The report spills below the formula cell and recalculates by itself when new responses arrive from Google Forms.
Each pair uses its own common rows — the rows where both values are filled; text columns are left out of a matrix. p tests whether r differs from 0: t = r · √((n − 2) / (1 − r²)) with n − 2 degrees of freedom, two-sided or one-sided ("greater", "less"). The confidence interval uses the Fisher z transform.
With too few common rows a cell stays empty instead of showing a doubtful number: r needs 2 rows, p needs 3, the interval needs 4. A column where every value is the same also leaves r, p and the interval empty. Every number of the report is explained on this page in plain words.