Corrcoef of two variables of unequal lengths
12 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Roger Stafford
il 12 Dic 2012
Modificato: dpb
il 29 Dic 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Particle & Nuclear Physics in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!