Calculate more detailed density of numeric values
breakDensity(
x,
breaks = length(x)/3,
bw = NULL,
width = NULL,
densityBreaksFactor = 3,
weightFactor = 1,
addZeroEnds = TRUE,
baseline = 0,
floorBaseline = FALSE,
verbose = FALSE,
...
)
numeric vector
numeric breaks as described for stats::density()
except
that single integer value is multiplied by densityBreaksFactor
.
character name of a bandwidth function, or NULL.
NULL or numeric value indicating the width of breaks to apply.
numeric factor to adjust the width of density breaks, where higher values result in less detail.
optional vector of weights length(x)
to apply
to the density calculation.
logical indicating whether the start and end value should always be zero, which can be helpful for creating a polygon.
optional numeric value indicating the expected baseline, which is typically zero, but can be set to a higher value to indicate a "noise floor".
logical indicating whether to apply a noise floor to the output data.
logical indicating whether to print verbose output.
additional parameters are sent to stats::density()
.
list
output equivalent to density()
:
x
: The n
coordinates of the points where the density is
estimated.
y
: The estimated density values, non-negative, but can be zero.
bw
: The bandidth used.
n
: The sample size after elimination of missing values.
call
: the call which produced the result.
data.name
: the deparsed name of the x
argument.
has.na
: logical
for compatibility, and always FALSE
.
This function is a drop-in replacement for stats::density()
,
simply to provide a quick alternative that defaults to a higher
level of detail. Detail can be adjusted using densityBreaksFactor
,
where higher values will use a wider step size, thus lowering
the detail in the output.
Note that the density height is scaled by the total number of points,
and can be adjusted with weightFactor
. See Examples for how to
scale the y-axis range similar to density()
.
Other jam practical functions:
checkLightMode()
,
check_pkg_installed()
,
colNum2excelName()
,
color_dither()
,
diff_functions()
,
exp2signed()
,
fileInfo()
,
fixYellow()
,
getAxisLabel()
,
handleArgsText()
,
heads()
,
isFALSEV()
,
isTRUEV()
,
jamba
,
jargs()
,
kable_coloring()
,
lldf()
,
log2signed()
,
make_html_styles()
,
make_styles()
,
match_unique()
,
mergeAllXY()
,
middle()
,
minorLogTicks()
,
newestFile()
,
printDebug()
,
renameColumn()
,
rmInfinite()
,
rmNAs()
,
rmNA()
,
rmNULL()
,
sclass()
,
sdim()
,
setPrompt()
x <- c(rnorm(15000),
rnorm(5500)*0.25 + 1,
rnorm(12500)*0.5 + 2.5)
plot(density(x))
plot(breakDensity(x))
#> Warning: sum(weights) != 1 -- will not get true density
plot(breakDensity(x, densityBreaksFactor=200))
#> Warning: sum(weights) != 1 -- will not get true density
# trim values to show abrupt transitions
x2 <- x[x > 0 & x < 4]
plot(density(x2), lwd=2)
lines(breakDensity(x2, weightFactor=1/length(x2)/10), col="red")
#> Warning: sum(weights) != 1 -- will not get true density
legend("topright", c("density()", "breakDensity()"),
col=c("black", "red"), lwd=c(2, 1))