Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

# Load necessary libraries

> library(dplyr)
> library(readxl)
> library(car) # For ANOVA
>
> # Load the dataset
> data <- read_excel("mould_growth_experiment.xlsx")
>
> # Check the structure of the data
> str(data)
tibble [280 × 5] (S3: tbl_df/tbl/data.frame)
$ Bread_Type : chr [1:280] "Wholegrain" "White" "Wholegrain" "White" ...
$ Condition : chr [1:280] "Dry" "Dry" "Moist" "Moist" ...
$ Replicate : num [1:280] 1 1 1 1 2 2 2 2 3 3 ...
$ Day : num [1:280] 1 1 1 1 1 1 1 1 1 1 ...
$ Mould_Growth: num [1:280] 89.7 26.6 37.2 57.3 90.8 ...
>
> # Convert relevant columns to factors
> data <- data %>%
+ mutate(
+ Bread_Type = factor(Bread_Type),
+ Condition = factor(Condition),
+ Replicate = factor(Replicate),
+ Day = as.numeric(Day)
+ )
>
> # Two-way ANOVA
> anova_results <- aov(Mould_Growth ~ Bread_Type * Condition, data = data)
> summary(anova_results)
Df Sum Sq Mean Sq F value Pr(>F)
Bread_Type 1 690 689.7 0.940 0.333
Condition 1 296 295.8 0.403 0.526
Bread_Type:Condition 1 55 54.8 0.075 0.785
Residuals 276 202574 734.0
>
> # Interpretation:
> # - Significant main effects of Bread_Type and Condition indicate that
these factors independently affect mould growth.
> # - A significant interaction effect (Bread_Type:Condition) would suggest
that the effect of one factor depends on the level of the other factor.
>
> # Pairwise t-tests for Bread Type
> pairwise_t_bread <- pairwise.t.test(data$Mould_Growth, data$Bread_Type,
p.adjust.method = "bonferroni")
> pairwise_t_bread

Pairwise comparisons using t tests with pooled SD


data: data$Mould_Growth and data$Bread_Type

White
Wholegrain 0.33

P value adjustment method: bonferroni


>
> # Pairwise t-tests for Condition
> pairwise_t_condition <- pairwise.t.test(data$Mould_Growth, data$Condition,
p.adjust.method = "bonferroni")
> pairwise_t_condition

Pairwise comparisons using t tests with pooled SD

data: data$Mould_Growth and data$Condition

Dry
Moist 0.53

P value adjustment method: bonferroni


>
> # Interpretation:
> # - The pairwise t-tests will show which specific groups (e.g., wholegrain
vs. white) are significantly different from each other.
> # - The p.adjust.method = "bonferroni" adjusts for multiple comparisons to
control the family-wise error rate.
>
> # Interaction plot to visualize the interaction effect
> interaction.plot(data$Condition, data$Bread_Type, data$Mould_Growth,
+ col = c("red", "blue"), lty = 1:2, legend = TRUE,
+ xlab = "Condition", ylab = "Mean Mould Growth (%)",
+ main = "Interaction Plot of Mould Growth")
>
> # Save the results
> write.csv(summary(anova_results), "anova_results.csv")
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors =
stringsAsFactors) :
cannot coerce class ‘c("summary.aov", "listof")’ to a data.frame

>

You might also like