2.1.24.6.12 ocmath_t_test_one_sample


Description

Function to perform a One Sample t-Test with samples's mean and SD.

Syntax

int ocmath_t_test_one_sample( UINT nSize, double dMean, double dSD, double * pProb, int nFlag, int * pDOF = NULL, double * pTValue = NULL, double dHypotValue = 0.0, int TailType = TAILED_TEST_TWO )

Parameters

nSize
[input] number of samples.
dMean
[input] samples's mean value.
dSD
[input] samples's standard deviation.
pProb
[output] pointer to P-value: is the probability that the value of the t-test
is equal to or more extreme than the observed value by chance.
nFlag
[input] two options: MIN_EQUAL_TO_MAX and MIN_NOT_EQUAL_TO_MAX.
if nFlag == MIN_EQUAL_TO_MAX, that is to say samples's min value is
equal to samples's max value, P-value and tValue will be NANUM, else
nFlag == MIN_NOT_EQUAL_TO_MAX, then compute P-value and tValue. so
before do t-test, please check if min == max.
pDOF
[output] if not NULL, pointer to DOF: Degrees of freedom of the t-test, its
default value is NULL.
pTValue
[output] if not NULL, pointer to tValue: Value of the t-test, its default
value is NULL.
dHypotValue
[input] hypothesis that samples come from a distribution with mean dHypotValue,
its default value is 0.0.
TailType
[input] three options:
'TAILED_TEST_TWO' -- hypothesis that mean is not dHypotValue.
'TAILED_TEST_UPPER' -- hypothesis that mean is less than dHypotValue.
'TAILED_TEST_LOWER' -- hypothesis that mean is larger than dHypotValue.
Its default value is TAILED_TEST_TWO.

Return

Return OE_NOERROR if succeed, otherwise, non-zero error code is returned.

Examples

EX1

void ocmath_t_test_one_sample_ex1()
{
    vector vtemp = {-0.28611, 1.00966, 1.51881, -0.28641, -0.9683, -0.17186, 0.65496, -1.14554,
                    -0.07316, 1.39309, -1.72159, 1.29403, -0.95088, -0.30126, -0.40809, -2.75751,
                    0.09494, 0.3524, -0.22458, 0.07528, -0.18389, -1.22863, 0.37092, 0.82494,
                    -0.38305, 0.55881, -0.86485, -1.22789, -2.14137, 0.17896, -0.99818, -0.4235};
    double dmin, dmax;
    vtemp.GetMinMax(dmin, dmax);
    int nFlag;
    if(dmin == dmax)
        nFlag = MIN_EQUAL_TO_MAX;
    else
        nFlag = MIN_NOT_EQUAL_TO_MAX;
    double dMean, dSD;
    int nRet = ocmath_row_desc_stats(1, vtemp.GetSize(), vtemp, &dMean, &dSD);    
    int TailType;
    double dHypotValue = 0.0;
    double dProb, dTValue;
    int nDOF;
    nRet = ocmath_t_test_one_sample(vtemp.GetSize(), dMean, dSD, &dProb, nFlag, &nDOF, &dTValue, dHypotValue, TailType);
}
// At the end of example: dProb = 0.14289, dTValue = -1.50326, nDOF = 31.

Remark

Get probability of the value of the t-test, Degrees of freedom of the t-test(if pDOF != NULL) and Value of the t-test(if pTValue != NULL).

See Also

Header to Include

origin.h

Reference