@@ -59,7 +59,7 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
5959 if ((! wideFormat && options [[" subgroupSizeType" ]] == " manual" &&
6060 any(lapply(split(dataset [[stages ]], ceiling(seq_along(dataset [[stages ]])/ options [[" manualSubgroupSizeValue" ]])), FUN = function (x )length(unique(x ))) > 1 )) ||
6161 (! wideFormat && options [[" subgroupSizeType" ]] == " groupingVariable" &&
62- any(table(dplyr :: count_ (dataset , vars = c(stages , subgroupVariable ))[ subgroupVariable ]) > 1 ))) {
62+ any(table(dplyr :: count (dataset , dplyr :: across( dplyr :: all_of( c(stages , subgroupVariable ))))[[ subgroupVariable ] ]) > 1 ))) {
6363 plotNotes <- paste0(plotNotes , gettext(" One or more subgroups are assigned to more than one stage, only first stage is considered.<br>" ))
6464 }
6565 if (anyNA(dataset [[stages ]])) {
@@ -2703,6 +2703,37 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
27032703 return (plot )
27042704}
27052705
2706+ .qcObservedVarcov <- function (logdensity , X , parms , mle ) {
2707+ mle <- unlist(mle )
2708+
2709+ if (! all(parms %in% names(mle ))) {
2710+ if (length(mle ) != length(parms ))
2711+ stop(gettext(" Could not compute variance-covariance matrix: parameter vector has unexpected length." ), call. = FALSE )
2712+
2713+ names(mle ) <- parms
2714+ }
2715+
2716+ mle <- as.numeric(mle [parms ])
2717+ names(mle ) <- parms
2718+
2719+ negLogLik <- function (theta ) {
2720+ names(theta ) <- parms
2721+ env <- list2env(c(as.list(theta ), list (x = X )), parent = baseenv())
2722+ ll <- eval(logdensity , envir = env )
2723+ - sum(ll )
2724+ }
2725+
2726+ hessian <- stats :: optimHess(par = mle , fn = negLogLik )
2727+
2728+ if (anyNA(hessian ) || any(! is.finite(hessian )))
2729+ stop(gettext(" Could not compute variance-covariance matrix: Hessian contains invalid values." ), call. = FALSE )
2730+
2731+ varcov <- solve(hessian )
2732+ dimnames(varcov ) <- list (parms , parms )
2733+
2734+ list (varcov = varcov )
2735+ }
2736+
27062737.qcProbabilityPlotObject <- function (options , dataset , measurements , stages ) {
27072738 if (identical(stages , " " )) {
27082739 nStages <- 1
@@ -2749,8 +2780,8 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
27492780 # Computing according to the distribution
27502781 if (options [[" nullDistribution" ]] == " normal" ) {
27512782 lpdf <- quote(- log(sigma ) - 0.5 / sigma ^ 2 * (x - mu ) ^ 2 )
2752- matrix <- try(mle.tools :: observed.varcov (logdensity = lpdf , X = dataCurrentStage , parms = c(" mu" , " sigma" ),
2753- mle = c(mean(dataCurrentStage ), sd(dataCurrentStage ))))
2783+ matrix <- try(.qcObservedVarcov (logdensity = lpdf , X = dataCurrentStage , parms = c(" mu" , " sigma" ),
2784+ mle = c(mean(dataCurrentStage ), sd(dataCurrentStage ))))
27542785 # Gracefully handle confidence band computation failure
27552786 if (jaspBase :: isTryError(matrix )) {
27562787 hasConfidenceBands <- FALSE
@@ -2781,7 +2812,7 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
27812812 meanlog <- as.numeric(fit $ parameters [1 ])
27822813 sdlog <- as.numeric(fit $ parameters [2 ])
27832814 lpdf <- quote(log(1 / (sqrt(2 * pi )* x * sdlog ) * exp(- (log(x )- meanlog )^ 2 / (2 * sdlog ^ 2 ))))
2784- matrix <- try(mle.tools :: observed.varcov (logdensity = lpdf , X = dataCurrentStage , parms = c(" meanlog" , " sdlog" ), mle = fit $ parameters ))
2815+ matrix <- try(.qcObservedVarcov (logdensity = lpdf , X = dataCurrentStage , parms = c(" meanlog" , " sdlog" ), mle = fit $ parameters ))
27852816 # Gracefully handle confidence band computation failure
27862817 if (jaspBase :: isTryError(matrix )) {
27872818 hasConfidenceBands <- FALSE
@@ -2819,7 +2850,7 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
28192850 shape <- as.numeric(fit_Weibull [[" beta" ]])
28202851 scale <- as.numeric(fit_Weibull [[" theta" ]])
28212852 lpdf <- quote(log(shape ) - shape * log(scale ) + shape * log(x ) - (x / scale )^ shape )
2822- matrix <- try(mle.tools :: observed.varcov (logdensity = lpdf , X = dataCurrentStage , parms = c(" shape" , " scale" ), mle = c(" shape" = shape , " scale" = scale )))
2853+ matrix <- try(.qcObservedVarcov (logdensity = lpdf , X = dataCurrentStage , parms = c(" shape" , " scale" ), mle = c(" shape" = shape , " scale" = scale )))
28232854 # Gracefully handle confidence band computation failure
28242855 if (jaspBase :: isTryError(matrix )) {
28252856 hasConfidenceBands <- FALSE
0 commit comments