Comments (1)
I already have both methods implemented, see code snippet below -- it'll be just a matter of refactoring and merging in.
from scipy import stats
from skbio.stats.composition import ilr
from statsmodels.regression.linear_model import OLS
def regression_test(Bxy, Bxyr, iAr):
# Bxy : n x 1
# Bxyr : n x 1
# Bxy : n x r
intr = np.ones((len(Bxy), 1))
Bxy = Bxy.reshape(-1, 1)
Bxyr = Bxyr.reshape(-1, 1)
X = np.hstack((intr, Bxyr, iAr))
Y = Bxy.reshape(-1, 1)
return OLS(Y.ravel(), X)
def proportionality(table, pairs, references):
""" Adapted from `Linear Association in Compositional Data Analysis`
This is the Regression test from 5.2.
Parameters
----------
table : biom.Table
Table of abundances
pairs : list of tuple of str
List of pairs to test
references : list of str
Reference Features
Return
------
tests : list of OLS results
"""
# Extract reference features
Ar = np.vstack([table.data(r, axis='observation') for r in references]).T
Ar[Ar==0] = 0.65
gAr = np.mean(np.log(Ar), axis=1)
lrA = ilr(Ar)
r, s = 2, len(references)
results = []
for i, (x, y) in enumerate(pairs):
print(i)
Ax, Ay = table.data(x, axis='observation'), table.data(y, axis='observation')
idx = np.logical_and(Ax > 0, Ay > 0)
Ax, Ay = np.log(Ax[idx]), np.log(Ay[idx])
n = np.sum(idx)
df = n - 2
# Compute balances
Bxyr = np.sqrt( r * s / (r + s)) * (0.5 * (Ax + Ay) - gAr[idx])
Bxy = Ax - Ay
try:
res = regression_test(Bxy, Bxyr, lrA[idx])
fit = res.fit()
summ = fit.summary()
fval = float(summ.tables[0].data[2][3])
pval = float(summ.tables[0].data[3][3])
results.append((x, y, fval, pval))
except:
continue
return results
from gneiss.
Related Issues (20)
- [Question] How to correctly use ILR with balance tree basis? HOT 5
- Gneiss Maximum Recursion Depth Error
- TODO:
- Getting None/NaN values in columns from `gneiss.composition.ilr_transform` HOT 2
- Sign change in ilr_transform results using new dependencies HOT 3
- pvalues disagree between interactive plot
- numerator cutoff is slightly off in proportion_plot HOT 2
- phyloseq support HOT 1
- Update the pip and bioconda version 0.4.4 to require skbio ≥ 0.5.1 instead of == 0.5.1 HOT 3
- Balance test HOT 1
- Tutorials for proportion plots
- Faster random_linkage method
- Compatiability with xarray
- Renaming clades HOT 1
- BUG: match appears to be broken with biom tables
- Faster hierarchical clustering
- match and match_tips functions are deprecated
- ImportError: cannot import name 'balanceplot' HOT 2
- Numpy 1.24 incompatibility
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gneiss.