#include <libpspp/assertion.h>
#include <math/covariance.h>
+#include <math/correlation.h>
#include <math/design-matrix.h>
#include <gsl/gsl_matrix.h>
#include <data/casegrouper.h>
#define N_(msgid) msgid
-static double
-significance_of_correlation (double rho, double w)
-{
- double t = w - 2;
- t /= 1 - MIN (1, pow2 (rho));
- t = sqrt (t);
- t *= rho;
-
- if (t > 0)
- return gsl_cdf_tdist_Q (t, w - 2);
- else
- return gsl_cdf_tdist_P (t, w - 2);
-}
-
-
struct corr
{
size_t n_vars_total;
}
-static gsl_matrix *
-correlation_from_covariance (const gsl_matrix *cv, const gsl_matrix *v)
-{
- size_t i, j;
- gsl_matrix *corr = gsl_matrix_calloc (cv->size1, cv->size2);
-
- for (i = 0 ; i < cv->size1; ++i)
- {
- for (j = 0 ; j < cv->size2; ++j)
- {
- double rho = gsl_matrix_get (cv, i, j);
-
- rho /= sqrt (gsl_matrix_get (v, i, j))
- *
- sqrt (gsl_matrix_get (v, j, i));
-
- gsl_matrix_set (corr, i, j, rho);
- }
- }
-
- return corr;
-}
-
-
-
-
static void
run_corr (struct casereader *r, const struct corr_opts *opts, const struct corr *corr)
{
src/math/covariance.h \
src/math/covariance-matrix.c \
src/math/covariance-matrix.h \
+ src/math/correlation.c \
+ src/math/correlation.h \
src/math/design-matrix.c src/math/design-matrix.h \
src/math/extrema.c src/math/extrema.h \
src/math/group.c src/math/group.h \
--- /dev/null
+/* PSPP - a program for statistical analysis.
+ Copyright (C) 2009 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "correlation.h"
+
+#include <gsl/gsl_matrix.h>
+#include <gsl/gsl_cdf.h>
+#include <math.h>
+#include <libpspp/misc.h>
+#include "minmax.h"
+
+
+double
+significance_of_correlation (double rho, double w)
+{
+ double t = w - 2;
+ t /= 1 - MIN (1, pow2 (rho));
+ t = sqrt (t);
+ t *= rho;
+
+ if (t > 0)
+ return gsl_cdf_tdist_Q (t, w - 2);
+ else
+ return gsl_cdf_tdist_P (t, w - 2);
+}
+
+gsl_matrix *
+correlation_from_covariance (const gsl_matrix *cv, const gsl_matrix *v)
+{
+ size_t i, j;
+ gsl_matrix *corr = gsl_matrix_calloc (cv->size1, cv->size2);
+
+ for (i = 0 ; i < cv->size1; ++i)
+ {
+ for (j = 0 ; j < cv->size2; ++j)
+ {
+ double rho = gsl_matrix_get (cv, i, j);
+
+ rho /= sqrt (gsl_matrix_get (v, i, j))
+ *
+ sqrt (gsl_matrix_get (v, j, i));
+
+ gsl_matrix_set (corr, i, j, rho);
+ }
+ }
+
+ return corr;
+}
--- /dev/null
+/* PSPP - a program for statistical analysis.
+ Copyright (C) 2009 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+#ifndef SRC_MATH_CORRELATION_H
+#define SRC_MATH_CORRELATION_H
+
+#include <gsl/gsl_matrix.h>
+
+gsl_matrix * correlation_from_covariance (const gsl_matrix *cv, const gsl_matrix *v);
+
+double significance_of_correlation (double rho, double w);
+
+#endif