Skip to content

Commit

Permalink
Change Mahalanobis distance summary to showing (one-line) summary sta…
Browse files Browse the repository at this point in the history
…tistics and cases to exclude
  • Loading branch information
sjentsch committed Oct 31, 2024
1 parent 038c9e7 commit fefb471
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 30 deletions.
25 changes: 9 additions & 16 deletions R/linreg.b.R
Original file line number Diff line number Diff line change
Expand Up @@ -891,29 +891,22 @@ linRegClass <- R6::R6Class(
mahalp <- as.numeric(self$options$mahalp)
groups <- self$results$models
termsAll <- private$.getModelTerms()
print(termsAll)
print(mahal)

for (i in seq_along(termsAll)) {
table <- groups$get(key=i)$dataSummary$mahal
if (is.null(mahal[[i]])) {
table$setNote("row", .("Mahalanobis distance can only be calculated for models with two or more independent variables."))
# setAnalysisNotice(self, .("Mahalanobis distance can only be calculated for models with two or more independent variables."))
} else if (all(mahal[[i]]$p <= mahalp)) {
table$setNote(
"row",
jmvcore::format(.("There were no Mahalanobis distances with a threshold below p < {p}."), p = mahalp)
)
} else {
# select values below p-threshold (outliers)
selRow <- which(mahal[[i]]$p <= mahalp)
for (j in selRow)
table$addRow(rowKey = j, values = mahal[[i]][j, ])
table$setNote(
"row",
jmvcore::format(.("Filter syntax: {filter}"),
filter = paste(paste0("ROW() != ", mahal[[i]][selRow, "row"]), collapse = " and "))
)
# select which rows contain values below p-threshold (outliers)
mahalRow <- mahal[[i]][mahal[[i]]$p <= mahalp, "row"]
mahalVal = list(mean = mean(mahal[[i]]$chisq), median = median(mahal[[i]]$chisq), sd = sd(mahal[[i]]$chisq),
min = min(mahal[[i]]$chisq), max = max(mahal[[i]]$chisq), excRow = paste(mahalRow, collapse = ", "))
table$setRow(rowNo = 1, values = mahalVal)
table$setNote("excRow",
ifelse(length(mahalRow) == 0,
jmvcore::format(.("There were no Mahalanobis distances with a threshold below p < {p}."), p = mahalp),
jmvcore::format(.("Filter syntax: {filter}"), filter = paste(paste0("ROW() != ", mahalRow), collapse = " and "))))
}
}
},
Expand Down
28 changes: 21 additions & 7 deletions R/linreg.h.R
Original file line number Diff line number Diff line change
Expand Up @@ -665,25 +665,39 @@ linRegResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
options=options,
name="mahal",
title="Mahalanobis Distance",
rows=1,
visible="(mahal)",
clearWith=list(
"dep",
"blocks",
"weights"),
columns=list(
list(
`name`="row",
`title`="Row",
`name`="mean",
`title`="Mean",
`type`="number"),
list(
`name`="chisq",
`title`="Statistics",
`name`="median",
`title`="Median",
`type`="number"),
list(
`name`="p",
`title`="p",
`name`="sd",
`title`="SD",
`type`="number"),
list(
`name`="min",
`title`="Min",
`type`="number",
`superTitle`="Range"),
list(
`name`="max",
`title`="Max",
`type`="number",
`format`="zto,pvalue"))))}))$new(options=options))
`superTitle`="Range"),
list(
`name`="excRow",
`title`="Participants (rows) below p-threshold",
`type`="text"))))}))$new(options=options))
self$add(R6::R6Class(
inherit = jmvcore::Group,
active = list(
Expand Down
28 changes: 21 additions & 7 deletions jamovi/linreg.r.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,25 +273,39 @@ items:
- name: mahal
title: Mahalanobis Distance
type: Table
rows: 1
visible: (mahal)
clearWith:
- dep
- blocks
- weights

columns:
- name: row
title: Row
- name: mean
title: Mean
type: number

- name: chisq
title: Statistics
- name: median
title: Median
type: number

- name: p
title: p
- name: sd
title: SD
type: number
format: zto,pvalue

- name: min
title: Min
type: number
superTitle: Range

- name: max
title: Max
type: number
superTitle: Range

- name: excRow
title: Participants (rows) below p-threshold
type: text

- name: assump
title: Assumption Checks
Expand Down

0 comments on commit fefb471

Please sign in to comment.