Corrcoef of two variables of unequal lengths
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ben Yang
am 12 Dez. 2012
Bearbeitet: dpb
am 29 Dez. 2019
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 Kommentare
Akzeptierte Antwort
Roger Stafford
am 12 Dez. 2012
Bearbeitet: dpb
am 29 Dez. 2019
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Descriptive Statistics finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!