Solved

Formula for computing standard deviation

Posted on 1998-02-14
1
1,197 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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