Discriminant Analysis for Evolutionary Inference

Discriminant Analysis (DA) for evolutionary inference (Qin, X. et al, 2020, ), especially for population genetic structure and community structure inference. This package incorporates the commonly used linear and non-linear, local and global supervised learning approaches (discriminant analysis), including Linear Discriminant Analysis of Kernel Principal Components (LDAKPC), Local (Fisher) Linear Discriminant Analysis (LFDA), Local (Fisher) Discriminant Analysis of Kernel Principal Components (LFDAKPC) and Kernel Local (Fisher) Discriminant Analysis (KLFDA). These discriminant analyses can be used to do ecological and evolutionary inference, including demography inference, species identification, and population/community structure inference.


DA: Discriminant analysis

For a more detailed tutorial on population structure and community structure inference please visit: https://xinghuq.github.io/DA/

DAPC, DAKPC, LFDA, LFDAKPC, KLFDA

This package implements five supervised learning approaches that are suitable for ecological and evolutionary inference both visually and statistically. Five approaches in our vignette: Linear discriminant analysis of principal components (DAPC), linear discriminant analysis of kernel principal components (DAKPC), local (Fisher) linear discriminant analysis (LFDA), local (Fisher) discriminant analysis of kernel principal components (LFDAKPC) and kernel local (Fisher) linear discriminant analysis (KLFDA).

Welcome any feedback and pull request.

Install the package from github:

library(devtools)

install_github("xinghuq/DA")

library("DA")

Basic examples using the irish data

x <- iris[,-5] # this matrix contains all the predictors to be transformed
y <- iris[,5] # this should be a vector that represents different classes

Discriminant analysis of principal components (DAPC)

library(adegenet)
iris_dapc=dapc(iris[,-5],grp=iris[,5],n.pca=3, n.da=3)

#plot the data projection on the components
library(plotly)
   cols=rainbow(length(unique(iris[,5])))
   p1 <- plot_ly(as.data.frame(iris_dapc$ind.coord), x =iris_dapc$ind.coord[,1], y =iris_dapc$ind.coord[,2], color = iris[,5],colors=cols[iris[,5]],symbol = iris[,5],symbols = 1:3L) %>% 
     add_markers() %>%
     layout(scene = list(xaxis = list(title = 'LDA1'),
                         yaxis = list(title = 'LDA2')))
p1

Discriminant analysis of kernel principal components (DAKPC)

iris_ldakpc=LDAKPC(iris[,-5],y=iris[,5],n.pc=3)

 p2 <- plot_ly(as.data.frame(iris_ldakpc$LDs), x =iris_ldakpc$LDs[,1], y =iris_ldakpc$LDs[,2], color = iris[,5],colors=cols[iris[,5]],symbol = iris[,5],symbols = 1:3L) %>% 
     add_markers() %>%
     layout(scene = list(xaxis = list(title = 'LDA1'),
                         yaxis = list(title = 'LDA2')))
p2

Local Fisher Discriminant Analysis(LFDA)

iris_lfda=LFDA(iris[,-5],y=iris[,5],r=3,tol=1)

 p3 <- plot_ly(as.data.frame(iris_lfda$Z), x =iris_lfda$Z[,1], y =iris_lfda$Z[,2], color = iris[,5],colors=cols[iris[,5]],symbol = iris[,5],symbols = 1:3L) %>% 
     add_markers() %>%
     layout(scene = list(xaxis = list(title = 'LDA1'),
                         yaxis = list(title = 'LDA2')))
p3

Local (fisher) discriminant analysis of kernel principal components (LFDAKPC)

iris_lfdakpc=LFDAKPC(iris[,-5],y=iris[,5],n.pc=3,tol=1)

 p4 <- plot_ly(as.data.frame(iris_lfdakpc$$LFDAKPC$Z), x =iris_lfdakpc$$LFDAKPC$Z[,1], y =iris_lfdakpc$$LFDAKPC$Z[,2], color = iris[,5],colors=cols[iris[,5]],symbol = iris[,5],symbols = 1:3L) %>% 
     add_markers() %>%
     layout(scene = list(xaxis = list(title = 'LDA1'),
                         yaxis = list(title = 'LDA2')))
p4

Kernel Local Fisher Discriminant Analysis(KLFDA)

The default kernel is polydot(degree = 1, scale = 1, offset = 1). Users can set the kernel based on their own purpose.

iris_klfda=KLFDA(as.matrix(iris[,-5]),as.matrix(iris[,5]),r=3,tol=1E-10,prior = NULL)


p5 <- plot_ly(as.data.frame(iris_klfda$Z), x =iris_klfda$Z[,1], y =iris_klfda$Z[,2], color = iris[,5],colors=cols[iris[,5]],symbol = iris[,5],symbols = 1:3L) %>% 
     add_markers() %>%
     layout(scene = list(xaxis = list(title = 'LDA1'),
                         yaxis = list(title = 'LDA2')))
p5

Note we did not show the discrimination results,users can look into the discriminated classes and their posterior possibility from the results.

Citation

Qin. X, Wu. M, Lock, T. R, Kallenbach, R. 2020. DA: Ecological and evolutionary inference using machine learning approaches both visually and statistically. R package version 1.2.0.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("DA")

1.2.0 by Xinghu Qin, 5 years ago


https://xinghuq.github.io/DA/index.html


Report a bug at https://github.com/xinghuq/DA/issues


Browse source code at https://github.com/cran/DA


Authors: Xinghu Qin [aut, cre, cph]


Documentation:   PDF Manual  


GPL-3 license


Imports adegenet, lfda, MASS, kernlab, klaR, plotly, rARPACK, grDevices, stats, utils

Suggests knitr, testthat, rmarkdown

System requirements: GNU make


See at CRAN