You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tidy_bootstrap<-function(.x, .num_sims=2000, .proportion=0.8,
.distribution_type="continuous"){
# Tidyeval ----x_term<- as.numeric(.x)
n<- length(x_term)
dist_type<- tolower(as.character(.distribution_type))
num_sims<- as.integer(.num_sims)
size<- as.numeric(.proportion)
# Checks ----if (!is.vector(x_term)) {
rlang::abort(
message="You must pass a vector as the .x argument to this function.",
use_cli_format=TRUE
)
}
if (size<0|size>1){
rlang::abort(
message="The '.proportion' parameter must be between 0 and 1 inclusive.",
use_cli_format=TRUE
)
}
if (!dist_type%in% c("continuous","discrete")){
rlang::abort(
message="You must choose either 'continuous' or 'discrete'.",
use_cli_format=TRUE
)
}
if (num_sims<2000){
rlang::warn(
message="Setting '.num_sims' to less than 2000 means that results can be potentially unstable. Consider setting to 2000 or more.",
use_cli_format=TRUE
)
}
# Data ----df<-dplyr::tibble(sim_number= as.factor(1:num_sims)) %>%
dplyr::group_by(sim_number) %>%
dplyr::mutate(bootstrap_samples=list(
sample(x=x_term, size= floor(size*n) ,replace=TRUE)
)
) %>%
dplyr::ungroup()
# Attach descriptive attributes to tibble
attr(df, "distribution_family_type") <-dist_type
attr(df, ".x") <-.x
attr(df, ".num_sims") <-.num_sims
attr(df, "tibble_type") <-"tidy_bootstrap"
attr(df, "dist_with_params") <-"Empirical"# Return ----return(df)
}
Example:
>x<-mtcars$mpg>tb<- tidy_bootstrap(x, .num_sims=200)
Warningmessage:Setting'.num_sims'tolessthan2000meansthatresultscanbepotentiallyunstable.Considersettingto2000ormore.>tb<- tidy_bootstrap(x, .num_sims=2000)
>tb# A tibble: 2,000 x 2sim_numberbootstrap_samples<fct><list>11<dbl [25]>22<dbl [25]>33<dbl [25]>44<dbl [25]>55<dbl [25]>66<dbl [25]>77<dbl [25]>88<dbl [25]>99<dbl [25]>1010<dbl [25]># ... with 1,990 more rows
The text was updated successfully, but these errors were encountered:
Function:
Example:
The text was updated successfully, but these errors were encountered: