Skip to main content

Exp 10

 10. Write a program to calculate chi-square value using Python. Report your observation.

import math

a=[[ 250,200],

   [50,1000]]

print("Elements in dataset a are:\n");

for i in a:

    for j in i:

        print(j,end = " ")

    print()

row1tot= a[0][0]+a[0][1];

row2tot=a[1][0]+a[1][1];

col1tot=a[0][0]+a[1][0];

col2tot=a[0][1]+a[1][1];


print("\nRow one total:",row1tot); 

print("\nRow two total:",row2tot) 

print("\nColumn one total:",col1tot); 

print("\n Column two total:",col2tot); 

totalValueallcolumns= col1tot+col2tot;

totalValueallrows= row1tot+row2tot;

print("\nTotal value of all columns:",totalValueallcolumns); 

print("\nTotal value of all rows:",totalValueallrows); 

e00= (col1tot*row1tot)/totalValueallcolumns;

e01= (col2tot*row1tot)/totalValueallcolumns;

e10= (col1tot*row2tot)/totalValueallcolumns;

e11= (col2tot*row2tot)/totalValueallcolumns;

print("\nExpected value of arr[0][0] position:",e00);

print("\nExpected value of arr[0][1] position:",e01);

print("\nExpected value of arr[1][0] position:",e10);

print("\nExpected value of arr[1][1] position:",e11);

#finding Chi square value

ChiSquareValue=(math.pow((a[0][0]-e00),2)/e00)+(math.pow((a[0][1]-e01),2)/e01)+(math.pow((a[1][0]-e10),2)/e10)+(math.pow((a[1][1]-e11),2)/e11);

print("\nChi square value is:",ChiSquareValue);


Comments

Popular posts from this blog

Data structures: Introduction to Trees

Tree: The data in a tree are not stored in a sequential manner i.e., they are not stored linearly. Instead, they are arranged on multiple levels or we can say it is a hierarchical structure. For this reason, the tree is considered to be a non-linear data structure. KeyConcepts : Nodes : Individual units within the tree, each storing data and potentially linking to other nodes. Edges : Connections between nodes, representing relationships (parent-child, sibling, etc.). Root : The topmost node in the tree, from which all other nodes originate. Parent : A node that has one or more child nodes. Child : A node connected to a parent node. Leaf : A node with no children. Subtree : A portion of a tree that is itself a tree. Representation of tree: Binary search tree :

Hashing and hash functions

Types of hash functions

Data structures dequeues