This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
If you would like to follow the code used for the data visualisation and analysis, install and use the library function for the following packages.
library(ggpubr)
## Loading required package: ggplot2
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(pastecs)
##
## Attaching package: 'pastecs'
## The following objects are masked from 'package:dplyr':
##
## first, last
library(readr)
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
##
## recode
library(tidyr)
##
## Attaching package: 'tidyr'
## The following object is masked from 'package:pastecs':
##
## extract
library(ez)
library(lme4)
## Loading required package: Matrix
##
## Attaching package: 'Matrix'
## The following objects are masked from 'package:tidyr':
##
## expand, pack, unpack
library(emmeans)
Creating a graph that displays the normalised cell counts from experiment 1.
data_for_BMDM1 <- data.frame(
Conditions = c("M0", "IL-4", "HMW-15ng/mL", "HMW-30ng/mL", "LMW-15ng/mL", "LMW-30ng/mL"),
Normalised.cell.count = c(1, 0.8591549, 0.8028169, 0.7535211, 1.1338028, 1.0492958),
Standard.Deviation = c(0, 0.090119071, 0.001457451, 0.096677602, 0.370556989, 0.095220151)
)
data_for_BMDM1$Conditions <- factor(data_for_BMDM1$Conditions, levels = c("M0", "IL-4", "HMW-15ng/mL", "HMW-30ng/mL", "LMW-15ng/mL", "LMW-30ng/mL"))
ggplot(data_for_BMDM1, aes(x = Conditions, y = Normalised.cell.count, fill = Conditions)) +
geom_bar(stat = "identity") +
geom_errorbar(aes(ymin = Normalised.cell.count - Standard.Deviation, ymax = Normalised.cell.count + Standard.Deviation), position = position_dodge(width = 0.8), width = 0.25) +
theme(axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title.y = element_text(face = "bold", size = 12),
axis.title.x = element_text(face = "bold", size = 12),
legend.title = element_text(face = "bold", size = 12)) + # Customize legend title
scale_fill_brewer(palette = "Set3") +
labs(y = "Normalised cell counts",
fill = "Conditions") + # Set custom legend title
guides(fill = guide_legend(title.position = "top", title.vjust = 0.5))
Creating a graph that displays the normalized cell counts for experiment 2.
# Your dataset
data_for_BMDM2 <- data.frame(
Conditions = c("M0", "Starve", "IL-4+CSF-1-", "IL-4+CSF-1+", "HMW-0.75mg/mL", "HMW-1.5mg/mL", "LMW-0.75mg/mL", "LMW-1.5mg/mL"),
Normalised.cell.count = c(1, 0.178571429, 0.214285714, 0.75, 0.267857143, 0.553571429, 0.803571429, 0.785714286),
Standard.Deviation = c(0, 0, 0.101015254, 0.404061018, 0.126269068, 0.025253814, 0.126269068, 0.151522882)
)
# Order the levels of the Conditions factor
data_for_BMDM2$Conditions <- factor(data_for_BMDM2$Conditions, levels = c("M0", "Starve", "IL-4+CSF-1-", "IL-4+CSF-1+", "HMW-0.75mg/mL", "HMW-1.5mg/mL", "LMW-0.75mg/mL", "LMW-1.5mg/mL"))
# Create a bar graph with error bars
ggplot(data_for_BMDM2, aes(x = Conditions, y = Normalised.cell.count, fill = Conditions)) +
geom_bar(stat = "identity") +
geom_errorbar(aes(ymin = Normalised.cell.count - Standard.Deviation, ymax = Normalised.cell.count + Standard.Deviation), position = position_dodge(width = 0.8), width = 0.25) +
theme(axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title.y = element_text(face = "bold", size = 12),
axis.title.x = element_text(face = "bold", size = 12),
legend.title = element_text(face = "bold", size = 12)) + # Customize legend title
scale_fill_brewer(palette = "Set3") +
labs(y = "Normalised cell counts",
fill = "Conditions") + # Set custom legend title
guides(fill = guide_legend(title.position = "top", title.vjust = 0.5))
Loading in the csv, that contains the RT-qPCR results from plates 1 and 2.
quantification_cq_data <- read_csv("~/Desktop/6BBI0310/Data/Quantification_Cq_Both_plates.csv")
## Rows: 36 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): Gene, Sample, Group
## dbl (2): 2^-AACt, SD
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
quantification_cq_data
## # A tibble: 36 × 5
## Gene Sample `2^-AACt` Group SD
## <chr> <chr> <dbl> <chr> <dbl>
## 1 CIITA M0 1 M1 0
## 2 CIITA IL-4 1.55 M1 0.728
## 3 CIITA HMW-15ng/mL 2.16 M1 1.80
## 4 CIITA HMW-30ng/mL 2.98 M1 1.92
## 5 CIITA LMW-15ng/mL 1.29 M1 0.488
## 6 CIITA LMW-30ng/mL 1.23 M1 0.177
## 7 NOS2 M0 1 M1 0
## 8 NOS2 IL-4 0.46 M1 0.198
## 9 NOS2 HMW-15ng/mL 8.09 M1 10.0
## 10 NOS2 HMW-30ng/mL 9.48 M1 7.04
## # ℹ 26 more rows
Plotting of the graph using the results of the RT-qPCR results, utilising features such as facet_grid to divide the graph by M1 and M2 genes for better visualisation.
quantification_cq_data$Sample <- factor(quantification_cq_data$Sample, levels = c("M0", "IL-4", "HMW-15ng/mL", "HMW-30ng/mL", "LMW-15ng/mL", "LMW-30ng/mL"))
ggplot(quantification_cq_data, aes(fill = Sample, y = `2^-AACt`, x = Gene)) +
geom_bar(position = "dodge", stat = "identity") +
geom_errorbar(aes(ymin = `2^-AACt` - quantification_cq_data$SD, ymax = `2^-AACt` + quantification_cq_data$SD),
position = position_dodge(width = 0.9), width = 0.25) +
facet_grid(. ~ Group, scales = "free_x", space = "free_x", switch = "x") +
coord_cartesian(ylim = c(0, 10)) +
theme_minimal() + # Remove background
theme(
axis.title = element_text(face = "bold")
)
standard_deviation_ARG1 <- c(0 , 1.21834498, 8.35093109, 1.72534055, 0.04949747, 0.6225396)
# Filter data for the specific gene
gene_data <- quantification_cq_data %>% filter(Gene == "ARG1")
# Add error bars to the clustered bar plot
ggplot(gene_data, aes(fill = Sample, y = `2^-AACt`, x = Gene)) +
geom_bar(position = "dodge", stat = "identity") +
geom_errorbar(aes(ymin = `2^-AACt` - standard_deviation_ARG1, ymax = `2^-AACt` + standard_deviation_ARG1),
position = position_dodge(width = 0.9), width = 0.25) +
theme_minimal() +
theme(
axis.title = element_text(face = "bold")
)
Because this graph uses repeated measurements at 3 different time points, a repeated measurement ANOVA would be a fitting statistical analysis.
The results of the repeated measures ANOVA.
The effect of time p value = the p value is greater than 0.05, it suggests that there is not enough evidence to reject the null hypothesis that the means of your groups are equal with respect to time. It indicates that there may not be a statistically significant effect of time on the dependent variable.
A p-value less than 0.05 in the Wilk’s Lambda test suggests that there is evidence to reject the null hypothesis that the group means are equal. This supports the idea that there is a significant effect of time on the dependent variable.
(For the GGe and HFe corrections ) Both corrections are applied when there are violations of the sphericity assumption. If their p-values are greater than 0.05, it indicates that the corrections did not significantly impact the results. In other words, the violation of sphericity may not have substantially affected the overall interpretation.
# First, let me introduce my data from Excel into the environment
data_HA_quantification <- data.frame(
Time = c("Week6", "Week8", "Week10"),
Tim4_in_HA = c(28.9642303, 37.60756024, 67.71211153),
CD163_in_HA = c(49.68265053, 48.50711292, 70.52469463),
CD163_Tim4_in_HA = c(56.02019277, 44.88529963, 57.38168159)
)
# Reshape data for tests
data_HA_quantification_long <- tidyr::pivot_longer(
data_HA_quantification,
cols = c(Tim4_in_HA, CD163_in_HA, CD163_Tim4_in_HA),
names_to = "Cell_Type",
values_to = "Percentage"
)
# Check for normality using Shapiro-Wilk test
shapiro_test <- by(data_HA_quantification_long$Percentage, data_HA_quantification_long$Cell_Type, shapiro.test)
shapiro_test_results <- sapply(shapiro_test, function(x) x$p.value)
print("Shapiro-Wilk Test for Normality:")
## [1] "Shapiro-Wilk Test for Normality:"
print(shapiro_test_results)
## CD163_in_HA CD163_Tim4_in_HA Tim4_in_HA
## 0.09066168 0.18995623 0.40889907
# Reshape the data for repeated-measures ANOVA
library(tidyr)
data_long <- tidyr::pivot_longer(
data_HA_quantification,
cols = c(Tim4_in_HA, CD163_in_HA, CD163_Tim4_in_HA),
names_to = "Cell_Type",
values_to = "Percentage"
)
# Perform repeated-measures ANOVA
library(ez)
ezANOVA(data = data_long, dv = Percentage, wid = Cell_Type, within = Time)
## Warning: Converting "Cell_Type" to factor for ANOVA.
## Warning: Converting "Time" to factor for ANOVA.
## $ANOVA
## Effect DFn DFd F p p<.05 ges
## 2 Time 2 4 5.017297 0.08123071 0.6115266
##
## $`Mauchly's Test for Sphericity`
## Effect W p p<.05
## 2 Time 0.0006078238 0.02465408 *
##
## $`Sphericity Corrections`
## Effect GGe p[GG] p[GG]<.05 HFe p[HF] p[HF]<.05
## 2 Time 0.500152 0.1543972 0.5006082 0.1543011
I will try use an alternative statistical test.
# Create a sample data frame
data_HA_quantification <- data.frame(
Time = rep(c("Week6", "Week8", "Week10"), each = 3),
Cell_Type = rep(c("Tim4_in_HA", "CD163_in_HA", "CD163_Tim4_in_HA"), each = 3),
Percentage = c(28.96, 37.61, 67.71, 49.68, 48.51, 70.52, 56.02, 44.89, 57.38)
)
# Convert Time and Cell_Type to factors
data_HA_quantification$Time <- factor(data_HA_quantification$Time)
data_HA_quantification$Cell_Type <- factor(data_HA_quantification$Cell_Type)
# Fit a linear mixed-effects model
lmm_model <- lmer(Percentage ~ Time * Cell_Type + (1|Time:Cell_Type), data = data_HA_quantification)
## fixed-effect model matrix is rank deficient so dropping 6 columns / coefficients
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## unable to evaluate scaled gradient
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Hessian is numerically singular: parameters are not uniquely determined
# Perform post hoc pairwise comparisons
posthoc_results <- emmeans(lmm_model, pairwise ~ Time:Cell_Type, adjust = "tukey")
## NOTE: A nesting structure was detected in the fitted model:
## Time %in% Cell_Type
# Print the results
summary(posthoc_results)
## $emmeans
## Time Cell_Type emmean SE df lower.CL upper.CL
## Week8 CD163_in_HA 56.2 10.1 13.6 34.4 78.0
## Week10 CD163_Tim4_in_HA 52.8 10.1 13.6 31.0 74.6
## Week6 Tim4_in_HA 44.8 10.1 13.6 23.0 66.6
##
## Degrees-of-freedom method: kenward-roger
## Confidence level used: 0.95
##
## $contrasts
## contrast estimate SE df t.ratio p.value
## Week8 CD163_in_HA - Week10 CD163_Tim4_in_HA 3.47 14.3 13.6 0.242 0.9683
## Week8 CD163_in_HA - Week6 Tim4_in_HA 11.48 14.3 13.6 0.800 0.7092
## Week10 CD163_Tim4_in_HA - Week6 Tim4_in_HA 8.00 14.3 13.6 0.558 0.8442
##
## Degrees-of-freedom method: kenward-roger
## P value adjustment: tukey method for comparing a family of 3 estimates
Use of a Friedman’s test
# Create a data frame
data_test <- data.frame(
Cells = rep(c("Tim4 in HA", "CD163 in HA", "CD163 Tim4 in HA"), each = 3),
Weeks = rep(c("Week6", "Week8", "Week10"), 3),
Percentage = c(28.9642303, 37.60756024, 67.71211153,
49.68265053, 48.50711292, 70.52469463,
56.02019277, 44.88529963, 57.38168159)
)
# Perform Friedman test
result_friedman <- friedman.test(Percentage ~ Weeks | Cells, data = data_test)
# Print the test results
print(result_friedman)
##
## Friedman rank sum test
##
## data: Percentage and Weeks and Cells
## Friedman chi-squared = 4.6667, df = 2, p-value = 0.09697