11"""
2- D = density(x::Vector{<:Real}; nbins::Integer=200, bins::Vector{<:Real}=Vector{Real}(),
3- bandwidth=nothing, kernel::StrSymb="normal")
2+ D = density(x; first::Bool=true, nbins::Integer=200, bins::Vector{<:Real}=Vector{Real}(),
3+ bandwidth=nothing, kernel::StrSymb="normal", printbw::Bool=false,
4+ extend=0, plot::Bool=true, kwargs...)
45
5- - `x`: calculate the kernel density 'd' of a dataset X for query points 'xd' The density, by default, is
6- estimated using a gaussian kernel with a width obtained with the Silverman's rule. `x` may be
7- a vector, a matrix or Vector{Vector{Real}}.
8- - `nbins`: points are queried between MIN(Y[:]) and MAX(Y[:]) where Y is the data vector.
6+ Calculate the kernel density 'd' of a dataset X at query points determined by `nbins` or `bins`.
7+
8+ - `x`: A vector, a matrix or Vector{Vector{Real}}. The density, by default, is estimated using a
9+ gaussian kernel with a width obtained with the Silverman's rule.
10+ - `nbins`: points are queried between MIN(X[:]) and MAX(X[:]) where X is the data vector.
911- `bins`: Calculates the density for the query points specified by BINS. The values are used as the
1012 query points directly. Default is 200 points.
1113- `bandwidth`: uses the 'bandwidth' to calculate the kernel density. It must be a scalar.
1214 For the uniform case the bandwidth is set to 15% of the range, otherwise the bandwidth is chosen
1315 with the Silverman's rule.
14- - `printbw`: Logical value indicating to print the computed value of the `bandwidth`.
1516- `kernel`: Uses the kernel function specified by KERNEL name (a string or a symbol) to calculate the density.
1617 The kernel may be: 'Normal' (default) or 'Uniform'
18+ - `printbw`: Logical value indicating to print the computed value of the `bandwidth`.
1719- `extend`: By default the density curve is computed at the `bins` locatins or between data extrema as
1820 mentioned above. However, this is not normally enough to go down to zero. Use this option in terms of
1921 number of bandwidth to expand de curve. *e.g.* `extend=2`
22+ - `plot`: Logical value indicating to plot the density curve. If `false` returns the GMTdataset
23+ - `kwargs`: Any keyword argument accepted by `plot` to customize the density plot.
24+
25+ ### Returns
26+ - `nothing` or a `GMTps` and plots the density curve directly if `plot=true` (the fedault) and shows it is `show=true`.
27+ - `D`: A GMTdataset with two columns: first the query points and second the density values.
2028
2129The version
30+
2231 G = density(data, x,y; weights=nothing, bandwidth=nothing, showbw=false)
2332
2433Computes the smoothed kernel probability density estimate of a two-column matrix `data`. The estimate is
@@ -32,10 +41,11 @@ The `showbw` option is used to print the bandwidth used. It returns a GMTgrid of
3241 viz(G, figsize=(12,12), view=(225,30))
3342```
3443"""
35- function density (x; first:: Bool = true , nbins:: Integer = 200 , bins:: Vector{<:Real} = Vector {Real} (), bandwidth= nothing ,
36- kernel:: StrSymb = " normal" , printbw:: Bool = false , horizontal:: Bool = false , extend= 0 , kwargs... )
44+ function density (x; first:: Bool = true , nbins:: Integer = 200 , bins:: Vector{<:Real} = Vector {Real} (),
45+ bandwidth= nothing , kernel:: StrSymb = " normal" , printbw:: Bool = false , horizontal:: Bool = false ,
46+ extend= 0 , plot:: Bool = true , kwargs... )
3747 D = kernelDensity (x, horizontal; nbins= nbins, bins= bins, bandwidth= bandwidth, kernel= kernel, printbw= printbw, ext= extend)
38- common_plot_xyz (" " , D, " line" , first, false ; kwargs... )
48+ return plot ? common_plot_xyz (" " , D, " line" , first, false ; kwargs... ) : D
3949end
4050density! (x; nbins:: Integer = 200 , bins:: Vector{<:Real} = Vector {Real} (), bandwidth= nothing , kernel:: StrSymb = " normal" , printbw:: Bool = false , horizontal:: Bool = false , extend= 0 , kw... ) = density (x; first= false , nbins= nbins, bins= bins, bandwidth= bandwidth, kernel= kernel, printbw= printbw, horizontal= horizontal, extend= extend, kw... )
4151
0 commit comments