Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ThreeVariableRegression
//g++ 7.4.0 //Three Variable Regression //the code is created by Rezaul Hoque on January 07,2021 //Please contact at jewelmrh@yahoo.com #include <iostream> #include <cmath> using namespace std; int main() { int n=13; float sumX2=0,sumX3=0,sumY=0,sumsqX2D=0, sumsqX3D=0,sumX2X3D=0,sumX2YD=0,sumX3YD=0,sumYD=0,sumYestY=0,sumestY2=0; float y[n]={5.92,4.30,3.30,6.23,10.97,9.14,5.77,6.45,7.60,11.47,13.46,10.24,5.99}; float x2[n]={4.9,5.9,5.6,4.9,5.6,8.5,7.7,7.1,6.1,5.8,7.1,7.6,9.7}; float x3[n]={4.78,3.84,3.13,3.44,6.84,9.47,6.51,5.92,6.08,8.09,10.01,10.81,8.00}; float meanX2,meanX3, meanY,sigma2=0,b1,b2,b3,varb1,seb1,varb2,seb2,varb3, seb3; for(int i=0;i<n;i++) { sumX2 += x2[i]; sumY += y[i]; sumX3 += x3[i]; } meanX2 = sumX2/n; meanX3 = sumX3/n; meanY = sumY/n; for(int i=0; i<n; i++) { sumsqX2D += (x2[i] - meanX2)*(x2[i] - meanX2); sumsqX3D += (x3[i] - meanX3)*(x3[i] - meanX3); sumX2X3D +=(x2[i] - meanX2)*(x3[i] - meanX3); sumX2YD += (x2[i] - meanX2)*(y[i]- meanY); sumX3YD += (x3[i] - meanX3)*(y[i]-meanY); } //finding the slope coefficient for X2 b2= ((sumX2YD * sumsqX3D) -( sumX3YD*sumX2X3D))/((sumsqX2D*sumsqX3D)-pow(sumX2X3D,2)); //Finding slope coefficient for X3 b3 = ((sumX3YD*sumsqX2D)-(sumX2YD*sumX2X3D))/((sumsqX2D*sumsqX3D)-pow(sumX2X3D,2)); //finding the intercept b1= meanY - b2*meanX2 -b3*meanX3; //finding the estimated Y float *estY; estY = new float[n]; for(int i=0;i<n;i++) estY[i]=b1+b2*x2[i]+b3*x3[i]; //finding the residual float *resid; resid = new float[n]; for(int i=0;i<n;i++) resid[i]=y[i]-estY[i]; float theF,sumResid2=0; float gof; for (int i=0;i<n; i++) { sumYestY += (estY[i]-meanY)*(y[i]-meanY); sumestY2 += (estY[i]-meanY)*(estY[i]-meanY); sumResid2 += resid[i]* resid[i]; sumYD += (y[i]-meanY)*(y[i]-meanY); } //finding goodness of fit gof = ((b2*sumX2YD)+(b3*sumX3YD))/(sumYD); //finding the F theF =( (b2*sumX2YD)+(b3*sumX3YD))/2/(sumResid2/(n-3)); //finding the variance and standard error sigma2=(sumResid2/(n-3)); varb2 = (sumsqX3D*sigma2)/((sumsqX2D*sumsqX3D)-pow(sumX2X3D,2)); seb2 = sqrt(varb2); varb1 = (1/n+((pow(meanX2,2)*sumsqX3D+pow(meanX3,2)*sumsqX2D-(2*meanX2*meanX3*sumX2X3D))/((sumsqX2D*sumsqX3D)-pow(sumX2X3D,2))))*sigma2; seb1 = sqrt(varb1); cout<<"The estimated regression line is:\n"; cout<<"Y = "<<b1<<" + "<<b2<<"X2 + "<<b3<<"X3"; cout <<endl; cout<<"varb1:\t"<<varb1<<"\tseb1:\t"<<seb1; cout<<endl; cout<<"varb2:\t"<<varb2<<"\tseb2:\t"<<seb2; cout <<endl; cout<<"varb3:\t"<<varb3<<"\tseb3:\t"<<seb3; cout<<endl; cout<<"Goodness of fit :\t"<<gof; cout<<endl; cout<<" F :\t"<<theF; return 0; }
run
|
edit
|
history
|
help
0
ExceptionHandling2
325324
c++
typeid
star print1
4149 coj WIP
Sum of digits of number
NamespaceId
რიცხვები დაფაზა~ფინალური
Day3