Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Read the Skewed Data problem description below. Apply the technique of stepwise

ID: 3680452 • Letter: R

Question

Read the Skewed Data problem description below. Apply the technique of stepwise refinement to design an algorithm for the function described.

You should be guided by the approach given in the problem description. It describes critical steps in the algorithm and how these can be broken into more managable pieces.

Use a text editor (e.g., emacs, the Code::Blocks editor, or NotePad++, or …) to make your first pseudocode statement of the problem.

Each time you refine a step, copy and paste your current version of the function design to the end of your text file, then make your change. Follow the instructor’s convention of using different number of ** to indicate the level of expansion responsible for each statement. When you are done with the design, you should have a complete record of the design process you followed to reach your final design.

In almost any kind of experiment where sampling is done, experimental measurements are subject to random error and other sources of variation. In many cases, a histogram of the collected data would approximate a bell-shaped curve like the one shown here.

Suppose we have collected a number of data values d1,d2,…,dn . The peak of this curve will occur at the mean average of the data, d¯ .

d¯=ni=1din

The width of the curve is controlled by the standard deviation of the data, s :

s=ni=1(d2i)nd¯2n1

If, however, some sort of systematic bias creeps into the measurement process, then the data may be skewed. Experimenters are often interested in detecting skew, so that they can then track down and maybe eliminate the bias responsible for it.

One measurement of skew is

3(d¯Md)/s

where Md is the median of the di (defined below). If this quantity exceeds plus or minus 1, we will say that the data is “badly skewed”.

The median of a collection of measurements is obtained by sorting the measurements into ascending order, then selecting the middle value from the sorted list if there are an odd number of measurements, or the midpoint between the two middle values if the number of measurements is even.

Design a function to determine whether data sets are badly skewed.

Explanation / Answer

Hi below i have written the sample code for your reference,

#include <iostream>

#include <fstream>

#include <cmath>

#include "arrayUtils.h"

using namespace std;

float calculateDeviation(float data[], int arraySize, float mean)

{

float sum = 0.0;

for(int i = 0; i < arraySize; i++)

{

sum += pow(data[i], 2);

}

float numerator = sum - (arraySize*(pow(mean,2)));

float denominator = arraySize -1;

float s = sqrt(numerator/denominator);

return s;

}

float calculateMean(float data[], int arraySize)

{

float sum = 0.0;

for(int i = 0; i < arraySize; i++)

{

sum += data[i];

}

return (sum/arraySize);

}

float calculateMedian(float data[], int arraySize)

{

insertionSort(data, arraySize);

if ( arraySize % 2== 0 ) //ODD

{

double high, low;

low = data[arraySize/2];

high = data[(arraySize/2)+1];

return ((high+low)/2);

}

else //EVEN

{

return (data[arraySize/2]);

}

}

// Determine if a data set is skewed

float skew (float data[], int arraySize)

{

float mean = calculateMean(data, arraySize);

//cout << "Mean = " << mean;

float deviation = calculateDeviation(data, arraySize, mean);

float median = calculateMedian(data, arraySize);

float numerator = 3*(mean - median);

float denomirator = deviation;

return (numerator/denomirator);

}

int main()

{

float data [10000];

int arraySize = 0;

ifstream myfile;

myfile.open ("test0.in");

float temp;

while(myfile >> temp)

{

addToEnd(data, arraySize, temp);

}

for(int i = 0; i < arraySize; i++)

{

cout << data[i] << endl;

}

float skewValue = skew(data, arraySize);

//cout << "SKEW VALUE= " << skewValue << endl;

if (skewValue > 1 || skewValue <-1)

{

cout << "Badly skewed";

}

else

{

cout << "Not badly skewed";

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote