Skip to content

Commit 4f91294

Browse files
committed
bootridge: Minor bug fix for categor, and added df_t and P_vec to STATS output
1 parent 8d926f6 commit 4f91294

File tree

1 file changed

+37
-31
lines changed

1 file changed

+37
-31
lines changed

inst/bootridge.m

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
% -- Function File: bootridge (Y, X, CATEGOR, NBOOT, ALPHA, L, DEFF, SEED, TOL)
1212
% -- Function File: S = bootridge (Y, X, ...)
1313
% -- Function File: [S, YHAT] = bootridge (Y, X, ...)
14-
% -- Function File: [S, YHAT, P] = bootridge (Y, X, ...)
1514
%
1615
% 'bootridge (Y, X)' fits an empirical Bayes ridge regression model using
1716
% a linear Normal (Gaussian) likelihood with an empirical Bayes normal
@@ -189,20 +188,28 @@
189188
% Reported as 't (mu, sigma, df_t)' on the coefficient (or estimate)
190189
% scale; see CONDITIONAL VS MARGINAL PRIORS for details.
191190
%
191+
% o Deff
192+
% Design effect used to inflate the residual covariance and reduce
193+
% inferential degrees of freedom to account for clustering.
194+
%
192195
% o lambda
193196
% Scalar ridge tuning constant selected by minimizing the .632
194197
% bootstrap estimate of prediction error (then scaled by DEFF).
195198
%
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-
%
201199
% o df_lambda
202200
% Effective residual degrees of freedom under ridge regression,
203201
% defined as m minus the trace of the ridge hat matrix. Used for
204202
% residual variance estimation (scale); does NOT include DEFF.
205203
%
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+
%
206213
% o tau2_hat
207214
% Estimated prior covariance of the regression coefficients across
208215
% outcomes, proportional to Sigma_Y_hat and inversely proportional
@@ -217,10 +224,6 @@
217224
% Number of bootstrap samples used to estimate the .632 bootstrap
218225
% prediction error.
219226
%
220-
% o Deff
221-
% Design effect used to inflate the residual covariance and reduce
222-
% inferential degrees of freedom to account for clustering.
223-
%
224227
% o tol
225228
% Numeric tolerance used in the golden-section search for optimizing
226229
% the ridge tuning constant.
@@ -253,10 +256,11 @@
253256
% MARGINAL PRIORS and DETAIL below. Diagonal entries are undefined
254257
% and not included.
255258
%
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.
257262
%
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.
260264
%
261265
% DETAIL: The model implements an empirical Bayes ridge regression that
262266
% simultaneously addresses the problems of multicollinearity, multiple
@@ -558,20 +562,6 @@
558562
error ('bootwild: Y must contain single or double precision numbers.');
559563
end
560564

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-
575565
% If categor is not provided, set it to empty
576566
if ( (nargin < 3) || isempty (categor) )
577567
categor = [];
@@ -593,6 +583,20 @@
593583
end
594584
end
595585

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+
596600
% If nboot is not specified, set it to 100.
597601
if ( (nargin < 4) || isempty (nboot) )
598602
nboot = 100;
@@ -659,8 +663,8 @@
659663
end
660664

661665
% 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.');
664668
end
665669

666670
% Check if running in Octave (else assume Matlab)
@@ -980,18 +984,20 @@
980984
S.BF10 = BF10;
981985
S.lnBF10 = lnBF10;
982986
S.prior = prior;
987+
S.Deff = deff;
983988
S.lambda = lambda;
984-
S.Sigma_Y_hat = Sigma_Y_hat;
985989
S.df_lambda = df_lambda;
990+
S.df_t = df_t;
991+
S.Sigma_Y_hat = Sigma_Y_hat;
986992
S.tau2_hat = tau2_hat;
987993
S.Sigma_Beta = Sigma_Beta;
988994
S.nboot = nboot;
989-
S.Deff = deff;
990995
S.tol = tol;
991996
S.iter = iter;
992997
S.pred_err = pred_err;
993998
S.stability = stability;
994999
if (q > 1); S.RTAB = RTAB; end
1000+
S.P_vec = P_vec;
9951001
if (nargout > 1)
9961002
YHAT = X * Beta;
9971003
end

0 commit comments

Comments
 (0)