Skip to content

Commit

Permalink
Merge pull request #622 from easystats/iss620
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke authored Oct 24, 2021
2 parents 1b9763c + 7337964 commit a6b742b
Show file tree
Hide file tree
Showing 27 changed files with 257 additions and 156 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Depends:
Imports:
bayestestR (>= 0.11.0),
datawizard (>= 0.2.1),
insight (>= 0.14.4),
insight (>= 0.14.5),
graphics,
methods,
stats,
Expand Down Expand Up @@ -101,7 +101,7 @@ Suggests:
dplyr,
drc,
DRR,
effectsize (>= 0.5),
effectsize (>= 0.5.0.1),
EGAnet (>= 0.7),
emmeans (>= 1.7.0),
factoextra,
Expand Down Expand Up @@ -174,6 +174,8 @@ Suggests:
truncreg,
VGAM,
WRS2
Remotes:
easystats/effectsize
VignetteBuilder:
knitr
Encoding: UTF-8
Expand Down
54 changes: 30 additions & 24 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@

## Changes to functions

* `model_parameters()` for `merMod` models now also computes CIs for the
random SD parameters when `ci_method="boot"` (previously, this was only
possible when `ci_method` was `"profile"`).
* `model_parameters()` for `merMod` models now also computes CIs for the random
SD parameters when `ci_method="boot"` (previously, this was only possible when
`ci_method` was `"profile"`).

* `model_parameters()` for `glmmTMB` models now computes CIs for the
random SD parameters. Note that these are based on a Wald-z-distribution.
* `model_parameters()` for `glmmTMB` models now computes CIs for the random SD
parameters. Note that these are based on a Wald-z-distribution.

* Similar to `model_parameters.htest()`, the `model_parameters.BFBayesFactor()`
method gains `cohens_d` and `cramers_v` arguments to control if you need to
add frequentist effect size estimates to the returned summary dataframe.
Previously, this was done by default.

## Bug fixes

Expand Down Expand Up @@ -56,13 +61,14 @@ necessary changes before this breaking change is implemented.

## General

* The handling to approximate the degrees of freedom in `model_parameters()`,
* The handling to approximate the degrees of freedom in `model_parameters()`,
`ci()` and `p_value()` was revised and should now be more consistent. Some
bugs related to the previous computation of confidence intervals and p-values
have been fixed. Now it is possible to change the method to approximate
have been fixed. Now it is possible to change the method to approximate
degrees of freedom for CIs and p-values using the `ci_method`, resp. `method`
argument. This change has been documented in detail in `?model_parameters`,
and online here: https://easystats.github.io/parameters/reference/model_parameters.html
argument. This change has been documented in detail in `?model_parameters`,
and online here:
https://easystats.github.io/parameters/reference/model_parameters.html

* Minor changes to `print()` for *glmmTMB* with dispersion parameter.

Expand All @@ -82,8 +88,8 @@ necessary changes before this breaking change is implemented.
option for the `ci_method` (resp. `method`) argument, to explicitly calculate
confidence intervals based on the residual degrees of freedom, when present.

* `model_parameters()` supports following new objects:
`trimcibt`, `wmcpAKP`, `dep.effect` (in *WRS2* package), `systemfit`
* `model_parameters()` supports following new objects: `trimcibt`, `wmcpAKP`,
`dep.effect` (in *WRS2* package), `systemfit`

* `model_parameters()` gains a new argument `table_wide` for ANOVA tables. This
can be helpful for users who may wish to report ANOVA table in wide format
Expand All @@ -99,19 +105,19 @@ necessary changes before this breaking change is implemented.
not the default value, the printed output includes a message indicating which
approximation-method for degrees of freedom was used.

