Skip to content

Commit f773176

Browse files
committed
Update R-square calculations
Update R-square calculations to allow big data samples. Drop use of M0 matrix in R-square calculation.
1 parent 261fd2d commit f773176

4 files changed

Lines changed: 14 additions & 10 deletions

File tree

paneldata/estimation/iv2sls.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,12 @@
174174
stderr = sqrt(diag(varcoef));
175175

176176
% Goodness of fit
177-
M0 = eye(N) - 1/N * ones(N);
177+
% M0 = eye(N) - 1/N * ones(N);
178178
RSS = res' * res;
179179
TSS = y' * y;
180180
ESS = TSS - RSS;
181-
r2 = 1 - (res' * M0 * res) ./ (y' * M0 * y);
181+
% r2 = 1 - (res' * M0 * res) ./ (y' * M0 * y);
182+
r2 = 1 - RSS ./ sum((y - mean(y)).^2);
182183
adjr2 = 1 - (N - 1) ./ (N - k) .* (1 - r2);
183184

184185
% Save estimation

paneldata/estimation/ivpanel.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,16 +340,17 @@
340340

341341
% Goodness of fit
342342
if strcmp(method,'be')
343-
M0 = eye(n) - 1/n * ones(n);
343+
% M0 = eye(n) - 1/n * ones(n);
344344
adjr2_correction = (n - 1) ./ (resdf);
345345
else
346-
M0 = eye(N) - 1/N * ones(N);
346+
% M0 = eye(N) - 1/N * ones(N);
347347
adjr2_correction = (N - 1) ./ (resdf);
348348
end
349349
RSS = res' * res;
350350
TSS = y' * y;
351351
ESS = TSS - RSS;
352-
r2 = 1 - (res' * M0 * res) ./ (ytr' * M0 * ytr);
352+
% r2 = 1 - (res' * M0 * res) ./ (ytr' * M0 * ytr);
353+
r2 = 1 - RSS ./ sum((ytr - mean(ytr)).^2);
353354
adjr2 = 1 - adjr2_correction .* (1 - r2);
354355

355356
% Compute correc r2 for 're'

paneldata/estimation/ols.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,12 @@
153153

154154

155155
% Goodness of fit
156-
M0 = eye(N) - 1/N * ones(N);
156+
% M0 = eye(N) - 1/N * ones(N);
157157
RSS = res' * res;
158158
TSS = y' * y;
159159
ESS = TSS - RSS;
160-
r2 = 1 - (res' * M0 * res) ./ (y' * M0 * y);
160+
% r2 = 1 - (res' * M0 * res) ./ (y' * M0 * y);
161+
r2 = 1 - RSS ./ sum((y - mean(y)).^2);
161162
adjr2 = 1 - (N - 1) ./ (N - k) .* (1 - r2);
162163

163164
% Save estimation

paneldata/estimation/panel.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@
278278

279279
% Goodness of fit
280280
if strcmp(method,'be')
281-
M0 = eye(n) - 1/n * ones(n);
281+
% M0 = eye(n) - 1/n * ones(n);
282282
adjr2_correction = (n - 1) ./ (resdf);
283283
else
284-
M0 = eye(N) - 1/N * ones(N);
284+
% M0 = eye(N) - 1/N * ones(N);
285285
if strcmp(method,'fe') && robust
286286
adjr2_correction = (N - 1) ./ ((N-n)-k);
287287
else
@@ -291,7 +291,8 @@
291291
RSS = res' * res;
292292
TSS = y' * y;
293293
ESS = TSS - RSS;
294-
r2 = 1 - (res' * M0 * res) ./ (ytr' * M0 * ytr);
294+
%r2 = 1 - (res' * M0 * res) ./ (ytr' * M0 * ytr);
295+
r2 = 1 - RSS ./ sum((ytr - mean(ytr)).^2);
295296
adjr2 = 1 - adjr2_correction .* (1 - r2);
296297

297298
% Compute correc r2 for 're'

0 commit comments

Comments
 (0)