statsmodels.stats.moment_helpers.cov2corr#
- statsmodels.stats.moment_helpers.cov2corr(cov, return_std=False, *, use_namedtuple=None)[source]#
Convert covariance matrix to correlation matrix
- Parameters:
- covarray_like, 2d
Covariance matrix, see Notes.
- return_stdbool
If this is true then the standard deviation is also returned. By default only the correlation matrix is returned.
- use_namedtuplebool,
optional Flag controlling whether a
Cov2CorrResultNamedTuple is returned. Whenreturn_std=TrueaCov2CorrResultis always returned; it holds the same two elements as the legacy tuple, so it unpacks and indexes identically. Whenreturn_std=Falsea bare correlation matrix is returned unlessuse_namedtuple=True, which yields aCov2CorrResultcarrying the standard deviations too.
- Returns:
Cov2CorrResultorndarrayWhen
return_std=True(oruse_namedtuple=True), a NamedTuple with fields:- corrndarray (subclass)
Correlation matrix.
- stdndarray
Standard deviation from the diagonal of cov.
Cov2CorrResulthas the same length and contents as the plain(corr, std_)tuple it replaces, so it unpacks and indexes identically. SeeCov2CorrResult.When
return_std=Falseanduse_namedtupleis not True, a bare correlation matrix is returned instead.
Notes
This function does not convert subclasses of ndarrays. This requires that division is defined elementwise. np.ma.array and np.matrix are allowed.