Skip to content

Commit

Permalink
Merge branch 'mahalanobis' into influentialCases
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyDoorn committed Mar 28, 2024
2 parents c3b83c9 + 58f9858 commit 891b321
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
19 changes: 12 additions & 7 deletions R/generalizedlinearmodel.R
Original file line number Diff line number Diff line change
Expand Up @@ -908,14 +908,14 @@ GeneralizedLinearModelInternal <- function(jaspResults, dataset = NULL, options,
tableOptionsOn <- c(options[["dfbetas"]],
options[["dffits"]],
options[["covarianceRatio"]],
# options[["cooksDistance"]],
options[["leverage"]])
options[["leverage"]],
options[["mahalanobis"]])

if (!ready | !options[["residualCasewiseDiagnostic"]])
return()


tableOptions <- c("dfbetas", "dffits", "covarianceRatio", "leverage")
tableOptions <- c("dfbetas", "dffits", "covarianceRatio", "leverage", "mahalanobis")
tableOptionsClicked <- tableOptions[tableOptionsOn]
tableOptionsClicked <- c("cooksDistance", tableOptionsClicked)

Expand All @@ -936,7 +936,8 @@ GeneralizedLinearModelInternal <- function(jaspResults, dataset = NULL, options,
"dffits" = "DFFITS",
"covarianceRatio" = "Covariance Ratio",
"cooksDistance" = "Cook's Distance",
"leverage" = "Leverage")
"leverage" = "Leverage",
"mahalanobis" = "Mahalanobis")
}

if (is.null(model)) {
Expand Down Expand Up @@ -998,15 +999,20 @@ GeneralizedLinearModelInternal <- function(jaspResults, dataset = NULL, options,
}

influenceResData <- as.data.frame(influenceRes[["infmat"]][, colInd])
colnames(influenceResData)[1:length(colInd)] <- colNames[1:length(colInd)]

influenceResData[["caseN"]] <- seq.int(nrow(influenceResData))
influenceResData[["stdResidual"]] <- rstandard(model)
influenceResData[["dependent"]] <- model.frame(model)[[options$dependent]]
influenceResData[["predicted"]] <- model$fitted.values
influenceResData[["residual"]] <- model$residual

# browser()
modelMatrix <- as.data.frame(model.matrix(model))
modelMatrix <- modelMatrix[colnames(modelMatrix) != "(Intercept)"]
influenceResData[["mahalanobis"]] <- mahalanobis(modelMatrix, center = colMeans(modelMatrix), cov = cov(modelMatrix))

if (options$residualCasewiseDiagnosticType == "cooksDistance")
index <- which(abs(influenceResData[["cook.d"]]) > options$residualCasewiseDiagnosticCooksDistanceThreshold)
index <- which(abs(influenceResData[["cooksDistance"]]) > options$residualCasewiseDiagnosticCooksDistanceThreshold)
else if (options$residualCasewiseDiagnosticType == "outliersOutside")
index <- which(abs(influenceResData[["stdResidual"]]) > options$residualCasewiseDiagnosticZThreshold)
else # all
Expand All @@ -1017,7 +1023,6 @@ GeneralizedLinearModelInternal <- function(jaspResults, dataset = NULL, options,
colnames(influenceResSig) <- colNames[1:length(colInd)]

influenceResData <- influenceResData[index, ]
colnames(influenceResData) <- colNames

if (length(index) == 0)
influenceTable$addFootnote(gettext("No influential cases found."))
Expand Down
21 changes: 10 additions & 11 deletions inst/qml/RegressionLinear.qml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ Form
title: qsTr("Statistics")

columns: 2
Group
{
title: qsTr("Model Summary")
CheckBox { name: "rSquaredChange"; label: qsTr("R squared change") }
CheckBox { name: "fChange"; label: qsTr("F change") }
CheckBox { name: "modelAICBIC"; label: qsTr("AIC and BIC") }
CheckBox { name: "residualDurbinWatson"; label: qsTr("Durbin-Watson") }

}

Group
{
title: qsTr("Coefficients")
Expand Down Expand Up @@ -115,17 +125,6 @@ Form
CheckBox { name: "collinearityStatistic"; label: qsTr("Tolerance and VIF") }
CheckBox { name: "vovkSellke"; label: qsTr("Vovk-Sellke maximum p-ratio") }
}


Group
{
title: qsTr("Model Summary")
CheckBox { name: "rSquaredChange"; label: qsTr("R squared change") }
CheckBox { name: "fChange"; label: qsTr("F change") }
CheckBox { name: "modelAICBIC"; label: qsTr("AIC and BIC") }
CheckBox { name: "residualDurbinWatson"; label: qsTr("Durbin-Watson") }

}

Group
{
Expand Down
8 changes: 5 additions & 3 deletions inst/qml/common/OutlierComponent.qml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ Group

Group
{
CheckBox { name: "dfbetas"; label: qsTr("DFBETAS") }
CheckBox { name: "dffits"; label: qsTr("DFFITS") }
CheckBox { name: "dfbetas"; label: qsTr("DFBETAS") }
CheckBox { name: "dffits"; label: qsTr("DFFITS") }
CheckBox { name: "covarianceRatio"; label: qsTr("Cov ratio") }
CheckBox { name: "leverage"; label: qsTr("Leverage") }
CheckBox { name: "leverage"; label: qsTr("Leverage") }
CheckBox { name: "mahalanobis"; label: qsTr("Mahalanobis") }

}

}
Expand Down

0 comments on commit 891b321

Please sign in to comment.