Solved

Formula for computing standard deviation

Posted on 1998-02-14
1
1,195 Views
Last Modified: 2008-03-17
Does anyone out there have a formula for computing Standard deviation for a set of given numbers.

P.S. This formula can not use any arrays, and also the numbers  will becoming from a file.
0
Comment
Question by:delbrad
1 Comment
 
LVL 5

Accepted Solution

by:
inter earned 50 total points
ID: 1359196
Lets assume that we have a file which is a text file and each line contains one data (you can easily modify this if you want):

The formula is:

  mean = SumOf(x1, x2, ..., xN) / N;
  variance = SumOf((x[i]-mean)^2/(N^2));
  stddev = sqrt(variance);

function StdDev(FileName : string):real;
var
  mean : real;
  nofitems : integer;
  F : text;
  S : string;
  variance : real;
begin
  AssignFile(F, FileName); Reset(F);
  // first compute the mean of the table
  nofitems := 0; mean := 0;
  while not eof(F) do
  begin
    readln(F, S);
    mean := mean + StrToFloat(S);
    Inc(nofitems);
  end;
  // divide total by number of items
  mean  := mean / nofitems;
  CloseFile(F);
  AssignFile(F, FileName); Reset(F);
  // then compute the variance
  variance := 0;
  while not eof(F) do
  begin
    readln(F, S);
    variance := variance + sqr(StrToFloat(S) - mean);
    Inc(nofitems);
  end;
  // normalize it
  variance := variance / sqr(nofitems);
  CloseFile(F);
  result := sqrt(Result); // std is the square root of variance
end;


See you around friend!  
Igor
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now