library(tidyverse)
library(ggbeeswarm)
library(plotrix)
library(car)
library(rstatix)
library(SimComp)
library(readxl)
library(dplyr)
library(ggsci)
dataset_exp_2_bm_imprint <- read_excel (path = "/mnt/c/Users/Toshiya Matsushima/OneDrive/R projects/BM_project/data analysis using Rstudio/BM_project_dataset.xlsx", sheet = "exp_2_3_bm_imprint")
dataset_exp_2_bm_imprint_ctrl_imi <- filter(dataset_exp_2_bm_imprint, drug == "00_ctrl"| drug == "07_imi")
dataset_exp_2_bm_imprint_imi <- filter(dataset_exp_2_bm_imprint, drug == "07_imi")
dataset_exp_2_bm_imprint_imi_1 <- filter(dataset_exp_2_bm_imprint, label == "07_imi_1")
dataset_exp_2_bm_imprint_imi_2 <- filter(dataset_exp_2_bm_imprint, label == "07_imi_2")
dataset_exp_2_bm_imprint_imi_3 <- filter(dataset_exp_2_bm_imprint, label == "07_imi_3")
dataset_exp_2_bm_imprint_imi_4 <- filter(dataset_exp_2_bm_imprint, label == "07_imi_4")
dataset_exp_2_bm_imprint_ctrl_imi
dataset_exp_2_bm_imprint_imi
dataset_exp_2_bm_imprint_imi_1
dataset_exp_2_bm_imprint_imi_2
dataset_exp_2_bm_imprint_imi_3
dataset_exp_2_bm_imprint_imi_4
dataset_exp_2_bm_imprint_imi %>%
group_by (label) %>%
get_summary_stats(bm)
fig <- ggplot(dataset_exp_2_bm_imprint_imi, mapping = aes(x=label, y=bm))+
geom_hline(yintercept = 0, linetype="dotted")+
geom_hline(yintercept=136.3089, linetype = "solid", color ="blue", size = 1)+ #average of the control data
geom_hline(yintercept=38.65567, linetype = "solid", color ="darkred", size = 1)+ #5% level below the control average
geom_hline(yintercept=-5.85836, linetype = "solid", color ="red", size = 1)+ #1% level below the control average
geom_boxplot()+
geom_quasirandom(shape=16, size=3, colour="black")+
ylim(-400, 600)+
theme_classic()
fig
ggsave(plot=fig, filename = "exp_3_imi_bm.png", dpi=300, height=10, width=7, units="cm")
fit_exp_3_bm <- lm (bm ~ label, data = dataset_exp_2_bm_imprint_ctrl_imi)
summary (fit_exp_3_bm)
Call:
lm(formula = bm ~ label, data = dataset_exp_2_bm_imprint_ctrl_imi)
Residuals:
Min 1Q Median 3Q Max
-434.31 -136.31 4.69 122.10 402.69
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 136.31 15.34 8.884 7.85e-16 ***
label07_imi_1 -46.90 44.03 -1.065 0.28829
label07_imi_2 -128.62 41.94 -3.067 0.00251 **
label07_imi_3 -132.81 55.95 -2.374 0.01871 *
label07_imi_4 -155.71 55.95 -2.783 0.00598 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 170.2 on 174 degrees of freedom
Multiple R-squared: 0.1002, Adjusted R-squared: 0.0795
F-statistic: 4.843 on 4 and 174 DF, p-value: 0.0009977
car::Anova(fit_exp_3_bm)
Anova Table (Type II tests)
Response: bm
Sum Sq Df F value Pr(>F)
label 560892 4 4.843 0.0009977 ***
Residuals 5037911 174
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
dataset_exp_2_bm_imprint_ctrl_imi %>%
group_by(label) %>%
get_summary_stats(imprint)
fig <- ggplot(dataset_exp_2_bm_imprint_imi, mapping = aes(x=label, y=imprint))+
geom_hline(yintercept = 0, linetype="dotted")+
geom_hline(yintercept=419.5203, linetype = "solid", color ="blue", size = 1)+ #average of the control data
geom_hline(yintercept=284.19273, linetype = "solid", color ="darkred", size = 1)+ #5% level below the control average
geom_hline(yintercept=217.9088, linetype = "solid", color ="red", size = 1)+ #1% level below the control average
geom_boxplot()+
geom_quasirandom(shape=16, size=3, colour="black")+
ylim(-400, 600)+
theme_classic()
fig
Warning: Removed 1 rows containing non-finite values (stat_boxplot).
Warning: Removed 1 rows containing missing values (position_quasirandom).
ggsave(plot=fig, filename = "exp_3_imi_imprint.png", dpi=300, height=10, width=7, units="cm")
Warning: Removed 1 rows containing non-finite values (stat_boxplot).
Warning: Removed 1 rows containing missing values (position_quasirandom).
fit_exp_3_imprint <- lm (imprint ~ label, data = dataset_exp_2_bm_imprint_ctrl_imi)
summary (fit_exp_3_imprint)
Call:
lm(formula = imprint ~ label, data = dataset_exp_2_bm_imprint_ctrl_imi)
Residuals:
Min 1Q Median 3Q Max
-947.52 -79.52 79.24 157.98 276.00
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 419.52 20.85 20.117 <2e-16 ***
label07_imi_1 18.24 59.84 0.305 0.7608
label07_imi_2 -101.52 57.01 -1.781 0.0767 .
label07_imi_3 -62.62 76.05 -0.823 0.4114
label07_imi_4 -103.62 76.05 -1.363 0.1748
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 231.3 on 174 degrees of freedom
Multiple R-squared: 0.03001, Adjusted R-squared: 0.007709
F-statistic: 1.346 on 4 and 174 DF, p-value: 0.2549
car::Anova(fit_exp_3_imprint)
Anova Table (Type II tests)
Response: imprint
Sum Sq Df F value Pr(>F)
label 287920 4 1.3457 0.2549
Residuals 9307070 174
#Correlations between BM scores and imprint scores ## x-y plotting of imprint vs BM
fig <- ggplot(data = dataset_exp_2_bm_imprint_imi, mapping = aes(x=bm, y=imprint, colour=label))+
scale_color_nejm()+
geom_point(shape=16, size=3)+
scale_color_manual(values = c("black", "red", "blue", "orange"))+
geom_vline(xintercept=0, linetype = "dotted")+
geom_hline(yintercept=0, linetype = "dotted")+
geom_smooth(method = "lm")+
xlim(-400, 600)+
ylim(-400, 600)+
theme_classic()
Scale for 'colour' is already present. Adding another scale for 'colour', which will replace the existing scale.
fig
`geom_smooth()` using formula 'y ~ x'
Warning: Removed 1 rows containing non-finite values (stat_smooth).
Warning: Removed 1 rows containing missing values (geom_point).
ggsave(plot = fig, filename = "exp_3_imi_imprint_bm.png", dpi = 300, height = 10, width = 13, units = "cm")
`geom_smooth()` using formula 'y ~ x'
Warning: Removed 1 rows containing non-finite values (stat_smooth).
Warning: Removed 1 rows containing missing values (geom_point).
cor_test(dataset_exp_2_bm_imprint_imi_1, bm, imprint, method = "spearman")
cor_test(dataset_exp_2_bm_imprint_imi_2, bm, imprint, method = "spearman")
cor_test(dataset_exp_2_bm_imprint_imi_3, bm, imprint, method = "spearman")
cor_test(dataset_exp_2_bm_imprint_imi_4, bm, imprint, method = "spearman")
sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.3 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
locale:
[1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8 LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8 LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8
[12] LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggsci_2.9 plotrix_3.8-2 ggbeeswarm_0.6.0 readxl_1.3.1 SimComp_3.3 rstatix_0.7.0 car_3.0-12 carData_3.0-5 plotly_4.10.0 forcats_0.5.1 stringr_1.4.0 dplyr_1.0.7 purrr_0.3.4 readr_2.1.1 tidyr_1.1.4
[16] tibble_3.1.6 ggplot2_3.3.5 tidyverse_1.3.1
loaded via a namespace (and not attached):
[1] nlme_3.1-144 fs_1.5.2 lubridate_1.8.0 httr_1.4.2 tools_3.6.3 backports_1.4.1 utf8_1.2.2 R6_2.5.1 vipor_0.4.5 DBI_1.1.1 lazyeval_0.2.2 mgcv_1.8-31
[13] colorspace_2.0-2 withr_2.4.3 tidyselect_1.1.1 compiler_3.6.3 survPresmooth_1.1-11 mratios_1.4.2 cli_3.1.0 rvest_1.0.2 xml2_1.3.3 sandwich_3.0-1 labeling_0.4.2 scales_1.1.1
[25] mvtnorm_1.1-3 digest_0.6.29 rmarkdown_2.11 pkgconfig_2.0.3 htmltools_0.5.2 dbplyr_2.1.1 fastmap_1.1.0 htmlwidgets_1.5.4 rlang_0.4.12 rstudioapi_0.13 jquerylib_0.1.4 generics_0.1.1
[37] farver_2.1.0 zoo_1.8-9 jsonlite_1.7.2 magrittr_2.0.1 Matrix_1.2-18 Rcpp_1.0.7 munsell_0.5.0 fansi_0.5.0 abind_1.4-5 lifecycle_1.0.1 stringi_1.7.6 multcomp_1.4-18
[49] yaml_2.2.1 MASS_7.3-51.5 grid_3.6.3 crayon_1.4.2 lattice_0.20-40 haven_2.4.3 splines_3.6.3 hms_1.1.1 knitr_1.37 pillar_1.6.4 codetools_0.2-16 reprex_2.0.1
[61] glue_1.6.0 evaluate_0.14 data.table_1.14.2 modelr_0.1.8 vctrs_0.3.8 tzdb_0.2.0 cellranger_1.1.0 gtable_0.3.0 assertthat_0.2.1 xfun_0.29 broom_0.7.10 survival_3.1-8
[73] viridisLite_0.4.0 beeswarm_0.4.0 TH.data_1.1-0 ellipsis_0.3.2