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)

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.

Kaptlt.Endrass 10-30-14 12:10 AM

You all got it wrong. Standard deviation is...

a) how far off you are from your target in darts.
b) how many drinks you've got left before you pass out.
c) how far the 'fire for effect' barrage is from hitting the obvious target.
d) completely irrevelant to anything we REALLY want to talk about (C'mon: Conversation about math or the next FIFA champs, which hopefully be Germany again)

Jeff-Groves 10-30-14 02:18 PM

I hate math. I work with visual geometry mostly.
If I cut this post and let it fall will it miss all the stuff I don't want to break?
That kind of thing.
:O:

Imagine the surprise on faces the day I was not at work.
Some cables were cut that no one bothered to look at closely.
Results were a building that shifted and leaned 2" in a Northernly direction!

Eichhörnchen 10-30-14 04:19 PM

The eyeball is a wonderful thing.:up:


All times are GMT -5. The time now is 05:27 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.