@@ -245,7 +245,19 @@ setMethod(f="model_apply",
245
245
out = lapply(D2 $ data ,function (x ) {
246
246
y1 = x [D2 $ sample_meta [[M $ factor_name ]]== L [A ]]
247
247
y2 = x [D2 $ sample_meta [[M $ factor_name ]]== L [B ]]
248
- val = ci_delta_nu(na.omit(y1 ),na.omit(y2 ),alpha = 1 - M $ conf_level ,paired = M $ paired )
248
+
249
+ if (M $ paired ) {
250
+ # if one of pair is NA, set both to NA
251
+ y1 [is.na(y2 )]= NA
252
+ y2 [is.na(y1 )]= NA
253
+ }
254
+
255
+ if (all(is.na(y1 )) | all(is.na(y2 ))) {
256
+ val = rep(NA ,3 ) # report NA if a group is missing
257
+ } else {
258
+ val = ci_delta_nu(y1 ,y2 ,alpha = 1 - M $ conf_level ,paired = M $ paired )
259
+ }
260
+
249
261
val = matrix (val ,nrow = 1 ,ncol = 3 )
250
262
colnames(val )= c(' median' ,' lci' ,' uci' )
251
263
return (val )
@@ -284,9 +296,22 @@ setMethod(f="model_apply",
284
296
285
297
# calculate means and confidence intervals for all features
286
298
out = lapply(D2 $ data ,function (x ) {
299
+
287
300
y1 = x [D2 $ sample_meta [[M $ factor_name ]]== L [A ]]
288
301
y2 = x [D2 $ sample_meta [[M $ factor_name ]]== L [B ]]
289
- ret = ci.mean.paired(1 - M $ conf_level ,y1 ,y2 )
302
+
303
+ if (M $ paired ) {
304
+ # if one of pair is NA, set both to NA
305
+ y1 [is.na(y2 )]= NA
306
+ y2 [is.na(y1 )]= NA
307
+ }
308
+
309
+ if (all(is.na(y1 )) | all(is.na(y2 ))) {
310
+ ret = matrix (NA ,nrow = 1 ,ncol = 3 ) # report NA if a group is missing
311
+ colnames(ret )= c(' fold_change' ,' lower_ci' ,' upper_ci' )
312
+ } else {
313
+ ret = ci.mean.paired(1 - M $ conf_level ,y1 ,y2 )
314
+ }
290
315
return (ret )
291
316
})
292
317
@@ -296,7 +321,13 @@ setMethod(f="model_apply",
296
321
out = lapply(D2 $ data ,function (x ) {
297
322
y1 = x [D2 $ sample_meta [[M $ factor_name ]]== L [A ]]
298
323
y2 = x [D2 $ sample_meta [[M $ factor_name ]]== L [B ]]
299
- ret = ci.mean.bs(1 - M $ conf_level ,na.omit(y1 ),na.omit(y2 ))
324
+
325
+ if (all(is.na(y1 )) | all(is.na(y2 ))) {
326
+ ret = matrix (NA ,nrow = 1 ,ncol = 8 ) # report NA if a group is missing
327
+ colnames(ret )= c(" Mean1" , " Mean2" , " df" , " Mean1/Mean2" , " LL" , " UL" , " Log-ratio" , " SE" )
328
+ } else {
329
+ ret = ci.mean.bs(1 - M $ conf_level ,na.exclude(y1 ),na.exclude(y2 ))
330
+ }
300
331
return (ret )
301
332
})
302
333
@@ -472,7 +503,7 @@ ci_delta_nu = function(y1,y2,alpha=0.05,paired=FALSE) {
472
503
return (out )
473
504
} else {
474
505
if (length(y1 ) != length(y2 )) {
475
- stop(' all samples must be present in all groups for a paired comparison' )
506
+ stop(' the same number of samples must be present in all groups for a paired comparison' )
476
507
}
477
508
r = y1 / y2
478
509
mr = mean(r )
0 commit comments