2.1.24.4.14 ocmath_corr_coeff


Description

Calculates Pearson rank, Spearman rank and Kendall rank correlation coefficients. This is an OriginPro only function.

Syntax

int ocmath_corr_coeff( UINT nRows, UINT nCols, const double * pData, double * pPeaCorr, double * pPeaSig, double * pSpeCorr, double * pSpeSig, double * pKenCorr, double * pKenSig, int nExcludeMissing = CORR_EXCLUDE_MISSING_PAIRWISE )

Parameters

nRows
[input]row number of data matrix
nCols
[input]column number of data matrix
pData
[input]pointer to data points
pPeaCorr
[Output]pointer to matrix of Pearson rank correlation coefficients. Size of matrix should be nCols*nCols.
pPeaSig
[Output]pointer to matrix of Pearson rank correlation significants. Size of matrix should be nCols*nCols. Diagonal should be NANUM
pSpeCorr
[Output]pointer to matrix of Spearman rank correlation coefficients. Size of matrix should be nCols*nCols.
pSpeSig
[Output]pointer to matrix of Spearman rank correlation significants. Size of matrix should be nCols*nCols. Diagonal should be NANUM
pKenCorr
[Output]pointer to matrix of Kendall rank correlation coefficients. Size of matrix should be nCols*nCols.
pKenSig
[Output]pointer to matrix of Kendall rank correlation significants. Size of matrix should be nCols*nCols. Diagonal should be NANUM
nExcludeMissing
[input] if set as CORR_EXCLUDE_MISSING_PAIRWISE, will exclude the row when the whole row are missing values,
if set as CORR_EXCLUDE_MISSING_LISTWISE, will exclude the row when any cell is with mising value in that row.

Return

Returns STATS_NO_ERROR on successful exit or an STATS error code on failure.

Examples

EX1

void ocmath_corr_coeff_Ex1()
{
    matrix mData = {{10,12,13,11},{13,10,11,12},{9,12,10,11}};
    double *pmData = mData;
    
    int nRet;
    int nRows = mData.GetNumRows();
    int nCols = mData.GetNumCols();
    
    double* pmPeaCov = NULL;
    double* pmPeaSig = NULL;
    matrix mPeaCorr(nCols, nCols);
    matrix mPeaSig(nCols, nCols);
    pmPeaCov = mPeaCorr;
    pmPeaSig = mPeaSig;    
    
    double* pmSpeCov = NULL;
    double* pmSpeSig = NULL;
    matrix mSpeCorr(nCols, nCols);
    matrix mSpeSig(nCols, nCols);
    pmSpeCov = mSpeCorr;
    pmSpeSig = mSpeSig;    
    
    double* pmKenCov = NULL;
    double* pmKenSig = NULL;
    matrix mKenCorr(nCols, nCols);
    matrix mKenSig(nCols, nCols);
    pmKenCov = mKenCorr;
    pmKenSig = mKenSig;    
        
    nRet = ocmath_corr_coeff(nRows, nCols, pmData, pmPeaCov, pmPeaSig, pmSpeCov, pmSpeSig, pmKenCov, pmKenSig);
    out_int("nRet=", nRet); // print out return value.
    
    int ii, jj;
    out_str("Pearson");//print out Pearson rank correlation coefficients
    for(ii=0; ii<mPeaCorr.GetNumRows(); ii++) 
    {
        for(jj =0; jj<mPeaCorr.GetNumCols(); jj++)
            printf("%f\t", mPeaCorr[ii][jj]);
        printf("\n");
    }
    
    out_str("Spearman");//print out Spearman rank correlation coefficients
    for(ii=0; ii<mSpeCorr.GetNumRows(); ii++)
    {
        for(jj =0; jj<mSpeCorr.GetNumCols(); jj++)
            printf("%f\t", mSpeCorr[ii][jj]);
        printf("\n");
    }
    
    out_str("Kendall");//print out Kendall rank correlation coefficients
    for(ii=0; ii<mKenCorr.GetNumRows(); ii++)
    {
        for(jj =0; jj<mKenCorr.GetNumCols(); jj++)
            printf("%f\t", mKenCorr[ii][jj]);
        printf("\n");
    }
}

Remark

See Also

Header to Included

origin.h

Reference