iFocus.Life News News - Breaking News & Top Stories - Latest World, US & Local News,Get the latest news, exclusives, sport, celebrities, showbiz, politics, business and lifestyle from The iFocus.Life,

How to Calculate a Correlation Matrix

104 38

    Computing a Correlation Matrix with R

    • 1). Get the data. If your data is in Excel, the easiest method is to save it as a .csv file (In Excel 7, click "File", then "Save as," then "other formats." Then in "Save as type," scroll down to CSV (comma separated values). Each row should have data on one subject, and each column should be one variable.

    • 2). Read the data into R using read.csv. For instance, if your data is in "c:\mydisk\mydir\data.csv" enter
      mydata <- read.csv ("c:/mydisk/mydir/data.csv").

    • 3). Calculate the correlation matrix using cor(). For example: cor(mydata). Or, you can store the correlation matrix as an object for later use, using: cormat <- cor(mydata).

    Computing a Correlation Matrix with SAS

    • 1). Get the data. SAS can read data in many formats. If you store your data in Excel, have one subject on each row and one variable in each column

    • 2). Read the data into SAS. You can use the IMPORT wizard to get your data. Click on "File," then "Import data," then choose a data type using the drop-down menu. Click "Next" and navigate to your data, then click "Finish."

    • 3). Calculate the correlation matrix. If your data is saved in SAS as mydata, with variables VAR1, VAR2 and VAR3, then type: PROC CORR data = mydata; VAR var1 var2 var3; RUN;

Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time
You might also like on "Society & Culture & Entertainment"

Leave A Reply

Your email address will not be published.