Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRAN submission 0.21.2 #903

Merged
merged 18 commits into from
Sep 16, 2023
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# Output files from R CMD check
/*.Rcheck/
revdep/

# RStudio files
.Rproj.user/
Expand Down
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 0.21.1
Date: 2023-05-26 09:34:52 UTC
SHA: 7ad4819088d188babebe5de6880d1230782b32ec
Version: 0.21.2
Date: 2023-09-16 12:58:15 UTC
SHA: a1a80b72020f0287b81563a419eddb36f59fa18d
5 changes: 2 additions & 3 deletions 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.21.1.9
Version: 0.21.2
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -81,7 +81,7 @@ Depends:
Imports:
bayestestR (>= 0.13.0),
datawizard (>= 0.7.0),
insight (>= 0.19.3.2),
insight (>= 0.19.4),
graphics,
methods,
stats,
Expand Down Expand Up @@ -213,4 +213,3 @@ Config/Needs/website:
r-lib/pkgdown,
easystats/easystatstemplate
Config/rcmdcheck/ignore-inconsequential-notes: true
Remotes: easystats/insight
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
accepts the `exponentiate` argument.

* The `print()`, `print_html()`, `print_md()` and `format()` methods for
`model_parameters()` get an `add_reference` argument, to add the reference
`model_parameters()` get an `include_reference` argument, to add the reference
category of categorical predictors to the parameters table.

## Bug fixes
Expand Down
34 changes: 14 additions & 20 deletions R/1_model_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,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 184 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=184,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 151 characters.

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

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/1_model_parameters.R,line=184,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 @@ -418,29 +418,25 @@
#'
#' @inheritSection model_parameters Confidence intervals and approximation of degrees of freedom
#'
#' @examples
#' @examplesIf require("boot", quietly = TRUE) && require("sandwich") && require("clubSandwich") && require("brglm2")
#' library(parameters)
#' model <- lm(mpg ~ wt + cyl, data = mtcars)
#'
#' model_parameters(model)
#'
#' # bootstrapped parameters
#' if (require("boot", quietly = TRUE)) {
#' model_parameters(model, bootstrap = TRUE)
#' }
#' model_parameters(model, bootstrap = TRUE)
#'
#' # standardized parameters
#' model_parameters(model, standardize = "refit")
#'
#' # robust, heteroskedasticity-consistent standard errors
#' if (require("sandwich") && require("clubSandwich")) {
#' model_parameters(model, vcov = "HC3")
#' model_parameters(model, vcov = "HC3")
#'
#' model_parameters(model,
#' vcov = "vcovCL",
#' vcov_args = list(cluster = mtcars$cyl)
#' )
#' }
#' model_parameters(model,
#' vcov = "vcovCL",
#' vcov_args = list(cluster = mtcars$cyl)
#' )
#'
#' # different p-value style in output
#' model_parameters(model, p_digits = 5)
Expand All @@ -454,15 +450,13 @@
#' model_parameters(model, exponentiate = TRUE)
#'
#' # bias-corrected logistic regression with penalized maximum likelihood
#' if (require("brglm2")) {
#' model <- glm(
#' vs ~ wt + cyl,
#' data = mtcars,
#' family = "binomial",
#' method = "brglmFit"
#' )
#' model_parameters(model)
#' }
#' model <- glm(
#' vs ~ wt + cyl,
#' data = mtcars,
#' family = "binomial",
#' method = "brglmFit"
#' )
#' model_parameters(model)
#' }
#' @return A data frame of indices related to the model's parameters.
#' @export
Expand Down Expand Up @@ -692,7 +686,7 @@
# tell user that profiled CIs don't respect vcov-args
if (identical(ci_method, "profile") && (!is.null(vcov) || !is.null(vcov_args)) && isTRUE(verbose)) {
insight::format_alert(
"When `ci_method=\"profile\"`, `vcov` only modifies standard errors, test-statistic and p-values, but not confidence intervals.",

Check warning on line 689 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=689,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 135 characters.

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

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/1_model_parameters.R,line=689,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 135 characters.
"Use `ci_method=\"wald\"` to return confidence intervals based on robust standard errors."
)
}
Expand Down
21 changes: 10 additions & 11 deletions R/2_ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,19 @@
#'
#' @inheritSection model_parameters Confidence intervals and approximation of degrees of freedom
#'
#' @examples
#' @examplesIf require("glmmTMB")
#' \donttest{
#' library(parameters)
#' if (require("glmmTMB")) {
#' model <- glmmTMB(
#' count ~ spp + mined + (1 | site),
#' ziformula = ~mined,
#' family = poisson(),
#' data = Salamanders
#' )
#' data(Salamanders, package = "glmmTMB")
#' model <- glmmTMB::glmmTMB(
#' count ~ spp + mined + (1 | site),
#' ziformula = ~mined,
#' family = poisson(),
#' data = Salamanders
#' )
#'
#' ci(model)
#' ci(model, component = "zi")
#' }
#' ci(model)
#' ci(model, component = "zi")
#' }
#' @export
ci.default <- function(x, ci = 0.95, dof = NULL, method = NULL, ...) {
Expand Down
16 changes: 6 additions & 10 deletions R/bootstrap_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,14 @@
#'
#' @seealso [`bootstrap_parameters()`], [`simulate_model()`], [`simulate_parameters()`]
#'
#' @examples
#' @examplesIf require("boot", quietly = TRUE) && require("emmeans", quietly = TRUE)
#' \dontrun{
#' if (require("boot", quietly = TRUE)) {
#' model <- lm(mpg ~ wt + factor(cyl), data = mtcars)
#' b <- bootstrap_model(model)
#' print(head(b))
#' model <- lm(mpg ~ wt + factor(cyl), data = mtcars)
#' b <- bootstrap_model(model)
#' print(head(b))
#'
#' if (require("emmeans", quietly = TRUE)) {
#' est <- emmeans(b, consec ~ cyl)
#' print(model_parameters(est))
#' }
#' }
#' est <- emmeans::emmeans(b, consec ~ cyl)
#' print(model_parameters(est))
#' }
#' @export
bootstrap_model <- function(model,
Expand Down
18 changes: 7 additions & 11 deletions R/bootstrap_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,15 @@
#' p-values can be biased, and it is suggested to use proper permutation tests
#' to obtain non-parametric p-values.
#'
#' @examples
#' @examplesIf require("boot", quietly = TRUE) && require("emmeans", quietly = TRUE)
#' \dontrun{
#' if (require("boot", quietly = TRUE)) {
#' set.seed(2)
#' model <- lm(Sepal.Length ~ Species * Petal.Width, data = iris)
#' b <- bootstrap_parameters(model)
#' print(b)
#' set.seed(2)
#' model <- lm(Sepal.Length ~ Species * Petal.Width, data = iris)
#' b <- bootstrap_parameters(model)
#' print(b)
#'
#' if (require("emmeans")) {
#' est <- emmeans(b, trt.vs.ctrl ~ Species)
#' print(model_parameters(est))
#' }
#' }
#' est <- emmeans::emmeans(b, trt.vs.ctrl ~ Species)
#' print(model_parameters(est))
#' }
#' @export
bootstrap_parameters <- function(model,
Expand Down
12 changes: 5 additions & 7 deletions R/cluster_discrimination.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
#' [`performance::check_clusterstructure()`] to check suitability of data for
#' clustering.
#'
#' @examples
#' if (requireNamespace("MASS", quietly = TRUE)) {
#' # Retrieve group classification from hierarchical cluster analysis
#' clustering <- cluster_analysis(iris[, 1:4], n = 3)
#' @examplesIf requireNamespace("MASS", quietly = TRUE)
#' # Retrieve group classification from hierarchical cluster analysis
#' clustering <- cluster_analysis(iris[, 1:4], n = 3)
#'
#' # Goodness of group classification
#' cluster_discrimination(clustering)
#' }
#' # Goodness of group classification
#' cluster_discrimination(clustering)
#' @export
cluster_discrimination <- function(x, cluster_groups = NULL, ...) {
UseMethod("cluster_discrimination")
Expand Down
10 changes: 4 additions & 6 deletions R/cluster_performance.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
cluster_performance.hclust <- function(model, data, clusters, ...) {
if (is.null(data)) {
insight::format_error(
"This function requires the data used to compute the clustering to be provided via `data` as it is not accessible from the clustering object itself."

Check warning on line 48 in R/cluster_performance.R

View workflow job for this annotation

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

file=R/cluster_performance.R,line=48,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 155 characters.
)
}
if (is.null(clusters)) {
insight::format_error(
"This function requires a vector of clusters assignments of same length as data to be passed, as it is not contained in the clustering object itself."

Check warning on line 53 in R/cluster_performance.R

View workflow job for this annotation

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

file=R/cluster_performance.R,line=53,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 156 characters.
)
}

Expand All @@ -61,19 +61,17 @@


#' @rdname cluster_performance
#' @examples
#' @examplesIf require("dbscan", quietly = TRUE)
#' # DBSCAN
#' if (require("dbscan", quietly = TRUE)) {
#' model <- dbscan::dbscan(iris[1:4], eps = 1.45, minPts = 10)
#' model <- dbscan::dbscan(iris[1:4], eps = 1.45, minPts = 10)
#'
#' rez <- cluster_performance(model, iris[1:4])
#' rez
#' }
#' rez <- cluster_performance(model, iris[1:4])
#' rez
#' @export
cluster_performance.dbscan <- function(model, data, ...) {
if (is.null(data)) {
insight::format_error(
"This function requires the data used to compute the clustering to be provided via `data` as it is not accessible from the clustering object itself."

Check warning on line 74 in R/cluster_performance.R

View workflow job for this annotation

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

file=R/cluster_performance.R,line=74,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 155 characters.
)
}

Expand Down
33 changes: 16 additions & 17 deletions R/convert_efa_to_cfa.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@
#' @param max_per_dimension Maximum number of variables to keep per dimension.
#' @inheritParams principal_components
#'
#' @examples
#' @examplesIf require("psych") && require("lavaan")
#' \donttest{
#' library(parameters)
#' if (require("psych") && require("lavaan")) {
#' efa <- psych::fa(attitude, nfactors = 3)
#' data(attitude)
#' efa <- psych::fa(attitude, nfactors = 3)
#'
#' model1 <- efa_to_cfa(efa)
#' model2 <- efa_to_cfa(efa, threshold = 0.3)
#' model3 <- efa_to_cfa(efa, max_per_dimension = 2)
#' model1 <- efa_to_cfa(efa)
#' model2 <- efa_to_cfa(efa, threshold = 0.3)
#' model3 <- efa_to_cfa(efa, max_per_dimension = 2)
#'
#' suppressWarnings(anova(
#' lavaan::cfa(model1, data = attitude),
#' lavaan::cfa(model2, data = attitude),
#' lavaan::cfa(model3, data = attitude)
#' ))
#' }
#' suppressWarnings(anova(
#' lavaan::cfa(model1, data = attitude),
#' lavaan::cfa(model2, data = attitude),
#' lavaan::cfa(model3, data = attitude)
#' ))
#' }
#' @return Converted index.
#' @export
Expand All @@ -42,9 +41,10 @@ convert_efa_to_cfa.fa <- function(model,
max_per_dimension = NULL,
...) {
.efa_to_cfa(model_parameters(model, threshold = threshold, ...),
names = names,
max_per_dimension = max_per_dimension,
...)
names = names,
max_per_dimension = max_per_dimension,
...
)
}

#' @export
Expand Down Expand Up @@ -78,7 +78,7 @@ efa_to_cfa <- convert_efa_to_cfa


#' @keywords internal
.efa_to_cfa <- function(loadings, names = NULL, max_per_dimension=NULL, ...) {
.efa_to_cfa <- function(loadings, names = NULL, max_per_dimension = NULL, ...) {
loadings <- attributes(loadings)$loadings_long

# Get dimension names
Expand All @@ -100,7 +100,6 @@ efa_to_cfa <- convert_efa_to_cfa
cfa <- NULL
# Iterate over dimensions
for (i in seq_along(names)) {

# Find correct subset
items <- loadings[loadings$Component == unique(loadings$Component)[i], ]

Expand Down
2 changes: 1 addition & 1 deletion R/display.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
font_size = "100%",
line_padding = 4,
column_labels = NULL,
add_reference = FALSE,
include_reference = FALSE,
verbose = TRUE,
...) {
if (identical(format, "html")) {
Expand Down Expand Up @@ -193,7 +193,7 @@
#' @inheritParams model_parameters.principal
#' @rdname display.parameters_model
#' @export
display.parameters_efa <- function(object, format = "markdown", digits = 2, sort = FALSE, threshold = NULL, labels = NULL, ...) {

Check warning on line 196 in R/display.R

View workflow job for this annotation

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

file=R/display.R,line=196,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 129 characters.
print_md(x = object, digits = digits, sort = sort, threshold = threshold, labels = labels, ...)
}

Expand Down
32 changes: 15 additions & 17 deletions R/dominance_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
#' @param contrasts A named list of [`contrasts`] used by the model object.
#' This list is required in order for the correct mapping of parameters to
#' predictors in the output when the model creates indicator codes for factor
#' variables using [`model_matrix`]. By default, the `contrast` element from
#' the model object submitted is used. If the model object does not have a
#' `contrast` element the user can supply this named list.
#' variables using [`insight::get_modelmatrix()`]. By default, the `contrast`
#' element from the model object submitted is used. If the model object does
#' not have a `contrast` element the user can supply this named list.
#'
#' @param ... Not used at current.
#'
Expand Down Expand Up @@ -115,24 +115,22 @@
#'
#' @author Joseph Luchman
#'
#' @examples
#' if (require("domir") && require("performance")) {
#' data(mtcars)
#' @examplesIf require("domir") && require("performance")
#' data(mtcars)
#'
#' # Dominance Analysis with Logit Regression
#' model <- glm(vs ~ cyl + carb + mpg, data = mtcars, family = binomial())
#' # Dominance Analysis with Logit Regression
#' model <- glm(vs ~ cyl + carb + mpg, data = mtcars, family = binomial())
#'
#' performance::r2(model)
#' dominance_analysis(model)
#' performance::r2(model)
#' dominance_analysis(model)
#'
#' # Dominance Analysis with Weighted Logit Regression
#' model_wt <- glm(vs ~ cyl + carb + mpg,
#' data = mtcars,
#' weights = wt, family = quasibinomial()
#' )
#' # Dominance Analysis with Weighted Logit Regression
#' model_wt <- glm(vs ~ cyl + carb + mpg,
#' data = mtcars,
#' weights = wt, family = quasibinomial()
#' )
#'
#' dominance_analysis(model_wt, quote_args = "weights")
#' }
#' dominance_analysis(model_wt, quote_args = "weights")
#' @export
dominance_analysis <- function(model, sets = NULL, all = NULL,
conditional = TRUE, complete = TRUE,
Expand All @@ -158,7 +156,7 @@
}

model_info <- insight::model_info(model)
if (any(unlist(model_info[c("is_bayesian", "is_mixed", "is_gam", "is_multivariate", "is_zero_inflated", "is_hurdle")]))) {

Check warning on line 159 in R/dominance_analysis.R

View workflow job for this annotation

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

file=R/dominance_analysis.R,line=159,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 124 characters.
insight::format_error(
paste0("`dominance_analysis()` does not yet support models of class `", class(model)[[1]], "`."),
"You may be able to dominance analyze this model using the {.pkg domir} package."
Expand Down Expand Up @@ -198,11 +196,11 @@
insight::format_error("Nested lists are not allowed in `sets`.")
}

if (!all(sapply(sets, inherits, "formula"))) {

Check warning on line 199 in R/dominance_analysis.R

View workflow job for this annotation

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

file=R/dominance_analysis.R,line=199,col=14,[undesirable_function_linter] Function "sapply" is undesirable.
insight::format_error("Each element of list in `sets` must be a formula.")
}

if (any(sapply(sets, function(x) attr(stats::terms(x), "response") == 1))) {

Check warning on line 203 in R/dominance_analysis.R

View workflow job for this annotation

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

file=R/dominance_analysis.R,line=203,col=13,[undesirable_function_linter] Function "sapply" is undesirable.
insight::format_error("Formulas in `sets` argument must not have responses/left hand sides.")
}
}
Expand Down Expand Up @@ -349,7 +347,7 @@

# quote arguments for domin
for (arg in quote_args) {
if (!(arg %in% names(args))) {

Check warning on line 350 in R/dominance_analysis.R

View workflow job for this annotation

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

file=R/dominance_analysis.R,line=350,col=9,[if_not_else_linter] In a simple if/else statement, prefer `if (A) x else y` to the less-readable `if (!A) y else x`.
insight::format_error(arg, " in `quote_args` not among arguments in model.")
} else {
args[[arg]] <-
Expand Down
6 changes: 3 additions & 3 deletions R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ format.parameters_model <- function(x,
zap_small = FALSE,
format = NULL,
groups = NULL,
add_reference = FALSE,
include_reference = FALSE,
...) {
# save attributes
coef_name <- attributes(x)$coefficient_name
Expand Down Expand Up @@ -168,7 +168,7 @@ format.parameters_model <- function(x,
ci_width = ci_width,
ci_brackets = ci_brackets,
zap_small = zap_small,
add_reference = add_reference,
include_reference = include_reference,
...
)
} else {
Expand All @@ -185,7 +185,7 @@ format.parameters_model <- function(x,
format = format,
coef_name = coef_name,
zap_small = zap_small,
add_reference = add_reference,
include_reference = include_reference,
...
)
}
Expand Down
Loading
Loading