Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: parameters
Title: Processing of Model Parameters
Version: 0.24.1.2
Version: 0.24.1.3
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ S3method(format,compare_parameters)
S3method(format,equivalence_test_lm)
S3method(format,p_calibrate)
S3method(format,parameters_brms_meta)
S3method(format,parameters_coef)
S3method(format,parameters_model)
S3method(format,parameters_p_function)
S3method(format,parameters_sem)
Expand Down Expand Up @@ -588,6 +589,7 @@ S3method(print,p_direction_lm)
S3method(print,p_significance_lm)
S3method(print,parameters_brms_meta)
S3method(print,parameters_clusters)
S3method(print,parameters_coef)
S3method(print,parameters_da)
S3method(print,parameters_efa)
S3method(print,parameters_efa_summary)
Expand Down
15 changes: 0 additions & 15 deletions R/1_model_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
#'
#' Compared to fixed effects (or single-level) models, determining appropriate
#' df for Wald-based inference in mixed models is more difficult.
#' See [the R GLMM FAQ](https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html#what-are-the-p-values-listed-by-summaryglmerfit-etc.-are-they-reliable)

Check warning on line 187 in R/1_model_parameters.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/1_model_parameters.R,line=187,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 151 characters.

Check warning on line 187 in R/1_model_parameters.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/1_model_parameters.R,line=187,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 151 characters.
#' for a discussion.
#'
#' Several approximate methods for computing df are available, but you should
Expand Down Expand Up @@ -476,7 +476,6 @@
#' @param include_info Logical, if `TRUE`, prints summary information about the
#' model (model formula, number of observations, residual standard deviation
#' and more).
#' @param summary Deprecated, please use `info` instead.
#' @param keep Character containing a regular expression pattern that
#' describes the parameters that should be included (for `keep`) or excluded
#' (for `drop`) in the returned data frame. `keep` may also be a
Expand Down Expand Up @@ -580,7 +579,6 @@
p_adjust = NULL,
vcov = NULL,
vcov_args = NULL,
summary = getOption("parameters_summary", FALSE),
include_info = getOption("parameters_info", FALSE),
keep = NULL,
drop = NULL,
Expand All @@ -589,12 +587,6 @@
# validation check for inputs
.is_model_valid(model)

## TODO remove deprecated later
if (!missing(summary)) {
.deprecated_warning("summary", "include_info", verbose)
include_info <- summary
}

# validation check, warn if unsupported argument is used.
# unsupported arguments will be removed from the argument list.
dots <- .check_dots(
Expand Down Expand Up @@ -777,20 +769,13 @@
p_adjust = NULL,
vcov = NULL,
vcov_args = NULL,
summary = getOption("parameters_summary", FALSE),
include_info = getOption("parameters_info", FALSE),
keep = NULL,
drop = NULL,
verbose = TRUE,
...) {
dots <- list(...)

## TODO remove deprecated later
if (!missing(summary)) {
.deprecated_warning("summary", "include_info", verbose)
include_info <- summary
}

# set default
if (is.null(ci_method)) {
if (isTRUE(bootstrap)) {
Expand Down
8 changes: 0 additions & 8 deletions R/dof_kenward.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ dof_kenward <- function(model) {
}



.divZero <- function(x, y, tol = 1e-14) {
## ratio x/y is set to 1 if both |x| and |y| are below tol
if (abs(x) < tol && abs(y) < tol) {
Expand All @@ -78,7 +77,6 @@ dof_kenward <- function(model) {
}



.vcov_kenward_ajusted <- function(model) {
insight::check_if_installed("lme4")

Expand Down Expand Up @@ -146,8 +144,6 @@ dof_kenward <- function(model) {
}




.index2UpperTriEntry <- function(k, N) {
## inverse of indexSymmat2vec
## result: index pair (i,j) with i>=j
Expand All @@ -161,8 +157,6 @@ dof_kenward <- function(model) {
}




.vcovAdj16_internal <- function(Phi, SigmaG, X) {
insight::check_if_installed("MASS")
insight::check_if_installed("Matrix")
Expand Down Expand Up @@ -242,7 +236,6 @@ dof_kenward <- function(model) {
}



.indexSymmat2vec <- function(i, j, N) {
## S[i,j] symetric N times N matrix
## r the vector of upper triangular element in row major order:
Expand Down Expand Up @@ -288,7 +281,6 @@ dof_kenward <- function(model) {
}



.get.RT.dim.by.RT <- function(model) {
insight::check_if_installed("lme4")

Expand Down
2 changes: 0 additions & 2 deletions R/extract_random_variances.R
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@

# extract CI for random SD ------------------------

.random_sd_ci <- function(model,

Check warning on line 337 in R/extract_random_variances.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/extract_random_variances.R,line=337,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this expression from 63 to at most 40.
out,
ci_method,
ci, ci_random,
Expand Down Expand Up @@ -856,8 +856,6 @@
}




# this is used to only temporarily load merDeriv and to point registered
# methods from merDeriv to lme4-methods. if merDeriv was loaded before,
# nothing will be changed. If merDeriv was not loaded, vcov-methods registered
Expand Down
5 changes: 5 additions & 0 deletions R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' @inheritParams print.parameters_model
#' @rdname print.parameters_model
#' @export
format.parameters_model <- function(x,

Check warning on line 6 in R/format.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/format.R,line=6,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this expression from 71 to at most 40.
pretty_names = TRUE,
split_components = TRUE,
select = NULL,
Expand Down Expand Up @@ -233,6 +233,11 @@
#' @export
format.parameters_brms_meta <- format.parameters_model

#' @export
format.parameters_coef <- function(x, format = NULL, ...) {
insight::format_table(x, format = format, ...)
}


# Compare parameters ----------------------

Expand All @@ -240,7 +245,7 @@
#' @rdname print.compare_parameters
#' @inheritParams print.parameters_model
#' @export
format.compare_parameters <- function(x,

Check warning on line 248 in R/format.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/format.R,line=248,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this expression from 43 to at most 40.
split_components = TRUE,
select = NULL,
digits = 2,
Expand Down Expand Up @@ -741,7 +746,7 @@


# footer: type of uncertainty interval
.print_footer_cimethod <- function(x) {

Check warning on line 749 in R/format.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/format.R,line=749,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this expression from 46 to at most 40.
if (isTRUE(getOption("parameters_cimethod", TRUE))) {
# get attributes
ci_method <- .additional_arguments(x, "ci_method", NULL)
Expand Down
196 changes: 196 additions & 0 deletions R/group_level_total.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
.group_level_total <- function(x, ...) {
UseMethod(".group_level_total")
}


.group_level_total.glmmTMB <- function(x, ...) {
params <- suppressWarnings(insight::compact_list(stats::coef(x)))
params_cond <- params$cond
params_zi <- params$zi

# handle random effects in conditional component
if (!is.null(params_cond)) {
# extract levels of group factors
group_levels <- insight::compact_list(lapply(
x$modelInfo$reTrms$cond$flist,
levels
))
# extract names of slopes
slope_names <- insight::compact_list(x$modelInfo$reTrms$cond$cnms)
# reshape "coef()" data
params_cond <- .reshape_group_level_coefficients(
x,
params = params_cond,
group_levels = group_levels,
slope_names = slope_names
)
params_cond$Component <- "conditional"
}

# handle random effects in zero-inflation component
if (!is.null(params_zi)) {
# extract levels of group factors
group_levels <- insight::compact_list(lapply(
x$modelInfo$reTrms$zi$flist,
levels
))
# extract names of slopes
slope_names <- insight::compact_list(x$modelInfo$reTrms$zi$cnms)
# reshape "coef()" data
params_zi <- .reshape_group_level_coefficients(
x,
params = params_zi,
group_levels = group_levels,
slope_names = slope_names,
component = "zero_inflated_random"
)
params_zi$Component <- "zero_inflated"
}

# create list of data frames
out <- insight::compact_list(list(params_cond, params_zi))

if (length(out) == 1) {
# unlist if only one component
out <- out[[1]]
} else {
# else, join - we can't use rbind() here, because column
# names do not necessarily match
out <- datawizard::data_join(out, join = "bind")
}

rownames(out) <- NULL
out
}


.group_level_total.merMod <- function(x, ...) {
params <- suppressWarnings(stats::coef(x))

# extract levels of group factors
group_levels <- insight::compact_list(lapply(methods::slot(x, "flist"), levels))
# extract names of slopes
slope_names <- insight::compact_list(methods::slot(x, "cnms"))
# reshape "coef()" data
params <- .reshape_group_level_coefficients(
x,
params = params,
group_levels = group_levels,
slope_names = slope_names
)

params
}


.group_level_total.brmsfit <- function(x, ...) {
# extract random effects information
group_factors <- insight::find_random(x, split_nested = TRUE, flatten = TRUE)
random_slopes <- insight::find_random_slopes(x)
params <- NULL

# create full data frame of all random effects retrieved from coef()
params <- do.call(rbind, lapply(group_factors, function(i) {
# we want the posterior distribution from coef(), so we can
# use bayestestR
ranef <- stats::coef(x, summary = FALSE)[[i]]
parameter_names <- dimnames(ranef)[[3]]
out <- lapply(
parameter_names,
function(pn) {
# summary of posterior
d <- bayestestR::describe_posterior(as.data.frame(ranef[, , pn]), verbose = FALSE, ...)
# add information about group factor and levels
d$Group <- i
# Parameters in the returned data frame are actually the levels
# # from the group factors
d$Level <- d$Parameter
# the parameter names can be taken from dimnames
d$Parameter <- pn
d
}
)
names(out) <- parameter_names
do.call(rbind, out)
}))

# select parameters to keep. We want all intercepts, and all random slopes
# from conditional and potential zero-inflation component
parameters_to_keep <- params$Parameter %in% c("Intercept", random_slopes$random)
parameters_to_keep <- parameters_to_keep | params$Parameter %in% c("zi_Intercept", random_slopes$zero_inflated_random)
# furthermore, categorical random slopes have levels in their name, so we
# try to find those parameters here, too
if (!is.null(random_slopes$random)) {
parameters_to_keep <- parameters_to_keep | startsWith(params$Parameter, random_slopes$random)
}
if (!is.null(random_slopes$zero_inflated_random)) {
parameters_to_keep <- parameters_to_keep | startsWith(params$Parameter, paste0("zi_", random_slopes$zero_inflated_random))

Check warning on line 127 in R/group_level_total.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/group_level_total.R,line=127,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 126 characters.
}

# add Component column
params$Component <- "conditional"
params$Component[startsWith(params$Parameter, "zi_")] <- "zero_inflated"

# clean names
params$Parameter <- gsub("^zi_", "", params$Parameter)
rownames(params) <- NULL

# make sure first columns are group and level
datawizard::data_relocate(params[parameters_to_keep, ], c("Group", "Level"))
}


# helper ----------------------------------------------------------------------

.reshape_group_level_coefficients <- function(x,
params,
group_levels,
slope_names = NULL,
component = "random") {
group_factors <- insight::find_random(x)
random_slopes <- insight::find_random_slopes(x)

# find all columns for which we can add fixed and random effects
cols <- c(random_slopes[[component]], "(Intercept)")

# iterate all random effects, add group name and levels
for (i in group_factors[[component]]) {
# overwrite cols? if random slopes are factors, the names are
# not the variable names, but name + factor level, so we need
# to upate the columns to select here
if (!is.null(slope_names) && length(slope_names)) {
cols <- slope_names[[i]]
}
# select columns
params[[i]] <- params[[i]][cols]
# add information about group factor and levels
params[[i]]$Group <- i
params[[i]]$Level <- group_levels[[i]]
}

# if only one component, unlist
if (length(params) == 1) {
out <- params[[1]]
} else {
# else, join - we can't use rbind() here, because column
# names do not necessarily match
class(params) <- "list"
out <- datawizard::data_join(params, join = "bind")
}

# reshape
to_reshape <- setdiff(colnames(out), c("Group", "Level"))
out <- datawizard::reshape_longer(out, select = to_reshape)

# rename
out <- datawizard::data_rename(
out,
select = c(Parameter = "name", Coefficient = "value")
)

# make sure first columns are group and level
out <- datawizard::data_relocate(out, c("Group", "Level"))

# remove those without valid values
out[stats::complete.cases(out), ]
}
7 changes: 0 additions & 7 deletions R/methods_aod.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ model_parameters.glimML <- function(model,
standardize = NULL,
exponentiate = FALSE,
p_adjust = NULL,
summary = getOption("parameters_summary", FALSE),
include_info = getOption("parameters_info", FALSE),
keep = NULL,
drop = NULL,
Expand All @@ -65,12 +64,6 @@ model_parameters.glimML <- function(model,
merge_by <- "Parameter"
}

## TODO remove deprecated later
if (!missing(summary)) {
.deprecated_warning("summary", "include_info", verbose)
include_info <- summary
}

# dispersion is just an alias...
if (component == "dispersion") {
component <- "random"
Expand Down
7 changes: 0 additions & 7 deletions R/methods_averaging.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,13 @@ model_parameters.averaging <- function(model,
component = "conditional",
exponentiate = FALSE,
p_adjust = NULL,
summary = getOption("parameters_summary", FALSE),
include_info = getOption("parameters_info", FALSE),
keep = NULL,
drop = NULL,
verbose = TRUE,
...) {
component <- insight::validate_argument(component, c("conditional", "full"))

## TODO remove deprecated later
if (!missing(summary)) {
.deprecated_warning("summary", "include_info", verbose)
include_info <- summary
}

out <- .model_parameters_generic(
model = model,
ci = ci,
Expand Down
Loading
Loading