Skip to content

Conversation

dcjones
Copy link
Contributor

@dcjones dcjones commented Mar 21, 2012

statistics.jl looked a little bare, so I've implemented some basic functions.

In this commit:

  • order : gives the permutation that puts an array in order (equivalent to the R order function).
  • tiedrank : as order but compensate for ties (comparable to the R rank function, or the matlab tiedrank), which is used fequently in rank based statistics.
  • weighted_mean : weighted mean---a little trivial, yet useful.
  • median : (corrected for even-lengthed arrays)
  • var : variance
  • mad : median absolute deviance (comparable to mad in matlab and R)
  • cov_pearson : pearson covariance
  • cor_pearson : pearson correlation
  • cov_spearman : spearman covariance
  • cor_spearman : spearman correlation
  • cov : alias for cov_pearson
  • cor : alias for cor_pearson

The correlation/covariance functions each have three forms, making them behave similarly to the R cor/cov functions and matlab corr/cov functions.

  1. cor(x, y) : return a single number giving the correlation between two vectors
  2. cor(X, Y) : return a matrix C, where C_ij gives correlation between column i in X and column j in Y.
  3. cor(X) : equivalent to cor(X, X) (but a bit more efficient).

Next up is to add kendall covariance/correlation, a quantile function, then move on to basic statistical tests (t-test, wilcoxon tests, etc).

@dcjones
Copy link
Contributor Author

dcjones commented Mar 21, 2012

The select function was defined over AbstractVector, so I did the same with median, but there was no need for that it turns out.

StefanKarpinski added a commit that referenced this pull request Mar 21, 2012
Basic statistics functions
@StefanKarpinski StefanKarpinski merged commit 21ee0db into JuliaLang:master Mar 21, 2012
@JeffBezanson
Copy link
Member

Thank you, this is great!
I made some edits in commit d16acc5; could you double-check that one of us hasn't mixed up R's order() vs. rank()? I think I got it right but it's confusing.
Obviously, we use rank for linear algebra, so what's another good name for that function in the statistics sense?

@dcjones
Copy link
Contributor Author

dcjones commented Mar 21, 2012

I think maybe we both mixed them up. :)

My order was incorrect, yours is correct. But my tiedrank was correct.

They should do two different things: order(x)[1] gives the index of the smallest element, whereas tiedrank(x)[1] gives what place the current first element should be in.

@JeffBezanson
Copy link
Member

I assume the fix is to use order(v) instead of invperm(order(v))?

LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Oct 11, 2021
This undocumented function does not actually ensure that the result is mutable.
Use the same approach as `Base.copymutable`, which relies only on public API.
ViralBShah pushed a commit that referenced this pull request May 17, 2025
Stdlib: SparseArrays
URL: https://github.com/JuliaSparse/SparseArrays.jl.git
Stdlib branch: main
Julia branch: master
Old commit: f3610c0
New commit: 6d072a8
Julia version: 1.13.0-DEV
SparseArrays version: 1.12.0(Does not match)
Bump invoked by: @IanButterworth
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaSparse/SparseArrays.jl@f3610c0...6d072a8

```
$ git log --oneline f3610c0..6d072a8
6d072a8 Lazily init cholmod (#626)
8ff11da fix libsuitesparseconfig bug (#625)
fac1548 lazily init cholmod
75eaa18 fix libsuitesparseconfig bug
7b6e810 Use `libsuitesparseconfig` from JLL (#620)
b225a85 Clarify pros, cons and limitations of Cholesky and LDLt (#621)
3d42644 Update index.md (#623)
16bbcbc 5-term mul! with Diagonal (#603)
d050b1b Relax `eltype` in `Diagonal` `ldiv!`/`rdiv!` (#616)
4968cff `ldiv!` for `Diagonal` and a sparse vector (#613)
5062034 Fix `issymmetric` for matrices with empty columns (#606)
9a46561 Replace `v == zero(v)` with  `_iszero` (#610)
```

Co-authored-by: IanButterworth <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants