Skip to content

Commit

Permalink
changed demos and tests of case resampling for regression to use buil…
Browse files Browse the repository at this point in the history
…tin function @mldivide
  • Loading branch information
acp29 committed Apr 13, 2024
1 parent 25276ea commit 786200d
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 46 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: statistics-resampling
version: 5.5.8
date: 2024-04-02
version: 5.5.9
date: 2024-04-12
author: Andrew Penn <[email protected]>
maintainer: Andrew Penn <[email protected]>
title: A statistics package with a variety of resampling tools
Expand Down
39 changes: 30 additions & 9 deletions inst/bootci.m
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@
%!
%! % 95% BCa bootstrap confidence intervals for the mean
%! ci = bootci (1999, @mean, data)
%!
%! % Please be patient, the calculations will be completed soon...

%!demo
%!
Expand Down Expand Up @@ -463,6 +465,8 @@
%!
%! % 90% percentile bootstrap confidence intervals for the variance
%! ci = bootci (1999, {{@var,1}, data}, 'type', 'per', 'alpha', 0.1)
%!
%! % Please be patient, the calculations will be completed soon...

%!demo
%!
Expand All @@ -472,6 +476,8 @@
%!
%! % 90% BCa bootstrap confidence intervals for the variance
%! ci = bootci (1999, {{@var,1}, data}, 'type', 'bca', 'alpha', 0.1)
%!
%! % Please be patient, the calculations will be completed soon...

%!demo
%!
Expand Down Expand Up @@ -606,6 +612,21 @@
%! %<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
%!
%! end
%!
%! % Please be patient, the calculations will be completed soon...

%!demo
%!
%! % Input dataset
%! y = randn (20,1); x = randn (20,1); X = [ones(20,1), x];
%!
%! % 95% BCa confidence interval for regression coefficients
%! ci = bootci (1999, @mldivide, X, y)
%!
%! % N.B: Consider using either the 'bootwild', 'bootbayes' or 'bootlm'
%! % functions for bootstrapping linear regression problems instead
%!
%! % Please be patient, the calculations will be completed soon...

