opt_bin: Get the optimal bin width for a histogram given a data set,...

Description Usage Arguments Details Value Author(s) Examples

View source: R/opt_bin.R

Description

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

Usage

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

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

Details

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

Value

A tibble of histogram breakpoints

Author(s)

Steven P. Sanderson II, MPH

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
library(dplyr)
library(tibble)
library(purrr)

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
  )

spsanderson/LICHospitalR documentation built on Jan. 6, 2022, 12:32 a.m.