From 786200dcbb1b6e923399312c18baaf8faf1b0129 Mon Sep 17 00:00:00 2001 From: acp29 Date: Sat, 13 Apr 2024 19:53:53 +0100 Subject: [PATCH] changed demos and tests of case resampling for regression to use builtin function @mldivide --- DESCRIPTION | 4 ++-- inst/bootci.m | 39 ++++++++++++++++++++++++++++++--------- inst/bootclust.m | 34 +++++++++++++++++++++++++--------- inst/bootknife.m | 25 +++++++++++++++++++------ test/test_script.m | 40 ++++++++++++++++++++-------------------- 5 files changed, 96 insertions(+), 46 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b24ce14b..0ec67d96 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 maintainer: Andrew Penn title: A statistics package with a variety of resampling tools diff --git a/inst/bootci.m b/inst/bootci.m index 18e842b1..a8938690 100755 --- a/inst/bootci.m +++ b/inst/bootci.m @@ -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 %! @@ -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 %! @@ -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 %! @@ -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 %! @@ -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) diff --git a/inst/bootclust.m b/inst/bootclust.m index de8567e5..f7a7bda2 100755 --- a/inst/bootclust.m +++ b/inst/bootclust.m @@ -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 @@ -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 %! @@ -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 %! @@ -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 %! @@ -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 %! @@ -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 %! @@ -854,6 +864,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], clustid); +%! +%! % Please be patient, the calculations will be completed soon... %!demo %! @@ -861,7 +873,9 @@ function print_output (stats, nboot, nalpha, alpha, probs, m, bootfun_str, ... %! 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 %! @@ -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 %! @@ -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 diff --git a/inst/bootknife.m b/inst/bootknife.m index ef1f9d43..898dea02 100755 --- a/inst/bootknife.m +++ b/inst/bootknife.m @@ -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 %! @@ -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 %! @@ -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 %! @@ -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 %! @@ -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 %! @@ -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) diff --git a/test/test_script.m b/test/test_script.m index 67f3deda..3741651b 100755 --- a/test/test_script.m +++ b/test/test_script.m @@ -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 @@ -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 @@ -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);