Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
TwoANOVA
//g++ 7.4.0 //Two-factor ANOVA (without replication) //code is created by Rezaul Hoque on January 17,2021 //please contact at jewelmrh@yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> using namespace std; int main () { float a[3][4] = {4.5,6.4,7.2,6.7,8.8,7.8,9.6,7.0,5.9,6.8,5.7,5.2}; float sum1=0,sum2=0,sum3=0,sum4=0,sum5=0,sum6=0,sum7=0,sumX=0; for (int i=0; i<3;i++) { for(int j=0;j<4; j++) sumX += a[i][j]; } for (int j=0;j<4; j++) { sum1 += a[0][j]; sum2 += a[1][j]; sum3 += a[2][j]; } for (int i=0; i<3;i++) { sum4 += a[i][0]; sum5 += a[i][1]; sum6 += a[i][2]; sum7 += a[i][3]; } //calculate row means and grand mean float greatX, romean1,romean2,romean3,colmean1,colmean2,colmean3,colmean4; romean1 = sum1/4; romean2 = sum2/4; romean3 = sum3/4; colmean1 = sum4/3; colmean2 = sum5/3; colmean3 = sum6/3; colmean4 = sum7/3; greatX = sumX/12; float * b = new float[3]; b[0]= romean1; b[1]= romean2; b[2]= romean3; float * c = new float[4]; c[0]=colmean1; c[1]=colmean2; c[2]= colmean3; c[3]= colmean4; float varB=0,varW=0, varE=0, sumTV=0; //calculate total variation for(int i=0;i<3;i++) { for(int j=0; j<4; j++) sumTV += (a[i][j]- greatX)*(a[i][j]- greatX); } //calculate variation between columns for(int j=0; j<4; j++) { varW += (3*((c[j]-greatX)*(c[j]-greatX))); } //calculate variation between rows for(int i=0;i<3;i++) { varB +=( 4*((b[i]-greatX)*(b[i]-greatX))); } //calculate variation due to error for (int i=0;i<3;i++) { for (int j=0;j<4;j++) varE += (a[i][j]- b[i]- c[j]+greatX)*(a[i][j]- b[i]- c[j]+greatX); } //calculate mean squares and F float meansqB, meansqW,meansqE, theFr,theFc; meansqB= varB/(3-1); meansqW = varW/(4-1); meansqE = varE/((3-1)*(4-1)); theFr = meansqB/meansqE; theFc = meansqW/meansqE; cout<<" The row-treatment and column-block look like:\n"; for (int i=0; i<3;i++) { for(int j=0;j<4; j++) cout<<" "<<a[i][j]; cout<<endl; } cout<<"The grand mean:\t"<<greatX; cout<<endl; cout<<" Total variation is:\t"<<sumTV; cout<<endl; cout<<" Variation between rows:\t"<<varB; cout<<endl; cout<<" Variation between columns:\t"<<varW; cout<<endl; cout <<"Variation due to error:\t"<<varE; cout<<endl; cout<<" F value for testing the difference in row means :\t"<< theFr; cout<<endl; cout<<" F value for testing the difference in column means :\t"<< theFc; return 0; }
run
|
edit
|
history
|
help
0
Good1
რიცხვები დაფაზა~ფინალური
iviewb
Addition of two matrix **Part 2
ADP_campus
Array Subset of another array
Triangle
Prime Factor
cppPyPoly2
Zahra_matrix