Corrcoef of two variables of unequal lengths

7 ビュー (過去 30 日間)
Ben Yang
Ben Yang 2012 年 12 月 12 日
編集済み: dpb 2019 年 12 月 29 日
Hi all! I'm new to MATLAB and I seem to be stuck with an issue that may be quite basic.
I have two variables that I want to apply the corrcoef function on. These variables, however, have different lengths, such that when I use the corrcoef function, I get:
??? Error using ==> corrcoef at 73 The lengths of X and Y must match.
Initially, length(Variable A) = 62 after removing the NaN's it became 60
Variable B is actually a zscored data of another variable, so the NaN's have already been removed before z-scoring. The length of Variable B is at 61.
Is it possible for me to get the corrcoef? If so, how?
It's strange that I've tried Googling for a solution but can't find anything that helps.

採用された回答

Roger Stafford
Roger Stafford 2012 年 12 月 12 日
編集済み: dpb 2019 年 12 月 29 日
Mathworks states in their description of corrcoef,
"R = corrcoef(X) returns a matrix R of correlation coefficients calculated from an input matrix X whose rows are observations and whose columns are variables."
To be meaningful in such correlation calculations, variable values in your two variable vectors within the same row should be matched observations, that is, values that were made in the same observation. Therefore you shouldn't eliminate a NaN in one variable without also eliminating the corresponding entry in the other variable even if it isn't a NaN. As a corollary to this the two variable vectors must therefore remain of the same length.
If you don't maintain this correspondence between matching observations, you will obtain nonsensical results.
Roger Stafford

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by