Advertisement
wjjd225

Simple Stat Calculator

Dec 15th, 2015
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 34.09 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <cmath>
  3. #include <iostream>
  4. #include <string>
  5. using namespace std;
  6.  
  7. // ************** function declaration statements ************
  8. void displayASCII();                                                                                                    //Displays program ASCII art
  9. void displayMenu();                                                                                                     //Displays program Menu
  10. void oneSampZInt(double mean, double z, double stdDev, int n);                                                          //Calculates one sample z interval
  11. void oneSampTInt(double mean, double t, double stdDev, int n);                                                          //Calculates one sample t interval
  12. void chiSqrdInt(double chiSqrdRight, double chiSqrdLeft, double variance, int n);                                       //Calculates chi-sqaured interval
  13. void indepMeansZInt(double meanOne, double meanTwo, double stDevOne, double stDevTwo, int n1, int n2, double z);        //Calculates two sample z interval for indpendent means
  14. void indepMeansTInt(double meanOne, double meanTwo, double stDevOne, double stDevTwo, int n1, int n2, double t);        //Calculates two sample t interval for indpendent means
  15. void matchedPairsTInt(double DBar, double SD, int n, double t);                                                         //Calculates matched pairs interval
  16. void twoPropZInt(double p1, double p2, int n1, int n2, double z);                                                       //Calculates two proportional z interval
  17. void onePropZInt(double p, double n, double z);                                                                         //Calculates one proportional z interval
  18. void oneSampZTest(double popMean, double sampMean, double popStDev, int n, double Z);                                   //One sample z hypothesis test
  19. void oneSamptTest(double popMean, double sampMean, double sampStDev, int n, double t);                                  //One sample t hypothesis test
  20. void twoSampZTest(double sampMeanOne, double sampMeanTwo, double popStDevOne, double popStDevTwo, int nOne, int nTwo, double Z);        //Two sample z hypothesis test
  21. void twoSamptTest(double sampMeanOne, double sampMeanTwo, double sampStDevOne, double sampStDevTwo, int nOne, int nTwo, double t);      //Two sample t hypothesis test
  22. void onePropZTest(double popProp, double sampProp, int n, double Z);                                                    //One proportional z hypothesis test
  23. void twoPropZTest(double sampPropOne, double sampPropTwo, int xOne, int xTwo, int nOne, int nTwo, double Z);            //Two proportional z hypothesis test
  24.  
  25. int main()
  26. {
  27.     double mean = 0.0;                              //Used to store a mean
  28.     double mean1 = 0.0;                             //Used to store first mean when dealing with more than one mean
  29.     double mean2 = 0.0;                             //Used to store second mean when dealing with more than one mean
  30.     double z = 0.0;                                 //Used to store z score
  31.     double t = 0.0;                                 //Used to store t score
  32.     double stDev = 0.0;                             //Used to store standard deviation
  33.     double stDev1 = 0.0;                            //Used to store first standard deviation when dealing with more than one standard deviation
  34.     double stDev2 = 0.0;                            //Used to store second standard deviation when dealing with more than one standard deviation
  35.     double chiSqrdRight = 0.0;                      //Used to store right chi-sqaured value
  36.     double chiSqrdLeft = 0.0;                       //Used to store left chi-sqaured value
  37.     double variance = 0.0;                          //Used to store variance
  38.     double p = 0.0;                                 //Used to store proportion
  39.     double p1 = 0.0;                                //Used to store first proportion when dealing with more than one proportion
  40.     double p2 = 0.0;                                //Used to store second proportion when dealing with more than one proportion
  41.     double SD = 0.0;                                //Used to store standard deviation of matched pair differences
  42.     double DBar = 0.0;                              //Used to store average of matched pair differences
  43.     int n = 0;                                      //Used to store sample size
  44.     int n1 = 0;                                     //Used to store first sample size when dealing with more than one sample
  45.     int n2 = 0;                                     //Used to store second sample size when dealing with more than one sample
  46.     int x1 = 0;                                     //Used to store first x value for two proportional z test
  47.     int x2 = 0;                                     //Used to store second x value for two proportional z test
  48.     string menuLoopChoice;                          //User's menu choice
  49.     bool runUserInputLoop = true;                   //flag variable to exit user input while loop
  50.  
  51.     displayASCII();
  52.     cout << "Simlpe Statistics Calculator" << endl << endl;
  53.    
  54.     while (runUserInputLoop)
  55.     {
  56.         displayMenu();
  57.         cout << "Enter the number that corresponds with your choice from the menu: ";
  58.         getline(cin, menuLoopChoice);
  59.  
  60.         if (menuLoopChoice == "1")
  61.         {
  62.             cout << "Enter mean: ";
  63.             cin >> mean;
  64.             cout << "Enter z-score: ";
  65.             cin >> z;
  66.             cout << "Enter standard deviation: ";
  67.             cin >> stDev;
  68.             cout << "Enter sample size: ";
  69.             cin >> n;
  70.             oneSampZInt(mean, z, stDev, n);
  71.         }
  72.  
  73.         else if (menuLoopChoice == "2")
  74.         {
  75.             cout << "Enter mean: ";
  76.             cin >> mean;
  77.             cout << "Enter t-score: ";
  78.             cin >> t;
  79.             cout << "Enter standard deviation: ";
  80.             cin >> stDev;
  81.             cout << "Enter sample size: ";
  82.             cin >> n;
  83.             oneSampTInt(mean, t, stDev, n);
  84.         }
  85.  
  86.         else if (menuLoopChoice == "3")
  87.         {
  88.             cout << "Enter mean for first sample: ";
  89.             cin >> mean1;
  90.             cout << "Enter mean for second sample: ";
  91.             cin >> mean2;
  92.             cout << "Enter standard deviation for first sample: ";
  93.             cin >> stDev1;
  94.             cout << "Enter standard deviation for second sample: ";
  95.             cin >> stDev2;
  96.             cout << "Enter z-score: ";
  97.             cin >> z;
  98.             cout << "Enter size of first sample: ";
  99.             cin >> n1;
  100.             cout << "Enter size of second sample: ";
  101.             cin >> n2;
  102.             indepMeansZInt(mean1, mean2, stDev2, stDev1, n1, n2, z);
  103.         }
  104.  
  105.         else if (menuLoopChoice == "4")
  106.         {
  107.             cout << "Enter mean for first sample: ";
  108.             cin >> mean1;
  109.             cout << "Enter mean for second sample: ";
  110.             cin >> mean2;
  111.             cout << "Enter standard deviation for first sample: ";
  112.             cin >> stDev1;
  113.             cout << "Enter standard deviation for second sample: ";
  114.             cin >> stDev2;
  115.             cout << "Enter t-score: ";
  116.             cin >> t;
  117.             cout << "Enter size of first sample: ";
  118.             cin >> n1;
  119.             cout << "Enter size of second sample: ";
  120.             cin >> n2;
  121.             indepMeansTInt(mean1, mean2, stDev2, stDev1, n1, n2, t);
  122.         }
  123.  
  124.         else if (menuLoopChoice == "5")
  125.         {
  126.             cout << "Enter sample proportion: ";
  127.             cin >> p;
  128.             cout << "Enter sample size: ";
  129.             cin >> n;
  130.             cout << "Enter z-score";
  131.             cin >> z;
  132.             onePropZInt(p, n, z);
  133.         }
  134.  
  135.         else if (menuLoopChoice == "6")
  136.         {
  137.             cout << "Enter proportion from sample one: ";
  138.             cin >> p1;
  139.             cout << "Enter proportion from sample two: ";
  140.             cin >> p2;
  141.             cout << "Enter size of sample one: ";
  142.             cin >> n1;
  143.             cout << "Enter size of sample two: ";
  144.             cin >> n2;
  145.             cout << "Enter z-score";
  146.             cin >> z;
  147.             twoPropZInt(p1, p2, n1, n2, z);
  148.         }
  149.  
  150.         else if (menuLoopChoice == "7")
  151.         {
  152.             cout << "Enter chi-sqaured right value: ";
  153.             cin >> chiSqrdRight;
  154.             cout << "Enter chi-sqaured left value: ";
  155.             cin >> chiSqrdLeft;
  156.             cout << "Enter sample variance: ";
  157.             cin >> variance;
  158.             cout << "Enter sample size: ";
  159.             cin >> n;
  160.             chiSqrdInt(chiSqrdRight, chiSqrdLeft, variance, n);
  161.         }
  162.  
  163.         else if (menuLoopChoice == "8")
  164.         {
  165.             cout << "Enter mean of differences: ";
  166.             cin >> DBar;
  167.             cout << "Enter standard deviation of differences: ";
  168.             cin >> SD;
  169.             cout << "Enter number of matched pairs: ";
  170.             cin >> n;
  171.             cout << "Enter t-score: ";
  172.             cin >> t;
  173.             matchedPairsTInt(DBar, SD, n, t);
  174.         }
  175.  
  176.         else if (menuLoopChoice == "A" || menuLoopChoice == "a")
  177.         {
  178.             cout << "Enter population mean: ";
  179.             cin >> mean1;
  180.             cout << "Enter sample mean: ";
  181.             cin >> mean2;
  182.             cout << "Enter population standard deviation: ";
  183.             cin >> stDev;
  184.             cout << "Enter size of sample: ";
  185.             cin >> n;
  186.             cout << "Enter z-score: ";
  187.             cin >> z;
  188.             oneSampZTest(mean1, mean2, stDev, n, z);
  189.         }
  190.  
  191.         else if (menuLoopChoice == "B" || menuLoopChoice == "b")
  192.         {
  193.             cout << "Enter mean of sample one: ";
  194.             cin >> mean1;
  195.             cout << "Enter mean of sample two: ";
  196.             cin >> mean2;
  197.             cout << "Enter standard deviation of population one: ";
  198.             cin >> stDev1;
  199.             cout << "Enter standard deviation of population two: ";
  200.             cin >> stDev2;
  201.             cout << "Enter size of sample one: ";
  202.             cin >> n1;
  203.             cout << "Enter size of sample two: ";
  204.             cin >> n2;
  205.             cout << "Enter z-score: ";
  206.             cin >> z;
  207.             twoSampZTest(mean1, mean2, stDev1, stDev2, n1, n2, z);
  208.         }
  209.  
  210.         else if (menuLoopChoice == "C" || menuLoopChoice == "c")
  211.         {
  212.             cout << "Enter population mean: ";
  213.             cin >> mean1;
  214.             cout << "Enter sample mean: ";
  215.             cin >> mean2;
  216.             cout << "Enter sample standard deviation: ";
  217.             cin >> stDev;
  218.             cout << "Enter size of sample: ";
  219.             cin >> n;
  220.             cout << "Enter t-score: ";
  221.             cin >> t;
  222.             oneSamptTest(mean1, mean2, stDev, n, z);
  223.         }
  224.  
  225.         else if (menuLoopChoice == "D" || menuLoopChoice == "d")
  226.         {
  227.             cout << "Enter mean of sample one: ";
  228.             cin >> mean1;
  229.             cout << "Enter mean of sample two: ";
  230.             cin >> mean2;
  231.             cout << "Enter standard deviation of sample one: ";
  232.             cin >> stDev1;
  233.             cout << "Enter standard deviation of sample two: ";
  234.             cin >> stDev2;
  235.             cout << "Enter size of sample one: ";
  236.             cin >> n1;
  237.             cout << "Enter size of sample two: ";
  238.             cin >> n2;
  239.             cout << "Enter t-score: ";
  240.             cin >> t;
  241.             twoSamptTest(mean1, mean2, stDev1, stDev2, n1, n2, t);
  242.         }
  243.  
  244.         else if (menuLoopChoice == "E" || menuLoopChoice == "e")
  245.         {
  246.             cout << "Enter the population proportion: ";
  247.             cin >> p1;
  248.             cout << "Enter the sample proportion: ";
  249.             cin >> p2;
  250.             cout << "Enter the sample size: ";
  251.             cin >> n;
  252.             cout << "Enter the z-score: ";
  253.             cin >> z;
  254.             onePropZTest(p1, p2, n, z);
  255.         }
  256.  
  257.         else if (menuLoopChoice == "F" || menuLoopChoice == "f")
  258.         {
  259.             cout << "Enter sample proportion one: ";
  260.             cin >> p1;
  261.             cout << "Enter sample proportion two: ";
  262.             cin >> p2;
  263.             cout << "Enter the x value of proportion one: ";
  264.             cin >> x1;
  265.             cout << "Enter the x value of proportion two: ";
  266.             cin >> x2;
  267.             cout << "Enter the size of sample one: ";
  268.             cin >> n1;
  269.             cout << "Enter the size of sample two: ";
  270.             cin >> n2;
  271.             cout << "Enter the z-score: ";
  272.             cin >> z;
  273.             twoPropZTest(p1, p2, x1, x2, n1, n2, z);
  274.         }
  275.  
  276.         else if (menuLoopChoice == "q" || menuLoopChoice == "Q")
  277.         {
  278.             runUserInputLoop = false;
  279.         }
  280.     }
  281.    
  282.     system("pause");
  283.  
  284.     return 0;
  285.  
  286. }//end of main
  287.  
  288.  /////////////////////////////////////////////////////////////////////////Function Definitions/////////////////////////////////////////////////////////////////////////
  289. void displayASCII()
  290. {
  291.     cout << "  ____________________________________  " << endl;
  292.     cout << " /   _____/\\__    ___/  _  \\__    ___/  " << endl;
  293.     cout << " \\_____  \\   |    | /  /_\\  \\|    |     " << endl;
  294.     cout << " /        \\  |    |/    |    \\    |     " << endl;
  295.     cout << "/_______  /  |____|\\____|__  /____|     " << endl;
  296.     cout << "        \\/                 \\/           " << endl;
  297.     cout << "_________     _____  .____   _________  " << endl;
  298.     cout << "\\_   ___ \\   /  _  \\ |    |  \\_   ___ \\ " << endl;
  299.     cout << "/    \\  \\/  /  /_\\  \\|    |  /    \\  \\/ " << endl;
  300.     cout << "\\     \\____/    |    \\    |__\\     \\____" << endl;
  301.     cout << " \\______  /\\____|__  /_______ \\______  /" << endl;
  302.     cout << "        \\/         \\/        \\/      \\/ " << endl;
  303. }
  304.  
  305. void displayMenu()
  306. {
  307.     cout << endl << "-----------------------------------------------" << endl;
  308.     cout << "Confidence Intervals" << endl;
  309.     cout << "-----------------------------------------------" << endl;
  310.     cout << "1  |  One Sample Z Interval" << endl;
  311.     cout << "2  |  One Sample t Interval" << endl;
  312.     cout << "3  |  Two Sample Z interval (independent means)" << endl;
  313.     cout << "4  |  Two Sample t Interval (independent means)" << endl;
  314.     cout << "5  |  One Proportional Z Interval" << endl;
  315.     cout << "6  |  Two Proportional Z Interval" << endl;
  316.     cout << "7  |  Chi-sqaured Interval" << endl;
  317.     cout << "8  |  Matched Pairs Interval" << endl;
  318.     cout << "-----------------------------------------------" << endl;
  319.     cout << "Hypothesis Tests" << endl;
  320.     cout << "-----------------------------------------------" << endl;
  321.     cout << "A  |  One Sample Z Test" << endl;
  322.     cout << "B  |  Two Sample Z Test" << endl;
  323.     cout << "C  |  One Sample T Test" << endl;
  324.     cout << "D  |  Two Sample T Test" << endl;
  325.     cout << "E  |  One Proportional Z Test" << endl;
  326.     cout << "F  |  Two Proportional Z Test" << endl;
  327.     cout << "q  |  QUIT" << endl;
  328. }
  329.  
  330.  
  331. /////////////////////////////////////////////////////////////////////////Confidence Intervals/////////////////////////////////////////////////////////////////////////
  332. void oneSampZInt(double mean, double z, double stdDev, int n)
  333. {
  334.     double leftBound = 0.0;                 //Left boundary of confidence interval
  335.     double rightBound = 0.0;                //Right boundary of confidence interval
  336.  
  337.     leftBound = mean - (z * (stdDev / sqrt(n)));
  338.     rightBound = mean + (z * (stdDev / sqrt(n)));
  339.  
  340.     cout << "=============================================" << endl;
  341.     cout << leftBound << " < population mean < " << rightBound << endl;
  342.     system("pause");
  343. }// end of one sample z-interval
  344.  
  345. void oneSampTInt(double mean, double t, double stdDev, int n)
  346. {
  347.     double leftBound = 0.0;                 //Left boundary of confidence interval
  348.     double rightBound = 0.0;                //Right boundary of confidence interval
  349.  
  350.     leftBound = mean - (t * (stdDev / sqrt(n)));
  351.     rightBound = mean + (t * (stdDev / sqrt(n)));
  352.  
  353.     cout << "=============================================" << endl;
  354.     cout << leftBound << " < population mean < " << rightBound << endl;
  355.     system("pause");
  356. }// end of one sample t-interval
  357.  
  358. void chiSqrdInt(double chiSqrdRight, double chiSqrdLeft, double variance, int n)
  359. {
  360.     double leftBound = 0.0;                 //Left boundary of confidence interval
  361.     double rightBound = 0.0;                //Right boundary of confidence interval
  362.     double dividend = 0.0;                  //Dividend for calculating confidence interval
  363.  
  364.     dividend = variance * (n - 1);
  365.  
  366.     leftBound = dividend / chiSqrdRight;
  367.     rightBound = dividend / chiSqrdLeft;
  368.  
  369.     cout << "=============================================" << endl;
  370.     cout << "(" << leftBound << " < population variance < " << rightBound << ")" << endl;
  371.     system("pause");
  372. }//end of chi-sqaured interval
  373.  
  374. void indepMeansZInt(double meanOne, double meanTwo, double stDevOne, double stDevTwo, int n1, int n2, double z)
  375. {
  376.     double leftBound = 0.0;                 //Left boundary of confidence interval
  377.     double rightBound = 0.0;                //Right boundary of confidence interval
  378.     double addendMinuend = 0.0;             //Used to store addend/ minuend for calculating confindence interval
  379.     double radicand = 0.0;                  //Used to store radicand for calculating confidence interval
  380.     double addendSubtrahend = 0.0;          //Used to store the addend/ subtrahend for calculating confidence interval
  381.  
  382.     addendMinuend = meanOne - meanTwo;
  383.     radicand = sqrt((pow(stDevOne,2) / n1) + (pow(stDevTwo,2) / n2));
  384.     addendSubtrahend = z * radicand;
  385.  
  386.     leftBound = addendMinuend - addendSubtrahend;
  387.     rightBound = addendMinuend + addendSubtrahend;
  388.  
  389.     cout << "=============================================" << endl;
  390.     cout << leftBound << " < difference in means < " << rightBound << endl;
  391.     system("pause");
  392. }//end of independent means z-interval
  393.  
  394. void indepMeansTInt(double meanOne, double meanTwo, double stDevOne, double stDevTwo, int n1, int n2, double t)
  395. {
  396.     double leftBound = 0.0;                 //Left boundary of confidence interval
  397.     double rightBound = 0.0;                //Right boundary of confidence interval
  398.     double addendMinuend = 0.0;             //Used to store addend/ minuend for calculating confindence interval
  399.     double radicand = 0.0;                  //Used to store radicand for calculating confidence interval
  400.     double addendSubtrahend = 0.0;          //Used to store the addend/ subtrahend for calculating confidence interval
  401.  
  402.     addendMinuend = meanOne - meanTwo;
  403.     radicand = sqrt((pow(stDevOne, 2) / n1) + (pow(stDevTwo, 2) / n2));
  404.     addendSubtrahend = t * radicand;
  405.  
  406.     leftBound = addendMinuend - addendSubtrahend;
  407.     rightBound = addendMinuend + addendSubtrahend;
  408.  
  409.     cout << "=============================================" << endl;
  410.     cout << "(" << leftBound << " < difference in means < " << rightBound << ")" << endl;
  411.     system("pause");
  412. }//end of independent means t-interval
  413.  
  414. void matchedPairsTInt(double DBar, double SD, int n, double t)
  415. {
  416.     double leftBound = 0.0;                 //Left boundary of confidence interval
  417.     double rightBound = 0.0;                //Right boundary of confidence interval
  418.     double addendSubtrahend = 0.0;          //Used to store addend/ subtrahend
  419.  
  420.     addendSubtrahend = t * (SD / sqrt(n));
  421.  
  422.     leftBound = DBar - addendSubtrahend;
  423.     rightBound = DBar + addendSubtrahend;
  424.  
  425.     cout << "=============================================" << endl;
  426.     cout << "(" << leftBound << " < mean difference < " << rightBound << ")" << endl;
  427.     system("pause");
  428. }//end of matched pairs t-interval
  429.  
  430. void twoPropZInt(double p1, double p2, int n1, int n2, double z)
  431. {
  432.     double leftBound = 0.0;                 //Left boundary of confidence interval
  433.     double rightBound = 0.0;                //Right boundary of confidence interval
  434.     double addendMinuend = 0.0;             //Used to store addend/ minuend for calculating confindence interval
  435.     double addendSubtrahend = 0.0;          //Used to store addend/ subtrahend
  436.  
  437.     addendMinuend = p1 - p2;
  438.     addendSubtrahend = z * sqrt(((p1 * (1 - p1)) / n1) + ((p2 * (1 - p2)) / n2));
  439.  
  440.     leftBound = addendMinuend - addendSubtrahend;
  441.     rightBound = addendMinuend + addendSubtrahend;
  442.  
  443.     cout << "=============================================" << endl;
  444.     cout << "(" << leftBound << " < difference between the two population proportions < " << rightBound << ")" << endl;
  445.     system("pause");
  446. }//end of two proportional z interval
  447.  
  448. void onePropZInt(double p, double n, double z)
  449. {
  450.     double leftBound = 0.0;                 //Left boundary of confidence interval
  451.     double rightBound = 0.0;                //Right boundary of confidence interval
  452.     double addendSubtrahend = 0.0;          //Used to store addend/ subtrahend
  453.  
  454.     addendSubtrahend = z * sqrt((p * (1 - p)) / n);
  455.  
  456.     leftBound = p - addendSubtrahend;
  457.     rightBound = p + addendSubtrahend;
  458.  
  459.     cout << "=============================================" << endl;
  460.     cout << "(" << leftBound << " < population proportion < " << rightBound << ")" << endl;
  461.     system("pause");
  462. }//end of one proportional z interval
  463.  
  464.  
  465. /////////////////////////////////////////////////////////////////////////Hypothesis tests/////////////////////////////////////////////////////////////////////////
  466. void oneSampZTest(double popMean, double sampMean, double popStDev, int n, double Z)
  467. {
  468.     string subMenuChoice;                   //Used to store user's choice from the submenu
  469.     double testStat = 0.0;                  //Used to store test statistic
  470.  
  471.     cout << "==============================================" << endl;
  472.     cout << "Null Hypothesis: population mean = sample mean" << endl;
  473.     cout << "------------------------------------------------" << endl;
  474.     cout << "1  |  population mean (not equal to) sample mean" << endl;
  475.     cout << "2  |  population mean (<) sample mean" << endl;
  476.     cout << "3  |  population mean (>) sample mean" << endl;
  477.     cout << "r  |  return to main menu" << endl;
  478.     cout << "------------------------------------------------" << endl << endl;
  479.  
  480.     cout << endl << "Enter the number that corresponds with the proper Alternative Hypothesis from the menu: ";
  481.     getline(cin, subMenuChoice);
  482.  
  483.     testStat = ((sampMean - popMean) / (popStDev / sqrt(n)));
  484.  
  485.     if (subMenuChoice == "1")
  486.     {
  487.         if (testStat < (-1 * Z) || testStat >(Z))
  488.         {
  489.             cout << "=============================================" << endl;
  490.             cout << "Test statistic in rejection region" << endl;
  491.             cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
  492.         }
  493.         else
  494.         {
  495.             cout << "=============================================" << endl;
  496.             cout << "Test statistic not in rejection region" << endl;
  497.             cout << "DO NOT reject the Null Hypothesis" << endl;
  498.         }
  499.     }
  500.  
  501.     else if (subMenuChoice == "2")
  502.     {
  503.         if (testStat < (-1 * Z))
  504.         {
  505.             cout << "=============================================" << endl;
  506.             cout << "Test statistic in rejection region" << endl;
  507.             cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
  508.         }
  509.         else
  510.         {
  511.             cout << "=============================================" << endl;
  512.             cout << "Test statistic not in rejection region" << endl;
  513.             cout << "DO NOT reject the Null Hypothesis" << endl;
  514.         }
  515.     }
  516.     else if (subMenuChoice == "3")
  517.     {
  518.         if (testStat > Z)
  519.         {
  520.             cout << "=============================================" << endl;
  521.             cout << "Test statistic in rejection region" << endl;
  522.             cout << "Reject the Null Hypothesis in support of Alternative Hypothesis" << endl;
  523.         }
  524.         else
  525.         {
  526.             cout << "=============================================" << endl;
  527.             cout << "Test statistic not in rejection region" << endl;
  528.             cout << "DO NOT reject the Null Hypothesis" << endl;
  529.         }
  530.     }
  531.     else if (subMenuChoice == "r" || subMenuChoice == "R")
  532.     {
  533.         cout << "Main Menu" << endl;
  534.     }
  535.  
  536.     else
  537.     {
  538.         oneSampZTest(popMean, sampMean, popStDev, n, Z);
  539.     }
  540. }//end of one sample z test
  541.  
  542. void oneSamptTest(double popMean, double sampMean, double sampStDev, int n, double t)
  543. {
  544.     string subMenuChoice;                   //Used to store user's choice from the submenu
  545.     double testStat = 0.0;                  //Used to store test statistic
  546.  
  547.     cout << "==============================================" << endl;
  548.     cout << "Null Hypothesis: population mean = sample mean" << endl;
  549.     cout << "------------------------------------------------" << endl;
  550.     cout << "1  |  population mean (not equal to) sample mean" << endl;
  551.     cout << "2  |  population mean (<) sample mean" << endl;
  552.     cout << "3  |  population mean (>) sample mean" << endl;
  553.     cout << "r  |  return to main menu" << endl;
  554.     cout << "------------------------------------------------" << endl << endl;
  555.  
  556.     cout << endl << "Enter the number that corresponds with the proper Alternative Hypothesis from the menu: ";
  557.     getline(cin, subMenuChoice);
  558.  
  559.     testStat = ((sampMean - popMean) / (sampStDev / sqrt(n)));
  560.  
  561.     if (subMenuChoice == "1")
  562.     {
  563.         if (testStat < (-1 * t) || testStat >(t))
  564.         {
  565.             cout << "=============================================" << endl;
  566.             cout << "Test statistic in rejection region" << endl;
  567.             cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
  568.         }
  569.         else
  570.         {
  571.             cout << "=============================================" << endl;
  572.             cout << "Test statistic not in rejection region" << endl;
  573.             cout << "DO NOT reject the Null Hypothesis" << endl;
  574.         }
  575.     }
  576.  
  577.     else if (subMenuChoice == "2")
  578.     {
  579.         if (testStat < (-1 * t))
  580.         {
  581.             cout << "=============================================" << endl;
  582.             cout << "Test statistic in rejection region" << endl;
  583.             cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
  584.         }
  585.         else
  586.         {
  587.             cout << "=============================================" << endl;
  588.             cout << "Test statistic not in rejection region" << endl;
  589.             cout << "DO NOT reject the Null Hypothesis" << endl;
  590.         }
  591.     }
  592.     else if (subMenuChoice == "3")
  593.     {
  594.         if (testStat > t)
  595.         {
  596.             cout << "=============================================" << endl;
  597.             cout << "Test statistic in rejection region" << endl;
  598.             cout << "Reject the Null Hypothesis in support of Alternative Hypothesis" << endl;
  599.         }
  600.         else
  601.         {
  602.             cout << "=============================================" << endl;
  603.             cout << "Test statistic not in rejection region" << endl;
  604.             cout << "DO NOT reject the Null Hypothesis" << endl;
  605.         }
  606.     }
  607.     else if (subMenuChoice == "r" || subMenuChoice == "R")
  608.     {
  609.         cout << "Main Menu" << endl;
  610.     }
  611.  
  612.     else
  613.     {
  614.         oneSamptTest(popMean, sampMean, sampStDev, n, t);
  615.     }
  616. }//end of one sample t test
  617.  
  618. void twoSampZTest(double sampMeanOne, double sampMeanTwo, double popStDevOne, double popStDevTwo, int nOne, int nTwo, double Z)
  619. {
  620.     string subMenuChoice;                   //Used to store user's choice from the submenu
  621.     double testStat = 0.0;                  //Used to store test statistic
  622.  
  623.     cout << "==========================================================" << endl;
  624.     cout << "Null Hypothesis: population mean one = population mean two" << endl;
  625.     cout << "------------------------------------------------" << endl;
  626.     cout << "1  |  population mean one (not equal to) population mean two" << endl;
  627.     cout << "2  |  population mean one (<) population mean two" << endl;
  628.     cout << "3  |  population mean one (>) population mean two" << endl;
  629.     cout << "r  |  return to main menu" << endl;
  630.     cout << "------------------------------------------------" << endl << endl;
  631.  
  632.     cout << endl << "Enter the number that corresponds with the proper Alternative Hypothesis from the menu: ";
  633.     getline(cin, subMenuChoice);
  634.  
  635.     testStat = ((sampMeanOne - sampMeanTwo) / sqrt((pow(popStDevOne, 2) / nOne) + (pow(popStDevTwo, 2) / nTwo)));
  636.  
  637.     if (subMenuChoice == "1")
  638.     {
  639.         if (testStat < (-1 * Z) || testStat >(Z))
  640.         {
  641.             cout << "=============================================" << endl;
  642.             cout << "Test statistic in rejection region" << endl;
  643.             cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
  644.         }
  645.         else
  646.         {
  647.             cout << "=============================================" << endl;
  648.             cout << "Test statistic not in rejection region" << endl;
  649.             cout << "DO NOT reject the Null Hypothesis" << endl;
  650.         }
  651.     }
  652.  
  653.     else if (subMenuChoice == "2")
  654.     {
  655.         if (testStat < (-1 * Z))
  656.         {
  657.             cout << "=============================================" << endl;
  658.             cout << "Test statistic in rejection region" << endl;
  659.             cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
  660.         }
  661.         else
  662.         {
  663.             cout << "=============================================" << endl;
  664.             cout << "Test statistic not in rejection region" << endl;
  665.             cout << "DO NOT reject the Null Hypothesis" << endl;
  666.         }
  667.     }
  668.     else if (subMenuChoice == "3")
  669.     {
  670.         if (testStat > Z)
  671.         {
  672.             cout << "=============================================" << endl;
  673.             cout << "Test statistic in rejection region" << endl;
  674.             cout << "Reject the Null Hypothesis in support of Alternative Hypothesis" << endl;
  675.         }
  676.         else
  677.         {
  678.             cout << "=============================================" << endl;
  679.             cout << "Test statistic not in rejection region" << endl;
  680.             cout << "DO NOT reject the Null Hypothesis" << endl;
  681.         }
  682.     }
  683.     else if (subMenuChoice == "r" || subMenuChoice == "R")
  684.     {
  685.         cout << "Main Menu" << endl;
  686.     }
  687.  
  688.     else
  689.     {
  690.         twoSampZTest(sampMeanOne, sampMeanTwo, popStDevOne, popStDevTwo, nOne, nTwo, Z);
  691.     }
  692. }//end of two sample z test
  693.  
  694. void twoSamptTest(double sampMeanOne, double sampMeanTwo, double sampStDevOne, double sampStDevTwo, int nOne, int nTwo, double t)
  695. {
  696.     string subMenuChoice;                   //Used to store user's choice from the submenu
  697.     double testStat = 0.0;                  //Used to store test statistic
  698.  
  699.     cout << "==========================================================" << endl;
  700.     cout << "Null Hypothesis: population mean one = population mean two" << endl;
  701.     cout << "------------------------------------------------" << endl;
  702.     cout << "1  |  population mean one (not equal to) population mean two" << endl;
  703.     cout << "2  |  population mean one (<) population mean two" << endl;
  704.     cout << "3  |  population mean one (>) population mean two" << endl;
  705.     cout << "r  |  return to main menu" << endl;
  706.     cout << "------------------------------------------------" << endl << endl;
  707.  
  708.     cout << endl << "Enter the number that corresponds with the proper Alternative Hypothesis from the menu: ";
  709.     getline(cin, subMenuChoice);
  710.  
  711.     testStat = ((sampMeanOne - sampMeanTwo) / sqrt((pow(sampStDevOne, 2) / nOne) + (pow(sampStDevTwo, 2) / nTwo)));
  712.  
  713.     if (subMenuChoice == "1")
  714.     {
  715.         if (testStat < (-1 * t) || testStat >(t))
  716.         {
  717.             cout << "=============================================" << endl;
  718.             cout << "Test statistic in rejection region" << endl;
  719.             cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
  720.         }
  721.         else
  722.         {
  723.             cout << "=============================================" << endl;
  724.             cout << "Test statistic not in rejection region" << endl;
  725.             cout << "DO NOT reject the Null Hypothesis" << endl;
  726.         }
  727.     }
  728.  
  729.     else if (subMenuChoice == "2")
  730.     {
  731.         if (testStat < (-1 * t))
  732.         {
  733.             cout << "=============================================" << endl;
  734.             cout << "Test statistic in rejection region" << endl;
  735.             cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
  736.         }
  737.         else
  738.         {
  739.             cout << "=============================================" << endl;
  740.             cout << "Test statistic not in rejection region" << endl;
  741.             cout << "DO NOT reject the Null Hypothesis" << endl;
  742.         }
  743.     }
  744.     else if (subMenuChoice == "3")
  745.     {
  746.         if (testStat > t)
  747.         {
  748.             cout << "=============================================" << endl;
  749.             cout << "Test statistic in rejection region" << endl;
  750.             cout << "Reject the Null Hypothesis in support of Alternative Hypothesis" << endl;
  751.         }
  752.         else
  753.         {
  754.             cout << "=============================================" << endl;
  755.             cout << "Test statistic not in rejection region" << endl;
  756.             cout << "DO NOT reject the Null Hypothesis" << endl;
  757.         }
  758.     }
  759.     else if (subMenuChoice == "r" || subMenuChoice == "R")
  760.     {
  761.         cout << "Main Menu" << endl;
  762.     }
  763.  
  764.     else
  765.     {
  766.         twoSamptTest(sampMeanOne, sampMeanTwo, sampStDevOne, sampStDevTwo, nOne, nTwo, t);
  767.     }
  768. }//end of two sample t test
  769.  
  770. void onePropZTest(double popProp, double sampProp, int n, double Z)
  771. {
  772.     string subMenuChoice;                   //Used to store user's choice from the submenu
  773.     double testStat = 0.0;                  //Used to store test statistic
  774.  
  775.     cout << "==========================================================" << endl;
  776.     cout << "Null Hypothesis: population proportion = sample proportion" << endl;
  777.     cout << "------------------------------------------------" << endl;
  778.     cout << "1  |  population proportion (not equal to) sample proportion" << endl;
  779.     cout << "2  |  population proportion (<) sample proportion" << endl;
  780.     cout << "3  |  population proportion (>) sample proportion" << endl;
  781.     cout << "r  |  return to main menu" << endl;
  782.     cout << "------------------------------------------------" << endl << endl;
  783.  
  784.     cout << endl << "Enter the number that corresponds with the proper Alternative Hypothesis from the menu: ";
  785.     getline(cin, subMenuChoice);
  786.  
  787.     testStat = ((sampProp - popProp) / sqrt((popProp * (1-popProp)) / n));
  788.  
  789.     if (subMenuChoice == "1")
  790.     {
  791.         if (testStat < (-1 * Z) || testStat > (Z))
  792.         {
  793.             cout << "=============================================" << endl;
  794.             cout << "Test statistic in rejection region" << endl;
  795.             cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
  796.         }
  797.         else
  798.         {
  799.             cout << "=============================================" << endl;
  800.             cout << "Test statistic not in rejection region" << endl;
  801.             cout << "DO NOT reject the Null Hypothesis" << endl;
  802.         }
  803.     }
  804.  
  805.     else if (subMenuChoice == "2")
  806.     {
  807.         if (testStat < (-1 * Z))
  808.         {
  809.             cout << "=============================================" << endl;
  810.             cout << "Test statistic in rejection region" << endl;
  811.             cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
  812.         }
  813.         else
  814.         {
  815.             cout << "=============================================" << endl;
  816.             cout << "Test statistic not in rejection region" << endl;
  817.             cout << "DO NOT reject the Null Hypothesis" << endl;
  818.         }
  819.     }
  820.     else if (subMenuChoice == "3")
  821.     {
  822.         if (testStat > Z)
  823.         {
  824.             cout << "=============================================" << endl;
  825.             cout << "Test statistic in rejection region" << endl;
  826.             cout << "Reject the Null Hypothesis in support of Alternative Hypothesis" << endl;
  827.         }
  828.         else
  829.         {
  830.             cout << "=============================================" << endl;
  831.             cout << "Test statistic not in rejection region" << endl;
  832.             cout << "DO NOT reject the Null Hypothesis" << endl;
  833.         }
  834.     }
  835.     else if (subMenuChoice == "r" || subMenuChoice == "R")
  836.     {
  837.         cout << "Main Menu" << endl;
  838.     }
  839.  
  840.     else
  841.     {
  842.         onePropZTest(popProp, sampProp, n, Z);
  843.     }
  844. }//end of one prop z test
  845.  
  846. void twoPropZTest(double sampPropOne, double sampPropTwo, int xOne, int xTwo, int nOne, int nTwo, double Z)
  847. {
  848.     string subMenuChoice;                   //Used to store user's choice from the submenu
  849.     double testStat = 0.0;                  //Used to store test statistic
  850.     double pHat = 0.0;                      //Used to store p-hat
  851.  
  852.     cout << "======================================================================" << endl;
  853.     cout << "Null Hypothesis: population proportion one = population proportion two" << endl;
  854.     cout << "------------------------------------------------" << endl;
  855.     cout << "1  |  population proportion one (not equal to) population proportion two" << endl;
  856.     cout << "2  |  population proportion one (<) population proportion two" << endl;
  857.     cout << "3  |  population proportion one (>) population proportion two" << endl;
  858.     cout << "r  |  return to main menu" << endl;
  859.     cout << "------------------------------------------------" << endl << endl;
  860.  
  861.     cout << endl << "Enter the number that corresponds with the proper Alternative Hypothesis from the menu: ";
  862.     getline(cin, subMenuChoice);
  863.  
  864.     pHat = (xOne + xTwo) / (nOne + nTwo);
  865.     testStat = ((sampPropOne - sampPropTwo) / sqrt(pHat * (1 - pHat) * ((1 / nOne) + (1 / nTwo))));
  866.  
  867.     if (subMenuChoice == "1")
  868.     {
  869.         if (testStat < (-1 * Z) || testStat >(Z))
  870.         {
  871.             cout << "=============================================" << endl;
  872.             cout << "Test statistic in rejection region" << endl;
  873.             cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
  874.         }
  875.         else
  876.         {
  877.             cout << "=============================================" << endl;
  878.             cout << "Test statistic not in rejection region" << endl;
  879.             cout << "DO NOT reject the Null Hypothesis" << endl;
  880.         }
  881.     }
  882.  
  883.     else if (subMenuChoice == "2")
  884.     {
  885.         if (testStat < (-1 * Z))
  886.         {
  887.             cout << "=============================================" << endl;
  888.             cout << "Test statistic in rejection region" << endl;
  889.             cout << "Reject Null Hypothesis in support of Alternative Hypothesis" << endl;
  890.         }
  891.         else
  892.         {
  893.             cout << "=============================================" << endl;
  894.             cout << "Test statistic not in rejection region" << endl;
  895.             cout << "DO NOT reject the Null Hypothesis" << endl;
  896.         }
  897.     }
  898.     else if (subMenuChoice == "3")
  899.     {
  900.         if (testStat > Z)
  901.         {
  902.             cout << "=============================================" << endl;
  903.             cout << "Test statistic in rejection region" << endl;
  904.             cout << "Reject the Null Hypothesis in support of Alternative Hypothesis" << endl;
  905.         }
  906.         else
  907.         {
  908.             cout << "=============================================" << endl;
  909.             cout << "Test statistic not in rejection region" << endl;
  910.             cout << "DO NOT reject the Null Hypothesis" << endl;
  911.         }
  912.     }
  913.     else if (subMenuChoice == "r" || subMenuChoice == "R")
  914.     {
  915.         cout << "Main Menu" << endl;
  916.     }
  917.  
  918.     else
  919.     {
  920.         twoPropZTest(sampPropOne, sampPropTwo, xOne, xTwo, nOne, nTwo, Z);
  921.     }
  922. }//end of one prop z test
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement