nclass package:grDevices R Documentation(latin1) _C_o_m_p_u_t_e _t_h_e _N_u_m_b_e_r _o_f _C_l_a_s_s_e_s _f_o_r _a _H_i_s_t_o_g_r_a_m _D_e_s_c_r_i_p_t_i_o_n: Compute the number of classes for a histogram. _U_s_a_g_e: nclass.Sturges(x) nclass.scott(x) nclass.FD(x) _A_r_g_u_m_e_n_t_s: x: A data vector. _D_e_t_a_i_l_s: 'nclass.Sturges' uses Sturges' formula, implicitly basing bin sizes on the range of the data. 'nclass.scott' uses Scott's choice for a normal distribution based on the estimate of the standard error, unless that is zero where it returns '1'. 'nclass.FD' uses the Freedman-Diaconis choice based on the inter-quartile range ('IQR') unless that's zero where it reverts to 'mad(x, constant=2)' and when that is 0 as well, returns '1'. _V_a_l_u_e: The suggested number of classes. _R_e_f_e_r_e_n_c_e_s: Venables, W. N. and Ripley, B. D. (2002) _Modern Applied Statistics with S-PLUS._ Springer, page 112. Freedman, D. and Diaconis, P. (1981) On the histogram as a density estimator: L_2 theory. _Zeitschrift fuer Wahrscheinlichkeitstheorie und verwandte Gebiete_ *57*, 453-476. Scott, D. W. (1979) On optimal and data-based histograms. _Biometrika_ *66*, 605-610. Scott, D. W. (1992) _Multivariate Density Estimation. Theory, Practice, and Visualization_. Wiley. Sturges, H. A. (1926) The choice of a class interval. _Journal of the American Statistical Association_ *21*, 65-66. _S_e_e _A_l_s_o: 'hist' and 'truehist' (which use a different default); 'dpih' for a plugin bandwidth proposed by Wand(1995). _E_x_a_m_p_l_e_s: set.seed(1) x <- stats::rnorm(1111) nclass.Sturges(x) ## Compare them: NC <- function(x) c(Sturges = nclass.Sturges(x), Scott = nclass.scott(x), FD = nclass.FD(x)) NC(x) onePt <- rep(1, 11) NC(onePt) # no longer gives NaN