The t-test is a statistical algorithm used to determine if the mean of a sample or the mean difference between two samples is significantly different from a specified value. There are three types of t-tests: 

1. One Sample T-Test: This test determines if a sample could have been generated by a process with a specific mean. It calculates the sample mean, sample standard deviation, and test statistic using the formula provided. The t value is then compared to the t-distribution to calculate a p-value.

2. Paired Sample T-Test: This test determines if the mean difference between two sets of paired observations is equal to a given value. It calculates the differences between the paired samples, the sample mean difference, sample standard deviation, and test statistic using the provided formulas. The t value is compared to the t-distribution to calculate a p-value.

3. Independent Sample T-Test: This test determines if the mean difference between two unrelated groups is equal to a given value. It calculates the sample means, sample standard deviations, and test statistic using the provided formulas. The t value is compared to the t-distribution to calculate a p-value. The degrees of freedom are calculated differently depending on whether the variances of the two distributions are assumed to be equal or not.

In PAL, the t-test algorithm is used based on the input table. If the table has only one column, a one sample t-test is performed. If the table has two columns and the PAIRED parameter is set to 1, a paired sample t-test is performed. In all other cases, an independent sample t-test is performed.
------

SET SCHEMA DM_PAL;

DROP TABLE PAL_TTEST_DATA1_TBL;
CREATE COLUMN TABLE PAL_TTEST_DATA1_TBL ("X1" DOUBLE);
INSERT INTO PAL_TTEST_DATA1_TBL VALUES (1);
INSERT INTO PAL_TTEST_DATA1_TBL VALUES (2);
INSERT INTO PAL_TTEST_DATA1_TBL VALUES (4);
INSERT INTO PAL_TTEST_DATA1_TBL VALUES (7);
INSERT INTO PAL_TTEST_DATA1_TBL VALUES (3);

DROP TABLE PAL_TTEST_PARAMETER_TBL;
CREATE COLUMN TABLE PAL_TTEST_PARAMETER_TBL (
    "PARAM_NAME" NVARCHAR(256),
    "INT_VALUE" INTEGER,
    "DOUBLE_VALUE" DOUBLE,
    "STRING_VALUE" NVARCHAR (1000)
);
INSERT INTO PAL_TTEST_PARAMETER_TBL VALUES ('TEST_TYPE', 0, NULL, NULL);
INSERT INTO PAL_TTEST_PARAMETER_TBL VALUES ('MU', NULL, 0, NULL);
INSERT INTO PAL_TTEST_PARAMETER_TBL VALUES ('CONF_LEVEL', NULL, 0.95, NULL);

DROP TABLE PAL_TTEST_STATISTIC_TBL;
CREATE COLUMN TABLE PAL_TTEST_STATISTIC_TBL (
    "STAT_NAME" NVARCHAR(100),
    "STAT_VALUE" DOUBLE
);

DO BEGIN
  lt_data = SELECT * FROM PAL_TTEST_DATA1_TBL;
  lt_param = SELECT * FROM PAL_TTEST_PARAMETER_TBL;
  CALL _SYS_AFL.PAL_T_TEST (:lt_data, :lt_param, lt_statistic);
  INSERT INTO PAL_TTEST_STATISTIC_TBL SELECT * FROM :lt_statistic;
END;

SELECT * FROM PAL_TTEST_STATISTIC_TBL;
