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

📄 ocn_g04.h

📁 图像处理的压缩算法
💻 H
📖 第 1 页 / 共 3 页
字号:

		SE of difference in means =      36.14
		
	Parameter:
		Input:pointers to which memory has been allocated internally in nag anova factorial(g04cac).
        Output:The memory allocated to each of the pointers is freed and the pointers are set to NULL.
	Return:
		None
*/ 
void nag_anova_factorial_free(
	 double **table, 
	 double **tmean, 
	 double **e,
	 int **imean, 
	 double **semean, 
	 double **bmean
);


/**	g04dbc
		Computes confidence intervals for differences between means computed
		by nag_anova_random (g04bbc) or nag_anova_row_col (g04bcc).
	
Example:
	In the example taken from Winer (1970) a completely randomised design with unequal treatment replication 
	is analysed using nag_anova_random (g04bbc) and the confidence intervals are computed by 
	nag_anova_confid_interval using the Tukey-Kramer method.  There are 26 observations and 4 treatments.

void test_nag_anova_confid_interval()
{
	double bmean[1], tol = 5e-6;
	double irdf = 0;
	int nbolck = 1;
	double c[16];
	double cil[6];
	double ciu[6];
	double clevel = 0.95;
	double ef[4];
	double gmean;
	double r[26];
	double rdf;
	matrix table;
	table.SetSize(4,5);
	double tmean[4];
	int i, ij;
	int irep[4];
	int isig[6];
	int success;
	int j, n, nblock, nt;
	Nag_IntervalType type_enum;
	n = 26;
	nt = 4;
	type_enum = Nag_TukeyInterval;	
	double y[26] = {3, 2, 4, 3, 1, 5, 7, 8, 4, 10, 6, 3, 2, 1, 2, 4, 2, 3,
	1, 10, 12, 8, 5, 12, 10, 9};
    int it[26] = {1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3 ,3, 3, 3, 3, 3, 3, 4, 
    4, 4, 4, 4, 4, 4};
    
    success =nag_anova_random(n, y, Nag_NoBlocks, nblock, nt, it, &gmean, bmean, tmean, 
								table,  c, nt, irep, r, ef, tol, irdf);   
    
    printf("the input data and results as folowing\n\n");
    printf("input data:\n");
    printf("n = %d,  nt = %d  clevel = %4.2f type_enum = Nag_TurkeyInterval\n",n, nt, clevel);
    printf("\ny:\n");
    for(i = 0; i < 26; i ++)
  	{
  		printf("%2.0f,",y[i]);
  		if( (i + 1) % 13 == 0)
  		{
  			printf("\n");
  		}
  	}
  	
    printf("\nit:\n");
    for(i = 0; i < 26; i ++)
  	{
  		printf("%d, ",it[i]);
  		if( (i + 1) % 13 == 0)
  		{
  			printf("\n");
  		}
  	}
  	
    if(success ==0)
    {
    	printf("the results:\n");
    	printf("\nANOVA TABLE");
    	printf("\n\n  Source       df    SS         MS       F      Prob\n");
    	printf("Treatments   ");
    	for(j = 0; j < 5; j++)
    	{
    		if( j == 0)
    		printf("%3.0f", table[1][j]);
    		else if(j == 1 || j == 2)
    		printf("%10.1f", table[1][j]);
    		else if(j == 3)
    		printf("%10.3f", table[1][j]);
    		else
    		printf("%9.4f", table[1][j]);   		
    	} 
    	
    	printf("\nResidual    ");
    	for(j = 0; j < 3; j++)
    	{  	if( j == 0)
    		printf(" %3.0f", table[2][j]);
    		if(j == 1 || j == 2)
    		printf("%10.1f", table[2][j]);    		   	
    	}		
		
		printf("\nTotal   ");		
		for(j = 0; j < 2; j++)
    	{  	if( j == 0)
    		printf("     %3.0f", table[3][j]);
    		if(j == 1 || j == 2)
    		printf("%10.1f", table[3][j]);    		   	
    	}

    	printf("\nTreat means  ");		
		for(i = 0; i < nt; i ++)
  		{
  			printf("%6.3f  ",tmean[i]);
  			if( (i + 1) % 8 == 0)
  			{
  				printf("\n");
  			}
  		}
		
		printf("\nSimiltanous Confidence Intervals\n");
		rdf  = table[2][0];
		success = nag_anova_confid_interval(type_enum, nt, tmean, rdf, c, nt, clevel, cil, ciu, isig);
		if(success ==0)
		{
			ij = 0;
			for(i = 1; i <= nt; i++)
			{
				for(j = 1; j <= i-1; j++)
				{
					++ij;
					printf("%2ld%2ld %10.3f  %10.3f", i, j, cil[ij - 1], ciu[ij - 1]);
					if(isig[ij - 1] == 1)
					printf("    *");
					if(isig[ij - 1] == 2)
					printf("\0");
					if(isig[ij - 1] == 0)
					printf("  ");
					printf("\n");
				}								
			}			
		}
		else
		printf("there is some problem with function nag_anova_random");	    
    }
    else
    printf("there is some problem with the function of nag_anova_random"); 
}
		
	The output is following:
the input data and results as folowing

input data:
n = 26,  nt = 4  clevel = 0.95 type_enum = Nag_TurkeyInterval

y:
 3, 2, 4, 3, 1, 5, 7, 8, 4,10, 6, 3, 2,
 1, 2, 4, 2, 3, 1,10,12, 8, 5,12,10, 9,

it:
1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 
3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 
the results:

ANOVA TABLE

  Source       df    SS         MS       F      Prob
Treatments     3     239.9      80.0    24.029   0.0000
Residual      22      73.2       3.3
Total         25     313.1
Treat means   3.000   7.000   2.250   9.429  
Similtanous Confidence Intervals
 2 1      0.933       7.067    *
 3 1     -3.486       1.986  
 3 2     -7.638      -1.862    *
 4 1      3.610       9.247    *
 4 2     -0.538       5.395  
 4 3      4.557       9.800    *


Return:
	The function returns NAG error code, 0 if no error.
	
	NE_INT_ARG_LT(11): On entry, nt must not be less than 2: nt = <value>.
	NE_2_INT_ARG_LT(17): On entry, tdc = <value> while nt = <value>.
	NE_REAL_ARG_LT(5):  On entry, rdf must not be less than 1: rdf = <value>.
	NE_REAL(96): On entry, clevel <value>.  Constrant 0 < clevel < 1.
	NE_BAD_PARAM(70): On entry, parameter type has an illegal value.
	NE_ALLOC_FAIL(73): Memory allocation failed.
	NE_INTERNAL_ERROR(74): An internal error has occurred in this function.  Check the function call and array sizes.  If the function call is correct, please consult NAG for assistance.
	NE_STUDENTIZED_STAT(549): There has been a failure in the computation of the studentized range statistic.  Try using a smaller value of clevel.
			
	successfully call of the nag_anova_confid_interval function.	
*/

	int nag_anova_confid_interval(
		Nag_IntervalType type,
		int nt,				// the number of treatment means
		const double tmean[], // the treatment means
		double rdf,			// the residual degrees of freedom
		const double c[],	// the standard errors of the differences between the means
		int ldc,			// the second dimension of the array c
		double clevel,		// the confidence level for the computed intervals
		double cil[],		// lower limit to the confidence interval
		double ciu[],		// upper limit to the confidence interval
		int isig[]			// difference between the ith and jth means in tmean is significant.
	);	// Computes confidence intervals for differences between means computed 

