In: Statistics and Probability
What are some of the available commands that can be utilized in R for carrying out a one-sample and two-sample t-test? What are the differences between carrying out a t-test with equal and unequal variance? Please provide an example to illustrate your assertions.
One sample t test
>t.test(dataset$sample1, mu=mu0)
The mu argument gives the value with which you want to compare the sample mean. It is optional and has a default value of zero.
By default, R performs a two-tailed test. To perform a one-tailed test, set the alternative argument to "greater" or "less", as shown below.
> t.test(dataset$sample1, mu=mu0, alternative="greater")
A 95% confidence interval for the population mean is included with
the output. To adjust the size of the interval, use the conf.level
argument.
> t.test(dataset$sample1, mu=mu0, conf.level=0.99)
Two sample t test
>t.test(a,b, var.equal=TRUE, paired=FALSE, alternative ="lesser",conf.level=0.90)
This t-test is for homogeneous variances (var.equal = TRUE) and independent samples (paired = FALSE: you can omit this because the function works on independent samples by default) ,the alternative and the confidence interval are the same as one same t test.
For a paired t test
>t.test(a,b, paired=TRUE,,conf.level=0.99)
t test for unequal variances and equal variances.
For the unequal variance t test, the null hypothesis is that the two population means are the same but the two population variances may differ
For the equal variance t test, the null hypothesis is that the two population means and populatio n variances are the same .
The unequal variance t test is more useful when you think about it as a way to create a confidence interval. Your prime goal is not to ask whether two populations differ, but to quantify how far apart the two means are. The unequal variance t test reports a confidence interval for the difference between two means that is usable even if the standard deviations differ.
The homogenity can be tested using the F test and while conducting two sample t test , use the following code,
>var.test(a,b)
For example ,
= c(175, 168, 168, 190, 156, 181, 182, 175, 174, 179) b = c(185, 169, 173, 173, 188, 186, 175, 174, 179, 180) var.test(a,b) F test to compare two variances data: a and b F = 2.1028, num df = 9, denom df = 9, p-value = 0.2834 alternative hypothesis: true ratio of variances is not equal to 1 95 percent confidence interval: 0.5223017 8.4657950
Here the p value > 0.05,we accept H0 and hence the variances are assumed to be equal .