From e82f7b9fee136b65c6e4f5d5b3f93861ec57ebc9 Mon Sep 17 00:00:00 2001 From: HeleneBlt Date: Thu, 1 Aug 2024 14:54:14 +0200 Subject: [PATCH] na.rm for EMwmean --- R/biomod2_classes_5.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/R/biomod2_classes_5.R b/R/biomod2_classes_5.R index 69327f56..bfee74fb 100644 --- a/R/biomod2_classes_5.R +++ b/R/biomod2_classes_5.R @@ -691,10 +691,11 @@ setMethod('predict2', signature(object = 'EMwmean_biomod2_model', newdata = "dat if (ncol(newdata) < 1) { stop("Model EMwmean was not computed because no single model was kept in ensemble modeling") } - predfun <- function(newdata, on_0_1000, penalization_scores, ...){ - out <- as.vector( - as.matrix(newdata) %*% penalization_scores - ) + predfun <- function(newdata, on_0_1000, penalization_scores, na.rm, ...){ + # out <- as.vector( + # as.matrix(newdata) %*% penalization_scores + # ) + out <- as.vector(rowSums(t(apply(as.matrix(newdata), 1, function(x) penalization_scores*x)), na.rm = na.rm)) if (on_0_1000) { out <- round(out) }