# StatsBase crosscor standard deviation does not have lags applied

**URL:** <https://discourse.julialang.org/t/statsbase-crosscor-standard-deviation-does-not-have-lags-applied/116182>\
**Category:** Statistics\
**Tags:** statistics\
**Created:** [June 25, 2024, 5:41am UTC](https://discourse.julialang.org/t/statsbase-crosscor-standard-deviation-does-not-have-lags-applied/116182 "2024-06-25T05:41:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BG-marine](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bg-marine/32/210206_2.png) [@BG-marine](https://discourse.julialang.org/u/BG-marine)\
**Post date:** [June 25, 2024, 5:41am UTC](https://discourse.julialang.org/t/statsbase-crosscor-standard-deviation-does-not-have-lags-applied/116182/1 "2024-06-25T05:41:49Z")

</div>

In `StatsBase.crosscor!()` why is the standard deviation for normalisation calculated before the lag is applied to the input vectors, rather than after?  
This doesn’t appear to follow a standard correlation formula.

[Cross-Correlation with StatsBase crosscor answer does not make sense](https://discourse.julialang.org/t/cross-correlation-with-statsbase-crosscor-answer-does-not-make-sense/44374)

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [June 25, 2024, 5:47am UTC](https://discourse.julialang.org/t/statsbase-crosscor-standard-deviation-does-not-have-lags-applied/116182/2 "2024-06-25T05:47:57Z")

</div>

This is a common source of confusion, see issues

- [autocov incorrect? · Issue #273 · JuliaStats/StatsBase.jl · GitHub](https://github.com/JuliaStats/StatsBase.jl/issues/273)
- [constant normalization in autocor? · Issue #562 · JuliaStats/StatsBase.jl · GitHub](https://github.com/JuliaStats/StatsBase.jl/issues/562)
- [Please state in docstrings the normalization of autocor and crosscor · Issue #294 · JuliaStats/StatsBase.jl · GitHub](https://github.com/JuliaStats/StatsBase.jl/issues/294)
- [covariance and correlation · Issue #739 · JuliaStats/StatsBase.jl · GitHub](https://github.com/JuliaStats/StatsBase.jl/issues/739)
- [Possible error in autocov? · Issue #665 · JuliaStats/StatsBase.jl · GitHub](https://github.com/JuliaStats/StatsBase.jl/issues/665)
