STATS_CI – Confidence Interval Report for Filtered Columns

What it does

Calculates the confidence interval of the mean for filtered columns (Student's t).

type "greater" gives [lower, ∞), "less" gives (−∞, upper].

With fewer than 2 values SE, the margin and both bounds are empty (mean, n and df stay). On a column without spread the margin is 0 and a one-sided interval keeps its infinite side.

Syntax

=STATS_CI(columns, colFilter, ciLevel, type)

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 columns
  • A1:C200 — use 3 columns
  • A:F — use 6 columns
  • A1: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):

  1. By name - exact header text (case-sensitive)
    • "age,score,total"
  2. Negative rules - exclude by name (prefix with -)
    • "-id,-notes" (include all except id and notes)
  3. 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.
  4. 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.9
  • 0.95
  • 0.8
type — optional

Confidence interval type: "two-sided", "greater" (bounds [lower, ∞)) or "less" (bounds (−∞, upper]); 1 and -1 (number or text) mean greater and less.

Case and spaces around do not matter. Another value is an error: type must be two-sided, greater or less (or 1, -1), got "grater".

Examples:

  • "two-sided"
  • "greater"
  • "less"

Examples

  • — the sample data (50 rows) all examples use
  • — all columns starting with q =STATS_CI(Data!A1:T51, "/^q/", 0.95, "two-sided")

What the result contains

One table, a column per selected column: Mean, n, Std. deviation (σ), Margin of error (±), Std. error (SE), Lower bound, Upper bound, Degrees of freedom (df), and a line with the level and the type.

How to read the result

Read the interval as a range of plausible values for the true mean of the population.

A narrow interval — a precise mean; a wide one — too few values or much spread.

Two intervals side by side are not a test of the difference: compare the means with STATS_INDEPENDENT for different people, STATS_PAIRED for the same people answering twice (the q1…q7 of one survey are paired).

In a report: "M = 4.72, 95% CI [4.03, 5.41]."

What each number means

Metric / Column — Metric / Column

Read a row across to compare one metric between the columns.

Mean — Mean of the group

The estimate the interval is built around. In a report: M = 4.72, 95% CI [4.03, 5.41].

n — Number of values

How many observations the result rests on. Compare it with the size of your sample: empty cells are left out.

Std. deviation (σ) — Standard deviation

How far the values typically lie from the mean. In a report: M = 5.30, SD = 3.07.

Margin of error (±) — Margin of error

The ± after the mean: "4.72 ± 0.69".

Std. error (SE) — Standard error of the mean

How precisely the mean is known: the margin of error is the t quantile times it. Rarely reported on its own.

Lower bound — Lower bound of the mean

Together with the upper bound: a range of plausible values for the true mean. In a report: M = 4.72, 95% CI [4.03, 5.41].

Upper bound — Upper bound of the mean

Together with the lower bound: a range of plausible values for the true mean. In a report: M = 4.72, 95% CI [4.03, 5.41].

Degrees of freedom (df) — Degrees of freedom of the interval

Not reported usually; it shows how many values the interval rests on.

Calculated for sample (n-1) at level 0.95 by type two-sided. — How the interval was computed

The standard deviation is the sample one (n − 1), whatever pop says in Settings; then the level and the type of the interval; text columns left out are named after it.

How it is computed

For every selected column, on its valid values: SE = σ / √n, the margin of error t · SE with n − 1 degrees of freedom; σ is the sample standard deviation (n − 1) whatever pop says in Settings, as SPSS: the t quantile with n − 1 degrees of freedom gives the stated coverage only with it.

Two-sided: mean ± t(1 − (1 − level)/2) · SE; one-sided (greater or less): one bound with t(level), the other infinite.

Fewer than 2 values: SE, the margin and both bounds stay empty, as SPSS.

Errors

ciLevel outside 0…1: "ciLevel must be between 0 and 1 (e.g. 0.95), got 95".

An unknown type: "type must be two-sided, greater or less (or 1, -1), got \"grater\"".

A column that does not exist: "Column nope does not exist".

About STATS_CI

STATS_CI calculates the confidence interval of the mean for every selected column, based on Student's t: a range of plausible values for the population mean at the chosen level, 0.95 by default. Select the columns by name, by a pattern such as /^q/ (all questions starting with q) or by position, and compare them in one table. The table recalculates by itself when new responses arrive from Google Forms.

For each column the table gives the mean, n, the standard deviation, the standard error (SE), the margin of error (±), the lower and upper bounds and the degrees of freedom (df = n − 1). The standard deviation is always the sample one (n − 1), as in SPSS. The interval can be two-sided or one-sided: greater gives [lower, ∞), less gives (−∞, upper].

An empty cell is a missing answer, and each column uses its own valid values. With fewer than two values the standard error, the margin and both bounds stay empty, as in SPSS. Every number of the report is explained on this page in plain words.