Load necessary packages. \(~\)
library(WRS2)
library(ggplot2)
library(gplots)
library(readr)
library(tidyverse)
library(rstatix)
\(~\)
Import Wide Format Data into RStudio
inhibwide <- read.csv("C:/HAROLDSKI/inhibdata1.csv")
View(inhibwide)
\(~\)
First, we convert the data into long format:
# Gather the time columns into a single column (long format).
# Convert id and time into factor variables
inhiblong <- inhibwide%>%
gather(key = "time", value = "inhibition", t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20) %>%
convert_as_factor(id, Extract, time)
# Inspect some random rows of the data by extracts
set.seed(123)
inhiblong %>% sample_n_by(Extract, time, size = 2)
\(~\)
First we calculate summary statistics for inhibition by extract and time:
inhiblong$time<-factor(inhiblong$time, levels = unique(as.character(inhiblong$time)))
sum1 <- inhiblong %>%
group_by(Extract, time) %>%
summarise(
mean = mean(inhibition),
sd = sd(inhibition)
)
## `summarise()` has grouped output by 'Extract'. You can override using the `.groups` argument.
sum1
\(~\)
Let us now take a look at the plot of the dependent variable (inhibition) by extract and time.
# Plot of the mean % Inhibition at each time point for each extract.
ggplot(sum1, aes(x = time, y = mean, color = Extract, group = Extract))+
geom_point() +
geom_line() +
ggtitle("Average % Inhibition per Cycle") +
theme(plot.title = element_text(hjust = 0.8))
The plot shows that extract P92B have higher average % inhibition per cycle compared to all the other extracts whose average % inhibition, all throughout the 20 time periods, is within 50% and 213%.
\(~\)
Let us now check the assumptions prior to performing a Two-Way Mixed ANOVA.
First, we check for outliers in the data.
# Check for Outliers:
inhiblong%>%
group_by(time, Extract) %>%
identify_outliers(inhibition)
The result shows that there are no significant outliers in the data. \(~\)
Next, we check for homogeneity of variance assumption of the between-subjects factor which is the “Extract”. We do this by using Levene’s test which is performed at each level of the “time” variable.
inhiblong %>%
group_by(time) %>%
levene_test(inhibition ~ Extract)
The Levene’s test shows that the variances are homogeneous (p > 0.05). Hence, the assumption of homogeneity of variances is satisfied by the data.
\(~\)
Next, we look at the Homogeneity of Covariances assumption. This is assessed by means of the Box’s M-test.
box_m(inhiblong[, "inhibition", drop=FALSE], inhiblong$Extract)
Box’s M-test result show that p<0.001, indicating a significant result. However, since the sample sizes are equal, we can ignore the test (https://en.wikiversity.org/wiki/Box&27s_M, Tabachnik & Fidell, 2001).
\(~\)
Now, let us check the assumption of normality of data.
# Check for Normality of data
inhiblong%>%
group_by(Extract, time) %>%
shapiro_test(inhibition)
\(~\)
Since the normality assumption cannot be checked due to data on some combination of extract and time being identical. In addition, the Shapiro Wilk’s test of Normality does not have enough information needed to test the data distribution, most likely due to the fact that the sample sizes for each factor combination is very low (where we have only 3 data points for each level combination of Extract and Time).
Before we attempt to perform a robust Two-Way Mixed ANOVA, let us first try to perform the Two-Way Mixed ANOVA using the anova_test() function.
res.aov <- anova_test(
data = inhiblong, dv = inhibition, wid = id,
between = Extract, within = time
)
get_anova_table(res.aov)
With this, we now attempt to perform a robust Two-Way Mixed ANOVA. Robust methods does not require the data to meet any statistical assumptions, yet still arrive at reliable and valid results.
# Performing Robust Mixed ANOVA on the data.
sppba(inhibition ~ Extract*time, id, data = inhiblong, avg = TRUE)
sppbb(inhibition ~ Extract*time, id, data = inhiblong)
sppbi(inhibition ~ Extract*time, id, data = inhiblong)
The result of the robust Two-Way Mixed Anova on the data indicate that the design matrix is singular. This implies that the design matrix is non-invertible, hence,