Skip to content

Commit

Permalink
draft
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jan 8, 2024
1 parent d6b742e commit 8f11ab2
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: performance
Title: Assessment of Regression Models Performance
Version: 0.10.8.9
Version: 0.10.8.10
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ S3method(logLik,iv_robust)
S3method(logLik,ivreg)
S3method(logLik,plm)
S3method(logLik,svycoxph)
S3method(mcdonalds_omega,data.frame)
S3method(mcdonalds_omega,matrix)
S3method(model_performance,Arima)
S3method(model_performance,BFBayesFactor)
S3method(model_performance,DirichletRegModel)
Expand Down Expand Up @@ -542,6 +544,7 @@ export(item_reliability)
export(item_split_half)
export(looic)
export(mae)
export(mcdonalds_omega)
export(model_performance)
export(mse)
export(multicollinearity)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# performance 0.10.9

## New functions

* `mcdonalds_omega()` to calculate McDonald's Omega for a scale.

## Changes

* `r2()` for models of class `glmmTMB` without random effects now returns the
Expand Down
55 changes: 55 additions & 0 deletions R/mcdonalds_omega.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#' @title McDonald's Omega for Items or Scales
#' @name mcdonalds_omega
#'
#' @description Compute various measures of internal consistencies
#' for tests or item-scales of questionnaires.
#'
#' @param x A matrix or a data frame.
#' @param ... Currently not used.
#'
#' @return The McDonald's Omega value for `x`.
#'
#' @details The McDonald's Omega value for `x`. A value closer to 1
#' indicates greater internal consistency, where usually following
#' rule of thumb is applied to interpret the results:
#' \ifelse{html}{\out{&alpha;}}{\eqn{\alpha}{alpha}} < 0.5 is unacceptable,
#' 0.5 < \ifelse{html}{\out{&alpha;}}{\eqn{\alpha}{alpha}} < 0.6 is poor,
#' 0.6 < \ifelse{html}{\out{&alpha;}}{\eqn{\alpha}{alpha}} < 0.7 is questionable,
#' 0.7 < \ifelse{html}{\out{&alpha;}}{\eqn{\alpha}{alpha}} < 0.8 is acceptable,
#' and everything > 0.8 is good or excellent.
#'
#' @references Bland, J. M., and Altman, D. G. Statistics notes: Cronbach's
#' alpha. BMJ 1997;314:572. 10.1136/bmj.314.7080.572
#'
#' @examples
#' data(mtcars)
#' x <- mtcars[, c("cyl", "gear", "carb", "hp")]
#' mcdonalds_omega(x)
#' @export
mcdonalds_omega <- function(x, ...) {
UseMethod("mcdonalds_omega")
}


#' @export
mcdonalds_omega.data.frame <- function(x, verbose = TRUE, ...) {
# remove missings
.data <- stats::na.omit(x)

# we need at least two columns for Cronach's Alpha
if (is.null(ncol(.data)) || ncol(.data) < 2) {
if (verbose) {
insight::format_warning("Too few columns in `x` to compute McDonald's Omega.")
}
return(NULL)
}

# Compute Cronbach's Alpha
dim(.data)[2] / (dim(.data)[2] - 1) * (1 - sum(apply(.data, 2, stats::var)) / stats::var(rowSums(.data)))
}


#' @export
mcdonalds_omega.matrix <- function(x, verbose = TRUE, ...) {
mcdonalds_omega(as.data.frame(x), verbose = verbose, ...)
}
1 change: 1 addition & 0 deletions _pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ reference:
contents:
- check_itemscale
- cronbachs_alpha
- mcdonalds_omega
- starts_with("item_")

- title: "Comparing and Testing Models"
Expand Down
39 changes: 39 additions & 0 deletions man/mcdonalds_omega.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8f11ab2

Please sign in to comment.