Attribute VB_Name = "test_sign_os" '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 ts_sign_os_addHelp() Application.MacroOptions _ Macro:="ts_sign_os", _ Description:="one-sample sign test", _ category:=14, _ ArgumentDescriptions:=Array( _ "range with the data as numbers", _ "optional hypothesized median, otherwise the midrange will be used") Application.MacroOptions _ Macro:="ts_sign_os_arr", _ Description:="one-sample sign test" & vbNewLine & "array function, requires 2 rows and 2 columns as output", _ category:=14, _ ArgumentDescriptions:=Array( _ "range with the data as numbers", _ "optional hypothesized median, otherwise the midrange will be used") End Sub Function ts_sign_os(data As Range, Optional hypMed = "none") Attribute ts_sign_os.VB_Description = "perform a one-sample sign test" Attribute ts_sign_os.VB_ProcData.VB_Invoke_Func = " \n14" 'perform a one-sample sign test 'data -> scores as vector 'hypMed -> hypothesized median, default is use of midrange If hypMed = "none" Then hypMed = (WorksheetFunction.Min(data) + WorksheetFunction.Max(data)) / 2 End If 'count cases below hypothesized median and number of cases unequal to it. For i = 1 To data.Rows.Count If data.Cells(i, 1) < hypMed Then nbelow = nbelow + 1 n = n + 1 ElseIf data.Cells(i, 1) > hypMed Then n = n + 1 End If Next i 'determine expected number of cases in each group nExp = n * 0.5 'determine the probability If nbelow < nExp Then oneTail = WorksheetFunction.BinomDist(nbelow, n, 0.5, True) Else oneTail = 1 - WorksheetFunction.BinomDist(nbelow - 1, n, 0.5, True) End If ts_sign_os = 2 * oneTail End Function Function ts_sign_os_arr(data As Range, Optional hypMed = "none") 'perform a one-sample sign test 'data -> scores as vector 'hypMed -> hypothesized median, default is use of midrange If hypMed = "none" Then hypMed = (WorksheetFunction.Min(data) + WorksheetFunction.Max(data)) / 2 End If 'count cases below hypothesized median and number of cases unequal to it. For i = 1 To data.Rows.Count If data.Cells(i, 1) < hypMed Then nbelow = nbelow + 1 n = n + 1 ElseIf data.Cells(i, 1) > hypMed Then n = n + 1 End If Next i 'determine expected number of cases in each group nExp = n * 0.5 'determine the probability If nbelow < nExp Then oneTail = WorksheetFunction.BinomDist(nbelow, n, 0.5, True) Else oneTail = 1 - WorksheetFunction.BinomDist(nbelow - 1, n, 0.5, True) End If pVal = 2 * oneTail testUsed = "one-sample sign test" 'Results Dim res(1 To 2, 1 To 2) res(1, 1) = "p-value" res(1, 2) = "test" res(2, 1) = pVal res(2, 2) = testUsed ts_sign_os_arr = res End Function