0% found this document useful (0 votes)
5 views2 pages

Smisexpt 4

The document is a C++ program that calculates the Chi-square statistic based on user-input observed and expected frequencies. It prompts the user for the number of terms, collects the frequencies, computes the Chi-square value, and compares it to a critical value to determine whether to accept or reject the null hypothesis. The program utilizes a vector of pairs to store the frequencies and includes necessary libraries for input/output and mathematical functions.

Uploaded by

Aashva Salelkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Smisexpt 4

The document is a C++ program that calculates the Chi-square statistic based on user-input observed and expected frequencies. It prompts the user for the number of terms, collects the frequencies, computes the Chi-square value, and compares it to a critical value to determine whether to accept or reject the null hypothesis. The program utilizes a vector of pairs to store the frequencies and includes necessary libraries for input/output and mathematical functions.

Uploaded by

Aashva Salelkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#include <vector>
#include <cmath> // For pow()
using namespace std;
int main() {
int n;
vector<pair<int, double> > data; // Changed expected frequency to double
// Input the number of terms
cout << "Enter the number of terms: ";
cin >> n;

// Input observed and expected frequencies


for (int i = 0; i < n; ++i) {
int ob;
double ex; // Expected frequency is now a double
cout << "Enter the observed frequency " << i + 1 << ": ";
cin >> ob;
cout << "Enter the expected frequency " << i + 1 << ": ";
cin >> ex;
data.push_back(make_pair(ob, ex));
}

// Display the items


cout << "Items: ";
for (size_t i = 0; i < data.size(); ++i) {
cout << "(" << data[i].first << ", " << data[i].second << ") ";
}
cout << endl;

// Calculate the Chi-square value


double chi = 0;
for (size_t i = 0; i < data.size(); ++i) {
int o = data[i].first;
double e = data[i].second;
chi += pow(o - e, 2) / e;
}

cout << "Calculated Chi-square: " << chi << endl;

// Input critical value


double critical_value;
cout << "Enter the critical value for chi-square test: ";
cin >> critical_value;

// Check if we reject or accept the null hypothesis


if (chi > critical_value) {
cout << "Reject the null hypothesis" << endl;
} else {
cout << "Accept the null hypothesis" << endl;
}
return 0; }

You might also like