ecdfSteps.Rd
Compute Coordinates of an Empirical Distribution Function
ecdfSteps(x, extend)
a list with components x
and y
For a numeric vector uses the R built-in ecdf
function to compute
coordinates of the ECDF, with extension slightly below and above the
range of x
by default. This is useful for ggplot2
where the ECDF may need to be transformed. The returned object is suitable for creating stratified statistics using data.table
and other methods.
ecdfSteps(0:10)
#> $x
#> [1] -0.5 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 10.5
#>
#> $y
#> [1] 0.00000000 0.09090909 0.18181818 0.27272727 0.36363636 0.45454545
#> [7] 0.54545455 0.63636364 0.72727273 0.81818182 0.90909091 1.00000000
#> [13] 1.00000000
#>
if (FALSE) { # \dontrun{
# Use data.table for obtaining ECDFs by country and region
w <- d[, ecdfSteps(z, extend=c(1,11)), by=.(country, region)] # d is a DT
# Use ggplot2 to make one graph with multiple regions' ECDFs
# and use faceting for countries
ggplot(w, aes(x, y, color=region)) + geom_step() +
facet_wrap(~ country)
} # }