const struct variable **vars = mr->cvars;
size_t n_vars = mr->n_cvars;
- *mm = (struct matrix_material) {
- .n = gsl_matrix_calloc (n_vars, n_vars),
- .mean_matrix = gsl_matrix_calloc (n_vars, n_vars),
- .var_matrix = gsl_matrix_calloc (n_vars, n_vars),
- };
+ *mm = (struct matrix_material) { .n = NULL };
struct matrix
{
{
struct substring rowtype = matrix_reader_get_string (c, mr->rowtype);
- gsl_matrix *v
- = (ss_equals_case (rowtype, ss_cstr ("N")) ? mm->n
- : ss_equals_case (rowtype, ss_cstr ("MEAN")) ? mm->mean_matrix
- : ss_equals_case (rowtype, ss_cstr ("STDDEV")) ? mm->var_matrix
+ gsl_matrix **v
+ = (ss_equals_case (rowtype, ss_cstr ("N")) ? &mm->n
+ : ss_equals_case (rowtype, ss_cstr ("MEAN")) ? &mm->mean_matrix
+ : ss_equals_case (rowtype, ss_cstr ("STDDEV")) ? &mm->var_matrix
: NULL);
if (v)
{
+ if (!*v)
+ *v = gsl_matrix_calloc (n_vars, n_vars);
+
for (int x = 0; x < n_vars; ++x)
{
double n = case_num (c, vars[x]);
- if (v == mm->var_matrix)
+ if (v == &mm->var_matrix)
n *= n;
for (int y = 0; y < n_vars; ++y)
- gsl_matrix_set (v, y, x, n);
+ gsl_matrix_set (*v, y, x, n);
}
continue;
}
break;
bool add_corr = mm.cov && !mm.corr;
- bool add_cov = mm.corr && !mm.cov;
+ bool add_cov = mm.corr && !mm.cov && mm.var_matrix;
+ bool add_stddev = add_corr && !mm.var_matrix;
bool remove_corr = add_cov && !append;
bool remove_cov = add_corr && !append;
if (add_corr)
{
- assert (mm.cov->size1 == mr->n_cvars);
- assert (mm.cov->size2 == mr->n_cvars);
-
for (size_t y = 0; y < mr->n_cvars; y++)
{
struct ccase *c = case_clone (model);
ss_cstr (var_get_name (mr->cvars[y])));
casewriter_write (cw, c);
}
+ }
+ if (add_stddev)
+ {
struct ccase *c = case_clone (model);
for (size_t x = 0; x < mr->n_cvars; x++)
{
if (add_cov)
{
- assert (mm.corr->size1 == mr->n_cvars);
- assert (mm.corr->size2 == mr->n_cvars);
-
for (size_t y = 0; y < mr->n_cvars; y++)
{
struct ccase *c = case_clone (model);
free (factor.vars);
factor.vars = vars;
factor.n_vars = n_vars;
+
+ if (mr)
+ {
+ free (mr->cvars);
+ mr->cvars = xmemdup (vars, n_vars * sizeof *vars);
+ mr->n_cvars = n_vars;
+ }
}
else if (lex_match_id (lexer, "PLOT"))
{
static void
do_factor_by_matrix (const struct cmd_factor *factor, struct idata *idata)
{
- if (!idata->mm.cov && !idata->mm.corr)
+ if (!idata->mm.cov && !(idata->mm.corr && idata->mm.var_matrix))
{
- msg (ME, _("The dataset has no complete covariance or correlation matrix."));
+ msg (ME, _("The dataset has no covariance matrix or a "
+ "correlation matrix along with standard devications."));
return;
}
gsl_matrix_free (tmp);
}
- if (factor->print & PRINT_UNIVARIATE)
+ if (factor->print & PRINT_UNIVARIATE
+ && idata->mm.n && idata->mm.mean_matrix && idata->mm.var_matrix)
{
struct pivot_table *table = pivot_table_create (
N_("Descriptive Statistics"));
pivot_table_submit (table);
}
- if (factor->print & PRINT_KMO)
+ if (factor->print & PRINT_KMO && idata->mm.n)
{
struct pivot_table *table = pivot_table_create (
N_("KMO and Bartlett's Test"));
,,var08,81.000,82.000,83.000,84.000,85.000,86.000,87.000,88.000,89.000
,,var09,91.000,92.000,93.000,94.000,95.000,96.000,97.000,98.000,99.000
,N,Value,1.000,2.000,3.000,4.000,5.000,6.000,7.000,8.000,9.000
-,Mean,Value,.000,.000,.000,.000,.000,.000,.000,.000,.000
,Standard Deviation,Value,100.000,200.000,300.000,400.000,500.000,600.000,700.000,800.000,900.000
Table: Data List
,,v4xxxxxxxxxxxxxxxxxxxxxzzzzzzzzzzzzzxxxxxxxxx,. ,. ,. ,. @&t@
,N,Value,2.000,3.000,4.000,5.000
,Mean,Value,1.000,2.000,3.000,4.000
-,Standard Deviation,Value,.000,.000,.000,.000
])
AT_CLEANUP