Corrcoef of two variables of unequal lengths
9 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Descriptive Statistics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!