enero 28, 2013

Valores ajustados y residuos en regresión simple (R)


## Tabla 2.2 Valores ajustados y residuos de los 15 primeros directores generales
## Detalles en página 39 en Introducción a la Econometría: Un Enfoque Moderno. 2009. 
## Wooldridge, J. M. Segunda edición en español. pp. 39 

# cargando archivo "tabla2.2 - salario.csv" a R
ceosal1 = read.csv("C:/Users/Administrator/Desktop/tabla2.2 - salario.csv", header = T)

# ejecutando regression simple
modelo = lm(ceosal1$salary ~ ceosal1$roe)
summary(modelo)

Call:
lm(formula = ceosal1$salary ~ ceosal1$roe)

Residuals:
   Min     1Q Median     3Q    Max 
 -1160   -526   -254    139  13500 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)    963.2      213.2    4.52  1.1e-05 ***
ceosal1$roe     18.5       11.1    1.66    0.098 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1370 on 207 degrees of freedom
Multiple R-squared:  0.0132,    Adjusted R-squared:  0.00842 
F-statistic: 2.77 on 1 and 207 DF,  p-value: 0.0978

# valores ajustados "salaryhat""
salaryhat <- fitted(modelo)

# residuos "uhat"
uhat <- residuals(modelo)

# fusionando columnas
# Tabla 2.2 Valores ajustados y residuos de los 15 primeros directores generales
table2.2 <- cbind(ceosal1, salaryhat, uhat)
table2.2
     roe salary salaryhat       uhat
