<jupyter_start><jupyter_text>This notebook is to perform permanova tests on unweighted UniFrac<jupyter_code>library(vegan)
distance = read.table(file='../data/57316-unweighted_unifrac_distance/distance-matrix.tsv',
                      sep='\t', header=TRUE, row.names=1)
distance <- distance[ , order(colnames(distance))]
distance <- distance[ order(rownames(distance)), ]
distance[] <- lapply(distance, as.numeric)
dim(distance)
head(distance)
mf = read.csv('../data/mros_mapping_alpha.txt', sep='\t')
colnames(mf)[1] = 'SampleName'
dim(mf)
head(mf)
summary(mf)<jupyter_output><empty_output><jupyter_text>categorical variables<jupyter_code># GIERACE
set.seed(3120)
(GIERACE = adonis(distance ~ GIERACE, data=mf))
(GIERACE.pval = GIERACE$aov.tab$P[1])
# SITE
set.seed(3120)
(SITE = adonis(distance ~ SITE, data=mf))
(SITE.pval = SITE$aov.tab$P[1])
# TUDRAMT
set.seed(3120)
(TUDRAMT = adonis(distance ~ TUDRAMT, data=mf))
(TUDRAMT.pval = TUDRAMT$aov.tab$P[1])
# TURSMOKE
set.seed(3120)
(TURSMOKE = adonis(distance ~ TURSMOKE, data=mf))
(TURSMOKE.pval = TURSMOKE$aov.tab$P[1])
# M1ADEPR
set.seed(3120)
(M1ADEPR = adonis(distance ~ M1ADEPR, data=mf))
(M1ADEPR.pval = M1ADEPR$aov.tab$P[1])
# M1VITMND
set.seed(3120)
(M1VITMND = adonis(distance ~ M1VITMND, data=mf))
(M1VITMND.pval = M1VITMND$aov.tab$P[1])
# M1ANTIB
set.seed(3120)
(M1ANTIB = adonis(distance ~ M1ANTIB, data=mf))
(M1ANTIB.pval = M1ANTIB$aov.tab$P[1])
# M1PROBI
set.seed(3120)
(M1PROBI = adonis(distance ~ M1PROBI, data=mf))
(M1PROBI.pval = M1PROBI$aov.tab$P[1])
# OHSEAS
set.seed(3120)
(OHSEAS = adonis(distance ~ OHSEAS, data=mf))
(OHSEAS.pval = OHSEAS$aov.tab$P[1])
# QLCOMP
set.seed(3120)
(QLCOMP = adonis(distance ~ QLCOMP, data=mf))
(QLCOMP.pval = QLCOMP$aov.tab$P[1])
# VDstatus
set.seed(3120)
(VDstatus = adonis(distance ~ VDstatus, data=mf))
(VDstatus.pval = VDstatus$aov.tab$P[1])
# M1STATIN
set.seed(3120)
(M1STATIN = adonis(distance ~ M1STATIN, data=mf))
(M1STATIN.pval = M1STATIN$aov.tab$P[1])
# Antihistamine
set.seed(3120)
(Antihistamine = adonis(distance ~ Antihistamine, data=mf))
(Antihistamine.pval = Antihistamine$aov.tab$P[1])
# Laxative
set.seed(3120)
(Laxative = adonis(distance ~ Laxative, data=mf))
(Laxative.pval = Laxative$aov.tab$P[1])
# M1PPUMP
set.seed(3120)
(M1PPUMP = adonis(distance ~ M1PPUMP, data=mf))
(M1PPUMP.pval = M1PPUMP$aov.tab$P[1])<jupyter_output><empty_output><jupyter_text>Continuous variables<jupyter_code># Age
set.seed(3120)
(Age = adonis(distance ~ Age, data=mf))
(Age.pval = Age$aov.tab$P[1])
# BMI
set.seed(3120)
(BMI = adonis(distance ~ BMI, data=mf))
(BMI.pval = BMI$aov.tab$P[1])
# PASCORE
set.seed(3120)
(PASCORE = adonis(distance ~ PASCORE, data=mf))
(PASCORE.pval = PASCORE$aov.tab$P[1])
# Rstarch_total
set.seed(3120)
ind_Rstarch_total <- which(is.na(mf$Rstarch_total))
dist_Rstarch_total <- distance[-ind_Rstarch_total, ]
dist_Rstarch_total <- dist_Rstarch_total[, -ind_Rstarch_total]
mf_Rstarch_total <- mf[!is.na(mf$Rstarch_total), ]
(Rstarch_total  <- adonis(dist_Rstarch_total~Rstarch_total, data = mf_Rstarch_total))
(Rstarch_total.pval = Rstarch_total$aov.tab$P[1])
# OHV1D3
set.seed(3120)
ind_OHV1D3 <- which(is.na(mf$OHV1D3))
dist_OHV1D3 <- distance[-ind_OHV1D3, ]
dist_OHV1D3 <- dist_OHV1D3[, -ind_OHV1D3]
mf_OHV1D3 <- mf[!is.na(mf$OHV1D3), ]
(OHV1D3  <- adonis(dist_OHV1D3~OHV1D3, data = mf_OHV1D3))
(OHV1D3.pval = OHV1D3$aov.tab$P[1])
# OHVD3
set.seed(3120)
ind_OHVD3 <- which(is.na(mf$OHVD3))
dist_OHVD3 <- distance[-ind_OHVD3, ]
dist_OHVD3 <- dist_OHVD3[, -ind_OHVD3]
mf_OHVD3 <- mf[!is.na(mf$OHVD3), ]
(OHVD3  <- adonis(dist_OHVD3~OHVD3, data = mf_OHVD3))
(OHVD3.pval = OHVD3$aov.tab$P[1])
# OHV24D3
set.seed(3120)
ind_OHV24D3 <- which(is.na(mf$OHV24D3))
dist_OHV24D3 <- distance[-ind_OHV24D3, ]
dist_OHV24D3 <- dist_OHV24D3[, -ind_OHV24D3]
mf_OHV24D3 <- mf[!is.na(mf$OHV24D3), ]
(OHV24D3  <- adonis(dist_OHV24D3~OHV24D3, data = mf_OHV24D3))
(OHV24D3.pval = OHV24D3$aov.tab$P[1])
# ratio_activation
set.seed(3120)
ind_ratio_activation <- which(is.na(mf$ratio_activation))
dist_ratio_activation <- distance[-ind_ratio_activation, ]
dist_ratio_activation <- dist_ratio_activation[, -ind_ratio_activation]
mf_ratio_activation <- mf[!is.na(mf$ratio_activation), ]
(ratio_activation  <- adonis(dist_ratio_activation~ratio_activation, data = mf_ratio_activation))
(ratio_activation.pval = ratio_activation$aov.tab$P[1])
# ratio_catabolism
set.seed(3120)
ind_ratio_catabolism <- which(is.na(mf$ratio_catabolism))
dist_ratio_catabolism <- distance[-ind_ratio_catabolism, ]
dist_ratio_catabolism <- dist_ratio_catabolism[, -ind_ratio_catabolism]
mf_ratio_catabolism <- mf[!is.na(mf$ratio_catabolism), ]
(ratio_catabolism  <- adonis(dist_ratio_catabolism~ratio_catabolism, data = mf_ratio_catabolism))
(ratio_catabolism.pval = ratio_catabolism$aov.tab$P[1])<jupyter_output><empty_output><jupyter_text>output results<jupyter_code>name <- c('GIERACE', 'SITE', 'TUDRAMT', 'TURSMOKE', 'M1ADEPR', 'M1VITMND', 'M1ANTIB', 'M1PROBI',
          'OHSEAS','QLCOMP','VDstatus','M1STATIN','Antihistamine','Laxative','M1PPUMP',
          'Age','BMI','PASCORE', 'Rstarch_total', 'OHV1D3','OHVD3','OHV24D3','ratio_activation','ratio_catabolism')

pval <- c(GIERACE.pval, SITE.pval, TUDRAMT.pval, TURSMOKE.pval, M1ADEPR.pval, M1VITMND.pval, M1ANTIB.pval,
          M1PROBI.pval, OHSEAS.pval, QLCOMP.pval, VDstatus.pval, M1STATIN.pval, Antihistamine.pval, Laxative.pval, M1PPUMP.pval,
          Age.pval, BMI.pval, PASCORE.pval, Rstarch_total.pval, OHV1D3.pval, OHVD3.pval, OHV24D3.pval, ratio_activation.pval, ratio_catabolism.pval)
d <- cbind(name, pval)
d <-data.frame(name, pval, stringsAsFactors = F)

d <- cbind(d, round(p.adjust(d$pval, "BH"), 4))
colnames(d)[3] <- "qval"
d[order(d$qval), ]
table(mf$TUDRAMT)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1704900938477581, 'fraction_numerical': 0.048488008342022944, 'mean_word_length': 6.862021857923497, 'pattern_counts': {'":': 0, '<': 56, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '164559', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2946, 'n_tokens_neox': 2693, 'n_words': 337, 'path': '3.2 Beta Diversity (UW) -- PERMANOVA (R).ipynb', 'repo_name': 'knightlab-analyses/vitamin-d', 'size': '5754'}