Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7011765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:10:07+00:00 2026-05-27T22:10:07+00:00

While using princomp() function in R, the following error is encountered : covariance matrix

  • 0

While using princomp() function in R, the following error is encountered : "covariance matrix is not non-negative definite".

I think, this is due to some values being zero (actually close to zero, but becomes zero during rounding) in the covariance matrix.

Is there a work around to proceed with PCA when covariance matrix contains zeros ?

[FYI : obtaining the covariance matrix is an intermediate step within the princomp() call. Data file to reproduce this error can be downloaded from here – http://tinyurl.com/6rtxrc3%5D

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:10:08+00:00Added an answer on May 27, 2026 at 10:10 pm

    The first strategy might be to decrease the tolerance argument. Looks to me that princomp won’t pass on a tolerance argument but that prcomp does accept a ‘tol’ argument. If not effective, this should identify vectors which have nearly-zero covariance:

    nr0=0.001
    which(abs(cov(M)) < nr0, arr.ind=TRUE)
    

    And this would identify vectors with negative eigenvalues:

    which(eigen(M)$values < 0)
    

    Using the h9 example on the help(qr) page:

    > which(abs(cov(h9)) < .001, arr.ind=TRUE)
          row col
     [1,]   9   4
     [2,]   8   5
     [3,]   9   5
     [4,]   7   6
     [5,]   8   6
     [6,]   9   6
     [7,]   6   7
     [8,]   7   7
     [9,]   8   7
    [10,]   9   7
    [11,]   5   8
    [12,]   6   8
    [13,]   7   8
    [14,]   8   8
    [15,]   9   8
    [16,]   4   9
    [17,]   5   9
    [18,]   6   9
    [19,]   7   9
    [20,]   8   9
    [21,]   9   9
    > qr(h9[-9,-9])$rank  
    [1] 7                  # rank deficient, at least at the default tolerance
    > qr(h9[-(8:9),-(8:9)])$ take out only the vector  with the most dependencies
    [1] 6                   #Still rank deficient
    > qr(h9[-(7:9),-(7:9)])$rank
    [1] 6
    

    Another approach might be to use the alias function:

    alias( lm( rnorm(NROW(dfrm)) ~ dfrm) )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

while using the following constructor $this->pdo = new PDO ($this->source, $this->username, $this->password); if I
while using tiles along with spring i m getting following error: java.net.UnknownHostException: tiles.apache.org program
While using inner join on Pro*C I am getting the below error: PCC-S-02201, Encountered
While using django.core.paginator import ObjectPaginator, I'm getting this error: NeedIndexError: The built-in indices are
While using some regex in C#, I'm facing the following problem : Consider this
While using this line of code, I get the error CS1040: Preprocessor directives must
while using g.drawImage(img,0,0,100,100,0,0,0,0,null) it does not produce any result. So how to draw on
While using this code to serialize an object: public object Clone() { var serializer
while using document cookie <script typ=text/javascript> document.domain=example.com; </script> I got an error.i don't know
while using window.print() the background colors for table cells not printing Thanks for any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.