From e970815675114bf48125743f8cc065e7a33b1d5b Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 4 Jul 2022 17:31:07 -0700 Subject: [PATCH] unweighted statistics --- src/language/stats/ctables.c | 340 +++++++++++++++++++++++++++++++- tests/language/stats/ctables.at | 9 +- 2 files changed, 341 insertions(+), 8 deletions(-) diff --git a/src/language/stats/ctables.c b/src/language/stats/ctables.c index e745794781..f611af5100 100644 --- a/src/language/stats/ctables.c +++ b/src/language/stats/ctables.c @@ -93,6 +93,30 @@ enum ctables_vlabel S(CTSF_LAYERROWPCT_TOTALN, "LAYERROWPCT.TOTALN", N_("Layer Row Total N %"), CTF_PERCENT, CTFA_ALL) \ S(CTSF_LAYERCOLPCT_TOTALN, "LAYERCOLPCT.TOTALN", N_("Layer Column Total N %"), CTF_PERCENT, CTFA_ALL) \ \ + /* All variables (unweighted.) */ \ + S(CTSF_UCOUNT, "UCOUNT", N_("Unweighted Count"), CTF_COUNT, CTFA_ALL) \ + S(CTSF_UROWPCT_COUNT, "UROWPCT.COUNT", N_("Unweighted Row %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_UCOLPCT_COUNT, "UCOLPCT.COUNT", N_("Unweighted Column %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_UTABLEPCT_COUNT, "UTABLEPCT.COUNT", N_("Unweighted Table %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_USUBTABLEPCT_COUNT, "USUBTABLEPCT.COUNT", N_("Unweighted Subtable %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_ULAYERPCT_COUNT, "ULAYERPCT.COUNT", N_("Unweighted Layer %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_ULAYERROWPCT_COUNT, "ULAYERROWPCT.COUNT", N_("Unweighted Layer Row %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_ULAYERCOLPCT_COUNT, "ULAYERCOLPCT.COUNT", N_("Unweighted Layer Column %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_UROWPCT_VALIDN, "UROWPCT.VALIDN", N_("Unweighted Row Valid N %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_UCOLPCT_VALIDN, "UCOLPCT.VALIDN", N_("Unweighted Column Valid N %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_UTABLEPCT_VALIDN, "UTABLEPCT.VALIDN", N_("Unweighted Table Valid N %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_USUBTABLEPCT_VALIDN, "USUBTABLEPCT.VALIDN", N_("Unweighted Subtable Valid N %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_ULAYERPCT_VALIDN, "ULAYERPCT.VALIDN", N_("Unweighted Layer Valid N %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_ULAYERROWPCT_VALIDN, "ULAYERROWPCT.VALIDN", N_("Unweighted Layer Row Valid N %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_ULAYERCOLPCT_VALIDN, "ULAYERCOLPCT.VALIDN", N_("Unweighted Layer Column Valid N %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_UROWPCT_TOTALN, "UROWPCT.TOTALN", N_("Unweighted Row Total N %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_UCOLPCT_TOTALN, "UCOLPCT.TOTALN", N_("Unweighted Column Total N %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_UTABLEPCT_TOTALN, "UTABLEPCT.TOTALN", N_("Unweighted Table Total N %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_USUBTABLEPCT_TOTALN, "USUBTABLEPCT.TOTALN", N_("Unweighted Subtable Total N %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_ULAYERPCT_TOTALN, "ULAYERPCT.TOTALN", N_("Unweighted Layer Total N %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_ULAYERROWPCT_TOTALN, "ULAYERROWPCT.TOTALN", N_("Unweighted Layer Row Total N %"), CTF_PERCENT, CTFA_ALL) \ + S(CTSF_ULAYERCOLPCT_TOTALN, "ULAYERCOLPCT.TOTALN", N_("Unweighted Layer Column Total N %"), CTF_PERCENT, CTFA_ALL) \ + \ /* Scale variables, totals, and subtotals. */ \ S(CTSF_MAXIMUM, "MAXIMUM", N_("Maximum"), CTF_GENERAL, CTFA_SCALE) \ S(CTSF_MEAN, "MEAN", N_("Mean"), CTF_GENERAL, CTFA_SCALE) \ @@ -117,6 +141,26 @@ enum ctables_vlabel S(CTSF_LAYERPCT_SUM, "LAYERPCT.SUM", N_("Layer Sum %"), CTF_PERCENT, CTFA_SCALE) \ S(CTSF_LAYERROWPCT_SUM, "LAYERROWPCT.SUM", N_("Layer Row Sum %"), CTF_PERCENT, CTFA_SCALE) \ S(CTSF_LAYERCOLPCT_SUM, "LAYERCOLPCT.SUM", N_("Layer Column Sum %"), CTF_PERCENT, CTFA_SCALE) \ + \ + /* Scale variables, totals, and subtotals (unweighted). */ \ + S(CTSF_UMEAN, "UMEAN", N_("Unweighted Mean"), CTF_GENERAL, CTFA_SCALE) \ + S(CTSF_UMEDIAN, "UMEDIAN", N_("Unweighted Median"), CTF_GENERAL, CTFA_SCALE) \ + S(CTSF_UMISSING, "UMISSING", N_("Unweighted Missing"), CTF_GENERAL, CTFA_SCALE) \ + S(CTSF_UMODE, "UMODE", N_("Unweighted Mode"), CTF_GENERAL, CTFA_SCALE) \ + S(CTSF_UPTILE, "UPTILE", N_("Unweighted Percentile"), CTF_GENERAL, CTFA_SCALE) \ + S(CTSF_USEMEAN, "USEMEAN", N_("Unweighted Std Error of Mean"), CTF_GENERAL, CTFA_SCALE) \ + S(CTSF_USTDDEV, "USTDDEV", N_("Unweighted Std Deviation"), CTF_GENERAL, CTFA_SCALE) \ + S(CTSF_USUM, "USUM", N_("Unweighted Sum"), CTF_GENERAL, CTFA_SCALE) \ + S(CSTF_UTOTALN, "UTOTALN", N_("Unweighted Total N"), CTF_COUNT, CTFA_SCALE) \ + S(CTSF_UVALIDN, "UVALIDN", N_("Unweighted Valid N"), CTF_COUNT, CTFA_SCALE) \ + S(CTSF_UVARIANCE, "UVARIANCE", N_("Unweighted Variance"), CTF_GENERAL, CTFA_SCALE) \ + S(CTSF_UROWPCT_SUM, "UROWPCT.SUM", N_("Unweighted Row Sum %"), CTF_PERCENT, CTFA_SCALE) \ + S(CTSF_UCOLPCT_SUM, "UCOLPCT.SUM", N_("Unweighted Column Sum %"), CTF_PERCENT, CTFA_SCALE) \ + S(CTSF_UTABLEPCT_SUM, "UTABLEPCT.SUM", N_("Unweighted Table Sum %"), CTF_PERCENT, CTFA_SCALE) \ + S(CTSF_USUBTABLEPCT_SUM, "USUBTABLEPCT.SUM", N_("Unweighted Subtable Sum %"), CTF_PERCENT, CTFA_SCALE) \ + S(CTSF_ULAYERPCT_SUM, "ULAYERPCT.SUM", N_("Unweighted Layer Sum %"), CTF_PERCENT, CTFA_SCALE) \ + S(CTSF_ULAYERROWPCT_SUM, "ULAYERROWPCT.SUM", N_("Unweighted Layer Row Sum %"), CTF_PERCENT, CTFA_SCALE) \ + S(CTSF_ULAYERCOLPCT_SUM, "ULAYERCOLPCT.SUM", N_("Unweighted Layer Column Sum %"), CTF_PERCENT, CTFA_SCALE) \ #if 0 /* Multiple response sets not yet implemented. */ S(CTSF_RESPONSES, "RESPONSES", N_("Responses"), CTF_COUNT, CTFA_MRSETS) \ @@ -187,6 +231,9 @@ struct ctables_domain double e_valid; /* Effective weight */ double e_count; double e_total; + double u_valid; /* Unweighted. */ + double u_count; + double u_total; }; enum ctables_summary_variant @@ -830,6 +877,14 @@ ctables_summary_function_is_count (enum ctables_summary_function f) case CTSF_LAYERPCT_COUNT: case CTSF_LAYERROWPCT_COUNT: case CTSF_LAYERCOLPCT_COUNT: + case CTSF_UCOUNT: + case CTSF_UROWPCT_COUNT: + case CTSF_UCOLPCT_COUNT: + case CTSF_UTABLEPCT_COUNT: + case CTSF_USUBTABLEPCT_COUNT: + case CTSF_ULAYERPCT_COUNT: + case CTSF_ULAYERROWPCT_COUNT: + case CTSF_ULAYERCOLPCT_COUNT: return true; case CTSF_ROWPCT_VALIDN: @@ -869,6 +924,38 @@ ctables_summary_function_is_count (enum ctables_summary_function f) case CTSF_LAYERPCT_SUM: case CTSF_LAYERROWPCT_SUM: case CTSF_LAYERCOLPCT_SUM: + case CTSF_UROWPCT_VALIDN: + case CTSF_UCOLPCT_VALIDN: + case CTSF_UTABLEPCT_VALIDN: + case CTSF_USUBTABLEPCT_VALIDN: + case CTSF_ULAYERPCT_VALIDN: + case CTSF_ULAYERROWPCT_VALIDN: + case CTSF_ULAYERCOLPCT_VALIDN: + case CTSF_UROWPCT_TOTALN: + case CTSF_UCOLPCT_TOTALN: + case CTSF_UTABLEPCT_TOTALN: + case CTSF_USUBTABLEPCT_TOTALN: + case CTSF_ULAYERPCT_TOTALN: + case CTSF_ULAYERROWPCT_TOTALN: + case CTSF_ULAYERCOLPCT_TOTALN: + case CTSF_UMEAN: + case CTSF_UMEDIAN: + case CTSF_UMISSING: + case CTSF_UMODE: + case CTSF_UPTILE: + case CTSF_USEMEAN: + case CTSF_USTDDEV: + case CTSF_USUM: + case CSTF_UTOTALN: + case CTSF_UVALIDN: + case CTSF_UVARIANCE: + case CTSF_UROWPCT_SUM: + case CTSF_UCOLPCT_SUM: + case CTSF_UTABLEPCT_SUM: + case CTSF_USUBTABLEPCT_SUM: + case CTSF_ULAYERPCT_SUM: + case CTSF_ULAYERROWPCT_SUM: + case CTSF_ULAYERCOLPCT_SUM: return false; } NOT_REACHED (); @@ -2302,6 +2389,31 @@ ctables_summary_init (union ctables_summary *s, case CTSF_ETOTALN: case CTSF_VALIDN: case CTSF_EVALIDN: + case CTSF_UCOUNT: + case CTSF_UROWPCT_COUNT: + case CTSF_UCOLPCT_COUNT: + case CTSF_UTABLEPCT_COUNT: + case CTSF_USUBTABLEPCT_COUNT: + case CTSF_ULAYERPCT_COUNT: + case CTSF_ULAYERROWPCT_COUNT: + case CTSF_ULAYERCOLPCT_COUNT: + case CTSF_UROWPCT_VALIDN: + case CTSF_UCOLPCT_VALIDN: + case CTSF_UTABLEPCT_VALIDN: + case CTSF_USUBTABLEPCT_VALIDN: + case CTSF_ULAYERPCT_VALIDN: + case CTSF_ULAYERROWPCT_VALIDN: + case CTSF_ULAYERCOLPCT_VALIDN: + case CTSF_UROWPCT_TOTALN: + case CTSF_UCOLPCT_TOTALN: + case CTSF_UTABLEPCT_TOTALN: + case CTSF_USUBTABLEPCT_TOTALN: + case CTSF_ULAYERPCT_TOTALN: + case CTSF_ULAYERROWPCT_TOTALN: + case CTSF_ULAYERCOLPCT_TOTALN: + case CTSF_UMISSING: + case CSTF_UTOTALN: + case CTSF_UVALIDN: s->count = 0; break; @@ -2323,12 +2435,27 @@ ctables_summary_init (union ctables_summary *s, case CTSF_LAYERPCT_SUM: case CTSF_LAYERROWPCT_SUM: case CTSF_LAYERCOLPCT_SUM: + case CTSF_UMEAN: + case CTSF_USEMEAN: + case CTSF_USTDDEV: + case CTSF_USUM: + case CTSF_UVARIANCE: + case CTSF_UROWPCT_SUM: + case CTSF_UCOLPCT_SUM: + case CTSF_UTABLEPCT_SUM: + case CTSF_USUBTABLEPCT_SUM: + case CTSF_ULAYERPCT_SUM: + case CTSF_ULAYERROWPCT_SUM: + case CTSF_ULAYERCOLPCT_SUM: s->moments = moments1_create (MOMENT_VARIANCE); break; case CTSF_MEDIAN: case CTSF_MODE: case CTSF_PTILE: + case CTSF_UMEDIAN: + case CTSF_UMODE: + case CTSF_UPTILE: { struct caseproto *proto = caseproto_create (); proto = caseproto_add_width (proto, 0); @@ -2381,6 +2508,31 @@ ctables_summary_uninit (union ctables_summary *s, case CTSF_ETOTALN: case CTSF_VALIDN: case CTSF_EVALIDN: + case CTSF_UCOUNT: + case CTSF_UROWPCT_COUNT: + case CTSF_UCOLPCT_COUNT: + case CTSF_UTABLEPCT_COUNT: + case CTSF_USUBTABLEPCT_COUNT: + case CTSF_ULAYERPCT_COUNT: + case CTSF_ULAYERROWPCT_COUNT: + case CTSF_ULAYERCOLPCT_COUNT: + case CTSF_UROWPCT_VALIDN: + case CTSF_UCOLPCT_VALIDN: + case CTSF_UTABLEPCT_VALIDN: + case CTSF_USUBTABLEPCT_VALIDN: + case CTSF_ULAYERPCT_VALIDN: + case CTSF_ULAYERROWPCT_VALIDN: + case CTSF_ULAYERCOLPCT_VALIDN: + case CTSF_UROWPCT_TOTALN: + case CTSF_UCOLPCT_TOTALN: + case CTSF_UTABLEPCT_TOTALN: + case CTSF_USUBTABLEPCT_TOTALN: + case CTSF_ULAYERPCT_TOTALN: + case CTSF_ULAYERROWPCT_TOTALN: + case CTSF_ULAYERCOLPCT_TOTALN: + case CTSF_UMISSING: + case CSTF_UTOTALN: + case CTSF_UVALIDN: break; case CTSF_MAXIMUM: @@ -2400,12 +2552,27 @@ ctables_summary_uninit (union ctables_summary *s, case CTSF_LAYERPCT_SUM: case CTSF_LAYERROWPCT_SUM: case CTSF_LAYERCOLPCT_SUM: + case CTSF_UMEAN: + case CTSF_USEMEAN: + case CTSF_USTDDEV: + case CTSF_USUM: + case CTSF_UVARIANCE: + case CTSF_UROWPCT_SUM: + case CTSF_UCOLPCT_SUM: + case CTSF_UTABLEPCT_SUM: + case CTSF_USUBTABLEPCT_SUM: + case CTSF_ULAYERPCT_SUM: + case CTSF_ULAYERROWPCT_SUM: + case CTSF_ULAYERCOLPCT_SUM: moments1_destroy (s->moments); break; case CTSF_MEDIAN: case CTSF_MODE: case CTSF_PTILE: + case CTSF_UMEDIAN: + case CTSF_UMODE: + case CTSF_UPTILE: casewriter_destroy (s->writer); break; } @@ -2450,6 +2617,17 @@ ctables_summary_add (union ctables_summary *s, s->count += d_weight; break; + case CSTF_UTOTALN: + case CTSF_UROWPCT_TOTALN: + case CTSF_UCOLPCT_TOTALN: + case CTSF_UTABLEPCT_TOTALN: + case CTSF_USUBTABLEPCT_TOTALN: + case CTSF_ULAYERPCT_TOTALN: + case CTSF_ULAYERROWPCT_TOTALN: + case CTSF_ULAYERCOLPCT_TOTALN: + s->count += 1.0; + break; + case CTSF_COUNT: case CTSF_ROWPCT_COUNT: case CTSF_COLPCT_COUNT: @@ -2462,6 +2640,18 @@ ctables_summary_add (union ctables_summary *s, s->count += d_weight; break; + case CTSF_UCOUNT: + case CTSF_UROWPCT_COUNT: + case CTSF_UCOLPCT_COUNT: + case CTSF_UTABLEPCT_COUNT: + case CTSF_USUBTABLEPCT_COUNT: + case CTSF_ULAYERPCT_COUNT: + case CTSF_ULAYERROWPCT_COUNT: + case CTSF_ULAYERCOLPCT_COUNT: + if (is_scale || !excluded_missing) + s->count += 1.0; + break; + case CTSF_VALIDN: case CTSF_ROWPCT_VALIDN: case CTSF_COLPCT_VALIDN: @@ -2476,11 +2666,30 @@ ctables_summary_add (union ctables_summary *s, s->count += d_weight; break; + case CTSF_UVALIDN: + case CTSF_UROWPCT_VALIDN: + case CTSF_UCOLPCT_VALIDN: + case CTSF_UTABLEPCT_VALIDN: + case CTSF_USUBTABLEPCT_VALIDN: + case CTSF_ULAYERPCT_VALIDN: + case CTSF_ULAYERROWPCT_VALIDN: + case CTSF_ULAYERCOLPCT_VALIDN: + if (is_scale + ? !is_scale_missing + : !is_missing) + s->count += 1.0; + break; + case CTSF_MISSING: if (is_missing) s->count += d_weight; break; + case CTSF_UMISSING: + if (is_missing) + s->count += 1.0; + break; + case CTSF_ECOUNT: if (is_scale || !excluded_missing) s->count += e_weight; @@ -2526,6 +2735,27 @@ ctables_summary_add (union ctables_summary *s, moments1_add (s->moments, value->f, e_weight); break; + case CTSF_UMEAN: + case CTSF_USEMEAN: + case CTSF_USTDDEV: + case CTSF_USUM: + case CTSF_UVARIANCE: + case CTSF_UROWPCT_SUM: + case CTSF_UCOLPCT_SUM: + case CTSF_UTABLEPCT_SUM: + case CTSF_USUBTABLEPCT_SUM: + case CTSF_ULAYERPCT_SUM: + case CTSF_ULAYERROWPCT_SUM: + case CTSF_ULAYERCOLPCT_SUM: + if (!is_scale_missing) + moments1_add (s->moments, value->f, 1.0); + break; + + case CTSF_UMEDIAN: + case CTSF_UMODE: + case CTSF_UPTILE: + d_weight = e_weight = 1.0; + /* Fall through. */ case CTSF_MEDIAN: case CTSF_MODE: case CTSF_PTILE: @@ -2565,48 +2795,88 @@ ctables_function_domain (enum ctables_summary_function function) case CTSF_MEDIAN: case CTSF_PTILE: case CTSF_MODE: + case CTSF_UCOUNT: + case CTSF_UMISSING: + case CSTF_UTOTALN: + case CTSF_UVALIDN: + case CTSF_UMEAN: + case CTSF_USEMEAN: + case CTSF_USTDDEV: + case CTSF_USUM: + case CTSF_UVARIANCE: + case CTSF_UMEDIAN: + case CTSF_UPTILE: + case CTSF_UMODE: NOT_REACHED (); case CTSF_COLPCT_COUNT: case CTSF_COLPCT_SUM: case CTSF_COLPCT_TOTALN: case CTSF_COLPCT_VALIDN: + case CTSF_UCOLPCT_COUNT: + case CTSF_UCOLPCT_SUM: + case CTSF_UCOLPCT_TOTALN: + case CTSF_UCOLPCT_VALIDN: return CTDT_COL; case CTSF_LAYERCOLPCT_COUNT: case CTSF_LAYERCOLPCT_SUM: case CTSF_LAYERCOLPCT_TOTALN: case CTSF_LAYERCOLPCT_VALIDN: + case CTSF_ULAYERCOLPCT_COUNT: + case CTSF_ULAYERCOLPCT_SUM: + case CTSF_ULAYERCOLPCT_TOTALN: + case CTSF_ULAYERCOLPCT_VALIDN: return CTDT_LAYERCOL; case CTSF_LAYERPCT_COUNT: case CTSF_LAYERPCT_SUM: case CTSF_LAYERPCT_TOTALN: case CTSF_LAYERPCT_VALIDN: + case CTSF_ULAYERPCT_COUNT: + case CTSF_ULAYERPCT_SUM: + case CTSF_ULAYERPCT_TOTALN: + case CTSF_ULAYERPCT_VALIDN: return CTDT_LAYER; case CTSF_LAYERROWPCT_COUNT: case CTSF_LAYERROWPCT_SUM: case CTSF_LAYERROWPCT_TOTALN: case CTSF_LAYERROWPCT_VALIDN: + case CTSF_ULAYERROWPCT_COUNT: + case CTSF_ULAYERROWPCT_SUM: + case CTSF_ULAYERROWPCT_TOTALN: + case CTSF_ULAYERROWPCT_VALIDN: return CTDT_LAYERROW; case CTSF_ROWPCT_COUNT: case CTSF_ROWPCT_SUM: case CTSF_ROWPCT_TOTALN: case CTSF_ROWPCT_VALIDN: + case CTSF_UROWPCT_COUNT: + case CTSF_UROWPCT_SUM: + case CTSF_UROWPCT_TOTALN: + case CTSF_UROWPCT_VALIDN: return CTDT_ROW; case CTSF_SUBTABLEPCT_COUNT: case CTSF_SUBTABLEPCT_SUM: case CTSF_SUBTABLEPCT_TOTALN: case CTSF_SUBTABLEPCT_VALIDN: + case CTSF_USUBTABLEPCT_COUNT: + case CTSF_USUBTABLEPCT_SUM: + case CTSF_USUBTABLEPCT_TOTALN: + case CTSF_USUBTABLEPCT_VALIDN: return CTDT_SUBTABLE; case CTSF_TABLEPCT_COUNT: case CTSF_TABLEPCT_SUM: case CTSF_TABLEPCT_TOTALN: case CTSF_TABLEPCT_VALIDN: + case CTSF_UTABLEPCT_COUNT: + case CTSF_UTABLEPCT_SUM: + case CTSF_UTABLEPCT_TOTALN: + case CTSF_UTABLEPCT_VALIDN: return CTDT_TABLE; } @@ -2622,6 +2892,7 @@ ctables_summary_value (const struct ctables_cell *cell, { case CTSF_COUNT: case CTSF_ECOUNT: + case CTSF_UCOUNT: return s->count; case CTSF_ROWPCT_COUNT: @@ -2638,6 +2909,20 @@ ctables_summary_value (const struct ctables_cell *cell, : SYSMIS); } + case CTSF_UROWPCT_COUNT: + case CTSF_UCOLPCT_COUNT: + case CTSF_UTABLEPCT_COUNT: + case CTSF_USUBTABLEPCT_COUNT: + case CTSF_ULAYERPCT_COUNT: + case CTSF_ULAYERROWPCT_COUNT: + case CTSF_ULAYERCOLPCT_COUNT: + { + enum ctables_domain_type d = ctables_function_domain (ss->function); + return (cell->domains[d]->u_count + ? s->count / cell->domains[d]->u_count * 100 + : SYSMIS); + } + case CTSF_ROWPCT_VALIDN: case CTSF_COLPCT_VALIDN: case CTSF_TABLEPCT_VALIDN: @@ -2652,6 +2937,20 @@ ctables_summary_value (const struct ctables_cell *cell, : SYSMIS); } + case CTSF_UROWPCT_VALIDN: + case CTSF_UCOLPCT_VALIDN: + case CTSF_UTABLEPCT_VALIDN: + case CTSF_USUBTABLEPCT_VALIDN: + case CTSF_ULAYERPCT_VALIDN: + case CTSF_ULAYERROWPCT_VALIDN: + case CTSF_ULAYERCOLPCT_VALIDN: + { + enum ctables_domain_type d = ctables_function_domain (ss->function); + return (cell->domains[d]->u_valid + ? s->count / cell->domains[d]->u_valid * 100 + : SYSMIS); + } + case CTSF_ROWPCT_TOTALN: case CTSF_COLPCT_TOTALN: case CTSF_TABLEPCT_TOTALN: @@ -2666,16 +2965,27 @@ ctables_summary_value (const struct ctables_cell *cell, : SYSMIS); } - case CTSF_MISSING: - return s->count; + case CTSF_UROWPCT_TOTALN: + case CTSF_UCOLPCT_TOTALN: + case CTSF_UTABLEPCT_TOTALN: + case CTSF_USUBTABLEPCT_TOTALN: + case CTSF_ULAYERPCT_TOTALN: + case CTSF_ULAYERROWPCT_TOTALN: + case CTSF_ULAYERCOLPCT_TOTALN: + { + enum ctables_domain_type d = ctables_function_domain (ss->function); + return (cell->domains[d]->u_total + ? s->count / cell->domains[d]->u_total * 100 + : SYSMIS); + } + case CTSF_MISSING: + case CTSF_UMISSING: case CSTF_TOTALN: case CTSF_ETOTALN: - return s->count; - + case CSTF_UTOTALN: case CTSF_VALIDN: - return s->count; - + case CTSF_UVALIDN: case CTSF_EVALIDN: return s->count; @@ -2689,6 +2999,7 @@ ctables_summary_value (const struct ctables_cell *cell, return s->max != SYSMIS && s->min != SYSMIS ? s->max - s->min : SYSMIS; case CTSF_MEAN: + case CTSF_UMEAN: { double mean; moments1_calculate (s->moments, NULL, &mean, NULL, NULL, NULL); @@ -2696,6 +3007,7 @@ ctables_summary_value (const struct ctables_cell *cell, } case CTSF_SEMEAN: + case CTSF_USEMEAN: { double weight, variance; moments1_calculate (s->moments, &weight, NULL, &variance, NULL, NULL); @@ -2703,6 +3015,7 @@ ctables_summary_value (const struct ctables_cell *cell, } case CTSF_STDDEV: + case CTSF_USTDDEV: { double variance; moments1_calculate (s->moments, NULL, NULL, &variance, NULL, NULL); @@ -2710,6 +3023,7 @@ ctables_summary_value (const struct ctables_cell *cell, } case CTSF_SUM: + case CTSF_USUM: { double weight, mean; moments1_calculate (s->moments, &weight, &mean, NULL, NULL, NULL); @@ -2717,6 +3031,7 @@ ctables_summary_value (const struct ctables_cell *cell, } case CTSF_VARIANCE: + case CTSF_UVARIANCE: { double variance; moments1_calculate (s->moments, NULL, NULL, &variance, NULL, NULL); @@ -2730,10 +3045,19 @@ ctables_summary_value (const struct ctables_cell *cell, case CTSF_LAYERPCT_SUM: case CTSF_LAYERROWPCT_SUM: case CTSF_LAYERCOLPCT_SUM: + case CTSF_UROWPCT_SUM: + case CTSF_UCOLPCT_SUM: + case CTSF_UTABLEPCT_SUM: + case CTSF_USUBTABLEPCT_SUM: + case CTSF_ULAYERPCT_SUM: + case CTSF_ULAYERROWPCT_SUM: + case CTSF_ULAYERCOLPCT_SUM: NOT_REACHED (); case CTSF_MEDIAN: case CTSF_PTILE: + case CTSF_UMEDIAN: + case CTSF_UPTILE: if (s->writer) { struct casereader *reader = casewriter_make_reader (s->writer); @@ -2749,6 +3073,7 @@ ctables_summary_value (const struct ctables_cell *cell, return s->ovalue; case CTSF_MODE: + case CTSF_UMODE: if (s->writer) { struct casereader *reader = casewriter_make_reader (s->writer); @@ -3187,15 +3512,18 @@ ctables_cell_add__ (struct ctables_section *s, const struct ccase *c, struct ctables_domain *d = cell->domains[dt]; d->d_total += d_weight; d->e_total += e_weight; + d->u_total += 1.0; if (!excluded_missing) { d->d_count += d_weight; d->e_count += e_weight; + d->u_count += 1.0; } if (!is_missing) { d->d_valid += d_weight; d->e_valid += e_weight; + d->u_count += 1.0; } } } diff --git a/tests/language/stats/ctables.at b/tests/language/stats/ctables.at index 3b20068144..9f0eed8b9b 100644 --- a/tests/language/stats/ctables.at +++ b/tests/language/stats/ctables.at @@ -8,13 +8,12 @@ dnl - Preprocessing to distinguish categorical from scale. dnl - )CILEVEL in summary specifications dnl - Summary functions: dnl * Unimplemented ones. -dnl * U-prefix for unweighted summaries. dnl * .LCL and .UCL suffixes. dnl * .SE suffixes. dnl - CATEGORIES: dnl * Data-dependent sorting. dnl - PCOMPUTE: -dnl * multi-dimensional (multiple CCT_POSTCOMPUTE in one cell +dnl * multi-dimensional (multiple CCT_POSTCOMPUTE in one cell) dnl * dates dnl dnl Features not yet tested: @@ -27,6 +26,10 @@ dnl - Test WEIGHT and adjustment weights. dnl - EMPTY=INCLUDE For string ranges. dnl - Summary functions: dnl * Separate summary functions for totals and subtotals. +dnl Category sorting: +dnl * VALUE +dnl * LABEL +dnl * ascending/descending dnl - CATEGORIES: dnl * String values dnl * Date values @@ -47,6 +50,8 @@ dnl * MISSING, OTHERNM dnl * strings and string ranges dnl - PPROPERTIES: dnl * )LABEL[N]. +dnl - Summary functions: +dnl * U-prefix for unweighted summaries. dnl dnl Not for v1: dnl - Multiple response sets -- 2.30.2