EmpiricalCDFs.EmpiricalCDFs
— Modulemodule EmpiricalCDFs
Build and use empirical cumulative distribution functions.
Types/constructors: AbstractEmpiricalCDF
, EmpiricalCDF
, EmpiricalCDFHi
Functions/methods: Many of the methods defined for AbstractEmpiricalCDF
are forwarded to the underlying array.
logprint
, linprint
, length
, counts
, sort!
, issorted
, empty!
, mean
, median
, middle
, minimum
, maximum
, extrema
, std
, stdm
, var
, varm
, quantile
, iterate
The statistical methods extend functions in Statistics
. One way to use them with EmpiricalCDFs
is using Statistics
.
Binary IO is supported by the submodule EmpiricalCDFs.IOcdf
.
EmpiricalCDFs.AbstractEmpiricalCDF
— TypeAbstractEmpiricalCDF
Concrete types are EmpiricalCDF
and EmpiricalCDFHi
.
EmpiricalCDFs.EmpiricalCDF
— MethodEmpiricalCDF(lowreject::Real)
If lowreject
is finite return EmpiricalCDFHi(lowreject)
. Otherwise return EmpiricalCDF()
.
EmpiricalCDFs.EmpiricalCDF
— MethodEmpiricalCDF{T=Float64}()
Construct an empirical CDF. After inserting elements with push!
or append!
, and before using most of the functions below, the CDF must be sorted with sort!
.
EmpiricalCDF
and EmpiricalCDFHi
are callable objects. For cdf::AbstractEmpiricalCDF
, cdf(x)
returns the estimate of the CDF at x
. By contrast, cdf[inds]
indexes into the underlying data array.
julia> cdf = EmpiricalCDF();
julia> append!(cdf,randn(10^6));
julia> sort!(cdf);
julia> cdf(0.0)
0.499876
julia> cdf(1.0)
0.840944
julia> cdf(-1.0)
0.158494
In this example, we collected $10^6$ samples from the unit normal distribution. About half of the samples are greater than zero. Approximately the same mass is between zero and one as is between zero and minus one.
EmpiricalCDFs.EmpiricalCDFHi
— TypeEmpiricalCDFHi{T <: Real} <: AbstractEmpiricalCDF
Empirical CDF with lower cutoff. That is, keep only the tail.
EmpiricalCDFs.EmpiricalCDFHi
— MethodEmpiricalCDFHi(lowreject::Real)
Return a CDF that does not store samples whose values are less than lowreject
. The sorted CDF will still be properly normalized.
EmpiricalCDFs.counts
— Methodcounts(cdf::AbstractEmpiricalCDF)
Return the number of counts added to cdf
. This includes counts that may have been discarded because they are below of the cutoff.
EmpiricalCDFs.data
— Methoddata(cdf::AbstractEmpiricalCDF)
return the array holding samples for cdf
.
EmpiricalCDFs.finv
— Methodfinv(cdf::AbstractEmpiricalCDF) --> Function
Return the quantile function, that is, the functional inverse of cdf
. cdf
is a callable object. Note that finv differs slightly from quantile
.
Examples
Here, cdf
contains $10^6$ samples from the unit normal distribution.
julia> icdf = finv(cdf);
julia> icdf(.5)
-0.00037235611091389375
julia> icdf(1.0-eps())
4.601393290425543
julia> maximum(cdf)
4.601393290425543
EmpiricalCDFs.linprint
— Functionlinprint(fn::String, cdf::AbstractEmpiricalCDF, n=2000)
print cdf
to file fn
. Print no more than n
linearly spaced points.
EmpiricalCDFs.linprint
— Functionlinprint(io::IO ,cdf::AbstractEmpiricalCDF, n=2000)
print (not more than) n
linearly spaced points after sorting the data.
EmpiricalCDFs.logprint
— Methodlogprint(io::IO, cdf::EmpiricalCDF, n=2000)
print (not more than) n
log spaced points after sorting the data.
Base.append!
— Methodappend!(cdf::EmpiricalCDF, a::AbstractArray)
append!(cdf_to::AbstractEmpiricalCDF, cdf_from::AbstractEmpiricalCDF)
Add samples in a
to cdf
. Add samples in cdf_from
to cdf_to
.
Base.print
— Functionprint(io::IO, cdf::AbstractEmpiricalCDF)
Call logprint(io,cdf)
Base.push!
— Methodpush!(cdf::EmpiricalCDF,x::Real)
add the sample x
to cdf
.
Base.rand
— Methodrand(cdf::EmpiricalCDF)
Pick a random sample from the distribution represented by cdf
.
Base.sort!
— Functionsort!(cdf::AbstractEmpiricalCDF)
Sort the data collected in cdf
. You must call sort!
before using cdf
.