📄 myconf_utils.c,v
字号:
head 1.1;access;symbols;locks; strict;comment @ * @;1.1date 2002.07.02.19.29.58; author rbraud; state Exp;branches;next ;desc@@1.1log@Initial revision@text@#include <stdio.h>#include <math.h>#include <stdlib.h>/*************** FUNCTION TO CALCULATE CONFIDENCE STATISTICS ***************Function Usage: confidence(x,n,conf-level,mu_x,delta_x) Input parameters: long x[MAXCAMP] vector of data values int n number of data values float conf-level confidence level (90%, 95%, 98% or 99%) Modified parameters: double mu_x average of data values double delta_x confidence interval Function Behavior: This function calculates the confidence interval at 90, 95, 98or 99% confidence for a set of data values. For less than 30 data values,it uses the Student's T distribution. For more than 30 data values,it uses the normal (Gaussian) distribution. *******************************************************************************/float tabella(short nu, float conf_level);int confidence(long * x,int n,float conf_level,float * mu_x,float *delta_x){ short nu=n-1; float sigma_x; float t; // float tabella(); /* function to return Student's T value */ register float num=0.0; register short i; /* Calculate the average: */ for (i=0; i<=nu; i++) num = num + x[i]; *mu_x = num/n; /* Calculate the variance: */ num=0.0; for (i=0; i<=nu; i++) num = num + (*mu_x - x[i]) * (*mu_x - x[i]); sigma_x = sqrt(num/n); /* Get the Student's T value: */ t = tabella(nu,conf_level); /* Calculate confidence interval: */ if (nu <= 30) *delta_x = sigma_x * t / sqrt(nu); else *delta_x = sigma_x * t / sqrt(n); return 0;}float tabella(short nu, float conf_level){ short riga=nu-1; short column; float t; static float val_tabella[31][4] = /* table containing Student's T distribution column 1 (.90), column 2 (.95), column 3 (.98), column 4 (.99) */ { {6.314,12.706,31.821,63.657}, {2.920, 4.303, 6.965, 9.925}, {2.353, 3.182, 4.541, 5.841}, {2.132, 2.776, 3.747, 4.604}, {2.015, 2.571, 3.365, 4.032}, {1.943, 2.447, 3.143, 3.707}, {1.895, 2.365, 2.998, 3.499}, {1.860, 2.306, 2.896, 3.355}, {1.833, 2.262, 2.821, 3.250}, {1.812, 2.228, 2.764, 3.169}, {1.796, 2.201, 2.718, 3.106}, {1.782, 2.179, 2.681, 3.055}, {1.771, 2.160, 2.650, 3.012}, {1.761, 2.145, 2.624, 2.977}, {1.753, 2.131, 2.602, 2.947}, {1.746, 2.120, 2.583, 2.921}, {1.740, 2.110, 2.567, 2.898}, {1.734, 2.101, 2.552, 2.878}, {1.729, 2.093, 2.539, 2.861}, {1.725, 2.086, 2.528, 2.845}, {1.721, 2.080, 2.518, 2.831}, {1.717, 2.074, 2.508, 2.819}, {1.714, 2.069, 2.500, 2.807}, {1.711, 2.064, 2.492, 2.797}, {1.708, 2.060, 2.485, 2.787}, {1.706, 2.056, 2.479, 2.779}, {1.703, 2.052, 2.473, 2.771}, {1.701, 2.048, 2.467, 2.763}, {1.699, 2.045, 2.462, 2.756}, {1.697, 2.042, 2.457, 2.750}, {1.645, 1.960, 2.326, 2.576}, /* nu=infinito (stimatore gaussiano) */ }; if (conf_level >= 0.85 && conf_level <= 0.925) column=0; else if (conf_level >= 0.925 && conf_level <= 0.965) column=1; else if (conf_level >= 0.965 && conf_level <= 0.985) column=2; else if (conf_level >= 0.985 && conf_level <= 0.9945) column=3; else { fprintf(stderr,"The confidence level must be 90%%,95%%,98%% or 99%%).\n"); exit(1); } if (nu <= 30) t=val_tabella[riga][column]; /* stimatore di Student */ else t=val_tabella[30][column]; /* stimatore gaussiano */ return(t);}@
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -