[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Reviewing covariancematrix.c and interaction.c
From: 
Ben Pfaff 
Subject: 
Re: Reviewing covariancematrix.c and interaction.c 
Date: 
Thu, 18 Jun 2009 20:26:08 0700 
Useragent: 
Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) 
Jason Stover <address@hidden> writes:
> interaction.c and covariancematrix.c are ready for further review.
[...]
> I have been using this modified copy of glm.q to test:
>
> http://jstover.freeshell.org/pspp/src/language/stats/glm.q
Some of these modifications to glm.q add debug printing code,
which presumably helps you to better understand what is happening
inside. But some of it, I think, changes what the GLM procedure
does. If I'm right about that, then is one version or the other
"more correct"; otherwise, what is the reason for those changes?
(I'm trying to understand some of the background here. Maybe I
can review interaction.c and covariancematrix.c without that
background, but it would be nice to understand more.)
I'm appending the diff I see between what's in origin/master and
the http://... file mentioned above, in case you and I are
looking at different versions.
diff git a/glm.q b/glm.q
index 26b9036..8716030 100644
 a/glm.q
+++ b/glm.q
@@ 181,6 +181,7 @@ run_glm (struct casereader *input,
casenumber row;
const struct variable **indep_vars;
const struct variable **all_vars;
+ const struct variable **interaction_vars;
int n_indep = 0;
pspp_linreg_cache *model = NULL;
pspp_linreg_opts lopts;
@@ 190,6 +191,7 @@ run_glm (struct casereader *input,
size_t n_data; /* Number of valid cases. */
struct casereader *reader;
struct covariance_matrix *cov;
+ struct interaction_variable **interactions;
c = casereader_peek (input, 0);
if (c == NULL)
@@ 237,17 +239,35 @@ run_glm (struct casereader *input,
cat_stored_values_create (all_vars[i]);
cov = covariance_matrix_init (n_all_vars, all_vars, ONE_PASS, PAIRWISE,
MV_ANY);
+ size_t n_inter = 1; /* Number of interactions. */
+ size_t n_members = 2; /* Number of memebr variables in an interaction.
*/
+ interaction_vars = xnmalloc (n_inter, sizeof (*interaction_vars));
+ interaction_vars[0] = all_vars[0];
+ interaction_vars[1] = all_vars[1];
reader = casereader_create_counter (reader, &row, 1);
+ interactions = xmalloc (sizeof (*interactions));
+ interactions[0] = interaction_variable_create (interaction_vars,
n_members);
+ for (i = 0; i < n_inter; i++)
+ if (var_is_alpha (interaction_get_variable (interactions[i])))
+ cat_stored_values_create (interaction_get_variable (interactions[i]));
+ covariance_interaction_set (cov, interactions, 1);
for (; (c = casereader_read (reader)) != NULL; case_unref (c))
{
/*
Accumulate the covariance matrix.
*/
 covariance_matrix_accumulate (cov, c, NULL, 0);
+ covariance_matrix_accumulate (cov, c, interactions, 1);
n_data++;
}
covariance_matrix_compute (cov);

+ size_t j;
+ size_t n = covariance_matrix_get_n_rows (cov);
+ for (i = 0; i < n; i++)
+ {
+ for (j = 0; j < n; j++)
+ printf ("%lf\t", covariance_matrix_get_element (cov, i, j));
+ printf ("\n");
+ }
for (i = 0; i < n_dependent; i++)
{
model = fit_model (cov, v_dependent[i], indep_vars, n_data, n_indep);

Ben Pfaff
http://benpfaff.org