Hi all,
I would like to calculate the correlation between two vectors (1*744) for each. but the correlation output gives a matrix (744*744) contains NaNs with no number in the matrix.
Any help will be appreciated.
thanks

 Akzeptierte Antwort

Birdman
Birdman am 20 Dez. 2017

0 Stimmen

Try corrcoef
corrcoef(A,B)

12 Kommentare

Lilya
Lilya am 20 Dez. 2017
the obtained result is:
NaN NaN NaN 1
Birdman
Birdman am 20 Dez. 2017
Can you share your vectors in a mat file?
Lilya
Lilya am 20 Dez. 2017
Find the attachment, please. thank you
Birdman
Birdman am 20 Dez. 2017
If we want to omit NaN values from your data, the two array becomes differently sized. Therefore, a solution could be replacing NaN values with the mean of the array. Only JulTotcurr include NaN values.
JulTotcurr(isnan(JulTotcurr))=mean(JulTotcurr,'omitnan');
corrcoef(JulTotcurr,JulTotwnd)
Lilya
Lilya am 20 Dez. 2017
Bearbeitet: Lilya am 20 Dez. 2017
Great! it works But can we obtain it as a vector? to plot the data?
Birdman
Birdman am 20 Dez. 2017
What do you want to plot?
Lilya
Lilya am 20 Dez. 2017
the values of the correlation
Birdman
Birdman am 20 Dez. 2017
res=corrcoef(JulTotcurr,JulTotwnd);
plot(res(:,1),res(:,2),'o')
Lilya
Lilya am 20 Dez. 2017
Totally appreciate it thank you
Jos (10584)
Jos (10584) am 20 Dez. 2017
Statistically, it is not recommended to replace the missing values by the mean ("mean imputing"). There are other techniques that are (often) more reliable.
Statistical analyses with missing data is quite common, and there are many pitfalls to be aware of, in order to avoid drawing false conclusions!
Lilya
Lilya am 21 Dez. 2017
Thank you for your clarification Jos. Do you recommend one of them?
My pleasure. You can use random sampling, for instance. Replace the NaNs by values sampled from the rest of the data vector. The advantage is that it, in the long run, preserves both the mean and the variance of the original data (whereas mean imputing only preserves the mean). You also might consider bootstrapping this procedure to get a better estimate of the correlation with another vector. If X is your original vector:
Xcopy = X ;
tf = isnan(X) ;
Xcopy(tf) = randsample(X(~tf), sum(tf), true)
You also should analyse whether your missing data is (completely) random or not, as this would influence the inferences you can make.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Gefragt:

am 20 Dez. 2017

Kommentiert:

am 21 Dez. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by