diff --git a/docs/Project.toml b/docs/Project.toml index 3a52a5db..73a3ca8c 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,5 +1,6 @@ [deps] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +Statistics = "20745b16-79ce-11e8-11f9-7d13ad32a3b2" [compat] Documenter = "0.27" diff --git a/docs/src/cov.md b/docs/src/cov.md index 7deb9b2e..72550c1b 100644 --- a/docs/src/cov.md +++ b/docs/src/cov.md @@ -1,11 +1,23 @@ # Covariances and Correlations -Functions to computing various types of correlations and covariances are provided. +Functions to computing various types of covariances and correlations are provided. ## Covariance, Correlation and Scatter Matrix + ```@docs cov cor +scattermat +cov2cor +cor2cov +CovarianceEstimator +SimpleCovariance +``` + +## Partial Correlation + +```@docs +partialcor ``` ## Autocovariance and Autocorrelation diff --git a/src/Statistics.jl b/src/Statistics.jl index f05271fe..28394ed0 100644 --- a/src/Statistics.jl +++ b/src/Statistics.jl @@ -13,7 +13,7 @@ using Base: has_offset_axes, require_one_based_indexing using Printf: @printf -export cor, cov, std, stdm, var, varm, mean!, mean, +export std, stdm, var, varm, mean!, mean, median!, median, middle, quantile!, quantile, # moments.jl skewness, kurtosis, @@ -22,12 +22,24 @@ export cor, cov, std, stdm, var, varm, mean!, mean, weights, aweights, fweights, pweights, # scalarstats.jl geomean, harmmean, genmean, mode, modes, percentile, span, variation, sem, mad, mad!, - iqr, genvar, totalvar, entropy, renyientropy, crossentropy, kldivergence, describe - + iqr, genvar, totalvar, entropy, renyientropy, crossentropy, kldivergence, describe, + zscore, zscore!, + # cov.jl + cor, cov, scattermat, cov2cor, cor2cov, CovarianceEstimator, SimpleCovariance, + # partialcor.jl + partialcor, + # signalcorr.jl + autocov!, autocov, autocor!, autocor, crosscov!, crosscov, crosscor!, crosscor, + pacf!, pacf + +include("common.jl") include("weights.jl") include("wsum.jl") include("moments.jl") include("scalarstats.jl") +include("cov.jl") +include("partialcor.jl") +include("signalcorr.jl") ##### mean ##### diff --git a/src/common.jl b/src/common.jl index 2f5fb901..5f2fceec 100644 --- a/src/common.jl +++ b/src/common.jl @@ -25,17 +25,4 @@ const RealFP = Union{Float32, Float64} fptype(::Type{T}) where {T<:Union{Float32,Bool,Int8,UInt8,Int16,UInt16}} = Float32 fptype(::Type{T}) where {T<:Union{Float64,Int32,UInt32,Int64,UInt64,Int128,UInt128}} = Float64 fptype(::Type{Complex{Float32}}) = Complex{Float32} -fptype(::Type{Complex{Float64}}) = Complex{Float64} - -# A convenient typealias for deprecating default corrected Bool -const DepBool = Union{Bool, Nothing} - -function depcheck(fname::Symbol, b::DepBool) - if b == nothing - msg = "$fname will default to corrected=true in the future. Use corrected=false for previous behaviour." - Base.depwarn(msg, fname) - false - else - b - end -end +fptype(::Type{Complex{Float64}}) = Complex{Float64} \ No newline at end of file diff --git a/src/cov.jl b/src/cov.jl index 4251e96a..d1e51318 100644 --- a/src/cov.jl +++ b/src/cov.jl @@ -63,18 +63,6 @@ matrix (`corrected=false`) is computed by multiplying `scattermat(X, w)` by """ cov - -""" - mean_and_cov(x, [wv::AbstractWeights,] vardim=1; corrected=false) -> (mean, cov) - -Return the mean and covariance matrix as a tuple. A weighting -vector `wv` can be specified. `vardim` that designates whether -the variables are columns in the matrix (`1`) or rows (`2`). -Finally, bias correction is applied to the covariance calculation if -`corrected=true`. See [`cov`](@ref) documentation for more details. -""" -function mean_and_cov end - scattermat(x::DenseMatrix; mean=nothing, dims::Int=1) = _scattermatm(x, mean, dims) _scattermatm(x::DenseMatrix, ::Nothing, dims::Int) = @@ -91,11 +79,11 @@ _scattermatm(x::DenseMatrix, wv::AbstractWeights, mean, dims::Int) = ## weighted cov covm(x::DenseMatrix, mean, w::AbstractWeights, dims::Int=1; - corrected::DepBool=nothing) = + corrected::Bool=true) = rmul!(scattermat(x, w, mean=mean, dims=dims), varcorrection(w, depcheck(:covm, corrected))) -cov(x::DenseMatrix, w::AbstractWeights, dims::Int=1; corrected::DepBool=nothing) = +cov(x::DenseMatrix, w::AbstractWeights, dims::Int=1; corrected::Bool=true) = covm(x, mean(x, w, dims=dims), w, dims; corrected=depcheck(:cov, corrected)) function corm(x::DenseMatrix, mean, w::AbstractWeights, vardim::Int=1) @@ -113,16 +101,6 @@ Compute the Pearson correlation matrix of `X` along the dimension cor(x::DenseMatrix, w::AbstractWeights, dims::Int=1) = corm(x, mean(x, w, dims=dims), w, dims) -function mean_and_cov(x::DenseMatrix, dims::Int=1; corrected::Bool=true) - m = mean(x, dims=dims) - return m, covm(x, m, dims, corrected=corrected) -end -function mean_and_cov(x::DenseMatrix, wv::AbstractWeights, dims::Int=1; - corrected::DepBool=nothing) - m = mean(x, wv, dims=dims) - return m, cov(x, wv, dims; corrected=depcheck(:mean_and_cov, corrected)) -end - """ cov2cor(C, s) diff --git a/test/runtests.jl b/test/runtests.jl index c603910e..62a12603 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -891,3 +891,6 @@ end include("weights.jl") include("wsum.jl") include("moments.jl") +include("cov.jl") +include("partialcor.jl") +include("signalcorr.jl")