Attribute VB_Name = "eff_size_cramer_v_gof" 'Created by Peter Stikker 'Companion website: https://PeterStatistics.com 'YouTube channel: https://www.youtube.com/stikpet 'Donations welcome at Patreon: https://www.patreon.com/bePatron?u=19398076 Public Sub es_cramer_v_gof_addHelp() Application.MacroOptions _ Macro:="es_cramer_v_gof", _ Description:="Cramer's V for Goodness-of-Fit", _ category:=14, _ ArgumentDescriptions:=Array( _ "the chi-square test statistic", _ "the sample size", _ "the number of categories", _ "optional boolean to indicate the use of the Bergsma correction (default is False)", _ "output to show, either " & Chr(34) & "value (default)" & Chr(34) & ", or " & Chr(34) & "qual" & Chr(34)) Application.MacroOptions _ Macro:="es_cramer_v_gof_arr", _ Description:="Cramer's V for Goodness-of-Fit" & vbNewLine & "array function, requires 2 rows and 2 columns as output", _ category:=14, _ ArgumentDescriptions:=Array( _ "the chi-square test statistic", _ "the sample size", _ "the number of categories", _ "optional boolean to indicate the use of the Bergsma correction (default is False)") End Sub Function es_cramer_v_gof(chi2, n, k, Optional bergsma = False, Optional out = "value") 'this function calculates Cramer's V for a Goodness-of-Fit test 'input is the chi-square value, the total sample size and the number of categories. 'optional the use of a Bergsma correction, and the output to show (either "value", or "qual" df = k - 1 If bergsma Then kAvg = k - (k - 1) ^ 2 / (n - 1) phi2 = chi2 / n phi2Avg = WorksheetFunction.Max(0, phi2 - (k - 1) / (n - 1)) V = Sqr(phi2Avg / (kAvg - 1)) Else V = Sqr(chi2 / (n * df)) End If 'Results If out = "value" Then res = V Else 'Qualification Dim qual As String 'convert to w w = V / Sqr(df) 'Use Cohen (1988, p. 227). If Abs(w) < 0.1 Then qual = "negligible" ElseIf Abs(w) < 0.3 Then qual = "small" ElseIf Abs(w) < 0.5 Then qual = "medium" Else qual = "large" End If res = qual End If es_cramer_v_gof = res End Function Function es_cramer_v_gof_arr(chiSqValue, n, k, Optional bergsma = False) 'this function calculates Cramer's V for a Goodness-of-Fit test 'input is the chi-square value, the total sample size and the number of categories. 'optional the use of a Bergsma correction df = k - 1 If bergsma Then kAvg = k - (k - 1) ^ 2 / (n - 1) phi2 = chiSqValue / n phi2Avg = WorksheetFunction.Max(0, phi2 - (k - 1) / (n - 1)) V = Sqr(phi2Avg / (kAvg - 1)) testUsed = "Cramer's V (GoF), with Bergsma correction" Else testUsed = "Cramer's V (GoF)" V = Sqr(chiSqValue / (n * df)) End If 'Qualification Dim qual As String 'convert to w w = V / Sqr(df) 'Use Cohen (1988, p. 227). If Abs(w) < 0.1 Then qual = "negligible" ElseIf Abs(w) < 0.3 Then qual = "small" ElseIf Abs(w) < 0.5 Then qual = "medium" Else qual = "large" End If 'Results Dim res(1 To 2, 1 To 2) res(1, 1) = testUsed res(1, 2) = "Qualification" res(2, 1) = V res(2, 2) = qual es_cramer_v_gof_arr = res End Function