Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove readDataSetToEnd #108

Merged
merged 11 commits into from
Dec 9, 2024
60 changes: 38 additions & 22 deletions R/HayesModels.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,11 @@
}

if (number == 4) {
processRelationships <- list(
list(
processDependent = "Y",
processIndependent = "X",
processType = "mediators",
processVariable = "M"
)
)
processRelationships <- .generateProcessRelationships_4(k)
}

if (number == 5) {
processRelationships <- list(
list(
processDependent = "Y",
processIndependent = "X",
processType = "mediators",
processVariable = "M"
),
list(
processDependent = "Y",
processIndependent = "X",
processType = "moderators",
processVariable = "W"
)
)
processRelationships <- .generateProcessRelationships_5(k)
}

if (number == 6) {
Expand Down Expand Up @@ -1568,6 +1548,42 @@
return(.procEncodeProcessRelationships(processRelationships))
} # end of function on hardcoded models

.generateProcessRelationships_4 <- function(k) {
k <- max(k, 1)
processRelationships <- lapply(1:k, function(i) {
list(
processDependent = "Y",
processIndependent = "X",
processType = "mediators",
processVariable = paste0("M", i)
)
})
return(processRelationships)
}

.generateProcessRelationships_5 <- function(k) {
k <- max(k, 1)
processRelationships <- lapply(1:k, function(i) {
list(
processDependent = "Y",
processIndependent = "X",
processType = "mediators",
processVariable = paste0("M", i)
)
})

processRelationships <- append(processRelationships,
list(list(
processDependent = "Y",
processIndependent = "X",
processType = "moderators",
processVariable = "W"
))
)

return(processRelationships)
}

# model 6
.generateProcessRelationships_6 <- function(k) {

Expand Down
2 changes: 0 additions & 2 deletions R/bayesianProcess.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ BayesianProcess <- function(jaspResults, dataset = NULL, options) {
return()
}
options$naAction <- "listwise"
# Read dataset
dataset <- .procReadData(options)
# Check for errors in dataset
.procErrorHandling(dataset, options)
# Create a container for each model
Expand Down
68 changes: 44 additions & 24 deletions R/classicProcess.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ ClassicProcess <- function(jaspResults, dataset = NULL, options) {
.procModelSummaryTable(jaspResults, options, NULL)
return()
}
# Read dataset
dataset <- .procReadData(options)
# Check for errors in dataset
.procErrorHandling(dataset, options)
# Create a container for each model
Expand Down Expand Up @@ -83,7 +81,7 @@ ClassicProcess <- function(jaspResults, dataset = NULL, options) {
"meanCenteredModeration", "standardizedModelEstimates", "errorCalculationMethod", "bootstrapCiType",
"mcmcBurnin", "mcmcSamples", "mcmcChains", "seed", "setSeed", "nuPriorMu",
"nuPriorSigma", "betaPriorMu", "betaPriorSigma", "psiPriorAlpha",
"psiPriorBeta", "rhoPriorAlpha", "rhoPriorBeta"
"psiPriorBeta", "rhoPriorAlpha", "rhoPriorBeta", "moderationProbes"
))
}

