Patterns in static

Apophenia

stats.h

Go to the documentation of this file.
00001 
00002 /* Copyright (c) 2005--2009 by Ben Klemens.  Licensed under the modified GNU GPL v2; see COPYING and COPYING2. */
00003 #ifndef APOP_STATS_H
00004 #define APOP_STATS_H
00005 #include <math.h>
00006 #include <gsl/gsl_rng.h>
00007 #include <gsl/gsl_cdf.h>
00008 #include <gsl/gsl_matrix.h>
00009 #include <gsl/gsl_randist.h>
00010 #include <gsl/gsl_multimin.h>
00011 #include <gsl/gsl_histogram.h>
00012 #include <gsl/gsl_statistics_double.h>
00013 #include "linear_algebra.h"
00014 
00015 #ifdef    __cplusplus
00016 extern "C" {
00017 #endif
00018 
00019 #define APOP_SUBMATRIX(m, srow, scol, nrows, ncols, o) gsl_matrix apop_mm_##o = gsl_matrix_submatrix(m, (srow), (scol), (nrows),(ncols)).matrix;\
00020 gsl_matrix * o = &( apop_mm_##o );
00021 
00022 #define APOP_MATRIX_ROW(m, row, v) gsl_vector apop_vv_##v = gsl_matrix_row(m, (row)).vector;\
00023 gsl_vector * v = &( apop_vv_##v );
00024 
00025 #define APOP_MATRIX_COL(m, col, v) gsl_vector apop_vv_##v = gsl_matrix_column(m, (col)).vector;\
00026 gsl_vector * v = &( apop_vv_##v );
00027 
00028 #define APOP_ROW_T(m, row, v) gsl_vector apop_vv_##v = gsl_matrix_row((m)->matrix, apop_name_find((m)->names, row, 'r')).vector;\
00029 gsl_vector * v = &( apop_vv_##v );
00030 
00031 #define APOP_COL_T(m, col, v) gsl_vector apop_vv_##v = gsl_matrix_column((m)->matrix, apop_name_find((m)->names, col, 'c')).vector;\
00032 gsl_vector * v = &( apop_vv_##v );
00033 
00034 #define APOP_ROW(m, row, v) gsl_vector apop_vv_##v = gsl_matrix_row((m)->matrix, (row)).vector;\
00035 gsl_vector * v = &( apop_vv_##v );
00036 
00037 #define APOP_COL(m, col, v) gsl_vector apop_vv_##v = gsl_matrix_column((m)->matrix, (col)).vector;\
00038 gsl_vector * v = &( apop_vv_##v );
00039 
00040 #define Apop_col APOP_COL 
00041 #define Apop_row APOP_ROW
00042 #define Apop_col_t APOP_COL_T
00043 #define Apop_row_t APOP_ROW_T
00044 #define Apop_matrix_col APOP_MATRIX_COL 
00045 #define Apop_matrix_row APOP_MATRIX_ROW
00046 #define Apop_submatrix APOP_SUBMATRIX
00047 #define apop_vector_kurt(in) apop_vector_kurtosis(in)
00048 
00049 long double apop_vector_sum(const gsl_vector *in);
00050 double apop_var(const gsl_vector *in);
00051 double apop_vector_var_m(const gsl_vector *in, const double mean);
00052 double apop_vector_cov(const gsl_vector *ina, const gsl_vector *inb);
00053 double apop_vector_correlation(const gsl_vector *ina, const gsl_vector *inb);
00054 double apop_vector_kurtosis_pop(const gsl_vector *in);
00055 double apop_vector_kurtosis(const gsl_vector *in);
00056 double apop_vector_skew(const gsl_vector *in);
00057 double apop_vector_skew_pop(const gsl_vector *in);
00058 double apop_vector_weighted_mean(const gsl_vector *, const gsl_vector *);
00059 double apop_vector_weighted_var(const gsl_vector *v, const gsl_vector *w);
00060 double apop_vector_weighted_cov(const gsl_vector *, const gsl_vector *, const gsl_vector *);
00061 double apop_vector_weighted_skew(const gsl_vector *v, const gsl_vector *w);
00062 double apop_vector_weighted_kurt(const gsl_vector *v, const gsl_vector *w);
00063 
00064 #define apop_sum(in) apop_vector_sum(in)
00065 #define apop_var(in) apop_vector_var(in) 
00066 #define apop_vector_covar(in) apop_vector_cov(in) 
00067 #define apop_mean(in) apop_vector_mean(in)
00068 #define apop_vector_mean(in)  gsl_stats_mean((in)->data,(in)->stride, (in)->size)
00069 #define apop_vector_var(in)  gsl_stats_variance((in)->data,(in)->stride, (in)->size)
00070 
00071 #ifdef APOP_NO_VARIADIC
00072  double apop_vector_distance(const gsl_vector *ina, const gsl_vector *inb, const char metric, const double norm);
00073 #else
00074  double apop_vector_distance_base(const gsl_vector *ina, const gsl_vector *inb, const char metric, const double norm);
00075  apop_varad_declare(double, apop_vector_distance, const gsl_vector *ina; const gsl_vector *inb; const char metric; const double norm);
00076 #define apop_vector_distance(...) apop_varad_link(apop_vector_distance, __VA_ARGS__)
00077 #endif
00078 double apop_vector_grid_distance(const gsl_vector *ina, const gsl_vector *inb);
00079 
00080 
00081 #ifdef APOP_NO_VARIADIC
00082  void apop_vector_normalize(gsl_vector *in, gsl_vector **out, const char normalization_type);
00083 #else
00084  void apop_vector_normalize_base(gsl_vector *in, gsl_vector **out, const char normalization_type);
00085  apop_varad_declare(void, apop_vector_normalize, gsl_vector *in; gsl_vector **out; const char normalization_type);
00086 #define apop_vector_normalize(...) apop_varad_link(apop_vector_normalize, __VA_ARGS__)
00087 #endif
00088 void apop_matrix_normalize(gsl_matrix *data, const char row_or_col, const char normalization);
00089 
00090 #ifdef APOP_NO_VARIADIC
00091  double apop_random_double(double min, double max, gsl_rng *r);
00092 #else
00093  double apop_random_double_base(double min, double max, gsl_rng *r);
00094  apop_varad_declare(double, apop_random_double, double min; double max; gsl_rng *r);
00095 #define apop_random_double(...) apop_varad_link(apop_random_double, __VA_ARGS__)
00096 #endif
00097 #ifdef APOP_NO_VARIADIC
00098  int apop_random_int(double min, double max, const gsl_rng *r);
00099 #else
00100  int apop_random_int_base(double min, double max, const gsl_rng *r);
00101  apop_varad_declare(int, apop_random_int, double min; double max; const gsl_rng *r);
00102 #define apop_random_int(...) apop_varad_link(apop_random_int, __VA_ARGS__)
00103 #endif
00104 
00105 #ifdef APOP_NO_VARIADIC
00106  gsl_matrix * apop_matrix_covariance(gsl_matrix *in, const char normalize);
00107 #else
00108  gsl_matrix * apop_matrix_covariance_base(gsl_matrix *in, const char normalize);
00109  apop_varad_declare(gsl_matrix *, apop_matrix_covariance, gsl_matrix *in; const char normalize);
00110 #define apop_matrix_covariance(...) apop_varad_link(apop_matrix_covariance, __VA_ARGS__)
00111 #endif
00112 #ifdef APOP_NO_VARIADIC
00113   gsl_matrix * apop_matrix_correlation(gsl_matrix *in, const char normalize);
00114 #else
00115   gsl_matrix * apop_matrix_correlation_base(gsl_matrix *in, const char normalize);
00116  apop_varad_declare( gsl_matrix *, apop_matrix_correlation, gsl_matrix *in; const char normalize);
00117 #define apop_matrix_correlation(...) apop_varad_link(apop_matrix_correlation, __VA_ARGS__)
00118 #endif
00119 apop_data * apop_data_covariance(const apop_data *in);
00120 apop_data * apop_data_correlation(const apop_data *in);
00121 long double apop_matrix_sum(const gsl_matrix *m);
00122 double apop_matrix_mean(const gsl_matrix *data);
00123 double apop_matrix_var_m(const gsl_matrix *data, double mean);
00124 void apop_matrix_mean_and_var(const gsl_matrix *data, double *mean, double *var);
00125 apop_data * apop_data_summarize(apop_data *data);
00126 
00127 //from apop_fisher.c:
00128 apop_data *apop_test_fisher_exact(apop_data *intab);
00129 
00130 //from apop_t_f_chi.c:
00131 #ifdef APOP_NO_VARIADIC
00132  int apop_matrix_is_positive_semidefinite(gsl_matrix *m, char semi);
00133 #else
00134  int apop_matrix_is_positive_semidefinite_base(gsl_matrix *m, char semi);
00135  apop_varad_declare(int, apop_matrix_is_positive_semidefinite, gsl_matrix *m; char semi);
00136 #define apop_matrix_is_positive_semidefinite(...) apop_varad_link(apop_matrix_is_positive_semidefinite, __VA_ARGS__)
00137 #endif
00138 double apop_matrix_to_positive_semidefinite(gsl_matrix *m);
00139 double apop_multivariate_gamma(double a, double p);
00140 double apop_multivariate_lngamma(double a, double p);
00141 
00142 //from the regression code:
00143 #define apop_F_test apop_f_test
00144 #define apop_estimate_r_squared(in) apop_estimate_coefficient_of_determination(in)
00145 
00146 apop_data *    apop_t_test(gsl_vector *a, gsl_vector *b);
00147 apop_data *    apop_paired_t_test(gsl_vector *a, gsl_vector *b);
00148 
00149 
00150 apop_data * apop_text_unique_elements(const apop_data *d, size_t col);
00151 gsl_vector * apop_vector_unique_elements(const gsl_vector *v);
00152 apop_data *apop_text_to_factors(apop_data *d, size_t textcol, int datacol);
00153 
00154 #ifdef APOP_NO_VARIADIC
00155  apop_data * apop_data_to_dummies(apop_data *d, int col, char type, int keep_first);
00156 #else
00157  apop_data * apop_data_to_dummies_base(apop_data *d, int col, char type, int keep_first);
00158  apop_varad_declare(apop_data *, apop_data_to_dummies, apop_data *d; int col; char type; int keep_first);
00159 #define apop_data_to_dummies(...) apop_varad_link(apop_data_to_dummies, __VA_ARGS__)
00160 #endif
00161 #ifdef APOP_NO_VARIADIC
00162  apop_data * apop_f_test (apop_model *est, apop_data *contrast, int normalize);
00163 #else
00164  apop_data * apop_f_test_base(apop_model *est, apop_data *contrast, int normalize);
00165  apop_varad_declare(apop_data *, apop_f_test, apop_model *est; apop_data *contrast; int normalize);
00166 #define apop_f_test(...) apop_varad_link(apop_f_test , __VA_ARGS__)
00167 #endif
00168 
00169 apop_model *apop_estimate_fixed_effects_OLS(apop_data *data, gsl_vector *categories);
00170 
00171 apop_data *apop_estimate_coefficient_of_determination (apop_model *in);
00172 apop_data *apop_estimate_r_squared (apop_model *in);
00173 void apop_estimate_parameter_t_tests (apop_model *est);
00174 
00175 //apop_testing.c
00176 apop_data* apop_anova(char *table, char *data, char *grouping1, char *grouping2);
00177 
00178 #define apop_ANOVA(table, data, grouping1, grouping2) apop_anova(table, data, grouping1, grouping2)
00179 
00180 #ifdef    __cplusplus
00181 }
00182 #endif
00183 #endif
00184 

SourceForge.net Logo

Autogenerated by doxygen on 28 Sep 2009.