×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Difference between nancov and corr2cov with NaNs

Difference between nancov and corr2cov with NaNs

Difference between nancov and corr2cov with NaNs

(OP)
Can somebody explain the difference?

I have a set of returns (with NaN Values) and I want to create a covariance matrix. I have the option of two functions (When I have NaN values in my returns they yield different results- Can you explain why?). Here is an example:
 
This is a sample returns matrix
X=[[2; 9; 1; 0.2], [4; 5; NaN; 0.5],[0.2; 5; 8; NaN]]
 
1. Using the covariance function
nancov(X,'pairwise')
 
ans =
 
   16.2767    8.8167    0.3000
    8.8167    5.5833    2.4000
    0.3000    2.4000   15.4800
 
 
 
2. Using corr2cov
Convert standard deviation and correlation to covariance
ExpCovariance = corr2cov(ExpSigma, ExpCorrC)
 
corr2cov(nanstd(X), corrcoef(X,'rows','pairwise'))
 
ans =
 
   16.2767    7.6511    0.2777
    7.6511    5.5833    9.2968
    0.2777    9.2968   15.4800
 
 
Can anyone explain why these two fucntions- which should yield the same result- actually display a different covariance matrix?

Thank you!!!!
Much appreciated!!!!!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources