Skip to content

Commit b8ece21

Browse files
committed
improve fold change computations
- simplify computation of flags when applying fc threshold for consistency across methods - better handling of NA when computing intervals for median and mean methods
1 parent 4c94414 commit b8ece21

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: structToolbox
22
Type: Package
33
Title: Data processing & analysis tools for Metabolomics and other omics
4-
Version: 1.13.4
4+
Version: 1.13.5
55
Authors@R: c(
66
person(
77
c("Gavin","Rhys"),

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Changes 1.13.5
2+
+ improve consistency between methods in fold change computations
3+
+ better handling of NA in fold change computations
4+
15
Changes 1.13.4
26
+ fix PLSDA predicted group assignment
37
+ add option to PLSDA to use probability for yhat for predictions

R/fold_change_class.R

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,15 +373,17 @@ setMethod(f="model_apply",
373373
M$fold_change=as.data.frame(2^FC)
374374
M$lower_ci=as.data.frame(2^LCI)
375375
M$upper_ci=as.data.frame(2^UCI)
376-
M$significant=as.data.frame((UCI < (-log2(M$threshold))) | (LCI>log2(M$threshold)))
377376
} else {
378377
M$fold_change = as.data.frame(FC)
379378
M$lower_ci = as.data.frame(LCI)
380379
M$upper_ci = as.data.frame(UCI)
381-
M$significant=as.data.frame((UCI < (-M$threshold)) | (LCI>(M$threshold)))
382380
}
383381

382+
check1 = M$lower_ci > M$threshold
383+
check2 = M$upper_ci < 1/M$threshold
384+
M$significant = data.frame(significant=check1 | check2)
384385
colnames(M$significant)=comp
386+
rownames(M$significant)=colnames(D)
385387
return(M)
386388
}
387389
)
@@ -506,6 +508,7 @@ ci_delta_nu = function(y1,y2,alpha=0.05,paired=FALSE) {
506508
stop('the same number of samples must be present in all groups for a paired comparison')
507509
}
508510
r = y1/y2
511+
r=r[!is.na(r)]
509512
mr=mean(r)
510513
md=median(r)
511514
s=sd(r)/sqrt(length(r)) # standard error of mean
@@ -530,6 +533,9 @@ ci.mean.bs <- function(alpha, y1, y2){
530533
# y2: n2 x 1 vector of scores for group 2
531534
# Returns:
532535
# confidence interval
536+
y1=y1[!is.na(y1)]
537+
y2=y2[!is.na(y2)]
538+
533539
n1 <- length(y1)
534540
n2 <- length(y2)
535541
m1 <- mean(y1)
@@ -551,11 +557,13 @@ ci.mean.bs <- function(alpha, y1, y2){
551557

552558

553559
ci.mean.paired = function(alpha,x,y) {
554-
555560
r = x/y
561+
r=r[!is.na(r)]
562+
556563
mr=mean(r)
557-
s=sd(r)/sqrt(length(x)) # standard error of mean
558-
z=qt(1-(alpha/2),length(x)-1)
564+
565+
s=sd(r)/sqrt(length(r)) # standard error of mean
566+
z=qt(1-(alpha/2),length(r)-1)
559567

560568
out=t(c(mr,mr-(z*s),mr+z*s))
561569
colnames(out)=c('fold_change','lower_ci','upper_ci')
@@ -575,6 +583,8 @@ ci.median.bs <- function(alpha, y1, y2) {
575583
# y2: n2 x 1 vector of scores for group 2
576584
# Returns:
577585
# confidence interval
586+
y1=y1[!is.na(y1)]
587+
y2=y2[!is.na(y2)]
578588
z <- qnorm(1 - alpha/2)
579589
n1 <- length(y1)
580590
y1 <- sort(y1)

0 commit comments

Comments
 (0)