Skip to content
Open
Changes from all 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
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -3,6 +3,9 @@
S3method(describe_nonlinear,data.frame)
S3method(describe_nonlinear,estimate_predicted)
S3method(describe_nonlinear,numeric)
S3method(estimate_contrasts,default)
S3method(estimate_contrasts,estimate_means)
S3method(estimate_contrasts,estimate_slopes)
S3method(format,estimate_contrasts)
S3method(format,estimate_grouplevel)
S3method(format,estimate_means)
46 changes: 35 additions & 11 deletions R/estimate_contrasts.R
Original file line number Diff line number Diff line change
@@ -98,17 +98,24 @@
#'
#' @return A data frame of estimated contrasts.
#' @export
estimate_contrasts <- function(model,
contrast = NULL,
by = NULL,
predict = NULL,
ci = 0.95,
p_adjust = "holm",
comparison = "pairwise",
backend = getOption("modelbased_backend", "emmeans"),
transform = NULL,
verbose = TRUE,
...) {
estimate_contrasts <- function(model, ...) {
UseMethod("estimate_contrasts")
}


#' @export
#' @rdname estimate_contrasts
estimate_contrasts.default <- function(model,
contrast = NULL,
by = NULL,
predict = NULL,
ci = 0.95,
p_adjust = "holm",
comparison = "pairwise",
backend = getOption("modelbased_backend", "emmeans"),
transform = NULL,
verbose = TRUE,
...) {
## TODO: remove deprecation warning later
if (!is.null(transform)) {
insight::format_warning("Argument `transform` is deprecated. Please use `predict` instead.")
@@ -173,3 +180,20 @@ estimate_contrasts <- function(model,
class(out) <- c("estimate_contrasts", "see_estimate_contrasts", class(out))
out
}


#' @export
estimate_contrasts.estimate_means <- function(model, ...) {
x <- attributes(model)$model
contrast <- attributes(model)$by
# prepare dots - `by` must be removed
dot_args <- list(...)
dot_args$by <- NULL
# function arguments
fun_args <- c(list(x, contrast = contrast), dot_args)
# call contrasts function
do.call(estimate_contrasts, insight::compact_list(fun_args))
}

#' @export
estimate_contrasts.estimate_slopes <- estimate_contrasts.estimate_means
9 changes: 6 additions & 3 deletions man/estimate_contrasts.Rd

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


Unchanged files with check annotations Beta

attr(random, "type") <- type
attr(random, "model") <- model
attr(random, "parameters") <- params
attr(random, "data") <- insight::get_data(model, verbose = FALSE)[insight::find_random(model, split_nested = TRUE, flatten = TRUE)]

Check warning on line 92 in R/estimate_grouplevel.R

GitHub Actions / lint / lint

file=R/estimate_grouplevel.R,line=92,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 133 characters.
class(random) <- c("estimate_grouplevel", class(random))
random
#' @export
format.marginaleffects_contrasts <- function(x, model, p_adjust, comparison, ...) {
predict <- attributes(x)$predict

Check warning on line 108 in R/format.R

GitHub Actions / lint / lint

file=R/format.R,line=108,col=3,[object_overwrite_linter] 'predict' is an exported object from package 'stats'. Avoid re-using such symbols.
groups <- attributes(x)$by
contrast <- attributes(x)$contrast
focal_terms <- attributes(x)$focal_terms
.format_emmeans_contrasts <- function(model, estimated, ci, p_adjust, ...) {
predict <- attributes(estimated)$predict

Check warning on line 111 in R/get_emcontrasts.R

GitHub Actions / lint / lint

file=R/get_emcontrasts.R,line=111,col=3,[object_overwrite_linter] 'predict' is an exported object from package 'stats'. Avoid re-using such symbols.
# Summarize and clean
if (insight::model_info(model)$is_bayesian) {
out <- cbind(estimated@grid, bayestestR::describe_posterior(estimated, ci = ci, verbose = FALSE, ...))
.format_emmeans_means <- function(x, model, ci = 0.95, verbose = TRUE, ...) {
predict <- attributes(x)$predict

Check warning on line 145 in R/get_emmeans.R

GitHub Actions / lint / lint

file=R/get_emmeans.R,line=145,col=3,[object_overwrite_linter] 'predict' is an exported object from package 'stats'. Avoid re-using such symbols.
# Summarize and clean
if (insight::model_info(model)$is_bayesian) {
means <- parameters::parameters(x, ci = ci, ...)
# Get original dataframe of random
data <- attributes(x)$data

Check warning on line 27 in R/reshape_grouplevel.R

GitHub Actions / lint / lint

file=R/reshape_grouplevel.R,line=27,col=3,[object_overwrite_linter] 'data' is an exported object from package 'utils'. Avoid re-using such symbols.
# Random parameters
if (all(group == "all")) group <- unique(x$Group)
# Merge while preserving order of original random
data[["__sort_id"]] <- seq_len(nrow(data))
data <- merge(data, data_wide, by = g, sort = FALSE)

Check warning on line 70 in R/reshape_grouplevel.R

GitHub Actions / lint / lint

file=R/reshape_grouplevel.R,line=70,col=5,[object_overwrite_linter] 'data' is an exported object from package 'utils'. Avoid re-using such symbols.
data <- data[order(data[["__sort_id"]]), ]

Check warning on line 71 in R/reshape_grouplevel.R

GitHub Actions / lint / lint

file=R/reshape_grouplevel.R,line=71,col=5,[object_overwrite_linter] 'data' is an exported object from package 'utils'. Avoid re-using such symbols.
data[["__sort_id"]] <- NULL
}
for (i in seq_len(nrow(combinations))) {
current_row <- paste(t(combinations[i, ]), collapse = "_")
x[x$temp == current_row, nums] <- sapply(x[x$temp == current_row, nums], smoothing, method = method, strength = strength, ...)

Check warning on line 86 in R/smoothing.R

GitHub Actions / lint / lint

file=R/smoothing.R,line=86,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 132 characters.
}
x$temp <- NULL
#' @export
standardize.estimate_predicted <- function(x, include_response = TRUE, ...) {
# Get data of predictors
data <- insight::get_data(attributes(x)$model, ...)

Check warning on line 6 in R/standardize_methods.R

GitHub Actions / lint / lint

file=R/standardize_methods.R,line=6,col=3,[object_overwrite_linter] 'data' is an exported object from package 'utils'. Avoid re-using such symbols.
data[[attributes(x)$response]] <- NULL # Remove resp from data
# Standardize predictors
x[names(data)] <- datawizard::standardize(as.data.frame(x)[names(data)], reference = data, ...)
# Standardize response
if (include_response == TRUE && insight::model_info(attributes(x)$model)$is_linear) {

Check warning on line 13 in R/standardize_methods.R

GitHub Actions / lint / lint

file=R/standardize_methods.R,line=13,col=7,[redundant_equals_linter] Using == on a logical vector is redundant. Well-named logical vectors can be used directly in filtering. For data.table's `i` argument, wrap the column name in (), like `DT[(is_treatment)]`.
resp <- insight::get_response(attributes(x)$model)
disp <- attributes(datawizard::standardize(resp, ...))$scale