Data was collected on individuals to analyze the effects of body-fat, smoking and gender on an individual’s physical stress tolerance. The target variable collected was minutes until the subject felt fatigued. The subjects were not screened for anything other than the those mentioned above, so factors such as age, relationship status or exercise habits were not considered.

In the end the data provided us with a good understanding of which factors contribute to physical stress fatigue.

```
# Load Data
# The varables are coded as follows:
# Smoking = A, 1 = Heavy, -1 = Light
# Gender = B, 1 = Female, -1 = Male
# Bodyfat = C, 1 = High, -1 = Low
# The results of the target variable are:
tolerance <- matrix(c(24.1,29.2,24.6,17.6, 18.8, 23.2,
20, 21.9, 17.6, 14.8, 10.3, 11.3,
14.6, 15.3, 12.3, 14.9, 20.4, 12.8,
16.1, 9.3, 10.8, 10.1, 14.4, 6.1),
byrow=T,ncol=3)
# Build Table
dimnames(tolerance) <- list(
c("(1)","a","b","ab","c","ac","bc","abc"),
c("Rep1","Rep2","Rep 3"))
A <- as.numeric(rep(c("-1","1"),4))
B <- as.numeric(rep(c("-1","-1","1","1"),2))
C <- as.numeric(c(rep("-1",4),rep("1",4)))
Total <- as.numeric(apply(tolerance,1,sum))
Average <- Total/3
cbind(A,B,C,tolerance,Total)
```

Next, we organized the data in a table which includes treatment combinations, totals, and averages for each combination. Now, for example, we can see that there is a large difference among males with a light smoking history and low body fat percentage versus males with a light smoking history and high body fat percentage (11.87 minutes).

```
## Interaction effects
AB <- A*B
AC <- A*C
BC <- B*C
ABC <- A*B*C
cbind(A,B,C,AB,AC,BC,ABC,Total,Average)
## Summary
#Effects <- t(Total) %*% cbind(A,B,C,AB,AC,BC,ABC)/(4*n)
#Summary <- rbind( cbind(A,B,C,AB,AC,BC,ABC),Effects)
#dimnames(Summary)[[1]] <- c(dimnames(tolerance)[[1]],"Effect")
#Summary
```

Now we run a model to estimate parameters and conduct an analysis of variance. The ANOVA table is below.

```
# Fit as an ANOVA model
tolerance.vec <- c(t(tolerance))
Af <- rep(as.factor(A),rep(3,8))
Bf <- rep(as.factor(B),rep(3,8))
Cf <- rep(as.factor(C),rep(3,8))
options(contrasts=c("contr.sum","contr.poly"))
tol.lm <- lm(tolerance.vec ~ Af*Bf*Cf)
anova(tol.lm)
```

The analysis of variance confirms that all three main effects and one interaction effect (AC, or Smoking and Body-fat) are significant. Then the reduced model may be described as below.

```
# Reduced ANOVA
tol.lm2 <- lm(tolerance.vec ~ Bf+Af*Cf+Af)
anova(tol.lm2)
```

```
# Residuls
tol.res = resid(tol.lm2)
tolerance.data = c(24.1,29.2,24.6,17.6, 18.8, 23.2, 20, 21.9, 17.6, 14.8, 10.3, 11.3,
14.6, 15.3, 12.3, 14.9, 20.4, 12.8,
16.1, 9.3, 10.8, 10.1, 14.4, 6.1)
plot(tolerance.data, tol.res,
ylab="Residuals", xlab="Tolerance (minutes)",
main="Stress Test, Residual Plot", col=tolerance,pch=16)
abline(0, 0)
# Normal Prob.
# Check if error term is normally distributed
tol.stdres = rstandard(tol.lm2)
qqnorm(tol.stdres,
ylab="Standardized Residuals",
xlab="Normal Scores",
main="Stress Test, Normal Probability Plot")
qqline(tol.stdres, col=16)
# Shapiro test
shapiro.test(tol.res)
```

In the above residual and normal probability plots, we see the assumptions of constancy and normality hold.

Additionally, there appears to be no outliers. Also confirmed through the Shapiro Wilk’s test, which fails to reject the hypothesis of normality at the 5% level.

```
## Interaction Plots
A2 <- rep(c("Light","Heavy"),4)
B2 <- rep(c("Male","Male","Female","Female"),2)
C2 <- c(rep("Low",4),rep("High",4))
Af2 <- rep(as.factor(A2),rep(3,8))
Bf2 <- rep(as.factor(B2),rep(3,8))
Cf2 <- rep(as.factor(C2),rep(3,8))
Smoking <- Af2
Gender <- Bf2
Fat <- Cf2
interaction.plot(Gender, Smoking, tolerance.vec, col
= c("red","blue"), lty=1, leg.bty = "o",
main = "Interaction Plot, Gender and Smoking")
```

```
interaction.plot(Gender, Fat, tolerance.vec, col
= c("red","blue"), lty=1, leg.bty = "o",
main= "Interaction plot, Gender and Fat Level")
```

```
interaction.plot(Smoking, Fat, tolerance.data, col
= c("red","blue"), lty=1, leg.bty = "o",
main= "Interaction plot, Smoking and Fat Level")
```

As seen in the interaction plot above, subjects with heavy smoking history and low body fat showed significantly lower mean physical stress tolerance compared to subjects with light smoking history and low body fat, which is not surprising. However, subjects with heavy smoking histories and high body fat have about the same mean tolerance as those with light smoking histories and high body fat. Furthermore, subjects with light smoking histories and high body fat had significantly lower mean physical stress tolerance compared to those with light smoking histories and low fat. This sort of significance was not exhibited in other factor level comparisons. This suggests that heavy smoking does not lower physical stress tolerance in high body fat individuals.