Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange calculation for Variance and StandardDeviation #2360

Closed
1 of 5 tasks
larshagencognite opened this issue Oct 31, 2023 · 1 comment · Fixed by #2505
Closed
1 of 5 tasks

Strange calculation for Variance and StandardDeviation #2360

larshagencognite opened this issue Oct 31, 2023 · 1 comment · Fixed by #2505
Assignees

Comments

@larshagencognite
Copy link

Type of issue

  • Bug
  • Enhancement
  • Compliance
  • Question
  • Help wanted

Current Behavior

The calculation of standard deviation and variance in https://github.com/OPCFoundation/UA-.NETStandard/blob/master/Libraries/Opc.Ua.Server/Aggregates/StdDevAggregateCalculator.cs is very strange.

  • Bounds are always included for variance, never for standard deviation
  • The square root is taken on the result for VariancePopulation, StandardDeviationPopulation, and not for the sample variants.
  • When including bounds, the sum of squared errors is divided by n+1, I would expect n-1.
  • When including bounds, the last bound is ignored.
  • When not including bounds, the last data point in the range is ignored.

Expected Behavior

I would expect the calculations to follow the documentation.

  • StandardDeviation* = sqrt(Variance*)
  • Don't ignore last value
  • Divide by n-1 for samples

Steps To Reproduce

No response

Environment

No response

Anything else?

No response

@ThomasNehring
Copy link
Contributor

ThomasNehring commented Feb 6, 2024

the fact that the standard deviation is not always the sqrt of the Variance is an error and probably due to a typo when calling the method ComputeValue(TimeSlice).

I assume that dividing by n+1 instead of dividing by n-1 is a typo, also. (see, e.g. Why we use (n.1) in the denominator of standard deviation formula.)

For the question of when to include the bounds I need to have a closer look at the pertinent sections of the spec.
StandardDeviationSample
VarianceSample
StandardDeviationPopulation
VariancePopulation

Updated (202402071607 CET):
Actually, there is sample data in the spec (part 13, section A.1), together with the expected outcome of the aggregate calculation (sections A.35, A.36, A.37, A.38) which we can use to figure out whether the behavior wrt to the boundary values is in sync with the specification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants