vignettes/Microbiome.Rmd
Microbiome.Rmd
We will be using data from Wagner et al. (2016), which studies the effects of plant age, genotype, and environment on the bacterial microbiome of a perennial herb, Boechera stricta, in the mustard family. The raw data of Wagner et al. (2016) is available on dryad.
I have stored the data into the package and users can load the data from package.
library(DA) f <- system.file('extdata',package='DA') infile <- file.path(f, "microbiome.Rdata") load(infile) # Warning: namespace 'taxa' is not available and has been replaced # by .GlobalEnv when processing object 'obj' micro_abund=as.data.frame(t(obj$data$otu_rarefied[, sample_data$SampleID])) sample_data$Site=factor(sample_data$Site,levels = unique(sample_data$Site))
We first use PCA to analyse the bacterial community from the plants at different sites.
### PCA Microbiome_pc=prcomp(micro_abund,scale. = TRUE) #plot the data projection on the components library(plotly) # Loading required package: ggplot2 # # Attaching package: 'plotly' # The following object is masked from 'package:ggplot2': # # last_plot # The following object is masked from 'package:stats': # # filter # The following object is masked from 'package:graphics': # # layout cols=rainbow(length(unique(sample_data$Site))) p0 <- plot_ly(as.data.frame(Microbiome_pc$x), x =Microbiome_pc$x[,1], y =Microbiome_pc$x[,2], color = sample_data$Site,colors=cols[sample_data$Site],symbol = sample_data$Site,symbols = 1:3L) %>% add_markers() %>% layout(scene = list(xaxis = list(title = 'PC1'), yaxis = list(title = 'PC2'))) p0
Fig.1 PCA plot of bacterial microbiome community at different sites.
DAPC has widely used in ecology and evolution. Using DAPC to display the community structure of bacterial microbiomes is rarely exploited.
library(adegenet) # Loading required package: ade4 # Registered S3 method overwritten by 'spdep': # method from # plot.mst ape # Registered S3 methods overwritten by 'vegan': # method from # plot.rda klaR # predict.rda klaR # print.rda klaR # # /// adegenet 2.1.1 is loaded //////////// # # > overview: '?adegenet' # > tutorials/doc/questions: 'adegenetWeb()' # > bug reports/feature requests: adegenetIssues() sample_data$Site=factor(sample_data$Site,levels = unique(sample_data$Site)) ###DAPC Microbiome_dapc=dapc(micro_abund,grp=sample_data$Site,n.pca=10, n.da=3) #plot the data projection on the components library(plotly) cols=rainbow(length(unique(sample_data$Site))) p1 <- plot_ly(as.data.frame(Microbiome_dapc$ind.coord), x =Microbiome_dapc$ind.coord[,1], y =Microbiome_dapc$ind.coord[,2], color = sample_data$Site,colors=cols[sample_data$Site],symbol = sample_data$Site,symbols = 1:3L) %>% add_markers() %>% layout(scene = list(xaxis = list(title = 'DAPC1'), yaxis = list(title = 'DAPC2'))) p1
Fig.2 DAPC plot of bacterial microbiome community at different sites.
This is an interactive plot that allows you to point the data values and display the value as you wish.
Compared to DAPC, discriminant analysis of kernel principal components (DAKPC) uses the non-liner kernal technique. The kernel principal component analysis is emolyed to incorporate the non-linear relationship between sites and samples in DAKPC. Below is the implementation of DAKPC.
Microbiome_ldakpc=LDAKPC(micro_abund,sample_data$Site,n.pc=10) # Loading required package: kernlab # # Attaching package: 'kernlab' # The following object is masked from 'package:ggplot2': # # alpha cols=rainbow(length(unique(sample_data$Site))) p2 <- plot_ly(as.data.frame(Microbiome_ldakpc$LDs), x =Microbiome_ldakpc$LDs[,1], y =Microbiome_ldakpc$LDs[,2], color = sample_data$Site,colors=cols[sample_data$Site],symbol = sample_data$Site,symbols = 1:3L) %>% add_markers() %>% layout(scene = list(xaxis = list(title = 'LDAKPC1'), yaxis = list(title = 'LDAKPC2'))) p2
Fig.3 LDAKPC plot of bacterial microbiome community at different sites.
LDAKPC has the similar result with DAPC.
As we mentioned in previous example, LFDA can discriminate the multimodal data while LDA can not. LFDA is an upgraded version of LDA preserving within group variance.
Microbiome_lfda=LFDA(micro_abund,sample_data$Site,r=3,tol=1E-3) # Loading required package: lfda # Loading required package: klaR # Loading required package: MASS # # Attaching package: 'MASS' # The following object is masked from 'package:plotly': # # select cols=rainbow(length(unique(sample_data$Site))) p3 <- plot_ly(as.data.frame(Microbiome_lfda$Z), x =Microbiome_lfda$Z[,1], y =Microbiome_lfda$Z[,2], color = sample_data$Site,colors=cols[sample_data$Site],symbol = sample_data$Site,symbols = 1:3L) %>% add_markers() %>% layout(scene = list(xaxis = list(title = 'LFDA1'), yaxis = list(title = 'LFDA2'))) p3
Fig.4 LFDA plot of bacterial microbiome community at different sites.
Replacing LFDA for discriminant analysis on the basis of LDAKPC we will get LFDAKPC, Local (Fisher) Discriminant Analysis of Kernel Principal Components (LFDAKPC). Below is the implementation of LFDAKPC.
Microbiome_lfdakpc=LFDAKPC(micro_abund,sample_data$Site,kernel.name="polydot",kpar = list(degree = 1, scale = 1, offset = 1),n.pc=10,tol=1E-30) # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 1 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 2 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 3 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 4 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 5 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 6 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 7 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 8 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 9 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 10 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 11 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 12 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 13 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 14 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 15 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 16 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 17 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 18 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 19 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 20 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 21 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 22 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 23 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 24 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 25 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 26 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 27 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 28 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 29 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 30 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 31 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 32 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 33 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 34 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 35 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 36 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 37 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 38 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 39 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 40 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 41 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 42 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 43 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 44 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 45 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 46 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 47 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 48 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 49 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 50 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 51 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 52 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 53 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 54 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 55 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 56 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 57 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 58 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 59 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 60 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 61 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 62 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 63 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 64 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 65 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 66 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 67 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 68 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 69 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 70 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 71 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 72 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 73 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 74 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 75 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 76 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 77 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 78 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 79 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 80 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 81 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 82 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 83 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 84 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 85 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 86 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 87 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 88 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 89 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 90 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 91 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 92 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 93 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 94 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 95 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 96 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 97 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 98 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 99 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 100 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 101 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 102 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 103 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 104 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 105 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 106 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 107 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 108 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 109 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 110 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 111 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 112 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 113 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 114 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 115 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 116 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 117 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 118 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 119 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 120 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 121 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 122 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 123 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 124 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 125 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 126 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 127 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 128 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 129 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 130 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 131 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 132 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 133 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 134 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 135 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 136 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 137 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 138 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 139 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 140 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 141 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 142 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 143 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 144 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 145 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 146 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 147 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 148 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 149 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 150 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 151 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 152 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 153 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 154 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 155 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 156 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 157 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 158 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 159 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 160 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 161 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 162 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 163 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 164 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 165 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 166 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 167 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 168 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 169 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 170 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 171 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 172 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 173 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 174 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 175 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 176 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 177 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 178 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 179 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 180 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 181 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 182 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 183 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 184 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 185 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 186 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 187 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 188 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 189 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 190 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 191 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 192 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 193 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 194 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 195 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 196 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 197 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 198 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 199 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 200 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 201 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 202 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 203 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 204 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 205 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 206 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 207 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 208 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 209 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 210 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 211 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 212 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 213 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 214 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 215 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 216 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 217 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 218 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 219 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 220 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 221 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 222 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 223 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 224 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 225 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 226 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 227 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 228 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 229 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 230 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 231 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 232 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 233 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 234 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 235 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 236 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 237 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 238 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 239 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 240 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 241 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 242 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 243 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 244 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 245 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 246 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 247 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 248 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 249 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 250 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 251 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 252 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 253 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 254 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 255 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 256 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 257 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 258 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 259 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 260 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 261 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 262 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 263 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 264 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 265 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 266 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 267 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 268 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 269 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 270 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 271 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 272 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 273 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 274 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 275 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 276 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 277 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 278 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 279 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 280 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 281 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 282 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 283 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 284 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 285 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 286 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 287 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 288 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 289 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 290 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 291 # Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with # observation 292 cols=rainbow(length(unique(sample_data$Site))) p4 <- plot_ly(as.data.frame(Microbiome_lfdakpc$LDs), x =Microbiome_lfdakpc$LDs[,1], y =Microbiome_lfdakpc$LDs[,2], color = sample_data$Site,colors=cols[sample_data$Site],symbol = sample_data$Site,symbols = 1:3L) %>% add_markers() %>% layout(scene = list(xaxis = list(title = 'LFDAKPC1'), yaxis = list(title = 'LFDAKPC2'))) p4
Fig.5 LFDAKPC plot of bacterial microbiome community at different sites.
The LFDAKPC also produces the similar results as LDAKPC and DAPC.
Kernel local (Fisher) discriminant analysis (KLFDA) capatures the non-linear relationships between samples and also considers the within group multimodality.
### Note the kernel matrix used here is from kernelab library, while the kernel techniques in kernelab is different, it uses inverse kernel distance. Microbiome_klfda=klfda_1(as.matrix(micro_abund),as.matrix(sample_data$Site),kernel=kernlab::rbfdot(sigma = 0.00001),r=3,tol=1E-90,prior = NULL) # Loading required package: WMDB cols=rainbow(length(unique(sample_data$Site))) p5 <- plot_ly(as.data.frame(Microbiome_klfda$Z), x =Microbiome_klfda$Z[,1], y =Microbiome_klfda$Z[,2], color = sample_data$Site,colors=cols[sample_data$Site],symbol = sample_data$Site,symbols = 1:3L) %>% add_markers() %>% layout(scene = list(xaxis = list(title = 'LDA1'), yaxis = list(title = 'LDA2'))) p5
Fig.6 KLFDA plot of bacterial microbiome community at different sites.
KLFDA clearly presents the bacterial aggregates between different sites.
All the above methods show the same global structure for bacterial microbiome community at different sites. But LFDA and KLFDA do a better job in discriminating the communities.
Kernel local (Fisher) discriminant analysis (KLFDA) does the best for analysis of community structurte. Now, we plot the Microbiome individual membership representing the posterior possibilities of species as the community structure.
library(adegenet) ## asignment plot compoplot(as.matrix(Microbiome_klfda$bayes_assigment$posterior),show.lab = TRUE, posi=list(x=5,y=-0.01),txt.leg = unique(sample_data$Site))
Fig. 7 The community structure of bacterial microbiome community at different sites (individual assignment)
Laloë, D., Jombart, T., Dufour, A.-B. & Moazami-Goudarzi, K. (2007). Consensus genetic structuring and typological value of markers using multiple co-inertia analysis. Genetics Selection Evolution, 39, 545.
Jombart, T. (2008). adegenet: a R package for the multivariate analysis of genetic markers. Bioinformatics, 24, 1403-1405. Sugiyama, M (2007).Dimensionality reduction of multimodal labeled data by local Fisher discriminant analysis. Journal of Machine Learning Research, vol.8, 1027-1061.
Sugiyama, M (2006). Local Fisher discriminant analysis for supervised dimensionality reduction. In W. W. Cohen and A. Moore (Eds.), Proceedings of 23rd International Conference on Machine Learning (ICML2006), 905-912.
Original Matlab Implementation: http://www.ms.k.u-tokyo.ac.jp/software.html#LFDA
Tang, Y., & Li, W. (2019). lfda: Local Fisher Discriminant Analysis inR. Journal of Open Source Software, 4(39), 1572.
Moore, A. W. (2004). Naive Bayes Classifiers. In School of Computer Science. Carnegie Mellon University.
Pierre Enel (2020). Kernel Fisher Discriminant Analysis (https://www.github.com/p-enel/MatlabKFDA), GitHub. Retrieved March 30, 2020.
Karatzoglou, A., Smola, A., Hornik, K., & Zeileis, A. (2004). kernlab-an S4 package for kernel methods in R. Journal of statistical software, 11(9), 1-20.
Bingpei Wu, 2012, WMDB 1.0: Discriminant Analysis Methods by Weight Mahalanobis Distance and bayes.
Ito, Y., Srinivasan, C., & Izumi, H. (2006, September). Discriminant analysis by a neural network with Mahalanobis distance. In International Conference on Artificial Neural Networks (pp. 350-360). Springer, Berlin, Heidelberg.
Wölfel, M., & Ekenel, H. K. (2005, September). Feature weighted Mahalanobis distance: improved robustness for Gaussian classifiers. In 2005 13th European signal processing conference (pp. 1-4). IEEE.
Wagner, Maggie R, Derek S Lundberg, G Tijana, Susannah G Tringe, Jeffery L Dangl, and Thomas Mitchell-Olds. 2016. “Host Genotype and Age Shape the Leaf and Root Microbiomes of a Wild Perennial Plant.” Nature Communications 7. Nature Publishing Group: 12151. doi:10.1038/ncomms12151.