/* FIXME:
- - How to calculate significance of some symmetric and directional measures?
+ - How to calculate significance of some directional measures?
- How to calculate ASE for symmetric Somers ' d?
- How to calculate ASE for Goodman and Kruskal's tau?
- How to calculate approx. T of symmetric uncertainty coefficient?
#include "libpspp/misc.h"
#include "libpspp/pool.h"
#include "libpspp/str.h"
+#include "math/correlation.h"
#include "output/pivot-table.h"
#include "output/charts/barchart.h"
free (indexes);
}
+struct symmetric_statistic
+ {
+ double v; /* Value. */
+ double ase; /* Appropriate standard error. */
+ double t; /* Student's t value. */
+ double sig; /* Significance. */
+ };
+
static void calc_r (struct crosstabulation *,
- double *XT, double *Y, double *, double *, double *);
+ double *XT, double *Y, struct symmetric_statistic *);
static void calc_chisq (struct crosstabulation *,
double[N_CHISQ], int[N_CHISQ], double *, double *);
free (indexes);
}
-struct symmetric_statistic
- {
- double v; /* Value. */
- double ase; /* Appropriate standard error. */
- double t; /* Student's t value. */
- double sig; /* Significance. */
- };
-
struct somers_d
{
double v;
if (var_is_numeric (xt->vars[ROW_VAR].var)
&& var_is_numeric (xt->vars[COL_VAR].var))
{
- double r, ase_0, ase_1;
+ struct symmetric_statistic r;
calc_r (xt, (double *) xt->vars[ROW_VAR].values,
- (double *) xt->vars[COL_VAR].values,
- &r, &ase_0, &ase_1);
+ (double *) xt->vars[COL_VAR].values, &r);
- chisq[4] = (xt->total - 1.) * r * r;
+ chisq[4] = (xt->total - 1.) * pow2 (r.v);
df[4] = 1;
}
}
-/* Calculate the value of Pearson's r. r is stored into R, its T value into
- T, and standard error into ERROR. The row and column values must be
- passed in XT and Y. */
+/* Calculate the value of Pearson's r and stores it into *R. The row and
+ column values must be passed in XT and Y. */
static void
calc_r (struct crosstabulation *xt,
- double *XT, double *Y, double *r, double *t, double *error)
+ double *XT, double *Y, struct symmetric_statistic *r)
{
size_t n_rows = xt->vars[ROW_VAR].n_values;
size_t n_cols = xt->vars[COL_VAR].n_values;
double SX = sum_X2r - pow2 (sum_Xr) / xt->total;
double SY = sum_Y2c - pow2 (sum_Yc) / xt->total;
double T = sqrt (SX * SY);
- *r = S / T;
- *t = *r / sqrt (1 - pow2 (*r)) * sqrt (xt->total - 2);
+ r->v = S / T;
+ r->t = r->v / sqrt (1 - pow2 (r->v)) * sqrt (xt->total - 2);
+ r->sig = 2 * significance_of_correlation (r->v, xt->total);
double s = 0;
double c = 0;
c = (t - s) - y;
s = t;
}
- *error = sqrt (s) / (T * T);
+ r->ase = sqrt (s) / (T * T);
}
/* Calculate symmetric statistics and their asymptotic standard
s = t;
}
- calc_r (xt, R, C, &sym[6].v, &sym[6].t, &sym[6].ase);
+ calc_r (xt, R, C, &sym[6]);
free (R);
free (C);
calc_r (xt, (double *) xt->vars[ROW_VAR].values,
(double *) xt->vars[COL_VAR].values,
- &sym[7].v, &sym[7].t, &sym[7].ase);
+ &sym[7]);
}
/* Cohen's kappa. */
,,N of Valid Cases,4,,
Table: Symmetric Measures
-,,,,Value,Asymp. Std. Error,Approx. T
-z,1,Nominal by Nominal,Phi,1.00,,
-,,,Cramer's V,1.00,,
-,,,Contingency Coefficient,.71,,
-,,Ordinal by Ordinal,Kendall's tau-b,.00,.32,.00
-,,,Kendall's tau-c,.00,.32,.00
-,,,Gamma,.00,.50,.00
-,,,Spearman Correlation,.00,.22,.00
-,,Interval by Interval,Pearson's R,.04,.22,.07
-,,N of Valid Cases,,5,,
-,2,Nominal by Nominal,Phi,1.00,,
-,,,Cramer's V,1.00,,
-,,,Contingency Coefficient,.71,,
-,,Ordinal by Ordinal,Kendall's tau-b,-.71,.20,-1.73
-,,,Kendall's tau-c,-.75,.43,-1.73
-,,,Gamma,-1.00,.00,-1.73
-,,,Spearman Correlation,-.77,.17,-1.73
-,,Interval by Interval,Pearson's R,-.73,.18,-1.49
-,,N of Valid Cases,,4,,
+,,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
+z,1,Nominal by Nominal,Phi,1.00,,,
+,,,Cramer's V,1.00,,,
+,,,Contingency Coefficient,.71,,,
+,,Ordinal by Ordinal,Kendall's tau-b,.00,.32,.00,
+,,,Kendall's tau-c,.00,.32,.00,
+,,,Gamma,.00,.50,.00,
+,,,Spearman Correlation,.00,.22,.00,1.000
+,,Interval by Interval,Pearson's R,.04,.22,.07,.950
+,,N of Valid Cases,,5,,,
+,2,Nominal by Nominal,Phi,1.00,,,
+,,,Cramer's V,1.00,,,
+,,,Contingency Coefficient,.71,,,
+,,Ordinal by Ordinal,Kendall's tau-b,-.71,.20,-1.73,
+,,,Kendall's tau-c,-.75,.43,-1.73,
+,,,Gamma,-1.00,.00,-1.73,
+,,,Spearman Correlation,-.77,.17,-1.73,.225
+,,Interval by Interval,Pearson's R,-.73,.18,-1.49,.274
+,,N of Valid Cases,,4,,,
Table: Directional Measures
,,,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
Total,,Count,1,1,1,1,1,5
Table: Symmetric Measures
-,,Value,Asymp. Std. Error,Approx. T
-Ordinal by Ordinal,Spearman Correlation,.975,.022,7.550
-Interval by Interval,Pearson's R,.968,.017,6.708
-N of Valid Cases,,5,,
+,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
+Ordinal by Ordinal,Spearman Correlation,.975,.022,7.550,.005
+Interval by Interval,Pearson's R,.968,.017,6.708,.007
+N of Valid Cases,,5,,,
])
AT_CLEANUP
Total,,Count,2,1,1,1,1,1,1,1,1,10
Table: Symmetric Measures
-,,Value,Asymp. Std. Error,Approx. T
-Ordinal by Ordinal,Spearman Correlation,.973,.015,11.844
-Interval by Interval,Pearson's R,.971,.017,11.580
-N of Valid Cases,,10,,
+,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
+Ordinal by Ordinal,Spearman Correlation,.973,.015,11.844,.000
+Interval by Interval,Pearson's R,.971,.017,11.580,.000
+N of Valid Cases,,10,,,
])
AT_CLEANUP
Total,,Count,1,1,1,1,1,1,2,1,9
Table: Symmetric Measures
-,,Value,Asymp. Std. Error,Approx. T
-Ordinal by Ordinal,Spearman Correlation,.911,.068,5.860
-Interval by Interval,Pearson's R,.966,.017,9.915
-N of Valid Cases,,9,,
+,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
+Ordinal by Ordinal,Spearman Correlation,.911,.068,5.860,.001
+Interval by Interval,Pearson's R,.966,.017,9.915,.000
+N of Valid Cases,,9,,,
])
AT_CLEANUP
Total,,Count,1,1,1,1,1,1,1,1,1,1,1,1,12
Table: Symmetric Measures
-,,Value,Asymp. Std. Error,Approx. T
-Ordinal by Ordinal,Spearman Correlation,.657,.140,2.758
-Interval by Interval,Pearson's R,.667,.132,2.830
-N of Valid Cases,,12,,
+,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
+Ordinal by Ordinal,Spearman Correlation,.657,.140,2.758,.020
+Interval by Interval,Pearson's R,.667,.132,2.830,.018
+N of Valid Cases,,12,,,
])
AT_CLEANUP
Total,,Count,1,1,1,1,1,1,1,1,1,1,10
Table: Symmetric Measures
-,,Value,Asymp. Std. Error,Approx. T
-Ordinal by Ordinal,Spearman Correlation,1.000,.000,+Infinit
-Interval by Interval,Pearson's R,.992,.004,22.638
-N of Valid Cases,,10,,
+,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
+Ordinal by Ordinal,Spearman Correlation,1.000,.000,+Infinit,.000
+Interval by Interval,Pearson's R,.992,.004,22.638,.000
+N of Valid Cases,,10,,,
])
AT_CLEANUP
N of Valid Cases,66.0000,,
Table: Symmetric Measures
-,,Value,Asymp. Std. Error,Approx. T
-Nominal by Nominal,Phi,.3246,,
-,Cramer's V,.3246,,
-,Contingency Coefficient,.3088,,
-Ordinal by Ordinal,Kendall's tau-b,.2752,.0856,1.9920
-,Kendall's tau-c,.1497,.0751,1.9920
-,Gamma,.8717,.1250,1.9920
-,Spearman Correlation,.2908,.0906,2.4311
-Interval by Interval,Pearson's R,.2999,.0973,2.5147
-N of Valid Cases,,66.0000,,
+,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
+Nominal by Nominal,Phi,.3246,,,
+,Cramer's V,.3246,,,
+,Contingency Coefficient,.3088,,,
+Ordinal by Ordinal,Kendall's tau-b,.2752,.0856,1.9920,
+,Kendall's tau-c,.1497,.0751,1.9920,
+,Gamma,.8717,.1250,1.9920,
+,Spearman Correlation,.2908,.0906,2.4311,.018
+Interval by Interval,Pearson's R,.2999,.0973,2.5147,.014
+N of Valid Cases,,66.0000,,,
Table: Directional Measures
,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.