StatGeochemBase

Documentation for StatGeochemBase.

StatGeochemBase.DictDatasetFunction
DictDataset(t::NamedTuple, elements=keys(t))

Convert a tuple-based dataset to a dict-based dataset.

See also TupleDataset

Examples

julia> t 
NamedTuple with 2 elements:
  La  = Vector{Float64}(100,)   [0.6809734028326375 ... 0.30665937715972313]
  Yb  = Vector{Float64}(100,)   [0.8851029525168138 ... 0.866246147690925]

julia> d = DictDataset(t)
Dict{String, Vector{Float64}} with 2 entries:
  "Yb" => [0.885103, 0.284384, 0.351527, 0.643542, 0.631274, 0.653966, 0.968414, 0.00204819, 0.0655173, 0.5343…
  "La" => [0.680973, 0.35098, 0.0198742, 0.139642, 0.0703337, 0.0328973, 0.639431, 0.245205, 0.424142, 0.48889…    
source
StatGeochemBase.TupleDatasetFunction
TupleDataset(d::Dict, elements=keys(d))

Convert a dict-based dataset to a tuple-based dataset.

See also DictDataset

Examples

julia> d
Dict{String, Vector{Float64}} with 2 entries:
  "Yb" => [0.823733, 0.0531003, 0.47996, 0.560998, 0.001816, 0.455064, 0.694017, 0.737816, 0.0755015, 0.46098 …
  "La" => [0.440947, 0.937551, 0.464318, 0.694184, 0.253974, 0.521292, 0.857979, 0.0545946, 0.716639, 0.597616…

julia> t = TupleDataset(d)
NamedTuple with 2 elements:
  Yb  = Vector{Float64}(100,)   [0.8237334494155881 ... 0.012863893327602627]
  La  = Vector{Float64}(100,)   [0.44094669199955616 ... 0.5371416189174069]
source
StatGeochemBase.arcdistanceMethod
arcdistance(latᵢ,lonᵢ,lat,lon)

Calculate the distance on a sphere between the point (latᵢ,lonᵢ) and any number of points in (lat,lon). Latitude and Longitude should be specified in decimal degrees

source
StatGeochemBase.cntrMethod
cntr(edges::Collection)

Given an array of bin edges, return a corresponding vector of bin centers

Examples

julia> cntr(1:10)
 1.5:1.0:9.5
source
StatGeochemBase.concatenatedatasetsMethod
concatenatedatasets(d1::NamedTuple, d2::NamedTuple,... ;[elements::Vector{Symbol}])
concatenatedatasets(d1::AbstractDict, d2::AbstractDict,... ;[elements::Vector{String}])

Vertically concatenate two or more Dict- or Tuple-based datasets, variable-by-variable. Optionally, a list of variables to include may be specified in elements

Examples

julia> d1 = Dict("La" => rand(5), "Yb" => rand(5))
Dict{String, Vector{Float64}} with 2 entries:
  "Yb" => [0.221085, 0.203369, 0.0657271, 0.124606, 0.0975556]
  "La" => [0.298578, 0.481674, 0.888624, 0.632234, 0.564491]

julia> d2 = Dict("La" => rand(5), "Ce" => rand(5))
Dict{String, Vector{Float64}} with 2 entries:
  "Ce" => [0.0979752, 0.108585, 0.718315, 0.771128, 0.698499]
  "La" => [0.538215, 0.633298, 0.981322, 0.908532, 0.77754]

julia> concatenatedatasets(d1,d2)
Dict{String, Vector{Float64}} with 3 entries:
  "Ce" => [NaN, NaN, NaN, NaN, NaN, 0.0979752, 0.108585, 0.718315, 0.771128, 0.698499]
  "Yb" => [0.221085, 0.203369, 0.0657271, 0.124606, 0.0975556, NaN, NaN, NaN, NaN, NaN]
  "La" => [0.298578, 0.481674, 0.888624, 0.632234, 0.564491, 0.538215, 0.633298, 0.981322, 0.908532, 0.77754]
source
StatGeochemBase.containsiMethod
containsi(haystack, needle)

Converts both haystack and needle to strings and checks whether string(haystack) contains string(needle), ignoring case.

Examples

julia> containsi("QuickBrownFox", "brown")
true
source
StatGeochemBase.copyat!Method
copyat!(dest, src, tₛ::AbstractVector{Bool})

Copy from src to dest when tₛ is true. Equivalent to dest .= src[tₛ], but without inducing allocations.

See also reversecopyat!

source
StatGeochemBase.count_unique!Method
n = count_unique!(A)

Sort the array A in-place (if not already sorted), move unique elements to the front, and return the number of unique elements found.

A[1:count_unique!(A)] should return an array equivalent to unique(A)

Examples

julia> A = rand(1:5, 10)
10-element Vector{Int64}:
 4
 4
 2
 3
 3
 4
 1
 5
 1
 2

julia> A = rand(1:5, 7)
7-element Vector{Int64}:
 1
 1
 4
 3
 1
 1
 4

julia> n = count_unique!(A)
3

julia> A
7-element Vector{Int64}:
 1
 3
 4
 1
 3
 4
 4

julia> A[1:n]
3-element Vector{Int64}:
 1
 3
 4
source
StatGeochemBase.delim_string_functionMethod
delim_string_function(f, str, delim, T;
    	merge::Bool=false,

Parse a delimited string str with delimiter delim into substrings that will then be operated upon by function f. The results of f will be returned in an array with eltype T.

Examples

julia> delim_string_function(x -> delim_string_parse(x, ',', Int32, undefval=0), "1,2,3,4
5,6,7,8
9,10,11,12
13,14,15,16", '
', Array{Int32,1})
4-element Vector{Vector{Int32}}:
 [1, 2, 3, 4]
 [5, 6, 7, 8]
 [9, 10, 11, 12]
 [13, 14, 15, 16]
source
StatGeochemBase.delim_string_parseFunction
delim_string_parse(str, delim, T;
    	merge::Bool=false,
    	undefval=NaN)

Parse a delimited string str with delimiter delim into values of type T and return the answers as an array with eltype T

Optional keyword arguments and defaults:

merge::Bool=false

Merge repeated delimiters?

undefval=NaN

A value to subsitute for any value that cannot be parsed to type T.

See also delim_string_parse! for an in-place version.

Examples

julia> delim_string_parse("1,2,3,4,5", ',', Float64)
5-element Vector{Float64}:
 1.0
 2.0
 3.0
 4.0
 5.0
source
StatGeochemBase.delim_string_parse!Function
delim_string_parse!(result, str, delim, [T];
    	offset::Integer=0,
    	merge::Bool=false,
    	undefval=NaN)

Parse a delimited string str with delimiter delim into values of type T and return the answers in a pre-allocated result array provided as input.

If T is not specified explicitly, the eltype of the result array will be used by default.

Optional keyword arguments and defaults:

offset::Integer=0

Start writing the parsed results into result at index 1+offset

merge::Bool=false

Merge repeated delimiters?

undefval=NaN

A value to subsitute for any value that cannot be parsed to type T.

See also delim_string_parse for a non-in-place version that will automatically allocate a result array.

Examples

julia> A = zeros(100);

julia> n = delim_string_parse!(A, "1,2,3,4,5", ',', Float64)
5

julia> A[1:n]
5-element Vector{Float64}:
 1.0
 2.0
 3.0
 4.0
 5.0
source
StatGeochemBase.draw_from_distribution!Method
draw_from_distribution!(x::DenseArray{<:AbstractFloat}, dist::Collection{AbstractFloat})

Fill an existing variable x with random floating point numbers drawn from a continuous probability distribution specified by a vector dist defining the PDF curve thereof.

source
StatGeochemBase.draw_from_distributionMethod
draw_from_distribution(dist::Collection{AbstractFloat}, n::Integer)

Draw n random floating point numbers from a continuous probability distribution specified by a collection dist defining the PDF curve thereof.

Examples

julia> draw_from_distribution([0,1,2,1,0.], 7)
7-element Vector{Float64}:
 0.5271744125470383
 0.6624591724796276
 0.7737643383545575
 0.9603780726501608
 0.7772477857811155
 0.8307248435614027
 0.6351766227803024    
source
StatGeochemBase.elementifyMethod
elementify(data::AbstractArray, [elements=data[1,:]];
    	importas=:Dict,
    	standardize::Bool=true,
    	floattype=Float64,
    	skipstart::Integer=1,
    	skipnameless::Bool=true
)

Convert a flat array data into a Named Tuple (importas=:Tuple) or Dictionary (importas=:Dict) with each column as a variable. Tuples are substantially more efficient, so should be favored where possible.

Examples

julia> A = ["La" "Ce" "Pr"; 1.5 1.1 1.0; 3.7 2.9 2.5]
3×3 Matrix{Any}:
  "La"   "Ce"   "Pr"
 1.5    1.1    1.0
 3.7    2.9    2.5

julia> elementify(A, importas=:Tuple)
NamedTuple with 3 elements:
La  = Vector{Float64}(2,) [1.5 ... 3.7]
Ce  = Vector{Float64}(2,) [1.1 ... 2.9]
Pr  = Vector{Float64}(2,) [1.0 ... 2.5]

julia> elementify(A, importas=:Dict)
Dict{String, Union{Vector{Float64}, Vector{String}}} with 4 entries:
  "Ce"       => [1.1, 2.9]
  "Pr"       => [1.0, 2.5]
  "elements" => ["La", "Ce", "Pr"]
  "La"       => [1.5, 3.7]
source
StatGeochemBase.exportdatasetFunction
exportdataset(dataset, [elements], filepath, delim;
    	floatout::Bool=false,
    	findnumeric::Bool=false,
    	skipnan::Bool=true,
    	digits::Integer,
    	sigdigits::Integer
    	rows=:
)

Convert a dict or named tuple of vectors into a 2-D array with variables as columns Export a dataset (in the form of either a Dict or a NamedTuple), optionally specifying which elements to export, as a delimited ASCII text file with the name specified by filepath and delimiter delim.

Possible keyword arguments include:

	digits
	sigdigits

Specify a number of absolute or significant digits to which to round the printed output. Default is no rounding.

	skipnan

Leave NaNs as empty cells in the delimited output file. Boolean; true by default.

	floatout

Force all output to be represented as a floating-point number, or else NaN. Boolean; false by default.

	findnumeric

Export only numeric columns. Boolean; false by default.

	rows

specify which rows of the dataset to export. Default : exports all rows.

source
StatGeochemBase.fast_inv_sqrtMethod
fast_inv_sqrt(x)

The infamous fast inverse square root of x, in 32 and 64 bit versions. Can be up to 10x faster than base 1/sqrt(x), though with nontrivial loss of precision. The implementations here are good to about 4 ppm.

source
StatGeochemBase.find_grid_inpolygonMethod
(columns, rows) = find_grid_inpolygon(grid_x, grid_y, poly_x, poly_y)

Find the indexes of grid points that fall within a polygon for a grid with cell centers given by gridx (j-columns of grid) and gridy (i-rows of grid). Returns a list of rows and columns in the polygon

Examples

```julia julia> grid_x = -1.5:1/3:1.5;

julia> grid_y = -1.5:1/3:1.5;

julia> cols,rows = findgridinpolygon(gridx, gridy, [-.4,.4,.4,-.4],[.4,.4,-.4,-.4]) ([5, 5, 6, 6], [5, 6, 5, 6])

julia> grid_x[cols] 4-element Vector{Float64}: -0.16666666666666666 -0.16666666666666666 0.16666666666666666 0.16666666666666666

julia> grid_y[rows] 4-element Vector{Float64}: -0.16666666666666666 0.16666666666666666 -0.16666666666666666 0.16666666666666666

source
StatGeochemBase.findclosestMethod
findclosest(needles, haystack)

Return the index of the numerically closest value in the indexable collection haystack for each value in needles. If muliple values are equally close, the first one is used

Examples

julia> findclosest(3.4, 1:10)
3

julia> findclosest(3:4, 1:10)
2-element Vector{Int64}:
 3
 4
source
StatGeochemBase.findclosestaboveMethod
findclosestabove(needles, haystack)

Return the index of the nearest value of the indexable collection haystack that is greater than (i.e., "above") each value in needles. If no such values exist, returns lastindex(haystack)+1.

Examples

julia> findclosestabove(3.5, 1:10)
4

julia> findclosestabove(3:4, 1:10)
2-element Vector{Int64}:
 4
 5
source
StatGeochemBase.findclosestbelowMethod
findclosestbelow(needles, haystack)

Return the index of the nearest value of the indexable collection haystack that is less than (i.e., "below") each value in needles. If no such haystack values exist, returns firstindex(haystack)-1.

Examples

julia> findclosestbelow(3.5, 1:10)
3

julia> findclosestbelow(3:4, 1:10)
2-element Vector{Int64}:
 2
 3    
source
StatGeochemBase.findclosestunequalMethod
findclosestunequal(x::Collection, i::Integer)

Return the index of the closest index n to i for which x[n] != x[i], or i if no unequal values of x are found.

Examples

julia> x = [1, 2, 2, 3, 4]
5-element Vector{Int64}:
 1
 2
 2
 3
 4

julia> findclosestunequal(x, 2)
1

julia> findclosestunequal(x, 3)
4    
source
StatGeochemBase.findmatchesMethod
findmatches(needles, haystack)

Return the linear index of the first value in haystack (if any) that is equal to a given value in needles for each value in needles; else 0.

Examples

julia> findmatches([3,5],1:10)
2-element Vector{Int64}:
 3
 5
source
StatGeochemBase.findnthMethod
findnth(t::Collection{Bool}, n::Integer)

Return the index of the nth true value of t, else length(t)

Examples

julia> t = rand(Bool,5)
5-element Vector{Bool}:
 1
 1
 0
 1
 1

julia> findnth(t, 3)
4
source
StatGeochemBase.floatifyFunction
floatify(x, T::Type=Float64)

Convert x to a floating-point number (default Float64) by any means necessary

Examples

julia> StatGeochem.floatify(5)
5.0

julia> StatGeochem.floatify("5")
5.0

julia> StatGeochem.floatify("0x05")
5.0

julia> StatGeochem.floatify("0.5e1")
5.0
source
StatGeochemBase.hashdatasetMethod
hashdataset(ds::Union{Dict, NamedTuple}; digits::Number=3, elements=keys(ds))

Calculate a hash value for each row of a dataset. By default, this considers only the first 3 digits of each number, regardless of scale.

Examples

julia> ds = (La=rand(5), Yb=rand(5)/10)
NamedTuple with 2 elements:
La  = Vector{Float64}(5,)     [0.580683620945775 ... 0.23810020661332487]
Yb  = Vector{Float64}(5,)     [0.014069255862588826 ... 0.067367584177675]

julia> hashdataset(ds)
5-element Vector{UInt64}:
0x89a02fa88348e07c
0x181e78f0ad2af144
0xa3811bd05cca4743
0xfcfe1b6edf0c81cf
0x647868efa9352972
source
StatGeochemBase.image_from_pathsMethod
image_from_paths(xpoints::AbstractMatrix, ypoints::AbstractMatrix; 
    xresolution::Int=1800, 
    yresolution::Int=1200, 
    xrange=nanextrema(xpoints), 
    yrange=nanextrema(ypoints),
)

Produce a 2d image (histogram) of path densities given a set of x-y points stored column-wise in separate matrices xpoints and ypoints. x is assumed to be the independent variable (i.e., the x-y points are plotted in order of increasing x).

Examples

julia> nsims = 1000
1000

julia> xdist = rand(10, nsims);

julia> ydist = rand(10, nsims);

julia> imgcounts, xbincenters, ybincenters = image_from_paths(xpaths, ypaths; xresolution=50, yresolution=50)
([8 15 … 9 11; 12 4 … 14 11; … ; 9 15 … 9 9; 10 17 … 10 14], -3.715247394908744:0.1523101612461508:3.747950506152645, -3.86556932981587:0.1497772964483582:3.4735181961536803)
source
StatGeochemBase.importdatasetFunction
function importdataset(filepath, [delim];
    	importas=:Dict,
    	elements=nothing,
    	standardize::Bool=true,
    	floattype=Float64,
    	skipstart::Integer=0,
    	skipnameless::Bool=true,
    	mindefinedcolumns::Integer=0
)

Import a delimited file specified by filepath with delimiter delim as a dataset in the form of either a Dict or a NamedTuple.

Possible keyword arguments include:

	importas

Specify the format of the imported dataset. Options include :Dict and :Tuple

	elements

Specify the names to be used for each element (i.e., column) of the dataset. Default value (nothing) will cause elements to be read from the first row of the file

	standardize

Convert columns to uniform type wherever possible. Boolean; true by default.

	floattype

Preferred floating-point type for numerical data. Float64 by default.

	skipstart

Ignore this many rows at the start of the input file (useful if input file has a header or other text before the column names). 0 by default.

	skipnameless

Skip columns with no column name. Boolean; true by default

	mindefinedcolumns

Skip rows with fewer than this number of delimiters. 0 by default.

source
StatGeochemBase.imscFunction
imsc(A::AbstractArray, colormap::AbstractVector=viridis, cmin=nanminimum(A), cmax=nanmaximum(A))

Convert a matrix A to an image (an array of Colors.jl colors) using the specified colormap (default viridis), optionally scaled between cmin and cmax.

Examples

julia> A = rand(3,3)
3×3 Matrix{Float64}:
 0.39147   0.553489  0.351628
 0.331786  0.343836  0.824674
 0.639233  0.558113  0.965627

julia> img = imsc(A) # N.B. will display as image if `using ImageInTerminal`
3×3 Array{RGB{N0f8},2} with eltype ColorTypes.RGB{FixedPointNumbers.N0f8}:
 RGB{N0f8}(0.282,0.137,0.455)  …  RGB{N0f8}(0.278,0.051,0.376)
 RGB{N0f8}(0.267,0.004,0.329)     RGB{N0f8}(0.431,0.808,0.345)
 RGB{N0f8}(0.133,0.553,0.553)     RGB{N0f8}(0.992,0.906,0.145)

julia> using Images; save("img.png", img) # Save to file as PNG

julia> using Plots; plot(0:3, 0:3, img) # Plot with specified x and y axes
source
StatGeochemBase.imsciFunction
imsci(A::AbstractArray, colormap::AbstractVector=viridis, cmin=nanminimum(A), cmax=nanmaximum(A))

Convert a matrix A to an indirect array image (an IndirectArray of Colors.jl colors) using the specified colormap (default viridis), optionally scaled between cmin and cmax.

As imsc, but returns an IndirectArray; slightly more space efficient for small colormaps, but with computational cost.

Examples

julia> A = rand(3,3)
3×3 Matrix{Float64}:
 0.39147   0.553489  0.351628
 0.331786  0.343836  0.824674
 0.639233  0.558113  0.965627

 julia> img = imsci(A)
 3×3 IndirectArrays.IndirectArray{RGB{N0f8}, 2, UInt64, Matrix{UInt64}, Vector{RGB{N0f8}}}:
  RGB{N0f8}(0.282,0.137,0.455)  …  RGB{N0f8}(0.278,0.051,0.376)
  RGB{N0f8}(0.267,0.004,0.329)     RGB{N0f8}(0.431,0.808,0.345)
  RGB{N0f8}(0.133,0.553,0.553)     RGB{N0f8}(0.992,0.906,0.145)

julia> using Images; save("img.png", img) # Save to file as PNG

julia> using Plots; plot(0:3, 0:3, img) # Plot with specified x and y axes
source
StatGeochemBase.inpolygonMethod
inpolygon(x,y,point)

Check if a 2D polygon defined by the arrays x, y contains a given point. Returns boolean (true or false)

Examples

julia> x = [0, 1, 1, 0];

julia> y = [0, 0, 1, 1];

julia> inpolygon(x, y, (0.5,0.5))
true

julia> inpolygon(x, y, (0.5,1.5))
false
source
StatGeochemBase.isnumericMethod
isnumeric(x)

Return true if x can be parsed as a number, else false

Examples

julia> StatGeochem.isnumeric(1)
true

julia> StatGeochem.isnumeric("1")
true

julia> StatGeochem.isnumeric("0.5e9")
true

julia> StatGeochem.isnumeric("foo")
false
source
StatGeochemBase.leastsigfigMethod
leastsigfig(d)

Return the order of magnitude of the least significant decimal digit of a number d.

Examples

julia> leastsigfig(1000)
1000.0

julia> leastsigfig(1001)
1.0

julia> leastsigfig(1001.1234)
0.0001
source
StatGeochemBase.linregMethod
(a,b) = linreg(x::AbstractVector, y::AbstractVector)

Returns the coefficients for a simple linear least-squares regression of the form y = a + bx

Examples

julia> a, b = linreg(1:10, 1:10)
2-element Vector{Float64}:
 -1.19542133983862e-15
  1.0

julia> isapprox(a, 0, atol = 1e-12)
true

julia> isapprox(b, 1, atol = 1e-12)
true
source
StatGeochemBase.linterp1!Method
linterp1!(yq::StridedArray, x::AbstractArray, y::AbstractArray, xq; extrapolate=:Linear, knot_index=ones(Int, length(xq)))

In-place variant of linterp1.

source
StatGeochemBase.linterp1Method
yq = linterp1(x::AbstractArray, y::AbstractArray, xq; extrapolate=:Linear)

Simple linear interpolation in one dimension. Given a vector of knots x and values y, find the corresponding y values at position(s) xq.

Knots x must be sorted in increasing order.

If the optional keyword argument extrapolate is set to :Linear (default), xq values outside the range of x will be extrapolated using a linear extrapolation of the closest two x-y pairs. Otherwise, if extrapolate is set to a Number (e.g., 0, or NaN), that number will be used instead.

Examples

julia> linterp1(1:10, 1:10, 5.5)
5.5

julia> linterp1(1:10, 1:10, 0.5:10.5)
11-element Vector{Float64}:
  0.5
  1.5
  2.5
  3.5
  4.5
  5.5
  6.5
  7.5
  8.5
  9.5
 10.5
source
StatGeochemBase.linterp1s!Method
linterp1s!(yq::StridedArray, x::StridedArray, y::StridedArray, xq; extrapolate=:Linear)
linterp1s!(yq::StridedArray, knot_index::StridedArray{Int}, x::StridedArray, y::StridedArray, xq::AbstractArray; extrapolate=:Linear)

In-place variant of linterp1s. Will sort x and permute y to match, before interpolating at xq and storing the result in yq.

An optional temporary working array knot_index = similar(xq, Int) may be provided to fully eliminate allocations.

source
StatGeochemBase.linterp1sMethod
yq = linterp1s(x::AbstractArray, y::AbstractArray, xq; extrapolate=:Linear)

As as linterp1 (simple linear interpolation in one dimension), but will sort the knots x and values y pairwise if x if not already sorted in increasing order.

Examples

julia> linterp1s(10:-1:1, 1:10, 5.5)
5.5

julia> linterp1s(10:-1:1, 1:10, 0.5:10.5)
11-element Vector{Float64}:
 10.5
  9.5
  8.5
  7.5
  6.5
  5.5
  4.5
  3.5
  2.5
  1.5
  0.5
source
StatGeochemBase.midpointquadratureMethod
midpointquadrature(bincenters, values)

Add up the area under a curve with y positions specified by a vector of values and x positions specfied by a vector of bincenters using midpoint integration.

Examples

julia> midpointquadrature(0:0.1:10, 0:0.1:10)
50.5
source
StatGeochemBase.minarcdistanceMethod
minarcdistance(latᵢ,lonᵢ,lat,lon)

Return the smallest non-NaN arcdistance (i.e. distance on a sphere in arc degrees) between a given point (latᵢ[i],lonᵢ[i]) and any point in (lat,lon) for each i in eachindex(latᵢ, lonᵢ).

Latitude and Longitude should be specified in decimal degrees

source
StatGeochemBase.nearestMethod
nearest(T, x)

Convert x to the nearest representable value in type T, rounding if inexact

Examples

```julia julia> nearest(Int, 1234.56) 1235

julia> nearest(Int, Inf) 9223372036854775807

julia> nearest(Int, -Inf) -9223372036854775808 ````

source
StatGeochemBase.nonnumericMethod
nonnumeric(x)

Return true for if x is not missing but cannot be parsed as a number

Examples

julia> StatGeochem.nonnumeric(1)
false

julia> StatGeochem.nonnumeric("1")
false

julia> StatGeochem.nonnumeric("0.5e9")
false

julia> StatGeochem.nonnumeric("foo")
true
source
StatGeochemBase.norm_quantileMethod
norm_quantile(F::Number)

How far away from the mean (in units of sigma) should we expect proportion F of the samples to fall in a standard Gaussian (Normal[0,1]) distribution

source
StatGeochemBase.norm_widthMethod
norm_width(N::Number)

How dispersed (in units of sigma) should we expect a sample of N numbers drawn from a standard Gaussian (Normal[0,1]) distribution to be?

source
StatGeochemBase.normcdfMethod
normcdf(mu,sigma,x)

Cumulative distribution function of the Normal (Gaussian) distribution

$1/2 + erf( rac{x-μ}{σ√2})/2$

with mean mu and standard deviation sigma, evaluated at x.

source
StatGeochemBase.normcdf_ll!Method
normcdf_ll!(mu, sigma, x)

Fast log likelihood proportional to the natural logarithm of the cumulative distribution function of a Normal (Gaussian) distribution with mean mu and standard deviation sigma, evaluated at x.

As normcdf_ll, but in-place (using x as a buffer).

source
StatGeochemBase.normcdf_llMethod
normcdf_ll(mu, sigma, x)

Fast log likelihood proportional to the natural logarithm of the cumulative distribution function of a Normal (Gaussian) distribution with mean mu and standard deviation sigma, evaluated at x.

If x, [mu, and sigma] are given as arrays, the sum of the log likelihood over all x will be returned.

See also normcdf

source
StatGeochemBase.normlogpdfMethod
normlogpdf(mu, sigma, x)

The natural logarithm of the probability density function of a Normal (Gaussian) distribution with mean mu and standard deviation sigma, evaluated at x.

If x, [mu, and sigma] are given as arrays, the sum of the log probability density over all x will be returned.

See also normpdf, normlogpdf

source
StatGeochemBase.normpdfMethod
normpdf(mu,sigma,x)

Probability density function of the Normal (Gaussian) distribution

$ℯ^{-(x-μ)^2 / (2σ^2)} / σ√2π$

with mean mu and standard deviation sigma, evaluated at x

source
StatGeochemBase.normpdf_llMethod
normpdf_ll(mu, sigma, x)

Fast log likelihood proportional to the natural logarithm of the probability density function of a Normal (Gaussian) distribution with mean mu and standard deviation sigma, evaluated at x.

If x, [mu, and sigma] are given as arrays, the sum of the log likelihood over all x will be returned.

See also normpdf, normlogpdf

source
StatGeochemBase.normproductMethod
normproduct(μ1, σ1, μ2, σ2)

The integral of the product of two normal distributions N[μ1,σ1] * N[μ2,σ2]. This is itself just another Normal distribution! Specifically, one with variance σ1^2 + σ2^2, evaluated at distance |μ1-μ2| from the mean

source
StatGeochemBase.normproduct_llMethod
normproduct_ll(μ1, σ1, μ2, σ2)

Fast log likelihood proportional to the integral of N[μ1,σ1] * N[μ2,σ2] As normlogproduct, but using the fast log likelihood of a Normal distribution (i.e., without the preexponential terms).

source
StatGeochemBase.parsedlmMethod
parsedlm(str::AbstractString, delimiter::Char, T::Type=Float64; rowdelimiter::Char='\n')

Parse a string delimited by both row and column into a single (2-D) matrix. Default column delimiter is newline. Similar to readdlm, but operating on a string instead of a file.

Examples

julia> parsedlm("1,2,3
4,5,6
7,8,9
", ',', Float64)
3×3 Matrix{Float64}:
 1.0  2.0  3.0
 4.0  5.0  6.0
 7.0  8.0  9.0

julia> parsedlm("1,2,3,4
5,6,7,8
9,10,11,12
13,14,15,16", ',', Int64)
4×4 Matrix{Int64}:
  1   2   3   4
  5   6   7   8
  9  10  11  12
 13  14  15  16
source
StatGeochemBase.renormalize!Function
renormalize!(dataset, [elements]; total=1.0)

Normalize in-place a (i.e., compositional) dataset defined by a Dict or NamedTuple of one-dimensional numerical arrays, such that all the elements (i.e., variables – by default all keys in the datset) sum to a given total (by default, 1.0).

Note that the arrays representing each element or variable are assumed to be of uniform length

source
StatGeochemBase.renormalize!Method
renormalize!(A::AbstractArray; dim, total=1.0)

Normalize an array A in place such that it sums to total. Optionally may specify a dimension dim along which to normalize.

source
StatGeochemBase.rescaleFunction
rescale(y, min::Number=0, max::Number=1)

Rescale a collection of numbers y between a new minimum min and new maximum max

Examples

julia> rescale(1:5)
5-element Vector{Float64}:
0.0
0.25
0.5
0.75
1.0

julia> rescale(1:5, -1, 0)
5-element Vector{Float64}:
-1.0
-0.75
-0.5
-0.25
0.0
source
StatGeochemBase.reversecopyat!Method
reversecopyat!(dest, src, tₛ::AbstractVector{Bool})

As copyat!, but also reverse the order of stored elements.

Equivalent to dest .= reverse(src[tₛ]), but without inducing allocations.

source
StatGeochemBase.sanitizevarnameMethod
sanitizevarname(s::AbstractString)

Modify an input string s to transform it into an acceptable variable name.

Examples

julia> StatGeochemBase.sanitizevarname("foo")
"foo"

julia> StatGeochemBase.sanitizevarname("523foo")
"_523foo"

julia> StatGeochemBase.sanitizevarname("Length (μm)")
"Length_μm"
source
StatGeochemBase.sigdigitsMethod
sigdigits(d)

Determine the number of decimal significant figures of a number d.

Examples

julia> sigdigits(1000)
1

julia> sigdigits(1001)
4

julia> sigdigits(1001.1245)
8
source
StatGeochemBase.stepifyMethod
stepify(x::AbstractVector)

Duplicate every element of an array.

Together with stepifyedges, allows for convenient plotting of a histogram of bin counts and bin edges as a stepped line.

Examples

julia> stepify([1,3,2])
6-element Vector{Int64}:
 1
 1
 3
 3
 2
 2

julia> plot(stepifyedges(binedges), stepify(bincounts))
# Returns a stepped line plot of a histogram
source
StatGeochemBase.stepifyedgesMethod
stepifyedges(x::AbstractVector)

Duplicate every element of an array except for the first and last.

Together with stepify, allows for convenient plotting of a histogram of bin counts and bin edges as a stepped line.

Examples

julia> stepifyedges([1,2,3,4])
6-element Vector{Int64}:
 1
 2
 2
 3
 3
 4

julia> plot(stepifyedges(binedges), stepify(bincounts))
# Returns a stepped line plot of a histogram
source
StatGeochemBase.trapezoidalquadratureMethod
trapezoidalquadrature(edges, values)

Add up the area under a curve with y positions specified by a vector of values and x positions specfied by a vector of edges using trapezoidal integration. Bins need not be evenly spaced, though it helps (integration will be faster if edges are specified as an AbstractRange).

Examples

julia> trapezoidalquadrature(0:0.1:10, 0:0.1:10)
50.0
source
StatGeochemBase.unelementifyFunction
unelementify(dataset, elements;
    	floatout::Bool=false,
    	floattype=Float64,
    	findnumeric::Bool=false,
    	skipnan::Bool=false,
    	rows=:
)

Convert a Dict or Named Tuple of vectors into a 2-D array with variables as columns

Examples

julia> D
NamedTuple with 3 elements:
  La  = Vector{Float64}(2,) [1.5 ... 3.7]
  Ce  = Vector{Float64}(2,) [1.1 ... 2.9]
  Pr  = Vector{Float64}(2,) [1.0 ... 2.5]

julia> unelementify(D)
3×3 Matrix{Any}:
  "La"   "Ce"   "Pr"
 1.5    1.1    1.0
 3.7    2.9    2.5
source
StatGeochemBase.unionizeMethod
unionize(x::AbstractVector)

Turn an array with possibly abstract element type into one with eltype equal to a Union of all types of elements in the array.

Always returns a copy, even if x is already unionized.

Examples

julia> a = Any[false, 0, 1.0]
3-element Vector{Any}:
 false
     0
     1.0

julia> unionize(a)
3-element Vector{Union{Bool, Float64, Int64}}:
 false
     0
     1.0
source