# BiweightStats.jl

Robust statistics based on the biweight transform.

## Installation

BiweightStats.jl is a registered package and can be installed using the Julia package manager. From the Julia REPL, enter Pkg mode (by pressing ])

julia>]

pkg> add BiweightStats

To exit Pkg mode, just backspace. Once the package is installed it can be imported with

julia> using BiweightStats

To exit Pkg mode, just backspace. Once the package is installed it can be imported with For more information, see the Pkg documentation.

## Usage

The following examples show the biweight location and scale for a few distributions, and comparing them to the mean and standard deviation.

To run these examples, make sure the following packages need to be installed

using Pkg; Pkg.add(["Distributions", "StatsPlots"])
using BiweightStats
using Distributions: Normal, Logistic, Cauchy, Laplace
using Statistics
using StatsPlots
using Random
rng = Random.seed!(1001)
Random.TaskLocalRNG()

for all our examples, we'll sample 10,000 points

N = 10000
10000
function sample_measure_and_plot_dists(rng, dist, N; kwargs...)
samples = rand(rng, dist, N)

mu = mean(samples)
sig = std(samples; mean=mu)

loc = location(samples; c=9)
sca = scale(samples; c=9, M=loc)

p = histogram(samples; normalize=true, fill=0.3, c=1, lab="", leg=:topleft, kwargs...)
plot!(dist; c=1, lab="", lw=3)
vline!([mu loc]; c=[2 3], lab=["mean ± std" "biweight location ± scale"], lw=2)
vline!([mu loc] .+ [-sig -sca; sig sca]; c=[2 3], ls=:dash, lab="", lw=2)
return p
end
sample_measure_and_plot_dists (generic function with 1 method)

### Gaussian

dist = Normal()
sample_measure_and_plot_dists(rng, dist, N; title="Gaussian")

### Logistic

dist = Logistic()
sample_measure_and_plot_dists(rng, dist, N; title="Logistic")

### Cauchy

dist = Cauchy()
sample_measure_and_plot_dists(rng, dist, N; title="Cauchy", xlim=(-40, 40))