The one-sample t-test determines whether the sample mean is statistically significantly different from a known or hypothesized population mean.
Null hypothesis (H0): The sample mean equals the hypothesized mean.
The test computes a t-statistic and compares it against a t-distribution with the appropriate degrees of freedom. It assumes normally distributed data—this assumption is especially important when the sample size is small.
If the p-value is less than alpha (1 - confidence level), reject the null hypothesis and conclude that the sample mean differs significantly from the hypothesized mean.
Configure the component
Method 1: Configure in Machine Learning Designer
Add a One Sample T Test component on the pipeline page and configure the following parameters.
Fields setting
| Parameter | Description |
|---|---|
| Sample 1 Column | The column that contains the sample data. |
Parameters setting
| Parameter | Default | Description |
|---|---|---|
| Alternative Hypothesis Type | two.sided | The direction of the alternative hypothesis. See Choose an alternative hypothesis type. |
| Confidence Level | 0.95 | The confidence level of the test. Valid values: 0.8, 0.9, 0.95, 0.99, 0.995, 0.999. |
| Hypothesized Mean | 0 | The population mean to test against. |
| Core number | — | The number of cores. Must be a positive integer. |
| Memory Size per Core | — | The memory size per core. Valid values: 1–65536. Unit: MB. |
Choose an alternative hypothesis type
Select the alternative hypothesis type based on what you want to test:
| Value | Meaning | When to use |
|---|---|---|
two.sided | The sample mean is different from the hypothesized mean (two-tailed test). | No prior expectation of direction. |
less | The sample mean is less than the hypothesized mean (left-tailed test). | Expecting the sample mean to be lower. |
greater | The sample mean is greater than the hypothesized mean (right-tailed test). | Expecting the sample mean to be higher. |
Method 2: Use PAI commands
Use PAI commands to configure and run the one-sample t-test. For more information about command syntax, see SQL Script.
pai -name t_test -project algo_public
-DxTableName=pai_t_test_all_type
-DxColName=col1_double
-DoutputTableName=pai_t_test_out
-DxTablePartitions=ds=2010/dt=1
-Dalternative=less
-Dmu=47
-DconfidenceLevel=0.95| Parameter | Required | Default | Description |
|---|---|---|---|
xTableName | Yes | — | The name of the input table. |
xColName | Yes | — | The column to test. |
outputTableName | Yes | — | The name of the output table. |
xTablePartitions | No | null | The partitions to select from the input table. |
alternative | No | two.sided | The alternative hypothesis type. Valid values: two.sided, less, greater. |
mu | No | 0 | The hypothesized mean. |
confidenceLevel | No | 0.95 | The confidence level. Valid values: 0.8, 0.9, 0.95, 0.99, 0.995, 0.999. |
Sample output
{
"AlternativeHypthesis": "mean not equals to 0",
"ConfidenceInterval": "(44.72234194006504, 46.27765805993496)",
"ConfidenceLevel": 0.95,
"alpha": 0.05,
"df": 99,
"mean": 45.5,
"p": 0,
"stdDeviation": 3.919647479510927,
"t": 116.081867662439
}Output fields
| Field | Description |
|---|---|
AlternativeHypthesis | The alternative hypothesis tested, stated in plain language. |
ConfidenceInterval | The range in which the true population mean is expected to fall at the specified confidence level. |
ConfidenceLevel | The confidence level configured (for example, 0.95). |
alpha | The significance level (1 - confidence level). Reject the null hypothesis if p < alpha. |
df | Degrees of freedom (sample size minus 1). |
mean | The sample mean. |
p | The p-value. A value near 0 indicates strong evidence against the null hypothesis. A displayed value of 0 means the p-value is below the floating-point precision of the output, not exactly zero. |
stdDeviation | The sample standard deviation. |
t | The t-statistic. A large absolute value indicates the sample mean is far from the hypothesized mean. |
How to interpret the results
Compare p against alpha (1 - confidence level):
If
p<alpha: reject the null hypothesis. The sample mean is statistically significantly different from the hypothesized mean.If
p>=alpha: do not reject the null hypothesis. The data does not provide sufficient evidence of a difference.
Reading the example above: The p-value is approximately 0 (far below alpha = 0.05), and the t-statistic is 116.08. This is strong evidence to reject the null hypothesis—the sample mean of 45.5 is statistically significantly different from 0.