SUBSIM Radio Room Forums

SUBSIM Radio Room Forums (https://www.subsim.com/radioroom/index.php)
-   General Topics (https://www.subsim.com/radioroom/forumdisplay.php?f=175)
-   -   Standard Deviation. Explain. (https://www.subsim.com/radioroom/showthread.php?t=216458)

Aktungbby 10-27-14 02:49 PM

That's not mean deviation-that's CRUEL deviation!
 
^:sign_yeah::agree:http://www.mathsisfun.com/data/image...ion-sample.gif I see it so clearly now; Jeff! You've got it in a nutshell!:k_confused:I didn't know air guns were so complicated.:timeout:

ikalugin 10-27-14 03:16 PM

Err you don't really need to create an object (class) for this, a simple function should do just fine.

Jeff-Groves 10-28-14 09:38 AM

Yep. A new function is plenty good enuff. I don't like adding some monster package I'll never use.

Eichhörnchen 10-28-14 09:47 AM

Nothing worse than having a monster package and never using it.

Pisces 10-28-14 10:52 AM

I have never understood why it has to divide by N-1. Can anyone explain why it is less 1?

I mean, simple averages are simply the sum divided by N. That makes sense to spread the (sum of) differences accross all samples.

Tango589 10-28-14 01:34 PM

Quote:

Originally Posted by Eichhornchen (Post 2256030)
Nothing worse than having a monster package and never using it.

Fnaar, fnaar.

http://i298.photobucket.com/albums/m...drums-K5UJ.gif

vienna 10-28-14 04:58 PM

You know, when I saw the title of this thread, I was a bit confused. I live in Hollywood, California; here, a standard deviation is anything that does not require above normal medical attention, a lengthy session in a confessional, or an excessive bail...


<O>

Chad 10-28-14 05:28 PM

I am a bit rusty on my C++, but maybe we can get you going in the right direction with some psuedo-code!

We know we will have a list of items with numeric values, for simplicity sake, let's assume these are doubles.

So, let's pass that to stubbed method:

Code:

public void CalculateStandardDev(double listOfDoubles)
{

}

Now, we know the length of our array using the following:

Code:

listOfDoubles.size();
This will be our 'n' variable

Code:

public void CalculateStandardDev(double listOfDoubles)
{
    int sizeOfList = listOfDoubles.size();
}

Now we can find the mean by adding an additional local parameter called temporarySum and adding to it while in scope. This may be where my C++ rusty-ness shows :arrgh!:

Code:

public void CalculateStandardDev(double listOfDoubles)
{
    int sizeOfList = listOfDoubles.size();
    double temporarySum = 0;

    for(int i=0; i<sizeOfList; i++)
    {
        temporarySum += listOfDoubles[i];
    }
}


Chad 10-28-14 05:39 PM

Sorry, was scared I was going to lose progress.. Anyways, now we have the sum of all of our items and our 'n' variable. But we still don't have the mean, or the average. So.. to find the average we divide the sum of all of our numbers by 'n', our size of our list:

Code:

public void CalculateStandardDev(double listOfDoubles)
{
    int sizeOfList = listOfDoubles.size();
    double temporarySum = 0;

    for(int i=0; i<sizeOfList; i++)
    {
        temporarySum += listOfDoubles[i];
    }

    double averageOfList = temporarySum / sizeOfList;
}


:up: Done with Step 1!

So now we go into Step 2, which has this equation:

http://www.mathsisfun.com/data/image...tion-part1.gif

We look at each value and subtract the mean and square the result. Sounds easy enough:


Code:

public void CalculateStandardDev(double listOfDoubles)
{
    int sizeOfList = listOfDoubles.size();
    double temporarySum = 0;

    for(int i=0; i<sizeOfList; i++)
    {
        temporarySum += listOfDoubles[i];
    }

    double averageOfList = temporarySum / sizeOfList;

    for(int j=0; j<sizeOfList; j++)
    {
        listOfDoubles[j] = pow(listOfDoubles[j] - averageOfList, 2);
    }
}

What I am doing is replacing the original value from the list with the calculated result of that value minus the average, and using the pow method to square the result. Square being to the second power.

Code:

pow(number, exponentValue)
Now we will loop through our list again and add the new listOfDoubles to eachother, or from 1 to N, N being our variable sizeOfList. We then need to divide by our size of list to give us, VARIANCE!

Code:

public void CalculateStandardDev(double listOfDoubles)
{
    int sizeOfList = listOfDoubles.size();
    double temporarySum = 0;

    for(int i=0; i<sizeOfList; i++)
    {
        temporarySum += listOfDoubles[i];
    }

    double averageOfList = temporarySum / sizeOfList;

    for(int j=0; j<sizeOfList; j++)
    {
        listOfDoubles[j] = pow(listOfDoubles[j] - averageOfList, 2);
    }

    double squaredDifference = 0;
    double variance = 0;

    for(int k=0; k<sizeOfList; k++)
  {
        squaredDifference += listOfDoubles[k];
  }

  variance = squaredDifference / sizeOfList;
}


Chad 10-28-14 05:43 PM

Now that we have our variance, the last step is extremely easy. We simply take the square root of variance to give us the Standard Deviation value!!!

Code:

public double CalculateStandardDev(double listOfDoubles)
{
    int sizeOfList = listOfDoubles.size();
    double temporarySum = 0;

    for(int i=0; i<sizeOfList; i++)
    {
        temporarySum += listOfDoubles[i];
    }

    double averageOfList = temporarySum / sizeOfList;

    for(int j=0; j<sizeOfList; j++)
    {
        listOfDoubles[j] = pow(listOfDoubles[j] - averageOfList, 2);
    }

    double squaredDifference = 0;
    double variance = 0;

    for(int k=0; k<sizeOfList; k++)
  {
        squaredDifference += listOfDoubles[k];
  }

  variance = squaredDifference / sizeOfList;

  double standardDeviationValue = sqrt (variance );
  return standardDeviationValue;
}


Skybird 10-28-14 05:52 PM

Brrr, take it away, it hurts our eyes! Last time I did stuff like that, was in GFA 3.0 on an Amiga, 25 years ago. :D

Jeff-Groves 10-29-14 12:04 PM

I'm gonna go with C++ Mathematical Expression Toolkit Library (ExprTk).
It's a neat header file I can use then throw away along with those old Dewalt side cuts.
:D

Chad 10-29-14 04:07 PM

Quote:

Originally Posted by Jeff-Groves (Post 2256380)
I'm gonna go with C++ Mathematical Expression Toolkit Library (ExprTk).
It's a neat header file I can use then throw away along with those old Dewalt side cuts.
:D

Well it was fun going back and writing that method :)

Armistead 10-29-14 05:16 PM

I had a deviated septum once.

Red October1984 10-29-14 09:02 PM

Quote:

Originally Posted by Skybird (Post 2255652)
Started statistics courses?

I've got this stuff in Psychology right now. It's in a chapter about mental retardation and how common and how severe it is.


All times are GMT -5. The time now is 11:47 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 1995- 2025 Subsim®
"Subsim" is a registered trademark, all rights reserved.