One-sample and paired-sample t-test Show
SyntaxDescriptionexample
example
example
example
example
example
example
Examplescollapse all t-Test for Mean Equal to ZeroLoad the sample data. Create a vector containing the third column of the stock returns data. load stockreturns
x = stocks(:,3); Test the null hypothesis that the sample data comes from a population with mean equal to zero. [h,p,ci,stats] = ttest(x) stats = struct with fields:
tstat: -2.6065
df: 99
sd: 1.6027
The returned value t-Test at Different Significance LevelLoad the sample data. Create a vector containing the third column of the stock returns data. load stockreturns
x = stocks(:,3); Test the null hypothesis that the sample data are from a population with mean equal to zero at the 1% significance level. h = ttest(x,0,'Alpha',0.01) The returned value Paired-Sample t-TestLoad the sample data. Create vectors containing the first and second columns of the data matrix to represent students’ grades on two exams. load examgrades
x = grades(:,1);
y = grades(:,2); Test the null hypothesis that the pairwise difference between data vectors The returned value of Paired-Sample t-Test at Different Significance LevelLoad the sample data. Create vectors containing the first and second columns of the data matrix to represent students’ grades on two exams. load examgrades
x = grades(:,1);
y = grades(:,2); Test the null hypothesis that the pairwise difference between data vectors [h,p] = ttest(x,y,'Alpha',0.01) The returned value of t-Test for a Hypothesized MeanLoad the sample data. Create a vector containing the first column of the students' exam grades data. load examgrades
x = grades(:,1); Test the null hypothesis that sample data comes from a distribution with mean The returned value of One-Sided t-TestLoad the sample data. Create a vector containing the first column of the students’ exam grades data. load examgrades
x = grades(:,1); Plot a histogram of the exam grades data and fit a normal density function. histfit(x) xlabel("Grade") ylabel("Frequency") Use a right-tailed t-test to test the null hypothesis that the data comes from a population with mean equal to 65, against the alternative that the mean is greater than 65. [h,~,~,stats] = ttest(x,65,"Tail","right") stats = struct with fields:
tstat: 12.5726
df: 119
sd: 8.7202
The returned value of Plot the corresponding Student's t-distribution, the returned t-statistic, and the critical t-value. Calculate the critical t-value for the default confidence level of 95% by using nu = stats.df; k = linspace(-15,15,300); tdistpdf = tpdf(k,nu); tval = stats.tstat tvalpdf = tpdf(tval,nu); tcrit = tinv(0.95,nu) plot(k,tdistpdf) hold on scatter(tval,tvalpdf,"filled") xline(tcrit,"--") legend(["Student's t pdf", "t-Statistic", ... "Critical Cutoff"]) The orange dot represents the t-statistic and is located to the right of the dashed black line that represents the critical t-value. Input Argumentscollapse all x — Sample data vector | matrix | multidimensional arraySample data, specified as
a vector, matrix, or multidimensional array. Data Types: y — Sample data vector | matrix | multidimensional arraySample data, specified as a vector, matrix, or multidimensional array. If Data Types: m — Hypothesized population mean 0 (default) | scalar valueHypothesized population mean, specified as a scalar value. Data Types: Name-Value ArgumentsSpecify optional pairs of arguments as Before R2021a, use commas to separate each name and value, and enclose Example: Significance level of the hypothesis test, specified as the comma-separated pair consisting of Example: Data Types: Dimension of the input matrix along which to test the means, specified as the comma-separated pair consisting of Example: Data
Types: Tail — Type of alternative hypothesis 'both' (default) | 'right' | 'left'Type of alternative hypothesis to evaluate, specified as the comma-separated pair consisting of
Example: Output Argumentscollapse all Hypothesis test result, returned as
p-value of the test, returned as
a scalar value in the range [0,1]. Confidence interval for the true population mean, returned as a two-element vector
containing the lower and upper boundaries of the 100 × (1 – stats — Test statistics structureTest statistics, returned as a structure containing the following:
More Aboutcollapse all One-Sample t-TestThe one-sample t-test is a parametric test of the location parameter when the population standard deviation is unknown. The test statistic is where x¯ is the sample mean, Multidimensional ArrayA multidimensional array has more than two dimensions. For example, if First Nonsingleton DimensionThe first nonsingleton dimension is the first dimension of an array whose size is not equal to 1. For example, if Tips
Extended CapabilitiesGPU Arrays Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox). Version HistoryIntroduced before R2006a What value is estimated with a confidence interval using t statistic?The correct answer is B) The value for an unknown population mean. The t-statistic is calculated during a t-test, giving it the name. This attempts to infer the value for some unknown population average.
What value is estimated with a confidence interval?Analysts often use confidence intervals than contain either 95% or 99% of expected observations. Thus, if a point estimate is generated from a statistical model of 10.00 with a 95% confidence interval of 9.50 - 10.50, it can be inferred that there is a 95% probability that the true value falls within that range.
What value is expected for the t statistic when the null hypothesis is true?If the sample data equals the null hypothesis precisely, the t-test produces a t-value of 0.
What is the null hypothesis for a repeatedHypothesis Tests with the Repeated-Measures t (cont.) In words, the null hypothesis says that there is no consistent or systematic difference between the two treatment conditions. Note that the null hypothesis does not say that each individual will have a difference score equal to zero.
|