Pages

Tuesday, December 20, 2011

C++ code Hypothesis Testing


#include // for normal_distribution
using boost::math::normal; // typedef provides default type is double.

#include
using std::cout; using std::endl; using std::left; using std::showpoint; using std::noshowpoint;
#include
using std::setw; using std::setprecision;
#include
using std::numeric_limits;
#include

using namespace std;
int main()
{

int mean,std,pvalue;
int testchoice,conf;
int z=0;
cout << "\n\n\n Hypothesis Testing - Using Normal Distribution";

try
{
{
int precision = 17; // traditional tables are only computed to much lower precision.

normal s; // (default mean = zero, and standard deviation = unity)
cout.precision(5);
cout.precision(6); // default
cout <<"\n Enter the mean value of the Sample"<
cin>>mean;
cout << "\n Enter Std Deviation for Sample"<
cin>>std;
z=0;
z = mean/std;

cout<<" \n Please use the following menu to Enter the hypothesis you want to test"<
cout<<"\n 1. to validate if population mean is equal to sample mean"
"\n 2. to test if population mean is less than sample mean"
"\n 3. to find if population mean is more than sample mean"<
cin>>testchoice;
cout<<" Enter the confidence interval you want to test for"<
cout<< "\n 1. for 90% confidence interval"
"\n 2. for 95% confidence interval"
"\n 3. for 99% confidence interval"<
cin>>conf;
if( testchoice == 1 && conf ==1 )
{
if (pvalue < .05 or pvalue > .95)
cout <<" \n Null Hypothesis not rejected as there is not enough statistical evidence";
else
cout<<"\n Null Hypothesis rejected and Alternative Hypothesis accepted";
}
else if( testchoice == 1 && conf ==2 )
{
if (pvalue < .10)
cout <<" \n Null Hypothesis not rejected as there is not enough statistical evidence";
else
cout<<"\n Null Hypothesis rejected and Alternative Hypothesis accepted";
}
else if( testchoice == 1 && conf ==3 )
{ if (pvalue > .90)
cout <<" \n Null Hypothesis not rejected as there is not enough statistical evidence";
else
cout<<"\n Null Hypothesis rejected and Alternative Hypothesis accepted";
}
if( testchoice == 2 && conf ==1 )
{
if (pvalue < .025 or pvalue > .975)
cout <<" \n Null Hypothesis not rejected as there is not enough statistical evidence";
else
cout<<"\n Null Hypothesis rejected and Alternative Hypothesis accepted";
}
else if( testchoice == 2 && conf ==2 )
{
if (pvalue < .05 )
cout <<" \n Null Hypothesis not rejected as there is not enough statistical evidence";
else
cout<<"\n Null Hypothesis rejected and Alternative Hypothesis accepted";
}
else if( testchoice == 2 && conf ==3 )
{
if(pvalue > .95 )
cout <<" \n Null Hypothesis not rejected as there is not enough statistical evidence";
else
cout<<"\n Null Hypothesis rejected and Alternative Hypothesis accepted";
}
if( testchoice == 3 && conf ==1 )
{
if (pvalue < .005 or pvalue > .995)
cout <<" \n Null Hypothesis not rejected as there is not enough statistical evidence";
else
cout<<"\n Null Hypothesis rejected and Alternative Hypothesis accepted";
}
else if( testchoice == 3 && conf ==2 )
{
if (pvalue < .01)
cout <<" \n Null Hypothesis not rejected as there is not enough statistical evidence";
else
cout<<"\n Null Hypothesis rejected and Alternative Hypothesis accepted";
}
else if( testchoice == 3 && conf ==3 )
{
if (pvalue > .01 )
cout <<" \n Null Hypothesis not rejected as there is not enough statistical evidence";
else
cout<<"\n Null Hypothesis rejected and Alternative Hypothesis accepted";
}

cout<


}
}

catch(const std::exception& e)
{
std::cout <<
"\n""Message from thrown exception was:\n " << e.what() << std::endl;
}
return 0;

}

No comments:

Post a Comment