How can I import and work with correlation matrix as the only data source in PCA and PCF in RHow can I create a correlation matrix in R?How to reconstruct the original data matrix after applying PCA in RHow can I view the source code for a function?PCA analysis using Correlation Matrix as input in RHow to retrieve eigenvalues & eigenvectors from Raster PCA in R?MATLAB perform PCA on the correlation matrixuse correlation matrix in robust PCA functions RHow can you create a correlation matrix in PCA on Python?PCA with zero and high correlation in dataDon't know why eigen() gives a vectors of wrong sign and the loading matrix is just vector

Font hinting is lost in Chrome-like browsers (for some languages )

LaTeX closing $ signs makes cursor jump

Has the BBC provided arguments for saying Brexit being cancelled is unlikely?

In Japanese, what’s the difference between “Tonari ni” (となりに) and “Tsugi” (つぎ)? When would you use one over the other?

Why Is Death Allowed In the Matrix?

Minkowski space

Watching something be written to a file live with tail

Collect Fourier series terms

Why, historically, did Gödel think CH was false?

Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?

What is the offset in a seaplane's hull?

Do I have a twin with permutated remainders?

Modeling an IPv4 Address

Why do I get two different answers for this counting problem?

How old can references or sources in a thesis be?

Have astronauts in space suits ever taken selfies? If so, how?

Is it possible to do 50 km distance without any previous training?

Why are 150k or 200k jobs considered good when there are 300k+ births a month?

Show that if two triangles built on parallel lines, with equal bases have the same perimeter only if they are congruent.

Today is the Center

Is a tag line useful on a cover?

