473,326 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Help with stats method

jane507
As I guess is standard in today's undergrad education, I've got to code a stats class with various statistical methods. I have them all under control except the one for standard deviation. We're supposed to use a specific formula, the one that take the square root of everything. I don't know how to put it in here like my teacher has it on her website, so hopefully this makes sense:
Sqrt [ (E (x - x) ^2) / n]
where E is the summation symbol, x is an array value, x is the mean and n is the number of values in the array.

I have tried to write this myself so don't think I'm wanting somebody out there to write the whole thing for me. I did however just get frustrated and deleted everything I had. So my code currently looks like this:
Expand|Select|Wrap|Line Numbers
  1. float StandardDeviation( int array[], int n)
  2. {
  3. }
I have the mean method coded already, if that helps. I tried to bring it down and use it and it didn't work. Any help at all would be so appreciated!!
Apr 2 '07 #1
3 1640
sicarie
4,677 Expert Mod 4TB
I wrote something similar to this recently, and it's tough, but doable. I broke everything down into a separate mathematical function - even simple additions. Is the array of a fixed length? I'm pretty sure you'll have to pass the mean, you won't be able to access it from a function - that's out of scope.
Apr 2 '07 #2
r035198x
13,262 8TB
As I guess is standard in today's undergrad education, I've got to code a stats class with various statistical methods. I have them all under control except the one for standard deviation. We're supposed to use a specific formula, the one that take the square root of everything. I don't know how to put it in here like my teacher has it on her website, so hopefully this makes sense:
Sqrt [ (E (x - x) ^2) / n]
where E is the summation symbol, x is an array value, x is the mean and n is the number of values in the array.

I have tried to write this myself so don't think I'm wanting somebody out there to write the whole thing for me. I did however just get frustrated and deleted everything I had. So my code currently looks like this:
Expand|Select|Wrap|Line Numbers
  1. float StandardDeviation( int array[], int n)
  2. {
  3. }
I have the mean method coded already, if that helps. I tried to bring it down and use it and it didn't work. Any help at all would be so appreciated!!
This is not very complicated if you make use of a simple for loop that for the summation
Apr 2 '07 #3
JosAH
11,448 Expert 8TB
I have tried to write this myself so don't think I'm wanting somebody out there to write the whole thing for me. I did however just get frustrated and deleted everything I had.
Remember those old calculators? Some of them could even do some stats
functions (such as the standard deviation). You could find those numbers for
thousands of samples but you can bet on it that those old calculators didn't
have many kilo/mega-bytes of ram avaialble to store those big arrays.

This is how they did it:

the square of the standard deviation is defined as:

sum(((x-m)^2)/n) where m is the average or mean of all values x and n is
the number of samples x. (identical to your formula).

the value m itself is defined as sum(x)/n

Let's fiddle a bit with that formula:

sum(((x-m)^2)/n) --> sum((x^2-2.x.m+m^2)/n) -->

sum(x^2/n)-sum(2.x.m/n)+sum(m^2/n) -->

sum(x^2/n)-m.sum(2.x)/n+sum(m^2/n) -->

sum(x^2/n)-2.m.m+m.m --> sum(x^2/n)-m.m --> sum(x^2)/n-(sum(x)/n)^2

The latest form requires just sum(x^2) and the mean of all those x's squared.
Suppose you have three variables:

Expand|Select|Wrap|Line Numbers
  1. double sx; // sum of x's
  2. double sxx; // sum of squares of x's
  3. int n; // number of sampes
  4.  
you can add a new x value as follows:
Expand|Select|Wrap|Line Numbers
  1. sx+= x;
  2. sxx+= x*x;
  3. n++;
  4.  
And you can find the square of the standard deviation as follows:

Expand|Select|Wrap|Line Numbers
  1. double ssd= ssx/n-(sx/n)*(sx/n);
  2.  
All you need are those three variables sx, sxx and n, keep on adding new
x values and you can have the ssd at any time you want.

kind regards,

Jos
Apr 2 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: dan glenn | last post by:
My client wants to see stats which tell him the number of hits he's getting from different countries. I'm coding page hit count stats myself in PHP on his site, which is simple enough, but haven't...
1
by: Robert Brewer | last post by:
I've been working on optimizing some code (yes, it really needs it--it's too slow ;) -- decided to use hotshot. I'm assuming things about the output of hotshot.stats that I want to verify before I...
1
by: Mauro Baraldi | last post by:
Hy, I have 2 tables whith some fields distincts. 1° Table: Clients Fields: Name, Adress, Fone, E-mail, Stats (this is a binary field - yes/no). 2° Table: Events Fields: Event, Date, Hour,...
8
by: chudson007 | last post by:
I need help capturing information from a free text field. The 10 examples below contain examples of the information I am trying to capture. In each cell I am trying to capture the number between...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
2
by: BerkshireGuy | last post by:
I have a routine in Access that loops through an Excel workbook and executes code base on the worksheet name. If the worksheet name contains the word 'Stats' than that is a sheet I want to read...
53
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
2
by: kage | last post by:
I am trying to use this with mushclient 3.84 it supports these type of scripts. If anyone could help me figure out which type of script it is or convert it to any of those that my client uses....
4
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.