Skip to content

Commit

Permalink
small renamings, fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DominiqueMakowski committed Mar 18, 2019
1 parent 2995364 commit 13a9b07
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ S3method(r2_nagelkerke,glm)
S3method(r2_nagelkerke,multinom)
S3method(r2_nagelkerke,polr)
S3method(r2_nagelkerke,vglm)
export(cronbachs_alpha)
export(alpha_cronbach)
export(error_rate)
export(icc)
export(item_difficulty)
Expand Down Expand Up @@ -92,6 +92,7 @@ importFrom(stats,nobs)
importFrom(stats,pchisq)
importFrom(stats,predict)
importFrom(stats,predict.glm)
importFrom(stats,quantile)
importFrom(stats,reformulate)
importFrom(stats,residuals)
importFrom(stats,sd)
Expand Down
6 changes: 3 additions & 3 deletions R/cronbachs_alpha.R → R/alpha_cronbach.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' @title Cronbach's Alpha for Items or Scales
#' @name cronbachs_alpha
#' @name alpha_cronbach
#'
#' @description Compute various measures of internal consistencies
#' for tests or item-scales of questionnaires.
Expand All @@ -20,11 +20,11 @@
#' @examples
#' data(mtcars)
#' x <- mtcars[, c("cyl", "gear", "carb", "hp")]
#' cronbachs_alpha(x)
#' alpha_cronbach(x)
#'
#' @importFrom stats var na.omit
#' @export
cronbachs_alpha <- function(x) {
alpha_cronbach <- function(x) {

This comment has been minimized.

Copy link
@strengejacke

strengejacke Mar 18, 2019

Member

I'm not sure, I think this name sounds strange. Though we have the other functions named r2_name() as well, I think this case is different, because we have no other alphas.

This comment has been minimized.

Copy link
@DominiqueMakowski

DominiqueMakowski Mar 18, 2019

Author Member

Ok, as you want (to me it sounds ok because in France we say "alpha de Cronbach", so I might be biased)! Let's stick with cronbachs_alpha then ☺️
Although maybe without the plural's "s"?

This comment has been minimized.

Copy link
@strengejacke

strengejacke Mar 18, 2019

Member

It's not the plural-s, it's the possessive pronoun-s, like the de in French. ;-) I think, as this statistic is an "eigenname", we should just name it cronbachs_alpha.

This comment has been minimized.

Copy link
@DominiqueMakowski

DominiqueMakowski Mar 18, 2019

Author Member

oh yes, the possessive, my mistake. Let's keep cronbachs_alpha ^^

# remove missings
.data <- stats::na.omit(x)

Expand Down
13 changes: 9 additions & 4 deletions R/icc.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#' the prediction. If \code{NULL} (default), include all group-level effects.
#' Else, for instance for nested models, name a specific group-level effect
#' to calculate the variance decomposition for this group-level.
#' @param ci The Credible Interval level.
#' @param ... Currently not used.
#'
#' @inheritParams r2_bayes
Expand Down Expand Up @@ -74,7 +75,6 @@
#' }
#'
#' @importFrom insight model_info get_variances
#' @importFrom stats var
#' @export
icc <- function(model, ...) {
UseMethod("icc")
Expand All @@ -99,15 +99,20 @@ icc.default <- function(model, ...) {
)
}





#' @importFrom stats quantile
#' @rdname icc
#' @export
icc.brmsfit <- function(model, re.form = NULL, robust = TRUE, ci.lvl = .95, ...) {
icc.brmsfit <- function(model, re.form = NULL, robust = TRUE, ci = .95, ...) {
if (!insight::model_info(model)$is_mixed) {
stop("'model' has no random effects.", call. = FALSE)
}

if (!requireNamespace("brms", quietly = TRUE)) {
stop("Please install and load package `brms` first.", call. = F)
stop("Please install and load package `brms` first.", call. = FALSE)
}

PPD <- brms::posterior_predict(model, re.form = re.form, summary = FALSE)
Expand All @@ -123,6 +128,6 @@ icc.brmsfit <- function(model, re.form = NULL, robust = TRUE, ci.lvl = .95, ...)

list(
"ICC_decomposed" = 1 - fun(tau.00 / total_var),
"CI" = 1 - quantile(tau.00 / total_var, probs = c((1 - ci.lvl) / 2, (1 + ci.lvl) / 2))
"ICC_CI" = 1 - quantile(tau.00 / total_var, probs = c((1 - ci) / 2, (1 + ci) / 2))
)
}
8 changes: 4 additions & 4 deletions man/cronbachs_alpha.Rd → man/alpha_cronbach.Rd

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

4 changes: 3 additions & 1 deletion man/icc.Rd

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

18 changes: 11 additions & 7 deletions tests/testthat/test-model_performance.bayesian.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ test_that("model_performance.stanreg", {
model <- circus::download_model("stanreg_lm_1")
perf <- model_performance(model)

testthat::expect_equal(perf$R2_Median, 0.826, tolerance = 0.01)
testthat::expect_equal(perf$R2_LOO_adjusted, 0.791, tolerance = 0.01)
testthat::expect_equal(perf$ELPD, -78.52894, tolerance = 0.01)
testthat::expect_equal(perf$R2_Median, 0.751, tolerance = 0.01)
testthat::expect_equal(perf$R2_LOO_adjusted, 0.7094, tolerance = 0.01)
testthat::expect_equal(perf$ELPD, -83.514, tolerance = 0.01)

model <- circus::download_model("stanreg_lm_2")
testthat::expect_error(model_performance(model)) ## FIXME
perf <- model_performance(model)

testthat::expect_equal(perf$R2_Median, 0.6392, tolerance = 0.01)
testthat::expect_equal(perf$R2_LOO_adjusted, 0.587247, tolerance = 0.01)
testthat::expect_equal(perf$ELPD, -31.622, tolerance = 0.01)

model <- circus::download_model("stanreg_lmerMod_1")
perf <- model_performance(model)

testthat::expect_equal(perf$R2_Median, 0.6384912, tolerance = 0.01)
testthat::expect_equal(perf$R2_LOO_adjusted, 0.5902234, tolerance = 0.01)
testthat::expect_equal(perf$ELPD, -31.61927, tolerance = 0.01)
testthat::expect_equal(perf$R2_Median, 0.6392, tolerance = 0.01)
testthat::expect_equal(perf$R2_LOO_adjusted, 0.58724, tolerance = 0.01)
testthat::expect_equal(perf$ELPD, -31.622, tolerance = 0.01)
})


Expand Down

0 comments on commit 13a9b07

Please sign in to comment.