Learn R Programming

bda (version 3.1.3-2)

histosmooth: Smooth A Histogram

Description

To fit a smooth curve to a histogram with equal bin widths.

Usage

histosmooth(x, weights, freq, type='spline', bw,
             from, to, gridsize, digits=0, rounding)

Arguments

x
A sample. 'NA' values will be automatically removed.
weights
A vector of weights of x
freq
A vector of frequencies of x
from,to,gridsize
start point, end point and size of a fine grid where the EDF will be evaluated.
digits
integer indicating the number of decimal places that x will be rounded to. Negative values are allowed. A negative number of digits means rounding to a power of ten, so for example digits = -2 rounds to the nearest hund
rounding
Rounding method. Options include nearest, up, down, or none.
type
Smoothing type: spline, kde, or lp/localpolynomial.
bw
Smoothing parameter. Numeric or character value is allowed. If missing, adaptive (LSCV) bandwidth selector will be used.

Examples

Run this code
par(mfrow=c(2,2))
x0 <- rnorm(1000,34.5,1.5)
hist(x0)
x <- round(x0)
(out1 <- histogram(x, rounding='nearest',digits=0))
out2 <- histosmooth(out1)
plot(out1)
lines(out2, col=2)

out3 <- histosmooth(out1, type='lp')
plot(out1)
lines(out3, col=2)

out4 <- histosmooth(out1, type='kde')
plot(out1)
lines(out4, col=2)

Run the code above in your browser using DataLab