Quantile
Ipaper.NanQuantile_3d! — FunctionArguments
fun: reference function,quantile!or_nanquantile!
Ipaper.NanQuantile_low — FunctionNanQuantile_low(A::AbstractArray{T,N};
probs::Vector=[0, 0.25, 0.5, 0.75, 1], dims::Integer=N, na_rm::Bool=true, dtype=nothing) where {T<:Real,N}NanQuantile_low(na_rm=rue) is 3~4 times faster than _nanquantile(na_rm=true)
Examples
using Test
dates = make_date(2010, 1, 1):Day(1):make_date(2010, 12, 31)
ntime = length(dates)
arr = rand(Float32, 140, 80, ntime)
arr2 = copy(arr)
# default `na_rm=true`
@test NanQuantile([1, 2, 3, NaN]; probs=[0.5, 0.9], dims=1) == [2.0, 2.8]
@time r0 = _nanquantile(arr, dims=3) # low version
@time r2_0 = NanQuantile_low(arr; dims=3, na_rm=false)
@time r2_1 = NanQuantile_low(arr; dims=3, na_rm=true)
@test r2_0 == r2_1
@test r2_0 == 20
@test arr2 == arrStatistics
Ipaper.movmean — Functionmovmean(x::AbstractVector{T}, win::Tuple{Int,Int}=(1, 1); skip_centre=false) where {T<:Real}Compute the moving mean of the input vector x with a specified window size.
Arguments
x::AbstractVector{T}: Input vector of typeTwhereTis a subtype ofReal.win::Tuple{Int,Int}: A tuple specifying the window size(win_left, win_right). Default is(1, 1).skip_centre::Bool: Iftrue, the center element is skipped in the mean calculation. Default isfalse.
Returns
- A vector of the same length as
xcontaining the moving mean values.
Example
x = [1.0, 2.0, 3.0, 4.0, 5.0]
movmean(x, (1, 1)) # returns [1.5, 2.0, 3.0, 4.0, 4.5]
movmean(x, (1, 1); skip_centre=true) # returns [1.0, 2.0, 3.0, 4.0, 5.0]Ipaper.linreg_simple — Functionlinreg_simple(y::AbstractVector, x::AbstractVector; na_rm=false)Ipaper.linreg_fast — Functionlinreg_fast(y::AbstractVector, x::AbstractVector; na_rm=false)apply
Ipaper.agg_time — Functionagg_time(A::AbstractArray{T,3}, by::Vector; parallel=true, progress=false,
fun=mean) where {T<:Real}
agg_time(A::AbstractArray{T,3}; fact::Int=2, parallel=true, progress=false,
fun=mean) where {T<:Real}Ipaper.apply — Functionapply(A::AbstractArray; ...) -> Any
apply(
A::AbstractArray,
dims_by,
args...;
dims,
by,
fun,
combine,
parallel,
progress,
kw...
) -> Any
Arguments
dims_by: ifbyprovided, the length ofdimsshould be one!dims: used by mapslicescombine: if true, combine the result to a large array
Examples
using Ipaper
using NaNStatistics
using Distributions
dates = make_date(2010, 1, 1):Day(1):make_date(2010, 12, 31)
yms = format.(dates, "yyyy-mm")
## example 01, some as R aggregate
x1 = rand(365)
apply(x1, 1, yms)
apply(x1, 1, by=yms)
## example 02
n = 100
x = rand(n, n, 365)
res = apply(x, 3, by=yms)
size(res) == (n, n, 12)
res = apply(x, 3)
size(res) == (n, n)
## example 03
dates = make_date(2010):Day(1):make_date(2013, 12, 31)
n = 10
ntime = length(dates)
x = rand(n, n, ntime, 13)
years = year.(dates)
res = apply(x, 3; by=years, fun=_nanquantile, combine=true, probs=[0.05, 0.95])
obj_size(res)
res = apply(x, 3; by=years, fun=mean, combine=true)
apply(x, 3; by = month.(dates), fun=slope_mk)Ipaper.approx — Functionapprox(x, y, xout; rule=2)Approximate the value of a function at a given point using linear interpolation.
DateTimeis also supported. ButDatenot!
Arguments
x::AbstractVector{Tx}: The x-coordinates of the data points.y::AbstractVector{Ty}: The y-coordinates of the data points.xout::AbstractVector: The x-coordinates of the points to approximate.rule::Int=2: The interpolation rule to use. Default is 2.- 1: NaN
- 2: nearest constant extrapolation
- 3: linear extrapolation