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

use fun() instead of fun across docs, fixes #383 #521

Merged
merged 9 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion R/boot.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' @param times The number of bootstrap samples.
#' @param apparent A logical. Should an extra resample be added where the
#' analysis and holdout subset are the entire data set. This is required for
#' some estimators used by the `summary` function that require the apparent
#' some estimators used by the `summary()` function that require the apparent
#' error rate.
#' @export
#' @return A tibble with classes `bootstraps`, `rset`, `tbl_df`, `tbl`, and
Expand Down
8 changes: 4 additions & 4 deletions R/caret.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#' \pkg{rsample} and \pkg{caret}.
#'
#' @param object An `rset` object. Currently,
#' `nested_cv` is not supported.
#' @return `rsample2caret` returns a list that mimics the
#' `nested_cv()` is not supported.
hfrick marked this conversation as resolved.
Show resolved Hide resolved
#' @return `rsample2caret()` returns a list that mimics the
#' `index` and `indexOut` elements of a
#' `trainControl` object. `caret2rsample` returns an
#' `trainControl` object. `caret2rsample()` returns an
hfrick marked this conversation as resolved.
Show resolved Hide resolved
#' `rset` object of the appropriate class.
#' @export
rsample2caret <- function(object, data = c("analysis", "assessment")) {
Expand All @@ -23,7 +23,7 @@ rsample2caret <- function(object, data = c("analysis", "assessment")) {
}

#' @rdname rsample2caret
#' @param ctrl An object produced by `trainControl` that has
#' @param ctrl An object produced by `caret::trainControl()` that has
#' had the `index` and `indexOut` elements populated by
#' integers. One method of getting this is to extract the
#' `control` objects from an object produced by `train`.
Expand Down
14 changes: 7 additions & 7 deletions R/initial_split.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#' Simple Training/Test Set Splitting
#'
#' `initial_split` creates a single binary split of the data into a training
#' set and testing set. `initial_time_split` does the same, but takes the
#' `initial_split()` creates a single binary split of the data into a training
#' set and testing set. `initial_time_split()` does the same, but takes the
#' _first_ `prop` samples for training, instead of a random selection.
#' `group_initial_split` creates splits of the data based
#' `group_initial_split()` creates splits of the data based
#' on some grouping variable, so that all data in a "group" is assigned to
#' the same split.
#' `training` and `testing` are used to extract the resulting data.
#' `training()` and `testing()` are used to extract the resulting data.
#' @template strata_details
#' @inheritParams vfold_cv
#' @inheritParams make_strata
#' @param prop The proportion of data to be retained for modeling/analysis.
#' @export
#' @return An `rsplit` object that can be used with the `training` and `testing`
#' @return An `rsplit` object that can be used with the `training()` and `testing()`
#' functions to extract the data in each split.
#' @examplesIf rlang::is_installed("modeldata")
#' set.seed(1353)
Expand Down Expand Up @@ -176,12 +176,12 @@ group_initial_split <- function(data, group, prop = 3 / 4, ..., strata = NULL, p
attrib <- .get_split_args(res, allow_strata_false = TRUE)

res <- res$splits[[1]]

attrib$times <- NULL
for (i in names(attrib)) {
attr(res, i) <- attrib[[i]]
}
class(res) <- c("group_initial_split", "initial_split", class(res))

res
}
2 changes: 1 addition & 1 deletion R/labels.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Find Labels from rset Object
#'
#' Produce a vector of resampling labels (e.g. "Fold1") from
#' an `rset` object. Currently, `nested_cv`
#' an `rset` object. Currently, `nested_cv()`
#' is not supported.
#'
#' @param object An `rset` object
Expand Down
2 changes: 1 addition & 1 deletion R/nest.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Nested or Double Resampling
#'
#' `nested_cv` can be used to take the results of one resampling procedure
#' `nested_cv()` can be used to take the results of one resampling procedure
#' and conduct further resamples within each split. Any type of resampling
#' used in `rsample` can be used.
#'
Expand Down
4 changes: 2 additions & 2 deletions R/rsplit.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ as.integer.rsplit <-
#'
#' The analysis or assessment code can be returned as a data
#' frame (as dictated by the `data` argument) using
#' `as.data.frame.rsplit`. `analysis` and
#' `assessment` are shortcuts.
#' `as.data.frame.rsplit()`. `analysis()` and
#' `assessment()` are shortcuts.
#' @param x An `rsplit` object.
#' @param row.names `NULL` or a character vector giving the row names for the data frame. Missing values are not allowed.
#' @param optional A logical: should the column names of the data be checked for legality?
Expand Down
12 changes: 6 additions & 6 deletions R/tidy.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Tidy Resampling Object
#'
#' The `tidy` function from the \pkg{broom} package can be used on `rset` and
#' The `tidy()` function from the \pkg{broom} package can be used on `rset` and
#' `rsplit` objects to generate tibbles with which rows are in the analysis and
#' assessment sets.
#' @param x A `rset` or `rsplit` object
Expand All @@ -9,11 +9,11 @@
#' sample for the same row in the original data.
#' @inheritParams rlang::args_dots_empty
#' @return A tibble with columns `Row` and `Data`. The latter has possible
#' values "Analysis" or "Assessment". For `rset` inputs, identification columns
#' are also returned but their names and values depend on the type of
#' resampling. `vfold_cv` contains a column "Fold" and, if repeats are used,
#' another called "Repeats". `bootstraps` and `mc_cv` use the column
#' "Resample".
#' values "Analysis" or "Assessment". For `rset` inputs, identification
#' columns are also returned but their names and values depend on the type of
#' resampling. For `vfold_cv()`, contains a column "Fold" and, if repeats are
#' used, another called "Repeats". `bootstraps()` and `mc_cv()` use the column
#' "Resample".
#' @details Note that for nested resampling, the rows of the inner resample,
#' named `inner_Row`, are *relative* row indices and do not correspond to the
#' rows in the original data set.
Expand Down
4 changes: 2 additions & 2 deletions man/as.data.frame.rsplit.Rd

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

2 changes: 1 addition & 1 deletion man/bootstraps.Rd

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

2 changes: 1 addition & 1 deletion man/group_bootstraps.Rd

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

10 changes: 5 additions & 5 deletions man/initial_split.Rd

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

2 changes: 1 addition & 1 deletion man/labels.rset.Rd

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

2 changes: 1 addition & 1 deletion man/nested_cv.Rd

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

8 changes: 4 additions & 4 deletions man/rsample2caret.Rd

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

10 changes: 5 additions & 5 deletions man/tidy.rsplit.Rd

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

4 changes: 2 additions & 2 deletions vignettes/Working_with_rsets.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ example[1:10, setdiff(names(example), names(attrition))]

For this model, the `.fitted` value is the linear predictor in log-odds units.

To compute this data set for each of the 100 resamples, we'll use the `map` function from the `purrr` package:
To compute this data set for each of the 100 resamples, we'll use the `map()` function from the `purrr` package:

```{r model_purrr, warning=FALSE}
library(purrr)
Expand Down Expand Up @@ -182,7 +182,7 @@ The calculated 95% confidence interval contains zero, so we don't have evidence

## Bootstrap Estimates of Model Coefficients

Unless there is already a column in the resample object that contains the fitted model, a function can be used to fit the model and save all of the model coefficients. The [`broom` package](https://cran.r-project.org/package=broom) package has a `tidy` function that will save the coefficients in a data frame. Instead of returning a data frame with a row for each model term, we will save a data frame with a single row and columns for each model term. As before, `purrr::map` can be used to estimate and save these values for each split.
Unless there is already a column in the resample object that contains the fitted model, a function can be used to fit the model and save all of the model coefficients. The [`broom` package](https://cran.r-project.org/package=broom) package has a `tidy()` function that will save the coefficients in a data frame. Instead of returning a data frame with a row for each model term, we will save a data frame with a single row and columns for each model term. As before, `purrr::map()` can be used to estimate and save these values for each split.


```{r coefs}
Expand Down
Loading