Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

System Number- 52/5

SET- B
Exam Roll No.- 21044568055
Course- Statistical Data Analysis Using C
Programming
Sem- 5
Paper-
UPC- 32371502
Q1.
/*WAP to generate random sample from Normal Distribution (Using CLT). Also. calculate
sample mean and sample variance. Run a program for sample size=4, mu=20, and
variance=9*/
#include<stdio.h>
#include<stdlib.h>
#include<values.h>
#include<conio.h>
#include<math.h>
vvoid main()
{
int i, j, n=4;
float r[20], y, mu=20, var=9, pm, pv, sm, sv, sum, vsum;
clrscr();
randomize();
printf("\nRandom Sample")
for(i=0;i<n;i++)
{
y = 0;
for(j=0 ;j<12 ;j++)
y = y + rand()/(float)MAXINT;
y = y-6;
r[i] = mu + y*sqrt(var);
printf("%f\t",r[i]);
}

//POPULATION PARAMETERS//

printf("\nPopuation Mean=%f and Population Variance=%f", mu, var);


//SAMPLE STATISTICS//

sum=0.0, vsum=0.0;
for(i=0;i<n;i++)
sum= sum+r[i];
sm=sum/n;
for(i=0 ;i<n ;i++)
vsum = vsum + (r[i]-sm)*(r[i]-sm);
sv = vsum/n;
printf("\nSample mean = %f and Sample variance = %f" ,sm ,sv);
getch();

}
Q4.
/* Write a program to prepare frequency table */
#include<stdio.h>
#include<conio.h>
main()
{
float value[50];
int maxvals,counter,i,low,high,group[12]={0};
printf("Enter no of items:");
scanf("%d",&maxvals);
printf("Enter no of groups:");
scanf("%d",&counter);
printf("Enter %d items:",maxvals);
for(i=0;i<maxvals;i++)
{
scanf("%f",&value[i]);
group[(int)(value[i]/10)]++;
}
printf("\n");
printf("group range frequency \n");
for(i=0;i<counter;i++)
{
low=i*10;
high=low+9;
printf("%2d %4d to %d %3d \n",i+1,low,high,group[i]);
}
getch();
}

OUTPUT:
Enter no of items:55
Enter no of groups:12
Enter 55 items:42 72 40 60 82 115 41 61 75 83 63
53 110 76 84 50 67 78 77 63 65 95
68 69 104 80 79 79 54 73 59 81 100
66 49 77 90 84 76 42 64 69 70 80
72 50 79 52 103 96 51 86 78 94 71
group range frequency
1 0 to 9 0
2 10 to 19 0
3 20 to 29 0
4 30 to 39 0
5 40 to 49 5
6 50 to 59 7
7 60 to 69 11
8 70 to 79 15
9 80 to 89 8
10 90 to 99 4
11 100 to 109 3
12 110 to 119 2
Q2.
/* Write a program to calculate multiple and partial correlation coefficient */
#include<stdio.h>
#include<conio.h>
#include<math.h>
float mean(float x[],int n);
float variance(float x[],int n);
float correlation(float x[],float y[],int n);
float pcorrelation(float rxy,float rxz,float ryz);
float mcorrelation(float rxy,float rxz,float ryz);
main()
{
int i,n;
float x[20],y[20],z[20],rxy,rxz,ryz,prxy_z,prxz_y,pryz_x,mrx_yz,mry_xz,
mrz_xy;
printf("enter the value of n:");
scanf("%d",&n);
printf("\n enter value of x,y and z:");
for(i=0;i<n;i++)
scanf("%f%f%f",&x[i],&y[i],&z[i]);
rxy=correlation(x,y,n);
rxz=correlation(x,z,n);
ryz=correlation(y,z,n);
printf("\n rxy=%f\t rxz=%f\t ryz=%f",rxy,rxz,ryz);
prxy_z=pcorrelation(rxy,rxz,ryz);
prxz_y=pcorrelation(rxz,rxy,ryz);
pryz_x=pcorrelation(ryz,rxy,rxz);
printf("\n prxy_z=%f\t prxz_y=%f\t pryz_x=%f",prxy_z,prxz_y,pryz_x);
mrx_yz=mcorrelation(rxy,rxz,ryz);
mry_xz=mcorrelation(rxy,ryz,rxz);
mrz_xy=mcorrelation(rxz,ryz,rxy);
printf("\n mrx_yz=%f\t mry_xz=%f\t mrz_xy=%f",mrx_yz,mry_xz,mrz_xy);
getch();
}
float mean(float x[],int n)
{
int i;
float sx=0.0;
for(i=0;i<n;i++)
sx=sx+x[i];
return(sx/n);
}
float variance(float x[],int n)
{
int i;
float svx=0.0,vx,mx;
mx=mean(x,n);
for(i=0;i<n;i++)
svx=svx+(x[i]-mx)*(x[i]-mx);
vx=svx/n;
return(vx);
}
float correlation(float x[],float y[],int n)
{
int i;
float covxy,rxy,mx,my,vx,vy;
covxy=0.0;
for(i=0;i<n;i++)
covxy=covxy+(x[i]*y[i]);
mx=mean(x,n);
my=mean(y,n);
vx=variance(x,n);
vy=variance(y,n);
covxy=(covxy/n)-(mx*my);
rxy=covxy/sqrt(vx*vy);
return(rxy);
}
float pcorrelation(float rxy,float rxz,float ryz)
{
float pcorr;
pcorr=(rxy-rxz*ryz)/sqrt((1-rxz*rxz)*(1-ryz*ryz));
return(pcorr);
}
float mcorrelation(float rxy,float rxz,float ryz)
{
float mcorr;
mcorr=(rxy*rxy+rxz*rxz-2*rxy*rxz*ryz)/(1-ryz*ryz);
return(sqrt(mcorr));
}

OUTPUT:
enter the value of n:15
enter value of x,y and z:4 6 7 9 13 15 17 18 20 24 26 27 30 31 34
38 36 30 27 24 23 22 20 18 16 10 7 4 3 2
90 72 54 42 30 12 10 9 8 6 5 5 4 3 1
rxy=0.982792 rxz=0.869975 ryz=0.941252
prxyz=0.984419 prxzy=-0.882984 pryzx=0.946916
mrxyz=0.996234 mryxz=0.998235 mrzxy=0.987356

You might also like