Multiple regression: Difference between revisions

+Stata
(+Stata)
Line 1,294:
{{out}}
<pre>Matrix[[0.9999999999999996], [2.0]]</pre>
 
=={{header|Stata}}==
 
First, build a random dataset:
 
<lang stata>clear
set seed 17760704
set obs 200
forv i=1/4 {
gen x`i'=rnormal()
}
gen y=1.5+0.8*x1-0.7*x2+1.1*x3-1.7*x4+rnormal()</lang>
 
Now, use the regress command:
 
<lang stata>reg y x*</lang>
 
'''Output'''
 
The command shows the coefficients along with a bunch of useful information, such as R<sup>2</sup>, F statistic, standard errors of the coefficients...
<pre>
Source | SS df MS Number of obs = 200
-------------+---------------------------------- F(4, 195) = 355.15
Model | 1343.81757 4 335.954392 Prob > F = 0.0000
Residual | 184.458622 195 .945941649 R-squared = 0.8793
-------------+---------------------------------- Adj R-squared = 0.8768
Total | 1528.27619 199 7.67977985 Root MSE = .9726
 
------------------------------------------------------------------------------
y | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
x1 | .7525247 .0689559 10.91 0.000 .6165295 .8885198
x2 | -.7036303 .0697456 -10.09 0.000 -.8411828 -.5660778
x3 | 1.157477 .072189 16.03 0.000 1.015106 1.299849
x4 | -1.718201 .0621758 -27.63 0.000 -1.840824 -1.595577
_cons | 1.399131 .0697862 20.05 0.000 1.261499 1.536764
------------------------------------------------------------------------------</pre>
 
The regress command also sets a number of '''ereturn''' values, which can be used by subsequent commands. The coefficients and their standard errors also have a special syntax:
 
<lang stata>. di _b[x1]
.75252466
 
. di _b[_cons]
1.3991314
 
. di _se[x1]
.06895593
 
. di _se[_cons]
.06978623</lang>
 
One can compute the covariance matrix of the estimates, the predicted values, residuals... See '''estat''', '''predict''', '''estimates''', '''margins''' and others. Here are a few examples:
 
<lang stata>. estat ic
 
Akaike's information criterion and Bayesian information criterion
 
-----------------------------------------------------------------------------
Model | Obs ll(null) ll(model) df AIC BIC
-------------+---------------------------------------------------------------
. | 200 -487.1455 -275.6985 5 561.397 577.8886
-----------------------------------------------------------------------------
Note: N=Obs used in calculating BIC; see [R] BIC note.
 
. estat vce
 
Covariance matrix of coefficients of regress model
 
e(V) | x1 x2 x3 x4 _cons
-------------+------------------------------------------------------------
x1 | .00475492
x2 | -.00040258 .00486445
x3 | -.00042516 .00017355 .00521125
x4 | -.00011915 -.0002568 .00054646 .00386583
_cons | .00030777 -.00031109 -.00023794 .00058926 .00487012
 
. predict yhat, xb
. predict r, r</lang>
 
 
=={{header|Tcl}}==
1,336

edits