Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. //to estimate regression equation form sampled data and evaluate values of standard deviation regression coffecient for atleast two independent variables
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<math.h>
  5. float mean(float *a,int n);
  6. void deviation(float *a,float mean,int n,float *d,float *s);
  7. void main()
  8. {
  9. float a[20],b[20],dx[20],dy[20];
  10. float sy=0,sx=0,mean_x=0,mean_y=0,sum_xy=0;
  11. float corr_coff=0,regcoff_xy=0,regcoff_yx=0;
  12. char type_coff[7];
  13. int n=0,i=0;
  14. printf("enter the value of n \n");
  15. scanf("%d",&n);
  16. printf("enter the value of x and y \n");
  17. for(i=0;i<n;i++)
  18. scanf("%f %f",&a[i],&b[i]);
  19. mean_x=mean(a,n);
  20. mean_y=mean(b,n);
  21. deviation(a,mean_x,n,dx,&sx);
  22. deviation(b,mean_y,n,dy,&sy);
  23. for(i=0;i<n;i++)
  24. sum_xy=sum_xy+dx[i]*dy[i];
  25. corr_coff=sum_xy/(n*sx*sy);
  26. printf("enter the type of regression coffecient as 'x on y'or 'y on x' \n");
  27. fflush(stdin);
  28. gets(type_coff);
  29. if(strcmp(type_coff,"x on y")==0)
  30. {
  31. regcoff_xy=corr_coff*(sx/sy);
  32. printf("\n the value of linear regression coff is %f",regcoff_xy);
  33. }
  34. else if(strcmp(type_coff,"y on x")==0)
  35. {
  36. regcoff_yx=corr_coff*(sy/sx);
  37. printf("\n the value of linear regression coff is %f",regcoff_yx);
  38. }
  39. else
  40. printf("enter the correct type of regression coffecient \n");
  41. getch();
  42. }
  43. float mean(float *a,int n)
  44. {
  45. float i=0,sum=0;
  46. for(i=0;i<n;i++)
  47. sum=sum+a[i];
  48. sum=sum/n;
  49. return(sum);
  50. }
  51. void deviation(float *a,float mean,int n,float *d,float *s)
  52. {
  53. float sum=0,t=0;
  54. int i=0;
  55. for(i=0;i<n;i++)
  56. {
  57. d[i]=a[i]-mean;
  58. t=d[i]*d[i];
  59. sum=sum+t;
  60. }
  61. sum=sum/n;
  62. *s=sqrt(sum);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement