One-Sample t-Test Reject Decision

Quick Overview

Compute a one-sample t-statistic in SQL, look up the two-tailed critical value for its degrees of freedom in a reference table, and return a reject or fail-to-reject verdict. It tests sample standard deviation aggregates, joining on a derived value, and the decision rule of a two-sided test.

One-Sample t-Test Reject Decision

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

Using `samples`, compute the one-sample t-statistic $t = (\text{mean} - 100) / (s / \sqrt{n})$, with $s$ the sample standard deviation. Look up the `critical_value` in `critical_values` for `df` = n - 1 and `alpha` = 0.05. Return one row with `t_statistic` (rounded to 4 decimals), `df`, and `verdict`: `'reject'` when $|t| \ge$ `critical_value`, else `'fail to reject'`. ```hint Pick the right spread PostgreSQL has separate aggregates for the sample and the population standard deviation. The t-statistic needs the one that divides by n - 1. ``` ### Input Table(s) Table `samples` | Column | Type | Meaning | |---|---|---| | `measurement` | NUMERIC(10,4) | one observed value | Keys: none. Each row is one observation. Table `critical_values` | Column | Type | Meaning | |---|---|---| | `df` | INTEGER | degrees of freedom | | `alpha` | NUMERIC(4,3) | significance level | | `critical_value` | NUMERIC(8,4) | two-tailed critical t for that `df` and `alpha` | Primary key: (`df`, `alpha`). ### Output Contract Exactly one row with these columns, in this order: | Column | Type | Meaning | |---|---|---| | `t_statistic` | NUMERIC | the t-statistic rounded to 4 decimal places | | `df` | INTEGER | n - 1 | | `verdict` | TEXT | `'reject'` when the unrounded $|t|$ is at least `critical_value`, else `'fail to reject'` | The result is a single row, so no ordering is needed. ### Example Input `samples`: | measurement | |---| | 96.4 | | 96.5 | | 103.9 | | 107.2 | | 96.1 | | 99.5 | | 104.2 | | 96.3 | | 93.2 | Input `critical_values`: | df | alpha | critical_value | |---|---|---| | 8 | 0.05 | 2.306 | | 24 | 0.05 | 2.064 | Expected output: | t_statistic | df | verdict | |---|---|---| | -0.4704 | 8 | fail to reject | There are 9 measurements with mean ${893.3 / 9 \approx 99.2556}$ and sample standard deviation $s \approx 4.7474$, so the standard error is $s / 3 \approx 1.5825$ and $t \approx -0.7444 / 1.5825 \approx -0.4704$. With `df` = 8 the critical value is 2.306, and 0.4704 is below it. ### Constraints and Clarifications - `samples` has at least 2 rows and the measurements are not all equal, so $s > 0$. - `measurement` is never NULL. - `critical_values` has exactly one row for `df` = n - 1 and `alpha` = 0.05. Rows for other `df` or `alpha` values are ignored. - The hypothesized mean is 100 and the test is two-sided. - The verdict uses the unrounded t. A $|t|$ equal to the critical value counts as `'reject'`. - Round `t_statistic` with PostgreSQL `ROUND(numeric, 4)`.

Overview: Compute a one-sample t-statistic in SQL, look up the two-tailed critical value for its degrees of freedom in a reference table, and return a reject or fail-to-reject verdict. It tests sample standard deviation aggregates, joining on a derived value, and the decision rule of a two-sided test.

General logo
General
Nov 24, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

Using samples, compute the one-sample t-statistic t=(mean−100)/(s/n)t = (\text{mean} - 100) / (s / \sqrt{n}), with ss the sample standard deviation. Look up the critical_value in critical_values for df = n - 1 and alpha = 0.05. Return one row with t_statistic (rounded to 4 decimals), df, and verdict: 'reject' when ∣t∣≥|t| \ge critical_value, else 'fail to reject'.

Input Table(s)

Table samples

ColumnTypeMeaning
measurementNUMERIC(10,4)one observed value

Keys: none. Each row is one observation.

Table critical_values

ColumnTypeMeaning
dfINTEGERdegrees of freedom
alphaNUMERIC(4,3)significance level
critical_valueNUMERIC(8,4)two-tailed critical t for that df and alpha

Primary key: (df, alpha).

Output Contract

Exactly one row with these columns, in this order:

ColumnTypeMeaning
t_statisticNUMERICthe t-statistic rounded to 4 decimal places
dfINTEGERn - 1
verdictTEXT'reject' when the unrounded $

The result is a single row, so no ordering is needed.

Example

Input samples:

measurement
96.4
96.5
103.9
107.2
96.1
99.5
104.2
96.3
93.2

Input critical_values:

dfalphacritical_value
80.052.306
240.052.064

Expected output:

t_statisticdfverdict
-0.47048fail to reject

There are 9 measurements with mean 893.3/9≈99.2556{893.3 / 9 \approx 99.2556} and sample standard deviation s≈4.7474s \approx 4.7474, so the standard error is s/3≈1.5825s / 3 \approx 1.5825 and t≈−0.7444/1.5825≈−0.4704t \approx -0.7444 / 1.5825 \approx -0.4704. With df = 8 the critical value is 2.306, and 0.4704 is below it.

Constraints and Clarifications

  • samples has at least 2 rows and the measurements are not all equal, so s>0s > 0 .
  • measurement is never NULL.
  • critical_values has exactly one row for df = n - 1 and alpha = 0.05. Rows for other df or alpha values are ignored.
  • The hypothesized mean is 100 and the test is two-sided.
  • The verdict uses the unrounded t. A ∣t∣|t| equal to the critical value counts as 'reject' .
  • Round t_statistic with PostgreSQL ROUND(numeric, 4) .