*** regression.h Fri Aug 16 16:33:38 2002 --- new_regression.h Mon Sep 9 18:45:07 2002 *************** *** 66,68 **** --- 66,125 ---- gnum_float *res, regression_stat_t *stat); + /** + * logarithmic_regression: + * @xss: x-vectors. (Ie., independent data.) + * @dim: number of x-vectors. + * @ys: y-vector. (Dependent data.) + * @n: number of data points. + * @affine: if true, a non-zero constant is allowed. + * @res: output place for constant[0] and factor1[1], factor2[2], ... + * There will be dim+1 results. + * + * This is almost a copy of linear_regression and produces multi-dimensional + * linear regressions on the input points after transforming xss to log(xss). + * Fits to "y = b + a1 * z1 + ... ad * zd" with "zi = log (xi)". + * Problems with arrays: see comment to gnumeric_linest in functions/fn-stat.c. + * + * Returns 0 for ok, non-zero otherwise. (Errors: less than two points, + * all points on a vertical line, non-positive x data.) + */ + + int logarithmic_regression (gnum_float **xss, int dim, + const gnum_float *ys, int n, + int affine, + gnum_float *res, regression_stat_t *stat); + + /** + * logarithmic_fit: + * @xs: x-vector. (Ie., independent data.) + * @ys: y-vector. (Dependent data.) + * @n: number of data points. + * @res: output place for sign[0], a[1], b[2], c[3], and + * sum of squared residuals[4]. + * + * This performs a two-dimensional non-linear fitting on the input points. + * Fits to "y = a + b * log (sign * (x - c))", with sign in {-1, +1}. + * The graph is a logarithmic curve moved horizontally by -c and possibly + * mirrored across the y-axis (if sign = -1). + * + * Returns 0 for OK, non-zero otherwise. + * (Requires: at least 3 different x values, at least 3 different y values.) + * + * Fits c (and sign) by iterative trials, but seems to be fast enough even + * for automatic recomputation. Accuracy of c is: Width of x-range rounded + * to the next smaller (10^integer) times 0.000005. + * + * Adapts c until a local minimum of squared residuals is reached. For each + * new c tried out the corresponding a and b are calculated by linear + * regression. If no local minimum is found, an error is returned. If there + * is more than one local minimum, the one found is not necessarily the + * smallest (i.e., there might be cases in which the returned fit is not the + * best possible). If the shape of the point cloud is to different from + * ``logarithmic'', either sign can not be determined (error returned) or no + * local minimum will be found. + */ + + int logarithmic_fit (gnum_float *xs, + const gnum_float *ys, int n, + gnum_float *res); #endif