You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I already have both methods implemented, see code snippet below -- it'll be just a matter of refactoring and merging in.
fromscipyimportstatsfromskbio.stats.compositionimportilrfromstatsmodels.regression.linear_modelimportOLSdefregression_test(Bxy, Bxyr, iAr):
# Bxy : n x 1# Bxyr : n x 1# Bxy : n x rintr=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)
returnOLS(Y.ravel(), X)
defproportionality(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 featuresAr=np.vstack([table.data(r, axis='observation') forrinreferences]).TAr[Ar==0] =0.65gAr=np.mean(np.log(Ar), axis=1)
lrA=ilr(Ar)
r, s=2, len(references)
results= []
fori, (x, y) inenumerate(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-Aytry:
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:
continuereturnresults
We will want to add some support for proportionality
The text was updated successfully, but these errors were encountered: