Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //to estimate regression equation form sampled data and evaluate values of standard deviation regression coffecient for atleast two independent variables
- #include<stdio.h>
- #include<string.h>
- #include<math.h>
- float mean(float *a,int n);
- void deviation(float *a,float mean,int n,float *d,float *s);
- void main()
- {
- float a[20],b[20],dx[20],dy[20];
- float sy=0,sx=0,mean_x=0,mean_y=0,sum_xy=0;
- float corr_coff=0,regcoff_xy=0,regcoff_yx=0;
- char type_coff[7];
- int n=0,i=0;
- printf("enter the value of n \n");
- scanf("%d",&n);
- printf("enter the value of x and y \n");
- for(i=0;i<n;i++)
- scanf("%f %f",&a[i],&b[i]);
- mean_x=mean(a,n);
- mean_y=mean(b,n);
- deviation(a,mean_x,n,dx,&sx);
- deviation(b,mean_y,n,dy,&sy);
- for(i=0;i<n;i++)
- sum_xy=sum_xy+dx[i]*dy[i];
- corr_coff=sum_xy/(n*sx*sy);
- printf("enter the type of regression coffecient as 'x on y'or 'y on x' \n");
- fflush(stdin);
- gets(type_coff);
- if(strcmp(type_coff,"x on y")==0)
- {
- regcoff_xy=corr_coff*(sx/sy);
- printf("\n the value of linear regression coff is %f",regcoff_xy);
- }
- else if(strcmp(type_coff,"y on x")==0)
- {
- regcoff_yx=corr_coff*(sy/sx);
- printf("\n the value of linear regression coff is %f",regcoff_yx);
- }
- else
- printf("enter the correct type of regression coffecient \n");
- getch();
- }
- float mean(float *a,int n)
- {
- float i=0,sum=0;
- for(i=0;i<n;i++)
- sum=sum+a[i];
- sum=sum/n;
- return(sum);
- }
- void deviation(float *a,float mean,int n,float *d,float *s)
- {
- float sum=0,t=0;
- int i=0;
- for(i=0;i<n;i++)
- {
- d[i]=a[i]-mean;
- t=d[i]*d[i];
- sum=sum+t;
- }
- sum=sum/n;
- *s=sqrt(sum);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement