InfluentialPoints.com
Biology, images, analysis, design...
 Use/Abuse Principles How To Related
"It has long been an axiom of mine that the little things are infinitely the most important" (Sherlock Holmes)

## t-tests and F-test - using R

### Test the ratio of sample variances (an F-test)

Since this test is supposed to precede a t-test, let us deal with it first.

Gives something like this:

 F test to compare two variances data: y1 and y2 F = 7.7881, num df = 4, denom df = 10, p-value = 0.008108 alternative hypothesis: true ratio of variances is not equal to 1 95 percent confidence interval: 1.74296 68.87739 sample estimates: ratio of variances 7.788141

### Using R's t-test function

The following code instructs R to perform an unequal variance 2-sample t-test.

Gives something like this:

 Welch Two Sample t-test data: y1 and y2 t = 2.3069, df = 4.474, p-value = 0.07533 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -5.462216 76.007671 sample estimates: mean of x mean of y 89.00000 53.72727

Note:
• By default this t.test function assumes you require an unequal variance, 2-sample t-test.

• To perform an equal variance t-test upon these data use t.test(y1,y2, var.equal=TRUE)

• t.test(y1,y2, paired=TRUE) would attempt to perform a 1-sample t-test of y1 and y2, but, given the data we used above, it would fail because these y1 and y2 do not have the same number of values - in other words, only some of them can be paired.

• Again by default, the t.test function assumes you want a 2-sided P-value, in other words that your alternative assumption is 2-sided. To make this function perform a 1-sided test set alternative='less' or alternative='greater'.

For example:

### t-test of weighted means

At the time of writing, the standard t.test function does not perform a t-test of weighted means. The instructions below calculate the required statistics and test them using R's cumulative t and F probability functions.

These are the results we obtained.

 For the F-test: Precise 2-sided P-value = 0.5566727> For the equal variance t-test: Precise 2-sided P-value = 0.005211392>

Note:
• Alternatively, we could have obtained the weighted means using a specific function: weighted.mean and performed the variance ratio test using the var.test function.

### Using R's t.test function

Gives something like this:

 Paired t-test data: y1 and y2 t = -5.2631, df = 14, p-value = 0.0001200 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -3.143450 -1.323217 sample estimates: mean of the differences -2.233333

Note:
• Pairs are assumed to occur according the order of values within variables y1 and y2 - in other words the ith pair are y1[i] and y2[i].

• By default the t.test function assumes paired=FALSE, so t.test(y1,y2) would perform a 2-sample t-test of y1 and y2

• Again by default, the t.test function assumes you want a 2-sided P-value, in other words that your alternative assumption is 2-sided. To make this function do a 1-sided test set alternative='less' or alternative='greater'.

For example: