Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
TwoVarRegression
//g++ 7.4.0 //Two Variable Regression //created by Rezaul Hoque on January 04,2021 //contact at jewelmrh@yahoo.com #include <iostream> #include <cmath> using namespace std; int main() { int n=10; float sumX=0,sumY=0,sumXX=0, sumXY=0,sumYY=0,sumXYD=0,sumYD=0,sumXD2=0,sumYestY=0,sumestY2=0; float y[n]={70,65,90,95,110,115,120,140,155,150}; float x[n]={80,100,120,140,160,180,200,220,240,260}; float meanX, meanY,sigma2=0,b1,b2,varb1,seb1,varb2,seb2; for(int i=0;i<n;i++) { sumX += x[i]; sumXX += x[i]*x[i]; sumY += y[i]; sumYY += y[i]*y[i]; sumXY += x[i]*y[i]; } meanX = sumX/n; meanY = sumY/n; for(int i=0; i<n; i++) { sumXD2 += (x[i]-meanX)*(x[i]-meanX); sumXYD += (x[i]-meanX)*(y[i]-meanY); } //finding the slope coefficient b2 = sumXYD/sumXD2; //finding the intercept b1=((sumXX*sumY)-(sumX*sumXY))/(n*sumXX-pow(sumX,2)); //finding the estimated Y float *estY; estY = new float[n]; for(int i=0;i<n;i++) estY[i]=b1+b2*x[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 = pow(sumYestY,2)/(sumYD*sumestY2); //finding the F theF = (b2*b2*sumXD2)/(sumResid2/(n-2)); // sigma2=(sumResid2/(n-2)); varb2 = sigma2/sumXD2; seb2 = sqrt(sigma2)/sqrt(sumXD2); varb1 = (sumXX*sigma2)/(n*sumXD2); seb1 = sqrt((sumXX*sigma2)/(n*sumXD2)); cout<<"The estimated regression line is:\n"; cout<<"Y = "<<b1<<" + "<<b2<<"X"; cout <<endl; cout<<"varb1:\t"<<varb1<<"\tseb1:\t"<<seb1; cout<<endl; cout<<"varb2:\t"<<varb2<<"\tseb2:\t"<<seb2; cout <<endl; cout<<"Goodness of fit :\t"<<gof; return 0; }
run
|
edit
|
history
|
help
0
BInTree Traversal
Defining Class Members
creating triangle using nested loop
PrintShape
FindMissingLagrange
NameTempSpecial2
volatile thread-safe object
srednie
PointSum
Gauss Jordan Ida