2.13.2.2 Hypothesis TestingHypothesis-Testing
Hypothesis TestOrigin/OriginPro supports the following set of X-Functions for hypothesis testing:
Name
|
Brief Description
|
rowttest2 (Pro Only)
|
Perform a two-sample t-test on rows.
|
ttest1
|
Compare the sample mean to the hypothesized population mean.
|
ttest2
|
Compare the sample means of two samples.
|
ttestpair
|
Determine whether two sample means are equal in the case that they are matched.
|
vartest1 (Pro Only)
|
Determine whether the sample variance is equal to a specified value.
|
vartest2 (Pro Only)
|
Determine whether two sample variances are equal.
|
For a full description of these X-functions, including input and output arguments, please see the Hypothesis Testing.
One-Sample T-Test
One-Sample T-TestIf you need to know whether the mean value of a sample is consistent with a hypothetical value for a given confidence level, consider using the one-sample T-test. Note that this test assumes that the sample is a normally distributed population. Before we apply the one-sample T-test, we should verify this assumption.
//Import a sample data
newbook;
fname$ = system.path.program$ + "Samples\Statistics\diameter.dat";
impasc;
//Normality test
swtest irng:=col(a) prob:=p1;
if (p1 < 0.05)
{
type "The sample is not likely to follow a normal distribution."
}
else
{
// Test whether the mean is 21
ttest1 irng:=col(1) mean:=21 tail:=two prob:=p2;
if (p2 < 0.05) {
type "At the 0.05 level, the population mean is";
type "significantly different from 21."; }
else {
type "At the 0.05 level, the population mean is NOT";
type "significantly different from 21."; }
}
Two-Sample T-TestTwo-Sample T-Test
The ttest2 X-Function is provided for performing two-sample t-test. The example below shows how to use it and print the results.
// Import sample data
newbook;
string fpath$ = "Samples\Statistics\time_raw.dat";
string fname$ = system.path.program$ + fpath$;
impAsc;
// Perform two-sample t-test on two columns
// Sample variance is not assumed to be equal
ttest2 irng:=(col(1), col(2)) equal:=0;
// Type some results
type "Value of t-test statistic is $(ttest2.stat)";
type "Degree of freedom is $(ttest2.df)";
type "P-value is $(ttest2.prob)";
type "Conf. levels in 95% is ($(ttest2.lcl), $(ttest2.ucl))";
The rowttest2 X-Function can be used to perform a two-sample T-test on rows. The following example demonstrates how to compute the corresponding probability value for each row:
// Import sample data
newbook;
string fpath$ = "Samples\Statistics\ANOVA\Two-Way_ANOVA_raw.dat";
fname$ = system.path.program$ + fpath$;
impasc;
// Two-sample T-test on a row
rowttest2 irng1:=(col(a):col(c)) irng2:=(col(d):col(f))
tail:=two prob:=<new>;
Pair-Sample T-Test
Origin provides the ttestpair X-Function for pair-sample t-test analysis, so to determine whether the means of two same-sized and dependent samples from a normal distribution are equal or not, and calculates the confidence interval for the difference between the means. The example below first imports a data file, and then perform pair-sample t-test, and then output the related results.
// Import sample data
newbook;
string fpath$ = "Samples\Statistics\abrasion_raw.dat";
string fname$ = system.path.program$ + fpath$;
impasc;
// Perform pair-sample t-test one two columns
// Hypothetical means difference is 0.5
// And Tail is upper tailed
ttestpair irng:=(col(1), col(2)) mdiff:=0.5 tail:=upper;
// Type the results
type "Value of paired-sample t-test statistic is $(ttestpair.stat)";
type "Degree of freedom for the paired-sample t-test is $(ttestpair.df)";
type "P-value is $(ttestpair.prob)";
type "Conf. levels in 95% is ($(ttestpair.lcl), $(ttestpair.ucl))";
One-Sample Test for Variance
X-Function vartest1 is used to perform a chi-squared variance test, so to determine whether the sample from a normal distribution could have a given hypothetical vaiance value. The following example will perform one-sample test for variance, and output the P-value.
// Import sample data
newbook;
string fpath$ = "Samples\Statistics\vartest1.dat";
string fname$ = system.path.program$ + fpath$;
impasc;
// Perform F-test
// Tail is two tailed
// Test variance is 2.0
// P-value stored in variable p
vartest1 irng:=col(1) var:=2.0 tail:=two prob:=p;
// Ouput P-value
p = ;
Two-Sample Test for Variance (F-Test)
F-test, also called two-sample test for variance, is performed by using vartest2 X-Function.
// Import sample data
newbook;
string fpath$ = "Samples\Statistics\time_raw.dat";
string fname$ = system.path.program$ + fpath$;
impasc;
// Perform F-test
// And Tail is upper tailed
vartest2 irng:=(col(1), col(2)) tail:=upper;
// Output the result tree
vartest2.=;
|