Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
^.*\.Rproj$
^\.Rproj\.user$
^\examples$
^\.positai$
^\.claude$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ renv/
_processedLockFile.lock

.vscode/
.positai
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Imports:
jaspDescriptives,
jaspGraphs,
lubridate,
mle.tools,
psych,
qcc,
rsm,
Expand Down
2 changes: 1 addition & 1 deletion R/TimeWeightedCharts.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ timeWeightedCharts <- function(jaspResults, dataset, options) {
if ((!wideFormat && options[["subgroupSizeType"]] == "manual" &&
any(lapply(split(dataset[[stages]], ceiling(seq_along(dataset[[stages]])/options[["manualSubgroupSizeValue"]])), FUN = function(x)length(unique(x))) > 1)) ||
(!wideFormat && options[["subgroupSizeType"]] == "groupingVariable" &&
any(table(dplyr::count_(dataset, vars = c(stages, subgroupVariable))[subgroupVariable]) > 1))) {
any(table(dplyr::count(dataset, dplyr::across(dplyr::all_of(c(stages, subgroupVariable))))[[subgroupVariable]]) > 1))) {
plotNotes <- paste0(plotNotes, gettext("One or more subgroups are assigned to more than one stage, only first stage is considered.<br>"))
}
if (anyNA(dataset[[stages]])) {
Expand Down
11 changes: 0 additions & 11 deletions R/commonQualityControl.R
Original file line number Diff line number Diff line change
Expand Up @@ -1456,15 +1456,8 @@ KnownControlStats.RS <- function(N, sigma = 3) {
theta <- fix.arg[["scale"]] # scale
} else {
fitWeibull <- try(fitdistrplus::fitdist(data, "weibull", method = "mle",
control = list(
maxit = 10000,
abstol = .Machine$double.eps^0.75,
reltol = .Machine$double.eps^0.75),
fix.arg = fix.arg))




if (jaspBase::isTryError(fitWeibull))
stop(estimationErrorMessage, call. = FALSE)

Expand Down Expand Up @@ -1513,10 +1506,6 @@ KnownControlStats.RS <- function(N, sigma = 3) {

# Estimate parameters using fitdistrplus, because it can keep values fixed
lnorm3Fit <- try(fitdistrplus::fitdist(data, "lnorm3Temp", method = "mle",
control = list(
maxit = 10000,
abstol = .Machine$double.eps^0.75,
reltol = .Machine$double.eps^0.75),
start = lnorm3startList,
fix.arg = fix.arg))
if (jaspBase::isTryError(lnorm3Fit))
Expand Down
120 changes: 75 additions & 45 deletions R/processCapabilityStudies.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
if ((!wideFormat && options[["subgroupSizeType"]] == "manual" &&
any(lapply(split(dataset[[stages]], ceiling(seq_along(dataset[[stages]])/options[["manualSubgroupSizeValue"]])), FUN = function(x)length(unique(x))) > 1)) ||
(!wideFormat && options[["subgroupSizeType"]] == "groupingVariable" &&
any(table(dplyr::count_(dataset, vars = c(stages, subgroupVariable))[subgroupVariable]) > 1))) {
any(table(dplyr::count(dataset, dplyr::across(dplyr::all_of(c(stages, subgroupVariable))))[[subgroupVariable]]) > 1))) {
plotNotes <- paste0(plotNotes, gettext("One or more subgroups are assigned to more than one stage, only first stage is considered.<br>"))
}
if (anyNA(dataset[[stages]])) {
Expand Down Expand Up @@ -856,9 +856,9 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
# Addition to consider that if distributions are set historically, they may fall outside the usual limits
if (distribution == "normal" && options[["historicalMean"]])
xLimits <- range(xLimits, options[["historicalMeanValue"]] - 1.5 * sdo, options[["historicalMeanValue"]] + 1.5 * sdo)
if (distribution == "weibull" || distribution == "3ParameterWeibull" && options[["historicalScale"]])
if ((distribution == "weibull" || distribution == "3ParameterWeibull") && options[["historicalScale"]])
xLimits <- range(xLimits, options[["historicalScaleValue"]] - 1.5 * sdo, options[["historicalScaleValue"]] + 1.5 * sdo)
if (distribution == "lognormal" || distribution == "3ParameterLognormal" && options[["historicalLogMean"]])
if ((distribution == "lognormal" || distribution == "3ParameterLognormal") && options[["historicalLogMean"]])
xLimits <- range(xLimits, exp(options[["historicalLogMeanValue"]]) - 1.5 * sdo,
exp(options[["historicalLogMeanValue"]]) + 1.5 * sdo)
if (distribution == "exponential")
Expand Down Expand Up @@ -2579,14 +2579,14 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
}
table$addColumnInfo(name = "n", title = gettext("N"), type = "integer")
if (options[["nullDistribution"]] == "normal") {
table$addColumnInfo(name = "mean", title = gettextf("Mean (%1$s)", "\u03BC"), type = "number")
table$addColumnInfo(name = "sd", title = gettextf("Std. dev. (%1$s)", "\u03C3"), type = "number")
table$addColumnInfo(name = "parameterEstimate1", title = gettextf("Mean (%1$s)", "\u03BC"), type = "number")
table$addColumnInfo(name = "parameterEstimate2", title = gettextf("Std. dev. (%1$s)", "\u03C3"), type = "number")
} else if (options[["nullDistribution"]] == "lognormal") {
table$addColumnInfo(name = "mean", title = gettextf("Log mean (%1$s)", "\u03BC"), type = "number")
table$addColumnInfo(name = "sd", title = gettextf("Log std.dev (%1$s)", "\u03C3"), type = "number")
table$addColumnInfo(name = "parameterEstimate1", title = gettextf("Log mean (%1$s)", "\u03BC"), type = "number")
table$addColumnInfo(name = "parameterEstimate2", title = gettextf("Log std.dev (%1$s)", "\u03C3"), type = "number")
} else if (options[["nullDistribution"]] == "weibull") {
table$addColumnInfo(name = "mean", title = gettextf("Shape (%1$s)", "\u03B2"), type = "number")
table$addColumnInfo(name = "sd", title = gettextf("Scale (%1$s)", "\u03B8"), type = "number")
table$addColumnInfo(name = "parameterEstimate1", title = gettextf("Shape (%1$s)", "\u03B2"), type = "number")
table$addColumnInfo(name = "parameterEstimate2", title = gettextf("Scale (%1$s)", "\u03B8"), type = "number")
}
table$addColumnInfo(name = "ad", title = gettext("AD"), type = "integer")
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In .qcProbabilityTable(), the AD column is declared as type integer, but the code computes and stores non-integer Anderson–Darling statistics (rounded to .numDecimals). This will likely display incorrectly in the UI (e.g., 0.43 shown as 0). Change the column type to number (and optionally add a numeric format) to match the actual values.

Suggested change
table$addColumnInfo(name = "ad", title = gettext("AD"), type = "integer")
table$addColumnInfo(name = "ad", title = gettext("AD"), type = "number")

Copilot uses AI. Check for mistakes.
table$addColumnInfo(name = "p", title = gettext("<i>p</i>-value"), type = "pvalue")
Expand All @@ -2601,51 +2601,50 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
container[["probabilityTable"]] <- table
return()
}
tableColNames <- c("mean", "sd", "n", "ad", "p")
tableColNames <- c("parameterEstimate1", "parameterEstimate2", "n", "ad", "p")
if (nStages > 1)
tableColNames <- c("stage", tableColNames)
tableDf <- data.frame(matrix(ncol = length(tableColNames), nrow = 0))
colnames(tableDf) <- tableColNames
for (i in seq_len(nStages)) {
stage <- unique(dataset[[stages]])[i]
dataCurrentStage <- dataset[which(dataset[[stages]] == stage), ][!names(dataset) %in% stages]
values <- as.vector(na.omit(unlist(dataCurrentStage[measurements]))) # distribution fitting function complains if this is not explicitly a vector
stageValues <- as.vector(na.omit(unlist(dataCurrentStage[measurements]))) # distribution fitting function complains if this is not explicitly a vector

if (options[["nullDistribution"]] == "normal") {
meanx <- mean(values)
sdx <- sd(values)
test <- goftest::ad.test(x = values, "norm", mean = meanx, sd = sdx)
parameterEstimate1 <- mean(stageValues)
parameterEstimate2 <- stats::sd(stageValues)
andersonDarlingTest <- goftest::ad.test(x = stageValues, "norm", mean = parameterEstimate1, sd = parameterEstimate2)
} else if (options[["nullDistribution"]] == "lognormal") {
fit <- EnvStats::elnorm(values)
meanx <- fit$parameters[1]
sdx <- fit$parameters[2]
test <- goftest::ad.test(x = values, "plnorm", meanlog = meanx, sdlog = sdx)
fitPars <- .distributionParameters(stageValues, distribution = "lognormal")
parameterEstimate1 <- fitPars$beta
parameterEstimate2 <- fitPars$theta
andersonDarlingTest <- goftest::ad.test(x = stageValues, "plnorm", meanlog = parameterEstimate1, sdlog = parameterEstimate2)
} else if (options[["nullDistribution"]] == "weibull") {
fit <- fitdistrplus::fitdist(values, 'weibull',
control = list(
maxit = 10000,
abstol = .Machine$double.eps^0.75,
reltol = .Machine$double.eps^0.75,
ndeps = rep(1e-8, 2)))
meanx <- fit$estimate[1]
sdx <- fit$estimate[2]
test <- goftest::ad.test(x = values, "pweibull", shape = meanx, scale = sdx)
}
n <- length(values)
ad <- test$statistic
adStar <- ad*(1 + (0.75/n) + (2.25/(n^2)))
if(ad >= 0.6) {
p <- exp(1.2937 - (5.709 * adStar) + 0.0186 * (adStar^2))
} else if(adStar < 0.6 && adStar > 0.34) {
p <- exp(0.9177 - (4.279 * adStar) - 1.38 * (adStar^2))
} else if(adStar < 0.34 && adStar > 0.2) {
p <- 1 - exp(-8.318 + (42.796 * adStar) - 59.938 * (adStar^2))
} else if(adStar <= 0.2) {
p <- 1 - exp(-13.436 + (101.14 * adStar) - 223.73 * (adStar^2)) #Jaentschi & Bolboaca (2018)
fitPars <- .distributionParameters(stageValues, distribution = "weibull")
parameterEstimate1 <- fitPars$beta
parameterEstimate2 <- fitPars$theta
andersonDarlingTest <- goftest::ad.test(x = stageValues, "pweibull", shape = parameterEstimate1, scale = parameterEstimate2)
}
sampleSize <- length(stageValues)
adStatistic <- andersonDarlingTest$statistic
adStatisticAdjusted <- adStatistic * (1 + (0.75 / sampleSize) + (2.25 / (sampleSize^2)))
if (adStatistic >= 0.6) {
pValue <- exp(1.2937 - (5.709 * adStatisticAdjusted) + 0.0186 * (adStatisticAdjusted^2))
} else if (adStatisticAdjusted < 0.6 && adStatisticAdjusted > 0.34) {
pValue <- exp(0.9177 - (4.279 * adStatisticAdjusted) - 1.38 * (adStatisticAdjusted^2))
} else if (adStatisticAdjusted < 0.34 && adStatisticAdjusted > 0.2) {
Comment on lines +2630 to +2636
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The p-value approximation branches mix adjusted and unadjusted AD statistics: the first threshold compares adStatistic to 0.6, while subsequent branches compare adStatisticAdjusted. Since the approximation formulas use the adjusted statistic, the thresholding should be based on the adjusted value consistently (otherwise you can select the wrong branch for small/medium sample sizes).

Copilot uses AI. Check for mistakes.
pValue <- 1 - exp(-8.318 + (42.796 * adStatisticAdjusted) - 59.938 * (adStatisticAdjusted^2))
} else if (adStatisticAdjusted <= 0.2) {
pValue <- 1 - exp(-13.436 + (101.14 * adStatisticAdjusted) - 223.73 * (adStatisticAdjusted^2)) #Jaentschi & Bolboaca (2018)
} else {
p <- test$p.value
pValue <- andersonDarlingTest$p.value
}
tableDfCurrentStage <- data.frame(mean = meanx, sd = sdx, n = n, ad = round(ad, .numDecimals), p = round(p, .numDecimals))
tableDfCurrentStage <- data.frame(parameterEstimate1 = parameterEstimate1,
parameterEstimate2 = parameterEstimate2,
n = sampleSize,
ad = round(adStatistic, .numDecimals),
p = round(pValue, .numDecimals))
if (i == 1 && nStages > 1)
baseLineDf <- tableDfCurrentStage
if (i > 1) {
Expand Down Expand Up @@ -2703,6 +2702,37 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
return(plot)
}

.qcObservedVarcov <- function(logdensity, X, parms, mle) {
mle <- unlist(mle)

if (!all(parms %in% names(mle))) {
if (length(mle) != length(parms))
stop(gettext("Could not compute variance-covariance matrix: parameter vector has unexpected length."), call. = FALSE)

names(mle) <- parms
}

mle <- as.numeric(mle[parms])
names(mle) <- parms

negLogLik <- function(theta) {
names(theta) <- parms
env <- list2env(c(as.list(theta), list(x = X)), parent = baseenv())
ll <- eval(logdensity, envir = env)
-sum(ll)
}

hessian <- stats::optimHess(par = mle, fn = negLogLik)

if (anyNA(hessian) || any(!is.finite(hessian)))
stop(gettext("Could not compute variance-covariance matrix: Hessian contains invalid values."), call. = FALSE)

varcov <- solve(hessian)
dimnames(varcov) <- list(parms, parms)

list(varcov = varcov)
}

.qcProbabilityPlotObject <- function(options, dataset, measurements, stages) {
if (identical(stages, "")) {
nStages <- 1
Expand Down Expand Up @@ -2749,8 +2779,8 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
# Computing according to the distribution
if (options[["nullDistribution"]] == "normal") {
lpdf <- quote(-log(sigma) - 0.5 / sigma ^ 2 * (x - mu) ^ 2)
matrix <- try(mle.tools::observed.varcov(logdensity = lpdf, X = dataCurrentStage, parms = c("mu", "sigma"),
mle = c(mean(dataCurrentStage), sd(dataCurrentStage))))
matrix <- try(.qcObservedVarcov(logdensity = lpdf, X = dataCurrentStage, parms = c("mu", "sigma"),
mle = c(mean(dataCurrentStage), sd(dataCurrentStage))))
# Gracefully handle confidence band computation failure
if (jaspBase::isTryError(matrix)) {
hasConfidenceBands <- FALSE
Expand Down Expand Up @@ -2781,7 +2811,7 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
meanlog <- as.numeric(fit$parameters[1])
sdlog <- as.numeric(fit$parameters[2])
lpdf <- quote(log(1/(sqrt(2*pi)*x*sdlog) * exp(-(log(x)- meanlog)^2/(2*sdlog^2))))
matrix <- try(mle.tools::observed.varcov(logdensity = lpdf, X = dataCurrentStage, parms = c("meanlog", "sdlog"), mle = fit$parameters))
matrix <- try(.qcObservedVarcov(logdensity = lpdf, X = dataCurrentStage, parms = c("meanlog", "sdlog"), mle = fit$parameters))
# Gracefully handle confidence band computation failure
if (jaspBase::isTryError(matrix)) {
hasConfidenceBands <- FALSE
Expand Down Expand Up @@ -2819,7 +2849,7 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
shape <- as.numeric(fit_Weibull[["beta"]])
scale <- as.numeric(fit_Weibull[["theta"]])
lpdf <- quote(log(shape) - shape * log(scale) + shape * log(x) - (x/scale)^shape)
matrix <- try(mle.tools::observed.varcov(logdensity = lpdf, X = dataCurrentStage, parms = c("shape", "scale"), mle = c("shape" = shape, "scale" = scale)))
matrix <- try(.qcObservedVarcov(logdensity = lpdf, X = dataCurrentStage, parms = c("shape", "scale"), mle = c("shape" = shape, "scale" = scale)))
# Gracefully handle confidence band computation failure
if (jaspBase::isTryError(matrix)) {
hasConfidenceBands <- FALSE
Expand Down
2 changes: 1 addition & 1 deletion R/variablesChartsSubgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ variablesChartsSubgroups <- function(jaspResults, dataset, options) {
if ((!wideFormat && options[["subgroupSizeType"]] == "manual" &&
any(lapply(split(dataset[[stages]], ceiling(seq_along(dataset[[stages]])/options[["manualSubgroupSizeValue"]])), FUN = function(x)length(unique(x))) > 1)) ||
(!wideFormat && options[["subgroupSizeType"]] == "groupingVariable" &&
any(table(dplyr::count_(dataset, vars = c(stages, subgroupVariable))[subgroupVariable]) > 1))) {
any(table(dplyr::count(dataset, dplyr::across(dplyr::all_of(c(stages, subgroupVariable))))[[subgroupVariable]]) > 1))) {
plotNotes <- paste0(plotNotes, gettext("One or more subgroups are assigned to more than one stage, only first stage is considered.<br>"))
}
if (anyNA(dataset[[stages]])) {
Expand Down
1 change: 0 additions & 1 deletion inst/help/processCapabilityStudies.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ The size of the subgroups is relevant for the calculation of the process varianc
- FAdist
- goftest
- fitdistrplus
- mle.tools
- tidyr
- tibble
- EnvStats
Expand Down
1 change: 0 additions & 1 deletion inst/help/variablesChartsSubgroups.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,3 @@ Select manually which tests you want to apply and modify them as desired:
- ggrepel
- tidyr
- tibble
- mle.tools
Loading
Loading