strToHex ( string to it's hex representation as string)

Why doesn't H₄O²⁺ exist?

Test whether all array elements are factors of a number



How can I import and work with correlation matrix as the only data source in PCA and PCF in R


How can I create a correlation matrix in R?How to reconstruct the original data matrix after applying PCA in RHow can I view the source code for a function?PCA analysis using Correlation Matrix as input in RHow to retrieve eigenvalues & eigenvectors from Raster PCA in R?MATLAB perform PCA on the correlation matrixuse correlation matrix in robust PCA functions RHow can you create a correlation matrix in PCA on Python?PCA with zero and high correlation in dataDon't know why eigen() gives a vectors of wrong sign and the loading matrix is just vector






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am new to R, and am working on a problem of *mporting and working with correlation matrix as the only data source in PCA and PCF in R



I have referred to stack overflow answer banks and even books, I could not find any hints, it make it like R only work with variables data file whereas in SAS you can simply input the correlation matrix and get the PCA and PCF result easily. Hope I am wrong.



I tried to look at stack overflow answer banks, and they are mostly about how to calculate the cor matrix or eigenvalue decomposition.



Below is my attempts:



setwd("D:/BlueHDD/MAQAB/RStudio/R/PCA/Intelligence")




mydata <- read.csv("Intelligence.csv",na.strings = ".")



head(mydata)




 X M P C E H F
1 M 1.000 0.620 0.540 0.320 0.284 0.370
2 P 0.620 1.000 0.510 0.380 0.351 0.430
3 C 0.540 0.510 1.000 0.360 0.336 0.405
4 E 0.320 0.380 0.360 1.000 0.686 0.730
5 H 0.284 0.351 0.336 0.686 1.000 0.735
6 F 0.370 0.430 0.405 0.730 0.735 1.000



ii <- as.matrix(mydata[,2:7])



rownames(ii)<- c ("M","P","C","E","H","F")



colnames(ii)<- c ("M","P","C","E","H","F")



head(ii)




 M P C E H F
M 1.000 0.620 0.540 0.320 0.284 0.370
P 0.620 1.000 0.510 0.380 0.351 0.430
C 0.540 0.510 1.000 0.360 0.336 0.405
E 0.320 0.380 0.360 1.000 0.686 0.730
H 0.284 0.351 0.336 0.686 1.000 0.735
F 0.370 0.430 0.405 0.730 0.735 1.000



myPCA <- eigen(ii)



head(myPCA)




$values



[1] 3.3670861 1.1941791 0.5070061 0.3718472 0.3131559 0.2467257


$vectors



 [,1] [,2] [,3] [,4] [,5] [,6]
[1,] -0.3677678 -0.5098401 0.266985551 0.72768020 0.047584025 -0.04178482
[2,] -0.3913477 -0.4092063 0.485916591 -0.66464527 -0.005392018 -0.03872816
[3,] -0.3719504 -0.3825819 -0.831626240 -0.15204371 -0.003331423 -0.02352388
[4,] -0.4321872 0.3748248 0.021531885 0.06531777 -0.742970281 -0.34056682
[5,] -0.4219572 0.4214599 0.002730054 0.01174474 0.665109730 -0.44922966
[6,] -0.4565228 0.3288196 0.023032686 0.03473540 0.057617669 0.82365511



myPCA$values




[1] 3.3670861 1.1941791 0.5070061 0.3718472 0.3131559 0.2467257



myPCA$vectors




 [,1] [,2] [,3] [,4] [,5] [,6]
[1,] -0.3677678 -0.5098401 0.266985551 0.72768020 0.047584025 -0.04178482
[2,] -0.3913477 -0.4092063 0.485916591 -0.66464527 -0.005392018 -0.03872816
[3,] -0.3719504 -0.3825819 -0.831626240 -0.15204371 -0.003331423 -0.02352388
[4,] -0.4321872 0.3748248 0.021531885 0.06531777 -0.742970281 -0.34056682
[5,] -0.4219572 0.4214599 0.002730054 0.01174474 0.665109730 -0.44922966
[6,] -0.4565228 0.3288196 0.023032686 0.03473540 0.057617669 0.82365511


The problem now in the vector, all the "+" and "-" are opposite !




Also, from here, I don't know how to get the loading matrix. I tried the below but fails:



fit <- princomp(ii)

summary(fit) # print variance accounted for

loadings(fit) # pc loadings

plot(fit,type="lines") # scree plot

fit$scores # the principal components

biplot(fit)









share|improve this question
























  • Can you give a little more detail, maybe an example? eigendecomposition of a correlation matrix is (scaled) PCA ...

    – Ben Bolker
    Mar 9 at 2:26











  • Understood eigendecomposition of a correlation matrix is (scaled) PCA.

    – Wilks
    Mar 9 at 3:19











  • My problem is that the only data source is a correlation matrix. And I could not find the way to import it in R and manipulate it in R.

    – Wilks
    Mar 9 at 3:20











  • Below is my attempts:

    – Wilks
    Mar 9 at 3:42

















0















I am new to R, and am working on a problem of *mporting and working with correlation matrix as the only data source in PCA and PCF in R



I have referred to stack overflow answer banks and even books, I could not find any hints, it make it like R only work with variables data file whereas in SAS you can simply input the correlation matrix and get the PCA and PCF result easily. Hope I am wrong.



I tried to look at stack overflow answer banks, and they are mostly about how to calculate the cor matrix or eigenvalue decomposition.



Below is my attempts:



setwd("D:/BlueHDD/MAQAB/RStudio/R/PCA/Intelligence")




mydata <- read.csv("Intelligence.csv",na.strings = ".")



head(mydata)




 X M P C E H F
1 M 1.000 0.620 0.540 0.320 0.284 0.370
2 P 0.620 1.000 0.510 0.380 0.351 0.430
3 C 0.540 0.510 1.000 0.360 0.336 0.405
4 E 0.320 0.380 0.360 1.000 0.686 0.730
5 H 0.284 0.351 0.336 0.686 1.000 0.735
6 F 0.370 0.430 0.405 0.730 0.735 1.000



ii <- as.matrix(mydata[,2:7])



rownames(ii)<- c ("M","P","C","E","H","F")



colnames(ii)<- c ("M","P","C","E","H","F")



head(ii)




 M P C E H F
M 1.000 0.620 0.540 0.320 0.284 0.370
P 0.620 1.000 0.510 0.380 0.351 0.430
C 0.540 0.510 1.000 0.360 0.336 0.405
E 0.320 0.380 0.360 1.000 0.686 0.730
H 0.284 0.351 0.336 0.686 1.000 0.735
F 0.370 0.430 0.405 0.730 0.735 1.000



myPCA <- eigen(ii)



head(myPCA)




$values



[1] 3.3670861 1.1941791 0.5070061 0.3718472 0.3131559 0.2467257


$vectors



 [,1] [,2] [,3] [,4] [,5] [,6]
[1,] -0.3677678 -0.5098401 0.266985551 0.72768020 0.047584025 -0.04178482
[2,] -0.3913477 -0.4092063 0.485916591 -0.66464527 -0.005392018 -0.03872816
[3,] -0.3719504 -0.3825819 -0.831626240 -0.15204371 -0.003331423 -0.02352388
[4,] -0.4321872 0.3748248 0.021531885 0.06531777 -0.742970281 -0.34056682
[5,] -0.4219572 0.4214599 0.002730054 0.01174474 0.665109730 -0.44922966
[6,] -0.4565228 0.3288196 0.023032686 0.03473540 0.057617669 0.82365511



myPCA$values




[1] 3.3670861 1.1941791 0.5070061 0.3718472 0.3131559 0.2467257



myPCA$vectors




 [,1] [,2] [,3] [,4] [,5] [,6]
[1,] -0.3677678 -0.5098401 0.266985551 0.72768020 0.047584025 -0.04178482
[2,] -0.3913477 -0.4092063 0.485916591 -0.66464527 -0.005392018 -0.03872816
[3,] -0.3719504 -0.3825819 -0.831626240 -0.15204371 -0.003331423 -0.02352388
[4,] -0.4321872 0.3748248 0.021531885 0.06531777 -0.742970281 -0.34056682
[5,] -0.4219572 0.4214599 0.002730054 0.01174474 0.665109730 -0.44922966
[6,] -0.4565228 0.3288196 0.023032686 0.03473540 0.057617669 0.82365511


The problem now in the vector, all the "+" and "-" are opposite !




Also, from here, I don't know how to get the loading matrix. I tried the below but fails:



fit <- princomp(ii)

summary(fit) # print variance accounted for

loadings(fit) # pc loadings

plot(fit,type="lines") # scree plot

fit$scores # the principal components

biplot(fit)









share|improve this question
























  • Can you give a little more detail, maybe an example? eigendecomposition of a correlation matrix is (scaled) PCA ...

    – Ben Bolker
    Mar 9 at 2:26











  • Understood eigendecomposition of a correlation matrix is (scaled) PCA.

    – Wilks
    Mar 9 at 3:19











  • My problem is that the only data source is a correlation matrix. And I could not find the way to import it in R and manipulate it in R.

    – Wilks
    Mar 9 at 3:20











  • Below is my attempts:

    – Wilks
    Mar 9 at 3:42













0












0








0








I am new to R, and am working on a problem of *mporting and working with correlation matrix as the only data source in PCA and PCF in R



I have referred to stack overflow answer banks and even books, I could not find any hints, it make it like R only work with variables data file whereas in SAS you can simply input the correlation matrix and get the PCA and PCF result easily. Hope I am wrong.



I tried to look at stack overflow answer banks, and they are mostly about how to calculate the cor matrix or eigenvalue decomposition.



Below is my attempts:



setwd("D:/BlueHDD/MAQAB/RStudio/R/PCA/Intelligence")




mydata <- read.csv("Intelligence.csv",na.strings = ".")



head(mydata)




 X M P C E H F
1 M 1.000 0.620 0.540 0.320 0.284 0.370
2 P 0.620 1.000 0.510 0.380 0.351 0.430
3 C 0.540 0.510 1.000 0.360 0.336 0.405
4 E 0.320 0.380 0.360 1.000 0.686 0.730
5 H 0.284 0.351 0.336 0.686 1.000 0.735
6 F 0.370 0.430 0.405 0.730 0.735 1.000



ii <- as.matrix(mydata[,2:7])



rownames(ii)<- c ("M","P","C","E","H","F")



colnames(ii)<- c ("M","P","C","E","H","F")



head(ii)




 M P C E H F
M 1.000 0.620 0.540 0.320 0.284 0.370
P 0.620 1.000 0.510 0.380 0.351 0.430
C 0.540 0.510 1.000 0.360 0.336 0.405
E 0.320 0.380 0.360 1.000 0.686 0.730
H 0.284 0.351 0.336 0.686 1.000 0.735
F 0.370 0.430 0.405 0.730 0.735 1.000



myPCA <- eigen(ii)



head(myPCA)




$values



[1] 3.3670861 1.1941791 0.5070061 0.3718472 0.3131559 0.2467257


$vectors



 [,1] [,2] [,3] [,4] [,5] [,6]
[1,] -0.3677678 -0.5098401 0.266985551 0.72768020 0.047584025 -0.04178482
[2,] -0.3913477 -0.4092063 0.485916591 -0.66464527 -0.005392018 -0.03872816
[3,] -0.3719504 -0.3825819 -0.831626240 -0.15204371 -0.003331423 -0.02352388
[4,] -0.4321872 0.3748248 0.021531885 0.06531777 -0.742970281 -0.34056682
[5,] -0.4219572 0.4214599 0.002730054 0.01174474 0.665109730 -0.44922966
[6,] -0.4565228 0.3288196 0.023032686 0.03473540 0.057617669 0.82365511



myPCA$values




[1] 3.3670861 1.1941791 0.5070061 0.3718472 0.3131559 0.2467257



myPCA$vectors




 [,1] [,2] [,3] [,4] [,5] [,6]
[1,] -0.3677678 -0.5098401 0.266985551 0.72768020 0.047584025 -0.04178482
[2,] -0.3913477 -0.4092063 0.485916591 -0.66464527 -0.005392018 -0.03872816
[3,] -0.3719504 -0.3825819 -0.831626240 -0.15204371 -0.003331423 -0.02352388
[4,] -0.4321872 0.3748248 0.021531885 0.06531777 -0.742970281 -0.34056682
[5,] -0.4219572 0.4214599 0.002730054 0.01174474 0.665109730 -0.44922966
[6,] -0.4565228 0.3288196 0.023032686 0.03473540 0.057617669 0.82365511


The problem now in the vector, all the "+" and "-" are opposite !




Also, from here, I don't know how to get the loading matrix. I tried the below but fails:



fit <- princomp(ii)

summary(fit) # print variance accounted for

loadings(fit) # pc loadings

plot(fit,type="lines") # scree plot

fit$scores # the principal components

biplot(fit)









share|improve this question
















I am new to R, and am working on a problem of *mporting and working with correlation matrix as the only data source in PCA and PCF in R



I have referred to stack overflow answer banks and even books, I could not find any hints, it make it like R only work with variables data file whereas in SAS you can simply input the correlation matrix and get the PCA and PCF result easily. Hope I am wrong.



I tried to look at stack overflow answer banks, and they are mostly about how to calculate the cor matrix or eigenvalue decomposition.



Below is my attempts:



setwd("D:/BlueHDD/MAQAB/RStudio/R/PCA/Intelligence")




mydata <- read.csv("Intelligence.csv",na.strings = ".")



head(mydata)




 X M P C E H F
1 M 1.000 0.620 0.540 0.320 0.284 0.370
2 P 0.620 1.000 0.510 0.380 0.351 0.430
3 C 0.540 0.510 1.000 0.360 0.336 0.405
4 E 0.320 0.380 0.360 1.000 0.686 0.730
5 H 0.284 0.351 0.336 0.686 1.000 0.735
6 F 0.370 0.430 0.405 0.730 0.735 1.000



ii <- as.matrix(mydata[,2:7])



rownames(ii)<- c ("M","P","C","E","H","F")



colnames(ii)<- c ("M","P","C","E","H","F")



head(ii)




 M P C E H F
M 1.000 0.620 0.540 0.320 0.284 0.370
P 0.620 1.000 0.510 0.380 0.351 0.430
C 0.540 0.510 1.000 0.360 0.336 0.405
E 0.320 0.380 0.360 1.000 0.686 0.730
H 0.284 0.351 0.336 0.686 1.000 0.735
F 0.370 0.430 0.405 0.730 0.735 1.000



myPCA <- eigen(ii)



head(myPCA)




$values



[1] 3.3670861 1.1941791 0.5070061 0.3718472 0.3131559 0.2467257


$vectors



 [,1] [,2] [,3] [,4] [,5] [,6]
[1,] -0.3677678 -0.5098401 0.266985551 0.72768020 0.047584025 -0.04178482
[2,] -0.3913477 -0.4092063 0.485916591 -0.66464527 -0.005392018 -0.03872816
[3,] -0.3719504 -0.3825819 -0.831626240 -0.15204371 -0.003331423 -0.02352388
[4,] -0.4321872 0.3748248 0.021531885 0.06531777 -0.742970281 -0.34056682
[5,] -0.4219572 0.4214599 0.002730054 0.01174474 0.665109730 -0.44922966
[6,] -0.4565228 0.3288196 0.023032686 0.03473540 0.057617669 0.82365511



myPCA$values




[1] 3.3670861 1.1941791 0.5070061 0.3718472 0.3131559 0.2467257



myPCA$vectors




 [,1] [,2] [,3] [,4] [,5] [,6]
[1,] -0.3677678 -0.5098401 0.266985551 0.72768020 0.047584025 -0.04178482
[2,] -0.3913477 -0.4092063 0.485916591 -0.66464527 -0.005392018 -0.03872816
[3,] -0.3719504 -0.3825819 -0.831626240 -0.15204371 -0.003331423 -0.02352388
[4,] -0.4321872 0.3748248 0.021531885 0.06531777 -0.742970281 -0.34056682
[5,] -0.4219572 0.4214599 0.002730054 0.01174474 0.665109730 -0.44922966
[6,] -0.4565228 0.3288196 0.023032686 0.03473540 0.057617669 0.82365511


The problem now in the vector, all the "+" and "-" are opposite !




Also, from here, I don't know how to get the loading matrix. I tried the below but fails:



fit <- princomp(ii)

summary(fit) # print variance accounted for

loadings(fit) # pc loadings

plot(fit,type="lines") # scree plot

fit$scores # the principal components

biplot(fit)






r pca






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 10 at 16:18









halfer

14.7k759116




14.7k759116










asked Mar 9 at 2:09









WilksWilks

11




11












  • Can you give a little more detail, maybe an example? eigendecomposition of a correlation matrix is (scaled) PCA ...

    – Ben Bolker
    Mar 9 at 2:26











  • Understood eigendecomposition of a correlation matrix is (scaled) PCA.

    – Wilks
    Mar 9 at 3:19











  • My problem is that the only data source is a correlation matrix. And I could not find the way to import it in R and manipulate it in R.

    – Wilks
    Mar 9 at 3:20











  • Below is my attempts:

    – Wilks
    Mar 9 at 3:42

















  • Can you give a little more detail, maybe an example? eigendecomposition of a correlation matrix is (scaled) PCA ...

    – Ben Bolker
    Mar 9 at 2:26











  • Understood eigendecomposition of a correlation matrix is (scaled) PCA.

    – Wilks
    Mar 9 at 3:19











  • My problem is that the only data source is a correlation matrix. And I could not find the way to import it in R and manipulate it in R.

    – Wilks
    Mar 9 at 3:20











  • Below is my attempts:

    – Wilks
    Mar 9 at 3:42
















Can you give a little more detail, maybe an example? eigendecomposition of a correlation matrix is (scaled) PCA ...

– Ben Bolker
Mar 9 at 2:26





Can you give a little more detail, maybe an example? eigendecomposition of a correlation matrix is (scaled) PCA ...

– Ben Bolker
Mar 9 at 2:26













Understood eigendecomposition of a correlation matrix is (scaled) PCA.

– Wilks
Mar 9 at 3:19





Understood eigendecomposition of a correlation matrix is (scaled) PCA.

– Wilks
Mar 9 at 3:19













My problem is that the only data source is a correlation matrix. And I could not find the way to import it in R and manipulate it in R.

– Wilks
Mar 9 at 3:20





My problem is that the only data source is a correlation matrix. And I could not find the way to import it in R and manipulate it in R.

– Wilks
Mar 9 at 3:20













Below is my attempts:

– Wilks
Mar 9 at 3:42





Below is my attempts:

– Wilks
Mar 9 at 3:42












1 Answer
1






active

oldest

votes


















1














You can perform PCA in R with the princomp function. The documentation says that if you supply the argument covmat it will compute the principal components from the covariance matrix. But it also works to use this argument with the correlation matrix.



Here is a simple example using the iris data.



## principal components from the original data
princomp(iris[,1:4], cor=T)
Standard deviations:
Comp.1 Comp.2 Comp.3 Comp.4
1.7083611 0.9560494 0.3830886 0.1439265


Now suppose that you only have a correlation matrix



## from correlation matrix
CM = cor(iris[,1:4])
myPCA = princomp(covmat=CM)
myPCA
Standard deviations:
Comp.1 Comp.2 Comp.3 Comp.4
1.7083611 0.9560494 0.3830886 0.1439265


You get the same answer either way. If you want the loadings, they are stored in the myPCA structure.



myPCA$loadings

Loadings:
Comp.1 Comp.2 Comp.3 Comp.4
Sepal.Length 0.521 0.377 0.720 0.261
Sepal.Width -0.269 0.923 -0.244 -0.124
Petal.Length 0.580 -0.142 -0.801
Petal.Width 0.565 -0.634 0.524

Comp.1 Comp.2 Comp.3 Comp.4
SS loadings 1.00 1.00 1.00 1.00
Proportion Var 0.25 0.25 0.25 0.25
Cumulative Var 0.25 0.50 0.75 1.00





share|improve this answer

























  • iris.csv is an original variable dataset. My problem is I only have the correlation matrix. And I could not find the way to import it in R and manipulate it in R.

    – Wilks
    Mar 9 at 3:27











  • Yes, but CM is just a correlation matrix.

    – G5W
    Mar 9 at 11:50











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073323%2fhow-can-i-import-and-work-with-correlation-matrix-as-the-only-data-source-in-pca%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You can perform PCA in R with the princomp function. The documentation says that if you supply the argument covmat it will compute the principal components from the covariance matrix. But it also works to use this argument with the correlation matrix.



Here is a simple example using the iris data.



## principal components from the original data
princomp(iris[,1:4], cor=T)
Standard deviations:
Comp.1 Comp.2 Comp.3 Comp.4
1.7083611 0.9560494 0.3830886 0.1439265


Now suppose that you only have a correlation matrix



## from correlation matrix
CM = cor(iris[,1:4])
myPCA = princomp(covmat=CM)
myPCA
Standard deviations:
Comp.1 Comp.2 Comp.3 Comp.4
1.7083611 0.9560494 0.3830886 0.1439265


You get the same answer either way. If you want the loadings, they are stored in the myPCA structure.



myPCA$loadings

Loadings:
Comp.1 Comp.2 Comp.3 Comp.4
Sepal.Length 0.521 0.377 0.720 0.261
Sepal.Width -0.269 0.923 -0.244 -0.124
Petal.Length 0.580 -0.142 -0.801
Petal.Width 0.565 -0.634 0.524

Comp.1 Comp.2 Comp.3 Comp.4
SS loadings 1.00 1.00 1.00 1.00
Proportion Var 0.25 0.25 0.25 0.25
Cumulative Var 0.25 0.50 0.75 1.00





share|improve this answer

























  • iris.csv is an original variable dataset. My problem is I only have the correlation matrix. And I could not find the way to import it in R and manipulate it in R.

    – Wilks
    Mar 9 at 3:27











  • Yes, but CM is just a correlation matrix.

    – G5W
    Mar 9 at 11:50















1














You can perform PCA in R with the princomp function. The documentation says that if you supply the argument covmat it will compute the principal components from the covariance matrix. But it also works to use this argument with the correlation matrix.



Here is a simple example using the iris data.



## principal components from the original data
princomp(iris[,1:4], cor=T)
Standard deviations:
Comp.1 Comp.2 Comp.3 Comp.4
1.7083611 0.9560494 0.3830886 0.1439265


Now suppose that you only have a correlation matrix



## from correlation matrix
CM = cor(iris[,1:4])
myPCA = princomp(covmat=CM)
myPCA
Standard deviations:
Comp.1 Comp.2 Comp.3 Comp.4
1.7083611 0.9560494 0.3830886 0.1439265


You get the same answer either way. If you want the loadings, they are stored in the myPCA structure.



myPCA$loadings

Loadings:
Comp.1 Comp.2 Comp.3 Comp.4
Sepal.Length 0.521 0.377 0.720 0.261
Sepal.Width -0.269 0.923 -0.244 -0.124
Petal.Length 0.580 -0.142 -0.801
Petal.Width 0.565 -0.634 0.524

Comp.1 Comp.2 Comp.3 Comp.4
SS loadings 1.00 1.00 1.00 1.00
Proportion Var 0.25 0.25 0.25 0.25
Cumulative Var 0.25 0.50 0.75 1.00





share|improve this answer

























  • iris.csv is an original variable dataset. My problem is I only have the correlation matrix. And I could not find the way to import it in R and manipulate it in R.

    – Wilks
    Mar 9 at 3:27











  • Yes, but CM is just a correlation matrix.

    – G5W
    Mar 9 at 11:50













1












1








1







You can perform PCA in R with the princomp function. The documentation says that if you supply the argument covmat it will compute the principal components from the covariance matrix. But it also works to use this argument with the correlation matrix.



Here is a simple example using the iris data.



## principal components from the original data
princomp(iris[,1:4], cor=T)
Standard deviations:
Comp.1 Comp.2 Comp.3 Comp.4
1.7083611 0.9560494 0.3830886 0.1439265


Now suppose that you only have a correlation matrix



## from correlation matrix
CM = cor(iris[,1:4])
myPCA = princomp(covmat=CM)
myPCA
Standard deviations:
Comp.1 Comp.2 Comp.3 Comp.4
1.7083611 0.9560494 0.3830886 0.1439265


You get the same answer either way. If you want the loadings, they are stored in the myPCA structure.



myPCA$loadings

Loadings:
Comp.1 Comp.2 Comp.3 Comp.4
Sepal.Length 0.521 0.377 0.720 0.261
Sepal.Width -0.269 0.923 -0.244 -0.124
Petal.Length 0.580 -0.142 -0.801
Petal.Width 0.565 -0.634 0.524

Comp.1 Comp.2 Comp.3 Comp.4
SS loadings 1.00 1.00 1.00 1.00
Proportion Var 0.25 0.25 0.25 0.25
Cumulative Var 0.25 0.50 0.75 1.00





share|improve this answer















You can perform PCA in R with the princomp function. The documentation says that if you supply the argument covmat it will compute the principal components from the covariance matrix. But it also works to use this argument with the correlation matrix.



Here is a simple example using the iris data.



## principal components from the original data
princomp(iris[,1:4], cor=T)
Standard deviations:
Comp.1 Comp.2 Comp.3 Comp.4
1.7083611 0.9560494 0.3830886 0.1439265


Now suppose that you only have a correlation matrix



## from correlation matrix
CM = cor(iris[,1:4])
myPCA = princomp(covmat=CM)
myPCA
Standard deviations:
Comp.1 Comp.2 Comp.3 Comp.4
1.7083611 0.9560494 0.3830886 0.1439265


You get the same answer either way. If you want the loadings, they are stored in the myPCA structure.



myPCA$loadings

Loadings:
Comp.1 Comp.2 Comp.3 Comp.4
Sepal.Length 0.521 0.377 0.720 0.261
Sepal.Width -0.269 0.923 -0.244 -0.124
Petal.Length 0.580 -0.142 -0.801
Petal.Width 0.565 -0.634 0.524

Comp.1 Comp.2 Comp.3 Comp.4
SS loadings 1.00 1.00 1.00 1.00
Proportion Var 0.25 0.25 0.25 0.25
Cumulative Var 0.25 0.50 0.75 1.00






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 9 at 11:52

























answered Mar 9 at 2:28









G5WG5W

23.6k92244




23.6k92244












  • iris.csv is an original variable dataset. My problem is I only have the correlation matrix. And I could not find the way to import it in R and manipulate it in R.

    – Wilks
    Mar 9 at 3:27











  • Yes, but CM is just a correlation matrix.

    – G5W
    Mar 9 at 11:50

















  • iris.csv is an original variable dataset. My problem is I only have the correlation matrix. And I could not find the way to import it in R and manipulate it in R.

    – Wilks
    Mar 9 at 3:27











  • Yes, but CM is just a correlation matrix.

    – G5W
    Mar 9 at 11:50
















iris.csv is an original variable dataset. My problem is I only have the correlation matrix. And I could not find the way to import it in R and manipulate it in R.

– Wilks
Mar 9 at 3:27





iris.csv is an original variable dataset. My problem is I only have the correlation matrix. And I could not find the way to import it in R and manipulate it in R.

– Wilks
Mar 9 at 3:27













Yes, but CM is just a correlation matrix.

– G5W
Mar 9 at 11:50





Yes, but CM is just a correlation matrix.

– G5W
Mar 9 at 11:50



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073323%2fhow-can-i-import-and-work-with-correlation-matrix-as-the-only-data-source-in-pca%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229