Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Formula for computing standard deviation

Posted on 1998-02-14
1
Medium Priority
?
1,205 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 200 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Integration Management Part 2
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

916 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