📄 ostat.c
字号:
// Rows and columns are indexed from 0
// Output Test name in Means Comparison header in
iRow = 0; // row 1 and column 2 of worksheet
iCol = 1;
strOut.Format( AN1_MEANS_COMP_HDR1, strTestName );
wksMeansTable.SetCell( iRow, iCol, strOut );
// Localize significance level and the test value
strSigLevel = LocalizeDouble( dSigLevel, OSTAT_SIG_CON_LEVEL_FORMAT );
// Output Significance Level in Means Comparison header in
iRow = 3; // row 4 and column 7 of worksheet
iCol = 6;
strOut.Format( AN_MEANS_COMP_AT_LEVEL, strSigLevel );
wksMeansTable.SetCell( iRow, iCol, strOut );
// Loop on all selected datasets
for( jj = 1; jj < inData; jj++ )
{
// Compute row of current dataset
iRow++;
if( jj != 1 ) // For all but first dataset...
{
Type_Blank_Lines_To_Wks( wksMeansTable, iRow, 2 ); // Blank out 2 rows and skip one blank row
iRow++;
}
// Output current dataset name in column 2 in row of current dataset
iCol = 1;
strDB.Format( "%%A=ANOVA1Way!SelectedDataLBX.v%d$", jj );
LT_execute( strDB );
LT_get_str( "%A", szTemp, 40 );
strDatasetName = szTemp;
wksMeansTable.SetCell( iRow, iCol, strDatasetName );
// Output mean of current dataset in column 3 in row of current dataset
iCol++;
wksMeansTable.SetCell( iRow, iCol, vMEAN[jj - 1] );
// Output separator line
iRow++;
Type_Separator_Line_To_Wks( wksMeansTable, iRow );
for( ii = jj + 1; ii <= inData; ii++ )
{
// Compute row of comparison dataset and initially blank row out
iRow++;
Type_Blank_Lines_To_Wks( wksMeansTable, iRow, 1 );
// Output comparison dataset name in column 2 in row of comparison dataset
iCol = 1;
strDB.Format( "%%A=ANOVA1Way!SelectedDataLBX.v%d$", ii );
LT_execute( strDB );
LT_get_str( "%A", szTemp, 40 );
strDatasetName = szTemp;
wksMeansTable.SetCell( iRow, iCol, strDatasetName );
// Output mean of comparison dataset in column 3 in row of comparison dataset
iCol++;
wksMeansTable.SetCell( iRow, iCol, vMEAN[ii - 1] );
// Output the difference of the mean of the current dataset minus the mean of the comparison
// dataset in column 4
iCol++;
dMeanDif = vMEAN[jj - 1] - vMEAN[ii - 1];
wksMeansTable.SetCell( iRow, iCol, dMeanDif );
// Compute index into confidence limit and significance vectors
iv = ( ( ii - 1 ) * ( ii - 2 ) ) / 2 + ( jj - 1 );
// Output lower confidence limit for difference of means in column 5
iCol++;
wksMeansTable.SetCell( iRow, iCol, vCILT[iv] );
// Output upper confidence limit for difference of means in column 6
iCol++;
wksMeansTable.SetCell( iRow, iCol, vCIUT[iv] );
// Output significance decision YES or NO in column 7
iCol++;
if( vISIG[iv] == 1 )
strOut = AN_SIGNIFICANT_YES;
else
strOut = AN_SIGNIFICANT_NO;
wksMeansTable.SetCell( iRow, iCol, strOut );
}
// Output separator line
iRow++;
Type_Separator_Line_To_Wks( wksMeansTable, iRow );
}
// GJL 11/14/02 v7.0434 USE_OC_WKS_TYPE_NOT_LT
// Send output Means Comparison worksheet to Results Log
wksMeansTable.Type( TYPETARGET_OUTPUTLOG, NULL, 8 );
return OSTAT_NO_ERROR;
}
////////////////////////////////////////////////////////////////////////////////////
/**
Main Two-Way ANOVA function used to compute and output the Two-Way ANOVA
table, Means Comparison, and Power analysis.
Example:
See the [ANOVA2Way] section in the ANOVA2Way.OGS file.
Parameter:
dSigLevel=Significance Level
iInteractions=Enable (1) or disable (0) computation of Two-Way ANOVA interactions
iSpecifyLevelsBy=Method of specifying levels. By Dataset=1, by Classification
Variable=2
iN=Number of selected datasets
iPower=Bitwise integer specifying whether or not to compute actual and hypothetical
Power: Actual=1, Hypothetical=2
dPowerAlpha=Alpha used to compute Power
strSampleSize=Name of dataset holding comma separated list of hypothetical sample sizes
iTest=Bitwise integer specifying which Means Comparison test(s) if any to run:
Bonferroni=1, Scheffe=2, Tukey=4
Return:
Outputs the Two-Way ANOVA table, Means Comparison table, and Power Analysis table
to the Results Log. Returns OSTAT_NO_ERROR on successful exit or an OSTAT error
code on failure.
*/
int osANOVA2Way( double dSigLevel, int iInteractions, int iSpecifyLevelsBy, int nData, int iPower, double dPowerAlpha,
string strSampleSizes, int iTest )
{
int iErr, iANOVAErr;
int nLevelsA, nLevelsB, nPts;
char cFactor;
string strErrMsg;
// Vector to hold names of selected datasets
vector<string> vDataNames;
vDataNames.SetSize( nData );
// Vectors to hold integral indexes to levels of Factors A and B
vector<int> vFACTOR_A;
vector<int> vFACTOR_B;
// Vector to hold the values of the dependent variable
vector<double> vDEP_VAR;
// Vectors to hold the text values of the levels of Factors A and B
vector<string> vLEVELSA;
vector<string> vLEVELSB;
// A four element array of an ANOVA2_Row structure to hold ANOVA2 Table
ANOVA2_Row arANOVA2_Table[4];
// Get all datasets needed from the Origin project file, combine individual datasets into factor A and factor B
// vectors (if needed), and return the number of levels and the number of data points in each factor
iErr = osANOVA2Way_Get_Data( iSpecifyLevelsBy, nData, vDataNames, vFACTOR_A, vLEVELSA, nLevelsA, vFACTOR_B, vLEVELSB,
nLevelsB, vDEP_VAR, nPts );
if( iErr != OSTAT_NO_ERROR ) // If error getting data return without performing ANOVA
return iErr;
// Factor A must have at least 2 levels, if not display error message and return
if( nLevelsA < 2 )
{
Type_ErrorMsg( AN2_TOO_FEW_LEVELSA );
return OSTAT_ABORT_NO_ERROR_MSG;
}
// Factor B must have at least 2 levels, if not display error message and return
if( nLevelsB < 2 )
{
Type_ErrorMsg( AN2_TOO_FEW_LEVELSB );
return OSTAT_ABORT_NO_ERROR_MSG;
}
// Compute all values displayed in Two-Way ANOVA table
iANOVAErr = osANOVA2Way_Compute_ANOVA_Table( iInteractions, vFACTOR_A, nLevelsA, vFACTOR_B, nLevelsB, vDEP_VAR, nPts, &arANOVA2_Table[0] );
// Output Two-Way ANOVA table to Results Log even if there were errors (still may be useful information)
iErr = osANOVA2Way_ANOVA_Table_Output_to_ResultsLog( iSpecifyLevelsBy, nData, vDataNames, iInteractions, &arANOVA2_Table[0] );
// If errors found when computing ANOVA table then exit after outputing ANOVA table and error message
if( iANOVAErr != OSTAT_NO_ERROR )
{
strErrMsg.Format( AN2_COMPUTATIONAL_ERROR_MSG, iANOVAErr );
Type_ErrorMsg( strErrMsg );
return OSTAT_ABORT_NO_ERROR_MSG;
}
// If errors found when outputing ANOVA table then exit
if( iErr != OSTAT_NO_ERROR )
return iErr;
// If Two-Way ANOVA Means Comparison is requested...
if( iTest )
{
// Perform Means Comparison of Factor A Levels, output to Results Log, and return if error
cFactor = 'A';
iErr = osANOVA2Way_Means_Comparison( cFactor, iTest, vFACTOR_A, vLEVELSA, nLevelsA, vDEP_VAR, nPts,
arANOVA2_Table[3].dDF, arANOVA2_Table[3].dMS, dSigLevel );
if( iErr != OSTAT_NO_ERROR )
return iErr;
// Perform Means Comparison of Factor B Levels, output to Results Log, and return if error
cFactor = 'B';
iErr = osANOVA2Way_Means_Comparison( cFactor, iTest, vFACTOR_B, vLEVELSB, nLevelsB, vDEP_VAR, nPts,
arANOVA2_Table[3].dDF, arANOVA2_Table[3].dMS, dSigLevel );
if( iErr != OSTAT_NO_ERROR )
return iErr;
}
// If Actual Power computation is requested...
if( iPower & 1 )
{
// Perform Power computations, output to Results Log, and return if error
iErr = osANOVA2Way_Power( iPower, iInteractions, dPowerAlpha, nPts, strSampleSizes,
&arANOVA2_Table[0] );
if( iErr != OSTAT_NO_ERROR )
return iErr;
}
return OSTAT_NO_ERROR;
}
/**
Two-Way ANOVA function to read in and pre-process all required input datasets.
Example:
See the function osANOVA2Way above for a sample call.
Parameter:
iSpecifyLevelsBy=Radio button setting that determines how levels are specified: either by datasets (1)
or by classification variables (2)
nData=Number of input datasets
vDataNames=Output vector containing names of all input datasets and their levels or variable types
vFACTOR_A=Output vector containing integerized Factor A level indices into vLEVELSA for each data point
vLEVELSA=Output vector containing Factor A level names indexed by vFACTOR_A
nLevelsA=The output number of Factor A levels
vFACTOR_B=Output vector containing integerized Factor B level indices into vLEVELSB for each data point
vLEVELSB=Output vector containing Factor B level names indexed by vFACTOR_B
nLevelsB=The output number of Factor B levels
vDEP_VAR=Vector containing the dependent variable data whose levels are indicated by the paired vectors
vFACTOR_A and vFACTOR_B
iSize=The number of data values in the dependent variable vector
Return:
Returns required datasets and OSTAT_NO_ERROR on successful exit or an OSTAT error code on failure.
*/
int osANOVA2Way_Get_Data( int iSpecifyLevelsBy, int nData, vector<string> &vDataNames, vector<int> &vFACTOR_A,
vector<string> &vLEVELSA, int &nLevelsA, vector<int> &vFACTOR_B, vector<string> &vLEVELSB, int &nLevelsB,
vector<double> &vDEP_VAR, int &iSize )
{
BOOL bErr;
int ii, jj, iErr;
string str, strDB, strErrMsg;
char szTemp[40];
// Matrix to hold the number of data values in each treatment level combination
matrix<int> mValuesPerCell;
// Input dataset
Dataset dsDATA_IN();
if( iSpecifyLevelsBy == 1 ) // If levels are specified by Dataset...
{
int iiA, iiB;
int iNewSize, iIncrSizeBy;
string strDataName, strLevelA, strLevelB;
// Set vector of strings to size 0 and then start adding levels datasets
vLEVELSA.SetSize(0);
vLEVELSB.SetSize(0);
// Get all dataset and level names from list control in Two-Way ANOVA DB
for( ii = 0; ii < nData; ii++ )
{
// Get name of dataset in row ii and column 1 of list control
strDB.Format( "%%A=ANOVA2Way!SelectedDataLCNTRL.V%d_1$", ii + 1 );
LT_execute( strDB );
LT_get_str( "%A", szTemp, 40 );
strDataName = szTemp;
// Get name of Level A in row ii and column 2 of list control
strDB.Format( "%%A=ANOVA2Way!SelectedDataLCNTRL.V%d_2$", ii + 1 );
LT_execute( strDB );
LT_get_str( "%A", szTemp, 40 );
strLevelA = szTemp;
// Get name of Level B in row ii and column 3 of list control
strDB.Format( "%%A=ANOVA2Way!SelectedDataLCNTRL.V%d_3$", ii + 1 );
LT_execute( strDB );
LT_get_str( "%A", szTemp, 40 );
strLevelB = szTemp;
// Save dataset and level names for later output
str.Format( OSTAT_STR_TOKEN, OSTAT_SEPARATOR_CHAR, strLevelA );
vDataNames[ii] = strDataName + str;
str.Format( OSTAT_STR_TOKEN, OSTAT_SEPARATOR_CHAR, strLevelB );
vDataNames[ii] += str;
// Add new level names to vector of strings for sorting
osANOVA2Way_Add_String_to_Vector( strLevelA, vLEVELSA );
osANOVA2Way_Add_String_to_Vector( strLevelB, vLEVELSB );
}
vLEVELSA.Sort(); // Sort level names in Factor A Levels vector (in ascending order)
vLEVELSB.Sort(); // Sort level names in Factor B Levels vector (in ascending order)
// Read in dependent variable dataset and assign indices for level names in sorted vectors
iSize = 0;
for( ii = 0; ii < nData; ii++ )
{
// Get dataset and level names
str = vDataNames[ii]; // Get current element of vDataNames string array
strDataName = str.GetToken( 0, OSTAT_SEPARATOR_CHAR );
strLevelA = str.GetToken( 1, OSTAT_SEPARATOR_CHAR );
strLevelB = str.GetToken( 2, OSTAT_SEPARATOR_CHAR );
// Read in dependent variable dataset values
dsDATA_IN.Attach( strDataName );
vector<double> vDATA_IN( dsDATA_IN, TRUE ); // Copy dataset to vector removing missing and masked values
// Get index of level name from sorted vector of strings holding all level names
iiA = osANOVA2Way_Add_String_to_Vector( strLevelA, vLEVELSA ) + 1; // Add 1 because NAG indexs from 1
iiB = osANOVA2Way_Add_String_to_Vector( strLevelB, vLEVELSB ) + 1;
iIncrSizeBy = vDATA_IN.GetSize(); // Get number of elements to be added
iNewSize = iSize + iIncrSizeBy; // Compute new size of variables
vDEP_VAR.SetSize( iNewSize ); // Set new size of vectors
vFACTOR_A.SetSize( iNewSize );
vFACTOR_B.SetSize( iNewSize );
for( jj = 0; jj < iIncrSizeBy; jj++ ) // Loop for each element in input dataset
{
vDEP_VAR[ iSize + jj ] = vDATA_IN[jj]; // Copy dependent variable value to vector
vFACTOR_A[ iSize + jj ] = iiA; // Assign index to level name in vLEVELSA
vFACTOR_B[ iSize + jj ] = iiB; // Assign index to level name in vLEVELSB
}
iSize = iNewSize; // Update new current size of vectors
dsDATA_IN.Detach(); // No longer need input dataset
}
}
else // Else levels specified by Classification Variables...
{
string strVarName, strVarType, strValue;
string strDepVar, strFactAVar, strFactBVar;
CategoricalData cdDATA_IN; // Categorical Dataset
for( ii = 1; ii <= nData; ii++ )
{
// Get name of dataset in row ii and column 1 of list control
strDB.Format( "%%A=ANOVA2Way!SelectedDataLCNTRL.V%d_1$", ii );
LT_execute( strDB );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -