Skip to content

Commit 863ce5b

Browse files
committed
added checks for datatype
1 parent 6b85915 commit 863ce5b

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

inst/bootbayes.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,21 @@
197197
error ('bootbayes: DATA must be provided')
198198
end
199199
[n, q] = size (Y);
200+
% Check that Y contains floating point numbers
201+
if (~ any (strcmpi (class (Y), {'single', 'double'})))
202+
error ('bootwild: Y must contain single or double precision numbers.');
203+
end
200204

201205
% Evaluate the design matrix
202206
if ( (nargin < 2) || (isempty (X)) )
203207
X = ones (n, 1);
204208
elseif (size (X, 1) ~= n)
205209
error ('bootbayes: X must have the same number of rows as y')
206210
end
211+
% Check that Y contains floating point numbers
212+
if (~ any (strcmpi (class (X), {'single', 'double'})))
213+
error ('bootwild: Y must contain single or double precision numbers.');
214+
end
207215

208216
% Remove rows of the data whose outcome or value of any predictor is NaN or Inf
209217
excl = any ([isnan([Y, X]), isinf([Y, X])], 2);

inst/bootridge.m

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,12 +551,20 @@
551551
% Get dimensions of the data
552552
[m, n] = size (X);
553553
q = size (Y, 2);
554+
% Check that Y contains floating point numbers
555+
if (~ any (strcmpi (class (Y), {'single', 'double'})))
556+
error ('bootwild: Y must contain single or double precision numbers.');
557+
end
554558

555559
% Check that the first column is X are all equal to 1, if not create one
556560
if ( ~all (X(:, 1) == 1) )
557561
X = cat (2, ones (m, 1), X);
558562
n = n + 1;
559563
end
564+
% Check that X contains floating point numbers
565+
if (~ any (strcmpi (class (X), {'single', 'double'})))
566+
error ('bootwild: X must contain single or double precision numbers.');
567+
end
560568

561569
% If categor is not provided, set it to empty
562570
if ( (nargin < 3) || isempty (categor) )
@@ -629,7 +637,7 @@
629637
seed = 1;
630638
else
631639
if ( isinf (seed) || isnan (seed) || (numel (seed) > 1) || ...
632-
seed ~= fix(seed))
640+
seed ~= fix (seed))
633641
error ('bootridge: The seed must be a finite integer');
634642
end
635643
end
@@ -1408,6 +1416,19 @@
14081416

14091417
%-------------------------------------------------------------------------------
14101418

1419+
%!demo
1420+
%!
1421+
%! % Analysis of Rohwer's dataset
1422+
%! [group, SES, SAT, PPVT, Raven, n, s, ns, na, ss] = ...
1423+
%! textread ('./rohwer_data.csv', '%f %s %f %f %f %f %f %f %f %f', ...
1424+
%! 'Delimiter', ',', 'HeaderLines', 1);
1425+
%! MAT = bootlm (SAT, {SES, n, s, ns, na, ss}, 'model', 'linear', ...
1426+
%! 'nboot', 0, 'display', 'off', 'continuous', [2:6], ...
1427+
%! 'contrasts', 'helmert');
1428+
%!
1429+
%! % Analysis using bootridge
1430+
%! bootridge([SAT, PPVT, Raven], MAT.X, 2, 1999, .05);
1431+
14111432
%!demo
14121433
%!
14131434
%! % Simple linear regression. The data represents salaries of employees and

inst/bootwild.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
end
165165
end
166166

167-
% Calculate the length of y
167+
% Calculate the length and datatype of y
168168
if (nargin < 1)
169169
error ('bootwild: DATA must be provided')
170170
end
@@ -173,13 +173,21 @@
173173
error ('bootwild: y must be a column vector')
174174
end
175175
n = numel (y);
176+
% Check that y contains floating point numbers
177+
if (~ any (strcmpi (class (y), {'single', 'double'})))
178+
error ('bootwild: y must contain single or double precision numbers.');
179+
end
176180

177181
% Evaluate the design matrix
178182
if ( (nargin < 2) || (isempty (X)) )
179183
X = ones (n, 1);
180184
elseif (size (X, 1) ~= n)
181185
error ('bootwild: X must have the same number of rows as y')
182186
end
187+
% Check that X contains floating point numbers
188+
if (~ any (strcmpi (class (X), {'single', 'double'})))
189+
error ('bootwild: X must contain single or double precision numbers.');
190+
end
183191

184192
% Remove rows of the data whose outcome or value of any predictor is NaN or Inf
185193
excl = any ([isnan([y, X]), isinf([y, X])], 2);

0 commit comments

Comments
 (0)