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

Rename group/group_by arguments into by #433

Merged
merged 15 commits into from
May 24, 2024
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: report
Type: Package
Title: Automated Reporting of Results and Statistical Models
Version: 0.5.8.2
Version: 0.5.8.3
Authors@R:
c(person(given = "Dominique",
family = "Makowski",
Expand Down Expand Up @@ -150,3 +150,4 @@ Collate:
'utils_grouped_df.R'
'zzz.R'
Roxygen: list(markdown = TRUE)
Remotes: easystats/insight
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# report 0.5.9

Breaking

* Arguments named `group`, `at` and `group_by` will be deprecated in future
releases. of _easystats_ packages. Please use `by` instead. This affects
following functions in *report*:

* `report_participants()`
* `report_sample()`

Minor changes

* `report` now supports reporting of Bayesian model comparison with variables of class `brms::loo_compare`.
Expand Down
18 changes: 9 additions & 9 deletions R/report_htest_ttest.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@

.report_table_ttest <- function(table_full, effsize) {
table_full <- cbind(table_full, attributes(effsize)$table)
table <- datawizard::data_remove(
table_small <- datawizard::data_remove(
table_full,
c("Parameter", "Group", "Mean_Group1", "Mean_Group2", "Method", "d_CI_low", "d_CI_high")
)
list(table = table, table_full = table_full)
list(table = table_small, table_full = table_full)
}


# report_effectsize ---------------------

.report_effectsize_ttest <- function(x, table, dot_args, type, rules = "cohen1988") {
args <- c(list(x), dot_args)
table <- do.call(effectsize::effectsize, args)
my_args <- c(list(x), dot_args)
table <- do.call(effectsize::effectsize, my_args)
ci <- attributes(table)$ci
estimate <- names(table)[1]
rules <- ifelse(is.null(dot_args$rules), rules, dot_args$rules)

args <- list(table, rules = rules, dot_args)
interpretation <- do.call(effectsize::interpret, args)$Interpretation
my_args <- list(table, rules = rules, dot_args)
interpretation <- do.call(effectsize::interpret, my_args)$Interpretation
rules <- .text_effectsize(attr(attr(interpretation, "rules"), "rule_name"))

if (estimate %in% c("d", "Cohens_d")) {
Expand Down Expand Up @@ -88,7 +88,7 @@
.report_model_ttest <- function(x, table) {
# If against mu
if (names(x$null.value) == "mean") {
# TODO: @DominiqueMakowski why do we need "table" here?
# TODO: @DominiqueMakowski why do we need "table" here??

Copy link
Member Author

@strengejacke strengejacke May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DominiqueMakowski ?
The object table is never used...

table$Difference <- x$estimate - x$null.value
means <- paste0(" (mean = ", insight::format_value(x$estimate), ")")
Expand All @@ -106,12 +106,12 @@
vars <- paste0(x$data.name)
}

text <- paste0(
final_text <- paste0(
trimws(x$method),
" testing the difference ",
ifelse(grepl(" by ", x$data.name, fixed = TRUE), "of ", "between "),
vars_full
)

text
final_text
}
86 changes: 46 additions & 40 deletions R/report_participants.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
#' so countries that represent less than 10% will be combined in the "other" category).
#' @param participants The name of the participants' identifier column (for
#' instance in the case of repeated measures).
#' @param group A character vector indicating the name(s) of the column(s) used
#' @param by A character vector indicating the name(s) of the column(s) used
#' for stratified description.
#' @param spell_n Logical, fully spell the sample size (`"Three participants"`
#' instead of `"3 participants"`).
#' @inheritParams report.numeric
#' @param group Deprecated. Use `by` instead.
#'
#' @return A character vector with description of the "participants", based on
#' the information provided in `data`.
Expand Down Expand Up @@ -106,7 +107,7 @@
#' sex = "Sex",
#' gender = "Gender",
#' participants = "Participant",
#' group = "Condition"
#' by = "Condition"
#' )
#'
#' # Spell sample size
Expand All @@ -123,14 +124,21 @@ report_participants <- function(data,
country = NULL,
race = NULL,
participants = NULL,
group = NULL,
by = NULL,
spell_n = FALSE,
digits = 1,
threshold = 10,
group = NULL,
...) {
## TODO: deprecate later
if (!is.null(group)) {
format_warning("Argument `group` is deprecated and will be removed in a future release. Please use `by` instead.") # nolint
by <- group
}

# Convert empty strings to NA
data_list <- lapply(data, function(x) {
x[which(x == "")] <- NA
x[which(x == "")] <- NA # nolint
x
})
data <- as.data.frame(data_list, stringsAsFactors = FALSE)
Expand Down Expand Up @@ -165,8 +173,8 @@ report_participants <- function(data,
race <- .find_race_in_data(data)
}

if (is.null(group)) {
text <- .report_participants(
if (is.null(by)) {
final_text <- .report_participants(
data,
age = age,
sex = sex,
Expand All @@ -181,9 +189,9 @@ report_participants <- function(data,
...
)
} else {
text <- NULL
data[[group]] <- as.character(data[[group]])
for (i in split(data, data[group])) {
final_text <- NULL
data[[by]] <- as.character(data[[by]])
for (i in split(data, data[by])) {
current_text <- .report_participants(
i,
age = age,
Expand All @@ -200,15 +208,15 @@ report_participants <- function(data,

pre_text <- paste0(
"the '",
paste0(names(i[group]), " - ", vapply(i[group], unique, "character"), collapse = " and "),
paste0(names(i[by]), " - ", vapply(i[by], unique, "character"), collapse = " and "),
"' group: "
)

text <- c(text, paste0(pre_text, current_text))
final_text <- c(final_text, paste0(pre_text, current_text))
}
text <- paste("For", datawizard::text_concatenate(text, sep = ", for ", last = " and for "))
final_text <- paste("For", datawizard::text_concatenate(final_text, sep = ", for ", last = " and for "))
}
text
final_text
}

#' @keywords internal
Expand Down Expand Up @@ -338,9 +346,7 @@ report_participants <- function(data,
) %in% c("male", "m", "female", "f", NA, "na")]) /
nrow(data) * 100, digits = digits),
"% other",
if (!insight::format_value(length(data[[sex]][tolower(
data[[sex]]
) %in% c(NA, "na")]) / nrow(data) * 100) == "0.00") {
if (insight::format_value(length(data[[sex]][tolower(data[[sex]]) %in% c(NA, "na")]) / nrow(data) * 100) != "0.00") { # nolint
paste0(", ", insight::format_value(length(data[[sex]][tolower(
data[[sex]]
) %in% c(NA, "na")]) / nrow(data) * 100), "% missing")
Expand Down Expand Up @@ -375,9 +381,9 @@ report_participants <- function(data,
data[[gender]]
) %in% both_genders]) /
nrow(data) * 100), "% non-binary",
if (!insight::format_value(length(data[[gender]][tolower(
if (insight::format_value(length(data[[gender]][tolower(
data[[gender]]
) %in% c(NA, "na")]) / nrow(data) * 100) == "0.00") {
) %in% c(NA, "na")]) / nrow(data) * 100) != "0.00") {
paste0(", ", insight::format_value(length(data[[gender]][tolower(
data[[gender]]
) %in% c(NA, "na")]) / nrow(data) * 100), "% missing")
Expand All @@ -387,31 +393,29 @@ report_participants <- function(data,

if (all(is.na(data[[education]]))) {
text_education <- ""
} else {
if (is.numeric(data[[education]])) {
text_education <- summary(
report_statistics(
data[[education]],
n = FALSE,
centrality = "mean",
missing_percentage = NULL,
digits = digits,
...
)
)

text_education <- sub("Mean =", "Mean education =", text_education, fixed = TRUE)
} else {
data[which(data[[education]] %in% c(NA, "NA")), education] <- "missing"
txt <- summary(report_statistics(
as.factor(data[[education]]),
levels_percentage = TRUE,
} else if (is.numeric(data[[education]])) {
text_education <- summary(
report_statistics(
data[[education]],
n = FALSE,
centrality = "mean",
missing_percentage = NULL,
digits = digits,
...
))
)
)

text_education <- paste0("Education: ", txt)
}
text_education <- sub("Mean =", "Mean education =", text_education, fixed = TRUE)
} else {
data[which(data[[education]] %in% c(NA, "NA")), education] <- "missing"
txt <- summary(report_statistics(
as.factor(data[[education]]),
levels_percentage = TRUE,
digits = digits,
...
))

text_education <- paste0("Education: ", txt)
}

text_country <- if (all(is.na(data[[country]]))) {
Expand Down Expand Up @@ -468,6 +472,7 @@ report_participants <- function(data,
text_race <- paste("Race:", value_string)
}

# nolint start
paste0(
size,
" participants (",
Expand All @@ -491,6 +496,7 @@ report_participants <- function(data,
), text_race)),
")"
)
# nolint end
}

#' @keywords internal
Expand Down
Loading
Loading