RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
COMPUTER ORIENTED STATISTICAL METHODS - LAB
LIST OF PROGRAMS
[Link] Name of Programs Page No Remarks
2
1. Baye’s theorem
4
2. Binominal distribution
6
3. Poission distribution
8
4. Normal distribution
10
5. Hypothesis testing: Small Samples
13
6. Hypothesis testing: Large Samples
15
7. Chi-square test
17
8. Correlation
19
9. Regression
21
10. One way – Analysis of variance
24
11. Two way – Analysis of variance
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
Exercise No: 1
Baye's Therom
Aim:
To implement the baye’s therome
Coding:
#include<stdio.h>
#include<conio.h>
int main()
{
float a,b,ax,bx,num1,num1,den,baye1,baye2;
clrscr();
printf("\nEnter the Pribability of Inputs : ");
scanf("%f%f%",&a,&b);
printf("\nEnter the Defective Probability Input : ");
scanf("%f%f",&ax,&bx);
num1=a*ax;
num2=b*bx;
den=a*ax+b*bx;
baye1=num1/den;
baye2=num2/den;
printf("\nThe Required Probabilty : %.4f",baye1);
printf("\nThe Required Probablity : %.4f",baye2);
getch();
return 0;
}
2
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
Output for Baye's Therome:
Enter the Pribability of Inputs : 0.3 0.7
Enter the Defective Probability Input : 0.05 0.01
The Required Probabilty : 0.6818
The Required Probabilty : 0.3182
Result:
Hence, the above program has been executed successfully.
3
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
Exercise No: 2
Binomial Distribution
Aim:
To implement the Binomial Distribution
Coding:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main(){
int n,i;
float fo[10],fe[10],x[10],sumfx=0,sumf=0,mean,p,q;
printf("enter the value of n:");
scanf("%d",&n);
printf("enter the x and f values:");
for(i=0;i<=n;i++){
scanf("%f",&x[i]);
scanf("%f",&fo[i]);
for(i=0;i<=n;i++){
sumfx=sumfx+fo[i]*x[i];
sumf=sumf+fo[i];
mean=sumfx/sumf;
p=mean/n;
q=1-p;
fe[0]=(sumf*pow(q,n));
for(i=1;i<=n;i++)
fe[i]=(fe[i-1]*(n-(i-1))/((i-1)+1)*(p/q));
4
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
for(i=0;i<=n;i++){
printf("%f\t%f\t%f\n",x[i],fo[i],fe[i]);
getch();
Output for Binomial Distribution
Enter the values of N: 5
Enter x and f:
01
13
25
37
4 10
59
0.000000 1.000000 0.117440
1.000000 3.000000 1.247805
2.000000 5.000000 5.303173
3.000000 7.000000 11.269243
4.000000 10.000000 11.973572
5.000000 9.000000 5.088768
Result:
Hence, the above program has been executed successfully.
Exercise No: 3
Poisson Distribution
5
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
Aim:
To implement the Poisson Distribution
Coding:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
int n,i;
float fo[10],fe[10],x[10],sumfx=0,sumf=0,lam;
printf("enter the values of n:");
scanf("%d",&n);
printf("enter the x and y values:");
for(i=0;i<=n;i++){
scanf("%f",&x[i]);
scanf("%f",&fo[i]);
for(i=0;i<=n;i++){
sumfx=sumfx+fo[i]*x[i];
sumf=sumf+fo[i];
lam=sumfx/sumf;
fe[0]=sumf*exp(-lam);
for(i=1;i<=n;i++){
fe[i]=(fe[i-1]*lam/((i-1)+1));
for(i=0;i<=n;i++)
printf("%f\t%f\t%f\n",x[i],fo[i],fe[i]);
getch();
6
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
Output for Poisson Distribution
Enter the values of N: 5
Enter x and f:
02
14
26
38
4 10
5 12
0.000000 2.000000 1.498308
1.000000 4.000000 4.994359
2.000000 6.000000 8.323933
3.000000 8.000000 9.248814
4.000000 10.000000 7.707345
5.000000 12.000000 5.138229
Result:
Hence, the above program has been executed successfully.
Exercise No: 4
Normal Distribution
Aim:
7
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
To implement the Normal Distribution
Coding:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int i;
float u,s,N,x1,math1,math2,math3,n,v,x;
printf("\nEnter Mean :");
scanf("%f",&u);
printf("Enter Standard Deviation :");
scanf("%f",&s);
printf("Enter Number of Inputs :");
scanf("%f",&n);
printf("\nEnter the Value :");
for(i=1;i<n;i++) {
scanf("%f",&x);
n=(-1/2);
printf("f(x) = ");
math1=1/(s*sqrt(2*M_PI));
math2=(x-u)/s*(x-u)/s;
math3=M_E*exp(n);
x1=math1*exp(math3)*exp(math2);
printf("%f\n",x1);
}
getch();
return 0;
}
8
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
Output for Normal Distribution
Enter Mean : 43.7
Enter Standard Deviation : 14.8
Enter Number of Inputs : 8
Enter the values: 12 28 40 60 32 20 8 10
F(x) = 40.141747
Result:
Hence, the above program has been executed successfully.
Exercise No: 5
Hypothesis Test - Small Sample
Aim:
To implement the Hypothesis Test - Small Sample
Coding:
9
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
float mu,mean,sd,n,sqnm1,num,den,ts,tv;
printf("\nTest the Hypopthesis Small Sample :\n");
printf("\nEnter the Population Mean : mu = ");
scanf("%f",&mu);
printf("\nEnter the Sample Mean : mean = ");
scanf("%f",&mean);
printf("\nEnter the Sample size (n<30) : n = ");
scanf("%f",&n);
printf("\nEnter the Standard Deviation : sd = ");
scanf("%f",&sd);
sqnm1=sqrt(n-1);
num=mean-mu;
den=sd/sqnm1;
ts=num/den;
if(ts>0){
ts=ts;
}
else{
ts=-ts;
}
printf("Test Statistics Value = ts = %.3f",ts);
printf("\nEnter the Table Value : tv =");
scanf("%f",&tv);
printf("\nH0 means Null Hypothesis :");
printf("\nH1 means Alternative Hypothesis : ");
10
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
if(ts>tv) {
printf("\nH0 is Rejeted:");
printf("\nH1 is Accepted:");
}
else {
printf("\nH0 is Accepted:");
printf("\nH1 is Rejected:");
}
getch();
return 0;
}
Output 1 for Hypothesis Test - Small Sample
Test the Hypothesis Small Sample :
Enter the Population Mean : mu = 5500
Enter the Sample Mean : mean = 6000
Enter the Sample Size(n<30) : n = 10
Enter the Standard Deviation: sd = 650
Test Statistic Value ts = 2.308
Enter the Table Value tv = 2.262
H0 means Null Hypothesis
H1 means Alternative Hypothesis
H0 is Rejected
H1 is Accepted
Output 2 for Hypothesis Test - Small Sample
11
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
Test the Hypothesis Small Sample :
Enter the Population Mean : mu = 14.5
Enter the Sample Mean : mean = 12.1
Enter the Sample Size(n<30) : n = 10
Enter the Standard Deviation: sd = 3.2
Test Statistic Value ts = 2.250
Enter the Table Value tv = 2.262
H0 means Null Hypothesis
H1 means Alternative Hypothesis
H0 is Accepted
H1 is Rejected
Result:
Hence, the above program has been executed successfully.
Exercise No: 6
Hypothesis Test – Large Sample
Aim:
To implement the Hypothesis Test – Large Sample
Coding:
#include<stdio.h>
12
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
#include<conio.h>
#include<math.h>
int main()
{
float mu,mean,sd,n,sqn,num,den,ts,tv;
printf("\nTest Hypothesis Large Sample :\n");
printf("\nEnter the Population Mean : mu = ");
scanf("%f",&mu);
printf("\nEnter the Sample Mean : mean = ");
scanf("%f",&mean);
printf("\nEnter the Sample size(n>30) : n = ");
scanf("%f",&n);
printf("\nEnter the Standard Deviation : sd = ");
scanf("%f",&sd);
sqn=sqrt(n);
num=mean-mu;
den=sd/sqn;
ts=num/den;
if(ts>0) {
ts=ts;
}
else {
ts=-ts;
}
printf("\nTest Statistic Value : ts = %.2f",ts);
printf("\nEnter the Table Value : tv = ");
scanf("%f",&tv);
printf("\n\nHo means Null Hypothesis :");
printf("\nH1 means Alternative Hypothesis :\n");
if(tv>ts) {
printf("\nH0 is Accepted:");
printf("\nH1 is Rejected:");
13
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
}
else {
printf("\nH0 is Rejected:");
printf("\nH1 is Accepted:");
}
getch();
return 0;
}
Output for Hypothesis Test – Large Sample
Test the Hypothesis Large Sample :
Enter the Population Mean : mu = 100
Enter the Sample Mean : mean = 99
Enter the Sample Size(n>30) : n = 1600
Enter the Standard Deviation : sd = 15
Test Statistic Value ts = 2.67
Enter the Table Value tv = 1.96
H0 means Null Hypothesis
H1 means Alternative Hypothesis
H0 is Rejected
H1 is Accepted
Result:
Hence, the above program has been executed successfully.
Exercise No: 7
Chi Square Test
Aim:
To implement the Chi Square Test
Coding:
14
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
int i,n;
float tv,of[10],ef[10],chisq=0;
printf("Enter how many Observed Frequency and Expected Frequency :");
scanf("%d",&n);
printf("\nEnter the Data :\n");
for(i=0;i<n;i++)
scanf("%f%f",&of[i],&ef[i]);
for(i=0;i<n;i++)
chisq=chisq+pow(of[i]-ef[i],2)/ef[i];
printf("Chi Sqaure Variable is %.2f\n\nEnter the Table Value :",chisq);
scanf("%f",&tv);
printf("\nThe Table Value is %.2f\n",tv);
if(chisq<tv)
printf("\nH0 is Accepted : \nH1 is Rejected :");
else
printf("\nH0 is Rejected : \nH1 is Accepted :");
getch();
return 0;
Output 1 for Chi Square Test
Enter how many Observed Frequency and Expected Frequency : 3
Enter the Data :
130 124
6 8
64 68
Chi Sqaure Variable is 1.03
15
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
Enter the Table Value :5.99
The Table Value is 5.99
H0 is Accepted :
H1 is Rejected :
Output 2 for Chi Square Test
Enter how many Observed Frequency and Expected Frequency :10
Enter the Data :
12 10
8 10
20 10
2 10
14 10
10 10
15 10
6 10
9 10
4 10
Chi Sqaure Variable is 26.60
Enter the Table Value :16.919
The Table Value is 16.92
H0 is Rejected :
H1 is Accepted :
Result:
Hence, the above program has been executed successfully.
Exercise No: 8
Correlation
Aim:
To implement the Correlation
Coding:
#include<stdio.h>
#include<conio.h>
int main(){
16
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
int N, i;
float x[10],y[10],sumx=0,sumy=0,sumxx=0,sumyy=0,sumxy=0,num,den1,den2,den,r;
printf("\nEnter How many Bi Variated Data :");
scanf("%d",&N);
printf("\nEnter the Data Clearly :");
for(i=0;i<N;i++) {
scanf("%f",&x[i]);
scanf("%f",&y[i]); }
for(i=0;i<N;i++) {
sumx=sumx+x[i];
sumy=sumy+y[i];
sumyy=sumyy+y[i]*y[i];
sumxx=sumxx+x[i]*x[i];
sumxy=sumxy+x[i]*y[i]; }
num=N*sumxy-sumx*sumy;
den1=sqrt(N*sumxx-sumx*sumx);
den2=sqrt(N*sumyy-sumy*sumy);
den=den1*den2;
r=num/den;
printf("\nCorrelation of given bi-variated Data : %.2f",r);
if(r>0)
printf("\nPositive Correlation Exist :");
else if(r<0)
printf("\nNegative Correlation Exist );
else
printf("\nNo Correlation Exist :");
getch();
return 0; }
Output 1 for Correlation
Enter How Many bi-variated Data : 6
Enter the Data Clearly :
1 3
17
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
3 4
5 8
8 10
9 12
10 11
Correlation of the Given bi-variated Data : 0.97
Possitive Correlation Exist
Output 2 for Correlation
Enter How Many bi-variated Data : 6
Enter the Data Clearly :
10 74
14 61
15 50
28 54
35 43
48 26
Correlation of the Given bi-variated Data : -0.91
Negative Correlation Exist
Result:
Hence, the above program has been executed successfully.
Exercise No: 9
Regression
Aim:
To implement the Regression
Coding:
#include<stdio.h>
#include<conio.h>
int main()
{
int N, i;
float
x[10],y[10],sumx=0,sumy=0,sumxx=0,sumyy=0,sumxy=0,num,den1,den2,meanx
, meany,bxy,byx;
18
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
printf("\nEnter How many Bi Variated Data :");
scanf("%d",&N);
printf("\nEnter the Data Clearly :");
for(i=0,i<N,i++) {
scanf("%f",&x[i]);
scanf("%f",&y[i]);
}
for(i=0,i<N,i++){
sumx=sumx+x[i];
sumy=sumy+y[i];
sumxx=sumxx+x[i]*x[i];
sumxy=sumxy+x[i]*y[i];
}
num=N*sumxy-sumx*sumy;
den1=N*sumxx-sumx*sumx;
den2=N*sumyy-sumy*sumy;
meanx=sumx/N;
meany=sumy/N;
bxy=num/den2;
byx=num/den1;
printf("\nRegression line of x on y\n");
printf("(x-%.2f)=%.2f(y-%.2)\n",meanx, bxy, meany);
printf("\nRegression line of y on x\n");
printf("(y-%.2f)=%.2f(x-%.2)\n",meany, byx, meanx);
getch();
return 0;
}
Output for Regression
Enter How Many bi-variated Data : 5
Enter the Data Clearly :
15
38
5 11
7 13
9 12
Regression line of x on y :
(x-5.00)=0.89(y-9.80)
Regression line of y on x :
(y-9.80)=0.95(x-5.00)
19
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
Result:
Hence, the above program has been executed successfully.
Exercise No: 10
One way – Analysis of variance
Aim:
To implement the one way – Analysis of variance
Coding:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int i,j,m,n,;
float o[8][8],T=0,TOT=0,N,CF,TSS,C[10],CT=0;
float CSS,CSSE,ndfT,ndfC,ndfE,MSS,MSSE,F,tv;
printf("Enter How many Rows and Columns :\n");
scanf("%d%d",&m,&n);
printf("\nEnter the Data :\n");
for(i=0;i<m;i++) {
for(j=0;j<n;j++) {
scanf("%f",&o[i][j]);
} }
printf("\nThe Given Data :\n");
for(i=0;i<m;i++) {
for(j=0;j<n;j++) {
printf("%f\t",o[i][j]);
T=T+o[i][j];
TOT=TOT+o[i][j]*o[i][j];
}
printf("\n\n");
}
20
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
N=m*n;
CF=pow(T,2)/N;
TSS=TOT-CF;
for(i=0;i<m;i++) {
C[j]=0;
for(j=0;j<n;j++) {
C[j]=C[j]+o[i][j];
} }
for(j=0;j<n;j++)
CT=CT+pow(C[j],2)/m;
CSS=CT-CF;
CSSE=TSS-CSS;
ndfT=N-1;
ndfC=n-1;
ndfE=ndfT-ndfC;
MSS=CSS/ndfC;
MSSE=CSSE/ndfE;
F=MSS/MSSE;
printf("\nF Ratio = %.2f",F);
printf("\nEnter the table value :");
scanf("%f",&tv);
if(F<tv){
printf("\nH0 is Accepted :");
printf("\nH1 is Rejected :");
}
else{
printf("\nH0 is Accepted :");
printf("\nH1 is Rejected :");
}
getch();
return 0;
21
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
}
Output for One way – Analysis of variance
Enter How many Rows and Columns :
53
Enter the Data :
10 9 14
12 7 11
9 12 15
16 11 14
13 11 16
The Given Data
10.000000 9.000000 14.000000
12.000000 7.000000 11.000000
9.000000 12.000000 15.000000
16.000000 11.000000 14.000000
13.000000 11.000000 16.000000
F Ratio = 4.00
Enter the Table Value : 3.88
H0 is Accepted
H1 is Rejected
Result:
Hence, the above program has been executed successfully.
22
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
Exercise No: 11
Two way – Analysis of variance
Aim:
To implement the two way – Analysis of variance
Coding:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
int i,j,m,n;
float o[8][8],T=0,TOT=0,N,CF,TSS,C[10],R[10],CT=0,RT=0;
float CSS,RSS,CSSE,RSSE,ndfT,ndfC,ndfR,ndfE,MSSC,MSSR,MSSE,F1,F1tv,F2,F2tv;
printf("Enter How many Rows and Columns :\n");
scanf("%d%d",&m,&n);
printf("\nEnter the Data :\n");
for(i=0;i<m;i++) {
for(j=0;j<n;j++) {
scanf("%f",&o[i][j]);
}}
printf("\nThe Given Data :\n");
for(i=0;i<m;i++) {
for(j=0;j<n;j++) {
printf("%f\t",o[i][j]);
T=T+o[i][j];
TOT=TOT+o[i][j]*o[i][j];
printf("\n\n");
N=m*n;
CF=pow(T,2)/N;
TSS=TOT-CF;
23
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
for(i=0;i<m;i++) {
C[j]=0;
for(j=0;j<n;j++) {
C[j]=C[j]+o[i][j];
} }
for(j=0;j<n;j++) {
CT=CT+pow(C[j],2)/m;
for(i=0;i<m;i++){
R[i]=0;
for(j=0;j<n;j++) {
R[i]=R[i]+o[i][j];
} }
for(i=0;i<m;i++)
RT=RT+pow(R[i],2)/n;
CSS=CT-CF;
RSS=RT-CF;
CSSE=TSS-CSS;
RSSE=TSS-RSS;
ndfT=N-1;
ndfR=m-1;
ndfC=n-1;
ndfE=ndfT-(ndfC+ndfR);
MSSC=CSS/ndfC;
MSSR=RSS/ndfR;
MSSE=CSSE/ndfE;
F1=MSSC/MSSE;
F2=MSSR/MSSE;
printf("\nF1 Ratio = %.2f",F1);
printf("\nF2 Ratio = %.2f",F2);
printf("\nEnter the table value for F1:");
scanf("%f",&F1tv);
24
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
printf("\nEnter the table value for F2 :");
scanf("%f",&F2tv);
if(F1<F1tv)
printf("\nH0 is Accepted for Column:\n");
printf("\nH1 is Rejected for Column:\n");
else
printf("\nH0 is Accepted for Column:\n");
printf("\nH1 is Rejected for Column:\n");
if(F2<F2tv)
printf("\nH0 is Accepted for Row:\n");
printf("\nH1 is Rejected for Row:\n");
else
printf("\nH0 is Accepted for Row:\n");
printf("\nH1 is Rejected for Row:\n");
getch();
return 0;
Output for Two way – Analysis of variance
Enter How many Rows and Columns: 3 4
Enter the Data:
38 40 41 39
25
II BCA ASHWIN.A UCAA1525
RAMAKRISHNA MISSION VIVEKANANDA COLLEGE (AUTONOMOUS) MYLAPORE
45 42 49 36
40 38 42 42
The Given Data :
38.000000 40.000000 41.000000 39.000000
45.000000 42.000000 49.000000 36.000000
40.000000 38.000000 42.000000 42.000000
F1 Rate =0.93
F2 Rate = 0.87
Enter the table value for F1: 5.14
Enter the table value for F2: 4.76
H0 is Accepted for Column
H1 is Accepted for Column
H0 is Accepted for Row
H1 is Accepted for Row
Result:
Hence, the above program has been executed successfully.
26
II BCA ASHWIN.A UCAA1525