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

📄 survivalanalysis.c

📁 图像处理的压缩算法
💻 C
📖 第 1 页 / 共 4 页
字号:
	// Loop on all covariate datasets counting covariates with jj and current row with iRow
	for( jj = 0; jj < nCovars; iRow++, jj++ )
	{
		// Output name of covariate dataset in column 2
		bErr = dsCovarNAMES.GetText( jj, strCovar );
		if( bErr == FALSE )
			return SA_GET_TEXT_ERROR;
		iCol = 1;
		wksParamTable.SetCell( iRow, iCol, strCovar );
		
		// Output parameter estimate in column 3
		iCol++;
		wksParamTable.SetCell( iRow, iCol, vB[jj] );
		
		// Output standard error in column 4		
		iCol++;
		wksParamTable.SetCell( iRow, iCol, vSE[jj] );
		
		// Output chi-square statistic in column 5		
		iCol++;
		wksParamTable.SetCell( iRow, iCol, vCHISQ[jj] );
		
		// Output p value in column 6
		iCol++;
		wksParamTable.SetCell( iRow, iCol, vPVAL[jj] );
		
		// Output hazard ratio in column 7
		iCol++;
		wksParamTable.SetCell( iRow, iCol, vHAZARD[jj] );
	}
	
	// Output -2 ln L after separater row and in column 3
	iRow++;
	iCol = 2;
	wksParamTable.SetCell( iRow, iCol, ddev );

	// GJL 11/14/02 v7.0434 USE_OC_WKS_TYPE_NOT_LT
	// Send output parameter estimates worksheet to Results Log
	wksParamTable.Type( TYPETARGET_OUTPUTLOG, NULL, 8 );
	
	// *** Output Survivorship Function ***	
	if( nResults & 1 )
	{
		Worksheet wksSurvFuncTable;

		// Create and attach to a temporary worksheet 
		strTablePath = GetFullPath( "saCoxSurvFunc.OGW", SA_OGW_SUBFOLDER, TRUE );
		if( !strTablePath.IsFile() )
		{
			Type_ErrorMsg1( SA_FILE_NOT_FOUND_ERROR_MSG, strTablePath );
			return SA_ABORT_NO_ERROR_MSG;
		}
		wksSurvFuncTable.Open( strTablePath, CREATE_TEMP );
		strTableName = wksSurvFuncTable.GetPage().GetName();
		
		// Rows and columns are indexed from 0
		
		// Insert a blank line in survivorship function table for each data point + 1
		// (+ 1 for time 0) starting at row 5
		iRow = 4;
		Type_Insert_Blank_Lines_in_Wks( wksSurvFuncTable, iRow, nPts + 1 );
		
		// Output time value = 0 in column 2
		iCol = 1;
		wksSurvFuncTable.SetCell( iRow, iCol, 0.0 );
			
		// Output survivorship function value = 1 for time = 0 in column 3
		iCol++;
		wksSurvFuncTable.SetCell( iRow, iCol, 1.0 );

		// Output non-zero time values starting in row 5
		iRow++;
		
		// Loop on all non-zero time values
		jj = -1;
		dPrevUncensoredTime = -1;
		for( ii = 0;ii < nPts; iRow++, ii++ )
		{
			// Output time value in column 2
			iCol = 1;
			wksSurvFuncTable.SetCell( iRow, iCol, vTIME[ii] );
			
			// Output survivorship function value in column 3
			iCol++;
			if( vCENSOR[ii] == 1 ) // If censored...
			{
				// Output missing value for survivorship function value
				wksSurvFuncTable.SetCell( iRow, iCol, NANUM );
			}
			else // Else if not censored...
			{
				// Output survivorship function value 
				// Must index into vSUR differently than vTIME because only non-repeated and uncensored survival
				//  values are in vSUR while all times are in vTIME 
				if( jj < 0 || vTIME[ii] != dPrevUncensoredTime )
					jj++;
				dPrevUncensoredTime = vTIME[ii];
				wksSurvFuncTable.SetCell( iRow, iCol, vSUR[jj] );
			}
		}			

	// GJL 11/14/02 v7.0434 USE_OC_WKS_TYPE_NOT_LT
	// Send output survivorship function worksheet to Results Log
	wksSurvFuncTable.Type( TYPETARGET_OUTPUTLOG, NULL, 4 );

	}

	return SA_NO_ERROR;
}

/**
		Outputs the results of the Cox Proportional Hazards Model to a worksheet.
	Example:
		See the function saCoxPHM above for sample call.
	Parameters:
		strSurvivalWKS=Name of current Survival Analysis worksheet
		nPts=Number of data points in Time, Censor, and Covariate datasets 
		nCovars=Number of Covariate datasets
		vTIME=Vector of Time values
		vCENSOR=Vector of Censor values
		nd=Number of distinct failure times
		vSUR=Vector containing Survivorship function values
		vB=Vector containing Covariate Parameter Estimates
		vSE=Vector containing Standard Errors
		vCHISQ=Vector containing Chi-Square Statistics
		vPVAL=Vector containing P Values
		vHAZARD=Vector containing Hazard Ratios
	Return:
		Outputs the results of the Cox Proportional Hazards Model (including a Covariate Parameters Estimate
		table and a Survivorship Function table) to a worksheet. Returns SA_NO_ERROR on successful exit.
*/
int saCoxPHM_Output_to_Worksheet( string strSurvivalWKS, int nPts, int nCovars, vector<double> &vTIME,
	 vector<int> &vCENSOR, int nd, vector<double> &vSUR, vector<double> &vB, vector<double> &vSE,
	 vector<double> &vCHISQ, vector<double> &vPVAL, vector<double> &vHAZARD )
{
	int ii, jj;
	double dPrevUncensoredTime;
	string strDatasetName;

	// Output Time dataset
	strDatasetName = strSurvivalWKS + SA_TIME_DATASET_NAME;
	Dataset dsTIME( strDatasetName );
	dsTIME.SetSize( nPts + 1 );

	// Output Survivorship Function dataset
	strDatasetName = strSurvivalWKS + SA_SURVIVAL_DATASET_NAME;
	Dataset dsSURVIVAL( strDatasetName );
	dsSURVIVAL.SetSize( nPts + 1 );

	// *** Output Survivorship Function to Worksheet ***
	dPrevUncensoredTime = -1;
	jj = nd;
	// Loop backward on all points in Time dataset
	for( ii = nPts; ii > 0; ii-- )
	{
		if( vCENSOR[ii-1] == 1 )           // If censored time...
		{
			dsTIME[ii] = vTIME[ii - 1];    // Output time value and NANUM for survival function value
			dsSURVIVAL[ii] = NANUM;
		}
		else                               // Else an event (failure) time...
		{
			if( jj == nd || vTIME[ii - 1] != dPrevUncensoredTime ) // If first non-censored time or non-repeated time... 
				jj--;                      // Decrement index into vSUR which only holds survival function values for non-censored and non-repeated times  
			dPrevUncensoredTime = vTIME[ii - 1]; // Remember previous non-censored time 
			dsTIME[ii] = vTIME[ii - 1];    // Output time value
			dsSURVIVAL[ii] = vSUR[jj];     // Output Survivorship Function value
			
		}
	}
	// Output survivorship function value for time==0; not computed but are known 
	dsTIME[ii] = 0.0;
	dsSURVIVAL[ii] = 1.0;

	// Output Covariate Parameter Estimate dataset name	
	strDatasetName = strSurvivalWKS + COX_PARAMEST_DATASET_NAME;
	Dataset dsPARAM( strDatasetName );
	dsPARAM.SetSize( nCovars );

	// Output Covariate Parameter Estimate Standard Error dataset name	
	strDatasetName = strSurvivalWKS + SA_STDERROR_DATASET_NAME;		
	Dataset dsERROR( strDatasetName );
	dsERROR.SetSize( nCovars );

	// Output Covariate Parameter Estimate Chi-Square dataset name	
	strDatasetName = strSurvivalWKS + COX_CHISQ_DATASET_NAME;		
	Dataset dsCHISQ( strDatasetName );
	dsCHISQ.SetSize( nCovars );

	// Output Covariate Parameter Estimate P Value dataset name	
	strDatasetName = strSurvivalWKS + COX_PVALUE_DATASET_NAME;		
	Dataset dsPVAL( strDatasetName );
	dsPVAL.SetSize( nCovars );

	// Output Covariate Parameter Estimate Hazard Ratio dataset name	
	strDatasetName = strSurvivalWKS + COX_HAZARD_DATASET_NAME;		
	Dataset dsHAZARD( strDatasetName );
	dsHAZARD.SetSize( nCovars );
		
	// Copy estimates of parameters et al for Cox model to output datasets in Survival worksheet  
	for( ii = 0; ii < nCovars; ii++ )
	{
		dsPARAM[ii] = vB[ii];
		dsERROR[ii] = vSE[ii];
		dsCHISQ[ii] = vCHISQ[ii];
		dsPVAL[ii] = vPVAL[ii];
		dsHAZARD[ii] = vHAZARD[ii];
	}
	
	return SA_NO_ERROR;
}

