Create covariance matrix from correlation table with both positively and negatively correlated value


I have a correlation table with both positively and negatively correlated values:

cor.table <- matrix(rep(c(-0.1, 0.1), each=1250),50,50) diag(cor.table) <- 1

I would like to create a covariance matrix from this using:


However I get the following error:

Error in cor2cov(cor.table, c(rep(100, 50))) : The object 'cor.mat' should be either a symmetric or a triangular matrix

How can I create a symmetric correlation matrix where values are either positively (0.1) or negatively (-0.1) correlated?


set.seed(1) cor.table <- matrix(sample(c(0.1,-0.1),50^2,replace=TRUE),50,50) > isSymmetric(cor.table) [1] FALSE ind <- lower.tri(cor.table) cor.table[ind] <- t(cor.table)[ind] diag(cor.table) <- 1 > isSymmetric(cor.table) [1] TRUE

Your problem was you did not create a symmetric matrix. It should work now.


  • How to keep always up-to-date reference to Activity
  • Coverity SA - excluding boost, stlport errors
  • Generating XML in Python
  • How is covariance implemented internally in numpy?
  • Compute covariance matrix from list of occurrences [duplicate]
  • Defining two random variables that depend on a single condition
  • Gaussian Basis Function
  • Vectorizing rep and seq in R
  • Mahalanobis distance of each pair of observations
  • Draw a vector from the centroid in point cloud
  • Special characters from xml file don't display correctly using php
  • Is it possible to load a 64-bit dll into a 32-bit process?
  • UIButton event 'Touch Up Inside' not working. 'Touch Down' works fine
  • OpenCV Java, Getting region of interest from image
  • OpenCV Android - convert MatOfPoint to Mat
  • Computing CCA through three approaches
  • Gradle can't find OpenCV Libraries for debugging with NDK
  • Add negative elements in matrix to whole row under the condition that all elements except diagonal a
  • Angular Material - Getting index of row in data table
  • Reduce size of self-loops in igraph
  • Add a row to a matrix in Julia?
  • how to split and categorize value in a column of a pandas dataframe
  • XSLT 1.0: copy everything except certain nodes according to value and variable
  • Creating BackgroundSubtractorMOG2 in Android by OpenCV 3.0 RC1
  • How to transform Byte[](decoded as PNG or JPG) to Tensorflows Tensor
  • R Impute NA's by Linear Increase Depending on Time Interval
  • How to customize whisker lines on a geom_box plot differently than the lines of the box itself
  • Runtime error in UVA Online Judge [closed]
  • Is mp4 stream able with ffserver?
  • NSMutableArray instance used in a block
  • XOR with Neural Networks (Matlab)
  • pymongo replication secondary readreference not work
  • JSON encode and decode on PHP
  • how to add data labels for bar graph in matlab
  • Comma separated Values
  • Error creating VM instance in Google Compute Engine
  • Hits per day in Google Big Query
  • how does django model after text[] in postgresql [duplicate]
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass