Skip to content

Commit

Permalink
z.warning/z.delete small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Japal committed Mar 13, 2024
1 parent 4724a83 commit cf11ec6
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: zCompositions
Type: Package
Title: Treatment of Zeros, Left-Censored and Missing Values in Compositional Data Sets
Version: 1.5.0-2
Date: 2024-03-09
Version: 1.5.0-3
Date: 2024-03-13
Authors@R:
c(person(given = "Javier",
family = "Palarea-Albaladejo",
Expand All @@ -26,7 +26,7 @@ Description: Principled methods for the imputation of zeros, left-censored and m
compositional data sets (Palarea-Albaladejo and Martin-Fernandez (2015) <doi:10.1016/j.chemolab.2015.02.019>).
License: GPL (>= 2)
Repository: CRAN, Github
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Encoding: UTF-8
URL: https://github.com/Japal/zCompositions
BugReports: https://github.com/Japal/zCompositions/issues
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RELEASE HISTORY OF THE "zCompositions" PACKAGE
==============================================

CHANGES IN zCompositions VERSION 1.5.0-2 [2024-03]:
CHANGES IN zCompositions VERSION 1.5.0-3 [2024-03]:
----------------------------------------------------

MODIFICATIONS
Expand Down
7 changes: 4 additions & 3 deletions R/lrDA.R
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,13 @@ lrDA <-
M <- matrix(colMeans(X_alr,na.rm=T),ncol=1)
C <- cov(X_alr,use=ini.cov)}
if (ini.cov == "multRepl"){
X.mr <- multRepl(X,label=NA,dl=dl,frac=frac,imp.missing=imp.missing,closure=closure)
X.mr <- multRepl(X,label=NA,dl=dl,frac=frac,imp.missing=imp.missing,closure=closure,z.warning=z.warning,z.delete=z.delete)
X.mr_alr <- t(apply(X.mr,1,function(x) log(x)-log(x[pos])))[,-pos]
M <- matrix(colMeans(X.mr_alr,na.rm=T),ncol=1)
C <- cov(X.mr_alr)}
if (ini.cov == "lrEM"){
X.em <- lrEM(X,label=NA,dl=dl,ini.cov="multRepl",frac=frac,imp.missing=imp.missing,closure=closure,suppress.print=TRUE)
X.em <- lrEM(X,label=NA,dl=dl,ini.cov="multRepl",frac=frac,imp.missing=imp.missing,closure=closure,suppress.print=TRUE,
z.warning=z.warning,z.delete=z.delete)
X.em_alr <- t(apply(X.em,1,function(x) log(x)-log(x[pos])))[,-pos]
M <- matrix(colMeans(X.em_alr,na.rm=T),ncol=1)
C <- cov(X.em_alr)}
Expand Down Expand Up @@ -265,7 +266,7 @@ lrDA <-
varobs <- which(!is.na(X_alr[i[1],]))
if (length(varobs) == 0){
alt.in <- TRUE
temp <- multRepl(X[i,,drop=FALSE],label=NA,dl=dl[i,,drop=FALSE],frac=frac,imp.missing=imp.missing,closure=closure)
temp <- multRepl(X[i,,drop=FALSE],label=NA,dl=dl[i,,drop=FALSE],frac=frac,imp.missing=imp.missing,closure=closure,z.warning=z.warning,z.delete=z.delete)
Y[i,] <- t(apply(temp,1,function(x) log(x)-log(x[pos])))[,-pos]
if (runs == 1){
alt.pat <- c(alt.pat,npat)
Expand Down
10 changes: 5 additions & 5 deletions R/lrEM.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ lrEM <- function(X,label=NULL,dl=NULL,rob=FALSE,ini.cov=c("complete.obs","multRe
M <- matrix(colMeans(X_alr,na.rm=T),ncol=1)
C <- cov(X_alr,use=ini.cov)}
else {
X.mr <- multRepl(X,label=NA,dl=dl,frac=frac,imp.missing=imp.missing,closure=closure)
X.mr <- multRepl(X,label=NA,dl=dl,frac=frac,imp.missing=imp.missing,closure=closure,z.warning=z.warning,z.delete=z.delete)
if (any(X.mr < 0)) {stop("ini.cov: negative values produced using multRepl (please check out closure argument and multRepl help for advice)")}
X.mr_alr <- t(apply(X.mr,1,function(x) log(x)-log(x[pos])))[,-pos]
M <- matrix(colMeans(X.mr_alr,na.rm=T),ncol=1)
Expand Down Expand Up @@ -252,7 +252,7 @@ lrEM <- function(X,label=NULL,dl=NULL,rob=FALSE,ini.cov=c("complete.obs","multRe
varobs <- which(!is.na(X_alr[i[1],]))
if (length(varobs) == 0){
alt.in <- TRUE
temp <- multRepl(X[i,,drop=FALSE],label=NA,dl=dl[i,,drop=FALSE],frac=frac,imp.missing=imp.missing,closure=closure)
temp <- multRepl(X[i,,drop=FALSE],label=NA,dl=dl[i,,drop=FALSE],frac=frac,imp.missing=imp.missing,closure=closure,z.warning=z.warning,z.delete=z.delete)
Y[i,] <- t(apply(temp,1,function(x) log(x)-log(x[pos])))[,-pos]
if (niters == 1){
alt.pat <- c(alt.pat,npat)
Expand Down Expand Up @@ -303,10 +303,10 @@ lrEM <- function(X,label=NULL,dl=NULL,rob=FALSE,ini.cov=c("complete.obs","multRe

if (ini.cov == "multRepl"){
if (imp.missing == TRUE){
X.mr <- multRepl(X,label=NA,imp.missing=T,closure=closure)
X.mr <- multRepl(X,label=NA,imp.missing=T,closure=closure,z.warning=z.warning,z.delete=z.delete)
if (any(X.mr < 0)) {stop("ini.cov: negative values produced using multRepl (please check out closure argument and multRepl help for advice)")}
}
else {X.mr <- multRepl(X,label=NA,dl=dl,frac=frac,closure=closure)
else {X.mr <- multRepl(X,label=NA,dl=dl,frac=frac,closure=closure,z.warning=z.warning,z.delete=z.delete)
if (any(X.mr < 0)) {stop("ini.cov: negative values produced using multRepl (please check out closure argument and multRepl help for advice)")}
}
}
Expand Down Expand Up @@ -335,7 +335,7 @@ lrEM <- function(X,label=NULL,dl=NULL,rob=FALSE,ini.cov=c("complete.obs","multRe
if (imp.missing==FALSE){
X[misspat==npat,] <- multRepl(X.old[misspat==npat,,drop=FALSE],
label=NA,dl=dl[misspat==npat,,drop=FALSE],
frac=frac,closure=closure)
frac=frac,closure=closure,z.warning=z.warning,z.delete=z.delete)
}
if (imp.missing==TRUE){
stop("Please remove samples with only one observed component (check it out using zPatterns).")
Expand Down
10 changes: 6 additions & 4 deletions R/lrEMplus.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ lrEMplus <- function(X, dl = NULL, rob = FALSE, ini.cov = c("complete.obs", "mul
# Initial lrEM imputation of missing data
X.old <- lrEM(X.old, label = NA, imp.missing = TRUE, ini.cov = ini.cov, rob = rob,
tolerance = tolerance, max.iter = max.iter, rlm.maxit = rlm.maxit,
suppress.print = TRUE, closure = closure)
suppress.print = TRUE, closure = closure, z.warning = z.warning,
z.delete = z.delete)
}

if (sum(is.na(X)) <= sum(X==0,na.rm=T)){
Expand All @@ -118,7 +119,8 @@ lrEMplus <- function(X, dl = NULL, rob = FALSE, ini.cov = c("complete.obs", "mul
# Initial lrEM imputation of zeros
X.old <- lrEM(X.old, label = 0, dl = dl, ini.cov = ini.cov, rob = rob,
tolerance = tolerance, max.iter = max.iter, rlm.maxit = rlm.maxit,
suppress.print = TRUE, closure = closure)
suppress.print = TRUE, closure = closure, z.warning = z.warning,
z.delete = z.delete)
}

# Initial parameter estimates
Expand All @@ -139,11 +141,11 @@ lrEMplus <- function(X, dl = NULL, rob = FALSE, ini.cov = c("complete.obs", "mul
X.old[which(X==0)] <- 0
X.new <- lrEM(X.old, label = 0, dl = dl, ini.cov = ini.cov, rob = rob,
tolerance = tolerance, max.iter = max.iter, rlm.maxit = rlm.maxit, suppress.print = TRUE,
closure = closure)
closure = closure, z.warning = z.warning, z.delete = z.delete)
X.new[is.na(X)] <- NA
X.new <- lrEM(X.new, label = NA, imp.missing = TRUE, ini.cov = ini.cov, rob = rob,
tolerance = tolerance, max.iter = max.iter, rlm.maxit = rlm.maxit, suppress.print = TRUE,
closure = closure)
closure = closure, z.warning = z.warning, z.delete = z.delete)

X.new_alr <- log(X.new)-log(X.new[,D])
X.new_alr <- as.matrix(X.new_alr[,-D])
Expand Down
2 changes: 1 addition & 1 deletion R/multReplus.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ multReplus <- function(X, dl = NULL, frac = 0.65, closure = NULL, z.warning = 0.

## Imputation of zeros ----

X <- multRepl(X,label=0,dl=dl,frac=frac,closure=closure)
X <- multRepl(X,label=0,dl=dl,frac=frac,closure=closure,z.warning=z.warning,z.delete=z.delete)

## Final section ----

Expand Down
4 changes: 2 additions & 2 deletions man/zCompositions-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Following compositional data analysis principles, this package provides simple a
\tabular{ll}{
Package: \tab zCompositions\cr
Type: \tab Package\cr
Version: \tab 1.5.0-2\cr
Date: \tab 2024-03-09\cr
Version: \tab 1.5.0-3\cr
Date: \tab 2024-03-13\cr
License: \tab GPL (>= 2)\cr
}
}
Expand Down

0 comments on commit cf11ec6

Please sign in to comment.