Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
OneANOVA
//g++ 7.4.0 //One-factor ANOVA //code is created by Rezaul Hoque on January 15,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 () { int a[3][4] = {48,49,50,49,47,49,48,48,49,51,50,50}; float sum1=0,sum2=0,sum3=0,sum4=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][1]; } //calculate row means and grand mean float greatX, romean1,romean2,romean3,colmean1; romean1 = sum1/4; romean2 = sum2/4; romean3 = sum3/4; colmean1 = sum4/3; greatX = sumX/12; float * b = new float[3]; b[0]= romean1; b[1]= romean2; b[2]= romean3; float varB=0,varW, 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 treatment for(int i=0;i<3;i++) { varB +=( 4*((b[i]-greatX)*(b[i]-greatX))); } //calculate variation within treatment varW= sumTV-varB; //calculate mean squares and F float meansqB, meansqW, theF; meansqB= varB/(4-1); meansqW = varW/(3*(4-1)); theF = meansqB/meansqW; cout<<" The row-treatment and column-measurement 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 treatment:\t"<<varB; cout<<endl; cout<<" Variation within treatment:\t"<<varW; cout<<endl; cout<<" F :\t"<< theF; return 0; }
run
|
edit
|
history
|
help
0
codechef
GCC compiler bug (should output 0 1)
Test constructors and operators
selection_sort
Parenthesis checker
Sorting Array
Get all anagrams from given words
KhadijahAlshehhi
D.E.Shaw Binary Search Question
Updated Linked Lists - 5/10/2017 V3.0