We analyze the OilDeapsorbtion dataset, which contains data from an experiment designed to measure the effect of ultrasound on removing oil from sand. The goal of this project is to determine whether the amount of oil and the duration of ultrasound exposure affect the difference in oil removed between experimental and control runs.
Create dot plots to explore the relationship between the explanatory variables and the response variable.
Create an interaction plot and determine whether an interaction term should be included in the model.
Check the conditions for a two-way ANOVA model with interaction.
Perform the two-way ANOVA and interpret the results.
Construct 95% confidence intervals and interpret them in context.
We will explore the questions above in detail.
library(Stat2Data)
data(OilDeapsorbtion)
OilDeapsorbtion$Oil <- as.factor(OilDeapsorbtion$Oil)
OilDeapsorbtion$Ultra <- as.factor(OilDeapsorbtion$Ultra)
head(OilDeapsorbtion)
## Salt Ultra Oil Diff
## 1 0 5 5 0.5
## 2 0 5 5 0.5
## 3 0 5 5 0.5
## 4 0 5 5 -0.5
## 5 0 5 5 0.0
## 6 0 10 5 -0.5
Create dot plots to investigate whether Oil and Ultra have an effect on Diff.
plot(OilDeapsorbtion$Oil, OilDeapsorbtion$Diff,
xlab = "Oil Amount", ylab = "Difference in Oil Removed",
main = "Diff vs Oil")
plot(OilDeapsorbtion$Ultra, OilDeapsorbtion$Diff,
xlab = "Ultrasound Time", ylab = "Difference in Oil Removed",
main = "Diff vs Ultra")
We used graphical methods (boxplots) to examine the relationship between the explanatory variables and the response variable. The plot shows that the difference in oil removal (Diff) tends to be higher when the oil amount is 10 ml compared to 5 ml.
This indicates that Oil likely has an effect on Diff. There is also some variability within each group, but the overall pattern suggests that higher oil levels are associated with greater oil removal.
Based on this pattern, it is reasonable to expect that Oil may be a significant factor in a two-way ANOVA analysis.
Create an interaction plot.
interaction.plot(OilDeapsorbtion$Ultra,
OilDeapsorbtion$Oil,
OilDeapsorbtion$Diff,
xlab = "Ultrasound Time",
trace.label = "Oil Amount",
ylab = "Mean Diff")
We used an interaction plot to examine whether there is an interaction between Oil and Ultra. The plot shows that the lines are not parallel and move in different directions, suggesting a possible interaction effect.
Specifically, for Oil = 10, the mean Diff decreases as Ultra increases, while for Oil = 5, the mean Diff increases as Ultra increases. This indicates that the effect of ultrasound time may depend on the level of oil.
However, this is only a visual indication, and further statistical testing is needed to determine whether the interaction is statistically significant. model.
Check conditions for two-way ANOVA with interaction.
model <- aov(Diff ~ Oil * Ultra, data = OilDeapsorbtion)
par(mfrow = c(2,2))
plot(model)
We used residual plots to check the assumptions required for a two-way ANOVA model with interaction.
The residuals versus fitted values plot shows no clear pattern, suggesting that the assumption of constant variance is reasonable. The Q-Q plot indicates that the residuals are approximately normally distributed, with only slight deviations at the extremes. The scale-location plot shows a relatively constant spread of residuals across fitted values, further supporting the assumption of equal variance.
Additionally, the residuals appear to be similarly distributed across factor levels, indicating no major issues with group variability.
Overall, the conditions for a two-way ANOVA model appear to be reasonably met, and it is appropriate to proceed with the analysis.
Run the two-way ANOVA model and interpret results.
model <- aov(Diff ~ Oil * Ultra, data = OilDeapsorbtion)
summary(model)
## Df Sum Sq Mean Sq F value Pr(>F)
## Oil 1 4.556 4.556 8.760 0.00542 **
## Ultra 1 0.056 0.056 0.108 0.74417
## Oil:Ultra 1 1.406 1.406 2.704 0.10883
## Residuals 36 18.725 0.520
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
We used a two-way ANOVA with interaction to test the effects of Oil and Ultra on Diff. The results show that:
The effect of Oil is statistically significant (p-value = 0.00542), indicating that the amount of oil has a significant impact on the difference in oil removal.
The effect of Ultra is not statistically significant (p-value = 0.74417), suggesting that the duration of ultrasound exposure does not have a significant effect on Diff.
The interaction effect between Oil and Ultra is not statistically significant (p-value = 0.10883), indicating that there is not sufficient evidence that the effect of one variable depends on the other.
Overall, the results indicate that Oil is the primary factor influencing Diff, while Ultra and the interaction between Oil and Ultra do not have significant effects.
Construct 95% confidence intervals.
TukeyHSD(model)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = Diff ~ Oil * Ultra, data = OilDeapsorbtion)
##
## $Oil
## diff lwr upr p adj
## 10-5 0.675 0.2124617 1.137538 0.0054183
##
## $Ultra
## diff lwr upr p adj
## 10-5 -0.075 -0.5375383 0.3875383 0.7441724
##
## $`Oil:Ultra`
## diff lwr upr p adj
## 10:5-5:5 1.05 0.1813444 1.9186556 0.0126083
## 5:10-5:5 0.30 -0.5686556 1.1686556 0.7889444
## 10:10-5:5 0.60 -0.2686556 1.4686556 0.2629340
## 5:10-10:5 -0.75 -1.6186556 0.1186556 0.1110906
## 10:10-10:5 -0.45 -1.3186556 0.4186556 0.5104645
## 10:10-5:10 0.30 -0.5686556 1.1686556 0.7889444
We constructed 95% confidence intervals for differences between group means using Tukey’s method.
For Oil, the confidence interval comparing 10 ml to 5 ml is (0.21, 1.14), which does not include zero. This indicates that there is a statistically significant difference between the two oil levels, with the 10 ml samples having a higher mean Diff than the 5 ml samples.
For Ultra, the confidence interval includes zero, indicating that there is no significant difference between the two ultrasound exposure times.
For the interaction comparisons, most confidence intervals include zero, suggesting that there is no consistent evidence of significant interaction effects between Oil and Ultra.
Overall, these results support the conclusion that Oil has a significant effect on Diff, while Ultra and the interaction between Oil and Ultra do not show consistent significant differences.
library(Stat2Data)
data(OilDeapsorbtion)
OilDeapsorbtion$Oil <- as.factor(OilDeapsorbtion$Oil)
OilDeapsorbtion$Ultra <- as.factor(OilDeapsorbtion$Ultra)
plot(OilDeapsorbtion$Oil, OilDeapsorbtion$Diff)
plot(OilDeapsorbtion$Ultra, OilDeapsorbtion$Diff)
interaction.plot(OilDeapsorbtion$Ultra,
OilDeapsorbtion$Oil,
OilDeapsorbtion$Diff)
model <- aov(Diff ~ Oil * Ultra, data = OilDeapsorbtion)
summary(model)
par(mfrow = c(2,2))
plot(model)
TukeyHSD(model)