File indexing completed on 2024-05-12 15:27:10

0001 /***************************************************************************
0002     File                 : nsl_stats.h
0003     Project              : LabPlot
0004     Description          : NSL statistics functions
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2016-2017 by Stefan Gerlach (stefan.gerlach@uni.kn)
0007 
0008  ***************************************************************************/
0009 
0010 /***************************************************************************
0011  *                                                                         *
0012  *  This program is free software; you can redistribute it and/or modify   *
0013  *  it under the terms of the GNU General Public License as published by   *
0014  *  the Free Software Foundation; either version 2 of the License, or      *
0015  *  (at your option) any later version.                                    *
0016  *                                                                         *
0017  *  This program is distributed in the hope that it will be useful,        *
0018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0020  *  GNU General Public License for more details.                           *
0021  *                                                                         *
0022  *   You should have received a copy of the GNU General Public License     *
0023  *   along with this program; if not, write to the Free Software           *
0024  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0025  *   Boston, MA  02110-1301  USA                                           *
0026  *                                                                         *
0027  ***************************************************************************/
0028 
0029 #ifndef NSL_STATS_H
0030 #define NSL_STATS_H
0031 
0032 #include <stdlib.h>
0033 
0034 /* estimation types of quantile (see https://en.wikipedia.org/wiki/Quantile,
0035  * https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.mstats.mquantiles.html) */
0036 #define NSL_STATS_QUANTILE_TYPE_COUNT 9
0037 typedef enum {nsl_stats_quantile_type1=1, nsl_stats_quantile_type2, nsl_stats_quantile_type3, nsl_stats_quantile_type4, 
0038         nsl_stats_quantile_type5, nsl_stats_quantile_type6, nsl_stats_quantile_type7, nsl_stats_quantile_type8,
0039         nsl_stats_quantile_type9} nsl_stats_quantile_type;
0040 
0041 /* minimum value of data array 
0042     data - data array
0043     n - size of data array
0044     index - index of minimum value  (not used if NULL)
0045 */
0046 double nsl_stats_minimum(const double data[], const size_t n, size_t *index);
0047 /* maximum value of data array 
0048     data - data array
0049     n - size of data array
0050     index - index of maximum value (not used if NULL)
0051 */
0052 double nsl_stats_maximum(const double data[], const size_t n, size_t *index);
0053 
0054 /* median from unsorted data. data will be sorted! */
0055 double nsl_stats_median(double data[], size_t stride, size_t n, nsl_stats_quantile_type type);
0056 /* median from sorted data */
0057 double nsl_stats_median_sorted(const double sorted_data[], size_t stride, size_t n, nsl_stats_quantile_type type);
0058 /* GSL legacy function */
0059 double nsl_stats_median_from_sorted_data(const double sorted_data[], size_t stride, size_t n);
0060 
0061 /* quantile from unsorted data. data will be sorted! */
0062 double nsl_stats_quantile(double data[], size_t stride, size_t n, double p, nsl_stats_quantile_type type);
0063 /* quantile from sorted data */
0064 double nsl_stats_quantile_sorted(const double sorted_data[], size_t stride, size_t n, double p, nsl_stats_quantile_type type);
0065 /* GSL legacy function */
0066 double nsl_stats_quantile_from_sorted_data(const double sorted_data[], size_t stride, size_t n, double p);
0067 
0068 /* R^2 */
0069 double nsl_stats_rsquare(double sse, double sst);
0070 /* adj. R^2 default version=1 */
0071 double nsl_stats_rsquareAdj(double rsquare, size_t np, size_t dof, int version);
0072 
0073 /* t distribution */
0074 double nsl_stats_tdist_t(double parameter, double error);
0075 /* p value */
0076 double nsl_stats_tdist_p(double t, double dof);
0077 /* margin (half of confidence interval) */
0078 double nsl_stats_tdist_margin(double alpha, double dof, double error);
0079 
0080 /* chi^2 distribution */
0081 double nsl_stats_chisq_p(double t, double dof);
0082 
0083 /* F distribution */
0084 double nsl_stats_fdist_F(double rsquare, size_t np, size_t dof);
0085 /* p value */
0086 double nsl_stats_fdist_p(double F, size_t np, double dof);
0087 
0088 /* log-likelihood */
0089 double nsl_stats_logLik(double sse, size_t n);
0090 
0091 /* Akaike information criterion (AIC) */
0092 double nsl_stats_aic(double sse, size_t n, size_t np, int version);
0093 /* bias-corrected version */
0094 double nsl_stats_aicc(double sse, size_t n, size_t np, int version);
0095 
0096 /* Schwarz Bayesian information criterion (BIC, SBC, SBIC) */
0097 double nsl_stats_bic(double sse, size_t n, size_t np, int version);
0098 
0099 #endif /* NSL_STATS_H */