-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6b742e
commit 8f11ab2
Showing
6 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{α}}{\eqn{\alpha}{alpha}} < 0.5 is unacceptable, | ||
#' 0.5 < \ifelse{html}{\out{α}}{\eqn{\alpha}{alpha}} < 0.6 is poor, | ||
#' 0.6 < \ifelse{html}{\out{α}}{\eqn{\alpha}{alpha}} < 0.7 is questionable, | ||
#' 0.7 < \ifelse{html}{\out{α}}{\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, ...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.