From 58e3342297621c8764a94d6efb7c2190e382f27e Mon Sep 17 00:00:00 2001 From: Johnny Date: Thu, 12 Mar 2026 16:40:39 +0100 Subject: [PATCH 1/4] fix reg equation and optimizer e-notation --- R/doeAnalysis.R | 65 ++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/R/doeAnalysis.R b/R/doeAnalysis.R index 06201c9a..258c2ed3 100644 --- a/R/doeAnalysis.R +++ b/R/doeAnalysis.R @@ -604,27 +604,28 @@ doeAnalysis <- function(jaspResults, dataset, options, ...) { } # Uncoded Formula - + fmtCoef <- formatC(abs(coefs[-1, 1]), digits = .numDecimals, format = "g") coefFormula <- paste(ifelse(sign(coefs[-1,1])==1, " +", " \u2013"), - round(abs(coefs[-1,1]), .numDecimals), + fmtCoef, coefNames[-1], collapse = "", sep = " ") # Now add dependent name and intercept filledFormula <- paste0(dep, " = ", - round(coefs[1, 1], .numDecimals), + formatC(coefs[1, 1], digits = .numDecimals, format = "g"), coefFormula) # Coded Formula + fmtCoefCoded <- formatC(abs(coefsCoded[-1, 1]), digits = .numDecimals, format = "g") coefFormulaCoded <- paste(ifelse(sign(coefsCoded[-1,1])==1, " +", " \u2013"), - round(abs(coefsCoded[-1,1]), .numDecimals), - coefNames[-1], - collapse = "", sep = " ") + fmtCoefCoded, + coefNames[-1], + collapse = "", sep = " ") filledFormulaCoded <- paste0(dep, " = ", - round(coefsCoded[1, 1], .numDecimals), - coefFormulaCoded) + formatC(coefsCoded[1, 1], digits = .numDecimals, format = "g"), + coefFormulaCoded) result[["regression"]][["filledFormula"]] <- gsubInteractionSymbol(filledFormula) jaspResults[[currentDependent]][["doeResult"]] <- createJaspState(result) @@ -770,6 +771,14 @@ get_levels <- function(var, num_levels, dataset) { tb2 <- createJaspTable(gettext("Response Optimizer Solution")) tb2$addColumnInfo(name = "desi", title = "Composite desirability", type = "number") + allPredictors <- c(continuousPredictors, unlist(discretePredictors)) + allPredictors <- allPredictors[allPredictors != ""] + for (pred in allPredictors) { + predType <- if (pred %in% continuousPredictors) "number" else "string" + tb2$addColumnInfo(name = pred, title = pred, type = predType) + } + for (dep in roDependent) + tb2$addColumnInfo(name = paste0(dep, " fit"), title = paste0(dep, " fit"), type = "number") tb2$dependOn(options = c("responsesResponseOptimizer", "responseOptimizerGoal", "responseOptimizerLowerBound", "responseOptimizerTarget", "responseOptimizerUpperBound", "responseOptimizerWeight", "responseOptimizerImportance", "optimizationPlotCustomParameters", "responseOptimizerManualBounds", "responseOptimizerManualTarget", @@ -779,17 +788,14 @@ get_levels <- function(var, num_levels, dataset) { jaspResults[["tableRoSolution"]] <- tb2 rows2 <- data.frame(desi = desi) - if (length(continuousPredictors) >= 1 && length(optimParam) > 1 && !identical(continuousPredictors, "")) { - optimParam[continuousPredictors] <- round(optimParam[continuousPredictors], .numDecimals) - } else if (length(continuousPredictors) == 1 && length(optimParam) == 1 && !identical(continuousPredictors, "")) { - optimParam <- round(optimParam, .numDecimals) + for (pred in allPredictors) { + if (pred %in% continuousPredictors) + rows2[[pred]] <- round(as.numeric(optimParam[[pred]]), .numDecimals) + else + rows2[[pred]] <- as.character(optimParam[[pred]]) } - rows2 <- cbind(rows2, optimParam) - if (length(optimParam) == 1) # transform it this way to have the correct naming - colnames(rows2)[ncol(rows2)] <- c(continuousPredictors, discretePredictors)[c(continuousPredictors, discretePredictors) != ""] - predValuesFit <- setNames(predValues, paste0(names(predValues), " fit")) - predValuesFit <- round(predValuesFit, .numDecimals) - rows2 <- cbind(rows2, as.data.frame(t(predValuesFit))) + for (dep in roDependent) + rows2[[paste0(dep, " fit")]] <- round(as.numeric(predValues[[dep]]), .numDecimals) tb2$addRows(rows2) } @@ -1018,6 +1024,12 @@ get_levels <- function(var, num_levels, dataset) { tbTitle <- if (options[["optimizationPlotCustomParameters"]]) gettext("Optimization Plot Summary (Manual Predictor Values)") else gettext("Optimization Plot Summary") tb <- createJaspTable(tbTitle) tb$addColumnInfo(name = "desi", title = "Composite desirability", type = "number") + for (pred in allPredictors) { + predType <- if (pred %in% continuousPredictors) "number" else "string" + tb$addColumnInfo(name = pred, title = pred, type = predType) + } + for (dep in roDependent) + tb$addColumnInfo(name = paste0(dep, " fit"), title = paste0(dep, " fit"), type = "number") tb$dependOn(options = c("responsesResponseOptimizer", "responseOptimizerGoal", "responseOptimizerLowerBound", "responseOptimizerTarget", "responseOptimizerUpperBound", "responseOptimizerWeight", "responseOptimizerImportance", "optimizationPlotCustomParameters", "responseOptimizerManualBounds", "responseOptimizerManualTarget", @@ -1034,17 +1046,14 @@ get_levels <- function(var, num_levels, dataset) { currentDiscreteLevels = currentDiscreteLevels, coefficients = coefficients, dependent = roDependent) rows <- data.frame(desi = desi) - predValuesFit <- setNames(predValues, paste0(names(predValues), " fit")) - predValuesFit <- round(predValuesFit, .numDecimals) - rows <- cbind(rows, as.data.frame(t(predValuesFit))) - if (length(continuousPredictors) >= 1 && length(currentSettings) > 1 && !identical(continuousPredictors, "")) { - currentSettings[continuousPredictors] <- round(currentSettings[continuousPredictors], .numDecimals) - } else if (length(continuousPredictors) == 1 && length(currentSettings) == 1 && !identical(continuousPredictors, "")) { - currentSettings <- round(currentSettings, .numDecimals) + for (pred in allPredictors) { + if (pred %in% continuousPredictors) + rows[[pred]] <- round(as.numeric(currentSettings[[pred]]), .numDecimals) + else + rows[[pred]] <- as.character(currentSettings[[pred]]) } - rows <- cbind(rows, currentSettings) - if (length(currentSettings) == 1) # transform it this way to have the correct naming - colnames(rows)[ncol(rows)] <- allPredictors + for (dep in roDependent) + rows[[paste0(dep, " fit")]] <- round(as.numeric(predValues[[dep]]), .numDecimals) tb$addRows(rows) } From 7546f6ba72667caf302cc4d2e34478af1156f436 Mon Sep 17 00:00:00 2001 From: Johnny van Doorn <15704203+JohnnyDoorn@users.noreply.github.com> Date: Fri, 20 Mar 2026 12:40:41 +0100 Subject: [PATCH 2/4] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- R/doeAnalysis.R | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/R/doeAnalysis.R b/R/doeAnalysis.R index 258c2ed3..1c1820a5 100644 --- a/R/doeAnalysis.R +++ b/R/doeAnalysis.R @@ -777,8 +777,11 @@ get_levels <- function(var, num_levels, dataset) { predType <- if (pred %in% continuousPredictors) "number" else "string" tb2$addColumnInfo(name = pred, title = pred, type = predType) } - for (dep in roDependent) - tb2$addColumnInfo(name = paste0(dep, " fit"), title = paste0(dep, " fit"), type = "number") + for (dep in roDependent) { + colName <- paste0(dep, "_fit") + colTitle <- gettextf("%s fit", dep) + tb2$addColumnInfo(name = colName, title = colTitle, type = "number") + } tb2$dependOn(options = c("responsesResponseOptimizer", "responseOptimizerGoal", "responseOptimizerLowerBound", "responseOptimizerTarget", "responseOptimizerUpperBound", "responseOptimizerWeight", "responseOptimizerImportance", "optimizationPlotCustomParameters", "responseOptimizerManualBounds", "responseOptimizerManualTarget", @@ -794,8 +797,10 @@ get_levels <- function(var, num_levels, dataset) { else rows2[[pred]] <- as.character(optimParam[[pred]]) } - for (dep in roDependent) - rows2[[paste0(dep, " fit")]] <- round(as.numeric(predValues[[dep]]), .numDecimals) + for (dep in roDependent) { + colName <- paste0(dep, "_fit") + rows2[[colName]] <- round(as.numeric(predValues[[dep]]), .numDecimals) + } tb2$addRows(rows2) } From eebb74777e716089cc171c27e0d939080346f826 Mon Sep 17 00:00:00 2001 From: Johnny Date: Fri, 20 Mar 2026 12:50:28 +0100 Subject: [PATCH 3/4] add gettext --- R/doeAnalysis.R | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/R/doeAnalysis.R b/R/doeAnalysis.R index 1c1820a5..39a04db8 100644 --- a/R/doeAnalysis.R +++ b/R/doeAnalysis.R @@ -1028,13 +1028,18 @@ get_levels <- function(var, num_levels, dataset) { tbTitle <- if (options[["optimizationPlotCustomParameters"]]) gettext("Optimization Plot Summary (Manual Predictor Values)") else gettext("Optimization Plot Summary") tb <- createJaspTable(tbTitle) - tb$addColumnInfo(name = "desi", title = "Composite desirability", type = "number") + tb$addColumnInfo(name = "desi", title = gettext("Composite desirability"), type = "number") for (pred in allPredictors) { predType <- if (pred %in% continuousPredictors) "number" else "string" tb$addColumnInfo(name = pred, title = pred, type = predType) } - for (dep in roDependent) - tb$addColumnInfo(name = paste0(dep, " fit"), title = paste0(dep, " fit"), type = "number") + + for (dep in roDependent) { + colName <- paste0(dep, " fit") + colTitle <- gettextf("%s fit", dep) + tb$addColumnInfo(name = colName, title = colTitle, type = "number") + } + tb$dependOn(options = c("responsesResponseOptimizer", "responseOptimizerGoal", "responseOptimizerLowerBound", "responseOptimizerTarget", "responseOptimizerUpperBound", "responseOptimizerWeight", "responseOptimizerImportance", "optimizationPlotCustomParameters", "responseOptimizerManualBounds", "responseOptimizerManualTarget", From ddb543e858a68688dd5e1c07ad94b089d886e090 Mon Sep 17 00:00:00 2001 From: Johnny Date: Fri, 20 Mar 2026 14:28:33 +0100 Subject: [PATCH 4/4] make sure low numbers don't get e notation --- R/doeAnalysis.R | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/R/doeAnalysis.R b/R/doeAnalysis.R index 39a04db8..bd47f4dd 100644 --- a/R/doeAnalysis.R +++ b/R/doeAnalysis.R @@ -15,6 +15,21 @@ # along with this program. If not, see . # +.formatCoefEquation <- function(x, digits = .numDecimals) { + vapply(x, function(val) { + if (val == 0) return("0") + absVal <- abs(val) + if (absVal < 1e4) { + # avoid e-notation for small-to-moderate numbers + mag <- floor(log10(absVal)) + sigDigits <- max(digits, mag + 1 + digits) + trimws(formatC(val, digits = sigDigits, format = "g", drop0trailing = TRUE)) + } else { + trimws(formatC(val, digits = digits, format = "g", drop0trailing = TRUE)) + } + }, character(1)) +} + #' @export doeAnalysis <- function(jaspResults, dataset, options, ...) { @@ -604,7 +619,7 @@ doeAnalysis <- function(jaspResults, dataset, options, ...) { } # Uncoded Formula - fmtCoef <- formatC(abs(coefs[-1, 1]), digits = .numDecimals, format = "g") + fmtCoef <- .formatCoefEquation(abs(coefs[-1, 1]), digits = .numDecimals) coefFormula <- paste(ifelse(sign(coefs[-1,1])==1, " +", " \u2013"), fmtCoef, coefNames[-1], @@ -612,11 +627,11 @@ doeAnalysis <- function(jaspResults, dataset, options, ...) { # Now add dependent name and intercept filledFormula <- paste0(dep, " = ", - formatC(coefs[1, 1], digits = .numDecimals, format = "g"), + .formatCoefEquation(coefs[1, 1], digits = .numDecimals), coefFormula) # Coded Formula - fmtCoefCoded <- formatC(abs(coefsCoded[-1, 1]), digits = .numDecimals, format = "g") + fmtCoefCoded <- .formatCoefEquation(abs(coefsCoded[-1, 1]), digits = .numDecimals) coefFormulaCoded <- paste(ifelse(sign(coefsCoded[-1,1])==1, " +", " \u2013"), fmtCoefCoded, coefNames[-1], @@ -624,7 +639,7 @@ doeAnalysis <- function(jaspResults, dataset, options, ...) { filledFormulaCoded <- paste0(dep, " = ", - formatC(coefsCoded[1, 1], digits = .numDecimals, format = "g"), + .formatCoefEquation(coefsCoded[1, 1], digits = .numDecimals), coefFormulaCoded) result[["regression"]][["filledFormula"]] <- gsubInteractionSymbol(filledFormula)