Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed May 9, 2024
1 parent 21339f3 commit 02429bc
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 38 deletions.
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ importFrom(performance,mse)
importFrom(performance,rmse)
importFrom(purrr,map)
importFrom(purrr,map_dbl)
importFrom(purrr,map_df)
importFrom(purrr,map_lgl)
importFrom(sjmisc,is_empty)
importFrom(sjmisc,is_float)
importFrom(sjmisc,str_contains)
importFrom(sjmisc,typical_value)
Expand Down
23 changes: 14 additions & 9 deletions R/boot_ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@
#' bs <- bootstrap(efc, 100)
#'
#' # now run models for each bootstrapped sample
#' bs$models <- map(bs$strap, ~lm(neg_c_7 ~ e42dep + c161sex, data = .x))
#' bs$models <- lapply(
#' bs$strap,
#' function(.x) lm(neg_c_7 ~ e42dep + c161sex, data = .x)
#' )
#'
#' # extract coefficient "dependency" and "gender" from each model
#' bs$dependency <- map_dbl(bs$models, ~coef(.x)[2])
#' bs$gender <- map_dbl(bs$models, ~coef(.x)[3])
#' bs$dependency <- vapply(bs$models, function(x) coef(x)[2], numeric(1))
#' bs$gender <- vapply(bs$models, function(x) coef(x)[3], numeric(1))
#'
#' # get bootstrapped confidence intervals
#' boot_ci(bs$dependency)
Expand All @@ -76,9 +79,9 @@
#'
#' # alternative function calls.
#' boot_ci(bs$dependency)
#' boot_ci(bs, dependency)
#' boot_ci(bs, dependency, gender)
#' boot_ci(bs, dependency, gender, method = "q")
#' boot_ci(bs, "dependency")
#' boot_ci(bs, c("dependency", "gender"))
#' boot_ci(bs, c("dependency", "gender"), method = "q")
#'
#'
#' # compare coefficients
Expand Down Expand Up @@ -130,13 +133,15 @@
#' # compute the CI for all bootstrapped model coefficients
#' boot_ci()}
#' @export
boot_ci <- function(data, ..., method = c("dist", "quantile"), ci.lvl = 0.95) {
insight::check_if_installed("dplyr")
boot_ci <- function(data, select = NULL, method = c("dist", "quantile"), ci.lvl = 0.95) {
# match arguments
method <- match.arg(method)

# evaluate arguments, generate data
.dat <- get_dot_data(data, dplyr::quos(...))
if (is.null(select))
.dat <- as.data.frame(data)
else
.dat <- data[select]

# compute confidence intervals for all values
transform_boot_result(lapply(.dat, function(x) {
Expand Down
23 changes: 11 additions & 12 deletions R/gmd.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,20 @@
#' @examples
#' data(efc)
#' gmd(efc$e17age)
#' gmd(efc, e17age, c160age, c12hour)
#' gmd(efc, c("e17age", "c160age", "c12hour"))
#'
#' @importFrom purrr map_df
#' @importFrom sjmisc is_empty
#' @export
gmd <- function(x, ...) {
insight::check_if_installed("dplyr")
# evaluate dots
qs <- dplyr::quos(...)
if (!sjmisc::is_empty(qs)) x <- suppressMessages(dplyr::select(x, !!!qs))

if (is.data.frame(x))
purrr::map_df(x, gmd_helper)
else
gmd <- function(x, select = NULL) {
if (is.data.frame(x)) {
do.call(rbind, lapply(select, function(i) {
data.frame(
variable = i,
gmd = gmd_helper(x[[i]])
)
}))
} else {
gmd_helper(x)
}
}


Expand Down
29 changes: 16 additions & 13 deletions man/boot_ci.Rd

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

4 changes: 2 additions & 2 deletions man/gmd.Rd

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

0 comments on commit 02429bc

Please sign in to comment.