/**
		Outputs to the Results Log the survival analysis main headers and a summary of events
		and censored values for both the Kaplan-Meier Estimator and the Cox Proportional Hazards
		Model. 
	Example:
		See functions saKaplanMeier_Output_to_ResultsLog and saCoxPHM_Output_to_ResultsLog above
		for sample call.
	Parameters:
		strDB=Dialog Box or feature name
		strTimeData=Name of Time dataset
		strCensorData=Name of Censor dataset
		strCensorValue=Censor value
		nPts=Number of data points in Time and Censor datasets
		dCensoredPts=Number of data points that are censored 
	Return:
		Outputs the survival analysis main headers and a summary table and returns SA_NO_ERROR
		on successful exit.
*/
static int saSurvival_Analysis_ResultsLog_Summary( string strDB, string strTimeData, string strCensorData, string strCensorValue,
	 int nPts, double dCensoredPts )
{
	int iRow, iCol;
	int iEvents;
	int iCensored;
	double dnPts;
	double dPercentCensored;
	string strTablePath;
	string strOut;
	string strTableName;
	Worksheet wksSumTable;

	// Compute summary values for output
	iCensored = (int) dCensoredPts;
	iEvents = nPts - iCensored;
	dnPts = (double) nPts;
	dPercentCensored = 10000.0 * dCensoredPts / dnPts + 0.5; // Round to 100ths place
	dPercentCensored = (int) dPercentCensored;
	dPercentCensored = dPercentCensored / 100;

	// Create and attach to a temporary worksheet 
	strTablePath = GetFullPath( "saSAEventSum.OGW", SA_OGW_SUBFOLDER, TRUE );
	if( !strTablePath.IsFile() )
	{
		Type_ErrorMsg1( SA_FILE_NOT_FOUND_ERROR_MSG, strTablePath );
		return SA_ABORT_NO_ERROR_MSG;
	}
	wksSumTable.Open( strTablePath, CREATE_TEMP );
	strTableName = wksSumTable.GetPage().GetName();
	
	// Rows and columns are indexed from 0

	// *** Output Survival Analysis Main Headers (starting in row 1 and column 1) ***
	// Output the dialog box name (feature name)
	iRow = 0;
	iCol = 0;
	wksSumTable.SetCell( iRow, iCol, strDB );
	
	// Output the name of the Time dataset
	iRow = 2;
	iCol = 3;
	wksSumTable.SetCell( iRow, iCol, strTimeData );
	
	// Output the name of the Censor dataset
	iRow++;
	wksSumTable.SetCell( iRow, iCol, strCensorData );
	
	// Output the Censor Value
	iRow++;
	wksSumTable.SetCell( iRow, iCol, strCensorValue );

	// *** Output Summary Data (in row 12 and starting in column 2) ***
	// Output the number of data points in the Time and Censor datasets
	iRow = 11;
	iCol = 1;
	wksSumTable.SetCell( iRow, iCol, nPts );
	
	// Output the number of events in column 3
	iCol++;
	wksSumTable.SetCell( iRow, iCol, iEvents );
	
	// Output the number of censored data points in column 4
	iCol++;
	wksSumTable.SetCell( iRow, iCol, iCensored );
	
	// Output the percent of censored events in column 5
	iCol++;
	strOut = LocalizeDouble( dPercentCensored, SA_PERCENT_FORMAT );
	wksSumTable.SetCell( iRow, iCol, strOut );
	
	// GJL 11/14/02 v7.0434 USE_OC_WKS_TYPE_NOT_LT
	// Send output worksheet to Results Log
	wksSumTable.Type( TYPETARGET_OUTPUTLOG, NULL, 6 );

	return SA_NO_ERROR;
}

⌨️ 快捷键说明

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