# What is the current best practice for population formula for cov?

**URL:** <https://discourse.julialang.org/t/what-is-the-current-best-practice-for-population-formula-for-cov/658>\
**Category:** General Usage\
**Created:** [November 30, 2016, 5:54pm UTC](https://discourse.julialang.org/t/what-is-the-current-best-practice-for-population-formula-for-cov/658 "2016-11-30T17:54:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabrielgellner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gabrielgellner/32/75_2.png) [@gabrielgellner](https://discourse.julialang.org/u/gabrielgellner)\
**Post date:** [November 30, 2016, 5:54pm UTC](https://discourse.julialang.org/t/what-is-the-current-best-practice-for-population-formula-for-cov/658/1 "2016-11-30T17:54:41Z")

</div>

Going back to some old code that uses `cov(mat, corrected=false)`, and am welcomed with a massive block of warnings to use `covm` instead … looking at masters source it seems that corrected is no longer a keyword, but a positional argument, so I guess in julia 0.6 I would change this call to `cov(mat, false)`? Currently what do people do? I am tempted to just make my own personal function call that does the population formula instead. But I keep doing this these days, and worry I have far to large of a personal library of personal api functions.

What are people currently using for population formula’s now that keywords are gone from all the basic stats functions? Is there a package?

Thanks so much

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [December 1, 2016, 1:44pm UTC](https://discourse.julialang.org/t/what-is-the-current-best-practice-for-population-formula-for-cov/658/2 "2016-12-01T13:44:33Z")

</div>

The deprecation warning is slightly misleading, as it appears to handle only the case when you pass a `mean` keyword argument. Just pass `corrected` as a positional argument. Though there’s another change which requires you to write `cov(mat, 1, false)` to replace the previous `cov(mat, corrected=false)`. As it’s undocumented, I’ve filed [an issue](https://github.com/JuliaLang/julia/issues/19471) about it.

---

<div class="post-metadata">

**Author:** ![gabrielgellner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gabrielgellner/32/75_2.png) [@gabrielgellner](https://discourse.julialang.org/u/gabrielgellner)\
**Post date:** [December 2, 2016, 6:03am UTC](https://discourse.julialang.org/t/what-is-the-current-best-practice-for-population-formula-for-cov/658/3 "2016-12-02T06:03:47Z")

</div>

Thanks so much for the clarification. I have tried to understand the arguments for removing the keywords, but it is a little lost on me (it is not clear to me how the type instability occurs in cases like this). Having to call `cov(mat, false)` or what it looks like will have to happen `cov(mat[:, 1], mat[:, 2], false)` feels a bit obscure to me. Are keywords largely being deprecated in Base? Should users code follow this? Thanks again.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [December 2, 2016, 8:18am UTC](https://discourse.julialang.org/t/what-is-the-current-best-practice-for-population-formula-for-cov/658/4 "2016-12-02T08:18:41Z")

</div>

I don’t think type stability was the main issue with the old API. The main goal was consistency with other functions like `mean` and `var` (cf. [this issue](https://github.com/JuliaLang/julia/issues/13081)).

Keyword arguments are fine, but they currently impose a small performance penalty, which becomes significant for operations that are fast to compute. In some cases they can also introduce type instabilities, though you can often fix this with some care. I’d personally prefer the keyword argument version for `corrected`, but for now it would be too slow.

Anyway you won’t need to call `cov(mat[:, 1], mat[:, 2], false)`, just `cov(mat, 1, false)`.

---

<div class="post-metadata">

**Author:** ![gabrielgellner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gabrielgellner/32/75_2.png) [@gabrielgellner](https://discourse.julialang.org/u/gabrielgellner)\
**Post date:** [December 2, 2016, 8:00pm UTC](https://discourse.julialang.org/t/what-is-the-current-best-practice-for-population-formula-for-cov/658/5 "2016-12-02T20:00:08Z")

</div>

Okay that makes more sense. Thanks again for all the clarification, makes some of the decision much clearer. From the issue you posted on the lack of documentation above, isn’t it suggested that passing a matrix might be deprecated in the future?

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [December 3, 2016, 2:44pm UTC](https://discourse.julialang.org/t/what-is-the-current-best-practice-for-population-formula-for-cov/658/6 "2016-12-03T14:44:38Z")

</div>

> [@gabrielgellner](#):
>
> From the issue you posted on the lack of documentation above, isn’t it suggested that passing a matrix might be deprecated in the future?

No, you’ll just have to specify the dimension along which variables are stored.
