Page 158 - Applied Statistics Using SPSS, STATISTICA, MATLAB and R
P. 158
138 4 Parametric Tests of Hypotheses
The R function t.test , already mentioned in Commands 4.1, can also be used to
perform the two-sample t test. This function has several arguments the most
important of which are mentioned above. Let us illustrate its use with Example 4.9.
The first thing to do is to apply the two-variance F test with the var.test
function mentioned in section 4.4.2.1. However, in this case we are analysing
grouped data with a specific grouping (classification) variable: the wine type. For
grouped data the function is applied as var.test(formula) where
formula is written as var~group . In our Example 4.9, assuming variable CL
represents the wine classification we would then test the equality of variances of
variable Asp with:
> var.test(Asp~CL)
In the ensuing list a p value of 0.8194 is published leading to the acceptance of
the null hypothesis. We would then proceed with:
> t.test(Asp~CL,var.equal=TRUE)
Part of the ensuing list is:
t = 2.3451, df = 65, p-value = 0.02208
which is in agreement with the values published in Table 4.6. For
var.test(Phe~CL) we get a p value of 0.002 leading to the rejection of the
equality of variances and hence we would proceed with t.test(Phe~CL,
var.equal=FALSE) obtaining
t = 3.3828, df = 44.21, p-value = 0.001512
also in agreement with the values published in Table 4.6.
R stats package also has the following power.t .test function for
performing power calculations of t tests:
power.t.test(n, delta, sd, sig.level, power, type =
c(“two.sample”, “one.sample”, “paired”), alternative
= c(“two.sided”, “one.sided”))
The arguments n , delta , sd are the number of cases, the difference of means
and the standard deviation, respectively. The power calculation for the first part of
Example 4.10 would then be performed with:
> power.t.test(30, 6, 2.64, type=c(“two.sample”),
alternative=c(“one.sided”))
A power of 1 is obtained. Note that the arguments of p ower.t.test have
default values. For instance, in the above command we are assuming the default
sig.level = 0.05 . The power.t .test function also allows computing
one parameter, passed as NULL , depending on the others. For instance, the second
part of Example 4.10 would be solved with: