⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ostat.c

📁 图像处理的压缩算法
💻 C
📖 第 1 页 / 共 5 页
字号:
/*------------------------------------------------------------------------------*
 * File Name: OStat.c: Contains OriginC source code for all OStat features		*
 *	except for Survival Analysis which was moved to SurvivalAnalysis.c.			*
 * Creation: GJL 5/29/2001														*
 * Purpose: Origin C file														*
 * Copyright ( c ) OriginLab Corp.	2000-2002									*
 * All Rights Reserved															*
 * 																				*
 * Modification Log:															*
 *	CPY 7/20/02 v7.0347 OSTAT_COMPILE_PROBLEM_WITH_TYPE_ERROR_MSG				*
 *		I have added Type_ErrorMsg1 function to replace all those that needs	*
 *		second string arguments													*
 *	GJL 11/14/02 v7.0434 USE_OC_WKS_TYPE_NOT_LT									*
 *------------------------------------------------------------------------------*/

////////////////////////////////////////////////////////////////////////////////////
//
// System includes
#include <Origin.h>
//#include <OC_const.h>
//#include <string.h>
//#include <data.h>
//#include <math.h>
//#include <utilities.h>
//#include <stdio.h>
//#include <page.h>

// Includes definitions of OStat constants, structures, and non-localized strings.
//  Also includes NAG definitions and prototypes of NAG functions used by OStat.
#include "OStat.h"

// Includes prototypes of Application Utilities.
#include "App_Utils.h"

// Includes definitions of all OStat.c localized strings. $ causes CodeBuilder to look for 
// correct version of Local.h depending on Windows Regional settings
#include "$Local.h"
//
////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////
/**
		Computes the lower tail probability of the Student's t-distribution with
		real degrees of freedom. The computational engine is the NAG function
		nag_prob_students_t (g01ebc).
	Example:
		See the [ComputeActualPower] section of tTestMean1Sample.OGS for a sample call.
		Also,
			double dProb;
			dProb = osTTest_ProbT( 2.160, 13 );
			ASSERT( fabs( 0.975 - dProb ) < 0.0005 );
	Parameters:
		dt=Value of t where t can be any Real number
		ddf=Degrees of freedom where ddf > 0
	Return:
		Returns the lower tail probability of the Student's t-distribution for
		parameters dt (value of t) and ddf (degrees of freedom).
*/
double osTTest_ProbT( double dt, int ddf )
{
	double dProbT;
	NagError neErr;					// NAG error structure
	NagError *pneFail = &neErr;
	
	// From <NAG\OCN_g01.h>: g01ebc nag_prob_students_t
	dProbT = nag_prob_students_t( Nag_LowerTail, dt, ddf, pneFail );
	if( pneFail->code != NE_NOERROR )
		return NANUM;				// Return missing value on NAG error
		
	return dProbT;
}

/**
		Function to output to the Results Log a t-Test Table for the One and Two Sample
		t-Test dialog boxes.		.
	Example:
		See the [DisplayTandP] section in TTestMean1Sample.OGS and TTestMean2Sample.OGS for
		sample calls. 
	Parameters:
		iTwoSampleTest=Flag for test type:0 for One Sample t-Test, 1 for Two Sample Independent t-Test, or
			2 for Two Sample Paired t-Test
		dPairedVar=Variance of Paired t-Test
		strNullHypot=Null Hypothesis
		strAltHypot=Alternative Hypothesis
		dt=T value
		iDoF=Degrees of Freedom
		dP=P Value
		iAltRBChoice=Alternative Hypothesis radio button setting
		dSigLevel=Significance Level
		dTestVal=Test Mean for One Sample and Test Difference for Two Sample t-Test
	Return:
		Outputs a t-Test Table for the One and Two Sample t-Test dialog boxes to the Results
		Log and returns OSTAT_NO_ERROR on successful exit or an OSTAT error code on failure.
*/
int	osTTest_Table_Output_to_ResultsLog( int iTwoSampleTest, double dPairedVar, string strNullHypot,
	 string strAltHypot, double dt, int iDoF, double dP, int iAltRBChoice, double dSigLevel, double dTestVal )
{
	// *** If Variance of Paired Two Sample t-Test is 0 abort to prevent division by 0 ***
	if( iTwoSampleTest == 2 && dPairedVar == 0 )
	{
		// Output error message DB and return OSTAT error code
		Type_ErrorMsg( TT2_PAIRED_SD_IS_0_MSG );
		return OSTAT_PAIRED_SD_IS_0_ERROR;
	}
	
	int ii, iSize;
	int iRow, iCol;
	string strOut;
	string strSigLevel, strTestVal;
	string strTablePath;
	string strTableName;
	Worksheet wksTTestTable;
		
	// Create and attach to a temporary t-Test Table output worksheet
	strTablePath = GetFullPath( "osTTestTTable.OGW", OSTAT_OGW_SUBFOLDER, TRUE );
	if( !strTablePath.IsFile() )
	{
		Type_ErrorMsg1( OSTAT_FILE_NOT_FOUND_ERROR_MSG, strTablePath );
		return OSTAT_ABORT_NO_ERROR_MSG;
	}
	wksTTestTable.Open( strTablePath, CREATE_TEMP );
	strTableName = wksTTestTable.GetPage().GetName();
	
	// All row and column numbers are indexed from 0
	
	// *** Output Null and Alternative Hypotheses ***
	// Output Null Hypothesis in row 1 and column 4
	iRow = 0;
	iCol = 3;
	wksTTestTable.SetCell( iRow, iCol, strNullHypot );
	
	// Output Alternative Hypothesis in row 2 and column 4
	iRow++;
	wksTTestTable.SetCell( iRow, iCol, strAltHypot );
	
	// *** Output t-Test Table Values t, Dof, and P ***
	// Output t value in row 6 and column 2
	iRow = 5;
	iCol = 1;	
	wksTTestTable.SetCell( iRow, iCol, dt );
	
	// Output DoF in column 3
	iCol++;
	wksTTestTable.SetCell( iRow, iCol, iDoF );
	
	// Output P value in column 4
	iCol++;
	wksTTestTable.SetCell( iRow, iCol, dP );

	// *** Output Decision Rule in Two Phrases ***
	// Localize significance level and the test value
	strSigLevel = LocalizeDouble( dSigLevel, OSTAT_SIG_CON_LEVEL_FORMAT );
	strTestVal = LocalizeDouble( dTestVal, OSTAT_MAX_DIGITS_FORMAT );

	// Output the first phrase of the decision rule in row 9 and column 2
	iRow = 8;
	iCol = 1;
	if( iTwoSampleTest ) // If Two Sample t-Test...
	{
		// Output the first phrase of the Two Sample t-Test decision rule
		strOut.Format( TT2_DECISION_PHRASE1, strSigLevel );
		wksTTestTable.SetCell( iRow, iCol, strOut );
	
		// Output the second phrase of the Two Sample t-Test decision rule in row 10 and column 2
		iRow++;
		switch( iAltRBChoice ) // What Alternative Hypothesis is selected?
		{
			case 1:
				if ( dP > dSigLevel )
					strOut.Format( TT2_DECISION_PHRASE2_IS_NOT_DIFFERENT, strTestVal ); // Is not significantly different
				else 
					strOut.Format( TT2_DECISION_PHRASE2_IS_DIFFERENT, strTestVal );     // Is significantly different
				break;
			case 2:
				if ( dP > dSigLevel )
					strOut.Format( TT2_DECISION_PHRASE2_IS_NOT_GREATER, strTestVal );   // Is not greater
				else 
					strOut.Format( TT2_DECISION_PHRASE2_IS_GREATER, strTestVal );       // Is greater
				break;
			case 3:
				if ( dP > dSigLevel )
					strOut.Format( TT2_DECISION_PHRASE2_IS_NOT_LESS, strTestVal );      // Is not less
				else 
					strOut.Format( TT2_DECISION_PHRASE2_IS_LESS, strTestVal );          // Is less
				break;
		}
		wksTTestTable.SetCell( iRow, iCol, strOut );
	}
	else // Else One Sample t-Test...
	{
		// Output the first phrase of the One Sample t-Test decision rule
		strOut.Format( TT1_DECISION_PHRASE1, strSigLevel );
		wksTTestTable.SetCell( iRow, iCol, strOut );
	
		// Output the second phrase of the One Sample t-Test decision rule in row 10 and column 2
		iRow++;
		switch( iAltRBChoice ) // What Alternative Hypothesis is selected?
		{
			case 1:
				if ( dP > dSigLevel )
					strOut.Format( TT1_DECISION_PHRASE2_IS_NOT_DIFFERENT, strTestVal ); // Is not significantly different
				else 
					strOut.Format( TT1_DECISION_PHRASE2_IS_DIFFERENT, strTestVal );     // Is significantly different
				break;
			case 2:
				if ( dP > dSigLevel )
					strOut.Format( TT1_DECISION_PHRASE2_IS_NOT_GREATER, strTestVal );   // Is not greater
				else 
					strOut.Format( TT1_DECISION_PHRASE2_IS_GREATER, strTestVal );       // Is greater
				break;
			case 3:
				if ( dP > dSigLevel )
					strOut.Format( TT1_DECISION_PHRASE2_IS_NOT_LESS, strTestVal );      // Is not less
				else 
					strOut.Format( TT1_DECISION_PHRASE2_IS_LESS, strTestVal );          // Is less
				break;
		}
		wksTTestTable.SetCell( iRow, iCol, strOut );
	}

	// GJL 11/14/02 v7.0434 USE_OC_WKS_TYPE_NOT_LT
	// Send output t-Test Table worksheet to Results Log
	wksTTestTable.Type( TYPETARGET_OUTPUTLOG, NULL, 5 );

	return OSTAT_NO_ERROR;	
}

/**
		Function to output to the Results Log Confidence Intervals for the One and Two Sample t-Test
		dialog boxes.
	Example:
		See the [DisplayConfidenceIntervals] section in TTestMean1Sample.OGS and TTestMean2Sample.OGS
		for sample calls. 
	Parameters:
		iTwoSampleTest=Flag for test type:0 for One Sample t-Test or 1 for Two Sample t-Test
		strConLevelDataName=Name of dataset containing confidence levels
		strLLimitDataName=Name of dataset containing lower confidence limits
		strULimitDataName=Name of dataset containing upper confidence limits
	Return:
		Outputs Confidence Intervals for the One and Two Sample t-Test dialog boxes to the Results
		Log and returns OSTAT_NO_ERROR on successful exit.
*/
int	osTTest_ConIntervals_Output_to_ResultsLog( int iTwoSampleTest, string strConLevelDataName,
		 string strLLimitDataName, string strULimitDataName )
{
	int ii, iSize;
	string strOut;

	int iRow, iCol;
	string strTablePath;
	string strTableName;
	Worksheet wksConIntTable;

	// Create and attach to a temporary Confidence Interval output worksheet
	strTablePath = GetFullPath( "osConfidenceInterval.OGW", OSTAT_OGW_SUBFOLDER, TRUE );
	if( !strTablePath.IsFile() )
	{
		Type_ErrorMsg1( OSTAT_FILE_NOT_FOUND_ERROR_MSG, strTablePath );
		return OSTAT_ABORT_NO_ERROR_MSG;
	}
	wksConIntTable.Open( strTablePath, CREATE_TEMP );
	strTableName = wksConIntTable.GetPage().GetName();
	
	// All row and column numbers are indexed from 0
	
	// *** Change Confidence Interval Main Header if Two Sample Test ***
	if( iTwoSampleTest )
	{
		iRow = 0; // Confidence interval main header in row 1 and column 2
		iCol = 1;
		strOut = TT2_CON_INTERVAL_MAIN_HDR;
		wksConIntTable.SetCell( iRow, iCol, strOut );
	}

	// *** Output Confidence Interval Rows ***	
	// Get confidence levels dataset
	Dataset dsConLevel( strConLevelDataName );
	iSize = dsConLevel.GetSize();
	vector<double> vConLevel;
	vConLevel.SetSize( iSize );
	vConLevel = dsConLevel;
	dsConLevel.Detach();

	// Get lower confidence limits dataset
	Dataset dsLLim( strLLimitDataName );
	iSize = dsLLim.GetSize();
	vector<double> vLLim;
	vLLim.SetSize( iSize );
	vLLim = dsLLim;
	dsLLim.Detach();
	
	// Get upper confidence limits dataset
	Dataset dsULim( strULimitDataName );
	iSize = dsULim.GetSize();
	vector<double> vULim;
	vULim.SetSize( iSize );
	vULim = dsULim;
	dsULim.Detach();
	
	// Insert one blank line in Confidence Interval table for each confidence level
	iRow = 5; // Insert blank lines starting in row 6
	Type_Insert_Blank_Lines_in_Wks( wksConIntTable, iRow, iSize );
		
	// Loop on confidence levels starting in row 6
	for( ii = 0; ii < iSize; iRow++, ii++ )
	{
		// Output confidence level in column 2
		iCol = 1;
		wksConIntTable.SetCell( iRow, iCol, vConLevel[ii] );
			// Output lower limit in column 3
		iCol++;
		wksConIntTable.SetCell( iRow, iCol, vLLim[ii] );
	
		// Output upper limit in column 4
		iCol++;
		wksConIntTable.SetCell( iRow, iCol, vULim[ii] );
	}

	// GJL 11/14/02 v7.0434 USE_OC_WKS_TYPE_NOT_LT
	// Send output Confidence Interval worksheet to Results Log
	wksConIntTable.Type( TYPETARGET_OUTPUTLOG, NULL, 5 );

	return OSTAT_NO_ERROR;	
}

/**
		Function to output to the Results Log Summary Statistics for the One and Two Sample
		t-Test and the One-Way ANOVA dialog boxes.
	Example:
		See the [DisplayTandP] section in TTestMean1Sample.OGS and TTestMean2Sample.OGS, or the 
		the [DisplayFandP] section in ANOVA1Way.OGS for sample calls. 
	Parameters:
		iTest=Flag for test type:0 for One Sample t-Test, 1 for Two Sample Independent t-Test,
			2 for Two Sample Paired t-Test, or 3 for One-Way ANOVA
		nData=Number of datasets to summarize
	Return:
		Outputs Summary Statistics for the One and Two Sample t-Test and the One-Way ANOVA
		dialog boxes to the Results Log and returns OSTAT_NO_ERROR on successful exit.
*/
int	osSummary_Stat_Output_to_ResultsLog( int iTest, int nData )
{
	int ii, iSize;
	double dGetVar;
	char szTemp[40];
	string strDatasetName;
	string strMainHDR;

	// Vector containing names of all selected datasets

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -