2.13.1.2 corrcoef(Pro)
Menu Information
Statistics: Descriptive Statistics: Correlation Coefficient
Brief Information
Calculate correlation coefficients for two or more columns
Additional Information
This feature is for OriginPro only.
Command Line Usage
1. corrcoef irng:= (wcol(1), wcol(2), wcol(3)) spearman:=1;
2. corrcoef irng:= (wcol(1):wcol(3)) scatter:=1;
3. corrcoef irng:= (col(a), col(b), col(c)) rt:= [book2]<new name:=CorrCoef> flag:=1;
4. corrcoef irng:= (col(a), col(b)) spearman:=1 kendall:=1 swks:=[<input>]<new> kwks:=[<input>]<new> flag:=1;
X-Function Execution Options
Please refer to the page for additional option switches when accessing the x-function from script
Variables
Display Name
|
Variable Name
|
I/O and Type
|
Default Value
|
Description
|
Input
|
irng
|
Input
Range
|
<active>
|
Specify the input data ranges, at least two ranges. Note that beginning with Origin 2020b, there is a shortened syntax that follows the form [Book]Sheet!(N1:N2), N1 = the beginning column index and N2 being the ending column index in a contiguous range of columns. More complex strings from non-contiguous data of the form [Book]Sheet!([Book]Sheet!N1:N2,[Book]Sheet!N3:N4) are also possible.
|
Pearson
|
pearson
|
Input
int
|
1
|
Decide if Pearson's product moment correlation coefficient is computed.
|
Spearman
|
spearman
|
Input
int
|
0
|
Decide if Spearman Rank correlation coefficient is computed.
|
Kendall
|
kendall
|
Input
int
|
0
|
Decide if Kendall correlation coefficient is computed.
|
Scatter plots
|
scatter
|
Input
int
|
0
|
Indicate whether to produce scatter plots for each pair of ranges.
|
Add Confidence Ellipse
|
ellipse
|
Input
int
|
0
|
Decide whether the confidence ellipse is plotted.
|
Confidence Level for Ellipse(%)
|
conflevel
|
Input
double
|
95
|
Specify the confidence level for the confidence ellipses.
|
Heatmap Plot
|
heatmap
|
Input
int
|
1
|
Specify to output the heatmap plot.
Option List:
|
Scatter Matrix Plot
|
scatterMatrix
|
Input
TreeNode
|
|
Specify to output the scatter matrix plot.
Option List:
See Details of Settings TreeNode section for more details setting.
|
Exclude Missing Values
|
missing
|
Input
int
|
0
|
Specify how to exclude the missing values.
Option list:
- pairwise:Pairwise
- Exclude the missing value pairwisely. That is, when computing correlation between two columns, the corresponding two entries will be excluded if there is any missing value.
- listwise:Listwise
- Exclude the missing value listwisely. That is, exclude the entire row for all dataset if there are any missing values.
|
Plot Data
|
rd
|
Output
ReportData
|
<optional>
|
Specify the output worksheet for scatter/ellipse data.
|
Plots
|
rtplot
|
Output
ReportTree
|
<optional>
|
Specify the report worksheet for scatter plots and confidence ellipse.
|
Results
|
rt
|
Output
ReportTree
|
[<input>]<new>
|
Specify the output worksheet for analysis results.
|
Pearson Sheet
|
pwks
|
Output
Worksheet
|
[<input>]<new>
|
Specify the output worksheet for Pearson Correlations.
|
Spearman Sheet
|
swks
|
Output
Worksheet
|
<optional>
|
Specify the output worksheet for Spearman Correlations.
|
Kendall Sheet
|
kwks
|
Output
Worksheet
|
<optional>
|
Specify the output worksheet for Kendall Correlations.
|
Show Significance in Result Table
|
sig
|
Input
int
|
1
|
Specify whether to display Significance in Result Table in the report worksheet.
|
Flag Significant Correlations
|
flag
|
Input
int
|
0
|
Specify whether to mark the Correlation Coefficient value significant at the 0.05 level with asterisk in Result Table, and highlight the Correlation Coefficient value significant at the 0.05 level with red color in Pearson/Spearman/Kendall Sheet.
|
Examples
/*
This example shows how to caculate three kinds of correlation coefficents, which are Pearson,
Spearman and Kendall correlation coefficent,When the distributions of the two variables satisfy
normality, we can use Pearson correlation coefficent to describe the relationship of the two
variables.Contrariwise, we should use Spearman or Kendall correlation coefficent.
OriginPath\Samples\Statistics folder.
1. Import the sample data into a book in Origin
2. use corrcoef XF to calculate the correlation coefficents
3. put the result into a new sheet
4. Plot the scatter into a new graph
*/
/*Import the sample data into a new book*/
string fname$=system.path.program$ + "Samples\Statistics\correlations.dat";
newbook;
impASC;
string bkn$=%H;
/*New a sheet to store the results*/
newsheet book:=bkn$ name:="Result" label:="method|coefficent|Sig.";
/*Use the corrcoef XF to calculate the correlation coefficent*/
corrcoef irng:=[bkn$]1!(col(2),col(3)) pearson:=1 rt:=<new name:="Pearson_Result">;
corrcoef irng:=[bkn$]1!(col(2),col(3)) pearson:=0 spearman:=1 rt:=<new name:="Spearman_Result">;
corrcoef irng:=[bkn$]1!(col(2),col(3)) pearson:=0 kendall:=1 rt:=<new name:="Kendall_Result">;
plotxy iy:=[bkn$]1!(2,3) plot:=201 ogl:=<new name:="Scatter Plot">;
//The first column of the new book is used to store the method of the correlation coefficent.
//The second one is exploited to store the coefficent, and the significant value is put in the third column.
range method=[bkn$]Result!col(1);
range coef=[bkn$]Result!col(2);
range Sig=[bkn$]Result!col(3);
method[1]$=Pearson;
method[2]$=Spearman;
method[3]$=Kendall;
getresults iw:=[bkn$]Pearson_Result tr:=mytreePearson;
getresults iw:=[bkn$]Spearman_Result tr:=mytreeSpearman;
getresults iw:=[bkn$]Kendall_Result tr:=mytreeKendall;
coef[1]=mytreePearson.peasoncorr.corr1.c2;
Sig[1]=mytreePearson.peasoncorr.Sig1.c2;
coef[2]=mytreeSpearman.spearcorr.corr1.c2;
Sig[2]=mytreeSpearman.spearcorr.Sig1.c2;
coef[3]=mytreeKendall.kencorr.corr1.c2;
Sig[3]=mytreeKendall.kencorr.Sig1.c2;
More Information
For more information, please refer to our User Guide.
Details of Settings TreeNode
The scatterMatrix tree specifies all setting options for the corrcoef X-Function.
Syntax: scatterMatrix.Treenode:=<value>
Example: scatterMatrix.ellipse = 1
Treenode
|
Label
|
Type
|
Default
|
Description
|
ellipse
|
Add Confidence Ellipse
|
Input int
|
0
|
Specify whether to show the confidence ellipse for the Scatter Matrix plot.
- 0=Not add confidence ellipse
- 1=Add confidence ellipse
|
conflevel
|
Confidence Level for Ellipse(%)
|
Input int
|
95
|
Specify the confidence level for ellipses. This value must be greater than 0 and less than 100.
|
Related X-Functions
pcorrcoef
Keywords:pearson, spearman, kendall
|