Skip to content

Instantly share code, notes, and snippets.

@willtownes
Created March 31, 2018 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willtownes/a0ff36c1fdac563550bb56942ad94ad2 to your computer and use it in GitHub Desktop.
Save willtownes/a0ff36c1fdac563550bb56942ad94ad2 to your computer and use it in GitHub Desktop.
Compositional Data Transformations
#compositional analysis
library(compositions)
x<-c(.1,.5,.4)
V<-t(ilrBase(x))
D<-rbind(c(1,0,-1),c(0,1,-1))
x_alr<-D%*%log(x)
x_ilr<-V%*%log(x)
x_alr
alr(x)
x_ilr
ilr(x,t(V))
#matrix to convert ilr to alr directly
A<-D%*%t(V)
#is A invertible?
det(A) #should be nonzero
x_alr2<-A%*%x_ilr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment