Statistical Analysis 

(Mean & Standard Deviation) 

Click Here to Download the Exercise 6,                                       For Additional Study Material Click Here

Objective : - To write a C++ Program for the Statistical Analysis, to find the Mean & Standard Deviation of the Sample Data Entered

Theory:

Statistics is a mathematical tool for quantitative analysis of data, and as such it serves as the means by which we extract useful information from data. When performing laboratory experiments, a certain variation in results will always occur regardless of the care taken in measuring. Though all systematic errors have been avoided, we will still notice that the values obtained will deviate from each other. Random errors are unavoidable. Variations occur because each measurement is subject to the sensitivity of the measuring instrument and/or the estimation of the experimenter. Statistical analysis can be used to summarize those observations by estimating the average, which provides an estimate of the true mean. Another important statistical calculation for summarizing the observations is the estimate of the variance, which quantifies the uncertainty in the measured variable. Sometimes we have made measurements of one quantity and we want to use those measurements to infer values of a derived quantity. Statistical analysis can be used to propagate the measurement error through a mathematical model to estimate the error in the derived quantity.

Program:

//Program to Calculate the Mean & Standard Deviation of the Sample Data

#include<iostream.h>

#include<conio.h>

#include<math.h>

float mean(float data[]);

float calculateSD(float data[]);

void main()

{

    clrscr();

    int i;

    float data[10];

    cout << "Enter 10 elements: ";

    for(i = 0; i < 10; ++i)

      {

  cin >> data[i];

      }

    cout << endl << "Mean = "<< mean(data);

    cout << endl << "Standard Deviation = " << calculateSD(data);

    getch();

}


float mean(float data[])

{

    float sum = 0.0, mean;

    int i;

    for(i = 0; i < 10; ++i)

    {

 sum += data[i];

    }

    mean = sum/10;

    return mean;

}


float calculateSD(float data[])

{

    float standardDeviation = 0.0;

    int i;

    for(i = 0; i < 10; ++i)

    {

 standardDeviation += pow(data[i] - mean(data), 2);

    }

    return sqrt(standardDeviation/10);

}

Output:

Output:

1.      Calculate the Mean & Standard Deviation of Sample Data

a.       (1,2,3,4,5,6,7,8,9,10)

b.      (2.3,2.4,2.2,2.2,2.4,2.2,2.4,2.5,2.2,2.3)

2.      Modify the Program to calculate the Mean & Standard Deviation of 25 Samples & Calculate the Mean & Standard Deviation of the following sample

(22,24,22,25,23,21,23,23,26,27, 22,24,22,25,23,21,23,23,26,27, 22,24,22,25,23)