Plotting randomly selected columns of correlation matrix - r

I have a really big similarity matrix having 444 columns. I want to plot a heatmap or corrplot to compare different similarity matrices, but I can't use all the columns. I want to take a random sample of columns and then plot a heatmap, but I don't want to compute similarities again for this columns as it takes a lot of time for some similarity functions that I have. Any ideas how I could take a random sample of columns from similarity matrix (it has the same structure as correlation matrix) to plot a heatmap for them?

Related

Multiple weighted matrices in a SLX model in R

Is there any packages or commands allow multiple weighted matrices in a spatial lagged X (SLX) model?
I want to include two different weighted matrices with one dependent variable, but I cannot find any packages for it?
Theoretically, in spatial analysis, including multiple W matrices are not appropriate? If it is possible, how can I conduct analysis with W1 and W2? Do I have to do it by hand?(I meant, once create the lagged variable by multiplying W matrix and the key DV, and and run a OLS regression with the variables. Is it the right way applying multiple weighted matrices?
Thanks!
Dongjin

correlation between features with R

I wanna calculate the correlation of features, every feature consists of a 50*100 matrix. My question is how can I use R to calculate the correlation between features, instead of correlation of columns inside the matrix.

Generate random matrix given a correlation value to an input matrix

Given an input matrix and a correlation Rho, I want to generate a random matrix that is correlated to the input matrix with a correlation value of Rho.
I can create random matrices through rnorm, but I'm not sure how to force this new matrix to be correlated to the original input matrix.
I looked through some other posts such as this but couldn't find what I was looking for. For example, this post Generating random correlation matrix with given average correlation looks to calculate a random matrix, but correlated to itself, not an input matrix.

Extracting pairwise correlations from correlation matrix

I've got a correlation matrix (say 3x3) and I'd like to extract the pairwise correlations and put them into a vector. That is, I'd like to go from the correlation matrix to:
corVec = c(rho_12, rho_13, rho_23)
I'd like to be able to do this for correlation matrices of any dimension.
The reason I'm doing this is because I'd like to construct a multivariate (elliptical) copula using the copula package with a random correlation matrix.
Thanks!
If the correlation matrix is rho then you can extract the pairwise correlations with:
rho[upper.tri(rho)]
Suppose you have a data.frame df1 with 3 columns.
rho=cor(df1) would make a 3x3 matrix.
To make a pairwise correlation "list" (data.frame):
require(reshape2)
rho[!upper.tri(rho)]=NA
rho=na.omit(melt(rho,value.name = 'cor'))
rho=rho[order(-rho$cor),]

Create an artificial correlation matrix

I want to do some testing of a program but I would like to have a really big matrix
Is there any tool that can generate an artificial correlation matrix?
Pick n random n-dimensional vectors of numbers from -1 to 1. Use the dot product of any 2 vectors is their correlation. Use that fact to make a random n x n correlation matrix.
Is this really a correlation matrix? Make each dimension into an independent standard normal distribution. The coefficients of each vector then describes a random variable. Those random variables have the specified correlations. So yes, this is actually going to be a correlation matrix.
There is a repository of sample matrix data for use in comparing algos available at the Matrix Market - free despite the name.

Resources