Community Server

The platform that enables you to build rich, interactive communities
Welcome to Community Server Sign in | Join | Help
in Search

SKEWNESS fails if StdDev=0

Last post 03-09-2010, 8:56 AM by virgule. 4 replies.
Sort Posts: Previous Next
  •  03-07-2010, 5:44 PM 106

    SKEWNESS fails if StdDev=0

    Hello John,

    New issue: the SKEWNESS command fails if the data array has a StdDev = 0 (eg a constant array), because the formula then divides by zero.

    The formula in the reference source would also fail - it's not a Stats101 coding error; it's an incomplete algorithm. The formulas on Wikipedia are slightly different...but as far as I can tell they would also divide by zero ;-)

    Any Statistics Wizard around with some suggestions?

    Gus
  •  03-08-2010, 8:46 AM 108 in reply to 106

    Re: SKEWNESS fails if StdDev=0

    Gus,

    I suspect that the answer is that skewness is not defined for a zero standard deviation. I haven't seen any definition that doesn't blow up with stdDev = 0. Try it on Microsoft Excel: It also blows up.

    So, in your code you might have to test for that case (stdDev = 0) and handle it in whatever special way you need to.

    John
  •  03-08-2010, 4:56 PM 110 in reply to 108

    Re: SKEWNESS fails if StdDev=0

    John,

    Point taken. I believe there is only 2 cases where this can happen:
    - Nul input vector. Hopefully I won't be doing stats on that.
    - Constant input vector, which in electronics would be called a Dirac pulse: StdDev = 0, but Mean is defined. If I remember correctly, the main property of a Dirac is that it's surface is unity (or a multiple), rather than zero or infinity, yes? Then what is a reasonable value for the skewness of such pulse? Zero? Infinity? Undefined?

    Whatever the answer is (it doesn't matter in my case, I just want my iteration loop to go over it without crashing at iteration #1), I will have to test for it and return a special value, by either creating MYSKEWNESS function or modifying lib\NormalTestCommands.txt

    Both options are easy to do, but do not feel like a proper approach. May I suggest modifying lib\NormalTestCommands.txt on your source would be more proper?

    Gus
  •  03-08-2010, 6:38 PM 111 in reply to 110

    Re: SKEWNESS fails if StdDev=0

    Gus,

    Since the skewness isn't defined for Std Dev of zero, there is no correct value that could be returned by the subroutine that would satisfy all uses of the subroutine. I suppose it could return NaN, but would that be any better? I think that a program or subroutine should not allow an attempt to perform a mathematically undefined or meaningless operation to go unnoticed. Rather it should raise an error to force the user to recognize and handle it in whatever way is most appropriate to his/her problem.

    John
  •  03-09-2010, 8:56 AM 112 in reply to 111

    Re: SKEWNESS fails if StdDev=0

    John,

    I respect your view point. If anyone else bumps onto this problem, here's how I am handling it.
    PS: forcing to zero actually works quite well in my application: the first iteration starts at Skewness=0 (with a warning message) and then it wanders up and down as per the simulation, as desired.
    Rgds
    Gus

    NEWCMD MYSKEWNESS Input Skewness @statistics ?"Computes the skewness of data in the input vector."
       STDEV Input InputSD
       IF InputSD = 0
          DATA 0 Skewness
          OUTPUT "WARNING: The standard deviation of your input data is nil. Skewness is not defined. Forcing result to zero to avoid crashing.\n"
       ELSE
          MEAN input inputMean
          SIZE input inputSize
          LET skewness = sum((input - inputMean)^3) / ((inputSize - 1)* (inputSD^3))
       END
    END
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems