TTest in RIn statistics, the Ttest is one of the most common test which is used to determine whether the mean of the two groups is equal to each other. The assumption for the test is that both groups are sampled from a normal distribution with equal fluctuation. The null hypothesis is that the two means are the same, and the alternative is that they are not identical. It is known that under the null hypothesis, we can compute a tstatistic that will follow a tdistribution with n1 + n2  2 degrees of freedom. In R, there are various types of Ttest like one sample and Welch Ttest. R provides a t.test() function, which provides a variety of Ttests. There are the following syntaxes of t.test() function for different Ttest Independent 2group Ttest here, y is numeric, and x is a binary factor. Independent 2group Ttest Here, y1 and y2 are numeric. Paired Ttest Here, y1 & y2 are numeric. One sample Ttest Here, Ho: mu=3 How to perform Ttests in RIn the Ttest, for specifying equal variances and a pooled variance estimate, we set var.equal=True. We can also use alternative="less" or alternative="greater" for specifying onetailed test. Let's see how onesample, paired sample, and independent samples Ttest is performed. OneSample TtestOneSample Ttest is a Ttest which compares the mean of a vector against a theoretical mean. There is a following formula which is used to compute the Ttest : Here,
For evaluating the statistical significance of the ttest, we need to compute the pvalue. The pvalue range starts from 0 to 1, and is interpreted as follow:
We construct the pvalue by looking at the corresponding absolute value of the ttest. In R, we use the following syntax of t.test() function for performing a onesample Ttest in R. Here,
Example Let's see an example of OneSample Ttest in which we test whether the volume of a shipment of wood was less than usual(?_{0}=0). Output: PairedSample TtestTo perform a pairedsample test, we need two vectors data y1 and y2. Then, we will run the code using the syntax t.test (y1, y2, paired = TRUE). Example: Suppose, we work in a large health clinic, and we are testing a new drug Procardia, which aims to reduce high blood pressure. We find 13000 individuals with high systolic blood pressure (x 150 = 150 mmHg, SD = 10 mmHg), and we provide them with Procardia for a month, and then measure their blood pressure again. We find that the average systolic blood pressure decreased to 144 mmHg with a standard deviation of 9 mmHg. Output: IndependentSample TtestDepending on the structure of our data and the equality of their variance, the independentsample Ttest can take one of the three forms, which are as follows:
There is the following general form of t.test() function for the independentsample ttest: By default, R assumes that the versions of y1 and y2 are unequal, thus defaulting to Welch's test. For toggling this, we set the flag var.equal=TRUE. Let's see some examples in which we test the hypothesis. In this hypothesis, Clevelanders and New Yorkers spend different amounts for eating outside on a monthly basis. Example 1: IndependentSample Ttest where y1 and y2 are numeric Output: Example 2: Where y1 is numeric and y2 are binary Output: Example 3: With equal variance not assumed Output:
Next TopicChiSquare Test
