diff --git a/R/commonQualityControl.R b/R/commonQualityControl.R
index 8e1c73e3..837eae03 100644
--- a/R/commonQualityControl.R
+++ b/R/commonQualityControl.R
@@ -1456,12 +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),
fix.arg = fix.arg))
-
-
-
if (jaspBase::isTryError(fitWeibull))
stop(estimationErrorMessage, call. = FALSE)
@@ -1510,7 +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),
start = lnorm3startList,
fix.arg = fix.arg))
if (jaspBase::isTryError(lnorm3Fit))
diff --git a/R/processCapabilityStudies.R b/R/processCapabilityStudies.R
index 3d411ced..94f93a5f 100644
--- a/R/processCapabilityStudies.R
+++ b/R/processCapabilityStudies.R
@@ -1131,20 +1131,20 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
if (options[["target"]] && options[["processCapabilityPlotSpecificationLimits"]])
xLimits <- range(xLimits, options[["targetValue"]])
- # 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"]])
- xLimits <- range(xLimits, options[["historicalScaleValue"]] - 1.5 * sdo, options[["historicalScaleValue"]] + 1.5 * sdo)
- 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")
- xLimits <- range(xLimits, 0)
- if (distribution == "gamma" && options[["historicalShape"]] && options[["historicalScale"]])
- xLimits <- range(xLimits, options[["historicalScaleValue"]] * (options[["historicalShapeValue"]] - 1))
- if ((distribution == "logistic" || distribution == "loglogistic") && options[["historicalLocation"]])
- xLimits <- range(xLimits, options[["historicalLocationValue"]])
+ # 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"]])
+ xLimits <- range(xLimits, options[["historicalScaleValue"]] - 1.5 * sdo, options[["historicalScaleValue"]] + 1.5 * sdo)
+ 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")
+ xLimits <- range(xLimits, 0)
+ if (distribution == "gamma" && options[["historicalShape"]] && options[["historicalScale"]])
+ xLimits <- range(xLimits, options[["historicalScaleValue"]] * (options[["historicalShapeValue"]] - 1))
+ if ((distribution == "logistic" || distribution == "loglogistic") && options[["historicalLocation"]])
+ xLimits <- range(xLimits, options[["historicalLocationValue"]])
xBreaks <- jaspGraphs::getPrettyAxisBreaks(c(allData))
xStep <- diff(xBreaks)[1]
@@ -3093,16 +3093,16 @@ 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")
+ table$addColumnInfo(name = "ad", title = gettext("AD"), type = "number")
table$addColumnInfo(name = "p", title = gettext("p-value"), type = "pvalue")
table$addFootnote(gettextf("The Anderson-Darling statistic AD is calculated against the %1$s distribution.", distributionTitle))
table$addFootnote(gettextf("Red dotted lines in the probability plot below represent a 95%% confidence interval."))
@@ -3115,7 +3115,7 @@ 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))
@@ -3123,39 +3123,42 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
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))
- 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 (adStatisticAdjusted >= 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) {
+ 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) {
diff --git a/tests/testthat/_snaps/processCapabilityStudies/capability-of-the-process-subplot-1.svg b/tests/testthat/_snaps/processCapabilityStudies/capability-of-the-process-subplot-1.svg
new file mode 100644
index 00000000..73ceff82
--- /dev/null
+++ b/tests/testthat/_snaps/processCapabilityStudies/capability-of-the-process-subplot-1.svg
@@ -0,0 +1,99 @@
+
+
diff --git a/tests/testthat/_snaps/processCapabilityStudies/histogram-subplot-1.svg b/tests/testthat/_snaps/processCapabilityStudies/histogram-subplot-1.svg
new file mode 100644
index 00000000..ff583489
--- /dev/null
+++ b/tests/testthat/_snaps/processCapabilityStudies/histogram-subplot-1.svg
@@ -0,0 +1,84 @@
+
+
diff --git a/tests/testthat/_snaps/processCapabilityStudies/probability-plot-against-weibull-distribution-subplot-1.svg b/tests/testthat/_snaps/processCapabilityStudies/probability-plot-against-weibull-distribution-subplot-1.svg
new file mode 100644
index 00000000..bf5c2bdc
--- /dev/null
+++ b/tests/testthat/_snaps/processCapabilityStudies/probability-plot-against-weibull-distribution-subplot-1.svg
@@ -0,0 +1,512 @@
+
+
diff --git a/tests/testthat/_snaps/processCapabilityStudies/probability-plot-against-weibull-distribution5-subplot-1.svg b/tests/testthat/_snaps/processCapabilityStudies/probability-plot-against-weibull-distribution5-subplot-1.svg
index fbddac62..2a714f74 100644
--- a/tests/testthat/_snaps/processCapabilityStudies/probability-plot-against-weibull-distribution5-subplot-1.svg
+++ b/tests/testthat/_snaps/processCapabilityStudies/probability-plot-against-weibull-distribution5-subplot-1.svg
@@ -1,5 +1,6 @@
-