
Calculate a Z-Squared Goodness-of-Fit Statistic
Source:R/fn_calculate.R
calculate_z_squared_score.RdCalculates a z-squared goodness-of-fit statistic comparing observed and expected frequencies.
Value
A list containing:
- z_square
Overall z-squared statistic.
- p_value
Chi-squared p-value.
- degrees_of_freedom
Number of degrees of freedom.
- critical_value
Chi-squared critical value at the 0.05 significance level.
- details
Data frame containing cell-level z scores and probabilities.
Details
The implementation follows the approach described by Voas and Williamson and incorporates the continuity correction proposed by Fleiss (1981).
The resulting z-squared statistic can be interpreted in a similar manner to a chi-squared test statistic and may be used to assess the fit of a synthetic population to a reference distribution.
For each contingency-table cell:
Observed and expected proportions are calculated.
A continuity correction is applied when the expected frequency is non-zero.
Cell-level z scores are calculated.
Squared z scores are summed to create an overall z-squared statistic.
When the expected count equals zero, a small surrogate expected proportion is used in the denominator to avoid division-by-zero problems.
This function is primarily intended for evaluating the fit of synthetic populations generated by replica.
References
Fleiss JL (1981). Statistical Methods for Rates and Proportions. Wiley.
Voas D, Williamson P (2001). "The Diversity of Diversity: A Critique of Geodemographic Classification".
Examples
df <- data.frame(
count_x = c(
40,
35,
25
),
count_y = c(
45,
30,
25
)
)
result <- calculate_z_squared_score(
df
)
result$z_square
#> [1] 1.795801
result$p_value
#> [1] 0.6158491