Added type 3 sums of squares to GLM
[pspp] / src / math / covariance.c
index b0b0b466676a58eb67311067dbba8f4aab2de413..a7a5f131651963716ee0b0b5e8b8589a26579b2f 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2010, 2011 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
 
 #include <config.h>
 
-#include <libpspp/assertion.h>
-#include "covariance.h"
-#include <gl/xalloc.h>
-#include "moments.h"
+#include "math/covariance.h"
+
 #include <gsl/gsl_matrix.h>
-#include <data/case.h>
-#include <data/variable.h>
-#include <libpspp/misc.h>
-#include "categoricals.h"
+
+#include "data/case.h"
+#include "data/variable.h"
+#include "libpspp/assertion.h"
+#include "libpspp/misc.h"
+#include "math/categoricals.h"
+#include "math/moments.h"
+
+#include "gl/xalloc.h"
 
 #define n_MOMENTS (MOMENT_VARIANCE + 1)
 
@@ -728,3 +731,28 @@ covariance_destroy (struct covariance *cov)
   free (cov->cm);
   free (cov);
 }
+
+size_t
+covariance_dim (const struct covariance * cov)
+{
+  return (cov->dim);
+}
+
+/*
+  Returns an array of variables corresponding to rows of the covariance matrix.
+  In other words, element i of the array is the variable corresponding to 
+  row (and column) i of the covariance matrix.
+ */
+void
+covariance_get_var_indices (const struct covariance *cov, struct variable **vars)
+{
+  int i;
+  for (i = 0; i < cov->n_vars; i++)
+    {
+      vars[i] = cov->vars[i];
+    }
+  for (i = cov->n_vars; i < cov->dim; i++)
+    {
+      vars[i] = categoricals_get_variable_by_subscript (cov->categoricals, i - cov->n_vars);
+    }
+}