1   14.1   1095    1224.1  -129.0581
2   10.9   1001    1164.9  -163.8543
3   23.5   1122    1398.0  -275.9692
4    5.9    578    1072.3  -494.3483
5   13.8   1368    1218.5   149.4923
6   20.0   1145    1333.2  -188.2151
7   16.4   1078    1266.6  -188.6108
8   16.3   1094    1264.8  -170.7607
9   10.5   1237    1157.5    79.5462
10  26.3    833    1449.8  -616.7725
11  25.9    567    1442.4  -875.3721
12  26.8    933    1459.0  -526.0231
13  14.8   1339    1237.0   101.9911
14  22.3    937    1375.8  -438.7678
15  56.3   2011    2004.8     6.1919
16  12.6   1585    1196.3   388.6937
17  20.4    905    1340.6  -435.6155
18   1.9   1058     998.3    59.6564
19  19.9    922    1331.4  -409.3649
20  15.4   1220    1248.1   -28.1096
21  38.7   1022    1679.2  -657.1873
22  16.4    759    1266.6  -507.6108
23  24.4   1414    1414.6    -0.6203
24  15.6   1041    1251.8  -210.8098
25  14.4   1688    1229.6   458.3916
26  19.0   2983    1314.7  1668.2861
27  16.1   1160    1261.1  -101.0604
28  12.1   3844    1187.1  2656.9443
29  16.2    476    1262.9  -786.9106
30  18.4   1492    1303.6   188.3868
31  14.2   1024    1225.9  -201.9082
32  14.9   1593    1238.9   354.1410
33  12.4    427    1192.6  -765.6060
34  17.1    829    1279.6  -450.5616
35  16.9    797    1275.9  -478.8614
36  18.1    577    1298.1  -721.0628
37  10.9   1342    1164.9   177.1457
38  19.3   1774    1320.3   453.7358
39  18.3    709    1301.8  -592.7630
40  18.4    860    1303.6  -443.6132
41  13.8   1336    1218.5   117.4923
42  13.7    516    1216.7  -700.6576
43  12.7    931    1198.2  -267.1564
44  15.1    815    1242.6  -427.5592
45  16.5   1681    1268.5   412.5391
46  10.2    568    1151.9  -583.9034
47  19.6    775    1325.8  -550.8146
48  12.8   1188    1200.0   -12.0065
49  15.9    782    1257.4  -475.3602
50  17.3   1170    1283.3  -113.2619
51   8.5   1469    1120.5   348.5486
52  16.4    916    1266.6  -350.6108
53  19.5   1070    1324.0  -253.9645
54  19.2    894    1318.4  -424.4141
55  15.9    829    1257.4  -428.3602
56  19.9    780    1331.4  -551.3649
57  28.1   2327    1483.1   843.9253
58  25.0    717    1425.7  -708.7210
59  15.0   1368    1240.7   127.2909
60  12.6   2028    1196.3   831.6937
61  20.3   1195    1338.8  -143.7654
62  22.7    256    1383.2 -1127.1683
63  14.8    775    1237.0  -462.0089
64  13.2   1407    1207.4   199.5930
65  10.3    543    1153.8  -610.7536
66  17.7    874    1290.7  -416.6623
67  10.0   1287    1148.2   138.7968
68  15.6   1248    1251.8    -3.8098
69   6.8    875    1089.0  -213.9994
70  12.4    925    1192.6  -267.6060
71  13.1    798    1205.6  -407.5569
72  15.8    760    1255.5  -495.5101
73  12.8    600    1200.0  -600.0065
74  15.3    991    1246.3  -255.2595
75   0.5   1570     972.4   597.5581
76  16.5    911    1268.5  -357.4609
77  15.1   1360    1242.6   117.4408
78  13.0    700    1203.7  -503.7068
79  11.1    741    1168.6  -427.5545
80   8.9   1097    1127.9   -30.8519
81  17.5    953    1287.0  -333.9621
82  15.9    441    1257.4  -816.3602
83  14.2    595    1225.9  -630.9082
84   9.3   1067    1135.3   -68.2524
85   9.5   1298    1139.0   159.0474
86  15.5   1798    1250.0   548.0403
87  14.4   4143    1229.6  2913.3916
88  11.1   1336    1168.6   167.4455
89  15.9   1750    1257.4   492.6398
90  16.4    912    1266.6  -354.6108
91   8.6   1892    1122.3   769.6985
92  24.6    833    1418.3  -585.3205
93  15.4   1142    1248.1  -106.1096
94  16.9   1159    1275.9  -116.8614
95   7.2   1283    1096.4   186.6001
96  11.6   2109    1177.8   931.1949
97  26.4   1039    1451.6  -412.6227
98  21.4    992    1359.1  -367.1167
99  19.2   1253    1318.4   -65.4141
100 15.1    721    1242.6  -521.5592
101  9.0   1351    1129.7   221.2980
102  9.4   1391    1137.1   253.8975
103 19.0   1245    1314.7   -69.7139
104  3.5   1550    1027.9   522.0545
105 22.1   2150    1372.1   777.9324
106 10.9   1846    1164.9   681.1457
107 15.1    573    1242.6  -669.5592
108 10.2   6640    1151.9  5488.0966
109 17.3    959    1283.3  -324.2619
110 33.3    612    1579.3  -967.2808
111 22.8   1820    1385.0   434.9816
112 11.1   1411    1168.6   242.4455
113 12.4   1026    1192.6  -166.6060
114 20.9   1287    1349.9   -62.8661
115  6.7    800    1087.1  -287.1493
116  7.1   1115    1094.5    20.4502
117 11.8   1631    1181.5   449.4947
118 14.0   1910    1222.2   687.7921
119 10.1    996    1150.1  -154.0533
120  6.4    918    1081.6  -163.5989
121 12.4   1261    1192.6    68.3940
122 17.6   1053    1288.8  -235.8122
123 15.1   1221    1242.6   -21.5592
124 23.6   1738    1399.8   338.1807
125 35.7   3142    1623.7  1518.3163
126 23.2   1900    1392.4   507.5811
127 12.4    427    1192.6  -765.6060
128 44.4   1700    1784.6   -84.6440
129  2.1    360    1002.0  -642.0438
130 18.4    459    1303.6  -844.6132
131 16.1   1340    1261.1    78.9396
132 15.1    729    1242.6  -513.5592
133 22.7    223    1383.2 -1160.1683
134 23.4   2101    1396.1   704.8809
135 25.7   1082    1438.7  -356.6718
136 27.0   1781    1462.7   318.2766
137 19.9    791    1331.4  -540.3649
138 43.7   2092    1771.7   320.3068
139 16.4   1573    1266.6   306.3892
140 11.6   1045    1177.8  -132.8051
141 24.8   1694    1422.0   271.9792
142 26.2    453    1447.9  -994.9224
143 44.5   1130    1786.5  -656.4941
144 22.3   1334    1375.8   -41.7678
145 22.3   1344    1375.8   -31.7678
146 35.1   1585    1612.6   -27.5830
147 13.1   1946    1205.6   740.4431
148 11.0   1619    1166.7   452.2956
149 19.4   1620    1322.1   297.8856
150 28.5    967    1490.5  -523.4752
151 43.9   1431    1775.4  -344.3934
152 26.8   1231    1459.0  -228.0231
153 15.7    770    1253.7  -483.6600
154 15.0   1594    1240.7   353.2909
155 28.2   1568    1484.9    83.0752
156 15.4    995    1248.1  -253.1096
157 20.0   1077    1333.2  -256.2151
158 42.2   1161    1743.9  -582.9414
159 19.6   1401    1325.8    75.1854
160 16.2   1127    1262.9  -135.9106
161 21.5   3068    1361.0  1707.0332
162 29.5    730    1509.0  -778.9763
163 22.6    729    1381.3  -652.3182
164 22.9  11233    1386.9  9846.1315
165 13.0    949    1203.7  -254.7068
166  7.8   3646    1107.5  2538.4994
167 48.1   1502    1853.1  -351.0984
168 18.0    807    1296.2  -489.2127
169 18.0    713    1296.2  -583.2127
170 21.7   1489    1364.7   124.3329
171 21.3    736    1357.3  -621.2666
172 26.9   1226    1460.9  -234.8733
173 30.5    543    1527.5  -984.4775
174 19.4  14822    1322.1 13499.8856
175 15.6    890    1251.8  -361.8098
176 19.4   1627    1322.1   304.8856
177 29.1   2408    1501.6   906.4241
178 40.8   2248    1718.0   529.9602
179 13.7    787    1216.7  -429.6576
180 11.1    474    1168.6  -694.5545
181 10.8    439    1163.0  -724.0041
182  5.1    465    1057.5  -592.5474
183 12.3    594    1190.8  -596.7559
184  7.4    688    1100.1  -412.1001
185  6.2    607    1077.9  -470.8987
186 12.7    634    1198.2  -564.1564
187 10.6    532    1159.3  -627.3039
188  7.4    441    1100.1  -659.1001
189 12.6    694    1196.3  -502.3063
190 12.8    520    1200.0  -680.0065
191  2.9    757    1016.8  -259.8448
192 13.5    668    1213.0  -544.9573
193 10.7    803    1161.2  -358.1540
194 11.9    500    1183.4  -683.3555
195 12.9    552    1201.9  -649.8566
196 10.1    412    1150.1  -738.0533
197  7.3   1100    1098.2     1.7500
198 14.6    959    1233.3  -274.3087
199 13.8    333    1218.5  -885.5077
200  8.9    503    1127.9  -624.8519
201 14.0    448    1222.2  -774.2079
202 12.9    732    1201.9  -469.8566
203 14.5    720    1231.5  -511.4585
204 14.7    808    1235.2  -427.1588
205  9.0    930    1129.7  -199.7020
206 15.5    525    1250.0  -724.9597
207 12.1    658    1187.1  -529.0557
208 13.7    555    1216.7  -661.6576
209 14.4    626    1229.6  -603.6084

No hay comentarios.: