Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to na.rm in decostand methods alr/clr #667

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a28cd54
Added rCLR matrix completion
antagomir Feb 3, 2024
2fa6867
matrix completion documentation
antagomir Feb 12, 2024
a04ca36
Remove testthat as dep
antagomir Feb 20, 2024
f7e44bc
sync
antagomir Jun 30, 2024
17dbf8f
Added na.rm option in clr
antagomir Jun 30, 2024
eed5811
Add unit tests for na.rm option in clr
antagomir Jun 30, 2024
a728925
Add na.rm option in alr and update unit tests
antagomir Jun 30, 2024
55852fa
rclr tunin
antagomir Jun 30, 2024
ba5c70f
Fixed the tests
antagomir Jun 30, 2024
0f635da
removed pkg reference in tests
antagomir Jun 30, 2024
5a4f4f6
Load vegan library in tests
antagomir Jun 30, 2024
a175b3a
Fixed TB comments
antagomir Jul 1, 2024
f55babe
Merge remote-tracking branch 'upstream/master' into nafix
antagomir Nov 16, 2024
dcebf00
Syncing the implementation with Python Gemelli
antagomir Nov 17, 2024
f3f52a2
Exporting OptSpac
antagomir Nov 17, 2024
449955b
unit tests added
antagomir Nov 17, 2024
4a2b84d
Exporting OptSpace in NAMESPACE
antagomir Nov 17, 2024
78daefe
Passing tests and examples
antagomir Nov 17, 2024
f73e773
Adding remarks from PR 619
antagomir Nov 17, 2024
676d71c
adding imputation in rclr
antagomir Nov 21, 2024
dda74fe
no need for na.rm in rclr
antagomir Nov 21, 2024
a4afb55
syncing the parts
antagomir Nov 21, 2024
438f6de
Merge remote-tracking branch 'upstream/master' into nafix
antagomir Nov 21, 2024
10255e3
updates for the documentation
antagomir Nov 21, 2024
d96c92a
Added matrix completion to the OptSpace output
antagomir Nov 22, 2024
14610d9
Merge remote-tracking branch 'upstream/master' into nafix
antagomir Mar 25, 2025
3690207
Fixes feedback in #667
antagomir Mar 25, 2025
2767f6b
test polished
antagomir Mar 25, 2025
8d6c0bb
removed returns
antagomir Apr 2, 2025
10ce904
foo and semicolon fix
antagomir Apr 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
no need for na.rm in rclr
antagomir committed Nov 21, 2024
commit dda74fec93e42b77a27e0429959749f478c18bc2
11 changes: 5 additions & 6 deletions R/decostand.R
Original file line number Diff line number Diff line change
@@ -139,8 +139,8 @@
if (missing(MARGIN))
MARGIN <- 1
if (MARGIN == 1)
x <- .calc_rclr(x, na.rm=na.rm, ...)
else x <- t(.calc_rclr(t(x), na.rm=na.rm, ...))
x <- .calc_rclr(x, ...)
else x <- t(.calc_rclr(t(x), ...))
attr <- attr(x, "parameters")
attr$margin <- MARGIN
})
@@ -192,11 +192,10 @@

# Modified from the original version in mia R package
.calc_rclr <-
function(x, na.rm, ROPT=3, NITER=5, TOL=1e-5, verbose=FALSE, impute=TRUE, ...)
function(x, ROPT=3, NITER=5, TOL=1e-5, verbose=FALSE, impute=TRUE, ...)
{
# Error with negative values
# Always na.rm=TRUE at this step!
if (any(x < 0, na.rm = na.rm)) {
if (any(x < 0)) {
stop("'rclr' cannot be used with negative data", call. = FALSE)
}

@@ -208,7 +207,7 @@

# Calculate log of geometric mean for every sample, ignoring the NAs
# Always na.rm=TRUE at this step!
means <- rowMeans(clog, na.rm = na.rm)
means <- rowMeans(clog, na.rm = TRUE)

# TODO
#if (any(is.na(means))) {
42 changes: 20 additions & 22 deletions man/decostand.Rd
Original file line number Diff line number Diff line change
@@ -113,28 +113,26 @@ decobackstand(x, zap = TRUE)
\item \code{rclr}: robust clr ("rclr") is similar to regular clr
(see above) but it allows data with zeroes. This method can avoid
the use of pseudocounts, unlike the standard clr. The robust clr
(rclr) divides the values by geometric mean of the observed
features within each sample and then performs matrix completion
for the zero entries. In high dimensional data the geometric mean
of rclr approximates the true geometric mean; see e.g. Martino et
al. (2019). The \code{rclr} transformation is defined formally as
follows: \deqn{rclr = log\frac{x}{g(x > 0)}}{% rclr = log(x/g(x >
0))} where \eqn{x} is a single value, and \eqn{g(x > 0)} is the
geometric mean of sample-wide values \eqn{x} that are positive (>
0). The OptSpace algorithm is then used for matrix completion of
the missing values that result from log transformation of the
zero entries in the original input data. The vegan implementation
was adapted from the original implementation
ROptSpace::OptSpace (version 0.2.3) following Keshavan et
al. (2010). The na.rm argument is required; this determines
whether the transformation will include the matrix completion
step for the 0/NA entries (na.rm=TRUE). The following parameters
can be passed to OptSpace through decostand: "ROPT" NA to guess
the rank, or a positive integer as a pre-defined rank (default:
3); "NITER" maximum number of iterations allowed (default: 5);
"TOL" stopping criterion for reconstruction in Frobenius norm
(default: 1e-5); "verbose" a logical value; TRUE to show
progress, FALSE otherwise (default: FALSE).
(rclr) the logarithmizes the data and divides it by the geometric
mean of the observed features within each sample. In high
dimensional data the geometric mean of rclr approximates the true
geometric mean; see e.g. Martino et al. (2019). The \code{rclr}
transformation is defined formally as follows: \deqn{rclr =
log\frac{x}{g(x > 0)}}{% rclr = log(x/g(x > 0))} where \eqn{x} is
a single value, and \eqn{g(x > 0)} is the geometric mean of
sample-wide values \eqn{x} that are positive (> 0). The OptSpace
algorithm is used for matrix completion of the missing values
that result from log transformation of the zero entries in the
original input data (this can be switched off with
impute=FALSE). The vegan implementation of the matrix completion
was adapted from the original implementation ROptSpace::OptSpace
(version 0.2.3) following Keshavan et al. (2010). The following
parameters can be passed to OptSpace through decostand: "ROPT" NA
to guess the rank, or a positive integer as a pre-defined rank
(default: 3); "NITER" maximum number of iterations allowed
(default: 5); "TOL" stopping criterion for reconstruction in
Frobenius norm (default: 1e-5); "verbose" a logical value; TRUE
to show progress, FALSE otherwise (default: FALSE).

}