* `model_parameters()` for mixed models with `ci_method = "profile` computes
(profiled) confidence intervals for both fixed and random effects. Thus,
`ci_method = "profile` allows to add confidence intervals to the random
effect variances.
* `model_parameters()` for mixed models with `ci_method = "profile` computes
(profiled) confidence intervals for both fixed and random effects. Thus,
`ci_method = "profile` allows to add confidence intervals to the random effect
variances.

* `model_parameters()` should longer fail for supported model classes when
robust standard errors are not available.

### Other functions

* `n_factors()` the methods based on fit indices have been fixed and can be
included separately (`package = "fit"`). Also added a `n_max` argument to
crop the output.
* `n_factors()` the methods based on fit indices have been fixed and can be
included separately (`package = "fit"`). Also added a `n_max` argument to crop
the output.

* `compare_parameters()` now also accepts a list of model objects.

Expand All @@ -121,9 +127,9 @@ necessary changes before this breaking change is implemented.
* `format_parameters()` removes dots and underscores from parameter names, to
make these more "human readable".

* The experimental calculation of p-values in `equivalence_test()` was
replaced by a proper calculation p-values. The argument `p_value` was removed
and p-values are now always included.
* The experimental calculation of p-values in `equivalence_test()` was replaced
by a proper calculation p-values. The argument `p_value` was removed and
p-values are now always included.

* Minor improvements to `print()`, `print_html()` and `print_md()`.

Expand All @@ -139,7 +145,7 @@ necessary changes before this breaking change is implemented.
returned residual degrees of freedom in the statistic column, but confidence
intervals were based on `Inf` degrees of freedom instead.

* Fixed issue in `ci_satterthwaite()`, which used `Inf` degrees of freedom
* Fixed issue in `ci_satterthwaite()`, which used `Inf` degrees of freedom
instead of the Satterthwaite approximation.

* Fixed issue in `model_parameters.mlm()` when model contained interaction
Expand All @@ -151,8 +157,8 @@ necessary changes before this breaking change is implemented.
* Fixed sign error for `model_parameters.htest()` for objects created with
`t.test.formula()` (issue #552)

* Fixed issue when computing random effect variances in `model_parameters()`
for mixed models with categorical random slopes.
* Fixed issue when computing random effect variances in `model_parameters()` for
mixed models with categorical random slopes.

# parameters 0.14.0

Expand Down
1 change: 0 additions & 1 deletion R/1_model_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ parameters <- model_parameters
#' # different p-value style in output
#' model_parameters(model, p_digits = 5)
#' model_parameters(model, digits = 3, ci_digits = 4, p_digits = "scientific")
#'
#' \donttest{
#' # logistic regression model
#' model <- glm(vs ~ wt + cyl, data = mtcars, family = "binomial")
Expand Down
1 change: 0 additions & 1 deletion R/2_ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ ci.glm <- function(x,
method = "profile",
robust = FALSE,
...) {

method <- match.arg(method, choices = c("profile", "wald", "normal", "residual"))
if (method == "profile") {
out <- lapply(ci, function(i) .ci_profiled(model = x, ci = i))
Expand Down
1 change: 0 additions & 1 deletion R/check_heterogeneity.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#'
#' @export
check_heterogeneity <- function(x, select = NULL, group = NULL) {

.Deprecated("performance::check_heterogeneity_bias()")

if (insight::is_model(x)) {
Expand Down
8 changes: 5 additions & 3 deletions R/ci_generic.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
method <- "wald"
}
method <- tolower(method)
method <- match.arg(method, choices = c("wald", "ml1", "betwithin", "kr",
"satterthwaite", "kenward", "boot",
"profile", "residual", "normal"))
method <- match.arg(method, choices = c(
"wald", "ml1", "betwithin", "kr",
"satterthwaite", "kenward", "boot",
"profile", "residual", "normal"
))

effects <- match.arg(effects)
component <- match.arg(component)
Expand Down
1 change: 0 additions & 1 deletion R/cluster_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,3 @@ print.cluster_analysis <- function(x, digits = 2, ...) {

list(model = model, clusters = model$cluster)
}

1 change: 0 additions & 1 deletion R/dof.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ degrees_of_freedom <- function(model, ...) {
#' @rdname degrees_of_freedom
#' @export
degrees_of_freedom.default <- function(model, method = "analytical", ...) {

if (is.null(method)) {
method <- "wald"
}
Expand Down
39 changes: 21 additions & 18 deletions R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -656,22 +656,24 @@ format.parameters_distribution <- function(x, digits = 2, format = NULL, ci_widt
}

string_tailed <- switch(toupper(ci_method),
"HDI" = "highest-density",
"UNIROOT" = ,
"PROFILE" = "profile-likelihood",
"equal-tailed")
"HDI" = "highest-density",
"UNIROOT" = ,
"PROFILE" = "profile-likelihood",
"equal-tailed"
)

string_method <- switch(toupper(ci_method),
"BCI" = ,
"BCAI" = "bias-corrected accelerated bootstrap",
"SI" = ,
"CI" = ,
"QUANTILE" = ,
"ETI" = ,
"HDI" = ifelse(isTRUE(bootstrap), "na\u0131ve bootstrap", "MCMC"),
"NORMAL" = "Wald normal",
"BOOT" = "parametric bootstrap",
"Wald")
"BCI" = ,
"BCAI" = "bias-corrected accelerated bootstrap",
"SI" = ,
"CI" = ,
"QUANTILE" = ,
"ETI" = ,
"HDI" = ifelse(isTRUE(bootstrap), "na\u0131ve bootstrap", "MCMC"),
"NORMAL" = "Wald normal",
"BOOT" = "parametric bootstrap",
"Wald"
)

if (toupper(ci_method) %in% c("KENWARD", "KR", "KENWARD-ROGER", "KENWARD-ROGERS", "SATTERTHWAITE")) {
string_approx <- paste0("with ", format_df_adjust(ci_method, approx_string = "", dof_string = ""), " ")
Expand All @@ -681,10 +683,11 @@ format.parameters_distribution <- function(x, digits = 2, format = NULL, ci_widt

if (!is.null(test_statistic) && !ci_method %in% c("normal") && !isTRUE(bootstrap)) {
string_statistic <- switch(tolower(test_statistic),
"t-statistic" = "t",
"chi-squared statistic" = ,
"z-statistic" = "z",
"")
"t-statistic" = "t",
"chi-squared statistic" = ,
"z-statistic" = "z",
""
)
string_method <- paste0(string_method, " ", string_statistic, "-")
} else {
string_method <- paste0(string_method, " ")
Expand Down
15 changes: 13 additions & 2 deletions R/methods_BayesFactor.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@

#' Parameters from BayesFactor objects
#'
#' Parameters from BayesFactor objects.
#' Parameters from `BFBayesFactor` objects from `{BayesFactor}` package.
#'
#' @param model Object of class `BFBayesFactor`.
#' @param cohens_d If `TRUE`, compute Cohens' *d* as index of effect size. Only
#' applies to objects from `ttestBF()`. See `effectsize::cohens_d()` for
#' details.
#' @inheritParams bayestestR::describe_posterior
#' @inheritParams p_value
#' @inheritParams model_parameters.htest
#'
#' @details
#' The meaning of the extracted parameters:
Expand All @@ -30,6 +34,7 @@
#' if (require("BayesFactor")) {
#' model <- ttestBF(x = rnorm(100, 1, 1))
#' model_parameters(model)
#' model_parameters(model, cohens_d = TRUE, ci = .9)
#' }
#' }
#' @return A data frame of indices related to the model's parameters.
Expand All @@ -43,6 +48,8 @@ model_parameters.BFBayesFactor <- function(model,
rope_range = "default",
rope_ci = 0.95,
priors = TRUE,
cohens_d = NULL,
cramers_v = NULL,
verbose = TRUE,
...) {
if (any(grepl("^Null", names(model@numerator)))) {
Expand Down Expand Up @@ -103,7 +110,11 @@ model_parameters.BFBayesFactor <- function(model,
)

# Effect size?
if (requireNamespace("effectsize", quietly = TRUE) && bf_type %in% c("ttest1", "ttest2", "xtable")) {
if (bf_type %in% c("ttest1", "ttest2") && !is.null(cohens_d) ||
bf_type == "xtable" && !is.null(cramers_v)) {
# needs {effectsize} to be installed
insight::check_if_installed("effectsize")

tryCatch(
{
effsize <- effectsize::effectsize(model,
Expand Down
1 change: 0 additions & 1 deletion R/methods_betareg.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ ci.betareg <- function(x,
ci = .95,
component = "all",
...) {

component <- match.arg(component, choices = c("all", "conditional", "precision"))
.ci_generic(model = x, ci = ci, dof = Inf, component = component)
}
Expand Down
1 change: 0 additions & 1 deletion R/methods_dbscan.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#' @inheritParams cluster_centers
#'
#' @examples
#'
#' \donttest{
#' # DBSCAN ---------------------------
#' if (require("dbscan", quietly = TRUE)) {
Expand Down
1 change: 0 additions & 1 deletion R/methods_glmmTMB.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ ci.glmmTMB <- function(x,
component = "all",
verbose = TRUE,
...) {

method <- tolower(method)
method <- match.arg(method, choices = c("wald", "normal", "ml1", "betwithin", "profile", "uniroot"))
component <- match.arg(component, choices = c("all", "conditional", "zi", "zero_inflated", "dispersion"))
Expand Down
17 changes: 15 additions & 2 deletions R/methods_htest.R
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,22 @@ model_parameters.pairwise.htest <- function(model, verbose = TRUE, ...) {
# chi2- and mcnemar-test -----------
out <- .extract_htest_chi2(model)
if (grepl("^McNemar", model$method)) {
out <- .add_effectsize_mcnemar(model, out, cohens_g = cohens_g, ci = ci, verbose = verbose)
out <- .add_effectsize_mcnemar(model,
out,
cohens_g = cohens_g,
ci = ci,
verbose = verbose
)
} else {
out <- .add_effectsize_chi2(model, out, cramers_v = cramers_v, phi = phi, ci = ci, alternative = alternative, verbose = verbose)
out <- .add_effectsize_chi2(
model,
out,
cramers_v = cramers_v,
phi = phi,
ci = ci,
alternative = alternative,
verbose = verbose
)
}
} else if (m_info$is_proptest) {

Expand Down
13 changes: 7 additions & 6 deletions R/methods_lme4.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ model_parameters.merMod <- function(model,
ci_method <- "quantile"
} else {
ci_method <- switch(insight::find_statistic(model),
"t-statistic" = "residual",
"wald"
"t-statistic" = "residual",
"wald"
)
}
}
Expand Down Expand Up @@ -236,11 +236,12 @@ ci.merMod <- function(x,
robust = FALSE,
iterations = 500,
...) {

method <- tolower(method)
method <- match.arg(method, choices = c("wald", "ml1", "betwithin", "kr",
"satterthwaite", "kenward", "boot",
"profile", "residual", "normal"))
method <- match.arg(method, choices = c(
"wald", "ml1", "betwithin", "kr",
"satterthwaite", "kenward", "boot",
"profile", "residual", "normal"
))

# bootstrapping
if (method == "boot") {
Expand Down
2 changes: 1 addition & 1 deletion R/methods_survival.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ p_value.coxph <- function(model, ...) {

# convert in case of z
if (identical(statistic, "z-statistic")) {
params$Statistic <- params$Statistic ^ 2
params$Statistic <- params$Statistic^2
}

.data_frame(
Expand Down
Loading

0 comments on commit a6b742b

Please sign in to comment.