Stairs.
cov
(other, lower=-inf, upper=inf, lag=0, clip='pre')¶Calculates either covariance, autocovariance or cross-covariance.
The calculation is between two step functions described by self and other. If lag is None or 0 then covariance is calculated, otherwise cross-covariance is calculated. Autocovariance is a special case of cross-covariance when other is equal to self.
Parameters: |
|
---|---|
Returns: | The covariance (or cross-covariance) between self and other |
Return type: | float |
See also
Examples
>>> fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(12,5), sharey=True, sharex=True)
>>> for ax, title, stair_instance in zip(axes, ("s1", "s2"), (s1, s2)):
... stair_instance.plot(ax, label=title)
... ax.set_title(title)
>>> s1.cov(s2)
0.1404958677685951
>>> s2.cov(s1)
0.1404958677685951
>>> s1.cov(s2, lower=0, upper=6)
0.125
>>> # autocovariance with lag 1
>>> s1.cov(s1, lower=1, upper=5, lag=1)
-0.3333333333333333
>>> # cross-covariance with lag 1
>>> s1.cov(s2, lower=1, upper=4.5, lag=1)
0.15999999999999998
>>> # cross-covariance with lag 1
>>> s1.cov(s2, lower=1, upper=4.5, lag=1, clip='post')
0.163265306122449