Do I have to type all of the following stuff for the central moment of a random variable by hand,
or is it partly generated automatically somehow ? Or even present in LO by default from the origin ?
REM ***** BASIC *****
Function centralNormalizedMoment(pSequence, pOrder, Optional pIsSample As Boolean) As Double
If IsMissing(pIsSample) Then pIsSample = True
fa = CreateUnoService("com.sun.star.sheet.FunctionAccess")
N = Ubound(pSequence)
mu = fa.callFunction("AVERAGE", Array(pSequence))
useVar = fa.callFunction("VARP", Array(pSequence)) * IIf(pIsSample, N/(N - 1), 1)
useSD = Sqr(useVar)
nFactor = 1 / useSD
For j = 1 To N
pSequence(j, 1) = ((pSequence(j, 1) - mu)*nFactor)^pOrder
Next j
prelim = fa.callFunction("AVERAGE", Array(pSequence))
If pIsSample Then
For k = 1 To pOrder - 1
prelim = prelim * N / (N-k)
Next k
End If
centralNormalizedMoment = prelim
End Function
Function generalNormalizedMoment(pSequence, pOrder, pFocus, Optional pIsSample As Boolean)
REM No responsibility taken! Errors expected! No responsibility taken! Errors expected!
If IsMissing(pIsSample) Then pIsSample = True
fa = CreateUnoService("com.sun.star.sheet.FunctionAccess")
N = Ubound(pSequence)
ct = fa.callFunction("COUNT", Array(pSequence))
If ct<N Then
generalNormalizedMoment = "only:numbers:allowed"
Exit Function
End If
mu = fa.callFunction("AVERAGE", Array(pSequence))
If TypeName(pFocus)="String" Then REM Any string interpreted as "central".
pFocus = mu
End If
useVar = fa.callFunction("VARP", Array(pSequence)) * IIf(pIsSample, N/(N - 1), 1)
useSD = Sqr(useVar)
nFactor = 1 / useSD
For j = 1 To N
pSequence(j, 1) = ((pSequence(j, 1) - pFocus)*nFactor)^pOrder
Next j
moment = fa.callFunction("AVERAGE", Array(pSequence))
If pIsSample Then
For k = 1 To pOrder - 1
moment = moment * N / (N-k)
Next k
End If
generalNormalizedMoment = moment
End Function