Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <cmath>
- #include <iostream>
- #include <string>
- using namespace std;
- // ************** function declaration statements ************
- void displayASCII(); //Displays program ASCII art
- void displayMenu(); //Displays program Menu
- void oneSampZInt(double mean, double z, double stdDev, int n); //Calculates one sample z interval
- void oneSampTInt(double mean, double t, double stdDev, int n); //Calculates one sample t interval
- void chiSqrdInt(double chiSqrdRight, double chiSqrdLeft, double variance, int n); //Calculates chi-sqaured interval
- void indepMeansZInt(double meanOne, double meanTwo, double stDevOne, double stDevTwo, int n1, int n2, double z); //Calculates two sample z interval for indpendent means
- void indepMeansTInt(double meanOne, double meanTwo, double stDevOne, double stDevTwo, int n1, int n2, double t); //Calculates two sample t interval for indpendent means
- void matchedPairsTInt(double DBar, double SD, int n, double t); //Calculates matched pairs interval
- void twoPropZInt(double p1, double p2, int n1, int n2, double z); //Calculates two proportional z interval
- void onePropZInt(double p, double n, double z); //Calculates one proportional z interval
- void oneSampZTest(double popMean, double sampMean, double popStDev, int n, double Z); //One sample z hypothesis test
- void oneSamptTest(double popMean, double sampMean, double sampStDev, int n, double t); //One sample t hypothesis test
- void twoSampZTest(double sampMeanOne, double sampMeanTwo, double popStDevOne, double popStDevTwo, int nOne, int nTwo, double Z); //Two sample z hypothesis test
- void twoSamptTest(double sampMeanOne, double sampMeanTwo, double sampStDevOne, double sampStDevTwo, int nOne, int nTwo, double t); //Two sample t hypothesis test
- void onePropZTest(double popProp, double sampProp, int n, double Z); //One proportional z hypothesis test
- void twoPropZTest(double sampPropOne, double sampPropTwo, int xOne, int xTwo, int nOne, int nTwo, double Z); //Two proportional z hypothesis test
- int main()
- {
- double mean = 0.0; //Used to store a mean
- double mean1 = 0.0; //Used to store first mean when dealing with more than one mean
- double mean2 = 0.0; //Used to store second mean when dealing with more than one mean
- double z = 0.0; //Used to store z score
- double t = 0.0; //Used to store t score
- double stDev = 0.0; //Used to store standard deviation
- double stDev1 = 0.0; //Used to store first standard deviation when dealing with more than one standard deviation
- double stDev2 = 0.0; //Used to store second standard deviation when dealing with more than one standard deviation
- double chiSqrdRight = 0.0; //Used to store right chi-sqaured value
- double chiSqrdLeft = 0.0; //Used to store left chi-sqaured value
- double variance = 0.0; //Used to store variance
- double p = 0.0; //Used to store proportion
- double p1 = 0.0; //Used to store first proportion when dealing with more than one proportion
- double p2 = 0.0; //Used to store second proportion when dealing with more than one proportion
- double SD = 0.0; //Used to store standard deviation of matched pair differences
- double DBar = 0.0; //Used to store average of matched pair differences
- int n = 0; //Used to store sample size
- int n1 = 0; //Used to store first sample size when dealing with more than one sample
- int n2 = 0; //Used to store second sample size when dealing with more than one sample
- int x1 = 0; //Used to store first x value for two proportional z test
- int x2 = 0; //Used to store second x value for two proportional z test
- string menuLoopChoice; //User's menu choice
- bool runUserInputLoop = true; //flag variable to exit user input while loop
- displayASCII();
- cout << "Simlpe Statistics Calculator" << endl << endl;
- while (runUserInputLoop)
- {
- displayMenu();
- cout << "Enter the number that corresponds with your choice from the menu: ";
- getline(cin, menuLoopChoice);
- if (menuLoopChoice == "1")
- {
- cout << "Enter mean: ";
- cin >> mean;
- cout << "Enter z-score: ";
- cin >> z;
- cout << "Enter standard deviation: ";
- cin >> stDev;
- cout << "Enter sample size: ";
- cin >> n;
- oneSampZInt(mean, z, stDev, n);
- }
- else if (menuLoopChoice == "2")
- {
- cout << "Enter mean: ";
- cin >> mean;
- cout << "Enter t-score: ";
- cin >> t;
- cout << "Enter standard deviation: ";
- cin >> stDev;
- cout << "Enter sample size: ";
- cin >> n;
- oneSampTInt(mean, t, stDev, n);
- }
- else if (menuLoopChoice == "3")
- {
- cout << "Enter mean for first sample: ";
- cin >> mean1;
- cout << "Enter mean for second sample: ";
- cin >> mean2;
- cout << "Enter standard deviation for first sample: ";
- cin >> stDev1;
- cout << "Enter standard deviation for second sample: ";
- cin >> stDev2;
- cout << "Enter z-score: ";
- cin >> z;
- cout << "Enter size of first sample: ";
- cin >> n1;
- cout << "Enter size of second sample: ";
- cin >> n2;
- indepMeansZInt(mean1, mean2, stDev2, stDev1, n1, n2, z);
- }
- else if (menuLoopChoice == "4")
- {
- cout << "Enter mean for first sample: ";
- cin >> mean1;
- cout << "Enter mean for second sample: ";
- cin >> mean2;
- cout << "Enter standard deviation for first sample: ";
- cin >> stDev1;
- cout << "Enter standard deviation for second sample: ";
- cin >> stDev2;
- cout << "Enter t-score: ";
- cin >> t;
- cout << "Enter size of first sample: ";
- cin >> n1;
- cout << "Enter size of second sample: ";
- cin >> n2;
- indepMeansTInt(mean1, mean2, stDev2, stDev1, n1, n2, t);
- }
- else if (menuLoopChoice == "5")
- {
- cout << "Enter sample proportion: ";
- cin >> p;
- cout << "Enter sample size: ";
- cin >> n;
- cout << "Enter z-score";
- cin >> z;
- onePropZInt(p, n, z);
- }
- else if (menuLoopChoice == "6")
- {
- cout << "Enter proportion from sample one: ";
- cin >> p1;
- cout << "Enter proportion from sample two: ";
- cin >> p2;
- cout << "Enter size of sample one: ";
- cin >> n1;
- cout << "Enter size of sample two: ";
- cin >> n2;
- cout << "Enter z-score";
- cin >> z;
- twoPropZInt(p1, p2, n1, n2, z);
- }
- else if (menuLoopChoice == "7")
- {
- cout << "Enter chi-sqaured right value: ";
- cin >> chiSqrdRight;
- cout << "Enter chi-sqaured left value: ";
- cin >> chiSqrdLeft;
- cout << "Enter sample variance: ";
- cin >> variance;
- cout << "Enter sample size: ";
- cin >> n;
- chiSqrdInt(chiSqrdRight, chiSqrdLeft, variance, n);
- }
- else if (menuLoopChoice == "8")
- {
- cout << "Enter mean of differences: ";
- cin >> DBar;
- cout << "Enter standard deviation of differences: ";
- cin >> SD;
- cout << "Enter number of matched pairs: ";
- cin >> n;
- cout << "Enter t-score: ";
- cin >> t;
- matchedPairsTInt(DBar, SD, n, t);
- }
- else if (menuLoopChoice == "A" || menuLoopChoice == "a")
- {
- cout << "Enter population mean: ";
- cin >> mean1;
- cout << "Enter sample mean: ";
- cin >> mean2;
- cout << "Enter population standard deviation: ";
- cin >> stDev;
- cout << "Enter size of sample: ";
- cin >> n;
- cout << "Enter z-score: ";
- cin >> z;
- oneSampZTest(mean1, mean2, stDev, n, z);
- }
- else if (menuLoopChoice == "B" || menuLoopChoice == "b")
- {
- cout << "Enter mean of sample one: ";
- cin >> mean1;
- cout << "Enter mean of sample two: ";
- cin >> mean2;
- cout << "Enter standard deviation of population one: ";
- cin >> stDev1;
- cout << "Enter standard deviation of population two: ";
- cin >> stDev2;
- cout << "Enter size of sample one: ";
- cin >> n1;
- cout << "Enter size of sample two: ";
- cin >> n2;
- cout << "Enter z-score: ";
- cin >> z;
- twoSampZTest(mean1, mean2, stDev1, stDev2, n1, n2, z);
- }
- else if (menuLoopChoice == "C" || menuLoopChoice == "c")
- {
- cout << "Enter population mean: ";
- cin >> mean1;
- cout << "Enter sample mean: ";
- cin >> mean2;
- cout << "Enter sample standard deviation: ";
- cin >> stDev;
- cout << "Enter size of sample: ";
- cin >> n;
- cout << "Enter t-score: ";
- cin >> t;
- oneSamptTest(mean1, mean2, stDev, n, z);
- }
- else if (menuLoopChoice == "D" || menuLoopChoice == "d")
- {
- cout << "Enter mean of sample one: ";
- cin >> mean1;
- cout << "Enter mean of sample two: ";
- cin >> mean2;
- cout << "Enter standard deviation of sample one: ";
- cin >> stDev1;
- cout << "Enter standard deviation of sample two: ";
- cin >> stDev2;
- cout << "Enter size of sample one: ";
- cin >> n1;
- cout << "Enter size of sample two: ";
- cin >> n2;
- cout << "Enter t-score: ";
- cin >> t;
- twoSamptTest(mean1, mean2, stDev1, stDev2, n1, n2, t);
- }
- else if (menuLoopChoice == "E" || menuLoopChoice == "e")
- {
- cout << "Enter the population proportion: ";
- cin >> p1;
- cout << "Enter the sample proportion: ";
- cin >> p2;
- cout << "Enter the sample size: ";
- cin >> n;
- cout << "Enter the z-score: ";
- cin >> z;
- onePropZTest(p1, p2, n, z);
- }
- else if (menuLoopChoice == "F" || menuLoopChoice == "f")
- {
- cout << "Enter sample proportion one: ";
- cin >> p1;
- cout << "Enter sample proportion two: ";
- cin >> p2;
- cout << "Enter the x value of proportion one: ";
- cin >> x1;
- cout << "Enter the x value of proportion two: ";
- cin >> x2;
- cout << "Enter the size of sample one: ";
- cin >> n1;
- cout << "Enter the size of sample two: ";
- cin >> n2;
- cout << "Enter the z-score: ";
- cin >> z;
- twoPropZTest(p1, p2, x1, x2, n1, n2, z);
- }
- else if (menuLoopChoice == "q" || menuLoopChoice == "Q")
- {
- runUserInputLoop = false;
- }
- }
- system("pause");
- return 0;
- }//end of main
- /////////////////////////////////////////////////////////////////////////Function Definitions/////////////////////////////////////////////////////////////////////////
- void displayASCII()
- {
- cout << " ____________________________________ " << endl;
- cout << " / _____/\\__ ___/ _ \\__ ___/ " << endl;
- cout << " \\_____ \\ | | / /_\\ \\| | " << endl;
- cout << " / \\ | |/ | \\ | " << endl;
- cout << "/_______ / |____|\\____|__ /____| " << endl;
- cout << " \\/ \\/ " << endl;
- cout << "_________ _____ .____ _________ " << endl;
- cout << "\\_ ___ \\ / _ \\ | | \\_ ___ \\ " << endl;
- cout << "/ \\ \\/ / /_\\ \\| | / \\ \\/ " << endl;
- cout << "\\ \\____/ | \\ |__\\ \\____" << endl;
- cout << " \\______ /\\____|__ /_______ \\______ /" << endl;
- cout << " \\/ \\/ \\/ \\/ " << endl;
- }
- void displayMenu()
- {
- cout << endl << "-----------------------------------------------" << endl;
- cout << "Confidence Intervals" << endl;
- cout << "-----------------------------------------------" << endl;
- cout << "1 | One Sample Z Interval" << endl;
- cout << "2 | One Sample t Interval" << endl;
- cout << "3 | Two Sample Z interval (independent means)" << endl;
- cout << "4 | Two Sample t Interval (independent means)" << endl;
- cout << "5 | One Proportional Z Interval" << endl;
- cout << "6 | Two Proportional Z Interval" << endl;
- cout << "7 | Chi-sqaured Interval" << endl;
- cout << "8 | Matched Pairs Interval" << endl;
- cout << "-----------------------------------------------" << endl;
- cout << "Hypothesis Tests" << endl;
- cout << "-----------------------------------------------" << endl;
- cout << "A | One Sample Z Test" << endl;
- cout << "B | Two Sample Z Test" << endl;
- cout << "C | One Sample T Test" << endl;
- cout << "D | Two Sample T Test" << endl;
- cout << "E | One Proportional Z Test" << endl;
- cout << "F | Two Proportional Z Test" << endl;
- cout << "q | QUIT" << endl;
- }
- /////////////////////////////////////////////////////////////////////////Confidence Intervals/////////////////////////////////////////////////////////////////////////
- void oneSampZInt(double mean, double z, double stdDev, int n)
- {
- double leftBound = 0.0; //Left boundary of confidence interval
- double rightBound = 0.0; //Right boundary of confidence interval
- leftBound = mean - (z * (stdDev / sqrt(n)));
- rightBound = mean + (z * (stdDev / sqrt(n)));
- cout << "=============================================" << endl;
- cout << leftBound << " < population mean < " << rightBound << endl;
- system("pause");
- }// end of one sample z-interval
- void oneSampTInt(double mean, double t, double stdDev, int n)
- {
- double leftBound = 0.0; //Left boundary of confidence interval
- double rightBound = 0.0; //Right boundary of confidence interval
- leftBound = mean - (t * (stdDev / sqrt(n)));
- rightBound = mean + (t * (stdDev / sqrt(n)));
- cout << "=============================================" << endl;
- cout << leftBound << " < population mean < " << rightBound << endl;
- system("pause");
- }// end of one sample t-interval
- void chiSqrdInt(double chiSqrdRight, double chiSqrdLeft, double variance, int n)
- {
- double leftBound = 0.0; //Left boundary of confidence interval
- double rightBound = 0.0; //Right boundary of confidence interval
- double dividend = 0.0; //Dividend for calculating confidence interval
- dividend = variance * (n - 1);
- leftBound = dividend / chiSqrdRight;
- rightBound = dividend / chiSqrdLeft;
- cout << "=============================================" << endl;
- cout << "(" << leftBound << " < population variance < " << rightBound << ")" << endl;
- system("pause");
- }//end of chi-sqaured interval
- void indepMeansZInt(double meanOne, double meanTwo, double stDevOne, double stDevTwo, int n1, int n2, double z)
- {
- double leftBound = 0.0; //Left boundary of confidence interval
- double rightBound = 0.0; //Right boundary of confidence interval
- double addendMinuend = 0.0; //Used to store addend/ minuend for calculating confindence interval
- double radicand = 0.0; //Used to store radicand for calculating confidence interval
- double addendSubtrahend = 0.0; //Used to store the addend/ subtrahend for calculating confidence interval
- addendMinuend = meanOne - meanTwo;
- radicand = sqrt((pow(stDevOne,2) / n1) + (pow(stDevTwo,2) / n2));
- addendSubtrahend = z * radicand;
- leftBound = addendMinuend - addendSubtrahend;
- rightBound = addendMinuend + addendSubtrahend;
- cout << "=============================================" << endl;
- cout << leftBound << " < difference in means < " << rightBound << endl;
- system("pause");
- }//end of independent means z-interval
- void indepMeansTInt(double meanOne, double meanTwo, double stDevOne, double stDevTwo, int n1, int n2, double t)
- {
- double leftBound = 0.0; //Left boundary of confidence interval
- double rightBound = 0.0; //Right boundary of confidence interval
- double addendMinuend = 0.0; //Used to store addend/ minuend for calculating confindence interval
- double radicand = 0.0; //Used to store radicand for calculating confidence interval
- double addendSubtrahend = 0.0; //Used to store the addend/ subtrahend for calculating confidence interval
- addendMinuend = meanOne - meanTwo;
- radicand = sqrt((pow(stDevOne, 2) / n1) + (pow(stDevTwo, 2) / n2));
- addendSubtrahend = t * radicand;
- leftBound = addendMinuend - addendSubtrahend;
- rightBound = addendMinuend + addendSubtrahend;
- cout << "=============================================" << endl;
- cout << "(" << leftBound << " < difference in means < " << rightBound << ")" << endl;
- system("pause");
- }//end of independent means t-interval
- void matchedPairsTInt(double DBar, double SD, int n, double t)
- {
- double leftBound = 0.0; //Left boundary of confidence interval
- double rightBound = 0.0; //Right boundary of confidence interval
- double addendSubtrahend = 0.0; //Used to store addend/ subtrahend
- addendSubtrahend = t * (SD / sqrt(n));
- leftBound = DBar - addendSubtrahend;
- rightBound = DBar + addendSubtrahend;
- cout << "=============================================" << endl;
- cout << "(" << leftBound << " < mean difference < " << rightBound << ")" << endl;
- system("pause");
- }//end of matched pairs t-interval
- void twoPropZInt(double p1, double p2, int n1, int n2, double z)
- {
- double leftBound = 0.0; //Left boundary of confidence interval
- double rightBound = 0.0; //Right boundary of confidence interval
- double addendMinuend = 0.0; //Used to store addend/ minuend for calculating confindence interval
- double addendSubtrahend = 0.0; //Used to store addend/ subtrahend
- addendMinuend = p1 - p2;
- addendSubtrahend = z * sqrt(((p1 * (1 - p1)) / n1) + ((p2 * (1 - p2)) / n2));
- leftBound = addendMinuend - addendSubtrahend;
- rightBound = addendMinuend + addendSubtrahend;
- cout << "=============================================" << endl;
- cout << "(" << leftBound << " < difference between the two population proportions < " << rightBound << ")" << endl;
- system("pause");
- }//end of two proportional z interval
- void onePropZInt(double p, double n, double z)
- {
- double leftBound = 0.0; //Left boundary of confidence interval
- double rightBound = 0.0; //Right boundary of confidence interval
- double addendSubtrahend = 0.0; //Used to store addend/ subtrahend
- addendSubtrahend = z * sqrt((p * (1 - p)) / n);
- leftBound = p - addendSubtrahend;
- rightBound = p + addendSubtrahend;
- cout << "=============================================" << endl;
- cout << "(" << leftBound << " < population proportion < " << rightBound << ")" << endl;
- system("pause");
- }//end of one proportional z interval
- /////////////////////////////////////////////////////////////////////////Hypothesis tests/////////////////////////////////////////////////////////////////////////
- void oneSampZTest(double popMean, double sampMean, double popStDev, int n, double Z)
- {
- string subMenuChoice; //Used to store user's choice from the submenu
- double testStat = 0.0; //Used to store test statistic
- cout << "==============================================" << endl;
- cout << "Null Hypothesis: population mean = sample mean" << endl;
- cout << "------------------------------------------------" << endl;
- cout << "1 | population mean (not equal to) sample mean" << endl;
- cout << "2 | population mean (<) sample mean" << endl;
- cout << "3 | population mean (>) sample mean" << endl;
- cout << "r | return to main menu" << endl;
- cout << "------------------------------------------------" << endl << endl;
- cout << endl << "Enter the number that corresponds with the proper Alternative Hypothesis from the menu: ";
- getline(cin, subMenuChoice);
- testStat = ((sampMean - popMean) / (popStDev / sqrt(n)));
- if (subMenuChoice == "1")
- {
- if (testStat < (-1 * Z) || testStat >(Z))
- {
- cout << "=============================================" << endl;
- cout << "Test statistic in rejection region" << endl;
- cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
- }
- else
- {
- cout << "=============================================" << endl;
- cout << "Test statistic not in rejection region" << endl;
- cout << "DO NOT reject the Null Hypothesis" << endl;
- }
- }
- else if (subMenuChoice == "2")
- {
- if (testStat < (-1 * Z))
- {
- cout << "=============================================" << endl;
- cout << "Test statistic in rejection region" << endl;
- cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
- }
- else
- {
- cout << "=============================================" << endl;
- cout << "Test statistic not in rejection region" << endl;
- cout << "DO NOT reject the Null Hypothesis" << endl;
- }
- }
- else if (subMenuChoice == "3")
- {
- if (testStat > Z)
- {
- cout << "=============================================" << endl;
- cout << "Test statistic in rejection region" << endl;
- cout << "Reject the Null Hypothesis in support of Alternative Hypothesis" << endl;
- }
- else
- {
- cout << "=============================================" << endl;
- cout << "Test statistic not in rejection region" << endl;
- cout << "DO NOT reject the Null Hypothesis" << endl;
- }
- }
- else if (subMenuChoice == "r" || subMenuChoice == "R")
- {
- cout << "Main Menu" << endl;
- }
- else
- {
- oneSampZTest(popMean, sampMean, popStDev, n, Z);
- }
- }//end of one sample z test
- void oneSamptTest(double popMean, double sampMean, double sampStDev, int n, double t)
- {
- string subMenuChoice; //Used to store user's choice from the submenu
- double testStat = 0.0; //Used to store test statistic
- cout << "==============================================" << endl;
- cout << "Null Hypothesis: population mean = sample mean" << endl;
- cout << "------------------------------------------------" << endl;
- cout << "1 | population mean (not equal to) sample mean" << endl;
- cout << "2 | population mean (<) sample mean" << endl;
- cout << "3 | population mean (>) sample mean" << endl;
- cout << "r | return to main menu" << endl;
- cout << "------------------------------------------------" << endl << endl;
- cout << endl << "Enter the number that corresponds with the proper Alternative Hypothesis from the menu: ";
- getline(cin, subMenuChoice);
- testStat = ((sampMean - popMean) / (sampStDev / sqrt(n)));
- if (subMenuChoice == "1")
- {
- if (testStat < (-1 * t) || testStat >(t))
- {
- cout << "=============================================" << endl;
- cout << "Test statistic in rejection region" << endl;
- cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
- }
- else
- {
- cout << "=============================================" << endl;
- cout << "Test statistic not in rejection region" << endl;
- cout << "DO NOT reject the Null Hypothesis" << endl;
- }
- }
- else if (subMenuChoice == "2")
- {
- if (testStat < (-1 * t))
- {
- cout << "=============================================" << endl;
- cout << "Test statistic in rejection region" << endl;
- cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
- }
- else
- {
- cout << "=============================================" << endl;
- cout << "Test statistic not in rejection region" << endl;
- cout << "DO NOT reject the Null Hypothesis" << endl;
- }
- }
- else if (subMenuChoice == "3")
- {
- if (testStat > t)
- {
- cout << "=============================================" << endl;
- cout << "Test statistic in rejection region" << endl;
- cout << "Reject the Null Hypothesis in support of Alternative Hypothesis" << endl;
- }
- else
- {
- cout << "=============================================" << endl;
- cout << "Test statistic not in rejection region" << endl;
- cout << "DO NOT reject the Null Hypothesis" << endl;
- }
- }
- else if (subMenuChoice == "r" || subMenuChoice == "R")
- {
- cout << "Main Menu" << endl;
- }
- else
- {
- oneSamptTest(popMean, sampMean, sampStDev, n, t);
- }
- }//end of one sample t test
- void twoSampZTest(double sampMeanOne, double sampMeanTwo, double popStDevOne, double popStDevTwo, int nOne, int nTwo, double Z)
- {
- string subMenuChoice; //Used to store user's choice from the submenu
- double testStat = 0.0; //Used to store test statistic
- cout << "==========================================================" << endl;
- cout << "Null Hypothesis: population mean one = population mean two" << endl;
- cout << "------------------------------------------------" << endl;
- cout << "1 | population mean one (not equal to) population mean two" << endl;
- cout << "2 | population mean one (<) population mean two" << endl;
- cout << "3 | population mean one (>) population mean two" << endl;
- cout << "r | return to main menu" << endl;
- cout << "------------------------------------------------" << endl << endl;
- cout << endl << "Enter the number that corresponds with the proper Alternative Hypothesis from the menu: ";
- getline(cin, subMenuChoice);
- testStat = ((sampMeanOne - sampMeanTwo) / sqrt((pow(popStDevOne, 2) / nOne) + (pow(popStDevTwo, 2) / nTwo)));
- if (subMenuChoice == "1")
- {
- if (testStat < (-1 * Z) || testStat >(Z))
- {
- cout << "=============================================" << endl;
- cout << "Test statistic in rejection region" << endl;
- cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
- }
- else
- {
- cout << "=============================================" << endl;
- cout << "Test statistic not in rejection region" << endl;
- cout << "DO NOT reject the Null Hypothesis" << endl;
- }
- }
- else if (subMenuChoice == "2")
- {
- if (testStat < (-1 * Z))
- {
- cout << "=============================================" << endl;
- cout << "Test statistic in rejection region" << endl;
- cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
- }
- else
- {
- cout << "=============================================" << endl;
- cout << "Test statistic not in rejection region" << endl;
- cout << "DO NOT reject the Null Hypothesis" << endl;
- }
- }
- else if (subMenuChoice == "3")
- {
- if (testStat > Z)
- {
- cout << "=============================================" << endl;
- cout << "Test statistic in rejection region" << endl;
- cout << "Reject the Null Hypothesis in support of Alternative Hypothesis" << endl;
- }
- else
- {
- cout << "=============================================" << endl;
- cout << "Test statistic not in rejection region" << endl;
- cout << "DO NOT reject the Null Hypothesis" << endl;
- }
- }
- else if (subMenuChoice == "r" || subMenuChoice == "R")
- {
- cout << "Main Menu" << endl;
- }
- else
- {
- twoSampZTest(sampMeanOne, sampMeanTwo, popStDevOne, popStDevTwo, nOne, nTwo, Z);
- }
- }//end of two sample z test
- void twoSamptTest(double sampMeanOne, double sampMeanTwo, double sampStDevOne, double sampStDevTwo, int nOne, int nTwo, double t)
- {
- string subMenuChoice; //Used to store user's choice from the submenu
- double testStat = 0.0; //Used to store test statistic
- cout << "==========================================================" << endl;
- cout << "Null Hypothesis: population mean one = population mean two" << endl;
- cout << "------------------------------------------------" << endl;
- cout << "1 | population mean one (not equal to) population mean two" << endl;
- cout << "2 | population mean one (<) population mean two" << endl;
- cout << "3 | population mean one (>) population mean two" << endl;
- cout << "r | return to main menu" << endl;
- cout << "------------------------------------------------" << endl << endl;
- cout << endl << "Enter the number that corresponds with the proper Alternative Hypothesis from the menu: ";
- getline(cin, subMenuChoice);
- testStat = ((sampMeanOne - sampMeanTwo) / sqrt((pow(sampStDevOne, 2) / nOne) + (pow(sampStDevTwo, 2) / nTwo)));
- if (subMenuChoice == "1")
- {
- if (testStat < (-1 * t) || testStat >(t))
- {
- cout << "=============================================" << endl;
- cout << "Test statistic in rejection region" << endl;
- cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
- }
- else
- {
- cout << "=============================================" << endl;
- cout << "Test statistic not in rejection region" << endl;
- cout << "DO NOT reject the Null Hypothesis" << endl;
- }
- }
- else if (subMenuChoice == "2")
- {
- if (testStat < (-1 * t))
- {
- cout << "=============================================" << endl;
- cout << "Test statistic in rejection region" << endl;
- cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
- }
- else
- {
- cout << "=============================================" << endl;
- cout << "Test statistic not in rejection region" << endl;
- cout << "DO NOT reject the Null Hypothesis" << endl;
- }
- }
- else if (subMenuChoice == "3")
- {
- if (testStat > t)
- {
- cout << "=============================================" << endl;
- cout << "Test statistic in rejection region" << endl;
- cout << "Reject the Null Hypothesis in support of Alternative Hypothesis" << endl;
- }
- else
- {
- cout << "=============================================" << endl;
- cout << "Test statistic not in rejection region" << endl;
- cout << "DO NOT reject the Null Hypothesis" << endl;
- }
- }
- else if (subMenuChoice == "r" || subMenuChoice == "R")
- {
- cout << "Main Menu" << endl;
- }
- else
- {
- twoSamptTest(sampMeanOne, sampMeanTwo, sampStDevOne, sampStDevTwo, nOne, nTwo, t);
- }
- }//end of two sample t test
- void onePropZTest(double popProp, double sampProp, int n, double Z)
- {
- string subMenuChoice; //Used to store user's choice from the submenu
- double testStat = 0.0; //Used to store test statistic
- cout << "==========================================================" << endl;
- cout << "Null Hypothesis: population proportion = sample proportion" << endl;
- cout << "------------------------------------------------" << endl;
- cout << "1 | population proportion (not equal to) sample proportion" << endl;
- cout << "2 | population proportion (<) sample proportion" << endl;
- cout << "3 | population proportion (>) sample proportion" << endl;
- cout << "r | return to main menu" << endl;
- cout << "------------------------------------------------" << endl << endl;
- cout << endl << "Enter the number that corresponds with the proper Alternative Hypothesis from the menu: ";
- getline(cin, subMenuChoice);
- testStat = ((sampProp - popProp) / sqrt((popProp * (1-popProp)) / n));
- if (subMenuChoice == "1")
- {
- if (testStat < (-1 * Z) || testStat > (Z))
- {
- cout << "=============================================" << endl;
- cout << "Test statistic in rejection region" << endl;
- cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
- }
- else
- {
- cout << "=============================================" << endl;
- cout << "Test statistic not in rejection region" << endl;
- cout << "DO NOT reject the Null Hypothesis" << endl;
- }
- }
- else if (subMenuChoice == "2")
- {
- if (testStat < (-1 * Z))
- {
- cout << "=============================================" << endl;
- cout << "Test statistic in rejection region" << endl;
- cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
- }
- else
- {
- cout << "=============================================" << endl;
- cout << "Test statistic not in rejection region" << endl;
- cout << "DO NOT reject the Null Hypothesis" << endl;
- }
- }
- else if (subMenuChoice == "3")
- {
- if (testStat > Z)
- {
- cout << "=============================================" << endl;
- cout << "Test statistic in rejection region" << endl;
- cout << "Reject the Null Hypothesis in support of Alternative Hypothesis" << endl;
- }
- else
- {
- cout << "=============================================" << endl;
- cout << "Test statistic not in rejection region" << endl;
- cout << "DO NOT reject the Null Hypothesis" << endl;
- }
- }
- else if (subMenuChoice == "r" || subMenuChoice == "R")
- {
- cout << "Main Menu" << endl;
- }
- else
- {
- onePropZTest(popProp, sampProp, n, Z);
- }
- }//end of one prop z test
- void twoPropZTest(double sampPropOne, double sampPropTwo, int xOne, int xTwo, int nOne, int nTwo, double Z)
- {
- string subMenuChoice; //Used to store user's choice from the submenu
- double testStat = 0.0; //Used to store test statistic
- double pHat = 0.0; //Used to store p-hat
- cout << "======================================================================" << endl;
- cout << "Null Hypothesis: population proportion one = population proportion two" << endl;
- cout << "------------------------------------------------" << endl;
- cout << "1 | population proportion one (not equal to) population proportion two" << endl;
- cout << "2 | population proportion one (<) population proportion two" << endl;
- cout << "3 | population proportion one (>) population proportion two" << endl;
- cout << "r | return to main menu" << endl;
- cout << "------------------------------------------------" << endl << endl;
- cout << endl << "Enter the number that corresponds with the proper Alternative Hypothesis from the menu: ";
- getline(cin, subMenuChoice);
- pHat = (xOne + xTwo) / (nOne + nTwo);
- testStat = ((sampPropOne - sampPropTwo) / sqrt(pHat * (1 - pHat) * ((1 / nOne) + (1 / nTwo))));
- if (subMenuChoice == "1")
- {
- if (testStat < (-1 * Z) || testStat >(Z))
- {
- cout << "=============================================" << endl;
- cout << "Test statistic in rejection region" << endl;
- cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
- }
- else
- {
- cout << "=============================================" << endl;
- cout << "Test statistic not in rejection region" << endl;
- cout << "DO NOT reject the Null Hypothesis" << endl;
- }
- }
- else if (subMenuChoice == "2")
- {
- if (testStat < (-1 * Z))
- {
- cout << "=============================================" << endl;
- cout << "Test statistic in rejection region" << endl;
- cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
- }
- else
- {
- cout << "=============================================" << endl;
- cout << "Test statistic not in rejection region" << endl;
- cout << "DO NOT reject the Null Hypothesis" << endl;
- }
- }
- else if (subMenuChoice == "3")
- {
- if (testStat > Z)
- {
- cout << "=============================================" << endl;
- cout << "Test statistic in rejection region" << endl;
- cout << "Reject the Null Hypothesis in support of Alternative Hypothesis" << endl;
- }
- else
- {
- cout << "=============================================" << endl;
- cout << "Test statistic not in rejection region" << endl;
- cout << "DO NOT reject the Null Hypothesis" << endl;
- }
- }
- else if (subMenuChoice == "r" || subMenuChoice == "R")
- {
- cout << "Main Menu" << endl;
- }
- else
- {
- twoPropZTest(sampPropOne, sampPropTwo, xOne, xTwo, nOne, nTwo, Z);
- }
- }//end of one prop z test
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement