473,543 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with stats method

jane507
1 New Member
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 1658
sicarie
4,677 Recognized Expert Moderator Specialist
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 MVP
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 Recognized Expert MVP
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
1886
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 dealt with this issue before. Can anyone give me the basic pointers and functions to use in collecting this type of data from hits? thanks -dg
1
1978
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 make decisions off of them. Here's an example of output I'm getting. I coded the same function 3 different ways--it's basically a type coercer....
1
1564
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, Cost.
8
5744
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 'TranID=' and the next '&'. So in the fisrt cell I would like to capture 14078800. Things you will need to keep in mind are; The number is not...
9
4046
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" portions of Babe Ruth page (http://www.baseballprospectus.com/dt/ruthba01.shtml) and store that info in a CSV file. Also, I would like to do this for...
2
1598
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 (the code). However, I want to process the company level first because I am going to need to compare the company stats with those of the...
53
4603
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, and .Net2005 code. I'm developing in vb.net 2005. This test sub just reads an input text file, writing out records to another text file, eliminating...
2
1165
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. VBscript Jscript Perlscript Pythonscript Tcl Lua phpscript
4
6282
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 Notice: Undefined index: args in /home/mattehz/public_html/acssr/trunk/inc_error.php on line 92 Warning: Invalid argument supplied for...
0
7594
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7354
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7693
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5888
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4898
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3394
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
643
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.