ocmath_row_desc_stats

 

Contents

Description

get input matrix's each row's mean, standard deviation, se of mean, min, max, sum and total number of data point and put result to relative pointer if the pointer not NULL.

Syntax

int ocmath_row_desc_stats( UINT nRows, UINT nCols, const double * pMat, double * pMean = NULL, double * pSd = NULL, double * pSem = NULL, double * pMin = NULL, double * pMax = NULL, double * pSum = NULL, double * pN = NULL, double * pLCL = NULL, double * pUCL = NULL, int nMomentDenFlag = DS_SAS1_DOF )

Parameters

nRows
[input] row number of input matrix.
nCols
[input] column number of input matrix.
pMat
[input] double pointer to input data which will do descriptive statistic.
pMean
[output] if not NULL, pointer to each row's mean value, its size should
be nRows. Its default value is NULL.
pSd
[output] if not NULL, pointer to each row's standard deviation, its size should
be nRows. Its default value is NULL.
pSem
[output] if not NULL, pointer to each row's se of mean, its size should be
nRows. Its default value is NULL.
pMin
[output] if not NULL, pointer to each row's min value, its size should be
nRows. Its default value is NULL.
pMax
[output] if not NULL, pointer to each row's max value, its size should be
nRows. Its default value is NULL.
pSum
[output] if not NULL, pointer to each row's sum, its size should be nRows.
its default value is NULL.
pN
[output] if not NULL, pointer to each row's total number of data point, its size
should be nRows. Its default value is NULL.
pLCL
[output] if not NULL, pointer to each row's lower confidence limit, its size should be nRows.
pUCL
[output] if not NULL, pointer to each row's upper confidence limit, its size should be nRows.
nMomentDenFlag
[input] Variance Divisor of Moment. This option decides the method to compute variance divisor d. You can use one of the following options: DS_SAS1_DOF, DS_SAS2_N, DS_SAS3_WDF, DS_SAS4_WGT and DS_NAG. They will compute d as degree of freedom, number of non-missing observations, degree of Sum of weights, sum of weights and WVR, respectively.

Return

Return OE_NOERROR(0) if succeed, otherwise, non-zero error code is returned:

OE_RANGE_ZERO(-3): nRows < 1 or nCols < 1

OE_NULL_POINTER(-11): pMat is NULL

OE_ALLOC_FAIL(-19): allocate internal used memory failed

Examples

EX1

/*
Usage from LT:
1. rr(1,2); // col(1) to col(2)
2. rr(1,0); // all columns, use 0 for nC2 to indicate last column
*/
bool rr(int nC1, int nC2)
{
    Worksheet wks = Project.ActiveLayer();
    if( !wks )
    {
        out_str("Please keep a worksheet active with data");
        return false;
    }    
 
    nC1--; //convert from LT index to OC index    
    if(nC2 <= 0) 
        nC2 = -1;//indicate all cols
    else
        nC2--;
 
    DataRange dr;
    string strRangeName = "X";
    dr.Add(wks, nC1, "X", nC2);//construct a data range object from worksheet
 
    matrix mData; 
    dr.GetData(mData); // get data from range object
 
    int nRows = mData.GetNumRows();
    int nCols = mData.GetNumCols();
    if( nRows <= 0 || nCols <= 0 )
    {
        out_str("Please make sure input argument r1, c1, r2, c2 all are correct.");
        return false;
    }
 
    vector vMean(nRows);
    vector vSd(nRows);
    int nRet = ocmath_row_desc_stats(nRows, nCols, mData, vMean, vSd);
 
    if( OE_NOERROR != nRet )
    {
        printf("Error: ocmath_row_desc_stats returns %d\nPlease press F1 to open Origin C help to see more details about this function.\n", nRet);
        return false;
    }   
    
    int nMean = wks.AddCol("Mean");
    int nSD = wks.AddCol("SD");
 
    DataRange drOutput; 
    drOutput.Add(wks, nMean, "X"); 
    drOutput.SetData(vMean, false, 0); 
    
    drOutput.Add(wks, nSD, "X"); 
    drOutput.SetData(vSd, false, 1);  
 
    return true;
}

Remark

See Also

ocmath_row_quantiles, ocmath_basic_summary_stats

header to Include

origin.h

Reference