Learn R Programming

healthyR (version 0.2.2)

opt_bin: Get the optimal binwidth for a histogram

Description

Gives the optimal binwidth for a histogram given a data set, it's value and the desired amount of bins

Usage

opt_bin(.data, .value_col, .iters = 30)

Value

A tibble of histogram breakpoints

Arguments

.data

The data set in question

.value_col

The column that holds the values

.iters

How many times the cost function loop should run

Author

Steven P. Sanderson II, MPH

Modified from Hideaki Shimazaki Department of Physics, Kyoto University shimazaki at ton.scphys.kyoto-u.ac.jp Feel free to modify/distribute this program.

Details

  • Supply a data.frame/tibble with a value column. from this an optimal binwidth will be computed for the amount of binds desired

See Also

Other Utilities: save_to_excel(), sql_left(), sql_mid(), sql_right()

Examples

Run this code

suppressPackageStartupMessages(library(purrr))
suppressPackageStartupMessages(library(dplyr))

df_tbl <- rnorm(n = 1000, mean = 0, sd = 1)
df_tbl <- df_tbl %>%
  as_tibble() %>%
  set_names("value")

df_tbl %>%
  opt_bin(
    .value_col = value
    , .iters = 100
  )

Run the code above in your browser using DataLab