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
bootstrap_density_augment<-function(.data){
atb<- attributes(.data)
# Checks if (!is.data.frame(.data)){
rlang::abort(
message="'.data' is expecting a data.frame/tibble. Please supply.",
use_cli_format=TRUE
)
}
if (!atb$tibble_type%in% c("tidy_bootstrap","tidy_bootstrap_nested")){
rlang::abort(
message="Must pass data to this function from either tidy_bootstrap() or bootstrap_unnest_tbl().",
use_cli_format=TRUE
)
}
# Add density dataif(atb$tibble_type=="tidy_bootstrap_nested"){
df_tbl<-dplyr::as_tibble(.data) %>%
TidyDensity::bootstrap_unnest_tbl()
}
if(atb$tibble_type=="tidy_bootstrap"){
df_tbl<-dplyr::as_tibble(.data)
}
df_tbl<-df_tbl %>%
dplyr::nest_by(sim_number) %>%
dplyr::mutate(dens_tbl=list(
stats::density(unlist(data),
n= nrow(data))[c("x","y")] %>%
purrr::set_names("dx","dy") %>%
dplyr::as_tibble())) %>%
tidyr::unnest(cols= c(data, dens_tbl)) %>%
dplyr::mutate(x=dplyr::row_number()) %>%
dplyr::ungroup() %>%
dplyr::select(sim_number, x, y, dx, dy)
# Returnreturn(df_tbl)
}
Example:
library(TidyDensity)
library(tidyverse)
x<-mtcars$mpg# Add density tibble from stats::dens()bootstrap_density_tbl<- tidy_bootstrap(x)
> bootstrap_density_augment(bootstrap_density_tbl)
# A tibble: 50,000 × 5sim_numberxydxdy<fct><int><dbl><dbl><dbl>11119.73.730.000082421227.35.270.00052931310.46.800.0022341415.58.340.0066351516.49.870.015961613.311.40.033671714.712.90.05978182614.50.080891914.716.00.0812101102117.50.0670# … with 49,990 more rows# ℹ Use `print(n = ...)` to see more rows
OR with table unnested already:
bootstrap_density_tbl<- tidy_bootstrap(x) %>%
bootstrap_unnest_tbl()
> bootstrap_density_augment(bootstrap_density_tbl)
# A tibble: 50,000 × 5sim_numberxydxdy<fct><int><dbl><dbl><dbl>111264.770.000106212156.340.00056331317.37.910.0022941424.49.480.0071851515.811.00.017561624.412.60.033571730.414.20.050581817.315.80.061691922.817.30.06331011033.918.90.0587# … with 49,990 more rows# ℹ Use `print(n = ...)` to see more rows
Function is not yet fully outlined but it is something like this:
The text was updated successfully, but these errors were encountered: