Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Correlation Coefficient
//g++ 7.4.0 //Correlation Coefficient: finding the value of Karl Pearson's coefficient of correlation //created by Rezaul Hoque on December 23,2020 //contact at jewelmrh@yahoo.com #include <iostream> #include <cmath> using namespace std; int main () { int n=10; float x[n]={50,50,55,60,65,65,65,60,60,50}; float y[n]={11,13,14,16,16,15,15,14,13,13}; float sumX=0,sumXD=0,sumXX=0,sumY=0,sumYD=0,sumYY=0, meanX,meanY, denom,kpcoef,sumXY=0; for (int i=0;i<n;i++) { sumX += x[i]; sumY += y[i]; } meanX=sumX/n; meanY= sumY/n; for (int i=0;i<n;i++) { sumXD += (x[i]-meanX); sumYD += (y[i]-meanY); sumXX += (x[i]-meanX)*(x[i]-meanX); sumYY += (y[i]-meanY)*(y[i]-meanY); sumXY += (x[i]-meanX)*(y[i]-meanY); } denom=sqrt(sumXX*sumYY); kpcoef=sumXY/denom; cout<<"The Karl Pearson's coefficient of correlation is:\t"<<kpcoef; cout<<endl; if (kpcoef>0 && kpcoef >0.5) cout <<"There is high degree of positive correlation between the two variables.\n"; else if (kpcoef>0 && kpcoef <0.5) cout <<"There is low degree of positive between the two variables.\n"; else if (kpcoef>0 && kpcoef ==1) cout <<"There is perfect positive between the two variables.\n"; else if (kpcoef<0 && kpcoef > -0.5) cout <<"There is high degree of negative correlation between the two variables.\n"; else if (kpcoef<0 && kpcoef <-0.5) cout <<"There is low degree of negative correlation between the two variables.\n"; else if (kpcoef<0 && kpcoef == -1) cout <<"There is perfect negative correlation between the two variables.\n"; else if (kpcoef==0) cout <<"There is no correlation between the two variables.\n"; else if (kpcoef>0 && kpcoef== 0.5) cout <<"There is moderate positive correlation between the two variables.\n"; else if (kpcoef<0 && kpcoef== -0.5) cout <<"There is moderate negative correlation between the two variables.\n"; else cout<<"Sorry! Not Defined!"; return 0; }
run
|
edit
|
history
|
help
0
replace_copy_if-30-Seconds-of-C++
Scope guarding
test
Tree
parallel_for_each
random lotto number game
Gauss v0.1
Round prices
O
isBST