Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed May 10, 2024
1 parent 0924f25 commit 82417ca
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 49 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Suggests:
broom,
car,
coin,
dplyr,
ggplot2,
graphics,
MASS,
Expand Down
15 changes: 5 additions & 10 deletions R/bootstrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#' @seealso \code{\link{boot_ci}} to calculate confidence intervals from
#' bootstrap samples.
#'
#' @examplesIf getRversion() >= "4.2.0" && requireNamespace("dplyr", quietly = TRUE) && requireNamespace("purrr", quietly = TRUE)
#' @examples
#' data(efc)
#' bs <- bootstrap(efc, 5)
#'
Expand All @@ -61,16 +61,11 @@
#' mean(as.data.frame(x)$c12hour, na.rm = TRUE)
#' }))
#'
#' # or as tidyverse-approach
#' library(dplyr)
#' library(purrr)
#' bs <- efc |>
#' bootstrap(100) |>
#' mutate(
#' c12hour = map_dbl(strap, ~mean(as.data.frame(.x)$c12hour, na.rm = TRUE))
#' )
#' # bootstrapped standard error
#' boot_se(bs, c12hour)
#' boot_se(bs, "c12hour")
#'
#' # bootstrapped CI
#' boot_ci(bs, "c12hour")
#' @export
bootstrap <- function(data, n, size) {
if (!missing(size) && !is.null(size)) {
Expand Down
53 changes: 26 additions & 27 deletions R/xtab_statistics.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,27 @@
#' )
#' @export
crosstable_statistics <- function(data, x1 = NULL, x2 = NULL, statistics = c("auto", "cramer", "phi", "spearman", "kendall", "pearson", "fisher"), weights = NULL, ...) {
insight::check_if_installed("dplyr")
# match arguments
statistics <- match.arg(statistics)

# name for test statistics in HTML
stat.html <- NULL

# check if data is a table
if (!is.table(data)) {
if (is.table(data)) {
# 'data' is a table - copy to table object
tab <- data
# check if statistics are possible to compute
if (statistics %in% c("spearman", "kendall", "pearson")) {
stop(
sprintf(
"Need arguments `data`, `x1` and `x2` to compute %s-statistics.",
statistics
),
call. = FALSE
)
}
} else {
# evaluate unquoted names
x1 <- deparse(substitute(x1))
x2 <- deparse(substitute(x2))
Expand Down Expand Up @@ -146,19 +158,6 @@ crosstable_statistics <- function(data, x1 = NULL, x2 = NULL, statistics = c("au
} else {
tab <- table(data)
}
} else {
# 'data' is a table - copy to table object
tab <- data
# check if statistics are possible to compute
if (statistics %in% c("spearman", "kendall", "pearson")) {
stop(
sprintf(
"Need arguments `data`, `x1` and `x2` to compute %s-statistics.",
statistics
),
call. = FALSE
)
}
}

# get expected values
Expand Down Expand Up @@ -218,21 +217,21 @@ crosstable_statistics <- function(data, x1 = NULL, x2 = NULL, statistics = c("au
}

# compute method string
method <- dplyr::case_when(
statistics == "kendall" ~ "Kendall's tau",
statistics == "spearman" ~ "Spearman's rho",
statistics == "pearson" ~ "Pearson's r",
statistics == "cramer" ~ "Cramer's V",
statistics == "phi" ~ "Phi"
method <- ifelse(statistics == "kendall", "Kendall's tau",
ifelse(statistics == "spearman", "Spearman's rho", # nolint
ifelse(statistics == "pearson", "Pearson's r", # nolint
ifelse(statistics == "cramer", "Cramer's V", "Phi") # nolint
)
)
)

# compute method string
method.html <- dplyr::case_when(
statistics == "kendall" ~ "Kendall's &tau;",
statistics == "spearman" ~ "Spearman's &rho;",
statistics == "pearson" ~ "Pearson's r",
statistics == "cramer" ~ "Cramer's V",
statistics == "phi" ~ "&phi;"
method.html <- ifelse(statistics == "kendall", "Kendall's &tau;",
ifelse(statistics == "spearman", "Spearman's &rho;", # nolint
ifelse(statistics == "pearson", "Pearson's r", # nolint
ifelse(statistics == "cramer", "Cramer's V", "&phi") # nolint
)
)
)

# return result
Expand Down
15 changes: 4 additions & 11 deletions man/bootstrap.Rd

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

0 comments on commit 82417ca

Please sign in to comment.