 
Equal variance ttest
Worked example
Time (hours) from treatment to lambing

Control
 Treated

45 87 123 120 70
 51 71 42 37 51 78
 51 49 56 47 58

= 89.0 s^{2}= 1104.5
 = 53.7 s^{2}= 141.8

This example uses hypothetical data on the effect of drug treatment on the length of time from treatment to lambing. It is based on a trial of the efficacy of dexamethasone to induce parturition in sheep. The design of this experiment is not ideal, with fewer animals in the control group than in the treatment group. Nevertheless, such designs are not uncommon in veterinary studies.
We first look at the distributions for the each group of observations, shown in the plots below. The distributions deviate from normality both for raw and transformed data. We will therefore postpone a decision on whether to transform until we have tested for equality of variances  but remember that the Fratio test will not be very reliable for this, since it is sensitive to departures from normality.

We first carry out an Fratio test on the variances of the untransformed data:
F = 1104.500/141.818 = 7.79 with 4 and 10 degrees of freedom (P = 0.0081).
Since the above result is highly significant, we carry out the same test on the variances of the log transformed data:
F = 0.03284/0.00855 = 3.84 with 4 and 10 degrees of freedom. (P = 0.077)
The test on the transformed data gives a borderline but nonsignificant Pvalue. Since with skewed distributions the Fratio test is too liberal in reporting differences, we are justified in assuming equality of variances for the transformed data.
Log transformed data

Group
 Mean
 Variance

Untreated Treated
 1.9214 1.7210
 0.03284 0.00856

Hence we proceed with a equal variance ttest on the log transformed data. Since our sample sizes are neither equal nor large, we use the general formula to obtain the best estimate of the tstatistic. We will use a null hypothesis of no difference.

t _{df=14}
 =
 (1.9214 − 1.7210) −(0)


√
 
[
 (4 × 0.03284) + (10 × 0.00856)
 ](
 5 + 11
 )

  
(5 + 11 − 2)
 5 × 11

 =
 2.984

For a twotailed test with a tstatistic of 2.984 with 14 degrees of freedom, P = 0.00986. This suggests that the treatment is providing a significant reduction in lambing time.
The 95% normal approximation confidence interval around the (transformed) treatment effect is obtained as follows, and then detransformed to give the ratio (control/treated) of the geometric means:
95% CI = 0.200 ± (2.145 × 0.0672) = 0.056 to 0.344 (transformed scale)
Ratio = 1.58 (95% CI 1.138 to 2.208) (detransformed scale)
We can conclude that the parturition time of untreated animals was on average 1.6 times (95% CI: 1.4 to 2.1) that of untreated animals. However, the small number of animals in the control group and the uncertainty over whether allocation was random means we cannot have much confidence in this result. The experiment should ideally be repeated with random allocation to similarly sized treatment groups.


Unequal variance ttest
Use of ttests for a crossover design
Worked example
Crossover design

 Indivs  Time period  Diffs

1  2

Sequence Group 1  1
 43 (A_{1})
 15 (A_{2})
 +28

2
 41 (A_{1})
 19 (A_{2})
 +22

3
 44 (A_{1})
 27 (A_{2})
 +17

4
 47 (A_{1})
 26 (A_{2})
 +21

Mean  _{1,1} = 43.75  _{1,2} = 21.75  d_{1} = 22

Sequence Group 2  5
 21 (A_{2})  33 (A_{1})
 −12

6
 25 (A_{2})
 39 (A_{1})
 −14

7
 23 (A_{2})
 41 (A_{1})
 −18

8
 30 (A_{2})
 40 (A_{1})
 −10

Mean  _{2,1} = 24.75  _{2,2} = 38.25  d_{2} = −13.5

We looked at the crossover design in Unit 7. It is a within units design where one group of units receives treatment A_{1} followed by treatment A_{2}, and the other group of units receives treatment A_{2} followed by treatment A_{1}. One might be tempted to ignore the crossover aspect of the design and just analyse such data with a paired ttest for all values of A_{1}  A_{2}. However, this would only be valid if there were no period effect. If there is a period effect (say both treatments are more effective in the second period), then a simple paired ttest would give a misleading result. Instead one carries out a series of twosample t tests.
This example uses data gathered in a trial of two drugs used for pain relief for arthritis patients. Subjects were randomly allocated to two sequence groups. A sequence group is characterized by the order in which treatments are given. All subjects in sequence group (1) received treatment A_{1} followed later by treatment A_{2}. All subjects in sequence group (2) received treatment A_{2} followed by treatment A_{1}. The response variable was the level of pain experienced.
We first display the results graphically. The two top figures below follow what happens to individual subjects through the trial. Irrespective of which order the drugs are given in, the pain score is lower when patients are on treatment A_{2} than when on A_{1}.
The lower figure shows mean responses. These suggest a slight period effect  pain levels decrease from period 1 to period 2  but it appears to affect both drugs similarly. In other words there is probably no period × treatment interaction. If there were an interaction, then the lines in the last figure would no longer be parallel and we could not analyse the data as a single crossover experiment. To understand why this is so, and how to test these results, let us rearrange these means and their differences as follows:
If we exclude random variation, the differences between these 4 means are due to a combination of the treatment effect, T, and period effect P.
 T is the difference between treatment A_{1} and treatment A_{2}
 P is the difference between period 1 and period 2.
 
Means and differences
 Effect  ⇒  Period
 ⇓   1  difference  2
 Group  1  _{1,1}  +P +T  _{1,2
}  difference  +T   −T
 2  _{2,1}  +P −T  _{2,2
}  
In which case we would expect that _{1,1}+P = _{2,2}, and _{2,1}+P =_{1,2}, which explains why the bottom graph's lines ought be parallel. Of course that simple relationship assumes T is the same in both periods, and that P&T are the same in both groups  in other words that these effects are both additive and independent.
 If that assumption is correct we would expect no difference between group means. So _{1,1}+_{1,2} = _{2,1}+_{2,2} and any observed difference between them is due to simple chance.
 Alternately, if these effects do interact, then we would expect a nonzero difference between group means  and can use a ttest of their difference to check for that interaction.
Let us check for any interaction between time period and treatment (in other words if the relative efficacy of the two treatments is dependent on time period) by comparing the mean of the totals (A_{1}+A_{2}) of the two sequence groups.
The mean of the subject totals for Group 1 = [58 + 60 + 71 + 73]/4 = 65.5
The mean of the subject totals for Group 2 = [54 + 64 + 64 + 70]/4 = 63.0
Comparing these two means with the equal variance ttest gives t = 0.496, df = 6, P = 0.638. Hence there is no significant interaction between period and treatment, and our analysis is valid.
Note that this test for interaction cannot distinguish between a period x treatment interaction and a difference between sequence groups. So it is very important that subjects are initially assigned at random to the two groups. In addition, the test for an interaction has low power because we are comparing means of totals with correspondingly fewer degrees of freedom. Hence it is advisable to use a 10% rather than 5% significance level.
Again provided P and T do not interact, excluding random variation, we would expect that:
The mean difference for period 1 to period 2 for group 1 (d_{1}) is 22
The mean difference for period 1 to period 2 for group 2 (d_{2}) is −13.5
An Fratio test shows that variances can be assumed equal, so we assess d_{1}−d_{2} with the equal variance ttest. This gives t = 12.48 with df = 6 for which P = 0.000016. This indicates a highly significant treatment effect with a mean difference between treatments of (d_{1} − d_{2})/2 = 17.8 units.
The 95% normal approximation confidence interval around the treatment effect is obtained as follows:
95% CI = 17.8 ± 0.5 × 2.447 × 2.843 = 14.3 to 21.3
We checked for a period effect, P, by assessing (d_{1} − −d_{2})/2 using an equal variance ttest.
In this case t = 2.99, df=6, P = 0.024. Hence we have a significant period effect.


The weighted ttest
Worked example
Malaria prevalence in intervention and control villages

Village
 Intervention group (1)
 Control group (2)

No.
 Prev (%)
 No.
 Prev (%)

1 2 3 4 5
_{w
}  38 65 32 75 122
 31 35 41 34 22 32.6 30.1
 27 21 94 31 102
 45 31 51 41 61 45.8 51.5

Trials of vector control methods are often carried out using cluster randomization because the effects of treatment tend to act at the group rather than individual level. We will take a hypothetical example of a trial of insecticide impregnated bed nets targeted at Anopheles mosquitoes for control of malaria. Ten villages are included in the trial. Five are allocated at random to receive a bed net intervention. The outcome variable is the prevalence of malaria parasites in children aged 15 years. There are a different number of eligible children in each village so a weighted analysis is required.

We first estimate the weighted mean prevalence of each treatment group:
_{w (1)} = [38×31 + 65×35....+ 122×22] / [38 + 65 +..... + 122] = 30.1
_{w (2)} = [27×45 + 21×31....+ 102×61] / [27 + 21 +..... + 102] = 51.5
The weighted means are markedly different from the unweighted means, with a larger apparent treatment effect. This is mainly because the two largest villages in the control group had higher prevalences than the others. Note that the weighted mean prevalences can also be obtained by dividing the total number of infections in each group by the total number of children.
Using
We then calculate the weighted variance of each treatment group:
 (38×31^{2} ....+ 122×22^{2})
 −
 5 × 30.1^{2}

s^{2}_{w (1)} =
 
66.4


5 − 1

=
 56.053

 (27×45^{2} ....+ 102×61^{2})
 −
 5 × 51.5^{2}

s^{2}_{w (2)} =
 
55.0


5 − 1

=
 98.338

Since the Fratio for these two variances is not significant, we can use the equal variance ttest. This gives a tvalue of 3.851 with 8 degrees of freedom (P = 0.005). The mean difference between prevalences is 21.4% (95% CI 8.6 to 34.2).
If we had ignored the different sample sizes we would still have found no significant difference between the variances, and proceeded with an unweighted equal variance ttest. This would have given a tvalue of 2.241 for which P = 0.055, in other words not quite significant at the conventional P = 0.05 level.