%!demo
%!
Expand Down Expand Up @@ -780,15 +801,15 @@
%! y = randn (20,1); x = randn (20,1); X = [ones(20,1),x];
%! bootci (1999, @cor, x, y);
%! bootci (1999, {@cor, x, y}, 'strata', g);
%! bootci (1999, @(y,X) pinv(X)*y, y, X);
%! bootci (1999, @(y,X) pinv(X)*y, y, X, 'alpha', 0.1);
%! bootci (1999, {@(y,X) pinv(X)*y, y, X}, 'alpha', 0.1);
%! bootci (1999, {@(y,X) pinv(X)*y, y, X}, 'alpha', 0.1, 'type', 'norm');
%! bootci (1999, {@(y,X) pinv(X)*y, y, X}, 'alpha', 0.1, 'type', 'per');
%! bootci (1999, {@(y,X) pinv(X)*y, y, X}, 'alpha', 0.1, 'type', 'basic');
%! bootci (1999, {@(y,X) pinv(X)*y, y, X}, 'alpha', 0.1, 'type', 'bca');
%! bootci (1999, {@(y,X) pinv(X)*y, y, X}, 'alpha', 0.1, 'type', 'stud');
%! bootci (1999, {@(y,X) pinv(X)*y, y, X}, 'alpha', 0.1, 'type', 'cal');
%! bootci (1999, @mldivide, X, y);
%! bootci (1999, @mldivide, X, y, 'alpha', 0.1);
%! bootci (1999, {@mldivide, X, y}, 'alpha', 0.1);
%! bootci (1999, {@mldivide, X, y}, 'alpha', 0.1, 'type', 'norm');
%! bootci (1999, {@mldivide, X, y}, 'alpha', 0.1, 'type', 'per');
%! bootci (1999, {@mldivide, X, y}, 'alpha', 0.1, 'type', 'basic');
%! bootci (1999, {@mldivide, X, y}, 'alpha', 0.1, 'type', 'bca');
%! bootci (1999, {@mldivide, X, y}, 'alpha', 0.1, 'type', 'stud');
%! bootci (1999, {@mldivide, X, y}, 'alpha', 0.1, 'type', 'cal');
%! catch
%! warning ('on', 'bootknife:parallel')
%! rethrow (lasterror)
Expand Down
34 changes: 25 additions & 9 deletions inst/bootclust.m
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@
% and skewness
switch (nalpha)
case 1
% No adjustements made
% No adjustments made
probs = repmat (probs, m, 1);
case 2
% Create distribution functions
Expand Down Expand Up @@ -800,6 +800,8 @@ function print_output (stats, nboot, nalpha, alpha, probs, m, bootfun_str, ...
%!
%! % 95% expanded BCa bootstrap confidence intervals for the mean
%! bootclust (data, 1999, @mean);
%!
%! % Please be patient, the calculations will be completed soon...

%!demo
%!
Expand All @@ -812,6 +814,8 @@ function print_output (stats, nboot, nalpha, alpha, probs, m, bootfun_str, ...
%! % 95% expanded BCa bootstrap confidence intervals for the mean with
%! % cluster resampling
%! bootclust (data, 1999, @mean, [0.025,0.975], clustid);
%!
%! % Please be patient, the calculations will be completed soon...

%!demo
%!
Expand All @@ -822,6 +826,8 @@ function print_output (stats, nboot, nalpha, alpha, probs, m, bootfun_str, ...
%! % 90% equal-tailed percentile bootstrap confidence intervals for
%! % the variance
%! bootclust (data, 1999, {@var, 1}, 0.1);
%!
%! % Please be patient, the calculations will be completed soon...

%!demo
%!
Expand All @@ -834,6 +840,8 @@ function print_output (stats, nboot, nalpha, alpha, probs, m, bootfun_str, ...
%! % 90% equal-tailed percentile bootstrap confidence intervals for
%! % the variance
%! bootclust (data, 1999, {@var, 1}, 0.1, clustid);
%!
%! % Please be patient, the calculations will be completed soon...

%!demo
%!
Expand All @@ -843,6 +851,8 @@ function print_output (stats, nboot, nalpha, alpha, probs, m, bootfun_str, ...
%!
%! % 90% BCa bootstrap confidence intervals for the variance
%! bootclust (data, 1999, {@var, 1}, [0.05 0.95]);
%!
%! % Please be patient, the calculations will be completed soon...

%!demo
%!
Expand All @@ -854,14 +864,18 @@ function print_output (stats, nboot, nalpha, alpha, probs, m, bootfun_str, ...
%!
%! % 90% BCa bootstrap confidence intervals for the variance
%! bootclust (data, 1999, {@var, 1}, [0.05 0.95], clustid);
%!
%! % Please be patient, the calculations will be completed soon...

%!demo
%!
%! % Input dataset
%! y = randn (20,1); x = randn (20,1); X = [ones(20,1), x];
%!
%! % 90% BCa confidence interval for regression coefficients
%! bootclust ({y,X}, 1999, @(y,X) X\y, [0.05 0.95]); % Could also use @regress
%! bootclust ({X,y}, 1999, @mldivide, [0.05 0.95]);
%!
%! % Please be patient, the calculations will be completed soon...

%!demo
%!
Expand All @@ -870,7 +884,9 @@ function print_output (stats, nboot, nalpha, alpha, probs, m, bootfun_str, ...
%! clustid = [1;1;1;1;2;2;2;3;3;3;3;4;4;4;4;4;5;5;5;6];
%!
%! % 90% BCa confidence interval for regression coefficients
%! bootclust ({y,X}, 1999, @(y,X) X\y, [0.05 0.95], clustid);
%! bootclust ({X,y}, 1999, @mldivide, [0.05 0.95], clustid);
%!
%! % Please be patient, the calculations will be completed soon...

%!demo
%!
Expand Down Expand Up @@ -951,12 +967,12 @@ function print_output (stats, nboot, nalpha, alpha, probs, m, bootfun_str, ...
%! y = randn (20,1); x = randn (20,1); X = [ones(20,1), x];
%! stats = bootclust ({x,y}, 1999, @cor);
%! stats = bootclust ({x,y}, 1999, @cor, [], clustid);
%! stats = bootclust ({y,x}, 1999, @(y,x) pinv(x)*y); % Could use @regress
%! stats = bootclust ({y,X}, 1999, @(y,X) pinv(X)*y);
%! stats = bootclust ({y,X}, 1999, @(y,X) pinv(X)*y, [], clustid);
%! stats = bootclust ({y,X}, 1999, @(y,X) pinv(X)*y, [], clustid, true);
%! stats = bootclust ({y,X}, 1999, @(y,X) pinv(X)*y, [], clustid, true, 1);
%! stats = bootclust ({y,X}, 1999, @(y,X) pinv(X)*y, [.05,.95], clustid);
%! stats = bootclust ({x,y}, 1999, @mldivide);
%! stats = bootclust ({X,y}, 1999, @mldivide);
%! stats = bootclust ({X,y}, 1999, @mldivide, [], clustid);
%! stats = bootclust ({X,y}, 1999, @mldivide, [], clustid, true);
%! stats = bootclust ({X,y}, 1999, @mldivide, [], clustid, true, 1);
%! stats = bootclust ({X,y}, 1999, @mldivide, [.05,.95], clustid);

%!test
%! % Air conditioning failure times in Table 1.2 of Davison A.C. and
Expand Down
25 changes: 19 additions & 6 deletions inst/bootknife.m
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,8 @@ function print_output (stats, nboot, alpha, l, m, bootfun_str, strata)
%!
%! % 95% expanded BCa bootstrap confidence intervals for the mean
%! bootknife (data, 1999, @mean);
%!
%! % Please be patient, the calculations will be completed soon...

%!demo
%!
Expand Down Expand Up @@ -1081,6 +1083,8 @@ function print_output (stats, nboot, alpha, l, m, bootfun_str, strata)
%! % 90% equal-tailed percentile bootstrap confidence intervals for
%! % the variance
%! bootknife (data, 1999, {@var, 1}, 0.1);
%!
%! % Please be patient, the calculations will be completed soon...

%!demo
%!
Expand All @@ -1090,6 +1094,8 @@ function print_output (stats, nboot, alpha, l, m, bootfun_str, strata)
%!
%! % 90% BCa bootstrap confidence intervals for the variance
%! bootknife (data, 1999, {@var, 1}, [0.05 0.95]);
%!
%! % Please be patient, the calculations will be completed soon...

%!demo
%!
Expand Down Expand Up @@ -1120,7 +1126,12 @@ function print_output (stats, nboot, alpha, l, m, bootfun_str, strata)
%! y = randn (20,1); x = randn (20,1); X = [ones(20,1), x];
%!
%! % 90% BCa confidence interval for regression coefficients
%! bootknife ({y,X}, 1999, @(y,X) X\y, [0.05 0.95]); % Could also use @regress
%! bootknife ({X,y}, 1999, @mldivide, [0.05 0.95]);
%!
%! % N.B: Consider using either the 'bootwild', 'bootbayes' or 'bootlm'
%! % functions for bootstrapping linear regression problems instead
%!
%! % Please be patient, the calculations will be completed soon...

%!demo
%!
Expand Down Expand Up @@ -1226,6 +1237,8 @@ function print_output (stats, nboot, alpha, l, m, bootfun_str, strata)
%! %<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
%!
%! end
%!
%! % Please be patient, the calculations will be completed soon...

%!demo
%!
Expand Down Expand Up @@ -1496,11 +1509,11 @@ function print_output (stats, nboot, alpha, l, m, bootfun_str, strata)
%! y = randn (20,1); x = randn (20,1); X = [ones(20,1), x];
%! stats = bootknife ({x,y}, 1999, @cor);
%! stats = bootknife ({x,y}, 1999, @cor, [], strata);
%! stats = bootknife ({y,x}, 1999, @(y,x) pinv(x)*y); % Could use @regress
%! stats = bootknife ({y,X}, 1999, @(y,X) pinv(X)*y);
%! stats = bootknife ({y,X}, 1999, @(y,X) pinv(X)*y, [], strata);
%! stats = bootknife ({y,X}, 1999, @(y,X) pinv(X)*y, [], strata, 2);
%! stats = bootknife ({y,X}, 1999, @(y,X) pinv(X)*y, [.05,.95], strata);
%! stats = bootknife ({x,y}, 1999, @mldivide);
%! stats = bootknife ({X,y}, 1999, @mldivide);
%! stats = bootknife ({X,y}, 1999, @mldivide, [], strata);
%! stats = bootknife ({X,y}, 1999, @mldivide, [], strata, 2);
%! stats = bootknife ({X,y}, 1999, @mldivide, [.05,.95], strata);
%! catch
%! warning ('on', 'bootknife:parallel')
%! rethrow (lasterror)
Expand Down
40 changes: 20 additions & 20 deletions test/test_script.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
y = randn (20,1); x = randn (20,1); X = [ones(20,1), x];
stats = bootknife ({x,y}, 2000, @cor);
stats = bootknife ({x,y}, 2000, @cor, [], strata);
stats = bootknife ({y,x}, 2000, @(y,x) pinv(x)*y); % Could also use @regress
stats = bootknife ({y,X}, 2000, @(y,X) pinv(X)*y);
stats = bootknife ({y,X}, 2000, @(y,X) pinv(X)*y, [], strata);
stats = bootknife ({y,X}, 2000, @(y,X) pinv(X)*y, [], strata, 2);
stats = bootknife ({y,X}, 2000, @(y,X) pinv(X)*y, [.05,.95], strata);
stats = bootknife ({x,y}, 2000, @mldivide);
stats = bootknife ({X,y}, 2000, @mldivide);
stats = bootknife ({X,y}, 2000, @mldivide, [], strata);
stats = bootknife ({X,y}, 2000, @mldivide, [], strata, 2);
stats = bootknife ({X,y}, 2000, @mldivide, [.05,.95], strata);

% bootclust
% bootclust:test:1
Expand Down Expand Up @@ -101,12 +101,12 @@
y = randn (20,1); x = randn (20,1); X = [ones(20,1), x];
stats = bootclust ({x,y}, 1999, @cor);
stats = bootclust ({x,y}, 1999, @cor, [], clustid);
stats = bootclust ({y,x}, 1999, @(y,x) pinv(x)*y); % Could use @regress
stats = bootclust ({y,X}, 1999, @(y,X) pinv(X)*y);
stats = bootclust ({y,X}, 1999, @(y,X) pinv(X)*y, [], clustid);
stats = bootclust ({y,X}, 1999, @(y,X) pinv(X)*y, [], clustid, true);
stats = bootclust ({y,X}, 1999, @(y,X) pinv(X)*y, [], clustid, true, 1);
stats = bootclust ({y,X}, 1999, @(y,X) pinv(X)*y, [.05,.95], clustid);
stats = bootclust ({x,y}, 1999, @mldivide);
stats = bootclust ({X,y}, 1999, @mldivide);
stats = bootclust ({X,y}, 1999, @mldivide, [], clustid);
stats = bootclust ({X,y}, 1999, @mldivide, [], clustid, true);
stats = bootclust ({X,y}, 1999, @mldivide, [], clustid, true, 1);
stats = bootclust ({X,y}, 1999, @mldivide, [.05,.95], clustid);

% bootci
% bootci:test:1
Expand Down Expand Up @@ -155,15 +155,15 @@
y = randn (20,1); x = randn (20,1); X = [ones(20,1),x];
bootci (1999, @cor, x, y);
bootci (1999, {@cor, x, y}, 'strata', g);
bootci (1999, @(y,X) pinv(X)*y, y, X);
bootci (1999, @(y,X) pinv(X)*y, y, X, 'alpha', 0.1);
bootci (1999, {@(y,X) pinv(X)*y, y, X}, 'alpha', 0.1);
bootci (1999, {@(y,X) pinv(X)*y, y, X}, 'alpha', 0.1, 'type', 'norm');
bootci (1999, {@(y,X) pinv(X)*y, y, X}, 'alpha', 0.1, 'type', 'per');
bootci (1999, {@(y,X) pinv(X)*y, y, X}, 'alpha', 0.1, 'type', 'basic');
bootci (1999, {@(y,X) pinv(X)*y, y, X}, 'alpha', 0.1, 'type', 'bca');
bootci (1999, {@(y,X) pinv(X)*y, y, X}, 'alpha', 0.1, 'type', 'stud');
bootci (1999, {@(y,X) pinv(X)*y, y, X}, 'alpha', 0.1, 'type', 'cal');
bootci (1999, @mldivide, X, y);
bootci (1999, @mldivide, X, y, 'alpha', 0.1);
bootci (1999, {@mldivide, X, y}, 'alpha', 0.1);
bootci (1999, {@mldivide, X, y}, 'alpha', 0.1, 'type', 'norm');
bootci (1999, {@mldivide, X, y}, 'alpha', 0.1, 'type', 'per');
bootci (1999, {@mldivide, X, y}, 'alpha', 0.1, 'type', 'basic');
bootci (1999, {@mldivide, X, y}, 'alpha', 0.1, 'type', 'bca');
bootci (1999, {@mldivide, X, y}, 'alpha', 0.1, 'type', 'stud');
bootci (1999, {@mldivide, X, y}, 'alpha', 0.1, 'type', 'cal');

% bootstrp
y = randn (20,1);
Expand Down

0 comments on commit 786200d

Please sign in to comment.