|
11 | 11 | % -- Function File: bootridge (Y, X, CATEGOR, NBOOT, ALPHA, L, DEFF, SEED, TOL) |
12 | 12 | % -- Function File: S = bootridge (Y, X, ...) |
13 | 13 | % -- Function File: [S, YHAT] = bootridge (Y, X, ...) |
14 | | -% -- Function File: [S, YHAT, P] = bootridge (Y, X, ...) |
15 | 14 | % |
16 | 15 | % 'bootridge (Y, X)' fits an empirical Bayes ridge regression model using |
17 | 16 | % a linear Normal (Gaussian) likelihood with an empirical Bayes normal |
|
189 | 188 | % Reported as 't (mu, sigma, df_t)' on the coefficient (or estimate) |
190 | 189 | % scale; see CONDITIONAL VS MARGINAL PRIORS for details. |
191 | 190 | % |
| 191 | +% o Deff |
| 192 | +% Design effect used to inflate the residual covariance and reduce |
| 193 | +% inferential degrees of freedom to account for clustering. |
| 194 | +% |
192 | 195 | % o lambda |
193 | 196 | % Scalar ridge tuning constant selected by minimizing the .632 |
194 | 197 | % bootstrap estimate of prediction error (then scaled by DEFF). |
195 | 198 | % |
196 | | -% o Sigma_Y_hat |
197 | | -% Estimated residual covariance matrix of the outcomes, inflated by |
198 | | -% the design effect DEFF when applicable. For a univariate outcome, |
199 | | -% this reduces to the residual variance. |
200 | | -% |
201 | 199 | % o df_lambda |
202 | 200 | % Effective residual degrees of freedom under ridge regression, |
203 | 201 | % defined as m minus the trace of the ridge hat matrix. Used for |
204 | 202 | % residual variance estimation (scale); does NOT include DEFF. |
205 | 203 | % |
| 204 | +% o df_t |
| 205 | +% Inferential degrees of freedom, which is df_lambda adjusted for |
| 206 | +% for the design effect. |
| 207 | +% |
| 208 | +% o Sigma_Y_hat |
| 209 | +% Estimated residual covariance matrix of the outcomes, inflated by |
| 210 | +% the design effect DEFF when applicable. For a univariate outcome, |
| 211 | +% this reduces to the residual variance. |
| 212 | +% |
206 | 213 | % o tau2_hat |
207 | 214 | % Estimated prior covariance of the regression coefficients across |
208 | 215 | % outcomes, proportional to Sigma_Y_hat and inversely proportional |
|
217 | 224 | % Number of bootstrap samples used to estimate the .632 bootstrap |
218 | 225 | % prediction error. |
219 | 226 | % |
220 | | -% o Deff |
221 | | -% Design effect used to inflate the residual covariance and reduce |
222 | | -% inferential degrees of freedom to account for clustering. |
223 | | -% |
224 | 227 | % o tol |
225 | 228 | % Numeric tolerance used in the golden-section search for optimizing |
226 | 229 | % the ridge tuning constant. |
|
253 | 256 | % MARGINAL PRIORS and DETAIL below. Diagonal entries are undefined |
254 | 257 | % and not included. |
255 | 258 | % |
256 | | -% '[S, YHAT] = bootridge (Y, X, ...)' returns fitted values. |
| 259 | +% o P_vec |
| 260 | +% A vector of predictor-wise penalty weights used to normalize |
| 261 | +% shrinkage across the predictor terms. |
257 | 262 | % |
258 | | -% '[S, YHAT, P] = bootridge (Y, X, ...)' returns the predictor-wise penalty |
259 | | -% weights used to normalize shrinkage across features of different scales. |
| 263 | +% '[S, YHAT] = bootridge (Y, X, ...)' returns fitted values. |
260 | 264 | % |
261 | 265 | % DETAIL: The model implements an empirical Bayes ridge regression that |
262 | 266 | % simultaneously addresses the problems of multicollinearity, multiple |
|
558 | 562 | error ('bootwild: Y must contain single or double precision numbers.'); |
559 | 563 | end |
560 | 564 |
|
561 | | - % Check that the first column is X are all equal to 1, if not create one |
562 | | - if ( ~all (X(:, 1) == 1) ) |
563 | | - X = cat (2, ones (m, 1), X); |
564 | | - n = n + 1; |
565 | | - if (~ isempty (categor)) |
566 | | - categor = categor + 1; % Shift indices to match new design matrix |
567 | | - end |
568 | | - end |
569 | | - p = n - 1; |
570 | | - % Check that X contains floating point numbers |
571 | | - if (~ any (strcmpi (class (X), {'single', 'double'}))) |
572 | | - error ('bootwild: X must contain single or double precision numbers.'); |
573 | | - end |
574 | | - |
575 | 565 | % If categor is not provided, set it to empty |
576 | 566 | if ( (nargin < 3) || isempty (categor) ) |
577 | 567 | categor = []; |
|
593 | 583 | end |
594 | 584 | end |
595 | 585 |
|
| 586 | + % Check that the first column is X are all equal to 1, if not create one |
| 587 | + if ( ~all (X(:, 1) == 1) ) |
| 588 | + X = cat (2, ones (m, 1), X); |
| 589 | + n = n + 1; |
| 590 | + if (~ isempty (categor)) |
| 591 | + categor = categor + 1; % Shift indices to match new design matrix |
| 592 | + end |
| 593 | + end |
| 594 | + p = n - 1; |
| 595 | + % Check that X contains floating point numbers |
| 596 | + if (~ any (strcmpi (class (X), {'single', 'double'}))) |
| 597 | + error ('bootwild: X must contain single or double precision numbers.'); |
| 598 | + end |
| 599 | + |
596 | 600 | % If nboot is not specified, set it to 100. |
597 | 601 | if ( (nargin < 4) || isempty (nboot) ) |
598 | 602 | nboot = 100; |
|
659 | 663 | end |
660 | 664 |
|
661 | 665 | % Check the number of output arguments requested |
662 | | - if (nargout > 3) |
663 | | - error ('bootridge: Only 3 output arguments can be requested.'); |
| 666 | + if (nargout > 2) |
| 667 | + error ('bootridge: Only 2 output arguments can be requested.'); |
664 | 668 | end |
665 | 669 |
|
666 | 670 | % Check if running in Octave (else assume Matlab) |
|
980 | 984 | S.BF10 = BF10; |
981 | 985 | S.lnBF10 = lnBF10; |
982 | 986 | S.prior = prior; |
| 987 | + S.Deff = deff; |
983 | 988 | S.lambda = lambda; |
984 | | - S.Sigma_Y_hat = Sigma_Y_hat; |
985 | 989 | S.df_lambda = df_lambda; |
| 990 | + S.df_t = df_t; |
| 991 | + S.Sigma_Y_hat = Sigma_Y_hat; |
986 | 992 | S.tau2_hat = tau2_hat; |
987 | 993 | S.Sigma_Beta = Sigma_Beta; |
988 | 994 | S.nboot = nboot; |
989 | | - S.Deff = deff; |
990 | 995 | S.tol = tol; |
991 | 996 | S.iter = iter; |
992 | 997 | S.pred_err = pred_err; |
993 | 998 | S.stability = stability; |
994 | 999 | if (q > 1); S.RTAB = RTAB; end |
| 1000 | + S.P_vec = P_vec; |
995 | 1001 | if (nargout > 1) |
996 | 1002 | YHAT = X * Beta; |
997 | 1003 | end |
|
0 commit comments