Data Import
df<-Complete_Summarized_Data_Bamboo
df
Inspect for NAs - Aligned Rank Transform won’t run otherwise!
which(is.na(df), arr.ind=TRUE)
row col
Convert variables into factors
df$Location <- factor(df$Location)
df$Species <- factor(df$Species)
Check ANOVA assumptions
Run Shapiro-Wilk’s Test to test for normality.
df%>%shapiro_test(CWT, CD, MOE, MOR, MVS, GSG, FSPL, MaxStress)
Only CWT (Culm Wall Thickness) seems to satisfy the normality assumption. We can proceed with ANOVA for CWT; rest of the variables will be passed to ART (Aligned Rank Transformation) ANOVA, a non-parametric approach to factorial ANOVA.
Run a two-way ANOVA for Culm Wall Thickness
We now proceed to analyzing CWT using regular ANOVA. We detect a strong interaction effect for Species x Location.
lm.cwt <-lm(CWT ~ Species * Location + (1|Sample), data=df)
anova(lm.cwt)
Analysis of Variance Table
Response: CWT
Df Sum Sq Mean Sq F value Pr(>F)
Species 2 191.222 95.611 96.8085 < 2.2e-16 ***
Location 4 11.617 2.904 2.9406 0.02686 *
Species:Location 6 49.245 8.208 8.3103 1.083e-06 ***
Residuals 65 64.196 0.988
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Run an ART ANOVA for CD, MOE, MOR, SpGrav, FSPL, MVS, and MaxStress
Now, we run ART-ANOVA for the rest of the variables in the data frame.
lm.cd <- art(CD ~ Species * Location + (1|Sample), data=df)
anova(lm.cd)
Analysis of Variance of Aligned Rank Transformed Data
Table Type: Analysis of Deviance Table (Type III Wald F tests with Kenward-Roger df)
Model: Mixed Effects (lmer)
Response: art(CD)
F Df Df.res Pr(>F)
1 Species 8.5699 2 63 0.0005105 ***
2 Location 10.7778 4 63 1.0176e-06 ***
3 Species:Location 9.5626 6 63 1.8359e-07 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
plot(cd.plot.fig)
Generate pairwise comparisons across Species within Location: Culm Diameter
# 'Species' is a column in the data frame
unique_species <- unique(df$Species)
# Initialize an empty list to store the results for each species
cld_results_list <- list()
# Loop through each species
for (species in unique_species) {
# Subset data for the current species
subset_species <- filter(df, Species == species)
# Fit an art model for the current species
art_model <- art(formula = CD ~ Location, data = subset_species)
# Perform contrasts for the main effects of Location using art.con()
marginal <- art.con(art_model, "Location")
# Convert to data frame
marginal_df <- as.data.frame(marginal)
# Perform post-hoc comparisons and store the results in the list
cld_results_list[[species]] <- cldList(p.value ~ contrast, data = marginal_df)
}
# Access the results for a specific species
cld_results_list$"Tinik"
cld_results_list$"Giant"
cld_results_list$"Bolo"
lm.moe <- art(MOE ~ Species * Location + (1|Sample), data=df)
anova(lm.moe)
Analysis of Variance of Aligned Rank Transformed Data
Table Type: Analysis of Deviance Table (Type III Wald F tests with Kenward-Roger df)
Model: Mixed Effects (lmer)
Response: art(MOE)
F Df Df.res Pr(>F)
1 Species 6.0788 2 63 0.0038556 **
2 Location 14.1179 4 63 2.7956e-08 ***
3 Species:Location 15.2145 6 63 1.1100e-10 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
plot(moe.plot.fig)
# 'Species' is a column in the data frame
unique_species <- unique(df$Species)
# Initialize an empty list to store the results for each species
cld_results_list <- list()
# Loop through each species
for (species in unique_species) {
# Subset data for the current species
subset_species <- filter(df, Species == species)
# Fit an art model for the current species
art_model <- art(formula = MOE ~ Location, data = subset_species)
# Perform contrasts for the main effects of Location using art.con()
marginal <- art.con(art_model, "Location")
# Convert to data frame
marginal_df <- as.data.frame(marginal)
# Perform post-hoc comparisons and store the results in the list
cld_results_list[[species]] <- cldList(p.value ~ contrast, data = marginal_df)
}
# Access the results for a specific species
cld_results_list$"Tinik"
cld_results_list$"Giant"
cld_results_list$"Bolo"
lm.mor <- art(MOR ~ Species * Location + (1|Sample), data=df)
anova(lm.mor)
Analysis of Variance of Aligned Rank Transformed Data
Table Type: Analysis of Deviance Table (Type III Wald F tests with Kenward-Roger df)
Model: Mixed Effects (lmer)
Response: art(MOR)
F Df Df.res Pr(>F)
1 Species 2.6638 2 63 0.077528 .
2 Location 9.3363 4 63 5.4538e-06 ***
3 Species:Location 10.8956 6 63 2.7399e-08 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
plot(mor.plot.fig)
# 'Species' is a column in the data frame
unique_species <- unique(df$Species)
# Initialize an empty list to store the results for each species
cld_results_list <- list()
# Loop through each species
for (species in unique_species) {
# Subset data for the current species
subset_species <- filter(df, Species == species)
# Fit an art model for the current species
art_model <- art(formula = MOR ~ Location, data = subset_species)
# Perform contrasts for the main effects of Location using art.con()
marginal <- art.con(art_model, "Location")
# Convert to data frame
marginal_df <- as.data.frame(marginal)
# Perform post-hoc comparisons and store the results in the list
cld_results_list[[species]] <- cldList(p.value ~ contrast, data = marginal_df)
}
# Access the results for a specific species
cld_results_list$"Tinik"
cld_results_list$"Giant"
cld_results_list$"Bolo"
lm.gsg <- art(GSG ~ Species * Location + (1|Sample), data=df)
anova(lm.gsg)
Analysis of Variance of Aligned Rank Transformed Data
Table Type: Analysis of Deviance Table (Type III Wald F tests with Kenward-Roger df)
Model: Mixed Effects (lmer)
Response: art(GSG)
F Df Df.res Pr(>F)
1 Species 0.26865 2 63 0.7652786
2 Location 4.71671 4 63 0.0021541 **
3 Species:Location 2.73439 6 63 0.0200236 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
plot(gsg.plot.fig)
# 'Species' is a column in the data frame
unique_species <- unique(df$Species)
# Initialize an empty list to store the results for each species
cld_results_list <- list()
# Loop through each species
for (species in unique_species) {
# Subset data for the current species
subset_species <- filter(df, Species == species)
# Fit an art model for the current species
art_model <- art(formula = GSG ~ Location, data = subset_species)
# Perform contrasts for the main effects of Location using art.con()
marginal <- art.con(art_model, "Location")
# Convert to data frame
marginal_df <- as.data.frame(marginal)
# Perform post-hoc comparisons and store the results in the list
cld_results_list[[species]] <- cldList(p.value ~ contrast, data = marginal_df)
}
# Access the results for a specific species
cld_results_list$"Tinik"
cld_results_list$"Giant"
cld_results_list$"Bolo"
lm.fspl <- art(FSPL ~ Species * Location + (1|Sample), data=df)
anova(lm.fspl)
Analysis of Variance of Aligned Rank Transformed Data
Table Type: Analysis of Deviance Table (Type III Wald F tests with Kenward-Roger df)
Model: Mixed Effects (lmer)
Response: art(FSPL)
F Df Df.res Pr(>F)
1 Species 1.1738 2 63 0.3158545
2 Location 4.8432 4 63 0.0018062 **
3 Species:Location 7.8765 6 63 2.3921e-06 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
plot(fspl.plot.fig)
# 'Species' is a column in the data frame
unique_species <- unique(df$Species)
# Initialize an empty list to store the results for each species
cld_results_list <- list()
# Loop through each species
for (species in unique_species) {
# Subset data for the current species
subset_species <- filter(df, Species == species)
# Fit an art model for the current species
art_model <- art(formula = FSPL ~ Location, data = subset_species)
# Perform contrasts for the main effects of Location using art.con()
marginal <- art.con(art_model, "Location")
# Convert to data frame
marginal_df <- as.data.frame(marginal)
# Perform post-hoc comparisons and store the results in the list
cld_results_list[[species]] <- cldList(p.value ~ contrast, data = marginal_df)
}
# Access the results for a specific species
cld_results_list$"Tinik"
cld_results_list$"Giant"
cld_results_list$"Bolo"
lm.stress <- art(MaxStress ~ Species * Location + (1|Sample), data=df)
anova(lm.stress)
Analysis of Variance of Aligned Rank Transformed Data
Table Type: Analysis of Deviance Table (Type III Wald F tests with Kenward-Roger df)
Model: Mixed Effects (lmer)
Response: art(MaxStress)
F Df Df.res Pr(>F)
1 Species 1.0516 2 63 0.35541314
2 Location 8.1105 4 63 2.4316e-05 ***
3 Species:Location 5.5986 6 63 0.00010521 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
plot(stress.plot.fig)
# 'Species' is a column in the data frame
unique_species <- unique(df$Species)
# Initialize an empty list to store the results for each species
cld_results_list <- list()
# Loop through each species
for (species in unique_species) {
# Subset data for the current species
subset_species <- filter(df, Species == species)
# Fit an art model for the current species
art_model <- art(formula = MaxStress ~ Location, data = subset_species)
# Perform contrasts for the main effects of Location using art.con()
marginal <- art.con(art_model, "Location")
# Convert to data frame
marginal_df <- as.data.frame(marginal)
# Perform post-hoc comparisons and store the results in the list
cld_results_list[[species]] <- cldList(p.value ~ contrast, data = marginal_df)
}
# Access the results for a specific species
cld_results_list$"Tinik"
cld_results_list$"Giant"
cld_results_list$"Bolo"