Expand Down Expand Up @@ -394,10 +392,10 @@ ClassicProcess <- function(jaspResults, dataset = NULL, options) {
# Get encoding
encoding <- .procVarEncoding()

independent <- modelOptions[["modelNumberIndependent"]][["value"]]
mediators <- modelOptions[["modelNumberMediators" ]][["value"]]
modW <- modelOptions[["modelNumberModeratorW" ]][["value"]]
modZ <- modelOptions[["modelNumberModeratorZ" ]][["value"]]
independent <- modelOptions[["modelNumberIndependent"]]
mediators <- modelOptions[["modelNumberMediators" ]]
modW <- modelOptions[["modelNumberModeratorW" ]]
modZ <- modelOptions[["modelNumberModeratorZ" ]]

# Apply the JASP coding to X, W, Z, and M if the user has specified the variables and 'vars' still contains the dummy version
if (independent != "" && encoding$X %in% vars) {
Expand Down Expand Up @@ -468,16 +466,6 @@ ClassicProcess <- function(jaspResults, dataset = NULL, options) {
return(graph)
}

.procReadData <- function(options) {
# Read in selected variables from dataset
dataset <- .readDataSetToEnd(
columns.as.numeric = c(options[['dependent']], options[['covariates']]),
columns.as.factor = options[['factors']]
)

return(dataset)
}

.procAddFactorDummyIntVars <- function(jaspResults, dataset, options) {
modelsContainer <- jaspResults[["modelsContainer"]]

Expand Down Expand Up @@ -651,7 +639,7 @@ ClassicProcess <- function(jaspResults, dataset = NULL, options) {
if (length(options[["covariates"]]) > 1) {
.hasErrors(dataset, "run",
type = "varCovData",
varCovData.target = options[["covariates"]],
varCovData.target = c(options[["dependent"]], options[["covariates"]]),
varCovData.corFun = stats::cov,
varCovData.corArgs = list(use = "complete.obs"),
exitAnalysisIfErrors = TRUE
Expand Down Expand Up @@ -1314,6 +1302,18 @@ ClassicProcess <- function(jaspResults, dataset = NULL, options) {
return(fittedModel)
}

.procCheckImpliedVarianceRatios <- function(fittedModel) {
impliedVariances <- diag(fittedModel@implied[["cov"]][[1]])

return(any(outer(impliedVariances, impliedVariances, FUN = "/") > 1000))
}

.procCheckImpliedVarianceMagnitudes <- function(fittedModel) {
impliedVariances <- diag(fittedModel@implied[["cov"]][[1]])

return(any(impliedVariances > 1000000))
}

.procResultsFitModel <- function(container, dataset, options, modelOptions) {
# Check if graph has error message
if (!.procCheckGraph(container[["graph"]]$object) && jaspBase::isTryError(container[["graph"]]$object)) {
Expand Down Expand Up @@ -1346,6 +1346,15 @@ ClassicProcess <- function(jaspResults, dataset = NULL, options) {
return(.procLavaanMsg(fittedModel))
}

if (doFit && is.null(lavaan::vcov(fittedModel))) {
checkImpliedVarianceRatios <- .procCheckImpliedVarianceRatios(fittedModel)
checkImpliedVarianceMagnitudes <- .procCheckImpliedVarianceMagnitudes(fittedModel)
return(.procNotIdentifiedMsg(
impliedVarianceRatios = checkImpliedVarianceRatios,
impliedVarianceMagnitudes = checkImpliedVarianceMagnitudes
))
}

if (doFit) {
if (options$errorCalculationMethod == "bootstrap") {
fittedModel <- .procBootstrap(fittedModel, options$bootstrapSamples)
Expand Down Expand Up @@ -1481,10 +1490,10 @@ ClassicProcess <- function(jaspResults, dataset = NULL, options) {

# Create model options dummy object
modelOptions <- list(
modelNumberIndependent = list(value = independent),
modelNumberMediators = list(value = mediators),
modelNumberModeratorW = list(value = modW),
modelNumberModeratorZ = list(value = modZ)
modelNumberIndependent = independent,
modelNumberMediators = mediators,
modelNumberModeratorW = modW,
modelNumberModeratorZ = modZ
)

# Check which hard-coded model matches user model
Expand All @@ -1511,7 +1520,7 @@ ClassicProcess <- function(jaspResults, dataset = NULL, options) {
}
}

.procModelSummaryTable <- function(jaspResults, options, modelsContainer) {
.procModelSummaryTable <- function(jaspResults, options, modelsContainer, errors) {
if (!is.null(jaspResults[["modelSummaryTable"]])) return()

modelNumbers <- lapply(options[["processModels"]], function(mod) {
Expand All @@ -1525,7 +1534,7 @@ ClassicProcess <- function(jaspResults, dataset = NULL, options) {
modelNames <- sapply(options[["processModels"]], function(mod) mod[["name"]])

procResults <- lapply(options[["processModels"]], function(mod) modelsContainer[[mod[["name"]]]][["fittedModel"]]$object)

if (length(procResults) == 0) return()

# Remove invalid models
Expand Down Expand Up @@ -2775,6 +2784,17 @@ ClassicProcess <- function(jaspResults, dataset = NULL, options) {

.procConvergenceMsg <- function() gettext("Model did not converge.")

.procNotIdentifiedMsg <- function(impliedVarianceRatios = FALSE, impliedVarianceMagnitudes = FALSE) {
reasons <- c()
if (impliedVarianceRatios) {
reasons <- c(reasons, gettext("<li>Some implied model variances are > 1,000,000</li>"))
}
if (impliedVarianceMagnitudes) {
reasons <- c(reasons, gettext("<li>Some implied model variances are at least a factor 1000 times larger than others</li>"))
}
gettextf("The information matrix could not be inverted. This may be a symptom that the model is not identified. Possible reasons: <ul>%s</ul>", paste(reasons, collapse = ""))
}

.procModelIncompleteMsg <- function() gettext("At least one model is incomplete or no model is specified. Please add at least one model and complete specified models.")

.procInformationCriteriaMsg <- function() gettext("The AIC, BIC and additional information criteria are only available with ML-type estimators.")
Expand Down
1 change: 1 addition & 0 deletions inst/Description.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Description
maintainer : "JASP Team <[email protected]>"
website : "https://jasp-stats.org"
license : "GPL (>= 2)"
preloadData : true

GroupTitle
{
Expand Down
1 change: 0 additions & 1 deletion inst/qml/BayesianProcess.qml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ Form
Common.InputVariables {
visible: inputType.value == "inputVariables"
adjustedWidth: models.width - 2 * jaspTheme.contentMargin
colWidth: (models.width - 3 * 40 * preferencesModel.uiScale) / 4
}

Common.InputModelNumber {
Expand Down
5 changes: 2 additions & 3 deletions inst/qml/ClassicProcess.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ Form
{
Common.VariablesForm {}


Section
{
title: qsTr("Models")
columns: 1


TabView
{
id: models
Expand All @@ -44,6 +42,7 @@ Form
content: Group
{
childControlsArea.anchors.leftMargin: jaspTheme.contentMargin

Common.InputType
{
id: inputType
Expand All @@ -56,7 +55,6 @@ Form
{
visible: inputType.value == "inputVariables"
adjustedWidth: models.width - 2 * jaspTheme.contentMargin
colWidth: (models.width - 3 * 40 * preferencesModel.uiScale) / 4
}

Common.InputModelNumber
Expand Down Expand Up @@ -230,6 +228,7 @@ Form

Common.PathPlotOptions {}
}

Section
{
id: advanced
Expand Down
2 changes: 1 addition & 1 deletion inst/qml/common/InputModelNumber.qml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Group
{
name: "modelNumberMediators"
title: qsTr("Mediators M")
allowedColumns: ["scale", "ordinal"]
allowedColumns: ["scale", "nominal"]
}
// TODO
// AssignedVariablesList
Expand Down
42 changes: 8 additions & 34 deletions inst/qml/common/InputVariables.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,10 @@ import JASP.Controls

Group
{
property int adjustedWidth: parent.width

id: modelsGroup

property int colWidth: parent.width / 4 - jaspTheme.contentMargin
property int labelWidth: modelsGroup.colWidth + jaspTheme.contentMargin

RowLayout
{
Layout.margins: jaspTheme.contentMargin
Label
{
text: qsTr("From")
Layout.preferredWidth: modelsGroup.labelWidth
}
Label
{

text: qsTr("To")
Layout.preferredWidth: modelsGroup.labelWidth
}
Label
{
text: qsTr("Process Type")
Layout.preferredWidth: modelsGroup.labelWidth
}
Label
{
text: qsTr("Process Variable")
Layout.preferredWidth: modelsGroup.labelWidth
}
}
property int adjustedWidth: parent.width
property int colWidth: (adjustedWidth / 4) - 4 * jaspTheme.contentMargin

ComponentsList
{
Expand All @@ -63,18 +35,20 @@ Group
preferredWidth: adjustedWidth
itemRectangle.color: jaspTheme.controlBackgroundColor
minimumItems: 1
headerLabels: [qsTr("From "), qsTr("To"), qsTr("Process Type"), qsTr("Process Variable")]
rowComponent: RowLayout
{
id: rowComp
enabled: rowIndex === relations.count - 1
spacing: jaspTheme.contentMargin

Layout.columnSpan: 4
DropDown
{
id: procIndep
name: 'processIndependent'
source: ['covariates', 'factors']
controlMinWidth: modelsGroup.colWidth
fieldWidth: modelsGroup.colWidth
addEmptyValue: true
onCurrentValueChanged:
{
Expand All @@ -93,7 +67,7 @@ Group
id: procDep
name: 'processDependent'
source: ["dependent", "processVariable"] //, {name: "processRelationships.processVariable", use: "discardIndex=" + (relations.count - 1)}]
controlMinWidth: modelsGroup.colWidth
fieldWidth: modelsGroup.colWidth
addEmptyValue: true
onCurrentValueChanged:
{
Expand All @@ -118,7 +92,7 @@ Group
{ label: qsTr("Confounder"), value: 'confounders' },
{ label: qsTr("Direct"), value: 'directs' }
]
controlMinWidth: modelsGroup.colWidth
fieldWidth: modelsGroup.colWidth
addEmptyValue: true
onCurrentValueChanged:
{
Expand All @@ -134,7 +108,7 @@ Group
name: 'processVariable'
enabled: procType.currentValue != "directs"
source: procType.currentValue == 'mediators' ? ['covariates'] : ['covariates', 'factors']
controlMinWidth: modelsGroup.colWidth
fieldWidth: modelsGroup.colWidth
addEmptyValue: true
onCurrentValueChanged:
{
Expand Down
Loading
Loading