/**	g04eac
		Computes orthogonal polynomials or dummy variables for factor/classification variable.
		
Example:
	Data are read in from an experiment with four treatments and three observations per 
	treatment with the treatment coded as a factor, nag_dummy_vars is used to compute the 
	required dummy variables and the model is then fitted by nag_regsn_mult_linear (g02dac).

void test_nag_dummy_vars()
{
	double b[5], cov[15], p[35], h[12], q[72], rep[4], res[12]; 
	double df, rss, tol;
	double se[5], v[1], com_ar[45], wt[12], x[48];
	double *wtptr;
	int i, j, ip, irank, levels, m, n, tdq, tdx;
	int isx[4];
	Boolean  svd;
	Nag_DummyType dum_type;
	Nag_IncludeMean  mean_enum;
	int success, success1;
	int ifact[12] = {1, 4, 2, 3, 4, 2, 4, 1, 3, 1, 3, 2};	
	double y[12] = {33.63, 39.62, 38.18, 41.46, 38.02, 35.83, 35.99, 36.58, 42.92,
	37.80, 40.43, 37.89};
	
	n = 12;
	levels = 4;
	dum_type = Nag_AllLevels;
	mean_enum = Nag_MeanInclude;
	tdx = levels;
	wtptr = NULL;
		
	printf("the input data are as following\n");
	printf("n = 12,	levels = 4,	dum_type = Nag_AllLevels,\nmean_enum = Nag_MeanInclude");
	printf(",tdx = levels, wtptr = NULL, tol = 1e-5, ip = 5, m = 4, tdx =4 \n");
	printf("ifact:\n");
	for(i = 0; i < n; i ++)
	{
		printf("%5.2f,  ",ifact[i]);
		if((i + 1) % 6 == 0)
			printf("\n");
	}
	
	printf("y:\n");
	for(i = 0; i < n; i ++)
	{
		printf("%5.2f,  ",y[i]);
		if((i + 1) % 6 == 0)
			printf("\n");
	}
	
	success = nag_dummy_vars(dum_type, n, levels, ifact, x, tdx, v, rep);
	
	if(success == 0)
	{
		m = tdx;
		ip = m;
		if(mean_enum == Nag_MeanInclude)
			ip++;
		for(j = 0; j < m ; j++)
			isx[j] = 1;
		tol = 1e-5;
		tdq = 6;
		success1 = nag_regsn_mult_linear(mean_enum, n, x, tdx, m, isx, ip, y, wtptr, &rss, &df, b,
										se, cov, res, h, q, tdq, &svd, &irank, p, tol, com_ar);
	
		if(success1 ==0)
		{
			if(svd)
				printf("Model not full of rank, rank = %4ld\n\n ", irank);
			printf("Residual sum of squares = %12.4e\n", rss);
			printf("Degrees of freedom = %3.1f\n\n", df);
			printf("Variable Parameter estimate Standard error\n\n");
			for (j=0; j<ip; j++)
				printf("%6ld%20.4e%20.4e\n", j+1, b[j], se[j]);
			printf("\n");			
		}
		else
			printf("what the hell  is the pronblem with nag_regsn_mult_linear");
	}	
	else
		printf("what the hell  is the pronblem with the fuction");

}
	
	The output is following:
	
the input data are as following
n = 12,	levels = 4,	dum_type = Nag_AllLevels,
mean_enum = Nag_MeanInclude,tdx = levels, wtptr = NULL, tol = 1e-5, ip = 5, m = 4, tdx =4 
ifact:
 0.00,   0.00,   0.00,   0.00,   0.00,   0.00,  
 0.00,   0.00,   0.00,   0.00,   0.00,   0.00,  
y:
33.63,  39.62,  38.18,  41.46,  38.02,  35.83,  
35.99,  36.58,  42.92,  37.80,  40.43,  37.89,  
Model not full of rank, rank =    4

 Residual sum of squares =  2.2227e+001
Degrees of freedom = 8.0

Variable Parameter estimate Standard error

     1         3.0557e+001         3.8494e-001
     2         5.4467e+000         8.3896e-001
     3         6.7433e+000         8.3896e-001
     4         1.1047e+001         8.3896e-001
     5         7.3200e+000         8.3896e-001

Return:
	The function returns NAG error code, 0 if no error.
	
	NE_INT_ARG_LT(11): On entry, levels must not be les than 2: levels = <value>.
	NE_2_INT_ARG_LT(17): On entry, n = <value> while levels = <value>.  These parameters must satisfy n >= levels.  On entry, tdx = <value> while levels = <value>.  These parameters must satisfy tdx >= levels.  On entry, tdx = <value> while levels - 1 = <value>.  These parameters must satisfy tdx >= levels - 1.
	NE_BAD_PARAM(70): On entry, parameter type has an illegal value.
	NE_ALLOC_FAIL(73): Memory allocation failed.
	NE_ARRAY_CONS(58): The contents of array v are not valid.  Constraint: all values of v must be distinct.
	NE_INT_ARRAY_CONS(103): On entry, factor{0] = <value>.  Constraint: 1 <= factor[0] <= levels.
	NE_G04EA_LEVELS(547): All levels are not represented in array factor.
	NE_G04EA_ORTHO_POLY(548): An orthogonal polynomial has all values zero.  This will be due to some values of v being close together.  This can only occur if type = Nag_Poly.
	NE_INTERNAL_ERROR(74): An internal error has occurred in this function.  Check the function call and array sizes.  If the function call is correct, please consult NAG for assistance.
		
	successfully call of the nag_dummy_vars function.	
*/

int nag_dummy_vars(
	Nag_DummyType type,
	int n,	// the number of observations for which the dummy variables are to be computed.
	int levels,	// the number of levels of the factor.
	const int ifact[], // the n values of the factor.
	double x[],	// the n by k matrix of dummy variables
	int tdx,	// the second dimension of the array x
	const double v[], // If type equal Nag_Poly, the k distinct values of the underlying variable for which 
					// the orthogonal polynomial is to be computed.  If type not equal Nag_Poly, v is not reference.
	double rep[]	// contains the number of replications for each level
);	// Computes orthogonal polynomials or dummy variables for factor/classification variable.

/* end proto */

#endif //!_O_NAG_G04_H

⌨️ 快捷键说明

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