Skip to content

Commit

Permalink
added feature to standardize data before fitting
Browse files Browse the repository at this point in the history
  • Loading branch information
acp29 committed Jan 20, 2024
1 parent 81cfa0a commit 78cec83
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: statistics-resampling
version: 5.5.5.2
version: 5.5.5.3
date: 2024-01-20
author: Andrew Penn <[email protected]>
maintainer: Andrew Penn <[email protected]>
Expand Down
44 changes: 43 additions & 1 deletion inst/bootlm.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
% -- Function File: bootlm (Y, GROUP, ..., 'dim', DIM)
% -- Function File: bootlm (Y, GROUP, ..., 'continuous', CONTINUOUS)
% -- Function File: bootlm (Y, GROUP, ..., 'model', MODELTYPE)
% -- Function File: bootlm (Y, GROUP, ..., 'standardize', STANDARDIZE)
% -- Function File: bootlm (Y, GROUP, ..., 'varnames', VARNAMES)
% -- Function File: bootlm (Y, GROUP, ..., 'method', METHOD)
% -- Function File: bootlm (Y, GROUP, ..., 'method', 'bayesian', 'prior', PRIOR)
Expand Down Expand Up @@ -97,6 +98,13 @@
% -- Example:
% A two-way design with interaction would be: [1 0; 0 1; 1 1]
%
% '[...] = bootlm (Y, GROUP, ..., 'standardize', STANDARDIZE)'
%
% <> STANDARDIZE can be either 'off' (or false, default) or 'on' (or true)
% and controls whether the outcome and any continuous predictors in the
% model should be standardized (i.e. converted to standard scores)
% before model fitting.
%
% '[...] = bootlm (Y, GROUP, ..., 'method', METHOD)'
%
% <> METHOD can be specified as one of the following:
Expand Down Expand Up @@ -498,6 +506,7 @@
SEED = rand ('seed');
DEP = [];
POSTHOC = 'none';
STANDARDIZE = false;
METHOD = 'wild';
PRIOR = 1;
L = [];
Expand Down Expand Up @@ -537,6 +546,8 @@
DIM = sort (value(:)');
case {'posthoc', 'posttest'}
POSTHOC = value;
case {'standardize','standardise'}
STANDARDIZE = value;
case 'nboot'
NBOOT = value;
case 'method'
Expand Down Expand Up @@ -836,6 +847,36 @@
end
end

% If requested, standardize the continuous predictors and the outcome
switch (class (STANDARDIZE))
case 'char'
if (ismember (lower (STANDARDIZE), {'on','yes'}))
STANDARDIZE = true;
elseif (ismember (lower (STANDARDIZE), {'off','no'}))
STANDARDIZE = false;
else
error ('bootlm: unrecognised value for ''standardize'' input argument')
end
case 'logical'
% Do nothing
otherwise
STANDARDIZE = logical (STANDARDIZE);
end
if STANDARDIZE
for j = 1:K
if cont_vec(j)
if iscell (GROUP(:,j))
tmp = cell2mat (GROUP(:,j));
GROUP(:,CONTINUOUS) = num2cell ((tmp - mean (tmp)) / std (tmp));
else
tmp = GROUP(:,j);
GROUP(:,CONTINUOUS) = (tmp - mean (tmp)) / std (tmp);
end
end
end
Y = (Y - mean (Y)) / std (Y);
end

% Create design matrix
[X, grpnames, nlevels, df, coeffnames, gid, CONTRASTS, ...
center_continuous] = mDesignMatrix (GROUP, TERMS, CONTINUOUS, ...
Expand Down Expand Up @@ -1075,7 +1116,7 @@

otherwise

% Model posthoc comparisons
% The model posthoc comparisons
switch (class (POSTHOC))
case 'cell'
if (strcmp (POSTHOC{1}, 'trt.vs.ctrl'))
Expand Down Expand Up @@ -1104,6 +1145,7 @@
end
L = make_test_matrix (L, pairs);
end
Np = size (pairs, 1); % Update the number of parameters
switch (lower (METHOD))
case 'wild'
[STATS, BOOTSTAT] = bootwild (Y, X, DEP, NBOOT, ALPHA, SEED, ...
Expand Down

0 comments on commit 78cec83

Please sign in to comment.