Skip to content

Commit

Permalink
Release fixes (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
FBartos authored Dec 6, 2024
1 parent 703b258 commit 9128378
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 27 deletions.
49 changes: 33 additions & 16 deletions R/MixedModelsCommon.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,28 @@

if (options$family %in% c("gamma", "inverseGaussian")) {

if (any(dataset[, options$dependent] <= 0))
if (options$dependent.type != "scale" || any(dataset[, options$dependent] <= 0))
.quitAnalysis(gettextf("%s requires that the dependent variable is positive.",familyText))

} else if (options$family %in% c("negativeBinomial", "poisson")) {

if (any(dataset[, options$dependent] < 0 | any(!.is.wholenumber(dataset[, options$dependent]))))
if (options$dependent.type != "scale" || any(dataset[, options$dependent] < 0 | any(!.is.wholenumber(dataset[, options$dependent]))))
.quitAnalysis(gettextf("%s requires that the dependent variable is an integer.",familyText))

} else if (options$family == "bernoulli") {

if (any(!dataset[, options$dependent] %in% c(0, 1)))
if (!options$dependent.type %in% c("scale", "nominal") || any(!dataset[, options$dependent] %in% c(0, 1)))
.quitAnalysis(gettextf("%s requires that the dependent variable contains only 0 and 1.",familyText))

} else if (options$family == "binomial") {

if (any(dataset[, options$dependentAggregation] < 0) || any(!.is.wholenumber(dataset[, options$dependentAggregation])))
if (options$dependentAggregation.type != "scale" || any(dataset[, options$dependentAggregation] < 0) || any(!.is.wholenumber(dataset[, options$dependentAggregation])))
.quitAnalysis(gettextf("%s requires that the number of trials variable is an integer.",familyText))

# if the user supplies the number of successes, transform them into the corresponding proportion
if (options$dependent.type != "scale")
.quitAnalysis(gettextf("%s requires that the number or proportion of successes is an integer.",familyText))

if (all(.is.wholenumber(dataset[, options$dependent]))){
if(any(dataset[, options$dependent] > dataset[, options$dependentAggregation]))
.quitAnalysis(gettextf("%s requires that the number of successes is lower that the number of trials.",familyText))
Expand All @@ -193,9 +196,14 @@

} else if (options$family == "beta") {

if (any(dataset[, options$dependent] <= 0 | dataset[, options$dependent] >= 1))
if (options$dependent.type != "scale" || any(dataset[, options$dependent] <= 0 | dataset[, options$dependent] >= 1))
.quitAnalysis(gettextf("%s requires that the dependent variable is higher than 0 and lower than 1.",familyText))

} else if (options$family == "gaussian") {

if (options$dependent.type != "scale")
.quitAnalysis(gettextf("%s requires that the dependent variable is continuous.",familyText))

}
}

Expand Down Expand Up @@ -1504,11 +1512,15 @@
return()

model <- jaspResults[["mmModel"]]$object$model
# deal with type II SS
if (is.list(model$full_model))
model <- model$full_model[[length(model$full_model)]]
else
model <- model$full_model

if (type %in% c("LMN", "GLMM")) {
# deal with type II SS
if (is.list(model$full_model))
model <- model$full_model[[length(model$full_model)]]
else
model <- model$full_model
}


# deal with continuous predictors
at <- NULL
Expand Down Expand Up @@ -2414,13 +2426,18 @@
divIterations <- rstan::get_num_divergent(model$stanfit)
lowBmfi <- rstan::get_low_bfmi_chains(model$stanfit)
maxTreedepth <- rstan::get_num_max_treedepth(model$stanfit)
minESS <- min(rstan::summary(model$stanfit)$summary[, "n_eff"])

if (any(is.infinite(rstan::summary(model$stanfit)$summary[, "Rhat"])))
maxRhat <- Inf
if (any(is.nan(rstan::summary(model$stanfit)$summary[, "n_eff"])))
minESS <- NaN
else
maxRhat <- max(rstan::summary(model$stanfit)$summary[, "Rhat"])
minESS <- min(rstan::summary(model$stanfit)$summary[, "n_eff"])

if (any(is.infinite(rstan::summary(model$stanfit)$summary[, "Rhat"])))
maxRhat <- Inf
else if (any(is.nan(rstan::summary(model$stanfit)$summary[, "Rhat"])))
maxRhat <- NaN
else
maxRhat <- max(rstan::summary(model$stanfit)$summary[, "Rhat"])

if (divIterations != 0)
tempTable$addFootnote(.mmMessageDivergentIter(divIterations), symbol = gettext("Warning:"))
Expand All @@ -2431,10 +2448,10 @@
if (maxTreedepth != 0)
tempTable$addFootnote(.mmMessageMaxTreedepth(maxTreedepth))

if (maxRhat > 1.01)
if (is.nan(maxRhat) || maxRhat > 1.01)
tempTable$addFootnote(.mmMessageMaxRhat(maxRhat), symbol = gettext("Warning:"))

if (minESS < 100 * options$mcmcChains || is.nan(minESS))
if (is.nan(minESS) || minESS < 100 * options$mcmcChains)
tempTable$addFootnote(.mmMessageMinESS(minESS, 100 * options$mcmcChains), symbol = gettext("Warning:"))


Expand Down
24 changes: 15 additions & 9 deletions R/MixedModelsMessages.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,24 @@
}

.mmMessageMaxRhat <- function(Rhat) {
gettextf(
"Inference possibly unreliable -- MCMC chains might not have converged; The largest R-hat is %.3f > 1.01. To lower R-hat please increase 'Iterations', or 'Adapt delta' in the Options section.",
Rhat
)
if (is.nan(Rhat))
return(gettext("Inference possibly unreliable -- MCMC chains might not have converged; R-hat cannot be computed for all parameters due too few distinct samples. Please re-scale the variables or increase 'Iterations', or 'Adapt delta' in the Options section."))
else
return(gettextf(
"Inference possibly unreliable -- MCMC chains might not have converged; The largest R-hat is %.3f > 1.01. To lower R-hat please increase 'Iterations', or 'Adapt delta' in the Options section.",
Rhat
))
}

.mmMessageMinESS <- function(ESS, treshold) {
gettextf(
"Low estimation accuracy -- The smallest Effective Sample Size (ESS) is %.2f < %1.0f. To increase accuracy please increase 'Iterations', or 'Adapt delta' in the Options section.",
ESS,
treshold
)
if (is.nan(ESS))
return(gettext("Inference possibly unreliable -- MCMC chains might not have converged; Effective Sample Size (ESS) cannot be computed for all parameters due too few distinct samples. Please re-scale the variables or increase 'Iterations', or 'Adapt delta' in the Options section."))
else
gettextf(
"Low estimation accuracy -- The smallest Effective Sample Size (ESS) is %.2f < %1.0f. To increase accuracy please increase 'Iterations', or 'Adapt delta' in the Options section.",
ESS,
treshold
)
}

.mmMessageBadWAIC <- function(n_bad) {
Expand Down
5 changes: 4 additions & 1 deletion inst/qml/MixedModelsBGLMM.qml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ Form {
}
}

MM.MixedModelsModel {}
MM.MixedModelsModel
{
analysisType: "Bayesian"
}

MM.MixedModelsBOptions {}

Expand Down
5 changes: 4 additions & 1 deletion inst/qml/MixedModelsBLMM.qml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ Form {
}
}

MM.MixedModelsModel {}
MM.MixedModelsModel
{
analysisType: "Bayesian"
}

MM.MixedModelsBOptions {}

Expand Down
3 changes: 3 additions & 0 deletions inst/qml/common/MixedModelsModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Section
{
title: qsTr("Model")

property string analysisType: "frequentist"

VariablesForm
{
preferredHeight: jaspTheme.smallDefaultVariablesFormHeight
Expand All @@ -49,6 +51,7 @@ Section
label: qsTr("Include intercept")
name: "includeIntercept"
checked: true
visible: analysisType == "frequentist" // stanova cannot summarize no-intercept models
}
}

Expand Down

0 comments on commit 9128378

Please sign in to comment.