Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

t_stat.c

Go to the documentation of this file.
00001 #include <volume_io/internal_volume_io.h> 00002 #include <bicpl.h> 00003 00004 #define N_POINTS 10000 00005 #define MAX_DIST 100.0 00006 #define N_STEPS_BETWEEN 10 00007 00008 private Real evaluate_probability_t( 00009 int v, 00010 Real t ) 00011 { 00012 Real gamma_top, gamma_bottom, top, bottom, p; 00013 00014 gamma_top = exp( gamma( ((Real) v + 1.0) / 2.0 ) ); 00015 gamma_bottom = exp( gamma( (Real) v / 2.0 ) ); 00016 00017 top = gamma_top * pow( 1.0 + t * t / (Real) v, - (Real) (v+1)/ 2.0 ); 00018 bottom = sqrt( (Real) v * PI ) * gamma_bottom; 00019 00020 p = top / bottom; 00021 00022 return( p ); 00023 } 00024 00025 private Real initialize_t_integral( 00026 int v, 00027 int n_points, 00028 Real cumulative_probs[], 00029 Real max_dist, 00030 int n_steps_between ) 00031 { 00032 Real error, cum_prob, this_p, prev_p, t, step_size; 00033 int i, step; 00034 00035 cumulative_probs[0] = 0.0; 00036 00037 this_p = evaluate_probability_t( v, 0.0 ); 00038 cum_prob = 0.0; 00039 error = 0.0; 00040 00041 step_size = max_dist / (Real) (n_points-1) / (Real) n_steps_between; 00042 00043 for_less( i, 0, n_points-1 ) 00044 { 00045 for_less( step, 0, n_steps_between ) 00046 { 00047 prev_p = this_p; 00048 00049 t = (Real) (i * n_steps_between + step + 1) / 00050 (Real) ((n_points-1) * n_steps_between) * max_dist; 00051 this_p = evaluate_probability_t( v, t ); 00052 cum_prob += (this_p + prev_p) / 2.0 * step_size; 00053 error += prev_p - this_p; 00054 } 00055 00056 cumulative_probs[i+1] = cum_prob; 00057 } 00058 00059 error *= step_size; 00060 error /= 2.0; 00061 00062 return( error ); 00063 } 00064 00065 private Real convert_t_stat_to_probability( 00066 int n_points, 00067 Real cumulative_probs[], 00068 Real max_dist, 00069 Real t ) 00070 { 00071 int ind; 00072 Real abs_t, alpha1, alpha2, value, interval_width; 00073 00074 abs_t = FABS( t ); 00075 00076 if( abs_t >= max_dist ) 00077 value = 0.5; 00078 else 00079 { 00080 interval_width = max_dist / (Real) (n_points-1); 00081 ind = (int) (abs_t / interval_width); 00082 alpha1 = abs_t / interval_width - (Real) ind; 00083 alpha2 = (Real) (ind+1) - abs_t / interval_width; 00084 value = alpha1 * cumulative_probs[ind] + 00085 alpha2 * cumulative_probs[ind+1]; 00086 } 00087 00088 if( t < 0.0 ) 00089 value = 0.5 - value; 00090 else 00091 value = value + 0.5; 00092 00093 return( value ); 00094 } 00095 00096 public void initialize_cumulative_t_stat( 00097 t_stat_struct *stat, 00098 int degrees_freedom ) 00099 { 00100 stat->degrees_freedom = degrees_freedom; 00101 stat->n_points = N_POINTS; 00102 stat->max_dist = MAX_DIST; 00103 00104 ALLOC( stat->cumulative_probs, stat->n_points ); 00105 00106 (void) initialize_t_integral( stat->degrees_freedom, 00107 stat->n_points, 00108 stat->cumulative_probs, 00109 stat->max_dist, 00110 N_STEPS_BETWEEN ); 00111 } 00112 00113 public void delete_cumulative_t_stat( 00114 t_stat_struct *stat ) 00115 { 00116 FREE( stat->cumulative_probs ); 00117 } 00118 00119 public Real get_cumulative_t_stat( 00120 t_stat_struct *stat, 00121 Real t ) 00122 { 00123 Real prob; 00124 00125 prob = convert_t_stat_to_probability( stat->n_points, 00126 stat->cumulative_probs, 00127 stat->max_dist, t ); 00128 00129 return( prob ); 00130 }

Generated on Wed Jul 28 09:10:58 2004 for BICPL by doxygen 1.3.7