@!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@ @ Sample Regression Program @ @!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@ library pgraph; graphset; @!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@ @ We could enter the data right here, if we wanted to @ x={0.3,1.8,1.2,2.1,3.9,4.2,5.8,7.1,9.0,8.5}; y={12,21,39,42,28,37,71,84,90,95}; @ Transforming data algebraically, if necessary @ @ Example x=ln(x); @ @!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@ @ Plotting the data @ @ Setting global values in GAUSS for plotting data @ _pstype=7; _pltype={6}; _plctrl=-1; heading="Scatter Plot of Data"; title(heading); xlabel("x1 value in x-units"); ylabel("y value in y-units"); xy( x[.,1],y ); pause(6); @!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@ @ Initialising an output file and opening it @ output file = c:\gauss50\Eco7424\samplreg.out reset; output on; @!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@ @ Regression in levels @ @ Programming the OLS formula @ beta=inv(x'*x)*(x'*y); yhat=x*beta; ehat=y-yhat; sse=ehat'*ehat; sigmahat=sqrt(sse/(rows(y)-cols(x))); stderr=sigmahat*sqrt(inv(x'*x)); @!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@ @ Writing the output to the output file @ format /rd 10,4; "OLS results from own programming of OLS formula "; ""; " Regression with no constant "; ""; "regression coefficient beta = ";; beta; "std error of beta = ";; stderr; pause(6); @!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@ @ Alternative way to do OLS - using the OLS command in GAUSS @ "";"";""; " Alternative way to do OLS - using the OLS command in GAUSS ";""; @ Setting values of global constants for linear regression @ __con=0; @ instructs GAUSS to exclude constant term in the regression @ __olsres=1; @ instructs GAUSS to compute and store OLS residuals @ @ no constant in regression @ " Regression with no constant "; ""; @ qr is the matrix containing the explanatory variables @ @ ql is the vector of dependent variables @ qr=x; ql=y; @ The GAUSS OLS command @ {a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11}=ols(0,ql,qr); ""; pause(6); @!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@ @ Interpreting the output @ "OLS results from GAUSS OLS command "; ""; "regression coefficient beta = ";; a3; ""; "std error of beta = ";; a6; ""; pause(6); @!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@ @ Calculating the 'Fitted Value' in the regression @ yhat=qr*a3; @ Plotting the raw data and the fitted values @ _pstype=7; _pltype={4,6}; _plctrl={-1,0}; heading="Regression Fit"; title(heading); xlabel("x1 value in x-units"); ylabel("y value in y-units"); xy( x[.,1],y~yhat ); pause(6); @!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@ @ Closing the output file @ output off; @ End of program @ end; /* @!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@ @ Useful stuff commented out from the current program @ @ Reading data @ @ We could load from a data file instead Example @ load data[] = c:\gausswin\programs\t9p4.txt; data1 = reshape(data,rows(data)/4,4); x1 = data1[1:rows(data1),2]; x2 = data1[1:rows(data1),3]; x3 = data1[.,4]; y = data1[1:rows(data1),1]; @ @ Defining a new variable @ x = x1~x2~x3; */