Introduction

This report has two parts. First we find how many samples of each insulating fluid we need for a new experiment. Then we analyze the data the experimenter actually collected, using a one-way ANOVA and Tukey’s test.

Question 1: How many samples of each fluid?

There are 4 fluids and we want to find the number of samples per fluid. The information we have is:

  • variance inside each group (within) = 3.5
  • alpha = 0.05
  • power = 0.80
  • the smallest mean is 18 and the largest mean is 20, so the difference we want to detect is 2 hours

The problem is that we only know the smallest and the largest mean. The other two means could be anywhere in between, and where we put them changes the variance between the groups. That is why we have to do three cases.

In R we use power.anova.test(). It needs between.var, which is the variance of the group means, so for each case we write the four means and use var().

Minimum variability

The two middle fluids go in the center, at 19. This makes the means as close to each other as possible.

min_means <- c(18, 19, 19, 20)
var(min_means)
## [1] 0.6666667
power.anova.test(groups = 4,
                 between.var = var(min_means),
                 within.var = 3.5,
                 sig.level = 0.05,
                 power = 0.80)
## 
##      Balanced one-way analysis of variance power calculation 
## 
##          groups = 4
##               n = 20.08368
##     between.var = 0.6666667
##      within.var = 3.5
##       sig.level = 0.05
##           power = 0.8
## 
## NOTE: n is number in each group

R gives n = 20.08, and we always round up, so we need 21 samples of each fluid.

Intermediate variability

The four means are spread evenly between 18 and 20.

int_means <- c(18, 18.6667, 19.3333, 20)
var(int_means)
## [1] 0.7407259
power.anova.test(groups = 4,
                 between.var = var(int_means),
                 within.var = 3.5,
                 sig.level = 0.05,
                 power = 0.80)
## 
##      Balanced one-way analysis of variance power calculation 
## 
##          groups = 4
##               n = 18.17901
##     between.var = 0.7407259
##      within.var = 3.5
##       sig.level = 0.05
##           power = 0.8
## 
## NOTE: n is number in each group

R gives n = 18.18, so we need 19 samples of each fluid.

Maximum variability

Two fluids go at 18 and the other two at 20. This makes the means as far apart as possible.

max_means <- c(18, 18, 20, 20)
var(max_means)
## [1] 1.333333
power.anova.test(groups = 4,
                 between.var = var(max_means),
                 within.var = 3.5,
                 sig.level = 0.05,
                 power = 0.80)
## 
##      Balanced one-way analysis of variance power calculation 
## 
##          groups = 4
##               n = 10.56952
##     between.var = 1.333333
##      within.var = 3.5
##       sig.level = 0.05
##           power = 0.8
## 
## NOTE: n is number in each group

R gives n = 10.57, so we need 11 samples of each fluid.

Answer

Case Variance of the means n per fluid Total
Minimum variability 0.667 21 84
Intermediate variability 0.741 19 76
Maximum variability 1.333 11 44

When the means are farther apart the difference is easier to see, so we need fewer samples. The minimum case is the safest one because it asks for the most samples.

Question 2: Analysis of the collected data

The experimenter used 6 observations per fluid. The data is entered in tidy format, which means one column with the fluid type and one column with the life measurement, instead of one column per fluid.

life <- c(17.6, 18.9, 16.3, 17.4, 20.1, 21.6,
          16.9, 15.3, 18.6, 17.1, 19.5, 20.3,
          21.4, 23.6, 19.4, 18.5, 20.5, 22.3,
          19.3, 21.1, 16.9, 17.5, 18.3, 19.8)

fluid <- factor(rep(1:4, each = 6))

dat <- data.frame(fluid, life)

head(dat)
##   fluid life
## 1     1 17.6
## 2     1 18.9
## 3     1 16.3
## 4     1 17.4
## 5     1 20.1
## 6     1 21.6
str(dat)
## 'data.frame':    24 obs. of  2 variables:
##  $ fluid: Factor w/ 4 levels "1","2","3","4": 1 1 1 1 1 1 2 2 2 2 ...
##  $ life : num  17.6 18.9 16.3 17.4 20.1 21.6 16.9 15.3 18.6 17.1 ...

rep(1:4, each = 6) repeats each fluid number six times, and factor() makes R treat the numbers as groups instead of as numbers.

Sample mean and standard deviation of each fluid:

tapply(dat$life, dat$fluid, mean)
##        1        2        3        4 
## 18.65000 17.95000 20.95000 18.81667
tapply(dat$life, dat$fluid, sd)
##        1        2        3        4 
## 1.952178 1.854454 1.879096 1.554885

a. Test for a difference in the mean life

The hypotheses are:

  • H0: mu1 = mu2 = mu3 = mu4 (all four fluids have the same mean life)
  • Ha: at least one fluid has a different mean life

The significance level is alpha = 0.10.

model <- aov(life ~ fluid, data = dat)
summary(model)
##             Df Sum Sq Mean Sq F value Pr(>F)  
## fluid        3  30.16   10.05   3.047 0.0525 .
## Residuals   20  65.99    3.30                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

The F value is 3.047 and the p-value is 0.0525. The p-value is smaller than 0.10, so we reject H0.

There is evidence that at least one of the four fluids has a different mean life. Note that this p-value is bigger than 0.05, so with a stricter alpha of 0.05 we would not have rejected H0.

b. Is the model adequate?

The ANOVA needs two things to be true: the residuals should be normal and the groups should have about the same variance. We check both with plots.

qqnorm(residuals(model), main = "Normal Q-Q Plot of the Residuals")
qqline(residuals(model))

plot(fitted(model), residuals(model),
     main = "Residuals vs Fitted Values",
     xlab = "Fitted Value (mean life of the fluid)",
     ylab = "Residual",
     pch = 19)
abline(h = 0, lty = 2)

boxplot(life ~ fluid, data = dat,
        col = "lightblue",
        main = "Life by Fluid Type",
        xlab = "Fluid Type",
        ylab = "Life (hours) at 35kV")

Comments

The normal Q-Q plot of the residuals is close to a straight line. The points follow the line and only move a little at the two ends, so the residuals look normal.

In the residuals vs fitted plot the points are spread around the zero line in a similar way for all four fluids. There is no pattern and no group looks much more spread out than the others, so the equal variance condition looks fine.

The boxplots say the same thing. The four boxes are about the same height, and the standard deviations are also close to each other (1.55 to 1.95). Fluid 3 is clearly higher than the rest.

The model looks adequate, so we can trust the ANOVA result.

c. Which fluids are different? (Tukey’s test)

The ANOVA only says that at least one fluid is different, not which one. Tukey’s test compares every pair of fluids and keeps the familywise error rate at 0.10. That is what conf.level = 0.90 does.

tukey <- TukeyHSD(model, conf.level = 0.90)
tukey
##   Tukey multiple comparisons of means
##     90% family-wise confidence level
## 
## Fit: aov(formula = life ~ fluid, data = dat)
## 
## $fluid
##           diff        lwr       upr     p adj
## 2-1 -0.7000000 -3.2670196 1.8670196 0.9080815
## 3-1  2.3000000 -0.2670196 4.8670196 0.1593262
## 4-1  0.1666667 -2.4003529 2.7336862 0.9985213
## 3-2  3.0000000  0.4329804 5.5670196 0.0440578
## 4-2  0.8666667 -1.7003529 3.4336862 0.8413288
## 4-3 -2.1333333 -4.7003529 0.4336862 0.2090635
plot(tukey, las = 1)

Comments

Only one pair is significant: fluid 3 against fluid 2. Their difference is 3.00 hours, the confidence interval goes from 0.43 to 5.57, and it does not contain zero. The adjusted p-value is 0.044, which is below 0.10.

All the other pairs have confidence intervals that contain zero, so we cannot say those fluids are different. In the plot this is easy to see: the line for 3-2 is the only one that does not cross the dashed line at zero.

Looking at the sample means, fluid 3 had the longest life (20.95 hours) and fluid 2 the shortest (17.95 hours), so those two are the ones far enough apart to be detected. Fluids 1 and 4 are in the middle (18.65 and 18.82) and are not different from anything.

Complete code

# ---- Question 1: sample size ----

# minimum variability
min_means <- c(18, 19, 19, 20)
var(min_means)

power.anova.test(groups = 4,
                 between.var = var(min_means),
                 within.var = 3.5,
                 sig.level = 0.05,
                 power = 0.80)

# intermediate variability
int_means <- c(18, 18.6667, 19.3333, 20)
var(int_means)

power.anova.test(groups = 4,
                 between.var = var(int_means),
                 within.var = 3.5,
                 sig.level = 0.05,
                 power = 0.80)

# maximum variability
max_means <- c(18, 18, 20, 20)
var(max_means)

power.anova.test(groups = 4,
                 between.var = var(max_means),
                 within.var = 3.5,
                 sig.level = 0.05,
                 power = 0.80)

# ---- Question 2: analysis of the data ----

life <- c(17.6, 18.9, 16.3, 17.4, 20.1, 21.6,
          16.9, 15.3, 18.6, 17.1, 19.5, 20.3,
          21.4, 23.6, 19.4, 18.5, 20.5, 22.3,
          19.3, 21.1, 16.9, 17.5, 18.3, 19.8)

fluid <- factor(rep(1:4, each = 6))

dat <- data.frame(fluid, life)

head(dat)
str(dat)

tapply(dat$life, dat$fluid, mean)
tapply(dat$life, dat$fluid, sd)

# a. ANOVA
model <- aov(life ~ fluid, data = dat)
summary(model)

# b. model adequacy
qqnorm(residuals(model), main = "Normal Q-Q Plot of the Residuals")
qqline(residuals(model))

plot(fitted(model), residuals(model),
     main = "Residuals vs Fitted Values",
     xlab = "Fitted Value (mean life of the fluid)",
     ylab = "Residual",
     pch = 19)
abline(h = 0, lty = 2)

boxplot(life ~ fluid, data = dat,
        col = "lightblue",
        main = "Life by Fluid Type",
        xlab = "Fluid Type",
        ylab = "Life (hours) at 35kV")

# c. Tukey
tukey <- TukeyHSD(model, conf.level = 0.90)
tukey

plot(tukey, las = 1)