=============================================================================== About this build: this rebuild has been done as part of reproduce.debian.net where we aim to reproduce Debian binary packages distributed via ftp.debian.org, by rebuilding using the exact same packages as the original build on the buildds, as described in the relevant .buildinfo file from buildinfos.debian.net. For more information please go to https://reproduce.debian.net or join #debian-reproducible on irc.debian.org =============================================================================== Preparing download of sources for /srv/rebuilderd/tmp/rebuilderdG1cRAZ/inputs/octave-statistics_2.0.0-1_amd64.buildinfo Source: octave-statistics Version: 2.0.0-1 rebuilderd-worker node: osuosl44-amd64 +------------------------------------------------------------------------------+ | Downloading sources Sun, 04 Oct 2026 23:32:26 +0000 | +------------------------------------------------------------------------------+ Get:1 https://deb.debian.org/debian trixie InRelease [140 kB] Get:2 https://deb.debian.org/debian-security trixie-security InRelease [43.4 kB] Get:3 https://deb.debian.org/debian trixie-updates InRelease [47.3 kB] Get:4 https://deb.debian.org/debian trixie-proposed-updates InRelease [57.7 kB] Get:5 https://deb.debian.org/debian trixie-backports InRelease [54.0 kB] Get:6 https://deb.debian.org/debian forky InRelease [151 kB] Get:7 https://deb.debian.org/debian sid InRelease [193 kB] Get:8 https://deb.debian.org/debian experimental InRelease [91.7 kB] Get:9 https://deb.debian.org/debian trixie/main Sources [10.5 MB] Get:10 https://deb.debian.org/debian trixie/non-free-firmware Sources [6,552 B] Get:11 https://deb.debian.org/debian-security trixie-security/non-free-firmware Sources [696 B] Get:12 https://deb.debian.org/debian-security trixie-security/main Sources [239 kB] Get:13 https://deb.debian.org/debian trixie-updates/main Sources [1,840 B] Get:14 https://deb.debian.org/debian trixie-proposed-updates/main Sources [127 kB] Get:15 https://deb.debian.org/debian trixie-backports/main Sources [317 kB] Get:16 https://deb.debian.org/debian trixie-backports/non-free-firmware Sources [3,412 B] Get:17 https://deb.debian.org/debian forky/non-free-firmware Sources [7,872 B] Get:18 https://deb.debian.org/debian forky/main Sources [11.3 MB] Get:19 https://deb.debian.org/debian sid/non-free-firmware Sources [10.6 kB] Get:20 https://deb.debian.org/debian sid/main Sources [12.0 MB] Get:21 https://deb.debian.org/debian experimental/non-free-firmware Sources [2,568 B] Get:22 https://deb.debian.org/debian experimental/main Sources [386 kB] Fetched 35.7 MB in 4s (9,800 kB/s) Reading package lists... 'https://deb.debian.org/debian/pool/main/o/octave-statistics/octave-statistics_2.0.0-1.dsc' octave-statistics_2.0.0-1.dsc 2455 SHA256:cbaf54b8a1bceb68ead184350f0277cabfc686a6f3f411aca0b7451e7f1269e3 'https://deb.debian.org/debian/pool/main/o/octave-statistics/octave-statistics_2.0.0.orig.tar.gz' octave-statistics_2.0.0.orig.tar.gz 4865827 SHA256:e82c1d6957885ee444adc91e35defd00665ec3c3e1eeae0bd39f89b7b28a6490 'https://deb.debian.org/debian/pool/main/o/octave-statistics/octave-statistics_2.0.0-1.debian.tar.xz' octave-statistics_2.0.0-1.debian.tar.xz 11008 SHA256:1857cf343a438680acb3df23381a93fd47d844d8cbcbbc9cd13e0289e7051c81 e82c1d6957885ee444adc91e35defd00665ec3c3e1eeae0bd39f89b7b28a6490 octave-statistics_2.0.0.orig.tar.gz 1857cf343a438680acb3df23381a93fd47d844d8cbcbbc9cd13e0289e7051c81 octave-statistics_2.0.0-1.debian.tar.xz cbaf54b8a1bceb68ead184350f0277cabfc686a6f3f411aca0b7451e7f1269e3 octave-statistics_2.0.0-1.dsc +------------------------------------------------------------------------------+ | Calling debrebuild Sun, 04 Oct 2026 23:32:31 +0000 | +------------------------------------------------------------------------------+ Rebuilding octave-statistics=2.0.0-1 in /srv/rebuilderd/tmp/rebuilderdG1cRAZ/inputs now. + /usr/bin/debrebuild --buildresult=/srv/rebuilderd/tmp/rebuilderdG1cRAZ/out --builder=sbuild+unshare --cache=/srv/rebuilderd/cache -- /srv/rebuilderd/tmp/rebuilderdG1cRAZ/inputs/octave-statistics_2.0.0-1_amd64.buildinfo /srv/rebuilderd/tmp/rebuilderdG1cRAZ/inputs/octave-statistics_2.0.0-1_amd64.buildinfo contains a GPG signature which has NOT been validated Using defined Build-Path: /build/reproducible-path/octave-statistics-2.0.0 I: verifying dsc... successful! Get:1 http://deb.debian.org/debian unstable InRelease [193 kB] Get:2 http://snapshot.debian.org/archive/debian/20261003T143013Z unstable InRelease [193 kB] Get:3 http://deb.debian.org/debian unstable/main amd64 Packages [10.8 MB] Get:4 http://snapshot.debian.org/archive/debian/20261003T143013Z unstable/main amd64 Packages [10.8 MB] Fetched 21.9 MB in 2s (8803 kB/s) Reading package lists... W: http://snapshot.debian.org/archive/debian/20261003T143013Z/dists/unstable/InRelease: Loading /etc/apt/trusted.gpg from deprecated option Dir::Etc::Trusted Get:1 http://deb.debian.org/debian unstable/main amd64 libabsl20260526 amd64 20260526.0-2+b1 [584 kB] Get:2 http://deb.debian.org/debian unstable/main amd64 libacl1 amd64 2.4.0-1 [37.1 kB] Get:3 http://deb.debian.org/debian unstable/main amd64 aglfn all 1.7+git20191031.4036a9c-2 [30.5 kB] Get:4 http://deb.debian.org/debian unstable/main amd64 libasound2-data all 1.2.16.1-2 [19.4 kB] Get:5 http://deb.debian.org/debian unstable/main amd64 libasound2t64 amd64 1.2.16.1-2 [417 kB] Get:6 http://deb.debian.org/debian unstable/main amd64 libaom3 amd64 3.14.1-1 [1923 kB] Get:7 http://deb.debian.org/debian unstable/main amd64 appstream amd64 1.2.1-1 [629 kB] Get:8 http://deb.debian.org/debian unstable/main amd64 libappstream5 amd64 1.2.1-1 [260 kB] Get:9 http://deb.debian.org/debian unstable/main amd64 libapt-pkg7.0 amd64 3.3.3 [1284 kB] Get:10 http://deb.debian.org/debian unstable/main amd64 libarpack2t64 amd64 3.9.1-6+b2 [105 kB] Get:11 http://deb.debian.org/debian unstable/main amd64 libattr1 amd64 1:2.6.0-1 [24.7 kB] Get:12 http://deb.debian.org/debian unstable/main amd64 libaudit-common all 1:4.2.1-1 [13.3 kB] Get:13 http://deb.debian.org/debian unstable/main amd64 libaudit1 amd64 1:4.2.1-1 [59.6 kB] Get:14 http://deb.debian.org/debian unstable/main amd64 autoconf all 2.73-2 [516 kB] Get:15 http://deb.debian.org/debian unstable/main amd64 automake all 1:1.19-2 [891 kB] Get:16 http://deb.debian.org/debian unstable/main amd64 autotools-dev all 20240727.1+nmu1 [60.0 kB] Get:17 http://deb.debian.org/debian unstable/main amd64 libavahi-client3 amd64 0.8-18 [49.2 kB] Get:18 http://deb.debian.org/debian unstable/main amd64 libavahi-common-data amd64 0.8-18 [113 kB] Get:19 http://deb.debian.org/debian unstable/main amd64 libavahi-common3 amd64 0.8-18 [45.2 kB] Get:20 http://deb.debian.org/debian unstable/main amd64 base-files amd64 14.2 [88.0 kB] Get:21 http://deb.debian.org/debian unstable/main amd64 base-passwd amd64 3.6.8 [54.6 kB] Get:22 http://deb.debian.org/debian unstable/main amd64 bash amd64 5.3-4 [1582 kB] Get:23 http://deb.debian.org/debian unstable/main amd64 binutils amd64 2.47-6 [288 kB] Get:24 http://deb.debian.org/debian unstable/main amd64 binutils-common amd64 2.47-6 [2686 kB] Get:25 http://deb.debian.org/debian unstable/main amd64 binutils-x86-64-linux-gnu amd64 2.47-6 [1132 kB] Get:26 http://deb.debian.org/debian unstable/main amd64 build-essential amd64 12.12 [4624 B] Get:27 http://deb.debian.org/debian unstable/main amd64 bzip2 amd64 1.0.8-6+b2 [40.4 kB] Get:28 http://deb.debian.org/debian unstable/main amd64 ca-certificates all 20260816 [134 kB] Get:29 http://deb.debian.org/debian unstable/main amd64 cme all 1.049-1 [72.6 kB] Get:30 http://deb.debian.org/debian unstable/main amd64 coreutils amd64 9.10-1 [3142 kB] Get:31 http://deb.debian.org/debian unstable/main amd64 dash amd64 0.5.12-12 [98.5 kB] Get:32 http://deb.debian.org/debian unstable/main amd64 debconf all 1.5.92 [123 kB] Get:33 http://deb.debian.org/debian unstable/main amd64 debhelper all 14.5 [944 kB] Get:34 http://deb.debian.org/debian unstable/main amd64 debianutils amd64 5.24 [93.3 kB] Get:35 http://deb.debian.org/debian unstable/main amd64 dh-autoreconf all 23 [12.7 kB] Get:36 http://deb.debian.org/debian unstable/main amd64 dh-octave all 1.18.1 [26.5 kB] Get:37 http://deb.debian.org/debian unstable/main amd64 dh-octave-autopkgtest all 1.18.1 [11.6 kB] Get:38 http://deb.debian.org/debian unstable/main amd64 diffstat amd64 1.69-1 [34.9 kB] Get:39 http://deb.debian.org/debian unstable/main amd64 diffutils amd64 1:3.12-1 [405 kB] Get:40 http://deb.debian.org/debian unstable/main amd64 distro-info-data all 2026.08.20-1 [6292 B] Get:41 http://deb.debian.org/debian unstable/main amd64 dpkg amd64 1.23.11 [1214 kB] Get:42 http://deb.debian.org/debian unstable/main amd64 dpkg-dev all 1.23.11 [1005 kB] Get:43 http://deb.debian.org/debian unstable/main amd64 dwz amd64 0.17-1 [109 kB] Get:44 http://deb.debian.org/debian unstable/main amd64 comerr-dev amd64 2.1-1.47.4-1+b2 [51.2 kB] Get:45 http://deb.debian.org/debian unstable/main amd64 file amd64 1:5.47-4 [43.0 kB] Get:46 http://deb.debian.org/debian unstable/main amd64 fontconfig amd64 2.17.1-5 [191 kB] Get:47 http://deb.debian.org/debian unstable/main amd64 fontconfig-config amd64 2.17.1-5 [56.1 kB] Get:48 http://deb.debian.org/debian unstable/main amd64 fonts-freefont-otf all 20211204+svn4273-4 [4322 kB] Get:49 http://deb.debian.org/debian unstable/main amd64 cpp-16 amd64 16.2.0-3 [1272 B] Get:50 http://deb.debian.org/debian unstable/main amd64 cpp-16-x86-64-linux-gnu amd64 16.2.0-3 [13.7 MB] Get:51 http://deb.debian.org/debian unstable/main amd64 g++-16 amd64 16.2.0-3 [35.4 kB] Get:52 http://deb.debian.org/debian unstable/main amd64 g++-16-x86-64-linux-gnu amd64 16.2.0-3 [15.1 MB] Get:53 http://deb.debian.org/debian unstable/main amd64 gcc-16 amd64 16.2.0-3 [538 kB] Get:54 http://deb.debian.org/debian unstable/main amd64 gcc-16-base amd64 16.2.0-3 [38.7 kB] Get:55 http://deb.debian.org/debian unstable/main amd64 gcc-16-x86-64-linux-gnu amd64 16.2.0-3 [26.6 MB] Get:56 http://deb.debian.org/debian unstable/main amd64 gfortran-16 amd64 16.2.0-3 [16.5 kB] Get:57 http://deb.debian.org/debian unstable/main amd64 gfortran-16-x86-64-linux-gnu amd64 16.2.0-3 [14.5 MB] Get:58 http://deb.debian.org/debian unstable/main amd64 libasan8 amd64 16.2.0-3 [2888 kB] Get:59 http://deb.debian.org/debian unstable/main amd64 libatomic1 amd64 16.2.0-3 [10.4 kB] Get:60 http://deb.debian.org/debian unstable/main amd64 cpp amd64 4:16.1.0-3 [1568 B] Get:61 http://deb.debian.org/debian unstable/main amd64 cpp-x86-64-linux-gnu amd64 4:16.1.0-3 [4472 B] Get:62 http://deb.debian.org/debian unstable/main amd64 g++ amd64 4:16.1.0-3 [1340 B] Get:63 http://deb.debian.org/debian unstable/main amd64 g++-x86-64-linux-gnu amd64 4:16.1.0-3 [1196 B] Get:64 http://deb.debian.org/debian unstable/main amd64 gcc amd64 4:16.1.0-3 [5148 B] Get:65 http://deb.debian.org/debian unstable/main amd64 gcc-x86-64-linux-gnu amd64 4:16.1.0-3 [1432 B] Get:66 http://deb.debian.org/debian unstable/main amd64 gfortran amd64 4:16.1.0-3 [1436 B] Get:67 http://deb.debian.org/debian unstable/main amd64 gfortran-x86-64-linux-gnu amd64 4:16.1.0-3 [1276 B] Get:68 http://deb.debian.org/debian unstable/main amd64 autopoint all 1.0-5 [820 kB] Get:69 http://deb.debian.org/debian unstable/main amd64 gettext amd64 1.0-5 [2704 kB] Get:70 http://deb.debian.org/debian unstable/main amd64 gettext-base amd64 1.0-5 [334 kB] Get:71 http://deb.debian.org/debian unstable/main amd64 gpg amd64 2.4.9-7+b1 [665 kB] Get:72 http://deb.debian.org/debian unstable/main amd64 gpgconf amd64 2.4.9-7+b1 [130 kB] Get:73 http://deb.debian.org/debian unstable/main amd64 gnuplot-data all 6.0.3+dfsg1-1 [73.0 kB] Get:74 http://deb.debian.org/debian unstable/main amd64 gnuplot-nox amd64 6.0.3+dfsg1-1 [928 kB] Get:75 http://deb.debian.org/debian unstable/main amd64 grep amd64 3.12-1 [443 kB] Get:76 http://deb.debian.org/debian unstable/main amd64 groff-base amd64 1.24.2-2 [1365 kB] Get:77 http://deb.debian.org/debian unstable/main amd64 gzip amd64 1.14-1 [149 kB] Get:78 http://deb.debian.org/debian unstable/main amd64 hdf5-helpers amd64 2.2.0+repack-5 [27.6 kB] Get:79 http://deb.debian.org/debian unstable/main amd64 hostname amd64 3.25 [11.0 kB] Get:80 http://deb.debian.org/debian unstable/main amd64 init-system-helpers all 1.69+nmu3 [37.3 kB] Get:81 http://deb.debian.org/debian unstable/main amd64 intltool-debian all 0.35.0+20060710.6 [22.9 kB] Get:82 http://deb.debian.org/debian unstable/main amd64 iso-codes all 4.20.1-1 [3319 kB] Get:83 http://deb.debian.org/debian unstable/main amd64 krb5-multidev amd64 1.22.1-3 [125 kB] Get:84 http://deb.debian.org/debian unstable/main amd64 libaec-dev amd64 1.1.7-1 [25.2 kB] Get:85 http://deb.debian.org/debian unstable/main amd64 libaec0 amd64 1.1.7-1 [22.3 kB] Get:86 http://deb.debian.org/debian unstable/main amd64 libalgorithm-c3-perl all 0.11-2 [10.8 kB] Get:87 http://deb.debian.org/debian unstable/main amd64 libaliased-perl all 0.34-3 [13.5 kB] Get:88 http://deb.debian.org/debian unstable/main amd64 libapp-cmd-perl all 0.340-1 [63.8 kB] Get:89 http://deb.debian.org/debian unstable/main amd64 libapt-pkg-perl amd64 0.1.43+b1 [68.3 kB] Get:90 http://deb.debian.org/debian unstable/main amd64 libarchive-zip-perl all 1.68-1 [104 kB] Get:91 http://deb.debian.org/debian unstable/main amd64 libarray-intspan-perl all 2.004-2 [25.7 kB] Get:92 http://deb.debian.org/debian unstable/main amd64 libassuan9 amd64 3.0.2-2+b2 [60.7 kB] Get:93 http://deb.debian.org/debian unstable/main amd64 libavif16 amd64 1.4.2-1 [147 kB] Get:94 http://deb.debian.org/debian unstable/main amd64 libamdhip64-6 amd64 6.4.3-5 [9385 kB] Get:95 http://deb.debian.org/debian unstable/main amd64 libamd-comgr3 amd64 7.0.2+dfsg-3 [13.9 MB] Get:96 http://deb.debian.org/debian unstable/main amd64 dh-strip-nondeterminism all 1.15.1-1 [6020 B] Get:97 http://deb.debian.org/debian unstable/main amd64 libamd3 amd64 1:7.14.1+dfsg-1 [49.9 kB] Get:98 http://deb.debian.org/debian unstable/main amd64 bsdextrautils amd64 2.42.4-1 [103 kB] Get:99 http://snapshot.debian.org/archive/debian/20261003T143013Z unstable/main amd64 findutils amd64 4.11.0-2 [782 kB] Get:100 http://snapshot.debian.org/archive/debian/20261003T143013Z unstable/main amd64 ibverbs-providers amd64 65.0-1 [424 kB] Fetched 135 MB in 2s (65.2 MB/s) dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libasound2-data_1.2.16.1-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/dpkg_1.23.11_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libarray-intspan-perl_2.004-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/gettext_1.0-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/gnuplot-data_6.0.3+dfsg1-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libabsl20260526_20260526.0-2+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libapt-pkg-perl_0.1.43+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/cpp-16_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/dh-octave-autopkgtest_1.18.1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/hostname_3.25_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/debhelper_14.5_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libaom3_3.14.1-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/g++-16_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/fonts-freefont-otf_20211204+svn4273-4_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/appstream_1.2.1-1_amd64.deb' dpkg-name: info: moved 'libattr1_1%3a2.6.0-1_amd64.deb' to '/srv/rebuilderd/tmp/tmp2elpyi8z/libattr1_2.6.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/diffstat_1.69-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libavahi-common3_0.8-18_amd64.deb' dpkg-name: info: moved 'file_1%3a5.47-4_amd64.deb' to '/srv/rebuilderd/tmp/tmp2elpyi8z/file_5.47-4_amd64.deb' dpkg-name: info: moved 'diffutils_1%3a3.12-1_amd64.deb' to '/srv/rebuilderd/tmp/tmp2elpyi8z/diffutils_3.12-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/gpg_2.4.9-7+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/gnuplot-nox_6.0.3+dfsg1-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/bsdextrautils_2.42.4-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/build-essential_12.12_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/coreutils_9.10-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/gzip_1.14-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/ibverbs-providers_65.0-1_amd64.deb' dpkg-name: info: moved 'gfortran_4%3a16.1.0-3_amd64.deb' to '/srv/rebuilderd/tmp/tmp2elpyi8z/gfortran_16.1.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/gfortran-16-x86-64-linux-gnu_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/findutils_4.11.0-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/debianutils_5.24_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libarpack2t64_3.9.1-6+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/dwz_0.17-1_amd64.deb' dpkg-name: info: moved 'cpp-x86-64-linux-gnu_4%3a16.1.0-3_amd64.deb' to '/srv/rebuilderd/tmp/tmp2elpyi8z/cpp-x86-64-linux-gnu_16.1.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libacl1_2.4.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/base-passwd_3.6.8_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/autotools-dev_20240727.1+nmu1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/intltool-debian_0.35.0+20060710.6_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/dh-strip-nondeterminism_1.15.1-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/aglfn_1.7+git20191031.4036a9c-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/binutils-common_2.47-6_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/grep_3.12-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/dash_0.5.12-12_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/gcc-16_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/debconf_1.5.92_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/comerr-dev_2.1-1.47.4-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/autopoint_1.0-5_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/fontconfig_2.17.1-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libassuan9_3.0.2-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libaliased-perl_0.34-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libamdhip64-6_6.4.3-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/fontconfig-config_2.17.1-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libaec-dev_1.1.7-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libappstream5_1.2.1-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libamd-comgr3_7.0.2+dfsg-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/g++-16-x86-64-linux-gnu_16.2.0-3_amd64.deb' dpkg-name: info: moved 'cpp_4%3a16.1.0-3_amd64.deb' to '/srv/rebuilderd/tmp/tmp2elpyi8z/cpp_16.1.0-3_amd64.deb' dpkg-name: info: moved 'gcc_4%3a16.1.0-3_amd64.deb' to '/srv/rebuilderd/tmp/tmp2elpyi8z/gcc_16.1.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libasan8_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libasound2t64_1.2.16.1-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/dpkg-dev_1.23.11_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/krb5-multidev_1.22.1-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libavif16_1.4.2-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libatomic1_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/hdf5-helpers_2.2.0+repack-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/gpgconf_2.4.9-7+b1_amd64.deb' dpkg-name: info: moved 'gfortran-x86-64-linux-gnu_4%3a16.1.0-3_amd64.deb' to '/srv/rebuilderd/tmp/tmp2elpyi8z/gfortran-x86-64-linux-gnu_16.1.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libavahi-client3_0.8-18_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libarchive-zip-perl_1.68-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/cpp-16-x86-64-linux-gnu_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libavahi-common-data_0.8-18_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/dh-octave_1.18.1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/gettext-base_1.0-5_amd64.deb' dpkg-name: info: moved 'automake_1%3a1.19-2_all.deb' to '/srv/rebuilderd/tmp/tmp2elpyi8z/automake_1.19-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/binutils-x86-64-linux-gnu_2.47-6_amd64.deb' dpkg-name: info: moved 'g++_4%3a16.1.0-3_amd64.deb' to '/srv/rebuilderd/tmp/tmp2elpyi8z/g++_16.1.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/gcc-16-base_16.2.0-3_amd64.deb' dpkg-name: info: moved 'libaudit-common_1%3a4.2.1-1_all.deb' to '/srv/rebuilderd/tmp/tmp2elpyi8z/libaudit-common_4.2.1-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/groff-base_1.24.2-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/iso-codes_4.20.1-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/distro-info-data_2026.08.20-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/autoconf_2.73-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/gfortran-16_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/bash_5.3-4_amd64.deb' dpkg-name: info: moved 'libaudit1_1%3a4.2.1-1_amd64.deb' to '/srv/rebuilderd/tmp/tmp2elpyi8z/libaudit1_4.2.1-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libalgorithm-c3-perl_0.11-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/bzip2_1.0.8-6+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/cme_1.049-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/ca-certificates_20260816_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/binutils_2.47-6_amd64.deb' dpkg-name: info: moved 'libamd3_1%3a7.14.1+dfsg-1_amd64.deb' to '/srv/rebuilderd/tmp/tmp2elpyi8z/libamd3_7.14.1+dfsg-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/gcc-16-x86-64-linux-gnu_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libapp-cmd-perl_0.340-1_all.deb' dpkg-name: info: moved 'gcc-x86-64-linux-gnu_4%3a16.1.0-3_amd64.deb' to '/srv/rebuilderd/tmp/tmp2elpyi8z/gcc-x86-64-linux-gnu_16.1.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libapt-pkg7.0_3.3.3_amd64.deb' dpkg-name: info: moved 'g++-x86-64-linux-gnu_4%3a16.1.0-3_amd64.deb' to '/srv/rebuilderd/tmp/tmp2elpyi8z/g++-x86-64-linux-gnu_16.1.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/libaec0_1.1.7-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/init-system-helpers_1.69+nmu3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/base-files_14.2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp2elpyi8z/dh-autoreconf_23_all.deb' Get:1 http://deb.debian.org/debian unstable/main amd64 libbinutils amd64 2.47-6 [562 kB] Get:2 http://deb.debian.org/debian unstable/main amd64 libctf-nobfd0 amd64 2.47-6 [166 kB] Get:3 http://deb.debian.org/debian unstable/main amd64 libctf0 amd64 2.47-6 [98.2 kB] Get:4 http://deb.debian.org/debian unstable/main amd64 libbrotli-dev amd64 1.2.0-4+b1 [324 kB] Get:5 http://deb.debian.org/debian unstable/main amd64 libbrotli1 amd64 1.2.0-4+b1 [312 kB] Get:6 http://deb.debian.org/debian unstable/main amd64 libbz2-1.0 amd64 1.0.8-6+b2 [39.9 kB] Get:7 http://deb.debian.org/debian unstable/main amd64 libcairo2 amd64 1.18.4-3+b1 [543 kB] Get:8 http://deb.debian.org/debian unstable/main amd64 libdebconfclient0 amd64 0.283 [7572 B] Get:9 http://deb.debian.org/debian unstable/main amd64 libcups2t64 amd64 2.4.18-1 [252 kB] Get:10 http://deb.debian.org/debian unstable/main amd64 libcurl4-gnutls amd64 8.23.0~rc2-1 [463 kB] Get:11 http://deb.debian.org/debian unstable/main amd64 libcurl4-openssl-dev amd64 8.23.0~rc2-1 [600 kB] Get:12 http://deb.debian.org/debian unstable/main amd64 libcurl4t64 amd64 8.23.0~rc2-1 [467 kB] Get:13 http://deb.debian.org/debian unstable/main amd64 libdav1d7 amd64 1.5.4-1 [583 kB] Get:14 http://deb.debian.org/debian unstable/main amd64 libdb5.3t64 amd64 5.3.28+dfsg2-11+b1 [709 kB] Get:15 http://deb.debian.org/debian unstable/main amd64 libdbus-1-3 amd64 1.16.2-8 [184 kB] Get:16 http://deb.debian.org/debian unstable/main amd64 libdebhelper-perl all 14.5 [77.7 kB] Get:17 http://deb.debian.org/debian unstable/main amd64 libdistro-info-perl all 1.19 [5360 B] Get:18 http://deb.debian.org/debian unstable/main amd64 libdouble-conversion3 amd64 3.4.0-1+b1 [40.7 kB] Get:19 http://deb.debian.org/debian unstable/main amd64 libdpkg-perl all 1.23.11 [650 kB] Get:20 http://deb.debian.org/debian unstable/main amd64 libduktape207 amd64 2.7.0-2+b3 [134 kB] Get:21 http://deb.debian.org/debian unstable/main amd64 libcom-err2 amd64 1.47.4-1+b2 [19.5 kB] Get:22 http://deb.debian.org/debian unstable/main amd64 libelf1t64 amd64 0.196-1 [61.2 kB] Get:23 http://deb.debian.org/debian unstable/main amd64 libcc1-0 amd64 16.2.0-3 [46.1 kB] Get:24 http://deb.debian.org/debian unstable/main amd64 libblas-dev amd64 3.12.1-8 [219 kB] Get:25 http://deb.debian.org/debian unstable/main amd64 libblas3 amd64 3.12.1-8 [206 kB] Get:26 http://deb.debian.org/debian unstable/main amd64 libb-hooks-endofscope-perl all 0.28-2 [17.6 kB] Get:27 http://deb.debian.org/debian unstable/main amd64 libb-hooks-op-check-perl amd64 0.22-3+b5 [10.6 kB] Get:28 http://deb.debian.org/debian unstable/main amd64 libb-keywords-perl all 1.29-1 [12.5 kB] Get:29 http://deb.debian.org/debian unstable/main amd64 libb2-1 amd64 0.98.1-1.1+b3 [42.0 kB] Get:30 http://deb.debian.org/debian unstable/main amd64 libberkeleydb-perl amd64 0.66-2+b2 [122 kB] Get:31 http://deb.debian.org/debian unstable/main amd64 libboolean-perl all 0.46-3 [9924 B] Get:32 http://deb.debian.org/debian unstable/main amd64 libbsd0 amd64 0.12.2-3 [132 kB] Get:33 http://deb.debian.org/debian unstable/main amd64 libcap-ng0 amd64 0.9.6-1 [19.0 kB] Get:34 http://deb.debian.org/debian unstable/main amd64 libcapture-tiny-perl all 0.50-1 [24.6 kB] Get:35 http://deb.debian.org/debian unstable/main amd64 libcarp-assert-more-perl all 2.9.0-1 [21.9 kB] Get:36 http://deb.debian.org/debian unstable/main amd64 libcgi-pm-perl all 4.72-1 [217 kB] Get:37 http://deb.debian.org/debian unstable/main amd64 libclass-c3-perl all 0.35-2 [21.0 kB] Get:38 http://deb.debian.org/debian unstable/main amd64 libclass-data-inheritable-perl all 0.10-1 [8632 B] Get:39 http://deb.debian.org/debian unstable/main amd64 libclass-inspector-perl all 1.36-3 [17.5 kB] Get:40 http://deb.debian.org/debian unstable/main amd64 libclass-load-perl all 0.25-2 [15.3 kB] Get:41 http://deb.debian.org/debian unstable/main amd64 libclass-method-modifiers-perl all 2.15-1 [18.0 kB] Get:42 http://deb.debian.org/debian unstable/main amd64 libclass-singleton-perl all 1.6-2 [12.5 kB] Get:43 http://deb.debian.org/debian unstable/main amd64 libclass-tiny-perl all 1.008-2 [18.6 kB] Get:44 http://deb.debian.org/debian unstable/main amd64 libclass-xsaccessor-perl amd64 1.19-4+b7 [36.7 kB] Get:45 http://deb.debian.org/debian unstable/main amd64 libclone-choose-perl all 0.010-2 [8676 B] Get:46 http://deb.debian.org/debian unstable/main amd64 libclone-perl amd64 0.50-1+b2 [21.6 kB] Get:47 http://deb.debian.org/debian unstable/main amd64 libclone-pp-perl all 1.08-2 [9224 B] Get:48 http://deb.debian.org/debian unstable/main amd64 libconfig-inifiles-perl all 3.003000-1 [45.4 kB] Get:49 http://deb.debian.org/debian unstable/main amd64 libconfig-model-backend-yaml-perl all 2.134-2 [10.8 kB] Get:50 http://deb.debian.org/debian unstable/main amd64 libconfig-model-dpkg-perl all 3.027 [200 kB] Get:51 http://deb.debian.org/debian unstable/main amd64 libconfig-model-perl all 2.167-1 [414 kB] Get:52 http://deb.debian.org/debian unstable/main amd64 libconfig-tiny-perl all 2.30-1 [18.9 kB] Get:53 http://deb.debian.org/debian unstable/main amd64 libconst-fast-perl all 0.014-2 [8792 B] Get:54 http://deb.debian.org/debian unstable/main amd64 libconvert-binhex-perl all 1.125-3 [27.4 kB] Get:55 http://deb.debian.org/debian unstable/main amd64 libcpanel-json-xs-perl amd64 4.51-1 [144 kB] Get:56 http://deb.debian.org/debian unstable/main amd64 libdata-dpath-perl all 0.60-1 [41.8 kB] Get:57 http://deb.debian.org/debian unstable/main amd64 libdata-messagepack-perl amd64 1.02-3+b1 [32.1 kB] Get:58 http://deb.debian.org/debian unstable/main amd64 libdata-optlist-perl all 0.115-1 [10.4 kB] Get:59 http://deb.debian.org/debian unstable/main amd64 libdata-section-perl all 0.200008-1 [13.1 kB] Get:60 http://deb.debian.org/debian unstable/main amd64 libdata-validate-domain-perl all 0.15-1 [11.9 kB] Get:61 http://deb.debian.org/debian unstable/main amd64 libdata-validate-ip-perl all 0.31-1 [20.6 kB] Get:62 http://deb.debian.org/debian unstable/main amd64 libdata-validate-uri-perl all 0.07-3 [11.0 kB] Get:63 http://deb.debian.org/debian unstable/main amd64 libdatetime-format-builder-perl all 0.8300-1 [63.8 kB] Get:64 http://deb.debian.org/debian unstable/main amd64 libdatetime-format-iso8601-perl all 0.19-1 [21.8 kB] Get:65 http://deb.debian.org/debian unstable/main amd64 libdatetime-format-rfc3339-perl all 1.10.0-1 [8660 B] Get:66 http://deb.debian.org/debian unstable/main amd64 libdatetime-format-strptime-perl all 1.8000-1 [33.8 kB] Get:67 http://deb.debian.org/debian unstable/main amd64 libdatetime-locale-perl all 1:1.46-1 [3429 kB] Get:68 http://deb.debian.org/debian unstable/main amd64 libdatetime-perl amd64 2:1.67-1 [118 kB] Get:69 http://deb.debian.org/debian unstable/main amd64 libdatetime-timezone-perl all 1:2.71-1+2026e [261 kB] Get:70 http://deb.debian.org/debian unstable/main amd64 libdatrie1 amd64 0.2.14-2 [39.1 kB] Get:71 http://deb.debian.org/debian unstable/main amd64 libde265-0 amd64 1.1.3-1+b1 [219 kB] Get:72 http://deb.debian.org/debian unstable/main amd64 libdecor-0-0 amd64 0.2.5-1+b1 [15.8 kB] Get:73 http://deb.debian.org/debian unstable/main amd64 libdeflate0 amd64 1.25-1 [48.0 kB] Get:74 http://deb.debian.org/debian unstable/main amd64 libdevel-callchecker-perl amd64 0.009-3+b1 [15.7 kB] Get:75 http://deb.debian.org/debian unstable/main amd64 libdevel-size-perl amd64 0.87-1+b1 [24.1 kB] Get:76 http://deb.debian.org/debian unstable/main amd64 libdevel-stacktrace-perl all 2.0500-1 [26.4 kB] Get:77 http://deb.debian.org/debian unstable/main amd64 libdrm-amdgpu1 amd64 2.4.134-3 [23.3 kB] Get:78 http://deb.debian.org/debian unstable/main amd64 libdrm-common all 2.4.134-3 [7860 B] Get:79 http://deb.debian.org/debian unstable/main amd64 libdrm-intel1 amd64 2.4.134-3 [64.2 kB] Get:80 http://deb.debian.org/debian unstable/main amd64 libdrm2 amd64 2.4.134-3 [38.5 kB] Get:81 http://deb.debian.org/debian unstable/main amd64 libdynaloader-functions-perl all 0.004-2 [12.2 kB] Get:82 http://deb.debian.org/debian unstable/main amd64 libedit2 amd64 3.1-20260512-1 [93.6 kB] Get:83 http://deb.debian.org/debian unstable/main amd64 libemail-address-xs-perl amd64 1.05-1+b5 [29.5 kB] Get:84 http://deb.debian.org/debian unstable/main amd64 libencode-locale-perl all 1.05-3 [12.9 kB] Get:85 http://deb.debian.org/debian unstable/main amd64 liberror-perl all 0.17030-1 [26.9 kB] Get:86 http://deb.debian.org/debian unstable/main amd64 libegl1 amd64 1.7.0-3+b1 [35.0 kB] Get:87 http://deb.debian.org/debian unstable/main amd64 libcrypt1 amd64 1:4.5.2+20251210-1 [100 kB] Get:88 http://deb.debian.org/debian unstable/main amd64 libclang-common-21-dev amd64 1:21.1.8-13 [769 kB] Get:89 http://deb.debian.org/debian unstable/main amd64 libegl-mesa0 amd64 26.2.4-1 [140 kB] Get:90 http://deb.debian.org/debian unstable/main amd64 libcamd3 amd64 1:7.14.1+dfsg-1 [46.9 kB] Get:91 http://deb.debian.org/debian unstable/main amd64 libccolamd3 amd64 1:7.14.1+dfsg-1 [49.2 kB] Get:92 http://deb.debian.org/debian unstable/main amd64 libcholmod5 amd64 1:7.14.1+dfsg-1 [713 kB] Get:93 http://deb.debian.org/debian unstable/main amd64 libcolamd3 amd64 1:7.14.1+dfsg-1 [41.9 kB] Get:94 http://deb.debian.org/debian unstable/main amd64 libcxsparse4 amd64 1:7.14.1+dfsg-1 [97.7 kB] Get:95 http://deb.debian.org/debian unstable/main amd64 libblkid1 amd64 2.42.4-1 [185 kB] Get:96 http://snapshot.debian.org/archive/debian/20261003T143013Z unstable/main amd64 libc-bin amd64 2.43-6 [620 kB] Get:97 http://snapshot.debian.org/archive/debian/20261003T143013Z unstable/main amd64 libc-dev-bin amd64 2.43-6 [39.5 kB] Get:98 http://snapshot.debian.org/archive/debian/20261003T143013Z unstable/main amd64 libc-gconv-modules-extra amd64 2.43-6 [1096 kB] Get:99 http://snapshot.debian.org/archive/debian/20261003T143013Z unstable/main amd64 libc6 amd64 2.43-6 [1867 kB] Get:100 http://snapshot.debian.org/archive/debian/20261003T143013Z unstable/main amd64 libc6-dev amd64 2.43-6 [2070 kB] Fetched 21.1 MB in 2s (12.3 MB/s) dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libclass-singleton-perl_1.6-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libb-hooks-op-check-perl_0.22-3+b5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libcarp-assert-more-perl_2.9.0-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdata-validate-uri-perl_0.07-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libclass-xsaccessor-perl_1.19-4+b7_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libcap-ng0_0.9.6-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libcpanel-json-xs-perl_4.51-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdatetime-format-builder-perl_0.8300-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libboolean-perl_0.46-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libclass-inspector-perl_1.36-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libemail-address-xs-perl_1.05-1+b5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libblas3_3.12.1-8_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libconst-fast-perl_0.014-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libcapture-tiny-perl_0.50-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libc-bin_2.43-6_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libbsd0_0.12.2-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdata-messagepack-perl_1.02-3+b1_amd64.deb' dpkg-name: info: moved 'libclang-common-21-dev_1%3a21.1.8-13_amd64.deb' to '/srv/rebuilderd/tmp/tmp4vyfip5_/libclang-common-21-dev_21.1.8-13_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libbrotli-dev_1.2.0-4+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdb5.3t64_5.3.28+dfsg2-11+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libconfig-model-dpkg-perl_3.027_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libegl-mesa0_26.2.4-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libcairo2_1.18.4-3+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdebconfclient0_0.283_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libedit2_3.1-20260512-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libbrotli1_1.2.0-4+b1_amd64.deb' dpkg-name: info: moved 'libcolamd3_1%3a7.14.1+dfsg-1_amd64.deb' to '/srv/rebuilderd/tmp/tmp4vyfip5_/libcolamd3_7.14.1+dfsg-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libclass-data-inheritable-perl_0.10-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdata-section-perl_0.200008-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libcups2t64_2.4.18-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdistro-info-perl_1.19_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdevel-stacktrace-perl_2.0500-1_all.deb' dpkg-name: info: moved 'libcholmod5_1%3a7.14.1+dfsg-1_amd64.deb' to '/srv/rebuilderd/tmp/tmp4vyfip5_/libcholmod5_7.14.1+dfsg-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libberkeleydb-perl_0.66-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdevel-callchecker-perl_0.009-3+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libcurl4t64_8.23.0~rc2-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdecor-0-0_0.2.5-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libconfig-model-backend-yaml-perl_2.134-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdatetime-format-iso8601-perl_0.19-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libclone-pp-perl_1.08-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libencode-locale-perl_1.05-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libblkid1_2.42.4-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libclone-choose-perl_0.010-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libclone-perl_0.50-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libclass-tiny-perl_1.008-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libcurl4-gnutls_8.23.0~rc2-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdatetime-format-rfc3339-perl_1.10.0-1_all.deb' dpkg-name: info: moved 'libdatetime-timezone-perl_1%3a2.71-1+2026e_all.deb' to '/srv/rebuilderd/tmp/tmp4vyfip5_/libdatetime-timezone-perl_2.71-1+2026e_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libc-dev-bin_2.43-6_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libduktape207_2.7.0-2+b3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libcc1-0_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdrm-common_2.4.134-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdata-optlist-perl_0.115-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libbinutils_2.47-6_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdata-validate-ip-perl_0.31-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdrm-intel1_2.4.134-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdouble-conversion3_3.4.0-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libb-hooks-endofscope-perl_0.28-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdata-validate-domain-perl_0.15-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdbus-1-3_1.16.2-8_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libc6_2.43-6_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libctf-nobfd0_2.47-6_amd64.deb' dpkg-name: info: moved 'libcrypt1_1%3a4.5.2+20251210-1_amd64.deb' to '/srv/rebuilderd/tmp/tmp4vyfip5_/libcrypt1_4.5.2+20251210-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libc-gconv-modules-extra_2.43-6_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libcurl4-openssl-dev_8.23.0~rc2-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libelf1t64_0.196-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/liberror-perl_0.17030-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libconvert-binhex-perl_1.125-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libb-keywords-perl_1.29-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdrm-amdgpu1_2.4.134-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdynaloader-functions-perl_0.004-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libb2-1_0.98.1-1.1+b3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdata-dpath-perl_0.60-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdatetime-format-strptime-perl_1.8000-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libc6-dev_2.43-6_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libconfig-inifiles-perl_3.003000-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libclass-c3-perl_0.35-2_all.deb' dpkg-name: info: moved 'libdatetime-locale-perl_1%3a1.46-1_all.deb' to '/srv/rebuilderd/tmp/tmp4vyfip5_/libdatetime-locale-perl_1.46-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdatrie1_0.2.14-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libconfig-tiny-perl_2.30-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libcom-err2_1.47.4-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libctf0_2.47-6_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdav1d7_1.5.4-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libde265-0_1.1.3-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libconfig-model-perl_2.167-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libbz2-1.0_1.0.8-6+b2_amd64.deb' dpkg-name: info: moved 'libdatetime-perl_2%3a1.67-1_amd64.deb' to '/srv/rebuilderd/tmp/tmp4vyfip5_/libdatetime-perl_1.67-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libclass-method-modifiers-perl_2.15-1_all.deb' dpkg-name: info: moved 'libcamd3_1%3a7.14.1+dfsg-1_amd64.deb' to '/srv/rebuilderd/tmp/tmp4vyfip5_/libcamd3_7.14.1+dfsg-1_amd64.deb' dpkg-name: info: moved 'libccolamd3_1%3a7.14.1+dfsg-1_amd64.deb' to '/srv/rebuilderd/tmp/tmp4vyfip5_/libccolamd3_7.14.1+dfsg-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libcgi-pm-perl_4.72-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libegl1_1.7.0-3+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libclass-load-perl_0.25-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdrm2_2.4.134-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdeflate0_1.25-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdevel-size-perl_0.87-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libblas-dev_3.12.1-8_amd64.deb' dpkg-name: info: moved 'libcxsparse4_1%3a7.14.1+dfsg-1_amd64.deb' to '/srv/rebuilderd/tmp/tmp4vyfip5_/libcxsparse4_7.14.1+dfsg-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdpkg-perl_1.23.11_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp4vyfip5_/libdebhelper-perl_14.5_all.deb' Get:1 http://deb.debian.org/debian unstable/main amd64 libgprofng0 amd64 2.47-6 [846 kB] Get:2 http://deb.debian.org/debian unstable/main amd64 libexpat1 amd64 2.8.5-2 [132 kB] Get:3 http://deb.debian.org/debian unstable/main amd64 libfftw3-bin amd64 3.3.11-1 [46.6 kB] Get:4 http://deb.debian.org/debian unstable/main amd64 libfftw3-dev amd64 3.3.11-1 [2063 kB] Get:5 http://deb.debian.org/debian unstable/main amd64 libfftw3-double3 amd64 3.3.11-1 [713 kB] Get:6 http://deb.debian.org/debian unstable/main amd64 libfftw3-long3 amd64 3.3.11-1 [313 kB] Get:7 http://deb.debian.org/debian unstable/main amd64 libfftw3-quad3 amd64 3.3.11-1 [554 kB] Get:8 http://deb.debian.org/debian unstable/main amd64 libfftw3-single3 amd64 3.3.11-1 [738 kB] Get:9 http://deb.debian.org/debian unstable/main amd64 libflac14 amd64 1.5.0+ds-5+b1 [179 kB] Get:10 http://deb.debian.org/debian unstable/main amd64 libfltk-gl1.4 amd64 1.4.4-4 [85.6 kB] Get:11 http://deb.debian.org/debian unstable/main amd64 libfltk1.4 amd64 1.4.4-4 [595 kB] Get:12 http://deb.debian.org/debian unstable/main amd64 libfontconfig1 amd64 2.17.1-5 [132 kB] Get:13 http://deb.debian.org/debian unstable/main amd64 libfreetype6 amd64 2.14.3+dfsg-2 [492 kB] Get:14 http://deb.debian.org/debian unstable/main amd64 libfribidi0 amd64 1.0.16-5+b1 [26.2 kB] Get:15 http://deb.debian.org/debian unstable/main amd64 libfuse3-4 amd64 3.18.3-1 [109 kB] Get:16 http://deb.debian.org/debian unstable/main amd64 libgcc-16-dev amd64 16.2.0-3 [2782 kB] Get:17 http://deb.debian.org/debian unstable/main amd64 libgcc-s1 amd64 16.2.0-3 [74.0 kB] Get:18 http://deb.debian.org/debian unstable/main amd64 libgfortran-16-dev amd64 16.2.0-3 [921 kB] Get:19 http://deb.debian.org/debian unstable/main amd64 libgfortran5 amd64 16.2.0-3 [879 kB] Get:20 http://deb.debian.org/debian unstable/main amd64 libgomp1 amd64 16.2.0-3 [151 kB] Get:21 http://deb.debian.org/debian unstable/main amd64 libhwasan0 amd64 16.2.0-3 [1580 kB] Get:22 http://deb.debian.org/debian unstable/main amd64 libgdbm-compat4t64 amd64 1.26-1+b2 [52.0 kB] Get:23 http://deb.debian.org/debian unstable/main amd64 libgdbm6t64 amd64 1.26-1+b2 [77.7 kB] Get:24 http://deb.debian.org/debian unstable/main amd64 libgl2ps1.4 amd64 1.4.2+dfsg1-4+b1 [43.0 kB] Get:25 http://deb.debian.org/debian unstable/main amd64 libglib2.0-0t64 amd64 2.90.0-1 [1618 kB] Get:26 http://deb.debian.org/debian unstable/main amd64 libglpk40 amd64 5.0-3 [392 kB] Get:27 http://deb.debian.org/debian unstable/main amd64 libgmp-dev amd64 2:6.3.0+dfsg-5+b2 [641 kB] Get:28 http://deb.debian.org/debian unstable/main amd64 libgmp10 amd64 2:6.3.0+dfsg-5+b2 [560 kB] Get:29 http://deb.debian.org/debian unstable/main amd64 libgmpxx4ldbl amd64 2:6.3.0+dfsg-5+b2 [328 kB] Get:30 http://deb.debian.org/debian unstable/main amd64 libgnutls-dane0t64 amd64 3.8.13-1 [496 kB] Get:31 http://deb.debian.org/debian unstable/main amd64 libgnutls28-dev amd64 3.8.13-1 [1479 kB] Get:32 http://deb.debian.org/debian unstable/main amd64 libgnutls30t64 amd64 3.8.13-1 [1546 kB] Get:33 http://deb.debian.org/debian unstable/main amd64 libgraphicsmagick++-q16-12t64 amd64 1.4+really1.3.48-1 [129 kB] Get:34 http://deb.debian.org/debian unstable/main amd64 libgraphicsmagick-q16-3t64 amd64 1.4+really1.3.48-1 [1308 kB] Get:35 http://deb.debian.org/debian unstable/main amd64 libgraphite2-3 amd64 1.3.15-2 [75.8 kB] Get:36 http://deb.debian.org/debian unstable/main amd64 libharfbuzz0b amd64 12.3.2-2+b2 [513 kB] Get:37 http://deb.debian.org/debian unstable/main amd64 libhdf5-320 amd64 2.2.0+repack-5 [2177 kB] Get:38 http://deb.debian.org/debian unstable/main amd64 libhdf5-cpp-320 amd64 2.2.0+repack-5 [144 kB] Get:39 http://deb.debian.org/debian unstable/main amd64 libhdf5-dev amd64 2.2.0+repack-5 [4248 kB] Get:40 http://deb.debian.org/debian unstable/main amd64 libhdf5-fortran-320 amd64 2.2.0+repack-5 [123 kB] Get:41 http://deb.debian.org/debian unstable/main amd64 libhdf5-hl-320 amd64 2.2.0+repack-5 [82.0 kB] Get:42 http://deb.debian.org/debian unstable/main amd64 libhdf5-hl-cpp-320 amd64 2.2.0+repack-5 [27.4 kB] Get:43 http://deb.debian.org/debian unstable/main amd64 libhdf5-hl-fortran-320 amd64 2.2.0+repack-5 [50.1 kB] Get:44 http://deb.debian.org/debian unstable/main amd64 libhdf5-openmpi-320 amd64 2.2.0+repack-5 [2273 kB] Get:45 http://deb.debian.org/debian unstable/main amd64 libgssapi-krb5-2 amd64 1.22.1-3 [137 kB] Get:46 http://deb.debian.org/debian unstable/main amd64 libgssrpc4t64 amd64 1.22.1-3 [58.3 kB] Get:47 http://deb.debian.org/debian unstable/main amd64 libesmtp6 amd64 1.1.0-3.2+b2 [59.3 kB] Get:48 http://deb.debian.org/debian unstable/main amd64 libeval-closure-perl all 0.14-3 [11.2 kB] Get:49 http://deb.debian.org/debian unstable/main amd64 libevdev2 amd64 1.13.7+dfsg-1 [33.2 kB] Get:50 http://deb.debian.org/debian unstable/main amd64 libevent-2.1-7t64 amd64 2.1.13-stable-1 [183 kB] Get:51 http://deb.debian.org/debian unstable/main amd64 libevent-core-2.1-7t64 amd64 2.1.13-stable-1 [133 kB] Get:52 http://deb.debian.org/debian unstable/main amd64 libevent-pthreads-2.1-7t64 amd64 2.1.13-stable-1 [53.8 kB] Get:53 http://deb.debian.org/debian unstable/main amd64 libexception-class-perl all 1.45-1 [34.6 kB] Get:54 http://deb.debian.org/debian unstable/main amd64 libexporter-lite-perl all 0.09-2 [10.7 kB] Get:55 http://deb.debian.org/debian unstable/main amd64 libexporter-tiny-perl all 1.006003-1 [37.5 kB] Get:56 http://deb.debian.org/debian unstable/main amd64 libfabric1 amd64 2.1.0-1.1+b2 [716 kB] Get:57 http://deb.debian.org/debian unstable/main amd64 libfeature-compat-class-perl all 0.08-1 [12.4 kB] Get:58 http://deb.debian.org/debian unstable/main amd64 libfeature-compat-try-perl all 0.05-1 [10.4 kB] Get:59 http://deb.debian.org/debian unstable/main amd64 libffi8 amd64 3.8.0-2 [32.5 kB] Get:60 http://deb.debian.org/debian unstable/main amd64 libfile-basedir-perl all 0.09-2 [15.1 kB] Get:61 http://deb.debian.org/debian unstable/main amd64 libfile-find-rule-perl all 0.35-1 [25.9 kB] Get:62 http://deb.debian.org/debian unstable/main amd64 libfile-homedir-perl all 1.006-2 [42.4 kB] Get:63 http://deb.debian.org/debian unstable/main amd64 libfile-libmagic-perl amd64 1.23-2+b3 [31.3 kB] Get:64 http://deb.debian.org/debian unstable/main amd64 libfile-listing-perl all 6.16-1 [12.4 kB] Get:65 http://deb.debian.org/debian unstable/main amd64 libfile-sharedir-perl all 1.118-3 [16.0 kB] Get:66 http://deb.debian.org/debian unstable/main amd64 libfile-which-perl all 1.27-2 [15.1 kB] Get:67 http://deb.debian.org/debian unstable/main amd64 libfont-ttf-perl all 1.06-2 [318 kB] Get:68 http://deb.debian.org/debian unstable/main amd64 libfyaml0 amd64 0.9.4-1 [312 kB] Get:69 http://deb.debian.org/debian unstable/main amd64 libgav1-2 amd64 0.20.0-2+b2 [372 kB] Get:70 http://deb.debian.org/debian unstable/main amd64 libgcrypt20 amd64 1.12.4-2 [936 kB] Get:71 http://deb.debian.org/debian unstable/main amd64 libgd3 amd64 2.3.3-14 [126 kB] Get:72 http://deb.debian.org/debian unstable/main amd64 libgetopt-long-descriptive-perl all 0.117-1 [29.8 kB] Get:73 http://deb.debian.org/debian unstable/main amd64 libglu1-mesa amd64 9.0.2-1.1+b4 [191 kB] Get:74 http://deb.debian.org/debian unstable/main amd64 libgl-dev amd64 1.7.0-3+b1 [99.8 kB] Get:75 http://deb.debian.org/debian unstable/main amd64 libgl1 amd64 1.7.0-3+b1 [87.1 kB] Get:76 http://deb.debian.org/debian unstable/main amd64 libglvnd0 amd64 1.7.0-3+b1 [54.3 kB] Get:77 http://deb.debian.org/debian unstable/main amd64 libglx-dev amd64 1.7.0-3+b1 [15.0 kB] Get:78 http://deb.debian.org/debian unstable/main amd64 libglx0 amd64 1.7.0-3+b1 [34.9 kB] Get:79 http://deb.debian.org/debian unstable/main amd64 libgpg-error0 amd64 1.61-5 [93.1 kB] Get:80 http://deb.debian.org/debian unstable/main amd64 libgudev-1.0-0 amd64 238-7+b2 [14.4 kB] Get:81 http://deb.debian.org/debian unstable/main amd64 libhash-merge-perl all 0.302-1 [14.7 kB] Get:82 http://deb.debian.org/debian unstable/main amd64 libheif-plugin-dav1d amd64 1.23.4-1+b1 [21.4 kB] Get:83 http://deb.debian.org/debian unstable/main amd64 libheif-plugin-libde265 amd64 1.23.4-1+b1 [18.9 kB] Get:84 http://deb.debian.org/debian unstable/main amd64 libheif1 amd64 1.23.4-1+b1 [867 kB] Get:85 http://deb.debian.org/debian unstable/main amd64 libhtml-form-perl all 6.13-1 [32.6 kB] Get:86 http://deb.debian.org/debian unstable/main amd64 libhtml-html5-entities-perl all 0.004-3 [21.0 kB] Get:87 http://deb.debian.org/debian unstable/main amd64 libhtml-parser-perl amd64 3.83-2+b2 [99.6 kB] Get:88 http://deb.debian.org/debian unstable/main amd64 libhtml-tagset-perl all 3.24-1 [14.7 kB] Get:89 http://deb.debian.org/debian unstable/main amd64 libhtml-tokeparser-simple-perl all 3.16-4 [39.1 kB] Get:90 http://deb.debian.org/debian unstable/main amd64 libhtml-tree-perl all 5.07-3 [211 kB] Get:91 http://deb.debian.org/debian unstable/main amd64 libhttp-cookies-perl all 6.12-2 [19.2 kB] Get:92 http://deb.debian.org/debian unstable/main amd64 libhttp-date-perl all 6.08-1 [12.1 kB] Get:93 http://deb.debian.org/debian unstable/main amd64 libhttp-message-perl all 7.04-1 [80.6 kB] Get:94 http://deb.debian.org/debian unstable/main amd64 libhttp-negotiate-perl all 6.01-2 [13.1 kB] Get:95 http://deb.debian.org/debian unstable/main amd64 libgbm1 amd64 26.2.4-1 [57.0 kB] Get:96 http://deb.debian.org/debian unstable/main amd64 libgl1-mesa-dri amd64 26.2.4-1 [37.8 kB] Get:97 http://deb.debian.org/debian unstable/main amd64 libglx-mesa0 amd64 26.2.4-1 [132 kB] Get:98 http://deb.debian.org/debian unstable/main amd64 libhogweed6t64 amd64 3.10.2-1+b1 [335 kB] Get:99 http://deb.debian.org/debian unstable/main amd64 libhsa-runtime64-1 amd64 6.4.3+dfsg-5 [678 kB] Get:100 http://deb.debian.org/debian unstable/main amd64 libfile-stripnondeterminism-perl all 1.15.1-1 [17.1 kB] Fetched 38.9 MB in 2s (20.1 MB/s) dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libevdev2_1.13.7+dfsg-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libexporter-tiny-perl_1.006003-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfont-ttf-perl_1.06-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfftw3-dev_3.3.11-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhsa-runtime64-1_6.4.3+dfsg-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libffi8_3.8.0-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgetopt-long-descriptive-perl_0.117-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfabric1_2.1.0-1.1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libglu1-mesa_9.0.2-1.1+b4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhttp-negotiate-perl_6.01-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libglvnd0_1.7.0-3+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libexpat1_2.8.5-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libexporter-lite-perl_0.09-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgudev-1.0-0_238-7+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhdf5-hl-fortran-320_2.2.0+repack-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhttp-date-perl_6.08-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfltk1.4_1.4.4-4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgdbm6t64_1.26-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfile-find-rule-perl_0.35-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfile-listing-perl_6.16-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfftw3-quad3_3.3.11-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgssrpc4t64_1.22.1-3_amd64.deb' dpkg-name: info: moved 'libgmp-dev_2%3a6.3.0+dfsg-5+b2_amd64.deb' to '/srv/rebuilderd/tmp/tmpg86ffd26/libgmp-dev_6.3.0+dfsg-5+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhttp-message-perl_7.04-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgl-dev_1.7.0-3+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libheif1_1.23.4-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libglx-dev_1.7.0-3+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libglx0_1.7.0-3+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libheif-plugin-libde265_1.23.4-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libharfbuzz0b_12.3.2-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfile-stripnondeterminism-perl_1.15.1-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libflac14_1.5.0+ds-5+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libeval-closure-perl_0.14-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhtml-tokeparser-simple-perl_3.16-4_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhdf5-dev_2.2.0+repack-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgpg-error0_1.61-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhash-merge-perl_0.302-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhtml-tagset-perl_3.24-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfftw3-bin_3.3.11-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfftw3-long3_3.3.11-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhogweed6t64_3.10.2-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfile-which-perl_1.27-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgdbm-compat4t64_1.26-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libevent-core-2.1-7t64_2.1.13-stable-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgraphicsmagick++-q16-12t64_1.4+really1.3.48-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfeature-compat-class-perl_0.08-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfile-sharedir-perl_1.118-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libevent-pthreads-2.1-7t64_2.1.13-stable-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgfortran5_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhdf5-fortran-320_2.2.0+repack-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhdf5-openmpi-320_2.2.0+repack-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgnutls-dane0t64_3.8.13-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libesmtp6_1.1.0-3.2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgomp1_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhtml-tree-perl_5.07-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhdf5-320_2.2.0+repack-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhwasan0_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgl1_1.7.0-3+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libexception-class-perl_1.45-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgcrypt20_1.12.4-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfftw3-double3_3.3.11-1_amd64.deb' dpkg-name: info: moved 'libgmpxx4ldbl_2%3a6.3.0+dfsg-5+b2_amd64.deb' to '/srv/rebuilderd/tmp/tmpg86ffd26/libgmpxx4ldbl_6.3.0+dfsg-5+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhtml-html5-entities-perl_0.004-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgav1-2_0.20.0-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgl2ps1.4_1.4.2+dfsg1-4+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhdf5-cpp-320_2.2.0+repack-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgnutls28-dev_3.8.13-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libheif-plugin-dav1d_1.23.4-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfile-libmagic-perl_1.23-2+b3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhtml-parser-perl_3.83-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhdf5-hl-320_2.2.0+repack-5_amd64.deb' dpkg-name: info: moved 'libgmp10_2%3a6.3.0+dfsg-5+b2_amd64.deb' to '/srv/rebuilderd/tmp/tmpg86ffd26/libgmp10_6.3.0+dfsg-5+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgl1-mesa-dri_26.2.4-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgcc-16-dev_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfyaml0_0.9.4-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libglx-mesa0_26.2.4-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libglib2.0-0t64_2.90.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgcc-s1_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgbm1_26.2.4-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfuse3-4_3.18.3-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgfortran-16-dev_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhdf5-hl-cpp-320_2.2.0+repack-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfreetype6_2.14.3+dfsg-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfontconfig1_2.17.1-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfile-homedir-perl_1.006-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgprofng0_2.47-6_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfribidi0_1.0.16-5+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libevent-2.1-7t64_2.1.13-stable-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfltk-gl1.4_1.4.4-4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhttp-cookies-perl_6.12-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libhtml-form-perl_6.13-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfile-basedir-perl_0.09-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfftw3-single3_3.3.11-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgraphite2-3_1.3.15-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libfeature-compat-try-perl_0.05-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgraphicsmagick-q16-3t64_1.4+really1.3.48-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgd3_2.3.3-14_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgnutls30t64_3.8.13-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libgssapi-krb5-2_1.22.1-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpg86ffd26/libglpk40_5.0-3_amd64.deb' Get:1 http://deb.debian.org/debian unstable/main amd64 libmarkdown2 amd64 2.2.7-2.1+b2 [36.5 kB] Get:2 http://deb.debian.org/debian unstable/main amd64 libmagic-mgc amd64 1:5.47-4 [345 kB] Get:3 http://deb.debian.org/debian unstable/main amd64 libmagic1t64 amd64 1:5.47-4 [111 kB] Get:4 http://deb.debian.org/debian unstable/main amd64 libitm1 amd64 16.2.0-3 [26.9 kB] Get:5 http://deb.debian.org/debian unstable/main amd64 liblsan0 amd64 16.2.0-3 [1281 kB] Get:6 http://deb.debian.org/debian unstable/main amd64 libhwy1t64 amd64 1.3.0-5.1 [694 kB] Get:7 http://deb.debian.org/debian unstable/main amd64 libhwloc-plugins amd64 2.15.0-2 [22.4 kB] Get:8 http://deb.debian.org/debian unstable/main amd64 libhwloc15 amd64 2.15.0-2 [178 kB] Get:9 http://deb.debian.org/debian unstable/main amd64 libicu78 amd64 78.3-2 [10.0 MB] Get:10 http://deb.debian.org/debian unstable/main amd64 libisl23 amd64 0.28-1 [667 kB] Get:11 http://deb.debian.org/debian unstable/main amd64 libjack-jackd2-0 amd64 1.9.22~dfsg-6 [284 kB] Get:12 http://deb.debian.org/debian unstable/main amd64 libjansson4 amd64 2.15.1-1 [65.6 kB] Get:13 http://deb.debian.org/debian unstable/main amd64 libjbig0 amd64 2.1-6.1+b3 [32.2 kB] Get:14 http://deb.debian.org/debian unstable/main amd64 libjxl0.11 amd64 0.11.2-5.1 [1273 kB] Get:15 http://deb.debian.org/debian unstable/main amd64 libkeyutils1 amd64 1.6.3-6+b2 [9348 B] Get:16 http://deb.debian.org/debian unstable/main amd64 libk5crypto3 amd64 1.22.1-3 [79.0 kB] Get:17 http://deb.debian.org/debian unstable/main amd64 libkadm5clnt-mit12 amd64 1.22.1-3 [40.3 kB] Get:18 http://deb.debian.org/debian unstable/main amd64 libkadm5srv-mit12 amd64 1.22.1-3 [54.1 kB] Get:19 http://deb.debian.org/debian unstable/main amd64 libkdb5-10t64 amd64 1.22.1-3 [41.3 kB] Get:20 http://deb.debian.org/debian unstable/main amd64 libkrb5-3 amd64 1.22.1-3 [335 kB] Get:21 http://deb.debian.org/debian unstable/main amd64 libkrb5-dev amd64 1.22.1-3 [14.0 kB] Get:22 http://deb.debian.org/debian unstable/main amd64 libkrb5support0 amd64 1.22.1-3 [31.1 kB] Get:23 http://deb.debian.org/debian unstable/main amd64 libmp3lame0 amd64 4.0-1 [289 kB] Get:24 http://deb.debian.org/debian unstable/main amd64 liblapack-dev amd64 3.12.1-8 [5230 kB] Get:25 http://deb.debian.org/debian unstable/main amd64 liblapack3 amd64 3.12.1-8 [2548 kB] Get:26 http://deb.debian.org/debian unstable/main amd64 liblcms2-2 amd64 2.19.1-1 [164 kB] Get:27 http://deb.debian.org/debian unstable/main amd64 liblerc4 amd64 4.2.0+ds-1 [203 kB] Get:28 http://deb.debian.org/debian unstable/main amd64 libice6 amd64 2:1.1.1-1+b2 [66.8 kB] Get:29 http://deb.debian.org/debian unstable/main amd64 libidn2-0 amd64 2.3.8-5 [109 kB] Get:30 http://deb.debian.org/debian unstable/main amd64 libidn2-dev amd64 2.3.8-5 [102 kB] Get:31 http://deb.debian.org/debian unstable/main amd64 libimagequant0 amd64 4.4.1-1+b2 [255 kB] Get:32 http://deb.debian.org/debian unstable/main amd64 libimport-into-perl all 1.002005-2 [11.3 kB] Get:33 http://deb.debian.org/debian unstable/main amd64 libindirect-perl amd64 0.39-2+b5 [27.3 kB] Get:34 http://deb.debian.org/debian unstable/main amd64 libinput-bin amd64 1.31.3-1 [28.0 kB] Get:35 http://deb.debian.org/debian unstable/main amd64 libinput10 amd64 1.31.3-1 [160 kB] Get:36 http://deb.debian.org/debian unstable/main amd64 libintl-perl all 1.37-1 [696 kB] Get:37 http://deb.debian.org/debian unstable/main amd64 libio-html-perl all 1.004-3 [16.2 kB] Get:38 http://deb.debian.org/debian unstable/main amd64 libio-interactive-perl all 1.027-1 [11.8 kB] Get:39 http://deb.debian.org/debian unstable/main amd64 libio-socket-ssl-perl all 2.099-1 [229 kB] Get:40 http://deb.debian.org/debian unstable/main amd64 libio-string-perl all 1.08-4 [12.1 kB] Get:41 http://deb.debian.org/debian unstable/main amd64 libio-stringy-perl all 2.113-2 [48.3 kB] Get:42 http://deb.debian.org/debian unstable/main amd64 libio-tiecombine-perl all 1.005-3 [10.8 kB] Get:43 http://deb.debian.org/debian unstable/main amd64 libipc-run3-perl all 0.049-1 [31.5 kB] Get:44 http://deb.debian.org/debian unstable/main amd64 libipc-system-simple-perl all 1.30-2 [26.8 kB] Get:45 http://deb.debian.org/debian unstable/main amd64 libiterator-perl all 0.03+ds1-2 [18.8 kB] Get:46 http://deb.debian.org/debian unstable/main amd64 libiterator-util-perl all 0.02+ds1-2 [14.0 kB] Get:47 http://deb.debian.org/debian unstable/main amd64 libjpeg-dev amd64 1:3.1.3-4 [78.8 kB] Get:48 http://deb.debian.org/debian unstable/main amd64 libjpeg62-turbo amd64 1:3.1.3-4 [213 kB] Get:49 http://deb.debian.org/debian unstable/main amd64 libjpeg62-turbo-dev amd64 1:3.1.3-4 [356 kB] Get:50 http://deb.debian.org/debian unstable/main amd64 libjson-maybexs-perl all 1.004008-1 [12.9 kB] Get:51 http://deb.debian.org/debian unstable/main amd64 libjson-perl all 4.10000-1 [87.5 kB] Get:52 http://deb.debian.org/debian unstable/main amd64 libksba8 amd64 1.8.1-1 [147 kB] Get:53 http://deb.debian.org/debian unstable/main amd64 liblingua-en-inflect-perl all 1.905-2 [52.7 kB] Get:54 http://deb.debian.org/debian unstable/main amd64 liblist-compare-perl all 0.55-2 [65.7 kB] Get:55 http://deb.debian.org/debian unstable/main amd64 liblist-moreutils-perl all 0.430-2 [46.9 kB] Get:56 http://deb.debian.org/debian unstable/main amd64 liblist-moreutils-xs-perl amd64 0.430-4+b3 [41.6 kB] Get:57 http://deb.debian.org/debian unstable/main amd64 liblist-someutils-perl all 0.59-1 [37.1 kB] Get:58 http://deb.debian.org/debian unstable/main amd64 liblist-someutils-xs-perl amd64 0.59-1+b1 [35.6 kB] Get:59 http://deb.debian.org/debian unstable/main amd64 liblist-utilsby-perl all 0.12-2 [15.5 kB] Get:60 http://deb.debian.org/debian unstable/main amd64 liblog-any-adapter-screen-perl all 0.141-2 [14.0 kB] Get:61 http://deb.debian.org/debian unstable/main amd64 liblog-any-perl all 1.720-1 [75.8 kB] Get:62 http://deb.debian.org/debian unstable/main amd64 liblog-log4perl-perl all 1.57-1 [367 kB] Get:63 http://deb.debian.org/debian unstable/main amd64 liblwp-mediatypes-perl all 6.04-2 [20.2 kB] Get:64 http://deb.debian.org/debian unstable/main amd64 liblwp-protocol-https-perl all 6.15-1 [10.7 kB] Get:65 http://deb.debian.org/debian unstable/main amd64 libmailtools-perl all 2.22-1 [88.8 kB] Get:66 http://deb.debian.org/debian unstable/main amd64 libmd0 amd64 1.3.0-1 [45.4 kB] Get:67 http://deb.debian.org/debian unstable/main amd64 libmime-tools-perl all 5.518-1 [205 kB] Get:68 http://deb.debian.org/debian unstable/main amd64 libmldbm-perl all 2.05-4 [16.8 kB] Get:69 http://deb.debian.org/debian unstable/main amd64 libmodule-implementation-perl all 0.09-2 [12.6 kB] Get:70 http://deb.debian.org/debian unstable/main amd64 libmodule-pluggable-perl all 6.4-1 [33.4 kB] Get:71 http://deb.debian.org/debian unstable/main amd64 libmodule-runtime-perl all 0.018-1 [17.8 kB] Get:72 http://deb.debian.org/debian unstable/main amd64 libmoo-perl all 2.005005-1 [58.0 kB] Get:73 http://deb.debian.org/debian unstable/main amd64 libmoox-aliases-perl all 0.001006-3 [6996 B] Get:74 http://deb.debian.org/debian unstable/main amd64 libmouse-perl amd64 2.6.2-1+b1 [144 kB] Get:75 http://deb.debian.org/debian unstable/main amd64 libmousex-nativetraits-perl all 1.09-3 [53.5 kB] Get:76 http://deb.debian.org/debian unstable/main amd64 libmousex-strictconstructor-perl all 0.02-3 [5304 B] Get:77 http://deb.debian.org/debian unstable/main amd64 libmro-compat-perl all 0.15-2 [11.8 kB] Get:78 http://deb.debian.org/debian unstable/main amd64 libnamespace-autoclean-perl all 0.31-1 [13.8 kB] Get:79 http://deb.debian.org/debian unstable/main amd64 libnamespace-clean-perl all 0.27-2 [17.8 kB] Get:80 http://deb.debian.org/debian unstable/main amd64 libltdl7 amd64 2.6.2-3 [427 kB] Get:81 http://deb.debian.org/debian unstable/main amd64 libllvm21 amd64 1:21.1.8-13 [28.3 MB] Get:82 http://deb.debian.org/debian unstable/main amd64 libllvm22 amd64 1:22.1.8-1+b2 [29.4 MB] Get:83 http://deb.debian.org/debian unstable/main amd64 liblua5.4-0 amd64 5.4.9-1 [152 kB] Get:84 http://deb.debian.org/debian unstable/main amd64 liblz4-1 amd64 1.10.0-10 [70.3 kB] Get:85 http://deb.debian.org/debian unstable/main amd64 liblz1 amd64 1.16-2 [40.4 kB] Get:86 http://deb.debian.org/debian unstable/main amd64 liblzo2-2 amd64 2.10-3+b2 [57.4 kB] Get:87 http://deb.debian.org/debian unstable/main amd64 libmd4c0 amd64 0.5.3-1 [49.5 kB] Get:88 http://deb.debian.org/debian unstable/main amd64 libmpc3 amd64 1.3.1-3 [52.2 kB] Get:89 http://deb.debian.org/debian unstable/main amd64 libmpfr6 amd64 4.2.2-3 [729 kB] Get:90 http://deb.debian.org/debian unstable/main amd64 libmpg123-0t64 amd64 1.33.7-1 [154 kB] Get:91 http://deb.debian.org/debian unstable/main amd64 libmtdev1t64 amd64 1.1.7-1+b2 [23.2 kB] Get:92 http://deb.debian.org/debian unstable/main amd64 libncurses-dev amd64 6.6+20260608-2 [356 kB] Get:93 http://deb.debian.org/debian unstable/main amd64 libncurses6 amd64 6.6+20260608-2 [107 kB] Get:94 http://deb.debian.org/debian unstable/main amd64 libldap-dev amd64 2.6.14+dfsg-2 [321 kB] Get:95 http://deb.debian.org/debian unstable/main amd64 libldap2 amd64 2.6.14+dfsg-2 [200 kB] Get:96 http://deb.debian.org/debian unstable/main amd64 libmount1 amd64 2.42.4-1 [232 kB] Get:97 http://deb.debian.org/debian unstable/main amd64 liblzma5 amd64 5.8.4-1 [354 kB] Get:98 http://snapshot.debian.org/archive/debian/20261003T143013Z unstable/main amd64 libibmad5 amd64 65.0-1 [44.2 kB] Get:99 http://snapshot.debian.org/archive/debian/20261003T143013Z unstable/main amd64 libibumad3 amd64 65.0-1 [29.6 kB] Get:100 http://snapshot.debian.org/archive/debian/20261003T143013Z unstable/main amd64 libibverbs1 amd64 65.0-1 [67.9 kB] Fetched 89.5 MB in 2s (39.8 MB/s) dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmro-compat-perl_0.15-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmldbm-perl_2.05-4_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libncurses-dev_6.6+20260608-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libjson-maybexs-perl_1.004008-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libkrb5-dev_1.22.1-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblapack-dev_3.12.1-8_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libibumad3_65.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libltdl7_2.6.2-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblist-moreutils-perl_0.430-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libncurses6_6.6+20260608-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libjxl0.11_0.11.2-5.1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libkadm5srv-mit12_1.22.1-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libio-string-perl_1.08-4_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblz4-1_1.10.0-10_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libksba8_1.8.1-1_amd64.deb' dpkg-name: info: moved 'libjpeg62-turbo-dev_1%3a3.1.3-4_amd64.deb' to '/srv/rebuilderd/tmp/tmpve6rhx2w/libjpeg62-turbo-dev_3.1.3-4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblist-someutils-xs-perl_0.59-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libjansson4_2.15.1-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libk5crypto3_1.22.1-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libimagequant0_4.4.1-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libimport-into-perl_1.002005-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libhwloc15_2.15.0-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libkrb5support0_1.22.1-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmp3lame0_4.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libinput10_1.31.3-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libintl-perl_1.37-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libindirect-perl_0.39-2+b5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libjson-perl_4.10000-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libitm1_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblerc4_4.2.0+ds-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libiterator-perl_0.03+ds1-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmd0_1.3.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libiterator-util-perl_0.02+ds1-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libldap2_2.6.14+dfsg-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libnamespace-clean-perl_0.27-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmount1_2.42.4-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmarkdown2_2.2.7-2.1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmpg123-0t64_1.33.7-1_amd64.deb' dpkg-name: info: moved 'libmagic1t64_1%3a5.47-4_amd64.deb' to '/srv/rebuilderd/tmp/tmpve6rhx2w/libmagic1t64_5.47-4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblwp-mediatypes-perl_6.04-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmoox-aliases-perl_0.001006-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblwp-protocol-https-perl_6.15-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblzo2-2_2.10-3+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmtdev1t64_1.1.7-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libio-stringy-perl_2.113-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libio-html-perl_1.004-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libldap-dev_2.6.14+dfsg-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libkeyutils1_1.6.3-6+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libhwloc-plugins_2.15.0-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libibmad5_65.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libidn2-0_2.3.8-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libjack-jackd2-0_1.9.22~dfsg-6_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libisl23_0.28-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmousex-strictconstructor-perl_0.02-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmouse-perl_2.6.2-1+b1_amd64.deb' dpkg-name: info: moved 'libllvm22_1%3a22.1.8-1+b2_amd64.deb' to '/srv/rebuilderd/tmp/tmpve6rhx2w/libllvm22_22.1.8-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libkrb5-3_1.22.1-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmoo-perl_2.005005-1_all.deb' dpkg-name: info: moved 'libjpeg-dev_1%3a3.1.3-4_amd64.deb' to '/srv/rebuilderd/tmp/tmpve6rhx2w/libjpeg-dev_3.1.3-4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmousex-nativetraits-perl_1.09-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libkadm5clnt-mit12_1.22.1-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libkdb5-10t64_1.22.1-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblist-someutils-perl_0.59-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libhwy1t64_1.3.0-5.1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblz1_1.16-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblist-utilsby-perl_0.12-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmodule-runtime-perl_0.018-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmodule-implementation-perl_0.09-2_all.deb' dpkg-name: info: moved 'libice6_2%3a1.1.1-1+b2_amd64.deb' to '/srv/rebuilderd/tmp/tmpve6rhx2w/libice6_1.1.1-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblog-any-adapter-screen-perl_0.141-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmpfr6_4.2.2-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libipc-run3-perl_0.049-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libio-tiecombine-perl_1.005-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libidn2-dev_2.3.8-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblcms2-2_2.19.1-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libipc-system-simple-perl_1.30-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libicu78_78.3-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmailtools-perl_2.22-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblzma5_5.8.4-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmime-tools-perl_5.518-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmpc3_1.3.1-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblapack3_3.12.1-8_amd64.deb' dpkg-name: info: moved 'libllvm21_1%3a21.1.8-13_amd64.deb' to '/srv/rebuilderd/tmp/tmpve6rhx2w/libllvm21_21.1.8-13_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libio-socket-ssl-perl_2.099-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libinput-bin_1.31.3-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblog-any-perl_1.720-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblsan0_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblingua-en-inflect-perl_1.905-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmd4c0_0.5.3-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libio-interactive-perl_1.027-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libibverbs1_65.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblog-log4perl-perl_1.57-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libnamespace-autoclean-perl_0.31-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblist-moreutils-xs-perl_0.430-4+b3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblist-compare-perl_0.55-2_all.deb' dpkg-name: info: moved 'libmagic-mgc_1%3a5.47-4_amd64.deb' to '/srv/rebuilderd/tmp/tmpve6rhx2w/libmagic-mgc_5.47-4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libjbig0_2.1-6.1+b3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/libmodule-pluggable-perl_6.4-1_all.deb' dpkg-name: info: moved 'libjpeg62-turbo_1%3a3.1.3-4_amd64.deb' to '/srv/rebuilderd/tmp/tmpve6rhx2w/libjpeg62-turbo_3.1.3-4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpve6rhx2w/liblua5.4-0_5.4.9-1_amd64.deb' Get:1 http://deb.debian.org/debian unstable/main amd64 libquadmath0 amd64 16.2.0-3 [148 kB] Get:2 http://deb.debian.org/debian unstable/main amd64 libopengl0 amd64 1.7.0-3+b1 [30.4 kB] Get:3 http://deb.debian.org/debian unstable/main amd64 libnet-domain-tld-perl all 1.75-4 [31.5 kB] Get:4 http://deb.debian.org/debian unstable/main amd64 libnet-http-perl all 6.24-1 [23.2 kB] Get:5 http://deb.debian.org/debian unstable/main amd64 libnet-ipv6addr-perl all 1.02-1 [21.7 kB] Get:6 http://deb.debian.org/debian unstable/main amd64 libnet-netmask-perl all 2.0003-1 [28.5 kB] Get:7 http://deb.debian.org/debian unstable/main amd64 libnet-smtp-ssl-perl all 1.04-2 [6548 B] Get:8 http://deb.debian.org/debian unstable/main amd64 libnet-ssleay-perl amd64 1.96-2 [335 kB] Get:9 http://deb.debian.org/debian unstable/main amd64 libnetaddr-ip-perl amd64 4.079+dfsg-2+b6 [98.3 kB] Get:10 http://deb.debian.org/debian unstable/main amd64 libnl-3-200 amd64 3.12.0-2+b1 [62.2 kB] Get:11 http://deb.debian.org/debian unstable/main amd64 libnl-route-3-200 amd64 3.12.0-2+b1 [200 kB] Get:12 http://deb.debian.org/debian unstable/main amd64 libnumber-compare-perl all 0.03-3 [6332 B] Get:13 http://deb.debian.org/debian unstable/main amd64 libobject-pad-perl amd64 0.825-1+b1 [141 kB] Get:14 http://deb.debian.org/debian unstable/main amd64 libogg0 amd64 1.3.6-2+b1 [24.0 kB] Get:15 http://deb.debian.org/debian unstable/main amd64 libpackage-stash-perl all 0.40-1 [22.0 kB] Get:16 http://deb.debian.org/debian unstable/main amd64 libparams-classify-perl amd64 0.015-2+b7 [22.7 kB] Get:17 http://deb.debian.org/debian unstable/main amd64 libparams-someutil-perl amd64 1.11-1 [24.5 kB] Get:18 http://deb.debian.org/debian unstable/main amd64 libparams-util-perl amd64 1.102-3+b2 [24.7 kB] Get:19 http://deb.debian.org/debian unstable/main amd64 libparams-validate-perl amd64 1.31-2+b5 [63.1 kB] Get:20 http://deb.debian.org/debian unstable/main amd64 libparams-validationcompiler-perl all 0.31-1 [30.9 kB] Get:21 http://deb.debian.org/debian unstable/main amd64 libparse-debcontrol-perl all 2.005-6 [21.6 kB] Get:22 http://deb.debian.org/debian unstable/main amd64 libparse-recdescent-perl all 1.967015+dfsg-4 [147 kB] Get:23 http://deb.debian.org/debian unstable/main amd64 libpath-iterator-rule-perl all 1.015-2 [41.7 kB] Get:24 http://deb.debian.org/debian unstable/main amd64 libpath-tiny-perl all 0.150-1 [56.4 kB] Get:25 http://deb.debian.org/debian unstable/main amd64 libpciaccess0 amd64 0.19-2 [18.5 kB] Get:26 http://deb.debian.org/debian unstable/main amd64 libperl-critic-perl all 1.156-1 [685 kB] Get:27 http://deb.debian.org/debian unstable/main amd64 libperlio-gzip-perl amd64 0.20-1+b5 [17.6 kB] Get:28 http://deb.debian.org/debian unstable/main amd64 libperlio-utf8-strict-perl amd64 0.010-1+b4 [11.4 kB] Get:29 http://deb.debian.org/debian unstable/main amd64 libpipeline1 amd64 1.5.8-3 [49.2 kB] Get:30 http://deb.debian.org/debian unstable/main amd64 libpng16-16t64 amd64 1.6.59-1 [293 kB] Get:31 http://deb.debian.org/debian unstable/main amd64 libpod-constants-perl all 0.19-2 [17.3 kB] Get:32 http://deb.debian.org/debian unstable/main amd64 libpod-parser-perl all 1.67-1 [94.1 kB] Get:33 http://deb.debian.org/debian unstable/main amd64 libpod-pom-perl all 2.01-4 [65.0 kB] Get:34 http://deb.debian.org/debian unstable/main amd64 libpod-spell-perl all 1.27-1 [32.0 kB] Get:35 http://deb.debian.org/debian unstable/main amd64 libppi-perl all 1.291-1 [300 kB] Get:36 http://deb.debian.org/debian unstable/main amd64 libppix-quotelike-perl all 0.024-1 [64.7 kB] Get:37 http://deb.debian.org/debian unstable/main amd64 libppix-regexp-perl all 0.092-1 [245 kB] Get:38 http://deb.debian.org/debian unstable/main amd64 libppix-utils-perl all 0.003-2 [28.0 kB] Get:39 http://deb.debian.org/debian unstable/main amd64 libproc-processtable-perl amd64 0.637-1+b4 [41.9 kB] Get:40 http://deb.debian.org/debian unstable/main amd64 libproxy1v5 amd64 0.5.12-3 [25.1 kB] Get:41 http://deb.debian.org/debian unstable/main amd64 libpsl-dev amd64 0.23.3-1 [30.1 kB] Get:42 http://deb.debian.org/debian unstable/main amd64 libpsl5t64 amd64 0.23.3-1 [61.7 kB] Get:43 http://deb.debian.org/debian unstable/main amd64 libpsm2-2 amd64 11.2.185-2.1 [181 kB] Get:44 http://deb.debian.org/debian unstable/main amd64 libreadonly-perl all 2.050-3 [23.1 kB] Get:45 http://deb.debian.org/debian unstable/main amd64 libregexp-common-perl all 2024080801-1 [167 kB] Get:46 http://deb.debian.org/debian unstable/main amd64 libregexp-pattern-license-perl all 3.11.2-1 [94.6 kB] Get:47 http://deb.debian.org/debian unstable/main amd64 libregexp-pattern-perl all 0.2.14-3 [18.3 kB] Get:48 http://deb.debian.org/debian unstable/main amd64 libregexp-wildcards-perl all 1.05-3 [14.1 kB] Get:49 http://deb.debian.org/debian unstable/main amd64 libncursesw6 amd64 6.6+20260608-2 [137 kB] Get:50 http://deb.debian.org/debian unstable/main amd64 libnettle8t64 amd64 3.10.2-1+b1 [305 kB] Get:51 http://deb.debian.org/debian unstable/main amd64 libnghttp2-14 amd64 1.70.0-1 [92.7 kB] Get:52 http://deb.debian.org/debian unstable/main amd64 libnghttp2-dev amd64 1.70.0-1 [131 kB] Get:53 http://deb.debian.org/debian unstable/main amd64 libnghttp3-9 amd64 1.17.0-1 [68.1 kB] Get:54 http://deb.debian.org/debian unstable/main amd64 libnghttp3-dev amd64 1.17.0-1 [96.3 kB] Get:55 http://deb.debian.org/debian unstable/main amd64 libngtcp2-16 amd64 1.24.0-1 [145 kB] Get:56 http://deb.debian.org/debian unstable/main amd64 libngtcp2-crypto-gnutls8 amd64 1.24.0-1 [23.9 kB] Get:57 http://deb.debian.org/debian unstable/main amd64 libngtcp2-crypto-ossl-dev amd64 1.24.0-1 [27.5 kB] Get:58 http://deb.debian.org/debian unstable/main amd64 libngtcp2-crypto-ossl0 amd64 1.24.0-1 [26.5 kB] Get:59 http://deb.debian.org/debian unstable/main amd64 libngtcp2-dev amd64 1.24.0-1 [204 kB] Get:60 http://deb.debian.org/debian unstable/main amd64 libnpth0t64 amd64 1.8-4 [23.1 kB] Get:61 http://deb.debian.org/debian unstable/main amd64 libnuma1 amd64 2.0.19-1+b2 [22.0 kB] Get:62 http://deb.debian.org/debian unstable/main amd64 libopenmpi40 amd64 6.0.0~rc2-2 [2880 kB] Get:63 http://deb.debian.org/debian unstable/main amd64 libopus0 amd64 1.6.1-1+b1 [3484 kB] Get:64 http://deb.debian.org/debian unstable/main amd64 libp11-kit-dev amd64 0.26.5-1 [226 kB] Get:65 http://deb.debian.org/debian unstable/main amd64 libp11-kit0 amd64 0.26.5-1 [482 kB] Get:66 http://deb.debian.org/debian unstable/main amd64 libpam-modules amd64 1.7.0-8 [168 kB] Get:67 http://deb.debian.org/debian unstable/main amd64 libpam-modules-bin amd64 1.7.0-8 [46.3 kB] Get:68 http://deb.debian.org/debian unstable/main amd64 libpam-runtime all 1.7.0-8 [246 kB] Get:69 http://deb.debian.org/debian unstable/main amd64 libpam0g amd64 1.7.0-8 [66.9 kB] Get:70 http://deb.debian.org/debian unstable/main amd64 libpango-1.0-0 amd64 1.58.2-1 [233 kB] Get:71 http://deb.debian.org/debian unstable/main amd64 libpangocairo-1.0-0 amd64 1.58.2-1 [35.3 kB] Get:72 http://deb.debian.org/debian unstable/main amd64 libpangoft2-1.0-0 amd64 1.58.2-1 [56.0 kB] Get:73 http://deb.debian.org/debian unstable/main amd64 libpcre2-16-0 amd64 10.48-3.1 [295 kB] Get:74 http://deb.debian.org/debian unstable/main amd64 libpcre2-8-0 amd64 10.48-3.1 [312 kB] Get:75 http://deb.debian.org/debian unstable/main amd64 libperl5.42 amd64 5.42.3-1 [4272 kB] Get:76 http://deb.debian.org/debian unstable/main amd64 libpixman-1-0 amd64 0.46.4-1+b2 [259 kB] Get:77 http://deb.debian.org/debian unstable/main amd64 libpkgconf7 amd64 2.5.1-4 [47.8 kB] Get:78 http://deb.debian.org/debian unstable/main amd64 libpmix2t64 amd64 7.0.0~rc1-1 [840 kB] Get:79 http://deb.debian.org/debian unstable/main amd64 libportaudio2 amd64 19.7.0-1+b1 [65.0 kB] Get:80 http://deb.debian.org/debian unstable/main amd64 libproc2-1 amd64 2:4.0.7-1 [73.0 kB] Get:81 http://deb.debian.org/debian unstable/main amd64 libqhull-r8.0 amd64 2020.2-9 [248 kB] Get:82 http://deb.debian.org/debian unstable/main amd64 libqrupdate1 amd64 1.2.0-1 [42.7 kB] Get:83 http://deb.debian.org/debian unstable/main amd64 libqscintilla2-qt6-15 amd64 2.14.1+dfsg-4 [1256 kB] Get:84 http://deb.debian.org/debian unstable/main amd64 libqscintilla2-qt6-l10n all 2.14.1+dfsg-4 [103 kB] Get:85 http://deb.debian.org/debian unstable/main amd64 libqt6core5compat6 amd64 6.11.2-2 [152 kB] Get:86 http://deb.debian.org/debian unstable/main amd64 libqt6core6t64 amd64 6.11.2+dfsg-5 [2075 kB] Get:87 http://deb.debian.org/debian unstable/main amd64 libqt6dbus6 amd64 6.11.2+dfsg-5 [294 kB] Get:88 http://deb.debian.org/debian unstable/main amd64 libqt6gui6 amd64 6.11.2+dfsg-5 [3516 kB] Get:89 http://deb.debian.org/debian unstable/main amd64 libqt6network6 amd64 6.11.2+dfsg-5 [880 kB] Get:90 http://deb.debian.org/debian unstable/main amd64 libqt6opengl6 amd64 6.11.2+dfsg-5 [462 kB] Get:91 http://deb.debian.org/debian unstable/main amd64 libqt6openglwidgets6 amd64 6.11.2+dfsg-5 [47.9 kB] Get:92 http://deb.debian.org/debian unstable/main amd64 libqt6printsupport6 amd64 6.11.2+dfsg-5 [228 kB] Get:93 http://deb.debian.org/debian unstable/main amd64 libqt6sql6 amd64 6.11.2+dfsg-5 [157 kB] Get:94 http://deb.debian.org/debian unstable/main amd64 libqt6widgets6 amd64 6.11.2+dfsg-5 [2793 kB] Get:95 http://deb.debian.org/debian unstable/main amd64 libqt6xml6 amd64 6.11.2+dfsg-5 [88.2 kB] Get:96 http://deb.debian.org/debian unstable/main amd64 libqt6help6 amd64 6.11.2-2 [202 kB] Get:97 http://deb.debian.org/debian unstable/main amd64 libreadline-dev amd64 8.3-4 [163 kB] Get:98 http://deb.debian.org/debian unstable/main amd64 libreadline8t64 amd64 8.3-4 [181 kB] Get:99 http://deb.debian.org/debian unstable/main amd64 librav1e0.8 amd64 0.8.1-12 [970 kB] Get:100 http://snapshot.debian.org/archive/debian/20261003T143013Z unstable/main amd64 librdmacm1t64 amd64 65.0-1 [79.0 kB] Fetched 33.5 MB in 2s (18.8 MB/s) dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpmix2t64_7.0.0~rc1-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpangocairo-1.0-0_1.58.2-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libportaudio2_19.7.0-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libproxy1v5_0.5.12-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libnet-netmask-perl_2.0003-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libqscintilla2-qt6-l10n_2.14.1+dfsg-4_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libqt6widgets6_6.11.2+dfsg-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libngtcp2-crypto-ossl0_1.24.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libparams-validate-perl_1.31-2+b5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libqt6core6t64_6.11.2+dfsg-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libqt6dbus6_6.11.2+dfsg-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpsl5t64_0.23.3-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libqt6network6_6.11.2+dfsg-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpath-tiny-perl_0.150-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpam-modules_1.7.0-8_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libqt6gui6_6.11.2+dfsg-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libppi-perl_1.291-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libparams-util-perl_1.102-3+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libregexp-wildcards-perl_1.05-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libperlio-gzip-perl_0.20-1+b5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libparse-debcontrol-perl_2.005-6_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpod-constants-perl_0.19-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libreadline-dev_8.3-4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpciaccess0_0.19-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/librav1e0.8_0.8.1-12_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libogg0_1.3.6-2+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpangoft2-1.0-0_1.58.2-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libnghttp2-dev_1.70.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libppix-quotelike-perl_0.024-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libregexp-pattern-license-perl_3.11.2-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libnpth0t64_1.8-4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libngtcp2-dev_1.24.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpam0g_1.7.0-8_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libparams-classify-perl_0.015-2+b7_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpcre2-8-0_10.48-3.1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libqrupdate1_1.2.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libopenmpi40_6.0.0~rc2-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libqt6printsupport6_6.11.2+dfsg-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libopengl0_1.7.0-3+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libqhull-r8.0_2020.2-9_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libnettle8t64_3.10.2-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpam-modules-bin_1.7.0-8_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpixman-1-0_0.46.4-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpcre2-16-0_10.48-3.1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libnl-route-3-200_3.12.0-2+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libqt6core5compat6_6.11.2-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpod-parser-perl_1.67-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libnghttp3-9_1.17.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libnghttp2-14_1.70.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libnet-http-perl_6.24-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libquadmath0_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libopus0_1.6.1-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpackage-stash-perl_0.40-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libnuma1_2.0.19-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpath-iterator-rule-perl_1.015-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libobject-pad-perl_0.825-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libregexp-common-perl_2024080801-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libparams-someutil-perl_1.11-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libqt6openglwidgets6_6.11.2+dfsg-5_amd64.deb' dpkg-name: info: moved 'libproc2-1_2%3a4.0.7-1_amd64.deb' to '/srv/rebuilderd/tmp/tmpduhrr7yg/libproc2-1_4.0.7-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libreadonly-perl_2.050-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpam-runtime_1.7.0-8_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libppix-utils-perl_0.003-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libngtcp2-16_1.24.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libngtcp2-crypto-gnutls8_1.24.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpkgconf7_2.5.1-4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libqt6opengl6_6.11.2+dfsg-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libppix-regexp-perl_0.092-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libnet-ssleay-perl_1.96-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpod-spell-perl_1.27-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libngtcp2-crypto-ossl-dev_1.24.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libp11-kit-dev_0.26.5-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpsm2-2_11.2.185-2.1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libp11-kit0_0.26.5-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libnet-ipv6addr-perl_1.02-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpod-pom-perl_2.01-4_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libperl-critic-perl_1.156-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/librdmacm1t64_65.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpipeline1_1.5.8-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpsl-dev_0.23.3-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libparams-validationcompiler-perl_0.31-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpng16-16t64_1.6.59-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libparse-recdescent-perl_1.967015+dfsg-4_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libncursesw6_6.6+20260608-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libperlio-utf8-strict-perl_0.010-1+b4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libreadline8t64_8.3-4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libqt6sql6_6.11.2+dfsg-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libqscintilla2-qt6-15_2.14.1+dfsg-4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libnghttp3-dev_1.17.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libregexp-pattern-perl_0.2.14-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libnet-smtp-ssl-perl_1.04-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libperl5.42_5.42.3-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libproc-processtable-perl_0.637-1+b4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libnumber-compare-perl_0.03-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libnetaddr-ip-perl_4.079+dfsg-2+b6_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libqt6xml6_6.11.2+dfsg-5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libqt6help6_6.11.2-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libnet-domain-tld-perl_1.75-4_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libnl-3-200_3.12.0-2+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpduhrr7yg/libpango-1.0-0_1.58.2-1_amd64.deb' Get:1 http://deb.debian.org/debian unstable/main amd64 libsframe3 amd64 2.47-6 [86.2 kB] Get:2 http://deb.debian.org/debian unstable/main amd64 libsasl2-2 amd64 2.1.28+dfsg1-11 [55.2 kB] Get:3 http://deb.debian.org/debian unstable/main amd64 libsasl2-modules-db amd64 2.1.28+dfsg1-11 [17.2 kB] Get:4 http://deb.debian.org/debian unstable/main amd64 libstdc++-16-dev amd64 16.2.0-3 [2755 kB] Get:5 http://deb.debian.org/debian unstable/main amd64 libstdc++6 amd64 16.2.0-3 [823 kB] Get:6 http://deb.debian.org/debian unstable/main amd64 libtsan2 amd64 16.2.0-3 [2574 kB] Get:7 http://deb.debian.org/debian unstable/main amd64 libubsan1 amd64 16.2.0-3 [1136 kB] Get:8 http://deb.debian.org/debian unstable/main amd64 libsz2 amd64 1.1.7-1 [18.7 kB] Get:9 http://deb.debian.org/debian unstable/main amd64 librole-tiny-perl all 2.002005-1 [19.5 kB] Get:10 http://deb.debian.org/debian unstable/main amd64 libsafe-isa-perl all 1.000010-1 [8288 B] Get:11 http://deb.debian.org/debian unstable/main amd64 libsamplerate0 amd64 0.2.2-4+b3 [954 kB] Get:12 http://deb.debian.org/debian unstable/main amd64 libseccomp2 amd64 2.6.1-1+b1 [51.7 kB] Get:13 http://deb.debian.org/debian unstable/main amd64 libselinux1 amd64 3.11-2.1 [92.2 kB] Get:14 http://deb.debian.org/debian unstable/main amd64 libsereal-decoder-perl amd64 5.006+ds-1+b1 [101 kB] Get:15 http://deb.debian.org/debian unstable/main amd64 libsereal-encoder-perl amd64 5.006+ds-1+b1 [104 kB] Get:16 http://deb.debian.org/debian unstable/main amd64 libset-intspan-perl all 1.19-3 [25.3 kB] Get:17 http://deb.debian.org/debian unstable/main amd64 libsm6 amd64 2:1.2.6-1+b2 [37.9 kB] Get:18 http://deb.debian.org/debian unstable/main amd64 libsndfile1 amd64 1.2.2-4+b1 [205 kB] Get:19 http://deb.debian.org/debian unstable/main amd64 libsoftware-copyright-perl all 0.015-1 [15.5 kB] Get:20 http://deb.debian.org/debian unstable/main amd64 libsoftware-license-perl all 0.104007-1 [121 kB] Get:21 http://deb.debian.org/debian unstable/main amd64 libsoftware-licensemoreutils-perl all 1.009-1 [22.0 kB] Get:22 http://deb.debian.org/debian unstable/main amd64 libsort-versions-perl all 1.62-3 [8928 B] Get:23 http://deb.debian.org/debian unstable/main amd64 libspecio-perl all 0.53-1 [134 kB] Get:24 http://deb.debian.org/debian unstable/main amd64 libssh2-1-dev amd64 1.11.1-6 [402 kB] Get:25 http://deb.debian.org/debian unstable/main amd64 libssh2-1t64 amd64 1.11.1-6 [253 kB] Get:26 http://deb.debian.org/debian unstable/main amd64 libstrictures-perl all 2.000006-1 [18.6 kB] Get:27 http://deb.debian.org/debian unstable/main amd64 libstring-copyright-perl all 0.003014-1 [23.4 kB] Get:28 http://deb.debian.org/debian unstable/main amd64 libstring-escape-perl all 2010.002-3 [18.7 kB] Get:29 http://deb.debian.org/debian unstable/main amd64 libstring-format-perl all 1.18-1 [9408 B] Get:30 http://deb.debian.org/debian unstable/main amd64 libstring-license-perl all 0.0.11-1 [34.7 kB] Get:31 http://deb.debian.org/debian unstable/main amd64 libstring-rewriteprefix-perl all 0.009-1 [7140 B] Get:32 http://deb.debian.org/debian unstable/main amd64 libsub-exporter-perl all 0.990-1.1 [49.5 kB] Get:33 http://deb.debian.org/debian unstable/main amd64 libsub-exporter-progressive-perl all 0.001013-3 [7496 B] Get:34 http://deb.debian.org/debian unstable/main amd64 libsub-identify-perl amd64 0.14-4+b1 [11.3 kB] Get:35 http://deb.debian.org/debian unstable/main amd64 libsub-install-perl all 0.929-1 [10.5 kB] Get:36 http://deb.debian.org/debian unstable/main amd64 libsub-name-perl amd64 0.28-1+b3 [12.6 kB] Get:37 http://deb.debian.org/debian unstable/main amd64 libsub-quote-perl all 2.006009-1 [21.3 kB] Get:38 http://deb.debian.org/debian unstable/main amd64 libsub-uplevel-perl all 0.2800-3 [14.0 kB] Get:39 http://deb.debian.org/debian unstable/main amd64 libsyntax-keyword-try-perl amd64 0.31-1+b1 [27.2 kB] Get:40 http://deb.debian.org/debian unstable/main amd64 libtask-weaken-perl all 1.06-2 [9364 B] Get:41 http://deb.debian.org/debian unstable/main amd64 libtasn1-6 amd64 4.21.0-2+b1 [49.3 kB] Get:42 http://deb.debian.org/debian unstable/main amd64 libtasn1-6-dev amd64 4.21.0-2+b1 [98.6 kB] Get:43 http://deb.debian.org/debian unstable/main amd64 libterm-readkey-perl amd64 2.38-2+b5 [24.7 kB] Get:44 http://deb.debian.org/debian unstable/main amd64 libtest-exception-perl all 0.43-3 [16.9 kB] Get:45 http://deb.debian.org/debian unstable/main amd64 libtext-autoformat-perl all 1.750000-2 [35.2 kB] Get:46 http://deb.debian.org/debian unstable/main amd64 libtext-charwidth-perl amd64 0.04-12+b1 [9344 B] Get:47 http://deb.debian.org/debian unstable/main amd64 libtext-glob-perl all 0.11-3 [7676 B] Get:48 http://deb.debian.org/debian unstable/main amd64 libtext-levenshtein-damerau-perl all 0.41-3 [12.3 kB] Get:49 http://deb.debian.org/debian unstable/main amd64 libtext-levenshteinxs-perl amd64 0.03-5+b5 [8780 B] Get:50 http://deb.debian.org/debian unstable/main amd64 libtext-markdown-discount-perl amd64 0.18-1+b1 [13.2 kB] Get:51 http://deb.debian.org/debian unstable/main amd64 libtext-reform-perl all 1.20-5 [36.0 kB] Get:52 http://deb.debian.org/debian unstable/main amd64 libtext-template-perl all 1.61-1 [54.4 kB] Get:53 http://deb.debian.org/debian unstable/main amd64 libtext-unidecode-perl all 1.30-3 [101 kB] Get:54 http://deb.debian.org/debian unstable/main amd64 libtext-wrapi18n-perl all 0.06-11 [7788 B] Get:55 http://deb.debian.org/debian unstable/main amd64 libtext-wrapper-perl all 1.05-4 [10.3 kB] Get:56 http://deb.debian.org/debian unstable/main amd64 libtext-xslate-perl amd64 3.5.9-2+b3 [175 kB] Get:57 http://deb.debian.org/debian unstable/main amd64 libthai-data all 0.1.30-3 [172 kB] Get:58 http://deb.debian.org/debian unstable/main amd64 libthai0 amd64 0.1.30-3 [51.7 kB] Get:59 http://deb.debian.org/debian unstable/main amd64 libtime-duration-perl all 1.21-2 [13.1 kB] Get:60 http://deb.debian.org/debian unstable/main amd64 libtime-moment-perl amd64 0.46-1+b1 [78.4 kB] Get:61 http://deb.debian.org/debian unstable/main amd64 libtimedate-perl all 2.3500-1 [64.2 kB] Get:62 http://deb.debian.org/debian unstable/main amd64 libtoml-tiny-perl all 0.22-1 [23.2 kB] Get:63 http://deb.debian.org/debian unstable/main amd64 libtool all 2.6.2-3 [552 kB] Get:64 http://deb.debian.org/debian unstable/main amd64 libtry-tiny-perl all 0.32-1 [22.9 kB] Get:65 http://deb.debian.org/debian unstable/main amd64 libunicode-utf8-perl amd64 0.75-1+b1 [28.8 kB] Get:66 http://deb.debian.org/debian unstable/main amd64 libunistring-dev amd64 1.4.2-1 [651 kB] Get:67 http://deb.debian.org/debian unstable/main amd64 libunistring5 amd64 1.4.2-1 [480 kB] Get:68 http://deb.debian.org/debian unstable/main amd64 liburi-perl all 5.37-1 [113 kB] Get:69 http://deb.debian.org/debian unstable/main amd64 liburing2 amd64 2.15-1 [29.5 kB] Get:70 http://deb.debian.org/debian unstable/main amd64 libvariable-magic-perl amd64 0.65-1 [45.4 kB] Get:71 http://deb.debian.org/debian unstable/main amd64 libvorbis0a amd64 1.3.7-3+b2 [93.2 kB] Get:72 http://deb.debian.org/debian unstable/main amd64 libvorbisenc2 amd64 1.3.7-3+b2 [76.1 kB] Get:73 http://deb.debian.org/debian unstable/main amd64 libwacom-common all 2.20.0-1 [119 kB] Get:74 http://deb.debian.org/debian unstable/main amd64 libwacom9 amd64 2.20.0-1 [26.5 kB] Get:75 http://deb.debian.org/debian unstable/main amd64 libsharpyuv0 amd64 1.6.0-0.1 [116 kB] Get:76 http://deb.debian.org/debian unstable/main amd64 libsensors-config all 1:3.6.2-2 [16.2 kB] Get:77 http://deb.debian.org/debian unstable/main amd64 libsensors5 amd64 1:3.6.2-2+b2 [37.2 kB] Get:78 http://deb.debian.org/debian unstable/main amd64 libtinfo6 amd64 6.6+20260608-2 [353 kB] Get:79 http://deb.debian.org/debian unstable/main amd64 libssl-dev amd64 3.6.5-1 [3165 kB] Get:80 http://deb.debian.org/debian unstable/main amd64 libssl3t64 amd64 3.6.5-1 [2621 kB] Get:81 http://deb.debian.org/debian unstable/main amd64 librtmp-dev amd64 2.6-1 [69.7 kB] Get:82 http://deb.debian.org/debian unstable/main amd64 librtmp1 amd64 2.6-1 [60.3 kB] Get:83 http://deb.debian.org/debian unstable/main amd64 libstemmer0d amd64 3.1.1-1 [138 kB] Get:84 http://deb.debian.org/debian unstable/main amd64 libsqlite3-0 amd64 3.53.4-2 [974 kB] Get:85 http://deb.debian.org/debian unstable/main amd64 libspqr4 amd64 1:7.14.1+dfsg-1 [160 kB] Get:86 http://deb.debian.org/debian unstable/main amd64 libsuitesparseconfig7 amd64 1:7.14.1+dfsg-1 [32.8 kB] Get:87 http://deb.debian.org/debian unstable/main amd64 libumfpack6 amd64 1:7.14.1+dfsg-1 [299 kB] Get:88 http://deb.debian.org/debian unstable/main amd64 libsvtav1enc4 amd64 4.1.0+dfsg-1 [2414 kB] Get:89 http://deb.debian.org/debian unstable/main amd64 libsystemd-shared amd64 262-1 [2789 kB] Get:90 http://deb.debian.org/debian unstable/main amd64 libsystemd0 amd64 262-1 [512 kB] Get:91 http://deb.debian.org/debian unstable/main amd64 libudev1 amd64 262-1 [148 kB] Get:92 http://deb.debian.org/debian unstable/main amd64 libtiff6 amd64 4.7.2-1 [383 kB] Get:93 http://deb.debian.org/debian unstable/main amd64 libts0t64 amd64 1.22-1.1+b2 [61.9 kB] Get:94 http://deb.debian.org/debian unstable/main amd64 libucc1 amd64 1.9.0-1 [379 kB] Get:95 http://deb.debian.org/debian unstable/main amd64 libuchardet0 amd64 0.0.8-2+b2 [69.0 kB] Get:96 http://deb.debian.org/debian unstable/main amd64 libucx0 amd64 1.22.0-1 [1064 kB] Get:97 http://deb.debian.org/debian unstable/main amd64 libunbound8 amd64 1.26.1-1 [664 kB] Get:98 http://deb.debian.org/debian unstable/main amd64 libsmartcols1 amd64 2.42.4-1 [153 kB] Get:99 http://deb.debian.org/debian unstable/main amd64 libuuid1 amd64 2.42.4-1 [34.5 kB] Get:100 http://deb.debian.org/debian unstable/main amd64 libvulkan1 amd64 1.4.363.0-1 [173 kB] Fetched 30.5 MB in 1s (27.4 MB/s) dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtext-wrapper-perl_1.05-4_all.deb' dpkg-name: info: moved 'libsensors-config_1%3a3.6.2-2_all.deb' to '/srv/rebuilderd/tmp/tmp850u5vvd/libsensors-config_3.6.2-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/librole-tiny-perl_2.002005-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtoml-tiny-perl_0.22-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libvorbisenc2_1.3.7-3+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libwacom-common_2.20.0-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsoftware-copyright-perl_0.015-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libstring-format-perl_1.18-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/liburing2_2.15-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libspecio-perl_0.53-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/liburi-perl_5.37-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsort-versions-perl_1.62-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtiff6_4.7.2-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsub-exporter-progressive-perl_0.001013-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libubsan1_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libudev1_262-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtest-exception-perl_0.43-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtinfo6_6.6+20260608-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libstring-escape-perl_2010.002-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libstrictures-perl_2.000006-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsereal-decoder-perl_5.006+ds-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsub-uplevel-perl_0.2800-3_all.deb' dpkg-name: info: moved 'libsensors5_1%3a3.6.2-2+b2_amd64.deb' to '/srv/rebuilderd/tmp/tmp850u5vvd/libsensors5_3.6.2-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libssh2-1-dev_1.11.1-6_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsasl2-modules-db_2.1.28+dfsg1-11_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsqlite3-0_3.53.4-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsoftware-license-perl_0.104007-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtime-duration-perl_1.21-2_all.deb' dpkg-name: info: moved 'libsuitesparseconfig7_1%3a7.14.1+dfsg-1_amd64.deb' to '/srv/rebuilderd/tmp/tmp850u5vvd/libsuitesparseconfig7_7.14.1+dfsg-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libunicode-utf8-perl_0.75-1+b1_amd64.deb' dpkg-name: info: moved 'libspqr4_1%3a7.14.1+dfsg-1_amd64.deb' to '/srv/rebuilderd/tmp/tmp850u5vvd/libspqr4_7.14.1+dfsg-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libstemmer0d_3.1.1-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtsan2_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtimedate-perl_2.3500-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/librtmp1_2.6-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtext-markdown-discount-perl_0.18-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libucc1_1.9.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtext-template-perl_1.61-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libstdc++6_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libstring-copyright-perl_0.003014-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtasn1-6_4.21.0-2+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsub-identify-perl_0.14-4+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsharpyuv0_1.6.0-0.1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libwacom9_2.20.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsystemd-shared_262-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libssl-dev_3.6.5-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtext-charwidth-perl_0.04-12+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libssl3t64_3.6.5-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsystemd0_262-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libseccomp2_2.6.1-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsub-quote-perl_2.006009-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtasn1-6-dev_4.21.0-2+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libunbound8_1.26.1-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtask-weaken-perl_1.06-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsamplerate0_0.2.2-4+b3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsereal-encoder-perl_5.006+ds-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libuuid1_2.42.4-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsframe3_2.47-6_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsz2_1.1.7-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsndfile1_1.2.2-4+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsmartcols1_2.42.4-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libssh2-1t64_1.11.1-6_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libselinux1_3.11-2.1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libunistring-dev_1.4.2-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libthai-data_0.1.30-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtry-tiny-perl_0.32-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libts0t64_1.22-1.1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libstring-rewriteprefix-perl_0.009-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsoftware-licensemoreutils-perl_1.009-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsafe-isa-perl_1.000010-1_all.deb' dpkg-name: info: moved 'libumfpack6_1%3a7.14.1+dfsg-1_amd64.deb' to '/srv/rebuilderd/tmp/tmp850u5vvd/libumfpack6_7.14.1+dfsg-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtime-moment-perl_0.46-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsyntax-keyword-try-perl_0.31-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libvorbis0a_1.3.7-3+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libvariable-magic-perl_0.65-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtext-reform-perl_1.20-5_all.deb' dpkg-name: info: moved 'libsm6_2%3a1.2.6-1+b2_amd64.deb' to '/srv/rebuilderd/tmp/tmp850u5vvd/libsm6_1.2.6-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libunistring5_1.4.2-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libuchardet0_0.0.8-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtext-xslate-perl_3.5.9-2+b3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsub-exporter-perl_0.990-1.1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/librtmp-dev_2.6-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libvulkan1_1.4.363.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libucx0_1.22.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsasl2-2_2.1.28+dfsg1-11_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtext-unidecode-perl_1.30-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtext-levenshtein-damerau-perl_0.41-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtext-wrapi18n-perl_0.06-11_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libset-intspan-perl_1.19-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsvtav1enc4_4.1.0+dfsg-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libterm-readkey-perl_2.38-2+b5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsub-name-perl_0.28-1+b3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtext-autoformat-perl_1.750000-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libstring-license-perl_0.0.11-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libsub-install-perl_0.929-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libthai0_0.1.30-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libstdc++-16-dev_16.2.0-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtext-glob-perl_0.11-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtool_2.6.2-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmp850u5vvd/libtext-levenshteinxs-perl_0.03-5+b5_amd64.deb' Get:1 http://deb.debian.org/debian unstable/main amd64 libze1 amd64 1.32.0-1 [648 kB] Get:2 http://deb.debian.org/debian unstable/main amd64 libwebp7 amd64 1.6.0-0.1 [349 kB] Get:3 http://deb.debian.org/debian unstable/main amd64 libwebpmux3 amd64 1.6.0-0.1 [127 kB] Get:4 http://deb.debian.org/debian unstable/main amd64 libwmflite-0.2-7 amd64 0.2.14-1 [74.1 kB] Get:5 http://deb.debian.org/debian unstable/main amd64 libwww-mechanize-perl all 2.22-1 [117 kB] Get:6 http://deb.debian.org/debian unstable/main amd64 libwww-perl all 6.83-1 [186 kB] Get:7 http://deb.debian.org/debian unstable/main amd64 libwww-robotrules-perl all 6.03-1 [15.8 kB] Get:8 http://deb.debian.org/debian unstable/main amd64 libx11-6 amd64 2:1.8.13-1 [829 kB] Get:9 http://deb.debian.org/debian unstable/main amd64 libx11-data all 2:1.8.13-1 [346 kB] Get:10 http://deb.debian.org/debian unstable/main amd64 libx11-dev amd64 2:1.8.13-1 [903 kB] Get:11 http://deb.debian.org/debian unstable/main amd64 libx11-xcb1 amd64 2:1.8.13-1 [250 kB] Get:12 http://deb.debian.org/debian unstable/main amd64 libxau-dev amd64 1:1.0.11-1+b2 [23.9 kB] Get:13 http://deb.debian.org/debian unstable/main amd64 libxau6 amd64 1:1.0.11-1+b2 [20.7 kB] Get:14 http://deb.debian.org/debian unstable/main amd64 libxcb-dri3-0 amd64 1.17.0-2+b2 [107 kB] Get:15 http://deb.debian.org/debian unstable/main amd64 libxcb-glx0 amd64 1.17.0-2+b2 [122 kB] Get:16 http://deb.debian.org/debian unstable/main amd64 libxcb-present0 amd64 1.17.0-2+b2 [106 kB] Get:17 http://deb.debian.org/debian unstable/main amd64 libxcb-randr0 amd64 1.17.0-2+b2 [117 kB] Get:18 http://deb.debian.org/debian unstable/main amd64 libxcb-render0 amd64 1.17.0-2+b2 [115 kB] Get:19 http://deb.debian.org/debian unstable/main amd64 libxcb-shape0 amd64 1.17.0-2+b2 [106 kB] Get:20 http://deb.debian.org/debian unstable/main amd64 libxcb-shm0 amd64 1.17.0-2+b2 [105 kB] Get:21 http://deb.debian.org/debian unstable/main amd64 libxcb-sync1 amd64 1.17.0-2+b2 [109 kB] Get:22 http://deb.debian.org/debian unstable/main amd64 libxcb-xfixes0 amd64 1.17.0-2+b2 [109 kB] Get:23 http://deb.debian.org/debian unstable/main amd64 libxcb-xinput0 amd64 1.17.0-2+b2 [130 kB] Get:24 http://deb.debian.org/debian unstable/main amd64 libxcb-xkb1 amd64 1.17.0-2+b2 [130 kB] Get:25 http://deb.debian.org/debian unstable/main amd64 libxcb1 amd64 1.17.0-2+b2 [144 kB] Get:26 http://deb.debian.org/debian unstable/main amd64 libxcb1-dev amd64 1.17.0-2+b2 [181 kB] Get:27 http://deb.debian.org/debian unstable/main amd64 libxcursor1 amd64 1:1.2.3-1+b2 [40.3 kB] Get:28 http://deb.debian.org/debian unstable/main amd64 libxdmcp-dev amd64 1:1.1.5-2+b1 [44.0 kB] Get:29 http://deb.debian.org/debian unstable/main amd64 libxdmcp6 amd64 1:1.1.5-2+b1 [28.2 kB] Get:30 http://deb.debian.org/debian unstable/main amd64 libxext6 amd64 2:1.3.4-1+b4 [50.7 kB] Get:31 http://deb.debian.org/debian unstable/main amd64 libxfixes3 amd64 1:6.0.0-2+b5 [20.3 kB] Get:32 http://deb.debian.org/debian unstable/main amd64 libxinerama1 amd64 2:1.1.4-3+b5 [16.0 kB] Get:33 http://deb.debian.org/debian unstable/main amd64 libxkbcommon-x11-0 amd64 1.13.1-1 [21.0 kB] Get:34 http://deb.debian.org/debian unstable/main amd64 libxkbcommon0 amd64 1.13.1-1 [148 kB] Get:35 http://deb.debian.org/debian unstable/main amd64 libxml-libxml-perl amd64 2.0207+dfsg+really+2.0134-8+b1 [314 kB] Get:36 http://deb.debian.org/debian unstable/main amd64 libxml-namespacesupport-perl all 1.12-2 [15.1 kB] Get:37 http://deb.debian.org/debian unstable/main amd64 libxml-sax-base-perl all 1.09-3 [20.6 kB] Get:38 http://deb.debian.org/debian unstable/main amd64 libxml-sax-perl all 1.02+dfsg-5 [53.6 kB] Get:39 http://deb.debian.org/debian unstable/main amd64 libxml2-16 amd64 2.15.4+dfsg-1 [683 kB] Get:40 http://deb.debian.org/debian unstable/main amd64 libxmlb2 amd64 0.3.29-1 [63.8 kB] Get:41 http://deb.debian.org/debian unstable/main amd64 libxnvctrl0 amd64 535.171.04-1+b3 [14.1 kB] Get:42 http://deb.debian.org/debian unstable/main amd64 libxpm4 amd64 1:3.5.19-1 [58.9 kB] Get:43 http://deb.debian.org/debian unstable/main amd64 libxrender1 amd64 1:0.9.12-1+b2 [27.7 kB] Get:44 http://deb.debian.org/debian unstable/main amd64 libxs-parse-keyword-perl amd64 0.51-1 [66.2 kB] Get:45 http://deb.debian.org/debian unstable/main amd64 libxs-parse-sublike-perl amd64 0.41-2 [50.7 kB] Get:46 http://deb.debian.org/debian unstable/main amd64 libxshmfence1 amd64 1.3.3-1+b2 [11.2 kB] Get:47 http://deb.debian.org/debian unstable/main amd64 libxstring-perl amd64 0.005-2+b7 [8164 B] Get:48 http://deb.debian.org/debian unstable/main amd64 libxxf86vm1 amd64 1:1.1.4-2+b1 [20.2 kB] Get:49 http://deb.debian.org/debian unstable/main amd64 libyaml-0-2 amd64 0.2.5-2+b1 [53.8 kB] Get:50 http://deb.debian.org/debian unstable/main amd64 libyaml-libyaml-perl amd64 0.910.0+ds-1+b1 [48.2 kB] Get:51 http://deb.debian.org/debian unstable/main amd64 libyaml-pp-perl all 0.41.0-1 [112 kB] Get:52 http://deb.debian.org/debian unstable/main amd64 libyaml-tiny-perl all 1.76-1 [29.8 kB] Get:53 http://deb.debian.org/debian unstable/main amd64 libyuv0 amd64 0.0.1971.20260904-2 [187 kB] Get:54 http://deb.debian.org/debian unstable/main amd64 libzstd-dev amd64 1.5.7+dfsg-4 [371 kB] Get:55 http://deb.debian.org/debian unstable/main amd64 libzstd1 amd64 1.5.7+dfsg-4 [304 kB] Get:56 http://deb.debian.org/debian unstable/main amd64 licensecheck all 3.3.9-1 [50.1 kB] Get:57 http://deb.debian.org/debian unstable/main amd64 lintian all 2.141.0 [1038 kB] Get:58 http://deb.debian.org/debian unstable/main amd64 lzop amd64 1.04-2 [84.2 kB] Get:59 http://deb.debian.org/debian unstable/main amd64 m4 amd64 1.4.21-1 [332 kB] Get:60 http://deb.debian.org/debian unstable/main amd64 make amd64 4.4.1-3 [463 kB] Get:61 http://deb.debian.org/debian unstable/main amd64 man-db amd64 2.13.1-1 [1469 kB] Get:62 http://deb.debian.org/debian unstable/main amd64 mawk amd64 1.3.4.20260302-2 [145 kB] Get:63 http://deb.debian.org/debian unstable/main amd64 mesa-libgallium amd64 26.2.4-1 [11.8 MB] Get:64 http://deb.debian.org/debian unstable/main amd64 ncurses-base all 6.6+20260608-2 [276 kB] Get:65 http://deb.debian.org/debian unstable/main amd64 ncurses-bin amd64 6.6+20260608-2 [445 kB] Get:66 http://deb.debian.org/debian unstable/main amd64 netbase all 6.6 [10.3 kB] Get:67 http://deb.debian.org/debian unstable/main amd64 nettle-dev amd64 3.10.2-1+b1 [1321 kB] Get:68 http://deb.debian.org/debian unstable/main amd64 ocl-icd-libopencl1 amd64 2.3.4-1+b1 [42.8 kB] Get:69 http://deb.debian.org/debian unstable/main amd64 octave amd64 11.3.0-1+b1 [9834 kB] Get:70 http://deb.debian.org/debian unstable/main amd64 octave-common all 11.3.0-1 [6779 kB] Get:71 http://deb.debian.org/debian unstable/main amd64 octave-dev amd64 11.3.0-1+b1 [1124 kB] Get:72 http://deb.debian.org/debian unstable/main amd64 octave-datatypes amd64 1.5.0-1 [431 kB] Get:73 http://deb.debian.org/debian unstable/main amd64 octave-datatypes-common all 1.5.0-1 [1228 kB] Get:74 http://deb.debian.org/debian unstable/main amd64 octave-io amd64 2.7.2-3 [256 kB] Get:75 http://deb.debian.org/debian unstable/main amd64 openssl amd64 3.6.5-1 [1554 kB] Get:76 http://deb.debian.org/debian unstable/main amd64 openssl-provider-legacy amd64 3.6.5-1 [329 kB] Get:77 http://deb.debian.org/debian unstable/main amd64 patch amd64 2.8-2 [134 kB] Get:78 http://deb.debian.org/debian unstable/main amd64 patchutils amd64 0.4.5-1 [85.7 kB] Get:79 http://deb.debian.org/debian unstable/main amd64 pci.ids all 0.0~2026.09.23-1 [287 kB] Get:80 http://deb.debian.org/debian unstable/main amd64 perl amd64 5.42.3-1 [266 kB] Get:81 http://deb.debian.org/debian unstable/main amd64 perl-base amd64 5.42.3-1 [1878 kB] Get:82 http://deb.debian.org/debian unstable/main amd64 perl-modules-5.42 all 5.42.3-1 [3213 kB] Get:83 http://deb.debian.org/debian unstable/main amd64 perl-openssl-defaults amd64 7+b2 [6724 B] Get:84 http://deb.debian.org/debian unstable/main amd64 perltidy all 20250105-1.1 [706 kB] Get:85 http://deb.debian.org/debian unstable/main amd64 pkgconf amd64 2.5.1-4 [33.6 kB] Get:86 http://deb.debian.org/debian unstable/main amd64 pkgconf-bin amd64 2.5.1-4 [35.9 kB] Get:87 http://deb.debian.org/debian unstable/main amd64 plzip amd64 1.13-2 [72.8 kB] Get:88 http://deb.debian.org/debian unstable/main amd64 po-debconf all 1.0.22 [216 kB] Get:89 http://deb.debian.org/debian unstable/main amd64 libwayland-client0 amd64 1.26.0-1 [29.4 kB] Get:90 http://deb.debian.org/debian unstable/main amd64 libwayland-cursor0 amd64 1.26.0-1 [11.8 kB] Get:91 http://deb.debian.org/debian unstable/main amd64 libwayland-egl1 amd64 1.26.0-1 [5688 B] Get:92 http://deb.debian.org/debian unstable/main amd64 libxcb-util1 amd64 0.4.1-1+b2 [23.8 kB] Get:93 http://deb.debian.org/debian unstable/main amd64 libxcb-cursor0 amd64 0.1.6-1 [17.8 kB] Get:94 http://deb.debian.org/debian unstable/main amd64 libxcb-image0 amd64 0.4.0-2+b3 [22.3 kB] Get:95 http://deb.debian.org/debian unstable/main amd64 libxcb-keysyms1 amd64 0.4.1-1+b2 [17.0 kB] Get:96 http://deb.debian.org/debian unstable/main amd64 libxcb-render-util0 amd64 0.3.10-1+b2 [18.7 kB] Get:97 http://deb.debian.org/debian unstable/main amd64 libxcb-icccm4 amd64 0.4.2-1+b2 [27.7 kB] Get:98 http://deb.debian.org/debian unstable/main amd64 libxxhash0 amd64 0.8.3-2+b2 [27.1 kB] Get:99 http://deb.debian.org/debian unstable/main amd64 libz3-4 amd64 4.13.3-1.1 [8644 kB] Get:100 http://snapshot.debian.org/archive/debian/20261003T143013Z unstable/main amd64 linux-libc-dev all 7.2.8-1 [2002 kB] Fetched 65.2 MB in 3s (23.5 MB/s) dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxml-sax-base-perl_1.09-3_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/openssl-provider-legacy_3.6.5-1_amd64.deb' dpkg-name: info: moved 'libxxf86vm1_1%3a1.1.4-2+b1_amd64.deb' to '/srv/rebuilderd/tmp/tmpt8df52yl/libxxf86vm1_1.1.4-2+b1_amd64.deb' dpkg-name: info: moved 'libxrender1_1%3a0.9.12-1+b2_amd64.deb' to '/srv/rebuilderd/tmp/tmpt8df52yl/libxrender1_0.9.12-1+b2_amd64.deb' dpkg-name: info: moved 'libxext6_2%3a1.3.4-1+b4_amd64.deb' to '/srv/rebuilderd/tmp/tmpt8df52yl/libxext6_1.3.4-1+b4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxmlb2_0.3.29-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/ncurses-base_6.6+20260608-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb-icccm4_0.4.2-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/patch_2.8-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libwayland-client0_1.26.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/octave-dev_11.3.0-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxkbcommon-x11-0_1.13.1-1_amd64.deb' dpkg-name: info: moved 'libxau6_1%3a1.0.11-1+b2_amd64.deb' to '/srv/rebuilderd/tmp/tmpt8df52yl/libxau6_1.0.11-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/pkgconf-bin_2.5.1-4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb-xfixes0_1.17.0-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libwww-robotrules-perl_6.03-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxml-sax-perl_1.02+dfsg-5_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb-xinput0_1.17.0-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libwebp7_1.6.0-0.1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/perl-base_5.42.3-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libyuv0_0.0.1971.20260904-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/ncurses-bin_6.6+20260608-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/perl-openssl-defaults_7+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libze1_1.32.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/po-debconf_1.0.22_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb-randr0_1.17.0-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/octave-io_2.7.2-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/lintian_2.141.0_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb-util1_0.4.1-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/perl-modules-5.42_5.42.3-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libz3-4_4.13.3-1.1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/pci.ids_0.0~2026.09.23-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb-shape0_1.17.0-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb-keysyms1_0.4.1-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/perltidy_20250105-1.1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/make_4.4.1-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb-glx0_1.17.0-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb-cursor0_0.1.6-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/m4_1.4.21-1_amd64.deb' dpkg-name: info: moved 'libxau-dev_1%3a1.0.11-1+b2_amd64.deb' to '/srv/rebuilderd/tmp/tmpt8df52yl/libxau-dev_1.0.11-1+b2_amd64.deb' dpkg-name: info: moved 'libxcursor1_1%3a1.2.3-1+b2_amd64.deb' to '/srv/rebuilderd/tmp/tmpt8df52yl/libxcursor1_1.2.3-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libwebpmux3_1.6.0-0.1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb1_1.17.0-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxml-libxml-perl_2.0207+dfsg+really+2.0134-8+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxkbcommon0_1.13.1-1_amd64.deb' dpkg-name: info: moved 'libxpm4_1%3a3.5.19-1_amd64.deb' to '/srv/rebuilderd/tmp/tmpt8df52yl/libxpm4_3.5.19-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/perl_5.42.3-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/mawk_1.3.4.20260302-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxxhash0_0.8.3-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb-render-util0_0.3.10-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb-render0_1.17.0-2+b2_amd64.deb' dpkg-name: info: moved 'libx11-6_2%3a1.8.13-1_amd64.deb' to '/srv/rebuilderd/tmp/tmpt8df52yl/libx11-6_1.8.13-1_amd64.deb' dpkg-name: info: moved 'libxfixes3_1%3a6.0.0-2+b5_amd64.deb' to '/srv/rebuilderd/tmp/tmpt8df52yl/libxfixes3_6.0.0-2+b5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/nettle-dev_3.10.2-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/octave-datatypes_1.5.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libwmflite-0.2-7_0.2.14-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxml2-16_2.15.4+dfsg-1_amd64.deb' dpkg-name: info: moved 'libxinerama1_2%3a1.1.4-3+b5_amd64.deb' to '/srv/rebuilderd/tmp/tmpt8df52yl/libxinerama1_1.1.4-3+b5_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxs-parse-keyword-perl_0.51-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/octave-datatypes-common_1.5.0-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libyaml-0-2_0.2.5-2+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/octave_11.3.0-1+b1_amd64.deb' dpkg-name: info: moved 'libxdmcp-dev_1%3a1.1.5-2+b1_amd64.deb' to '/srv/rebuilderd/tmp/tmpt8df52yl/libxdmcp-dev_1.1.5-2+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb-sync1_1.17.0-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/linux-libc-dev_7.2.8-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/openssl_3.6.5-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libyaml-tiny-perl_1.76-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/ocl-icd-libopencl1_2.3.4-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libwww-perl_6.83-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libwww-mechanize-perl_2.22-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb-dri3-0_1.17.0-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/plzip_1.13-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libzstd1_1.5.7+dfsg-4_amd64.deb' dpkg-name: info: moved 'libx11-dev_2%3a1.8.13-1_amd64.deb' to '/srv/rebuilderd/tmp/tmpt8df52yl/libx11-dev_1.8.13-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/netbase_6.6_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb-shm0_1.17.0-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb1-dev_1.17.0-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxnvctrl0_535.171.04-1+b3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libzstd-dev_1.5.7+dfsg-4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/licensecheck_3.3.9-1_all.deb' dpkg-name: info: moved 'libx11-xcb1_2%3a1.8.13-1_amd64.deb' to '/srv/rebuilderd/tmp/tmpt8df52yl/libx11-xcb1_1.8.13-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxs-parse-sublike-perl_0.41-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libwayland-egl1_1.26.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libwayland-cursor0_1.26.0-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxstring-perl_0.005-2+b7_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/pkgconf_2.5.1-4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb-xkb1_1.17.0-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/mesa-libgallium_26.2.4-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/lzop_1.04-2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libyaml-libyaml-perl_0.910.0+ds-1+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxml-namespacesupport-perl_1.12-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/man-db_2.13.1-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb-present0_1.17.0-2+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/patchutils_0.4.5-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libyaml-pp-perl_0.41.0-1_all.deb' dpkg-name: info: moved 'libxdmcp6_1%3a1.1.5-2+b1_amd64.deb' to '/srv/rebuilderd/tmp/tmpt8df52yl/libxdmcp6_1.1.5-2+b1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/octave-common_11.3.0-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxshmfence1_1.3.3-1+b2_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmpt8df52yl/libxcb-image0_0.4.0-2+b3_amd64.deb' dpkg-name: info: moved 'libx11-data_2%3a1.8.13-1_all.deb' to '/srv/rebuilderd/tmp/tmpt8df52yl/libx11-data_1.8.13-1_all.deb' Get:1 http://deb.debian.org/debian unstable/main amd64 procps amd64 2:4.0.7-1 [989 kB] Get:2 http://deb.debian.org/debian unstable/main amd64 readline-common all 8.3-4 [74.8 kB] Get:3 http://deb.debian.org/debian unstable/main amd64 sed amd64 4.9-3 [331 kB] Get:4 http://deb.debian.org/debian unstable/main amd64 sensible-utils all 0.0.26 [27.0 kB] Get:5 http://deb.debian.org/debian unstable/main amd64 shared-mime-info amd64 2.4-5+b3 [758 kB] Get:6 http://deb.debian.org/debian unstable/main amd64 systemd amd64 262-1 [3477 kB] Get:7 http://deb.debian.org/debian unstable/main amd64 sysvinit-utils amd64 3.18-1 [29.7 kB] Get:8 http://deb.debian.org/debian unstable/main amd64 t1utils amd64 1.41-4 [62.1 kB] Get:9 http://deb.debian.org/debian unstable/main amd64 tar amd64 1.35+dfsg-6 [825 kB] Get:10 http://deb.debian.org/debian unstable/main amd64 tex-common all 6.20 [29.7 kB] Get:11 http://deb.debian.org/debian unstable/main amd64 texinfo all 7.3-2 [1877 kB] Get:12 http://deb.debian.org/debian unstable/main amd64 texinfo-lib amd64 7.3-2+b1 [704 kB] Get:13 http://deb.debian.org/debian unstable/main amd64 tzdata all 2026e-1 [262 kB] Get:14 http://deb.debian.org/debian unstable/main amd64 ucf all 3.0056 [47.1 kB] Get:15 http://deb.debian.org/debian unstable/main amd64 unzip amd64 6.0-31 [176 kB] Get:16 http://deb.debian.org/debian unstable/main amd64 util-linux amd64 2.42.4-1 [1254 kB] Get:17 http://deb.debian.org/debian unstable/main amd64 xkb-data all 2.48-1 [841 kB] Get:18 http://deb.debian.org/debian unstable/main amd64 x11-common all 1:7.7+26 [217 kB] Get:19 http://deb.debian.org/debian unstable/main amd64 xorg-sgml-doctools all 1:1.12.1-1 [23.9 kB] Get:20 http://deb.debian.org/debian unstable/main amd64 x11proto-dev all 2025.1-1 [605 kB] Get:21 http://deb.debian.org/debian unstable/main amd64 xtrans-dev all 1.6.0-1 [93.5 kB] Get:22 http://deb.debian.org/debian unstable/main amd64 xz-utils amd64 5.8.4-1 [761 kB] Get:23 http://deb.debian.org/debian unstable/main amd64 zlib1g amd64 1:1.3.dfsg+really1.3.2-3 [90.9 kB] Get:24 http://deb.debian.org/debian unstable/main amd64 zlib1g-dev amd64 1:1.3.dfsg+really1.3.2-3 [918 kB] Fetched 14.5 MB in 0s (47.3 MB/s) dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/sensible-utils_0.0.26_all.deb' dpkg-name: info: moved 'procps_2%3a4.0.7-1_amd64.deb' to '/srv/rebuilderd/tmp/tmptup9iodl/procps_4.0.7-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/xkb-data_2.48-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/xtrans-dev_1.6.0-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/util-linux_2.42.4-1_amd64.deb' dpkg-name: info: moved 'zlib1g_1%3a1.3.dfsg+really1.3.2-3_amd64.deb' to '/srv/rebuilderd/tmp/tmptup9iodl/zlib1g_1.3.dfsg+really1.3.2-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/ucf_3.0056_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/readline-common_8.3-4_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/tex-common_6.20_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/shared-mime-info_2.4-5+b3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/texinfo_7.3-2_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/tar_1.35+dfsg-6_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/unzip_6.0-31_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/systemd_262-1_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/t1utils_1.41-4_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/texinfo-lib_7.3-2+b1_amd64.deb' dpkg-name: info: moved 'x11-common_1%3a7.7+26_all.deb' to '/srv/rebuilderd/tmp/tmptup9iodl/x11-common_7.7+26_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/xz-utils_5.8.4-1_amd64.deb' dpkg-name: info: moved 'xorg-sgml-doctools_1%3a1.12.1-1_all.deb' to '/srv/rebuilderd/tmp/tmptup9iodl/xorg-sgml-doctools_1.12.1-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/sed_4.9-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/x11proto-dev_2025.1-1_all.deb' dpkg-name: info: moved 'zlib1g-dev_1%3a1.3.dfsg+really1.3.2-3_amd64.deb' to '/srv/rebuilderd/tmp/tmptup9iodl/zlib1g-dev_1.3.dfsg+really1.3.2-3_amd64.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/tzdata_2026e-1_all.deb' dpkg-name: warning: skipping '/srv/rebuilderd/tmp/tmptup9iodl/sysvinit-utils_3.18-1_amd64.deb' dpkg-buildpackage: info: source package debootsnap-dummy dpkg-buildpackage: info: source version 1.0 dpkg-buildpackage: info: source distribution unstable dpkg-buildpackage: info: source changed by Equivs Dummy Package Generator dpkg-source --before-build . dpkg-buildpackage: info: host architecture amd64 debian/rules clean dh clean dh_clean debian/rules binary dh binary dh_update_autotools_config dh_autoreconf create-stamp debian/debhelper-build-stamp dh_prep dh_auto_install --destdir=debian/debootsnap-dummy/ dh_install dh_installdocs dh_installchangelogs dh_perl dh_link dh_strip_nondeterminism dh_compress dh_fixperms dh_missing dh_installdeb dh_gencontrol dh_md5sums dh_builddeb dpkg-deb: building package 'debootsnap-dummy' in '../debootsnap-dummy_1.0_all.deb'. dpkg-genbuildinfo --build=binary -O../debootsnap-dummy_1.0_amd64.buildinfo dpkg-genchanges --build=binary -O../debootsnap-dummy_1.0_amd64.changes dpkg-genchanges: info: binary-only upload (no source code included) dpkg-source --after-build . dpkg-buildpackage: info: binary-only upload (no source included) The package has been created. Attention, the package has been created in the /srv/rebuilderd/tmp/tmp9la7tdre/cache directory, not in ".." as indicated by the message above! I: automatically chosen mode: unshare I: chroot architecture amd64 is equal to the host's architecture I: using /srv/rebuilderd/tmp/mmdebstrap.4_fEM3isDR as tempdir I: running --setup-hook directly: /usr/share/mmdebstrap/hooks/maybe-merged-usr/setup00.sh /srv/rebuilderd/tmp/mmdebstrap.4_fEM3isDR 127.0.0.1 - - [04/Oct/2026 23:33:07] code 404, message File not found 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./InRelease HTTP/1.1" 404 - Ign:1 http://localhost:45007 ./ InRelease 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./Release HTTP/1.1" 200 - Get:2 http://localhost:45007 ./ Release [462 B] 127.0.0.1 - - [04/Oct/2026 23:33:07] code 404, message File not found 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./Release.gpg HTTP/1.1" 404 - Ign:3 http://localhost:45007 ./ Release.gpg 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./Packages HTTP/1.1" 200 - Get:4 http://localhost:45007 ./ Packages [895 kB] Fetched 896 kB in 0s (38.2 MB/s) Reading package lists... usr-is-merged found but not real -- not running merged-usr setup hook I: skipping apt-get update because it was already run I: downloading packages with apt... 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./gcc-16-base_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libc-gconv-modules-extra_2.43-6_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libc6_2.43-6_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libgcc-s1_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./mawk_1.3.4.20260302-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./base-files_14.2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libtinfo6_6.6%2b20260608-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./debianutils_5.24_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./bash_5.3-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libacl1_2.4.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libattr1_2.6.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libgmp10_6.3.0%2bdfsg-5%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libpcre2-8-0_10.48-3.1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libselinux1_3.11-2.1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libzstd1_1.5.7%2bdfsg-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./zlib1g_1.3.dfsg%2breally1.3.2-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libssl3t64_3.6.5-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./openssl-provider-legacy_3.6.5-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libsystemd0_262-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./coreutils_9.10-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./dash_0.5.12-12_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./diffutils_3.12-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libbz2-1.0_1.0.8-6%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./liblzma5_5.8.4-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libmd0_1.3.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./dpkg_1.23.11_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./findutils_4.11.0-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./grep_3.12-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./gzip_1.14-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./hostname_3.25_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./ncurses-bin_6.6%2b20260608-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libcrypt1_4.5.2%2b20251210-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./perl-base_5.42.3-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./sed_4.9-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./tar_1.35%2bdfsg-6_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libaudit-common_4.2.1-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libcap-ng0_0.9.6-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libaudit1_4.2.1-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libdb5.3t64_5.3.28%2bdfsg2-11%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./debconf_1.5.92_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libpam0g_1.7.0-8_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libpam-modules-bin_1.7.0-8_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libpam-modules_1.7.0-8_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libpam-runtime_1.7.0-8_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libblkid1_2.42.4-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libmount1_2.42.4-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libsmartcols1_2.42.4-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libudev1_262-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libuuid1_2.42.4-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./util-linux_2.42.4-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libdebconfclient0_0.283_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./base-passwd_3.6.8_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./init-system-helpers_1.69%2bnmu3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./libc-bin_2.43-6_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./ncurses-base_6.6%2b20260608-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:07] "GET /./sysvinit-utils_3.18-1_amd64.deb HTTP/1.1" 200 - I: extracting archives... I: running --extract-hook directly: /usr/share/mmdebstrap/hooks/maybe-merged-usr/extract00.sh /srv/rebuilderd/tmp/mmdebstrap.4_fEM3isDR 127.0.0.1 - - [04/Oct/2026 23:33:08] code 404, message File not found 127.0.0.1 - - [04/Oct/2026 23:33:08] "GET /./InRelease HTTP/1.1" 404 - Ign:1 http://localhost:45007 ./ InRelease 127.0.0.1 - - [04/Oct/2026 23:33:08] "GET /./Release HTTP/1.1" 304 - Hit:2 http://localhost:45007 ./ Release 127.0.0.1 - - [04/Oct/2026 23:33:08] code 404, message File not found 127.0.0.1 - - [04/Oct/2026 23:33:08] "GET /./Release.gpg HTTP/1.1" 404 - Ign:3 http://localhost:45007 ./ Release.gpg Reading package lists... usr-is-merged found but not real -- not running merged-usr extract hook I: installing essential packages... I: running --essential-hook directly: /usr/share/mmdebstrap/hooks/maybe-merged-usr/essential00.sh /srv/rebuilderd/tmp/mmdebstrap.4_fEM3isDR usr-is-merged was not installed in a previous hook -- not running merged-usr essential hook I: installing remaining packages inside the chroot... 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libsystemd-shared_262-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./systemd_262-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libexpat1_2.8.5-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./sensible-utils_0.0.26_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./tzdata_2026e-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libstdc%2b%2b6_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libuchardet0_0.0.8-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./groff-base_1.24.2-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./bsdextrautils_2.42.4-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libgdbm6t64_1.26-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libpipeline1_1.5.8-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libseccomp2_2.6.1-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./man-db_2.13.1-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./netbase_6.6_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libncursesw6_6.6%2b20260608-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libproc2-1_4.0.7-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./procps_4.0.7-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./bzip2_1.0.8-6%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./openssl_3.6.5-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./ca-certificates_20260816_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libmagic-mgc_5.47-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libmagic1t64_5.47-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./file_5.47-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./gettext-base_1.0-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./perl-modules-5.42_5.42.3-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libgdbm-compat4t64_1.26-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libperl5.42_5.42.3-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./perl_5.42.3-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libtext-charwidth-perl_0.04-12%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libtext-wrapi18n-perl_0.06-11_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./ucf_3.0056_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./xz-utils_5.8.4-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./aglfn_1.7%2bgit20191031.4036a9c-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libatomic1_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libffi8_3.8.0-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libglib2.0-0t64_2.90.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libxml2-16_2.15.4%2bdfsg-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./shared-mime-info_2.4-5%2bb3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libnghttp3-9_1.17.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libngtcp2-16_1.24.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libbrotli1_1.2.0-4%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libnettle8t64_3.10.2-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libhogweed6t64_3.10.2-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libunistring5_1.4.2-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libidn2-0_2.3.8-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libp11-kit0_0.26.5-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libtasn1-6_4.21.0-2%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libgnutls30t64_3.8.13-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libkrb5support0_1.22.1-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libcom-err2_1.47.4-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libk5crypto3_1.22.1-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libkeyutils1_1.6.3-6%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libkrb5-3_1.22.1-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libgssapi-krb5-2_1.22.1-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libsasl2-modules-db_2.1.28%2bdfsg1-11_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libsasl2-2_2.1.28%2bdfsg1-11_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libldap2_2.6.14%2bdfsg-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libnghttp2-14_1.70.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libngtcp2-crypto-gnutls8_1.24.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libpsl5t64_0.23.3-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libssh2-1t64_1.11.1-6_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libcurl4-gnutls_8.23.0%7erc2-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libfyaml0_0.9.4-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libstemmer0d_3.1.1-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libxmlb2_0.3.29-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libappstream5_1.2.1-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./appstream_1.2.1-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./m4_1.4.21-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./autoconf_2.73-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./autotools-dev_20240727.1%2bnmu1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./automake_1.19-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./autopoint_1.0-5_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libsframe3_2.47-6_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./binutils-common_2.47-6_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libbinutils_2.47-6_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libgprofng0_2.47-6_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libctf-nobfd0_2.47-6_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libctf0_2.47-6_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libjansson4_2.15.1-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./binutils-x86-64-linux-gnu_2.47-6_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./binutils_2.47-6_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libc-dev-bin_2.43-6_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./linux-libc-dev_7.2.8-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libc6-dev_2.43-6_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libisl23_0.28-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libmpfr6_4.2.2-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./libmpc3_1.3.1-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:23] "GET /./cpp-16-x86-64-linux-gnu_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./cpp-16_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./cpp-x86-64-linux-gnu_16.1.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./cpp_16.1.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libcc1-0_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libgomp1_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libitm1_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libasan8_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./liblsan0_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libtsan2_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libubsan1_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libhwasan0_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libquadmath0_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libgcc-16-dev_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./gcc-16-x86-64-linux-gnu_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./gcc-16_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./gcc-x86-64-linux-gnu_16.1.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./gcc_16.1.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libstdc%2b%2b-16-dev_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./g%2b%2b-16-x86-64-linux-gnu_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./g%2b%2b-16_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./g%2b%2b-x86-64-linux-gnu_16.1.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./g%2b%2b_16.1.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./make_4.4.1-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libdpkg-perl_1.23.11_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./patch_2.8-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./dpkg-dev_1.23.11_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./build-essential_12.12_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libcapture-tiny-perl_0.50-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libparams-someutil-perl_1.11-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libsub-install-perl_0.929-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libdata-optlist-perl_0.115-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libb-hooks-op-check-perl_0.22-3%2bb5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libdynaloader-functions-perl_0.004-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libdevel-callchecker-perl_0.009-3%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libparams-classify-perl_0.015-2%2bb7_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libmodule-runtime-perl_0.018-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libtry-tiny-perl_0.32-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libmodule-implementation-perl_0.09-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libpackage-stash-perl_0.40-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libclass-load-perl_0.25-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libio-stringy-perl_2.113-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libparams-validate-perl_1.31-2%2bb5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libparams-util-perl_1.102-3%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libsub-exporter-perl_0.990-1.1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libgetopt-long-descriptive-perl_0.117-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libio-tiecombine-perl_1.005-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libmodule-pluggable-perl_6.4-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libstring-rewriteprefix-perl_0.009-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libapp-cmd-perl_0.340-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libboolean-perl_0.46-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libsub-uplevel-perl_0.2800-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libtest-exception-perl_0.43-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libcarp-assert-more-perl_2.9.0-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libfile-which-perl_1.27-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libfile-homedir-perl_1.006-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libclone-choose-perl_0.010-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libhash-merge-perl_0.302-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libexporter-tiny-perl_1.006003-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./liblist-moreutils-xs-perl_0.430-4%2bb3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./liblist-moreutils-perl_0.430-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./liblog-log4perl-perl_1.57-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libmouse-perl_2.6.2-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libmousex-nativetraits-perl_1.09-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libmousex-strictconstructor-perl_0.02-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libparse-recdescent-perl_1.967015%2bdfsg-4_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libpath-tiny-perl_0.150-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libregexp-common-perl_2024080801-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libconfig-model-perl_2.167-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libjson-perl_4.10000-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libpod-pom-perl_2.01-4_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libyaml-pp-perl_0.41.0-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./cme_1.049-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./comerr-dev_2.1-1.47.4-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libdebhelper-perl_14.5_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libtool_2.6.2-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./dh-autoreconf_23_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libarchive-zip-perl_1.68-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libfile-stripnondeterminism-perl_1.15.1-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./dh-strip-nondeterminism_1.15.1-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libelf1t64_0.196-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./dwz_0.17-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./gettext_1.0-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./intltool-debian_0.35.0%2b20060710.6_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./po-debconf_1.0.22_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./debhelper_14.5_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libhwloc15_2.15.0-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libogg0_1.3.6-2%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libvorbis0a_1.3.7-3%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libxau6_1.0.11-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libxdmcp6_1.1.5-2%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libxcb1_1.17.0-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libx11-data_1.8.13-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libx11-6_1.8.13-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libxext6_1.3.4-1%2bb4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libglvnd0_1.7.0-3%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libdrm-common_2.4.134-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libdrm2_2.4.134-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libdrm-amdgpu1_2.4.134-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./pci.ids_0.0%7e2026.09.23-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libpciaccess0_0.19-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libdrm-intel1_2.4.134-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libbsd0_0.12.2-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libedit2_3.1-20260512-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libz3-4_4.13.3-1.1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libllvm22_22.1.8-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libsensors-config_3.6.2-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libsensors5_3.6.2-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libx11-xcb1_1.8.13-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libxcb-dri3-0_1.17.0-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libxcb-present0_1.17.0-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libxcb-randr0_1.17.0-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libxcb-sync1_1.17.0-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libxcb-xfixes0_1.17.0-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./libxshmfence1_1.3.3-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:24] "GET /./mesa-libgallium_26.2.4-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libgbm1_26.2.4-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libvulkan1_1.4.363.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libgl1-mesa-dri_26.2.4-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libxcb-glx0_1.17.0-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libxcb-shm0_1.17.0-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libxxf86vm1_1.1.4-2%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libglx-mesa0_26.2.4-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libglx0_1.7.0-3%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libgl1_1.7.0-3%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libtask-weaken-perl_1.06-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libcpanel-json-xs-perl_4.51-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libnet-domain-tld-perl_1.75-4_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libdata-validate-domain-perl_0.15-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libnet-ipv6addr-perl_1.02-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libnet-netmask-perl_2.0003-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libnetaddr-ip-perl_4.079%2bdfsg-2%2bb6_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libdata-validate-ip-perl_0.31-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libdata-validate-uri-perl_0.07-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libgpg-error0_1.61-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libksba8_1.8.1-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libqscintilla2-qt6-l10n_2.14.1%2bdfsg-4_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libclass-inspector-perl_1.36-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libfile-sharedir-perl_1.118-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libsub-exporter-progressive-perl_0.001013-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libvariable-magic-perl_0.65-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libb-hooks-endofscope-perl_0.28-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libsub-identify-perl_0.14-4%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libsub-name-perl_0.28-1%2bb3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libnamespace-clean-perl_0.27-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libnamespace-autoclean-perl_0.31-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libeval-closure-perl_0.14-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libclass-data-inheritable-perl_0.10-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libdevel-stacktrace-perl_2.0500-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libexception-class-perl_1.45-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libparams-validationcompiler-perl_0.31-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libclone-perl_0.50-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libclone-pp-perl_1.08-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libalgorithm-c3-perl_0.11-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libclass-c3-perl_0.35-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libmro-compat-perl_0.15-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libclass-method-modifiers-perl_2.15-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./librole-tiny-perl_2.002005-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libsub-quote-perl_2.006009-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libxstring-perl_0.005-2%2bb7_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libspecio-perl_0.53-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libdatetime-locale-perl_1.46-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libclass-singleton-perl_1.6-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libdatetime-timezone-perl_2.71-1%2b2026e_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libdatetime-perl_1.67-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libdatetime-format-strptime-perl_1.8000-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libdatetime-format-builder-perl_0.8300-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./xorg-sgml-doctools_1.12.1-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./x11proto-dev_2025.1-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libxau-dev_1.0.11-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libxdmcp-dev_1.1.5-2%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libxcb1-dev_1.17.0-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libssl-dev_3.6.5-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./zlib1g-dev_1.3.dfsg%2breally1.3.2-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libssh2-1-dev_1.11.1-6_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libqhull-r8.0_2020.2-9_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libsz2_1.1.7-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libsuitesparseconfig7_7.14.1%2bdfsg-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libamd3_7.14.1%2bdfsg-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libblas3_3.12.1-8_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libgfortran5_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./liblapack3_3.12.1-8_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libarpack2t64_3.9.1-6%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libccolamd3_7.14.1%2bdfsg-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libcamd3_7.14.1%2bdfsg-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libcolamd3_7.14.1%2bdfsg-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libcholmod5_7.14.1%2bdfsg-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libcxsparse4_7.14.1%2bdfsg-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libfftw3-double3_3.3.11-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libfftw3-single3_3.3.11-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libpng16-16t64_1.6.59-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libfreetype6_2.14.3%2bdfsg-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./fonts-freefont-otf_20211204%2bsvn4273-4_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./fontconfig-config_2.17.1-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libfontconfig1_2.17.1-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libpixman-1-0_0.46.4-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libxcb-render0_1.17.0-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libxrender1_0.9.12-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libcairo2_1.18.4-3%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libdbus-1-3_1.16.2-8_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libwayland-client0_1.26.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libdecor-0-0_0.2.5-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./fontconfig_2.17.1-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libfribidi0_1.0.16-5%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libgraphite2-3_1.3.15-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libharfbuzz0b_12.3.2-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libthai-data_0.1.30-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libdatrie1_0.2.14-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libthai0_0.1.30-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libpango-1.0-0_1.58.2-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libpangoft2-1.0-0_1.58.2-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libpangocairo-1.0-0_1.58.2-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libwayland-cursor0_1.26.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libxfixes3_6.0.0-2%2bb5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libxcursor1_1.2.3-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libxinerama1_1.1.4-3%2bb5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./xkb-data_2.48-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libxkbcommon0_1.13.1-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libfltk1.4_1.4.4-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libegl-mesa0_26.2.4-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libegl1_1.7.0-3%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libopengl0_1.7.0-3%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libglu1-mesa_9.0.2-1.1%2bb4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libwayland-egl1_1.26.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libfltk-gl1.4_1.4.4-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libgl2ps1.4_1.4.2%2bdfsg1-4%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libltdl7_2.6.2-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libglpk40_5.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libsharpyuv0_1.6.0-0.1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libde265-0_1.1.3-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libheif-plugin-libde265_1.23.4-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libdav1d7_1.5.4-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libheif-plugin-dav1d_1.23.4-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libheif1_1.23.4-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libjbig0_2.1-6.1%2bb3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libjpeg62-turbo_3.1.3-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libhwy1t64_1.3.0-5.1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./liblcms2-2_2.19.1-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libjxl0.11_0.11.2-5.1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libdeflate0_1.25-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./liblerc4_4.2.0%2bds-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libwebp7_1.6.0-0.1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libtiff6_4.7.2-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libwebpmux3_1.6.0-0.1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libwmflite-0.2-7_0.2.14-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libgraphicsmagick-q16-3t64_1.4%2breally1.3.48-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libgraphicsmagick%2b%2b-q16-12t64_1.4%2breally1.3.48-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libevent-core-2.1-7t64_2.1.13-stable-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libevent-pthreads-2.1-7t64_2.1.13-stable-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libnl-3-200_3.12.0-2%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libnl-route-3-200_3.12.0-2%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libibverbs1_65.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./ibverbs-providers_65.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libnuma1_2.0.19-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libpsm2-2_11.2.185-2.1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./librdmacm1t64_65.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libfabric1_2.1.0-1.1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libesmtp6_1.1.0-3.2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libxnvctrl0_535.171.04-1%2bb3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libze1_1.32.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./ocl-icd-libopencl1_2.3.4-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libhwloc-plugins_2.15.0-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libpmix2t64_7.0.0%7erc1-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libllvm21_21.1.8-13_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libclang-common-21-dev_21.1.8-13_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libamd-comgr3_7.0.2%2bdfsg-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libhsa-runtime64-1_6.4.3%2bdfsg-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libamdhip64-6_6.4.3-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libfuse3-4_3.18.3-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libibumad3_65.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libibmad5_65.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libucx0_1.22.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libucc1_1.9.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libopenmpi40_6.0.0%7erc2-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libhdf5-openmpi-320_2.2.0%2brepack-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libasound2-data_1.2.16.1-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libasound2t64_1.2.16.1-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:25] "GET /./libopus0_1.6.1-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libsamplerate0_0.2.2-4%2bb3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libjack-jackd2-0_1.9.22%7edfsg-6_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libportaudio2_19.7.0-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libqrupdate1_1.2.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libb2-1_0.98.1-1.1%2bb3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libdouble-conversion3_3.4.0-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libicu78_78.3-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libpcre2-16-0_10.48-3.1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./liburing2_2.15-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libqt6core6t64_6.11.2%2bdfsg-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./x11-common_7.7%2b26_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libice6_1.1.1-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libevdev2_1.13.7%2bdfsg-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libmtdev1t64_1.1.7-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libgudev-1.0-0_238-7%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libwacom-common_2.20.0-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libwacom9_2.20.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libinput-bin_1.31.3-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libinput10_1.31.3-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libmd4c0_0.5.3-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libqt6dbus6_6.11.2%2bdfsg-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libsm6_1.2.6-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libts0t64_1.22-1.1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libxcb-util1_0.4.1-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libxcb-image0_0.4.0-2%2bb3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libxcb-render-util0_0.3.10-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libxcb-cursor0_0.1.6-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libxcb-icccm4_0.4.2-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libxcb-keysyms1_0.4.1-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libxcb-shape0_1.17.0-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libxcb-xinput0_1.17.0-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libxcb-xkb1_1.17.0-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libxkbcommon-x11-0_1.13.1-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libqt6gui6_6.11.2%2bdfsg-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libavahi-common-data_0.8-18_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libavahi-common3_0.8-18_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libavahi-client3_0.8-18_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libcups2t64_2.4.18-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libqt6widgets6_6.11.2%2bdfsg-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libqt6printsupport6_6.11.2%2bdfsg-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libqscintilla2-qt6-15_2.14.1%2bdfsg-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libqt6core5compat6_6.11.2-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libqt6sql6_6.11.2%2bdfsg-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libqt6help6_6.11.2-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libduktape207_2.7.0-2%2bb3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libproxy1v5_0.5.12-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libqt6network6_6.11.2%2bdfsg-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libqt6opengl6_6.11.2%2bdfsg-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libqt6openglwidgets6_6.11.2%2bdfsg-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libqt6xml6_6.11.2%2bdfsg-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./readline-common_8.3-4_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libreadline8t64_8.3-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libflac14_1.5.0%2bds-5%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libmpg123-0t64_1.33.7-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libmp3lame0_4.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libvorbisenc2_1.3.7-3%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libsndfile1_1.2.2-4%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libspqr4_7.14.1%2bdfsg-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libumfpack6_7.14.1%2bdfsg-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libtext-unidecode-perl_1.30-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libintl-perl_1.37-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libxml-namespacesupport-perl_1.12-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libxml-sax-base-perl_1.09-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libxml-sax-perl_1.02%2bdfsg-5_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libxml-libxml-perl_2.0207%2bdfsg%2breally%2b2.0134-8%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./texinfo-lib_7.3-2%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./tex-common_6.20_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./texinfo_7.3-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./octave-common_11.3.0-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./octave_11.3.0-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./octave-io_2.7.2-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libldap-dev_2.6.14%2bdfsg-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libfftw3-quad3_3.3.11-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libconfig-inifiles-perl_3.003000-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libncurses6_6.6%2b20260608-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libncurses-dev_6.6%2b20260608-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libreadline-dev_8.3-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./liblzo2-2_2.10-3%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./liblua5.4-0_5.4.9-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libpkgconf7_2.5.1-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./pkgconf-bin_2.5.1-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./pkgconf_2.5.1-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libhtml-tagset-perl_3.24-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./liburi-perl_5.37-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libhtml-parser-perl_3.83-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libcgi-pm-perl_4.72-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libencode-locale-perl_1.05-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libtimedate-perl_2.3500-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libhttp-date-perl_6.08-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libio-html-perl_1.004-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./liblwp-mediatypes-perl_6.04-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libhttp-message-perl_7.04-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libhtml-form-perl_6.13-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libhtml-tree-perl_5.07-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libhttp-cookies-perl_6.12-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libfile-listing-perl_6.16-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libhttp-negotiate-perl_6.01-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./perl-openssl-defaults_7%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libnet-ssleay-perl_1.96-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libio-socket-ssl-perl_2.099-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libnet-http-perl_6.24-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./liblwp-protocol-https-perl_6.15-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libwww-robotrules-perl_6.03-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libwww-perl_6.83-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libwww-mechanize-perl_2.22-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libregexp-wildcards-perl_1.05-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libsafe-isa-perl_1.000010-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libppi-perl_1.291-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libreadonly-perl_2.050-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libppix-quotelike-perl_0.024-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libmarkdown2_2.2.7-2.1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libtext-markdown-discount-perl_0.18-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libxs-parse-keyword-perl_0.51-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libsyntax-keyword-try-perl_0.31-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libfeature-compat-try-perl_0.05-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libtime-duration-perl_1.21-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libnumber-compare-perl_0.03-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libexporter-lite-perl_0.09-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libyaml-tiny-perl_1.76-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./liblingua-en-inflect-perl_1.905-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libpod-parser-perl_1.67-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libpod-constants-perl_0.19-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libdata-messagepack-perl_1.02-3%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libtext-xslate-perl_3.5.9-2%2bb3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libclass-xsaccessor-perl_1.19-4%2bb7_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libtext-glob-perl_0.11-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./octave-datatypes-common_1.5.0-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./octave-datatypes_1.5.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libemail-address-xs-perl_1.05-1%2bb5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libhdf5-320_2.2.0%2brepack-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libhdf5-hl-320_2.2.0%2brepack-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libhdf5-hl-cpp-320_2.2.0%2brepack-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libb-keywords-perl_1.29-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libconfig-tiny-perl_2.30-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./liblist-someutils-perl_0.59-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libclass-tiny-perl_1.008-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libpod-spell-perl_1.27-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libppix-regexp-perl_0.092-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libppix-utils-perl_0.003-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libstring-format-perl_1.18-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./perltidy_20250105-1.1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libperl-critic-perl_1.156-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libhdf5-fortran-320_2.2.0%2brepack-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libhdf5-hl-fortran-320_2.2.0%2brepack-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libgmpxx4ldbl_6.3.0%2bdfsg-5%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libgmp-dev_6.3.0%2bdfsg-5%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./nettle-dev_3.10.2-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libiterator-perl_0.03%2bds1-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libabsl20260526_20260526.0-2%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libdatetime-format-iso8601-perl_0.19-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libterm-readkey-perl_2.38-2%2bb5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./hdf5-helpers_2.2.0%2brepack-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./xtrans-dev_1.6.0-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libx11-dev_1.8.13-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libglx-dev_1.7.0-3%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libimport-into-perl_1.002005-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libmoo-perl_2.005005-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libindirect-perl_0.39-2%2bb5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libxs-parse-sublike-perl_0.41-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libobject-pad-perl_0.825-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libfeature-compat-class-perl_0.08-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libio-interactive-perl_1.027-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./liblog-any-perl_1.720-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./liblog-any-adapter-screen-perl_0.141-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libpath-iterator-rule-perl_1.015-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libset-intspan-perl_1.19-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libstring-copyright-perl_0.003014-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libstring-escape-perl_2010.002-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libarray-intspan-perl_2.004-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libregexp-pattern-license-perl_3.11.2-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libregexp-pattern-perl_0.2.14-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libstring-license-perl_0.0.11-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./licensecheck_3.3.9-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libgfortran-16-dev_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libyaml-0-2_0.2.5-2%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libyaml-libyaml-perl_0.910.0%2bds-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libconfig-model-backend-yaml-perl_2.134-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libmldbm-perl_2.05-4_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libjpeg62-turbo-dev_3.1.3-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libjpeg-dev_3.1.3-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libhdf5-cpp-320_2.2.0%2brepack-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libnet-smtp-ssl-perl_1.04-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libmailtools-perl_2.22-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./gnuplot-data_6.0.3%2bdfsg1-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libaom3_3.14.1-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libgav1-2_0.20.0-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./librav1e0.8_0.8.1-12_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libsvtav1enc4_4.1.0%2bdfsg-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libyuv0_0.0.1971.20260904-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libavif16_1.4.2-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libimagequant0_4.4.1-1%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libxpm4_3.5.19-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libgd3_2.3.3-14_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./gnuplot-nox_6.0.3%2bdfsg1-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libdatetime-format-rfc3339-perl_1.10.0-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libtoml-tiny-perl_0.22-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libblas-dev_3.12.1-8_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libaliased-perl_0.34-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libiterator-util-perl_0.02%2bds1-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libdata-dpath-perl_0.60-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./liblist-utilsby-perl_0.12-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libstrictures-perl_2.000006-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./lzop_1.04-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libconst-fast-perl_0.014-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libfftw3-long3_3.3.11-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libfftw3-bin_3.3.11-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libfftw3-dev_3.3.11-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libmoox-aliases-perl_0.001006-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./liblist-compare-perl_0.55-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libunistring-dev_1.4.2-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./liblapack-dev_3.12.1-8_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./gfortran-16-x86-64-linux-gnu_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./gfortran-16_16.2.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./gfortran-x86-64-linux-gnu_16.1.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./gfortran_16.1.0-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./liblz1_1.16-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libgssrpc4t64_1.22.1-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libproc-processtable-perl_0.637-1%2bb4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libconvert-binhex-perl_1.125-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libmime-tools-perl_5.518-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libtext-wrapper-perl_1.05-4_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libsereal-decoder-perl_5.006%2bds-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libevent-2.1-7t64_2.1.13-stable-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libipc-run3-perl_0.049-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./patchutils_0.4.5-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libdata-section-perl_0.200008-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libtext-template-perl_1.61-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libsoftware-license-perl_0.104007-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libsoftware-licensemoreutils-perl_1.009-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libunbound8_1.26.1-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libgnutls-dane0t64_3.8.13-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libngtcp2-dev_1.24.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./diffstat_1.69-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libassuan9_3.0.2-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libgcrypt20_1.12.4-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./gpgconf_2.4.9-7%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libnpth0t64_1.8-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libsqlite3-0_3.53.4-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./gpg_2.4.9-7%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./iso-codes_4.20.1-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libxxhash0_0.8.3-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./liblz4-1_1.10.0-10_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libapt-pkg7.0_3.3.3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libapt-pkg-perl_0.1.43%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libberkeleydb-perl_0.66-2%2bb2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libdevel-size-perl_0.87-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./distro-info-data_2026.08.20-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libdistro-info-perl_1.19_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libipc-system-simple-perl_1.30-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:26] "GET /./libfile-basedir-perl_0.09-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libfile-find-rule-perl_0.35-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libfile-libmagic-perl_1.23-2%2bb3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libio-string-perl_1.08-4_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libfont-ttf-perl_1.06-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libhtml-html5-entities-perl_0.004-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libhtml-tokeparser-simple-perl_3.16-4_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libjson-maybexs-perl_1.004008-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./liblist-someutils-xs-perl_0.59-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libperlio-gzip-perl_0.20-1%2bb5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libperlio-utf8-strict-perl_0.010-1%2bb4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libsereal-encoder-perl_5.006%2bds-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libsort-versions-perl_1.62-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libtext-levenshteinxs-perl_0.03-5%2bb5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libtime-moment-perl_0.46-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libunicode-utf8-perl_0.75-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./plzip_1.13-2_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./t1utils_1.41-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./unzip_6.0-31_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./lintian_2.141.0_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libidn2-dev_2.3.8-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libkadm5clnt-mit12_1.22.1-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libgl-dev_1.7.0-3%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libtasn1-6-dev_4.21.0-2%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libp11-kit-dev_0.26.5-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libaec0_1.1.7-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libaec-dev_1.1.7-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libbrotli-dev_1.2.0-4%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libngtcp2-crypto-ossl0_1.24.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libcurl4t64_8.23.0%7erc2-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libkdb5-10t64_1.22.1-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libkadm5srv-mit12_1.22.1-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./krb5-multidev_1.22.1-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libkrb5-dev_1.22.1-3_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libnghttp2-dev_1.70.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libnghttp3-dev_1.17.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libngtcp2-crypto-ossl-dev_1.24.0-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libpsl-dev_0.23.3-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./librtmp1_2.6-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libgnutls28-dev_3.8.13-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./librtmp-dev_2.6-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libzstd-dev_1.5.7%2bdfsg-4_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libcurl4-openssl-dev_8.23.0%7erc2-1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libhdf5-dev_2.2.0%2brepack-5_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./octave-dev_11.3.0-1%2bb1_amd64.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./liberror-perl_0.17030-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libparse-debcontrol-perl_2.005-6_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libsoftware-copyright-perl_0.015-1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libtext-reform-perl_1.20-5_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libtext-autoformat-perl_1.750000-2_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libtext-levenshtein-damerau-perl_0.41-3_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./libconfig-model-dpkg-perl_3.027_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./dh-octave-autopkgtest_1.18.1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./dh-octave_1.18.1_all.deb HTTP/1.1" 200 - 127.0.0.1 - - [04/Oct/2026 23:33:27] "GET /./debootsnap-dummy_1.0_all.deb HTTP/1.1" 200 - I: running --customize-hook directly: /srv/rebuilderd/tmp/tmp9la7tdre/apt_install.sh /srv/rebuilderd/tmp/mmdebstrap.4_fEM3isDR Reading package lists... Building dependency tree... Reading state information... libasound2-data is already the newest version (1.2.16.1-2). libasound2-data set to manually installed. dpkg is already the newest version (1.23.11). libarray-intspan-perl is already the newest version (2.004-2). libarray-intspan-perl set to manually installed. gettext is already the newest version (1.0-5). gettext set to manually installed. gnuplot-data is already the newest version (6.0.3+dfsg1-1). gnuplot-data set to manually installed. libabsl20260526 is already the newest version (20260526.0-2+b1). libabsl20260526 set to manually installed. libapt-pkg-perl is already the newest version (0.1.43+b1). libapt-pkg-perl set to manually installed. cpp-16 is already the newest version (16.2.0-3). cpp-16 set to manually installed. dh-octave-autopkgtest is already the newest version (1.18.1). dh-octave-autopkgtest set to manually installed. libattr1 is already the newest version (1:2.6.0-1). hostname is already the newest version (3.25). debhelper is already the newest version (14.5). debhelper set to manually installed. libaom3 is already the newest version (3.14.1-1). libaom3 set to manually installed. g++-16 is already the newest version (16.2.0-3). g++-16 set to manually installed. fonts-freefont-otf is already the newest version (20211204+svn4273-4). fonts-freefont-otf set to manually installed. appstream is already the newest version (1.2.1-1). appstream set to manually installed. diffstat is already the newest version (1.69-1). diffstat set to manually installed. libavahi-common3 is already the newest version (0.8-18). libavahi-common3 set to manually installed. gpg is already the newest version (2.4.9-7+b1). gpg set to manually installed. gnuplot-nox is already the newest version (6.0.3+dfsg1-1). gnuplot-nox set to manually installed. bsdextrautils is already the newest version (2.42.4-1). bsdextrautils set to manually installed. build-essential is already the newest version (12.12). build-essential set to manually installed. coreutils is already the newest version (9.10-1). gzip is already the newest version (1.14-1). ibverbs-providers is already the newest version (65.0-1). ibverbs-providers set to manually installed. gfortran-16-x86-64-linux-gnu is already the newest version (16.2.0-3). gfortran-16-x86-64-linux-gnu set to manually installed. gfortran-x86-64-linux-gnu is already the newest version (4:16.1.0-3). gfortran-x86-64-linux-gnu set to manually installed. findutils is already the newest version (4.11.0-2). debianutils is already the newest version (5.24). libarpack2t64 is already the newest version (3.9.1-6+b2). libarpack2t64 set to manually installed. dwz is already the newest version (0.17-1). dwz set to manually installed. libacl1 is already the newest version (2.4.0-1). base-passwd is already the newest version (3.6.8). g++ is already the newest version (4:16.1.0-3). g++ set to manually installed. autotools-dev is already the newest version (20240727.1+nmu1). autotools-dev set to manually installed. intltool-debian is already the newest version (0.35.0+20060710.6). intltool-debian set to manually installed. cpp-x86-64-linux-gnu is already the newest version (4:16.1.0-3). cpp-x86-64-linux-gnu set to manually installed. dh-strip-nondeterminism is already the newest version (1.15.1-1). dh-strip-nondeterminism set to manually installed. aglfn is already the newest version (1.7+git20191031.4036a9c-2). aglfn set to manually installed. binutils-common is already the newest version (2.47-6). binutils-common set to manually installed. grep is already the newest version (3.12-1). dash is already the newest version (0.5.12-12). gcc-16 is already the newest version (16.2.0-3). gcc-16 set to manually installed. debconf is already the newest version (1.5.92). comerr-dev is already the newest version (2.1-1.47.4-1+b2). comerr-dev set to manually installed. libamd3 is already the newest version (1:7.14.1+dfsg-1). libamd3 set to manually installed. autopoint is already the newest version (1.0-5). autopoint set to manually installed. fontconfig is already the newest version (2.17.1-5). fontconfig set to manually installed. libassuan9 is already the newest version (3.0.2-2+b2). libassuan9 set to manually installed. libaliased-perl is already the newest version (0.34-3). libaliased-perl set to manually installed. libamdhip64-6 is already the newest version (6.4.3-5). libamdhip64-6 set to manually installed. fontconfig-config is already the newest version (2.17.1-5). fontconfig-config set to manually installed. libaec-dev is already the newest version (1.1.7-1). libaec-dev set to manually installed. libappstream5 is already the newest version (1.2.1-1). libappstream5 set to manually installed. gfortran is already the newest version (4:16.1.0-3). gfortran set to manually installed. file is already the newest version (1:5.47-4). file set to manually installed. libamd-comgr3 is already the newest version (7.0.2+dfsg-3). libamd-comgr3 set to manually installed. gcc is already the newest version (4:16.1.0-3). gcc set to manually installed. g++-16-x86-64-linux-gnu is already the newest version (16.2.0-3). g++-16-x86-64-linux-gnu set to manually installed. libasan8 is already the newest version (16.2.0-3). libasan8 set to manually installed. libasound2t64 is already the newest version (1.2.16.1-2). libasound2t64 set to manually installed. dpkg-dev is already the newest version (1.23.11). dpkg-dev set to manually installed. krb5-multidev is already the newest version (1.22.1-3). krb5-multidev set to manually installed. libavif16 is already the newest version (1.4.2-1). libavif16 set to manually installed. libatomic1 is already the newest version (16.2.0-3). libatomic1 set to manually installed. hdf5-helpers is already the newest version (2.2.0+repack-5). hdf5-helpers set to manually installed. gpgconf is already the newest version (2.4.9-7+b1). gpgconf set to manually installed. libavahi-client3 is already the newest version (0.8-18). libavahi-client3 set to manually installed. libarchive-zip-perl is already the newest version (1.68-1). libarchive-zip-perl set to manually installed. cpp-16-x86-64-linux-gnu is already the newest version (16.2.0-3). cpp-16-x86-64-linux-gnu set to manually installed. libavahi-common-data is already the newest version (0.8-18). libavahi-common-data set to manually installed. dh-octave is already the newest version (1.18.1). dh-octave set to manually installed. gettext-base is already the newest version (1.0-5). gettext-base set to manually installed. automake is already the newest version (1:1.19-2). automake set to manually installed. g++-x86-64-linux-gnu is already the newest version (4:16.1.0-3). g++-x86-64-linux-gnu set to manually installed. binutils-x86-64-linux-gnu is already the newest version (2.47-6). binutils-x86-64-linux-gnu set to manually installed. gcc-16-base is already the newest version (16.2.0-3). groff-base is already the newest version (1.24.2-2). groff-base set to manually installed. iso-codes is already the newest version (4.20.1-1). iso-codes set to manually installed. distro-info-data is already the newest version (2026.08.20-1). distro-info-data set to manually installed. autoconf is already the newest version (2.73-2). autoconf set to manually installed. cpp is already the newest version (4:16.1.0-3). cpp set to manually installed. diffutils is already the newest version (1:3.12-1). gfortran-16 is already the newest version (16.2.0-3). gfortran-16 set to manually installed. bash is already the newest version (5.3-4). gcc-x86-64-linux-gnu is already the newest version (4:16.1.0-3). gcc-x86-64-linux-gnu set to manually installed. libalgorithm-c3-perl is already the newest version (0.11-2). libalgorithm-c3-perl set to manually installed. bzip2 is already the newest version (1.0.8-6+b2). bzip2 set to manually installed. libaudit-common is already the newest version (1:4.2.1-1). cme is already the newest version (1.049-1). cme set to manually installed. libaudit1 is already the newest version (1:4.2.1-1). ca-certificates is already the newest version (20260816). ca-certificates set to manually installed. binutils is already the newest version (2.47-6). binutils set to manually installed. gcc-16-x86-64-linux-gnu is already the newest version (16.2.0-3). gcc-16-x86-64-linux-gnu set to manually installed. libapp-cmd-perl is already the newest version (0.340-1). libapp-cmd-perl set to manually installed. libapt-pkg7.0 is already the newest version (3.3.3). libapt-pkg7.0 set to manually installed. libaec0 is already the newest version (1.1.7-1). libaec0 set to manually installed. init-system-helpers is already the newest version (1.69+nmu3). base-files is already the newest version (14.2). dh-autoreconf is already the newest version (23). dh-autoreconf set to manually installed. libclass-singleton-perl is already the newest version (1.6-2). libclass-singleton-perl set to manually installed. libb-hooks-op-check-perl is already the newest version (0.22-3+b5). libb-hooks-op-check-perl set to manually installed. libcarp-assert-more-perl is already the newest version (2.9.0-1). libcarp-assert-more-perl set to manually installed. libdata-validate-uri-perl is already the newest version (0.07-3). libdata-validate-uri-perl set to manually installed. libclass-xsaccessor-perl is already the newest version (1.19-4+b7). libclass-xsaccessor-perl set to manually installed. libcap-ng0 is already the newest version (0.9.6-1). libcpanel-json-xs-perl is already the newest version (4.51-1). libcpanel-json-xs-perl set to manually installed. libdatetime-format-builder-perl is already the newest version (0.8300-1). libdatetime-format-builder-perl set to manually installed. libboolean-perl is already the newest version (0.46-3). libboolean-perl set to manually installed. libclass-inspector-perl is already the newest version (1.36-3). libclass-inspector-perl set to manually installed. libemail-address-xs-perl is already the newest version (1.05-1+b5). libemail-address-xs-perl set to manually installed. libblas3 is already the newest version (3.12.1-8). libblas3 set to manually installed. libconst-fast-perl is already the newest version (0.014-2). libconst-fast-perl set to manually installed. libcapture-tiny-perl is already the newest version (0.50-1). libcapture-tiny-perl set to manually installed. libc-bin is already the newest version (2.43-6). libbsd0 is already the newest version (0.12.2-3). libbsd0 set to manually installed. libcholmod5 is already the newest version (1:7.14.1+dfsg-1). libcholmod5 set to manually installed. libdata-messagepack-perl is already the newest version (1.02-3+b1). libdata-messagepack-perl set to manually installed. libbrotli-dev is already the newest version (1.2.0-4+b1). libbrotli-dev set to manually installed. libclang-common-21-dev is already the newest version (1:21.1.8-13). libclang-common-21-dev set to manually installed. libdb5.3t64 is already the newest version (5.3.28+dfsg2-11+b1). libconfig-model-dpkg-perl is already the newest version (3.027). libconfig-model-dpkg-perl set to manually installed. libegl-mesa0 is already the newest version (26.2.4-1). libegl-mesa0 set to manually installed. libcolamd3 is already the newest version (1:7.14.1+dfsg-1). libcolamd3 set to manually installed. libcairo2 is already the newest version (1.18.4-3+b1). libcairo2 set to manually installed. libdebconfclient0 is already the newest version (0.283). libedit2 is already the newest version (3.1-20260512-1). libedit2 set to manually installed. libbrotli1 is already the newest version (1.2.0-4+b1). libbrotli1 set to manually installed. libclass-data-inheritable-perl is already the newest version (0.10-1). libclass-data-inheritable-perl set to manually installed. libdata-section-perl is already the newest version (0.200008-1). libdata-section-perl set to manually installed. libcups2t64 is already the newest version (2.4.18-1). libcups2t64 set to manually installed. libdistro-info-perl is already the newest version (1.19). libdistro-info-perl set to manually installed. libdevel-stacktrace-perl is already the newest version (2.0500-1). libdevel-stacktrace-perl set to manually installed. libberkeleydb-perl is already the newest version (0.66-2+b2). libberkeleydb-perl set to manually installed. libdatetime-locale-perl is already the newest version (1:1.46-1). libdatetime-locale-perl set to manually installed. libdevel-callchecker-perl is already the newest version (0.009-3+b1). libdevel-callchecker-perl set to manually installed. libcurl4t64 is already the newest version (8.23.0~rc2-1). libcurl4t64 set to manually installed. libdecor-0-0 is already the newest version (0.2.5-1+b1). libdecor-0-0 set to manually installed. libconfig-model-backend-yaml-perl is already the newest version (2.134-2). libconfig-model-backend-yaml-perl set to manually installed. libdatetime-format-iso8601-perl is already the newest version (0.19-1). libdatetime-format-iso8601-perl set to manually installed. libclone-pp-perl is already the newest version (1.08-2). libclone-pp-perl set to manually installed. libencode-locale-perl is already the newest version (1.05-3). libencode-locale-perl set to manually installed. libblkid1 is already the newest version (2.42.4-1). libclone-choose-perl is already the newest version (0.010-2). libclone-choose-perl set to manually installed. libclone-perl is already the newest version (0.50-1+b2). libclone-perl set to manually installed. libclass-tiny-perl is already the newest version (1.008-2). libclass-tiny-perl set to manually installed. libcurl4-gnutls is already the newest version (8.23.0~rc2-1). libcurl4-gnutls set to manually installed. libdatetime-format-rfc3339-perl is already the newest version (1.10.0-1). libdatetime-format-rfc3339-perl set to manually installed. libc-dev-bin is already the newest version (2.43-6). libc-dev-bin set to manually installed. libcrypt1 is already the newest version (1:4.5.2+20251210-1). libduktape207 is already the newest version (2.7.0-2+b3). libduktape207 set to manually installed. libcc1-0 is already the newest version (16.2.0-3). libcc1-0 set to manually installed. libdrm-common is already the newest version (2.4.134-3). libdrm-common set to manually installed. libdata-optlist-perl is already the newest version (0.115-1). libdata-optlist-perl set to manually installed. libbinutils is already the newest version (2.47-6). libbinutils set to manually installed. libdata-validate-ip-perl is already the newest version (0.31-1). libdata-validate-ip-perl set to manually installed. libdrm-intel1 is already the newest version (2.4.134-3). libdrm-intel1 set to manually installed. libdouble-conversion3 is already the newest version (3.4.0-1+b1). libdouble-conversion3 set to manually installed. libb-hooks-endofscope-perl is already the newest version (0.28-2). libb-hooks-endofscope-perl set to manually installed. libdata-validate-domain-perl is already the newest version (0.15-1). libdata-validate-domain-perl set to manually installed. libdbus-1-3 is already the newest version (1.16.2-8). libdbus-1-3 set to manually installed. libc6 is already the newest version (2.43-6). libctf-nobfd0 is already the newest version (2.47-6). libctf-nobfd0 set to manually installed. libc-gconv-modules-extra is already the newest version (2.43-6). libcurl4-openssl-dev is already the newest version (8.23.0~rc2-1). libcurl4-openssl-dev set to manually installed. libelf1t64 is already the newest version (0.196-1). libelf1t64 set to manually installed. liberror-perl is already the newest version (0.17030-1). liberror-perl set to manually installed. libconvert-binhex-perl is already the newest version (1.125-3). libconvert-binhex-perl set to manually installed. libb-keywords-perl is already the newest version (1.29-1). libb-keywords-perl set to manually installed. libdrm-amdgpu1 is already the newest version (2.4.134-3). libdrm-amdgpu1 set to manually installed. libdynaloader-functions-perl is already the newest version (0.004-2). libdynaloader-functions-perl set to manually installed. libccolamd3 is already the newest version (1:7.14.1+dfsg-1). libccolamd3 set to manually installed. libdatetime-perl is already the newest version (2:1.67-1). libdatetime-perl set to manually installed. libb2-1 is already the newest version (0.98.1-1.1+b3). libb2-1 set to manually installed. libdata-dpath-perl is already the newest version (0.60-1). libdata-dpath-perl set to manually installed. libdatetime-format-strptime-perl is already the newest version (1.8000-1). libdatetime-format-strptime-perl set to manually installed. libc6-dev is already the newest version (2.43-6). libc6-dev set to manually installed. libconfig-inifiles-perl is already the newest version (3.003000-1). libconfig-inifiles-perl set to manually installed. libclass-c3-perl is already the newest version (0.35-2). libclass-c3-perl set to manually installed. libdatrie1 is already the newest version (0.2.14-2). libdatrie1 set to manually installed. libconfig-tiny-perl is already the newest version (2.30-1). libconfig-tiny-perl set to manually installed. libcom-err2 is already the newest version (1.47.4-1+b2). libcom-err2 set to manually installed. libctf0 is already the newest version (2.47-6). libctf0 set to manually installed. libdav1d7 is already the newest version (1.5.4-1). libdav1d7 set to manually installed. libde265-0 is already the newest version (1.1.3-1+b1). libde265-0 set to manually installed. libconfig-model-perl is already the newest version (2.167-1). libconfig-model-perl set to manually installed. libbz2-1.0 is already the newest version (1.0.8-6+b2). libclass-method-modifiers-perl is already the newest version (2.15-1). libclass-method-modifiers-perl set to manually installed. libcamd3 is already the newest version (1:7.14.1+dfsg-1). libcamd3 set to manually installed. libdatetime-timezone-perl is already the newest version (1:2.71-1+2026e). libdatetime-timezone-perl set to manually installed. libcxsparse4 is already the newest version (1:7.14.1+dfsg-1). libcxsparse4 set to manually installed. libcgi-pm-perl is already the newest version (4.72-1). libcgi-pm-perl set to manually installed. libegl1 is already the newest version (1.7.0-3+b1). libegl1 set to manually installed. libclass-load-perl is already the newest version (0.25-2). libclass-load-perl set to manually installed. libdrm2 is already the newest version (2.4.134-3). libdrm2 set to manually installed. libdeflate0 is already the newest version (1.25-1). libdeflate0 set to manually installed. libdevel-size-perl is already the newest version (0.87-1+b1). libdevel-size-perl set to manually installed. libblas-dev is already the newest version (3.12.1-8). libblas-dev set to manually installed. libdpkg-perl is already the newest version (1.23.11). libdpkg-perl set to manually installed. libdebhelper-perl is already the newest version (14.5). libdebhelper-perl set to manually installed. libevdev2 is already the newest version (1.13.7+dfsg-1). libevdev2 set to manually installed. libexporter-tiny-perl is already the newest version (1.006003-1). libexporter-tiny-perl set to manually installed. libfont-ttf-perl is already the newest version (1.06-2). libfont-ttf-perl set to manually installed. libfftw3-dev is already the newest version (3.3.11-1). libfftw3-dev set to manually installed. libhsa-runtime64-1 is already the newest version (6.4.3+dfsg-5). libhsa-runtime64-1 set to manually installed. libffi8 is already the newest version (3.8.0-2). libffi8 set to manually installed. libgetopt-long-descriptive-perl is already the newest version (0.117-1). libgetopt-long-descriptive-perl set to manually installed. libfabric1 is already the newest version (2.1.0-1.1+b2). libfabric1 set to manually installed. libglu1-mesa is already the newest version (9.0.2-1.1+b4). libglu1-mesa set to manually installed. libhttp-negotiate-perl is already the newest version (6.01-2). libhttp-negotiate-perl set to manually installed. libglvnd0 is already the newest version (1.7.0-3+b1). libglvnd0 set to manually installed. libexpat1 is already the newest version (2.8.5-2). libexpat1 set to manually installed. libexporter-lite-perl is already the newest version (0.09-2). libexporter-lite-perl set to manually installed. libgudev-1.0-0 is already the newest version (238-7+b2). libgudev-1.0-0 set to manually installed. libhdf5-hl-fortran-320 is already the newest version (2.2.0+repack-5). libhdf5-hl-fortran-320 set to manually installed. libhttp-date-perl is already the newest version (6.08-1). libhttp-date-perl set to manually installed. libfltk1.4 is already the newest version (1.4.4-4). libfltk1.4 set to manually installed. libgdbm6t64 is already the newest version (1.26-1+b2). libgdbm6t64 set to manually installed. libfile-find-rule-perl is already the newest version (0.35-1). libfile-find-rule-perl set to manually installed. libfile-listing-perl is already the newest version (6.16-1). libfile-listing-perl set to manually installed. libfftw3-quad3 is already the newest version (3.3.11-1). libfftw3-quad3 set to manually installed. libgssrpc4t64 is already the newest version (1.22.1-3). libgssrpc4t64 set to manually installed. libhttp-message-perl is already the newest version (7.04-1). libhttp-message-perl set to manually installed. libgl-dev is already the newest version (1.7.0-3+b1). libgl-dev set to manually installed. libheif1 is already the newest version (1.23.4-1+b1). libheif1 set to manually installed. libglx-dev is already the newest version (1.7.0-3+b1). libglx-dev set to manually installed. libglx0 is already the newest version (1.7.0-3+b1). libglx0 set to manually installed. libheif-plugin-libde265 is already the newest version (1.23.4-1+b1). libheif-plugin-libde265 set to manually installed. libharfbuzz0b is already the newest version (12.3.2-2+b2). libharfbuzz0b set to manually installed. libfile-stripnondeterminism-perl is already the newest version (1.15.1-1). libfile-stripnondeterminism-perl set to manually installed. libflac14 is already the newest version (1.5.0+ds-5+b1). libflac14 set to manually installed. libeval-closure-perl is already the newest version (0.14-3). libeval-closure-perl set to manually installed. libhtml-tokeparser-simple-perl is already the newest version (3.16-4). libhtml-tokeparser-simple-perl set to manually installed. libhdf5-dev is already the newest version (2.2.0+repack-5). libhdf5-dev set to manually installed. libgpg-error0 is already the newest version (1.61-5). libgpg-error0 set to manually installed. libhash-merge-perl is already the newest version (0.302-1). libhash-merge-perl set to manually installed. libhtml-tagset-perl is already the newest version (3.24-1). libhtml-tagset-perl set to manually installed. libfftw3-bin is already the newest version (3.3.11-1). libfftw3-bin set to manually installed. libfftw3-long3 is already the newest version (3.3.11-1). libfftw3-long3 set to manually installed. libhogweed6t64 is already the newest version (3.10.2-1+b1). libhogweed6t64 set to manually installed. libfile-which-perl is already the newest version (1.27-2). libfile-which-perl set to manually installed. libgdbm-compat4t64 is already the newest version (1.26-1+b2). libgdbm-compat4t64 set to manually installed. libevent-core-2.1-7t64 is already the newest version (2.1.13-stable-1). libevent-core-2.1-7t64 set to manually installed. libgraphicsmagick++-q16-12t64 is already the newest version (1.4+really1.3.48-1). libgraphicsmagick++-q16-12t64 set to manually installed. libfeature-compat-class-perl is already the newest version (0.08-1). libfeature-compat-class-perl set to manually installed. libfile-sharedir-perl is already the newest version (1.118-3). libfile-sharedir-perl set to manually installed. libevent-pthreads-2.1-7t64 is already the newest version (2.1.13-stable-1). libevent-pthreads-2.1-7t64 set to manually installed. libgfortran5 is already the newest version (16.2.0-3). libgfortran5 set to manually installed. libhdf5-fortran-320 is already the newest version (2.2.0+repack-5). libhdf5-fortran-320 set to manually installed. libhdf5-openmpi-320 is already the newest version (2.2.0+repack-5). libhdf5-openmpi-320 set to manually installed. libgnutls-dane0t64 is already the newest version (3.8.13-1). libgnutls-dane0t64 set to manually installed. libesmtp6 is already the newest version (1.1.0-3.2+b2). libesmtp6 set to manually installed. libgomp1 is already the newest version (16.2.0-3). libgomp1 set to manually installed. libhtml-tree-perl is already the newest version (5.07-3). libhtml-tree-perl set to manually installed. libhdf5-320 is already the newest version (2.2.0+repack-5). libhdf5-320 set to manually installed. libhwasan0 is already the newest version (16.2.0-3). libhwasan0 set to manually installed. libgl1 is already the newest version (1.7.0-3+b1). libgl1 set to manually installed. libexception-class-perl is already the newest version (1.45-1). libexception-class-perl set to manually installed. libgcrypt20 is already the newest version (1.12.4-2). libgcrypt20 set to manually installed. libfftw3-double3 is already the newest version (3.3.11-1). libfftw3-double3 set to manually installed. libhtml-html5-entities-perl is already the newest version (0.004-3). libhtml-html5-entities-perl set to manually installed. libgav1-2 is already the newest version (0.20.0-2+b2). libgav1-2 set to manually installed. libgl2ps1.4 is already the newest version (1.4.2+dfsg1-4+b1). libgl2ps1.4 set to manually installed. libhdf5-cpp-320 is already the newest version (2.2.0+repack-5). libhdf5-cpp-320 set to manually installed. libgnutls28-dev is already the newest version (3.8.13-1). libgnutls28-dev set to manually installed. libheif-plugin-dav1d is already the newest version (1.23.4-1+b1). libheif-plugin-dav1d set to manually installed. libfile-libmagic-perl is already the newest version (1.23-2+b3). libfile-libmagic-perl set to manually installed. libhtml-parser-perl is already the newest version (3.83-2+b2). libhtml-parser-perl set to manually installed. libhdf5-hl-320 is already the newest version (2.2.0+repack-5). libhdf5-hl-320 set to manually installed. libgl1-mesa-dri is already the newest version (26.2.4-1). libgl1-mesa-dri set to manually installed. libgcc-16-dev is already the newest version (16.2.0-3). libgcc-16-dev set to manually installed. libfyaml0 is already the newest version (0.9.4-1). libfyaml0 set to manually installed. libgmpxx4ldbl is already the newest version (2:6.3.0+dfsg-5+b2). libgmpxx4ldbl set to manually installed. libglx-mesa0 is already the newest version (26.2.4-1). libglx-mesa0 set to manually installed. libgmp10 is already the newest version (2:6.3.0+dfsg-5+b2). libglib2.0-0t64 is already the newest version (2.90.0-1). libglib2.0-0t64 set to manually installed. libgmp-dev is already the newest version (2:6.3.0+dfsg-5+b2). libgmp-dev set to manually installed. libgcc-s1 is already the newest version (16.2.0-3). libgbm1 is already the newest version (26.2.4-1). libgbm1 set to manually installed. libfuse3-4 is already the newest version (3.18.3-1). libfuse3-4 set to manually installed. libgfortran-16-dev is already the newest version (16.2.0-3). libgfortran-16-dev set to manually installed. libhdf5-hl-cpp-320 is already the newest version (2.2.0+repack-5). libhdf5-hl-cpp-320 set to manually installed. libfreetype6 is already the newest version (2.14.3+dfsg-2). libfreetype6 set to manually installed. libfontconfig1 is already the newest version (2.17.1-5). libfontconfig1 set to manually installed. libfile-homedir-perl is already the newest version (1.006-2). libfile-homedir-perl set to manually installed. libgprofng0 is already the newest version (2.47-6). libgprofng0 set to manually installed. libfribidi0 is already the newest version (1.0.16-5+b1). libfribidi0 set to manually installed. libevent-2.1-7t64 is already the newest version (2.1.13-stable-1). libevent-2.1-7t64 set to manually installed. libfltk-gl1.4 is already the newest version (1.4.4-4). libfltk-gl1.4 set to manually installed. libhttp-cookies-perl is already the newest version (6.12-2). libhttp-cookies-perl set to manually installed. libhtml-form-perl is already the newest version (6.13-1). libhtml-form-perl set to manually installed. libfile-basedir-perl is already the newest version (0.09-2). libfile-basedir-perl set to manually installed. libfftw3-single3 is already the newest version (3.3.11-1). libfftw3-single3 set to manually installed. libgraphite2-3 is already the newest version (1.3.15-2). libgraphite2-3 set to manually installed. libfeature-compat-try-perl is already the newest version (0.05-1). libfeature-compat-try-perl set to manually installed. libgraphicsmagick-q16-3t64 is already the newest version (1.4+really1.3.48-1). libgraphicsmagick-q16-3t64 set to manually installed. libgd3 is already the newest version (2.3.3-14). libgd3 set to manually installed. libgnutls30t64 is already the newest version (3.8.13-1). libgnutls30t64 set to manually installed. libgssapi-krb5-2 is already the newest version (1.22.1-3). libgssapi-krb5-2 set to manually installed. libglpk40 is already the newest version (5.0-3). libglpk40 set to manually installed. libmro-compat-perl is already the newest version (0.15-2). libmro-compat-perl set to manually installed. libmldbm-perl is already the newest version (2.05-4). libmldbm-perl set to manually installed. libncurses-dev is already the newest version (6.6+20260608-2). libncurses-dev set to manually installed. libjson-maybexs-perl is already the newest version (1.004008-1). libjson-maybexs-perl set to manually installed. libmagic-mgc is already the newest version (1:5.47-4). libmagic-mgc set to manually installed. libkrb5-dev is already the newest version (1.22.1-3). libkrb5-dev set to manually installed. liblapack-dev is already the newest version (3.12.1-8). liblapack-dev set to manually installed. libibumad3 is already the newest version (65.0-1). libibumad3 set to manually installed. libltdl7 is already the newest version (2.6.2-3). libltdl7 set to manually installed. liblist-moreutils-perl is already the newest version (0.430-2). liblist-moreutils-perl set to manually installed. libncurses6 is already the newest version (6.6+20260608-2). libncurses6 set to manually installed. libjxl0.11 is already the newest version (0.11.2-5.1). libjxl0.11 set to manually installed. libkadm5srv-mit12 is already the newest version (1.22.1-3). libkadm5srv-mit12 set to manually installed. libice6 is already the newest version (2:1.1.1-1+b2). libice6 set to manually installed. libio-string-perl is already the newest version (1.08-4). libio-string-perl set to manually installed. liblz4-1 is already the newest version (1.10.0-10). liblz4-1 set to manually installed. libksba8 is already the newest version (1.8.1-1). libksba8 set to manually installed. libmagic1t64 is already the newest version (1:5.47-4). libmagic1t64 set to manually installed. libjpeg62-turbo is already the newest version (1:3.1.3-4). libjpeg62-turbo set to manually installed. liblist-someutils-xs-perl is already the newest version (0.59-1+b1). liblist-someutils-xs-perl set to manually installed. libjansson4 is already the newest version (2.15.1-1). libjansson4 set to manually installed. libk5crypto3 is already the newest version (1.22.1-3). libk5crypto3 set to manually installed. libimagequant0 is already the newest version (4.4.1-1+b2). libimagequant0 set to manually installed. libimport-into-perl is already the newest version (1.002005-2). libimport-into-perl set to manually installed. libhwloc15 is already the newest version (2.15.0-2). libhwloc15 set to manually installed. libllvm22 is already the newest version (1:22.1.8-1+b2). libllvm22 set to manually installed. libkrb5support0 is already the newest version (1.22.1-3). libkrb5support0 set to manually installed. libmp3lame0 is already the newest version (4.0-1). libmp3lame0 set to manually installed. libinput10 is already the newest version (1.31.3-1). libinput10 set to manually installed. libintl-perl is already the newest version (1.37-1). libintl-perl set to manually installed. libindirect-perl is already the newest version (0.39-2+b5). libindirect-perl set to manually installed. libjson-perl is already the newest version (4.10000-1). libjson-perl set to manually installed. libitm1 is already the newest version (16.2.0-3). libitm1 set to manually installed. liblerc4 is already the newest version (4.2.0+ds-1). liblerc4 set to manually installed. libjpeg62-turbo-dev is already the newest version (1:3.1.3-4). libjpeg62-turbo-dev set to manually installed. libiterator-perl is already the newest version (0.03+ds1-2). libiterator-perl set to manually installed. libmd0 is already the newest version (1.3.0-1). libiterator-util-perl is already the newest version (0.02+ds1-2). libiterator-util-perl set to manually installed. libldap2 is already the newest version (2.6.14+dfsg-2). libldap2 set to manually installed. libnamespace-clean-perl is already the newest version (0.27-2). libnamespace-clean-perl set to manually installed. libmount1 is already the newest version (2.42.4-1). libmarkdown2 is already the newest version (2.2.7-2.1+b2). libmarkdown2 set to manually installed. libmpg123-0t64 is already the newest version (1.33.7-1). libmpg123-0t64 set to manually installed. liblwp-mediatypes-perl is already the newest version (6.04-2). liblwp-mediatypes-perl set to manually installed. libmoox-aliases-perl is already the newest version (0.001006-3). libmoox-aliases-perl set to manually installed. liblwp-protocol-https-perl is already the newest version (6.15-1). liblwp-protocol-https-perl set to manually installed. liblzo2-2 is already the newest version (2.10-3+b2). liblzo2-2 set to manually installed. libmtdev1t64 is already the newest version (1.1.7-1+b2). libmtdev1t64 set to manually installed. libio-stringy-perl is already the newest version (2.113-2). libio-stringy-perl set to manually installed. libio-html-perl is already the newest version (1.004-3). libio-html-perl set to manually installed. libldap-dev is already the newest version (2.6.14+dfsg-2). libldap-dev set to manually installed. libkeyutils1 is already the newest version (1.6.3-6+b2). libkeyutils1 set to manually installed. libhwloc-plugins is already the newest version (2.15.0-2). libhwloc-plugins set to manually installed. libibmad5 is already the newest version (65.0-1). libibmad5 set to manually installed. libidn2-0 is already the newest version (2.3.8-5). libidn2-0 set to manually installed. libjack-jackd2-0 is already the newest version (1.9.22~dfsg-6). libjack-jackd2-0 set to manually installed. libisl23 is already the newest version (0.28-1). libisl23 set to manually installed. libmousex-strictconstructor-perl is already the newest version (0.02-3). libmousex-strictconstructor-perl set to manually installed. libmouse-perl is already the newest version (2.6.2-1+b1). libmouse-perl set to manually installed. libllvm21 is already the newest version (1:21.1.8-13). libllvm21 set to manually installed. libkrb5-3 is already the newest version (1.22.1-3). libkrb5-3 set to manually installed. libmoo-perl is already the newest version (2.005005-1). libmoo-perl set to manually installed. libmousex-nativetraits-perl is already the newest version (1.09-3). libmousex-nativetraits-perl set to manually installed. libkadm5clnt-mit12 is already the newest version (1.22.1-3). libkadm5clnt-mit12 set to manually installed. libkdb5-10t64 is already the newest version (1.22.1-3). libkdb5-10t64 set to manually installed. liblist-someutils-perl is already the newest version (0.59-1). liblist-someutils-perl set to manually installed. libhwy1t64 is already the newest version (1.3.0-5.1). libhwy1t64 set to manually installed. liblz1 is already the newest version (1.16-2). liblz1 set to manually installed. liblist-utilsby-perl is already the newest version (0.12-2). liblist-utilsby-perl set to manually installed. libmodule-runtime-perl is already the newest version (0.018-1). libmodule-runtime-perl set to manually installed. libmodule-implementation-perl is already the newest version (0.09-2). libmodule-implementation-perl set to manually installed. liblog-any-adapter-screen-perl is already the newest version (0.141-2). liblog-any-adapter-screen-perl set to manually installed. libmpfr6 is already the newest version (4.2.2-3). libmpfr6 set to manually installed. libipc-run3-perl is already the newest version (0.049-1). libipc-run3-perl set to manually installed. libio-tiecombine-perl is already the newest version (1.005-3). libio-tiecombine-perl set to manually installed. libidn2-dev is already the newest version (2.3.8-5). libidn2-dev set to manually installed. liblcms2-2 is already the newest version (2.19.1-1). liblcms2-2 set to manually installed. libipc-system-simple-perl is already the newest version (1.30-2). libipc-system-simple-perl set to manually installed. libjpeg-dev is already the newest version (1:3.1.3-4). libjpeg-dev set to manually installed. libicu78 is already the newest version (78.3-2). libicu78 set to manually installed. libmailtools-perl is already the newest version (2.22-1). libmailtools-perl set to manually installed. liblzma5 is already the newest version (5.8.4-1). libmime-tools-perl is already the newest version (5.518-1). libmime-tools-perl set to manually installed. libmpc3 is already the newest version (1.3.1-3). libmpc3 set to manually installed. liblapack3 is already the newest version (3.12.1-8). liblapack3 set to manually installed. libio-socket-ssl-perl is already the newest version (2.099-1). libio-socket-ssl-perl set to manually installed. libinput-bin is already the newest version (1.31.3-1). libinput-bin set to manually installed. liblog-any-perl is already the newest version (1.720-1). liblog-any-perl set to manually installed. liblsan0 is already the newest version (16.2.0-3). liblsan0 set to manually installed. liblingua-en-inflect-perl is already the newest version (1.905-2). liblingua-en-inflect-perl set to manually installed. libmd4c0 is already the newest version (0.5.3-1). libmd4c0 set to manually installed. libio-interactive-perl is already the newest version (1.027-1). libio-interactive-perl set to manually installed. libibverbs1 is already the newest version (65.0-1). libibverbs1 set to manually installed. liblog-log4perl-perl is already the newest version (1.57-1). liblog-log4perl-perl set to manually installed. libnamespace-autoclean-perl is already the newest version (0.31-1). libnamespace-autoclean-perl set to manually installed. liblist-moreutils-xs-perl is already the newest version (0.430-4+b3). liblist-moreutils-xs-perl set to manually installed. liblist-compare-perl is already the newest version (0.55-2). liblist-compare-perl set to manually installed. libjbig0 is already the newest version (2.1-6.1+b3). libjbig0 set to manually installed. libmodule-pluggable-perl is already the newest version (6.4-1). libmodule-pluggable-perl set to manually installed. liblua5.4-0 is already the newest version (5.4.9-1). liblua5.4-0 set to manually installed. libpmix2t64 is already the newest version (7.0.0~rc1-1). libpmix2t64 set to manually installed. libpangocairo-1.0-0 is already the newest version (1.58.2-1). libpangocairo-1.0-0 set to manually installed. libportaudio2 is already the newest version (19.7.0-1+b1). libportaudio2 set to manually installed. libproxy1v5 is already the newest version (0.5.12-3). libproxy1v5 set to manually installed. libnet-netmask-perl is already the newest version (2.0003-1). libnet-netmask-perl set to manually installed. libqscintilla2-qt6-l10n is already the newest version (2.14.1+dfsg-4). libqscintilla2-qt6-l10n set to manually installed. libqt6widgets6 is already the newest version (6.11.2+dfsg-5). libqt6widgets6 set to manually installed. libngtcp2-crypto-ossl0 is already the newest version (1.24.0-1). libngtcp2-crypto-ossl0 set to manually installed. libparams-validate-perl is already the newest version (1.31-2+b5). libparams-validate-perl set to manually installed. libproc2-1 is already the newest version (2:4.0.7-1). libproc2-1 set to manually installed. libqt6core6t64 is already the newest version (6.11.2+dfsg-5). libqt6core6t64 set to manually installed. libqt6dbus6 is already the newest version (6.11.2+dfsg-5). libqt6dbus6 set to manually installed. libpsl5t64 is already the newest version (0.23.3-1). libpsl5t64 set to manually installed. libqt6network6 is already the newest version (6.11.2+dfsg-5). libqt6network6 set to manually installed. libpath-tiny-perl is already the newest version (0.150-1). libpath-tiny-perl set to manually installed. libpam-modules is already the newest version (1.7.0-8). libqt6gui6 is already the newest version (6.11.2+dfsg-5). libqt6gui6 set to manually installed. libppi-perl is already the newest version (1.291-1). libppi-perl set to manually installed. libparams-util-perl is already the newest version (1.102-3+b2). libparams-util-perl set to manually installed. libregexp-wildcards-perl is already the newest version (1.05-3). libregexp-wildcards-perl set to manually installed. libperlio-gzip-perl is already the newest version (0.20-1+b5). libperlio-gzip-perl set to manually installed. libparse-debcontrol-perl is already the newest version (2.005-6). libparse-debcontrol-perl set to manually installed. libpod-constants-perl is already the newest version (0.19-2). libpod-constants-perl set to manually installed. libreadline-dev is already the newest version (8.3-4). libreadline-dev set to manually installed. libpciaccess0 is already the newest version (0.19-2). libpciaccess0 set to manually installed. librav1e0.8 is already the newest version (0.8.1-12). librav1e0.8 set to manually installed. libogg0 is already the newest version (1.3.6-2+b1). libogg0 set to manually installed. libpangoft2-1.0-0 is already the newest version (1.58.2-1). libpangoft2-1.0-0 set to manually installed. libnghttp2-dev is already the newest version (1.70.0-1). libnghttp2-dev set to manually installed. libppix-quotelike-perl is already the newest version (0.024-1). libppix-quotelike-perl set to manually installed. libregexp-pattern-license-perl is already the newest version (3.11.2-1). libregexp-pattern-license-perl set to manually installed. libnpth0t64 is already the newest version (1.8-4). libnpth0t64 set to manually installed. libngtcp2-dev is already the newest version (1.24.0-1). libngtcp2-dev set to manually installed. libpam0g is already the newest version (1.7.0-8). libparams-classify-perl is already the newest version (0.015-2+b7). libparams-classify-perl set to manually installed. libpcre2-8-0 is already the newest version (10.48-3.1). libqrupdate1 is already the newest version (1.2.0-1). libqrupdate1 set to manually installed. libopenmpi40 is already the newest version (6.0.0~rc2-2). libopenmpi40 set to manually installed. libqt6printsupport6 is already the newest version (6.11.2+dfsg-5). libqt6printsupport6 set to manually installed. libopengl0 is already the newest version (1.7.0-3+b1). libopengl0 set to manually installed. libqhull-r8.0 is already the newest version (2020.2-9). libqhull-r8.0 set to manually installed. libnettle8t64 is already the newest version (3.10.2-1+b1). libnettle8t64 set to manually installed. libpam-modules-bin is already the newest version (1.7.0-8). libpixman-1-0 is already the newest version (0.46.4-1+b2). libpixman-1-0 set to manually installed. libpcre2-16-0 is already the newest version (10.48-3.1). libpcre2-16-0 set to manually installed. libnl-route-3-200 is already the newest version (3.12.0-2+b1). libnl-route-3-200 set to manually installed. libqt6core5compat6 is already the newest version (6.11.2-2). libqt6core5compat6 set to manually installed. libpod-parser-perl is already the newest version (1.67-1). libpod-parser-perl set to manually installed. libnghttp3-9 is already the newest version (1.17.0-1). libnghttp3-9 set to manually installed. libnghttp2-14 is already the newest version (1.70.0-1). libnghttp2-14 set to manually installed. libnet-http-perl is already the newest version (6.24-1). libnet-http-perl set to manually installed. libquadmath0 is already the newest version (16.2.0-3). libquadmath0 set to manually installed. libopus0 is already the newest version (1.6.1-1+b1). libopus0 set to manually installed. libpackage-stash-perl is already the newest version (0.40-1). libpackage-stash-perl set to manually installed. libnuma1 is already the newest version (2.0.19-1+b2). libnuma1 set to manually installed. libpath-iterator-rule-perl is already the newest version (1.015-2). libpath-iterator-rule-perl set to manually installed. libobject-pad-perl is already the newest version (0.825-1+b1). libobject-pad-perl set to manually installed. libregexp-common-perl is already the newest version (2024080801-1). libregexp-common-perl set to manually installed. libparams-someutil-perl is already the newest version (1.11-1). libparams-someutil-perl set to manually installed. libqt6openglwidgets6 is already the newest version (6.11.2+dfsg-5). libqt6openglwidgets6 set to manually installed. libreadonly-perl is already the newest version (2.050-3). libreadonly-perl set to manually installed. libpam-runtime is already the newest version (1.7.0-8). libppix-utils-perl is already the newest version (0.003-2). libppix-utils-perl set to manually installed. libngtcp2-16 is already the newest version (1.24.0-1). libngtcp2-16 set to manually installed. libngtcp2-crypto-gnutls8 is already the newest version (1.24.0-1). libngtcp2-crypto-gnutls8 set to manually installed. libpkgconf7 is already the newest version (2.5.1-4). libpkgconf7 set to manually installed. libqt6opengl6 is already the newest version (6.11.2+dfsg-5). libqt6opengl6 set to manually installed. libppix-regexp-perl is already the newest version (0.092-1). libppix-regexp-perl set to manually installed. libnet-ssleay-perl is already the newest version (1.96-2). libnet-ssleay-perl set to manually installed. libpod-spell-perl is already the newest version (1.27-1). libpod-spell-perl set to manually installed. libngtcp2-crypto-ossl-dev is already the newest version (1.24.0-1). libngtcp2-crypto-ossl-dev set to manually installed. libp11-kit-dev is already the newest version (0.26.5-1). libp11-kit-dev set to manually installed. libpsm2-2 is already the newest version (11.2.185-2.1). libpsm2-2 set to manually installed. libp11-kit0 is already the newest version (0.26.5-1). libp11-kit0 set to manually installed. libnet-ipv6addr-perl is already the newest version (1.02-1). libnet-ipv6addr-perl set to manually installed. libpod-pom-perl is already the newest version (2.01-4). libpod-pom-perl set to manually installed. libperl-critic-perl is already the newest version (1.156-1). libperl-critic-perl set to manually installed. librdmacm1t64 is already the newest version (65.0-1). librdmacm1t64 set to manually installed. libpipeline1 is already the newest version (1.5.8-3). libpipeline1 set to manually installed. libpsl-dev is already the newest version (0.23.3-1). libpsl-dev set to manually installed. libparams-validationcompiler-perl is already the newest version (0.31-1). libparams-validationcompiler-perl set to manually installed. libpng16-16t64 is already the newest version (1.6.59-1). libpng16-16t64 set to manually installed. libparse-recdescent-perl is already the newest version (1.967015+dfsg-4). libparse-recdescent-perl set to manually installed. libncursesw6 is already the newest version (6.6+20260608-2). libncursesw6 set to manually installed. libperlio-utf8-strict-perl is already the newest version (0.010-1+b4). libperlio-utf8-strict-perl set to manually installed. libreadline8t64 is already the newest version (8.3-4). libreadline8t64 set to manually installed. libqt6sql6 is already the newest version (6.11.2+dfsg-5). libqt6sql6 set to manually installed. libqscintilla2-qt6-15 is already the newest version (2.14.1+dfsg-4). libqscintilla2-qt6-15 set to manually installed. libnghttp3-dev is already the newest version (1.17.0-1). libnghttp3-dev set to manually installed. libregexp-pattern-perl is already the newest version (0.2.14-3). libregexp-pattern-perl set to manually installed. libnet-smtp-ssl-perl is already the newest version (1.04-2). libnet-smtp-ssl-perl set to manually installed. libperl5.42 is already the newest version (5.42.3-1). libperl5.42 set to manually installed. libproc-processtable-perl is already the newest version (0.637-1+b4). libproc-processtable-perl set to manually installed. libnumber-compare-perl is already the newest version (0.03-3). libnumber-compare-perl set to manually installed. libnetaddr-ip-perl is already the newest version (4.079+dfsg-2+b6). libnetaddr-ip-perl set to manually installed. libqt6xml6 is already the newest version (6.11.2+dfsg-5). libqt6xml6 set to manually installed. libqt6help6 is already the newest version (6.11.2-2). libqt6help6 set to manually installed. libnet-domain-tld-perl is already the newest version (1.75-4). libnet-domain-tld-perl set to manually installed. libnl-3-200 is already the newest version (3.12.0-2+b1). libnl-3-200 set to manually installed. libpango-1.0-0 is already the newest version (1.58.2-1). libpango-1.0-0 set to manually installed. libsensors-config is already the newest version (1:3.6.2-2). libsensors-config set to manually installed. libtext-wrapper-perl is already the newest version (1.05-4). libtext-wrapper-perl set to manually installed. librole-tiny-perl is already the newest version (2.002005-1). librole-tiny-perl set to manually installed. libtoml-tiny-perl is already the newest version (0.22-1). libtoml-tiny-perl set to manually installed. libvorbisenc2 is already the newest version (1.3.7-3+b2). libvorbisenc2 set to manually installed. libwacom-common is already the newest version (2.20.0-1). libwacom-common set to manually installed. libsoftware-copyright-perl is already the newest version (0.015-1). libsoftware-copyright-perl set to manually installed. libstring-format-perl is already the newest version (1.18-1). libstring-format-perl set to manually installed. liburing2 is already the newest version (2.15-1). liburing2 set to manually installed. libspecio-perl is already the newest version (0.53-1). libspecio-perl set to manually installed. liburi-perl is already the newest version (5.37-1). liburi-perl set to manually installed. libsm6 is already the newest version (2:1.2.6-1+b2). libsm6 set to manually installed. libsort-versions-perl is already the newest version (1.62-3). libsort-versions-perl set to manually installed. libtiff6 is already the newest version (4.7.2-1). libtiff6 set to manually installed. libsub-exporter-progressive-perl is already the newest version (0.001013-3). libsub-exporter-progressive-perl set to manually installed. libubsan1 is already the newest version (16.2.0-3). libubsan1 set to manually installed. libudev1 is already the newest version (262-1). libtest-exception-perl is already the newest version (0.43-3). libtest-exception-perl set to manually installed. libtinfo6 is already the newest version (6.6+20260608-2). libstring-escape-perl is already the newest version (2010.002-3). libstring-escape-perl set to manually installed. libstrictures-perl is already the newest version (2.000006-1). libstrictures-perl set to manually installed. libsereal-decoder-perl is already the newest version (5.006+ds-1+b1). libsereal-decoder-perl set to manually installed. libsub-uplevel-perl is already the newest version (0.2800-3). libsub-uplevel-perl set to manually installed. libssh2-1-dev is already the newest version (1.11.1-6). libssh2-1-dev set to manually installed. libsasl2-modules-db is already the newest version (2.1.28+dfsg1-11). libsasl2-modules-db set to manually installed. libsqlite3-0 is already the newest version (3.53.4-2). libsqlite3-0 set to manually installed. libsuitesparseconfig7 is already the newest version (1:7.14.1+dfsg-1). libsuitesparseconfig7 set to manually installed. libsoftware-license-perl is already the newest version (0.104007-1). libsoftware-license-perl set to manually installed. libtime-duration-perl is already the newest version (1.21-2). libtime-duration-perl set to manually installed. libunicode-utf8-perl is already the newest version (0.75-1+b1). libunicode-utf8-perl set to manually installed. libstemmer0d is already the newest version (3.1.1-1). libstemmer0d set to manually installed. libtsan2 is already the newest version (16.2.0-3). libtsan2 set to manually installed. libtimedate-perl is already the newest version (2.3500-1). libtimedate-perl set to manually installed. librtmp1 is already the newest version (2.6-1). librtmp1 set to manually installed. libspqr4 is already the newest version (1:7.14.1+dfsg-1). libspqr4 set to manually installed. libtext-markdown-discount-perl is already the newest version (0.18-1+b1). libtext-markdown-discount-perl set to manually installed. libucc1 is already the newest version (1.9.0-1). libucc1 set to manually installed. libtext-template-perl is already the newest version (1.61-1). libtext-template-perl set to manually installed. libstdc++6 is already the newest version (16.2.0-3). libstdc++6 set to manually installed. libstring-copyright-perl is already the newest version (0.003014-1). libstring-copyright-perl set to manually installed. libtasn1-6 is already the newest version (4.21.0-2+b1). libtasn1-6 set to manually installed. libsub-identify-perl is already the newest version (0.14-4+b1). libsub-identify-perl set to manually installed. libsharpyuv0 is already the newest version (1.6.0-0.1). libsharpyuv0 set to manually installed. libwacom9 is already the newest version (2.20.0-1). libwacom9 set to manually installed. libsystemd-shared is already the newest version (262-1). libsystemd-shared set to manually installed. libssl-dev is already the newest version (3.6.5-1). libssl-dev set to manually installed. libtext-charwidth-perl is already the newest version (0.04-12+b1). libtext-charwidth-perl set to manually installed. libssl3t64 is already the newest version (3.6.5-1). libsystemd0 is already the newest version (262-1). libseccomp2 is already the newest version (2.6.1-1+b1). libseccomp2 set to manually installed. libsub-quote-perl is already the newest version (2.006009-1). libsub-quote-perl set to manually installed. libtasn1-6-dev is already the newest version (4.21.0-2+b1). libtasn1-6-dev set to manually installed. libsensors5 is already the newest version (1:3.6.2-2+b2). libsensors5 set to manually installed. libunbound8 is already the newest version (1.26.1-1). libunbound8 set to manually installed. libtask-weaken-perl is already the newest version (1.06-2). libtask-weaken-perl set to manually installed. libsamplerate0 is already the newest version (0.2.2-4+b3). libsamplerate0 set to manually installed. libsereal-encoder-perl is already the newest version (5.006+ds-1+b1). libsereal-encoder-perl set to manually installed. libuuid1 is already the newest version (2.42.4-1). libsframe3 is already the newest version (2.47-6). libsframe3 set to manually installed. libsz2 is already the newest version (1.1.7-1). libsz2 set to manually installed. libsndfile1 is already the newest version (1.2.2-4+b1). libsndfile1 set to manually installed. libsmartcols1 is already the newest version (2.42.4-1). libssh2-1t64 is already the newest version (1.11.1-6). libssh2-1t64 set to manually installed. libselinux1 is already the newest version (3.11-2.1). libunistring-dev is already the newest version (1.4.2-1). libunistring-dev set to manually installed. libthai-data is already the newest version (0.1.30-3). libthai-data set to manually installed. libtry-tiny-perl is already the newest version (0.32-1). libtry-tiny-perl set to manually installed. libts0t64 is already the newest version (1.22-1.1+b2). libts0t64 set to manually installed. libstring-rewriteprefix-perl is already the newest version (0.009-1). libstring-rewriteprefix-perl set to manually installed. libumfpack6 is already the newest version (1:7.14.1+dfsg-1). libumfpack6 set to manually installed. libsoftware-licensemoreutils-perl is already the newest version (1.009-1). libsoftware-licensemoreutils-perl set to manually installed. libsafe-isa-perl is already the newest version (1.000010-1). libsafe-isa-perl set to manually installed. libtime-moment-perl is already the newest version (0.46-1+b1). libtime-moment-perl set to manually installed. libsyntax-keyword-try-perl is already the newest version (0.31-1+b1). libsyntax-keyword-try-perl set to manually installed. libvorbis0a is already the newest version (1.3.7-3+b2). libvorbis0a set to manually installed. libvariable-magic-perl is already the newest version (0.65-1). libvariable-magic-perl set to manually installed. libtext-reform-perl is already the newest version (1.20-5). libtext-reform-perl set to manually installed. libunistring5 is already the newest version (1.4.2-1). libunistring5 set to manually installed. libuchardet0 is already the newest version (0.0.8-2+b2). libuchardet0 set to manually installed. libtext-xslate-perl is already the newest version (3.5.9-2+b3). libtext-xslate-perl set to manually installed. libsub-exporter-perl is already the newest version (0.990-1.1). libsub-exporter-perl set to manually installed. librtmp-dev is already the newest version (2.6-1). librtmp-dev set to manually installed. libvulkan1 is already the newest version (1.4.363.0-1). libvulkan1 set to manually installed. libucx0 is already the newest version (1.22.0-1). libucx0 set to manually installed. libsasl2-2 is already the newest version (2.1.28+dfsg1-11). libsasl2-2 set to manually installed. libtext-unidecode-perl is already the newest version (1.30-3). libtext-unidecode-perl set to manually installed. libtext-levenshtein-damerau-perl is already the newest version (0.41-3). libtext-levenshtein-damerau-perl set to manually installed. libtext-wrapi18n-perl is already the newest version (0.06-11). libtext-wrapi18n-perl set to manually installed. libset-intspan-perl is already the newest version (1.19-3). libset-intspan-perl set to manually installed. libsvtav1enc4 is already the newest version (4.1.0+dfsg-1). libsvtav1enc4 set to manually installed. libterm-readkey-perl is already the newest version (2.38-2+b5). libterm-readkey-perl set to manually installed. libsub-name-perl is already the newest version (0.28-1+b3). libsub-name-perl set to manually installed. libtext-autoformat-perl is already the newest version (1.750000-2). libtext-autoformat-perl set to manually installed. libstring-license-perl is already the newest version (0.0.11-1). libstring-license-perl set to manually installed. libsub-install-perl is already the newest version (0.929-1). libsub-install-perl set to manually installed. libthai0 is already the newest version (0.1.30-3). libthai0 set to manually installed. libstdc++-16-dev is already the newest version (16.2.0-3). libstdc++-16-dev set to manually installed. libtext-glob-perl is already the newest version (0.11-3). libtext-glob-perl set to manually installed. libtool is already the newest version (2.6.2-3). libtool set to manually installed. libtext-levenshteinxs-perl is already the newest version (0.03-5+b5). libtext-levenshteinxs-perl set to manually installed. libxml-sax-base-perl is already the newest version (1.09-3). libxml-sax-base-perl set to manually installed. openssl-provider-legacy is already the newest version (3.6.5-1). libxau-dev is already the newest version (1:1.0.11-1+b2). libxau-dev set to manually installed. libxmlb2 is already the newest version (0.3.29-1). libxmlb2 set to manually installed. libx11-xcb1 is already the newest version (2:1.8.13-1). libx11-xcb1 set to manually installed. ncurses-base is already the newest version (6.6+20260608-2). libxcb-icccm4 is already the newest version (0.4.2-1+b2). libxcb-icccm4 set to manually installed. libxdmcp-dev is already the newest version (1:1.1.5-2+b1). libxdmcp-dev set to manually installed. patch is already the newest version (2.8-2). patch set to manually installed. libwayland-client0 is already the newest version (1.26.0-1). libwayland-client0 set to manually installed. octave-dev is already the newest version (11.3.0-1+b1). octave-dev set to manually installed. libxkbcommon-x11-0 is already the newest version (1.13.1-1). libxkbcommon-x11-0 set to manually installed. pkgconf-bin is already the newest version (2.5.1-4). pkgconf-bin set to manually installed. libxfixes3 is already the newest version (1:6.0.0-2+b5). libxfixes3 set to manually installed. libxcb-xfixes0 is already the newest version (1.17.0-2+b2). libxcb-xfixes0 set to manually installed. libwww-robotrules-perl is already the newest version (6.03-1). libwww-robotrules-perl set to manually installed. libxml-sax-perl is already the newest version (1.02+dfsg-5). libxml-sax-perl set to manually installed. libxcb-xinput0 is already the newest version (1.17.0-2+b2). libxcb-xinput0 set to manually installed. libwebp7 is already the newest version (1.6.0-0.1). libwebp7 set to manually installed. perl-base is already the newest version (5.42.3-1). libyuv0 is already the newest version (0.0.1971.20260904-2). libyuv0 set to manually installed. ncurses-bin is already the newest version (6.6+20260608-2). perl-openssl-defaults is already the newest version (7+b2). perl-openssl-defaults set to manually installed. libze1 is already the newest version (1.32.0-1). libze1 set to manually installed. po-debconf is already the newest version (1.0.22). po-debconf set to manually installed. libxcb-randr0 is already the newest version (1.17.0-2+b2). libxcb-randr0 set to manually installed. octave-io is already the newest version (2.7.2-3). octave-io set to manually installed. lintian is already the newest version (2.141.0). lintian set to manually installed. libxcb-util1 is already the newest version (0.4.1-1+b2). libxcb-util1 set to manually installed. perl-modules-5.42 is already the newest version (5.42.3-1). perl-modules-5.42 set to manually installed. libz3-4 is already the newest version (4.13.3-1.1). libz3-4 set to manually installed. pci.ids is already the newest version (0.0~2026.09.23-1). pci.ids set to manually installed. libxcb-shape0 is already the newest version (1.17.0-2+b2). libxcb-shape0 set to manually installed. libxcb-keysyms1 is already the newest version (0.4.1-1+b2). libxcb-keysyms1 set to manually installed. perltidy is already the newest version (20250105-1.1). perltidy set to manually installed. make is already the newest version (4.4.1-3). make set to manually installed. libxcb-glx0 is already the newest version (1.17.0-2+b2). libxcb-glx0 set to manually installed. libxcb-cursor0 is already the newest version (0.1.6-1). libxcb-cursor0 set to manually installed. m4 is already the newest version (1.4.21-1). m4 set to manually installed. libxau6 is already the newest version (1:1.0.11-1+b2). libxau6 set to manually installed. libxext6 is already the newest version (2:1.3.4-1+b4). libxext6 set to manually installed. libwebpmux3 is already the newest version (1.6.0-0.1). libwebpmux3 set to manually installed. libxpm4 is already the newest version (1:3.5.19-1). libxpm4 set to manually installed. libxcb1 is already the newest version (1.17.0-2+b2). libxcb1 set to manually installed. libxml-libxml-perl is already the newest version (2.0207+dfsg+really+2.0134-8+b1). libxml-libxml-perl set to manually installed. libxkbcommon0 is already the newest version (1.13.1-1). libxkbcommon0 set to manually installed. perl is already the newest version (5.42.3-1). perl set to manually installed. mawk is already the newest version (1.3.4.20260302-2). libxxf86vm1 is already the newest version (1:1.1.4-2+b1). libxxf86vm1 set to manually installed. libxxhash0 is already the newest version (0.8.3-2+b2). libxxhash0 set to manually installed. libxcb-render-util0 is already the newest version (0.3.10-1+b2). libxcb-render-util0 set to manually installed. libxcb-render0 is already the newest version (1.17.0-2+b2). libxcb-render0 set to manually installed. nettle-dev is already the newest version (3.10.2-1+b1). nettle-dev set to manually installed. octave-datatypes is already the newest version (1.5.0-1). octave-datatypes set to manually installed. libwmflite-0.2-7 is already the newest version (0.2.14-1). libwmflite-0.2-7 set to manually installed. libxml2-16 is already the newest version (2.15.4+dfsg-1). libxml2-16 set to manually installed. libxs-parse-keyword-perl is already the newest version (0.51-1). libxs-parse-keyword-perl set to manually installed. octave-datatypes-common is already the newest version (1.5.0-1). octave-datatypes-common set to manually installed. libxinerama1 is already the newest version (2:1.1.4-3+b5). libxinerama1 set to manually installed. libyaml-0-2 is already the newest version (0.2.5-2+b1). libyaml-0-2 set to manually installed. octave is already the newest version (11.3.0-1+b1). octave set to manually installed. libxcb-sync1 is already the newest version (1.17.0-2+b2). libxcb-sync1 set to manually installed. linux-libc-dev is already the newest version (7.2.8-1). linux-libc-dev set to manually installed. openssl is already the newest version (3.6.5-1). openssl set to manually installed. libyaml-tiny-perl is already the newest version (1.76-1). libyaml-tiny-perl set to manually installed. ocl-icd-libopencl1 is already the newest version (2.3.4-1+b1). ocl-icd-libopencl1 set to manually installed. libwww-perl is already the newest version (6.83-1). libwww-perl set to manually installed. libx11-dev is already the newest version (2:1.8.13-1). libx11-dev set to manually installed. libwww-mechanize-perl is already the newest version (2.22-1). libwww-mechanize-perl set to manually installed. libxcb-dri3-0 is already the newest version (1.17.0-2+b2). libxcb-dri3-0 set to manually installed. plzip is already the newest version (1.13-2). plzip set to manually installed. libx11-6 is already the newest version (2:1.8.13-1). libx11-6 set to manually installed. libzstd1 is already the newest version (1.5.7+dfsg-4). libxrender1 is already the newest version (1:0.9.12-1+b2). libxrender1 set to manually installed. netbase is already the newest version (6.6). netbase set to manually installed. libxcb-shm0 is already the newest version (1.17.0-2+b2). libxcb-shm0 set to manually installed. libx11-data is already the newest version (2:1.8.13-1). libx11-data set to manually installed. libxcb1-dev is already the newest version (1.17.0-2+b2). libxcb1-dev set to manually installed. libxnvctrl0 is already the newest version (535.171.04-1+b3). libxnvctrl0 set to manually installed. libzstd-dev is already the newest version (1.5.7+dfsg-4). libzstd-dev set to manually installed. licensecheck is already the newest version (3.3.9-1). licensecheck set to manually installed. libxcursor1 is already the newest version (1:1.2.3-1+b2). libxcursor1 set to manually installed. libxs-parse-sublike-perl is already the newest version (0.41-2). libxs-parse-sublike-perl set to manually installed. libwayland-egl1 is already the newest version (1.26.0-1). libwayland-egl1 set to manually installed. libwayland-cursor0 is already the newest version (1.26.0-1). libwayland-cursor0 set to manually installed. libxstring-perl is already the newest version (0.005-2+b7). libxstring-perl set to manually installed. pkgconf is already the newest version (2.5.1-4). pkgconf set to manually installed. libxcb-xkb1 is already the newest version (1.17.0-2+b2). libxcb-xkb1 set to manually installed. mesa-libgallium is already the newest version (26.2.4-1). mesa-libgallium set to manually installed. lzop is already the newest version (1.04-2). lzop set to manually installed. libyaml-libyaml-perl is already the newest version (0.910.0+ds-1+b1). libyaml-libyaml-perl set to manually installed. libxdmcp6 is already the newest version (1:1.1.5-2+b1). libxdmcp6 set to manually installed. libxml-namespacesupport-perl is already the newest version (1.12-2). libxml-namespacesupport-perl set to manually installed. man-db is already the newest version (2.13.1-1). man-db set to manually installed. libxcb-present0 is already the newest version (1.17.0-2+b2). libxcb-present0 set to manually installed. patchutils is already the newest version (0.4.5-1). patchutils set to manually installed. libyaml-pp-perl is already the newest version (0.41.0-1). libyaml-pp-perl set to manually installed. octave-common is already the newest version (11.3.0-1). octave-common set to manually installed. libxshmfence1 is already the newest version (1.3.3-1+b2). libxshmfence1 set to manually installed. libxcb-image0 is already the newest version (0.4.0-2+b3). libxcb-image0 set to manually installed. sensible-utils is already the newest version (0.0.26). sensible-utils set to manually installed. xkb-data is already the newest version (2.48-1). xkb-data set to manually installed. xtrans-dev is already the newest version (1.6.0-1). xtrans-dev set to manually installed. util-linux is already the newest version (2.42.4-1). ucf is already the newest version (3.0056). ucf set to manually installed. readline-common is already the newest version (8.3-4). readline-common set to manually installed. tex-common is already the newest version (6.20). tex-common set to manually installed. x11-common is already the newest version (1:7.7+26). x11-common set to manually installed. shared-mime-info is already the newest version (2.4-5+b3). shared-mime-info set to manually installed. texinfo is already the newest version (7.3-2). texinfo set to manually installed. tar is already the newest version (1.35+dfsg-6). unzip is already the newest version (6.0-31). unzip set to manually installed. xorg-sgml-doctools is already the newest version (1:1.12.1-1). xorg-sgml-doctools set to manually installed. systemd is already the newest version (262-1). systemd set to manually installed. t1utils is already the newest version (1.41-4). t1utils set to manually installed. texinfo-lib is already the newest version (7.3-2+b1). texinfo-lib set to manually installed. procps is already the newest version (2:4.0.7-1). procps set to manually installed. xz-utils is already the newest version (5.8.4-1). xz-utils set to manually installed. zlib1g is already the newest version (1:1.3.dfsg+really1.3.2-3). zlib1g-dev is already the newest version (1:1.3.dfsg+really1.3.2-3). zlib1g-dev set to manually installed. sed is already the newest version (4.9-3). x11proto-dev is already the newest version (2025.1-1). x11proto-dev set to manually installed. tzdata is already the newest version (2026e-1). tzdata set to manually installed. sysvinit-utils is already the newest version (3.18-1). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. I: running --customize-hook in shell: sh -c 'chroot "$1" dpkg -r debootsnap-dummy' exec /srv/rebuilderd/tmp/mmdebstrap.4_fEM3isDR (Reading database ... 40796 files and directories currently installed.) Removing debootsnap-dummy (1.0) ... I: running --customize-hook in shell: sh -c 'chroot "$1" dpkg-query --showformat '${binary:Package}=${Version}\n' --show > "$1/pkglist"' exec /srv/rebuilderd/tmp/mmdebstrap.4_fEM3isDR I: running special hook: download /pkglist ./pkglist I: running --customize-hook in shell: sh -c 'rm "$1/pkglist"' exec /srv/rebuilderd/tmp/mmdebstrap.4_fEM3isDR I: running special hook: upload sources.list /etc/apt/sources.list I: waiting for background processes to finish... I: cleaning package lists and apt cache... I: skipping cleanup/reproducible as requested I: creating tarball... I: done I: removing tempdir /srv/rebuilderd/tmp/mmdebstrap.4_fEM3isDR... I: success in 178.8933 seconds Downloading packages 1to 100 out of 724 Downloading packages 101to 200 out of 724 Downloading packages 201to 300 out of 724 Downloading packages 301to 400 out of 724 Downloading packages 401to 500 out of 724 Downloading packages 501to 600 out of 724 Downloading packages 601to 700 out of 724 Downloading packages 701to 724 out of 724 env --chdir=/srv/rebuilderd/tmp/rebuilderdG1cRAZ/out DEB_BUILD_OPTIONS=parallel=6 LANG=C.UTF-8 LC_COLLATE=C.UTF-8 LC_CTYPE=C.UTF-8 SOURCE_DATE_EPOCH=1791013082 SBUILD_CONFIG=/srv/rebuilderd/tmp/debrebuildfRc3uL/debrebuild.sbuildrc.22o_fjQkL3YN sbuild --build=amd64 --host=amd64 --arch-any --no-arch-all --chroot=/srv/rebuilderd/tmp/debrebuildfRc3uL/debrebuild.tar.LPAW5C6bzqN5 --chroot-mode=unshare --dist=unstable --no-run-lintian --no-run-piuparts --no-run-autopkgtest --no-apt-update --no-apt-upgrade --no-apt-distupgrade --no-source --verbose --nolog --bd-uninstallable-explainer= --build-path=/build/reproducible-path --dsc-dir=octave-statistics-2.0.0 /srv/rebuilderd/tmp/rebuilderdG1cRAZ/inputs/octave-statistics_2.0.0-1.dsc I: consider moving your ~/.sbuildrc to /srv/rebuilderd/.config/sbuild/config.pl The Debian buildds switched to the "unshare" backend and sbuild will default to it in the future. To start using "unshare" add this to your `~/.config/sbuild/config.pl`: $chroot_mode = "unshare"; If you want to keep the old "schroot" mode even in the future, add the following to your `~/.config/sbuild/config.pl`: $chroot_mode = "schroot"; $schroot = "schroot"; sbuild (Debian sbuild) 0.89.3+deb13u4 (28 December 2025) on osuosl44-amd64.novalocal +==============================================================================+ | octave-statistics 2.0.0-1 (amd64) Sun, 04 Oct 2026 23:36:06 +0000 | +==============================================================================+ Package: octave-statistics Version: 2.0.0-1 Source Version: 2.0.0-1 Distribution: unstable Machine Architecture: amd64 Host Architecture: amd64 Build Architecture: amd64 Build Type: any I: No tarballs found in /srv/rebuilderd/.cache/sbuild I: Unpacking /srv/rebuilderd/tmp/debrebuildfRc3uL/debrebuild.tar.LPAW5C6bzqN5 to /srv/rebuilderd/tmp/tmp.sbuild.TQ_u_xMheS... I: Setting up the chroot... I: Creating chroot session... I: Setting up log color... I: Setting up apt archive... +------------------------------------------------------------------------------+ | Fetch source files Sun, 04 Oct 2026 23:36:12 +0000 | +------------------------------------------------------------------------------+ Local sources ------------- /srv/rebuilderd/tmp/rebuilderdG1cRAZ/inputs/octave-statistics_2.0.0-1.dsc exists in /srv/rebuilderd/tmp/rebuilderdG1cRAZ/inputs; copying to chroot +------------------------------------------------------------------------------+ | Install package build dependencies Sun, 04 Oct 2026 23:36:13 +0000 | +------------------------------------------------------------------------------+ Setup apt archive ----------------- Merged Build-Depends: debhelper-compat (= 14), dh-octave (>= 1.11.1), dh-sequence-octave, octave, octave-datatypes (>= 1.2.6), octave-io, build-essential Merged Build-Conflicts: octave-nan Filtered Build-Depends: debhelper-compat (= 14), dh-octave (>= 1.11.1), dh-sequence-octave, octave, octave-datatypes (>= 1.2.6), octave-io, build-essential Filtered Build-Conflicts: octave-nan dpkg-deb: building package 'sbuild-build-depends-main-dummy' in '/build/reproducible-path/resolver-Kq6m6Q/apt_archive/sbuild-build-depends-main-dummy.deb'. Install main build dependencies (apt-based resolver) ---------------------------------------------------- Installing build dependencies +------------------------------------------------------------------------------+ | Check architectures Sun, 04 Oct 2026 23:36:16 +0000 | +------------------------------------------------------------------------------+ Arch check ok (amd64 included in any all) +------------------------------------------------------------------------------+ | Build environment Sun, 04 Oct 2026 23:36:16 +0000 | +------------------------------------------------------------------------------+ Kernel: Linux 6.12.111+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.111-1 (2026-09-28) amd64 (x86_64) Toolchain package versions: binutils_2.47-6 dpkg-dev_1.23.11 g++-16_16.2.0-3 gcc-16_16.2.0-3 libc6-dev_2.43-6 libstdc++-16-dev_16.2.0-3 libstdc++6_16.2.0-3 linux-libc-dev_7.2.8-1 Package versions: aglfn_1.7+git20191031.4036a9c-2 appstream_1.2.1-1 autoconf_2.73-2 automake_1:1.19-2 autopoint_1.0-5 autotools-dev_20240727.1+nmu1 base-files_14.2 base-passwd_3.6.8 bash_5.3-4 binutils_2.47-6 binutils-common_2.47-6 binutils-x86-64-linux-gnu_2.47-6 bsdextrautils_2.42.4-1 build-essential_12.12 bzip2_1.0.8-6+b2 ca-certificates_20260816 cme_1.049-1 comerr-dev_2.1-1.47.4-1+b2 coreutils_9.10-1 cpp_4:16.1.0-3 cpp-16_16.2.0-3 cpp-16-x86-64-linux-gnu_16.2.0-3 cpp-x86-64-linux-gnu_4:16.1.0-3 dash_0.5.12-12 debconf_1.5.92 debhelper_14.5 debianutils_5.24 dh-autoreconf_23 dh-octave_1.18.1 dh-octave-autopkgtest_1.18.1 dh-strip-nondeterminism_1.15.1-1 diffstat_1.69-1 diffutils_1:3.12-1 distro-info-data_2026.08.20-1 dpkg_1.23.11 dpkg-dev_1.23.11 dwz_0.17-1 file_1:5.47-4 findutils_4.11.0-2 fontconfig_2.17.1-5 fontconfig-config_2.17.1-5 fonts-freefont-otf_20211204+svn4273-4 g++_4:16.1.0-3 g++-16_16.2.0-3 g++-16-x86-64-linux-gnu_16.2.0-3 g++-x86-64-linux-gnu_4:16.1.0-3 gcc_4:16.1.0-3 gcc-16_16.2.0-3 gcc-16-base_16.2.0-3 gcc-16-x86-64-linux-gnu_16.2.0-3 gcc-x86-64-linux-gnu_4:16.1.0-3 gettext_1.0-5 gettext-base_1.0-5 gfortran_4:16.1.0-3 gfortran-16_16.2.0-3 gfortran-16-x86-64-linux-gnu_16.2.0-3 gfortran-x86-64-linux-gnu_4:16.1.0-3 gnuplot-data_6.0.3+dfsg1-1 gnuplot-nox_6.0.3+dfsg1-1 gpg_2.4.9-7+b1 gpgconf_2.4.9-7+b1 grep_3.12-1 groff-base_1.24.2-2 gzip_1.14-1 hdf5-helpers_2.2.0+repack-5 hostname_3.25 ibverbs-providers_65.0-1 init-system-helpers_1.69+nmu3 intltool-debian_0.35.0+20060710.6 iso-codes_4.20.1-1 krb5-multidev_1.22.1-3 libabsl20260526_20260526.0-2+b1 libacl1_2.4.0-1 libaec-dev_1.1.7-1 libaec0_1.1.7-1 libalgorithm-c3-perl_0.11-2 libaliased-perl_0.34-3 libamd-comgr3_7.0.2+dfsg-3 libamd3_1:7.14.1+dfsg-1 libamdhip64-6_6.4.3-5 libaom3_3.14.1-1 libapp-cmd-perl_0.340-1 libappstream5_1.2.1-1 libapt-pkg-perl_0.1.43+b1 libapt-pkg7.0_3.3.3 libarchive-zip-perl_1.68-1 libarpack2t64_3.9.1-6+b2 libarray-intspan-perl_2.004-2 libasan8_16.2.0-3 libasound2-data_1.2.16.1-2 libasound2t64_1.2.16.1-2 libassuan9_3.0.2-2+b2 libatomic1_16.2.0-3 libattr1_1:2.6.0-1 libaudit-common_1:4.2.1-1 libaudit1_1:4.2.1-1 libavahi-client3_0.8-18 libavahi-common-data_0.8-18 libavahi-common3_0.8-18 libavif16_1.4.2-1 libb-hooks-endofscope-perl_0.28-2 libb-hooks-op-check-perl_0.22-3+b5 libb-keywords-perl_1.29-1 libb2-1_0.98.1-1.1+b3 libberkeleydb-perl_0.66-2+b2 libbinutils_2.47-6 libblas-dev_3.12.1-8 libblas3_3.12.1-8 libblkid1_2.42.4-1 libboolean-perl_0.46-3 libbrotli-dev_1.2.0-4+b1 libbrotli1_1.2.0-4+b1 libbsd0_0.12.2-3 libbz2-1.0_1.0.8-6+b2 libc-bin_2.43-6 libc-dev-bin_2.43-6 libc-gconv-modules-extra_2.43-6 libc6_2.43-6 libc6-dev_2.43-6 libcairo2_1.18.4-3+b1 libcamd3_1:7.14.1+dfsg-1 libcap-ng0_0.9.6-1 libcapture-tiny-perl_0.50-1 libcarp-assert-more-perl_2.9.0-1 libcc1-0_16.2.0-3 libccolamd3_1:7.14.1+dfsg-1 libcgi-pm-perl_4.72-1 libcholmod5_1:7.14.1+dfsg-1 libclang-common-21-dev_1:21.1.8-13 libclass-c3-perl_0.35-2 libclass-data-inheritable-perl_0.10-1 libclass-inspector-perl_1.36-3 libclass-load-perl_0.25-2 libclass-method-modifiers-perl_2.15-1 libclass-singleton-perl_1.6-2 libclass-tiny-perl_1.008-2 libclass-xsaccessor-perl_1.19-4+b7 libclone-choose-perl_0.010-2 libclone-perl_0.50-1+b2 libclone-pp-perl_1.08-2 libcolamd3_1:7.14.1+dfsg-1 libcom-err2_1.47.4-1+b2 libconfig-inifiles-perl_3.003000-1 libconfig-model-backend-yaml-perl_2.134-2 libconfig-model-dpkg-perl_3.027 libconfig-model-perl_2.167-1 libconfig-tiny-perl_2.30-1 libconst-fast-perl_0.014-2 libconvert-binhex-perl_1.125-3 libcpanel-json-xs-perl_4.51-1 libcrypt1_1:4.5.2+20251210-1 libctf-nobfd0_2.47-6 libctf0_2.47-6 libcups2t64_2.4.18-1 libcurl4-gnutls_8.23.0~rc2-1 libcurl4-openssl-dev_8.23.0~rc2-1 libcurl4t64_8.23.0~rc2-1 libcxsparse4_1:7.14.1+dfsg-1 libdata-dpath-perl_0.60-1 libdata-messagepack-perl_1.02-3+b1 libdata-optlist-perl_0.115-1 libdata-section-perl_0.200008-1 libdata-validate-domain-perl_0.15-1 libdata-validate-ip-perl_0.31-1 libdata-validate-uri-perl_0.07-3 libdatetime-format-builder-perl_0.8300-1 libdatetime-format-iso8601-perl_0.19-1 libdatetime-format-rfc3339-perl_1.10.0-1 libdatetime-format-strptime-perl_1.8000-1 libdatetime-locale-perl_1:1.46-1 libdatetime-perl_2:1.67-1 libdatetime-timezone-perl_1:2.71-1+2026e libdatrie1_0.2.14-2 libdav1d7_1.5.4-1 libdb5.3t64_5.3.28+dfsg2-11+b1 libdbus-1-3_1.16.2-8 libde265-0_1.1.3-1+b1 libdebconfclient0_0.283 libdebhelper-perl_14.5 libdecor-0-0_0.2.5-1+b1 libdeflate0_1.25-1 libdevel-callchecker-perl_0.009-3+b1 libdevel-size-perl_0.87-1+b1 libdevel-stacktrace-perl_2.0500-1 libdistro-info-perl_1.19 libdouble-conversion3_3.4.0-1+b1 libdpkg-perl_1.23.11 libdrm-amdgpu1_2.4.134-3 libdrm-common_2.4.134-3 libdrm-intel1_2.4.134-3 libdrm2_2.4.134-3 libduktape207_2.7.0-2+b3 libdynaloader-functions-perl_0.004-2 libedit2_3.1-20260512-1 libegl-mesa0_26.2.4-1 libegl1_1.7.0-3+b1 libelf1t64_0.196-1 libemail-address-xs-perl_1.05-1+b5 libencode-locale-perl_1.05-3 liberror-perl_0.17030-1 libesmtp6_1.1.0-3.2+b2 libeval-closure-perl_0.14-3 libevdev2_1.13.7+dfsg-1 libevent-2.1-7t64_2.1.13-stable-1 libevent-core-2.1-7t64_2.1.13-stable-1 libevent-pthreads-2.1-7t64_2.1.13-stable-1 libexception-class-perl_1.45-1 libexpat1_2.8.5-2 libexporter-lite-perl_0.09-2 libexporter-tiny-perl_1.006003-1 libfabric1_2.1.0-1.1+b2 libfeature-compat-class-perl_0.08-1 libfeature-compat-try-perl_0.05-1 libffi8_3.8.0-2 libfftw3-bin_3.3.11-1 libfftw3-dev_3.3.11-1 libfftw3-double3_3.3.11-1 libfftw3-long3_3.3.11-1 libfftw3-quad3_3.3.11-1 libfftw3-single3_3.3.11-1 libfile-basedir-perl_0.09-2 libfile-find-rule-perl_0.35-1 libfile-homedir-perl_1.006-2 libfile-libmagic-perl_1.23-2+b3 libfile-listing-perl_6.16-1 libfile-sharedir-perl_1.118-3 libfile-stripnondeterminism-perl_1.15.1-1 libfile-which-perl_1.27-2 libflac14_1.5.0+ds-5+b1 libfltk-gl1.4_1.4.4-4 libfltk1.4_1.4.4-4 libfont-ttf-perl_1.06-2 libfontconfig1_2.17.1-5 libfreetype6_2.14.3+dfsg-2 libfribidi0_1.0.16-5+b1 libfuse3-4_3.18.3-1 libfyaml0_0.9.4-1 libgav1-2_0.20.0-2+b2 libgbm1_26.2.4-1 libgcc-16-dev_16.2.0-3 libgcc-s1_16.2.0-3 libgcrypt20_1.12.4-2 libgd3_2.3.3-14 libgdbm-compat4t64_1.26-1+b2 libgdbm6t64_1.26-1+b2 libgetopt-long-descriptive-perl_0.117-1 libgfortran-16-dev_16.2.0-3 libgfortran5_16.2.0-3 libgl-dev_1.7.0-3+b1 libgl1_1.7.0-3+b1 libgl1-mesa-dri_26.2.4-1 libgl2ps1.4_1.4.2+dfsg1-4+b1 libglib2.0-0t64_2.90.0-1 libglpk40_5.0-3 libglu1-mesa_9.0.2-1.1+b4 libglvnd0_1.7.0-3+b1 libglx-dev_1.7.0-3+b1 libglx-mesa0_26.2.4-1 libglx0_1.7.0-3+b1 libgmp-dev_2:6.3.0+dfsg-5+b2 libgmp10_2:6.3.0+dfsg-5+b2 libgmpxx4ldbl_2:6.3.0+dfsg-5+b2 libgnutls-dane0t64_3.8.13-1 libgnutls28-dev_3.8.13-1 libgnutls30t64_3.8.13-1 libgomp1_16.2.0-3 libgpg-error0_1.61-5 libgprofng0_2.47-6 libgraphicsmagick++-q16-12t64_1.4+really1.3.48-1 libgraphicsmagick-q16-3t64_1.4+really1.3.48-1 libgraphite2-3_1.3.15-2 libgssapi-krb5-2_1.22.1-3 libgssrpc4t64_1.22.1-3 libgudev-1.0-0_238-7+b2 libharfbuzz0b_12.3.2-2+b2 libhash-merge-perl_0.302-1 libhdf5-320_2.2.0+repack-5 libhdf5-cpp-320_2.2.0+repack-5 libhdf5-dev_2.2.0+repack-5 libhdf5-fortran-320_2.2.0+repack-5 libhdf5-hl-320_2.2.0+repack-5 libhdf5-hl-cpp-320_2.2.0+repack-5 libhdf5-hl-fortran-320_2.2.0+repack-5 libhdf5-openmpi-320_2.2.0+repack-5 libheif-plugin-dav1d_1.23.4-1+b1 libheif-plugin-libde265_1.23.4-1+b1 libheif1_1.23.4-1+b1 libhogweed6t64_3.10.2-1+b1 libhsa-runtime64-1_6.4.3+dfsg-5 libhtml-form-perl_6.13-1 libhtml-html5-entities-perl_0.004-3 libhtml-parser-perl_3.83-2+b2 libhtml-tagset-perl_3.24-1 libhtml-tokeparser-simple-perl_3.16-4 libhtml-tree-perl_5.07-3 libhttp-cookies-perl_6.12-2 libhttp-date-perl_6.08-1 libhttp-message-perl_7.04-1 libhttp-negotiate-perl_6.01-2 libhwasan0_16.2.0-3 libhwloc-plugins_2.15.0-2 libhwloc15_2.15.0-2 libhwy1t64_1.3.0-5.1 libibmad5_65.0-1 libibumad3_65.0-1 libibverbs1_65.0-1 libice6_2:1.1.1-1+b2 libicu78_78.3-2 libidn2-0_2.3.8-5 libidn2-dev_2.3.8-5 libimagequant0_4.4.1-1+b2 libimport-into-perl_1.002005-2 libindirect-perl_0.39-2+b5 libinput-bin_1.31.3-1 libinput10_1.31.3-1 libintl-perl_1.37-1 libio-html-perl_1.004-3 libio-interactive-perl_1.027-1 libio-socket-ssl-perl_2.099-1 libio-string-perl_1.08-4 libio-stringy-perl_2.113-2 libio-tiecombine-perl_1.005-3 libipc-run3-perl_0.049-1 libipc-system-simple-perl_1.30-2 libisl23_0.28-1 libiterator-perl_0.03+ds1-2 libiterator-util-perl_0.02+ds1-2 libitm1_16.2.0-3 libjack-jackd2-0_1.9.22~dfsg-6 libjansson4_2.15.1-1 libjbig0_2.1-6.1+b3 libjpeg-dev_1:3.1.3-4 libjpeg62-turbo_1:3.1.3-4 libjpeg62-turbo-dev_1:3.1.3-4 libjson-maybexs-perl_1.004008-1 libjson-perl_4.10000-1 libjxl0.11_0.11.2-5.1 libk5crypto3_1.22.1-3 libkadm5clnt-mit12_1.22.1-3 libkadm5srv-mit12_1.22.1-3 libkdb5-10t64_1.22.1-3 libkeyutils1_1.6.3-6+b2 libkrb5-3_1.22.1-3 libkrb5-dev_1.22.1-3 libkrb5support0_1.22.1-3 libksba8_1.8.1-1 liblapack-dev_3.12.1-8 liblapack3_3.12.1-8 liblcms2-2_2.19.1-1 libldap-dev_2.6.14+dfsg-2 libldap2_2.6.14+dfsg-2 liblerc4_4.2.0+ds-1 liblingua-en-inflect-perl_1.905-2 liblist-compare-perl_0.55-2 liblist-moreutils-perl_0.430-2 liblist-moreutils-xs-perl_0.430-4+b3 liblist-someutils-perl_0.59-1 liblist-someutils-xs-perl_0.59-1+b1 liblist-utilsby-perl_0.12-2 libllvm21_1:21.1.8-13 libllvm22_1:22.1.8-1+b2 liblog-any-adapter-screen-perl_0.141-2 liblog-any-perl_1.720-1 liblog-log4perl-perl_1.57-1 liblsan0_16.2.0-3 libltdl7_2.6.2-3 liblua5.4-0_5.4.9-1 liblwp-mediatypes-perl_6.04-2 liblwp-protocol-https-perl_6.15-1 liblz1_1.16-2 liblz4-1_1.10.0-10 liblzma5_5.8.4-1 liblzo2-2_2.10-3+b2 libmagic-mgc_1:5.47-4 libmagic1t64_1:5.47-4 libmailtools-perl_2.22-1 libmarkdown2_2.2.7-2.1+b2 libmd0_1.3.0-1 libmd4c0_0.5.3-1 libmime-tools-perl_5.518-1 libmldbm-perl_2.05-4 libmodule-implementation-perl_0.09-2 libmodule-pluggable-perl_6.4-1 libmodule-runtime-perl_0.018-1 libmoo-perl_2.005005-1 libmoox-aliases-perl_0.001006-3 libmount1_2.42.4-1 libmouse-perl_2.6.2-1+b1 libmousex-nativetraits-perl_1.09-3 libmousex-strictconstructor-perl_0.02-3 libmp3lame0_4.0-1 libmpc3_1.3.1-3 libmpfr6_4.2.2-3 libmpg123-0t64_1.33.7-1 libmro-compat-perl_0.15-2 libmtdev1t64_1.1.7-1+b2 libnamespace-autoclean-perl_0.31-1 libnamespace-clean-perl_0.27-2 libncurses-dev_6.6+20260608-2 libncurses6_6.6+20260608-2 libncursesw6_6.6+20260608-2 libnet-domain-tld-perl_1.75-4 libnet-http-perl_6.24-1 libnet-ipv6addr-perl_1.02-1 libnet-netmask-perl_2.0003-1 libnet-smtp-ssl-perl_1.04-2 libnet-ssleay-perl_1.96-2 libnetaddr-ip-perl_4.079+dfsg-2+b6 libnettle8t64_3.10.2-1+b1 libnghttp2-14_1.70.0-1 libnghttp2-dev_1.70.0-1 libnghttp3-9_1.17.0-1 libnghttp3-dev_1.17.0-1 libngtcp2-16_1.24.0-1 libngtcp2-crypto-gnutls8_1.24.0-1 libngtcp2-crypto-ossl-dev_1.24.0-1 libngtcp2-crypto-ossl0_1.24.0-1 libngtcp2-dev_1.24.0-1 libnl-3-200_3.12.0-2+b1 libnl-route-3-200_3.12.0-2+b1 libnpth0t64_1.8-4 libnuma1_2.0.19-1+b2 libnumber-compare-perl_0.03-3 libobject-pad-perl_0.825-1+b1 libogg0_1.3.6-2+b1 libopengl0_1.7.0-3+b1 libopenmpi40_6.0.0~rc2-2 libopus0_1.6.1-1+b1 libp11-kit-dev_0.26.5-1 libp11-kit0_0.26.5-1 libpackage-stash-perl_0.40-1 libpam-modules_1.7.0-8 libpam-modules-bin_1.7.0-8 libpam-runtime_1.7.0-8 libpam0g_1.7.0-8 libpango-1.0-0_1.58.2-1 libpangocairo-1.0-0_1.58.2-1 libpangoft2-1.0-0_1.58.2-1 libparams-classify-perl_0.015-2+b7 libparams-someutil-perl_1.11-1 libparams-util-perl_1.102-3+b2 libparams-validate-perl_1.31-2+b5 libparams-validationcompiler-perl_0.31-1 libparse-debcontrol-perl_2.005-6 libparse-recdescent-perl_1.967015+dfsg-4 libpath-iterator-rule-perl_1.015-2 libpath-tiny-perl_0.150-1 libpciaccess0_0.19-2 libpcre2-16-0_10.48-3.1 libpcre2-8-0_10.48-3.1 libperl-critic-perl_1.156-1 libperl5.42_5.42.3-1 libperlio-gzip-perl_0.20-1+b5 libperlio-utf8-strict-perl_0.010-1+b4 libpipeline1_1.5.8-3 libpixman-1-0_0.46.4-1+b2 libpkgconf7_2.5.1-4 libpmix2t64_7.0.0~rc1-1 libpng16-16t64_1.6.59-1 libpod-constants-perl_0.19-2 libpod-parser-perl_1.67-1 libpod-pom-perl_2.01-4 libpod-spell-perl_1.27-1 libportaudio2_19.7.0-1+b1 libppi-perl_1.291-1 libppix-quotelike-perl_0.024-1 libppix-regexp-perl_0.092-1 libppix-utils-perl_0.003-2 libproc-processtable-perl_0.637-1+b4 libproc2-1_2:4.0.7-1 libproxy1v5_0.5.12-3 libpsl-dev_0.23.3-1 libpsl5t64_0.23.3-1 libpsm2-2_11.2.185-2.1 libqhull-r8.0_2020.2-9 libqrupdate1_1.2.0-1 libqscintilla2-qt6-15_2.14.1+dfsg-4 libqscintilla2-qt6-l10n_2.14.1+dfsg-4 libqt6core5compat6_6.11.2-2 libqt6core6t64_6.11.2+dfsg-5 libqt6dbus6_6.11.2+dfsg-5 libqt6gui6_6.11.2+dfsg-5 libqt6help6_6.11.2-2 libqt6network6_6.11.2+dfsg-5 libqt6opengl6_6.11.2+dfsg-5 libqt6openglwidgets6_6.11.2+dfsg-5 libqt6printsupport6_6.11.2+dfsg-5 libqt6sql6_6.11.2+dfsg-5 libqt6widgets6_6.11.2+dfsg-5 libqt6xml6_6.11.2+dfsg-5 libquadmath0_16.2.0-3 librav1e0.8_0.8.1-12 librdmacm1t64_65.0-1 libreadline-dev_8.3-4 libreadline8t64_8.3-4 libreadonly-perl_2.050-3 libregexp-common-perl_2024080801-1 libregexp-pattern-license-perl_3.11.2-1 libregexp-pattern-perl_0.2.14-3 libregexp-wildcards-perl_1.05-3 librole-tiny-perl_2.002005-1 librtmp-dev_2.6-1 librtmp1_2.6-1 libsafe-isa-perl_1.000010-1 libsamplerate0_0.2.2-4+b3 libsasl2-2_2.1.28+dfsg1-11 libsasl2-modules-db_2.1.28+dfsg1-11 libseccomp2_2.6.1-1+b1 libselinux1_3.11-2.1 libsensors-config_1:3.6.2-2 libsensors5_1:3.6.2-2+b2 libsereal-decoder-perl_5.006+ds-1+b1 libsereal-encoder-perl_5.006+ds-1+b1 libset-intspan-perl_1.19-3 libsframe3_2.47-6 libsharpyuv0_1.6.0-0.1 libsm6_2:1.2.6-1+b2 libsmartcols1_2.42.4-1 libsndfile1_1.2.2-4+b1 libsoftware-copyright-perl_0.015-1 libsoftware-license-perl_0.104007-1 libsoftware-licensemoreutils-perl_1.009-1 libsort-versions-perl_1.62-3 libspecio-perl_0.53-1 libspqr4_1:7.14.1+dfsg-1 libsqlite3-0_3.53.4-2 libssh2-1-dev_1.11.1-6 libssh2-1t64_1.11.1-6 libssl-dev_3.6.5-1 libssl3t64_3.6.5-1 libstdc++-16-dev_16.2.0-3 libstdc++6_16.2.0-3 libstemmer0d_3.1.1-1 libstrictures-perl_2.000006-1 libstring-copyright-perl_0.003014-1 libstring-escape-perl_2010.002-3 libstring-format-perl_1.18-1 libstring-license-perl_0.0.11-1 libstring-rewriteprefix-perl_0.009-1 libsub-exporter-perl_0.990-1.1 libsub-exporter-progressive-perl_0.001013-3 libsub-identify-perl_0.14-4+b1 libsub-install-perl_0.929-1 libsub-name-perl_0.28-1+b3 libsub-quote-perl_2.006009-1 libsub-uplevel-perl_0.2800-3 libsuitesparseconfig7_1:7.14.1+dfsg-1 libsvtav1enc4_4.1.0+dfsg-1 libsyntax-keyword-try-perl_0.31-1+b1 libsystemd-shared_262-1 libsystemd0_262-1 libsz2_1.1.7-1 libtask-weaken-perl_1.06-2 libtasn1-6_4.21.0-2+b1 libtasn1-6-dev_4.21.0-2+b1 libterm-readkey-perl_2.38-2+b5 libtest-exception-perl_0.43-3 libtext-autoformat-perl_1.750000-2 libtext-charwidth-perl_0.04-12+b1 libtext-glob-perl_0.11-3 libtext-levenshtein-damerau-perl_0.41-3 libtext-levenshteinxs-perl_0.03-5+b5 libtext-markdown-discount-perl_0.18-1+b1 libtext-reform-perl_1.20-5 libtext-template-perl_1.61-1 libtext-unidecode-perl_1.30-3 libtext-wrapi18n-perl_0.06-11 libtext-wrapper-perl_1.05-4 libtext-xslate-perl_3.5.9-2+b3 libthai-data_0.1.30-3 libthai0_0.1.30-3 libtiff6_4.7.2-1 libtime-duration-perl_1.21-2 libtime-moment-perl_0.46-1+b1 libtimedate-perl_2.3500-1 libtinfo6_6.6+20260608-2 libtoml-tiny-perl_0.22-1 libtool_2.6.2-3 libtry-tiny-perl_0.32-1 libts0t64_1.22-1.1+b2 libtsan2_16.2.0-3 libubsan1_16.2.0-3 libucc1_1.9.0-1 libuchardet0_0.0.8-2+b2 libucx0_1.22.0-1 libudev1_262-1 libumfpack6_1:7.14.1+dfsg-1 libunbound8_1.26.1-1 libunicode-utf8-perl_0.75-1+b1 libunistring-dev_1.4.2-1 libunistring5_1.4.2-1 liburi-perl_5.37-1 liburing2_2.15-1 libuuid1_2.42.4-1 libvariable-magic-perl_0.65-1 libvorbis0a_1.3.7-3+b2 libvorbisenc2_1.3.7-3+b2 libvulkan1_1.4.363.0-1 libwacom-common_2.20.0-1 libwacom9_2.20.0-1 libwayland-client0_1.26.0-1 libwayland-cursor0_1.26.0-1 libwayland-egl1_1.26.0-1 libwebp7_1.6.0-0.1 libwebpmux3_1.6.0-0.1 libwmflite-0.2-7_0.2.14-1 libwww-mechanize-perl_2.22-1 libwww-perl_6.83-1 libwww-robotrules-perl_6.03-1 libx11-6_2:1.8.13-1 libx11-data_2:1.8.13-1 libx11-dev_2:1.8.13-1 libx11-xcb1_2:1.8.13-1 libxau-dev_1:1.0.11-1+b2 libxau6_1:1.0.11-1+b2 libxcb-cursor0_0.1.6-1 libxcb-dri3-0_1.17.0-2+b2 libxcb-glx0_1.17.0-2+b2 libxcb-icccm4_0.4.2-1+b2 libxcb-image0_0.4.0-2+b3 libxcb-keysyms1_0.4.1-1+b2 libxcb-present0_1.17.0-2+b2 libxcb-randr0_1.17.0-2+b2 libxcb-render-util0_0.3.10-1+b2 libxcb-render0_1.17.0-2+b2 libxcb-shape0_1.17.0-2+b2 libxcb-shm0_1.17.0-2+b2 libxcb-sync1_1.17.0-2+b2 libxcb-util1_0.4.1-1+b2 libxcb-xfixes0_1.17.0-2+b2 libxcb-xinput0_1.17.0-2+b2 libxcb-xkb1_1.17.0-2+b2 libxcb1_1.17.0-2+b2 libxcb1-dev_1.17.0-2+b2 libxcursor1_1:1.2.3-1+b2 libxdmcp-dev_1:1.1.5-2+b1 libxdmcp6_1:1.1.5-2+b1 libxext6_2:1.3.4-1+b4 libxfixes3_1:6.0.0-2+b5 libxinerama1_2:1.1.4-3+b5 libxkbcommon-x11-0_1.13.1-1 libxkbcommon0_1.13.1-1 libxml-libxml-perl_2.0207+dfsg+really+2.0134-8+b1 libxml-namespacesupport-perl_1.12-2 libxml-sax-base-perl_1.09-3 libxml-sax-perl_1.02+dfsg-5 libxml2-16_2.15.4+dfsg-1 libxmlb2_0.3.29-1 libxnvctrl0_535.171.04-1+b3 libxpm4_1:3.5.19-1 libxrender1_1:0.9.12-1+b2 libxs-parse-keyword-perl_0.51-1 libxs-parse-sublike-perl_0.41-2 libxshmfence1_1.3.3-1+b2 libxstring-perl_0.005-2+b7 libxxf86vm1_1:1.1.4-2+b1 libxxhash0_0.8.3-2+b2 libyaml-0-2_0.2.5-2+b1 libyaml-libyaml-perl_0.910.0+ds-1+b1 libyaml-pp-perl_0.41.0-1 libyaml-tiny-perl_1.76-1 libyuv0_0.0.1971.20260904-2 libz3-4_4.13.3-1.1 libze1_1.32.0-1 libzstd-dev_1.5.7+dfsg-4 libzstd1_1.5.7+dfsg-4 licensecheck_3.3.9-1 lintian_2.141.0 linux-libc-dev_7.2.8-1 lzop_1.04-2 m4_1.4.21-1 make_4.4.1-3 man-db_2.13.1-1 mawk_1.3.4.20260302-2 mesa-libgallium_26.2.4-1 ncurses-base_6.6+20260608-2 ncurses-bin_6.6+20260608-2 netbase_6.6 nettle-dev_3.10.2-1+b1 ocl-icd-libopencl1_2.3.4-1+b1 octave_11.3.0-1+b1 octave-common_11.3.0-1 octave-datatypes_1.5.0-1 octave-datatypes-common_1.5.0-1 octave-dev_11.3.0-1+b1 octave-io_2.7.2-3 openssl_3.6.5-1 openssl-provider-legacy_3.6.5-1 patch_2.8-2 patchutils_0.4.5-1 pci.ids_0.0~2026.09.23-1 perl_5.42.3-1 perl-base_5.42.3-1 perl-modules-5.42_5.42.3-1 perl-openssl-defaults_7+b2 perltidy_20250105-1.1 pkgconf_2.5.1-4 pkgconf-bin_2.5.1-4 plzip_1.13-2 po-debconf_1.0.22 procps_2:4.0.7-1 readline-common_8.3-4 sed_4.9-3 sensible-utils_0.0.26 shared-mime-info_2.4-5+b3 systemd_262-1 sysvinit-utils_3.18-1 t1utils_1.41-4 tar_1.35+dfsg-6 tex-common_6.20 texinfo_7.3-2 texinfo-lib_7.3-2+b1 tzdata_2026e-1 ucf_3.0056 unzip_6.0-31 util-linux_2.42.4-1 x11-common_1:7.7+26 x11proto-dev_2025.1-1 xkb-data_2.48-1 xorg-sgml-doctools_1:1.12.1-1 xtrans-dev_1.6.0-1 xz-utils_5.8.4-1 zlib1g_1:1.3.dfsg+really1.3.2-3 zlib1g-dev_1:1.3.dfsg+really1.3.2-3 +------------------------------------------------------------------------------+ | Build Sun, 04 Oct 2026 23:36:16 +0000 | +------------------------------------------------------------------------------+ Unpack source ------------- -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 Format: 3.0 (quilt) Source: octave-statistics Binary: octave-statistics, octave-statistics-common Architecture: any all Version: 2.0.0-1 Maintainer: Debian Octave Group Uploaders: Sébastien Villemot , Rafael Laboissière , Homepage: https://gnu-octave.github.io/packages/statistics/ Standards-Version: 4.7.4 Vcs-Browser: https://salsa.debian.org/octave-team/octave-statistics Vcs-Git: https://salsa.debian.org/octave-team/octave-statistics.git Testsuite: autopkgtest-pkg-octave Build-Depends: debhelper-compat (= 14), dh-octave (>= 1.11.1), dh-sequence-octave, octave, octave-datatypes (>= 1.2.6), octave-io Build-Conflicts: octave-nan Package-List: octave-statistics deb math optional arch=any octave-statistics-common deb math optional arch=all Checksums-Sha1: 907186008c65fd263298e43b2e8613a6d53f6b74 4865827 octave-statistics_2.0.0.orig.tar.gz 8442eb322c8dbf0ca3441d3e6f13897b75bd81e2 11008 octave-statistics_2.0.0-1.debian.tar.xz Checksums-Sha256: e82c1d6957885ee444adc91e35defd00665ec3c3e1eeae0bd39f89b7b28a6490 4865827 octave-statistics_2.0.0.orig.tar.gz 1857cf343a438680acb3df23381a93fd47d844d8cbcbbc9cd13e0289e7051c81 11008 octave-statistics_2.0.0-1.debian.tar.xz Files: 1cf431eaaa3bf9704e51ae6e59190a8d 4865827 octave-statistics_2.0.0.orig.tar.gz b4611d9b718620c2bd2b2a68232478ee 11008 octave-statistics_2.0.0-1.debian.tar.xz Dgit: a294a7a3b33126edbebace1c5da604939ad7611f debian archive/debian/2.0.0-1 https://git.dgit.debian.org/octave-statistics -----BEGIN PGP SIGNATURE----- iQJGBAEBCgAwFiEEP0ZDkUmP6HS9tdmPISSqGYN4XJAFAmrCeLoSHHJhZmFlbEBk ZWJpYW4ub3JnAAoJECEkqhmDeFyQs4AQAJPFjnRcwApI0+EJyez+jGWBiqJ7HEgK wnVU8DaK0dRHkXILukGS0Soc5I6X94RUcROIlLGduOixiQBrjkhSKiCP7xIjOWVV ZIXn2oUPyN1aMZH8QqhAMd+TmntGoZcbPfkrBiygZy5wgPqsiUJHyf1/cQ+OVCE5 /UKnJmiVvXmJVBrzN5AdqHFkZRwqRigk1BbPI/WlpnNkQRBm1Uppas4xGO6ADHGf DmafSG14BYebxwmQUY6OcBWvzkkdySxAjoWzD8uaX7x+NjU2XjAVFgu5cKwWjwew c3t+muwXWY3EaygH2ISpmqAsA3LTcuKUJyFH9wUPUUWscoLkYhxQBJB/Ddvw/F3J 5EJYC0bpUlfePEkyX383tUXIPJ1/i3NLy8FUDKeYdQt7ca6RzeZlOebkCdVdW0Nl QhOZGTGn0mippH2+ztYMXY4uM6KZ1quHrfHvnSU7v1jSZOso6GeMsptM8LHhSJ/G Ag2H8w5IcNbQLt46k9T/9n9A8BBDHqb3YaP2UwMVzyj/6/tnfEYWgewGWj0ylVLb CLCWg9uGnMshyH0KhXkTy5GxO0l7ZYlMSSoTivsMRFOeMUTBsw7bsGFlcF+si9l3 5d+Z0gW/8/Z4RExdS32fV5LZ4QU01aPzxyic/Hf57rrLH0oahSgcf1KfvpZp+pe4 oW/eIybm0NOB =XyBl -----END PGP SIGNATURE----- dpkg-source: warning: cannot verify inline signature for ./octave-statistics_2.0.0-1.dsc: missing OpenPGP keyrings dpkg-source: info: verifying ./octave-statistics_2.0.0-1.dsc dpkg-source: info: skipping absent keyring /usr/share/keyrings/debian-keyring.pgp dpkg-source: info: skipping absent keyring /usr/share/keyrings/debian-tag2upload.pgp dpkg-source: info: skipping absent keyring /usr/share/keyrings/debian-nonupload.pgp dpkg-source: info: skipping absent keyring /usr/share/keyrings/debian-maintainers.pgp dpkg-source: info: extracting octave-statistics in /build/reproducible-path/octave-statistics-2.0.0 dpkg-source: info: unpacking octave-statistics_2.0.0.orig.tar.gz dpkg-source: info: unpacking octave-statistics_2.0.0-1.debian.tar.xz Check disk space ---------------- Sufficient free space for build User Environment ---------------- APT_CONFIG=/var/lib/sbuild/apt.conf DEB_BUILD_OPTIONS=parallel=6 HOME=/sbuild-nonexistent LANG=C.UTF-8 LC_ALL=C.UTF-8 LC_COLLATE=C.UTF-8 LC_CTYPE=C.UTF-8 LOGNAME=sbuild PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games SHELL=/bin/sh SOURCE_DATE_EPOCH=1791013082 USER=sbuild dpkg-buildpackage ----------------- Command: dpkg-buildpackage --sanitize-env -us -uc -B dpkg-buildpackage: info: source package octave-statistics dpkg-buildpackage: info: source version 2.0.0-1 dpkg-buildpackage: info: source distribution unstable dpkg-buildpackage: info: source changed by Rafael Laboissière dpkg-source --before-build . dpkg-buildpackage: info: host architecture amd64 debian/rules clean dh clean --buildsystem=octave dh_auto_clean -O--buildsystem=octave dh_octave_clean make[1]: Entering directory '/build/reproducible-path/octave-statistics-2.0.0' make[1]: *** No rule to make target 'clean'. make[1]: *** No rule to make target 'distclean'. make[1]: Leaving directory '/build/reproducible-path/octave-statistics-2.0.0' make[1]: Entering directory '/build/reproducible-path/octave-statistics-2.0.0/src' rm -f editDistance.oct libsvmread.oct libsvmwrite.oct svmpredict.oct svmtrain.oct fcnntrain.oct fcnnpredict.oct gamtrain.oct gampredict.oct gamboosttrain.oct gamboostpredict.oct gamboostpairs.oct gamboostinter.oct __lbfgs__.oct __bhtsne__.oct __knnselect__.oct __knnbrute__.oct treetrain.oct treepredict.oct __treeprune__.oct __shapleytree__.oct __nomdist__.oct make[1]: *** No rule to make target 'distclean'. make[1]: Leaving directory '/build/reproducible-path/octave-statistics-2.0.0/src' dh_autoreconf_clean -O--buildsystem=octave dh_clean -O--buildsystem=octave debian/rules binary-arch dh binary-arch --buildsystem=octave dh_update_autotools_config -a -O--buildsystem=octave dh_autoreconf -a -O--buildsystem=octave dh_octave_version -a -O--buildsystem=octave Checking the Octave version... ok dh_auto_configure -a -O--buildsystem=octave dh_auto_build -a -O--buildsystem=octave dh_auto_test -a -O--buildsystem=octave create-stamp debian/debhelper-build-stamp dh_testroot -a -O--buildsystem=octave dh_prep -a -O--buildsystem=octave dh_auto_install -a -O--buildsystem=octave octave --no-gui --no-history --silent --no-init-file --no-window-system /usr/share/dh-octave/install-pkg.m /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/lib/x86_64-linux-gnu/octave/packages mkdir (/tmp/octave-statistics-2.0-build-dir) untar (/tmp//octave-statistics-2.0.0.tar.gz, /tmp/octave-statistics-2.0-build-dir) make[1]: Entering directory '/tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src' /usr/bin/mkoctfile --verbose editDistance.cc /usr/bin/mkoctfile --verbose libsvmread.cc /usr/bin/mkoctfile --verbose libsvmwrite.cc /usr/bin/mkoctfile --verbose svmpredict.cc svm.cpp svm_model_octave.cpp x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection editDistance.cc -o /tmp/oct-q5zH0m.o x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection libsvmread.cc -o /tmp/oct-woma8T.o x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection libsvmwrite.cc -o /tmp/oct-zoZCMz.o x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection svmpredict.cc -o /tmp/oct-OXqXnd.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o libsvmwrite.oct /tmp/oct-zoZCMz.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro /usr/bin/mkoctfile --verbose svmtrain.cc svm.cpp svm_model_octave.cpp x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection svmtrain.cc -o /tmp/oct-eE9kiK.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o libsvmread.oct /tmp/oct-woma8T.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro /usr/bin/mkoctfile --verbose fcnntrain.cc x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection fcnntrain.cc -o /tmp/oct-i6dwsh.o x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection svm.cpp -o /tmp/oct-voYGq9.o x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection svm_model_octave.cpp -o /tmp/oct-gZP6Ta.o x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection svm.cpp -o /tmp/oct-qppOEL.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o editDistance.oct /tmp/oct-q5zH0m.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro /usr/bin/mkoctfile --verbose fcnnpredict.cc x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection fcnnpredict.cc -o /tmp/oct-lrtzyD.o x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection svm_model_octave.cpp -o /tmp/oct-nxZbja.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o svmpredict.oct /tmp/oct-OXqXnd.o /tmp/oct-voYGq9.o /tmp/oct-gZP6Ta.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro /usr/bin/mkoctfile --verbose gamtrain.cc x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection gamtrain.cc -o /tmp/oct-eTQkAQ.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o svmtrain.oct /tmp/oct-eE9kiK.o /tmp/oct-qppOEL.o /tmp/oct-nxZbja.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro /usr/bin/mkoctfile --verbose gampredict.cc x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection gampredict.cc -o /tmp/oct-lZPhLB.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o fcnntrain.oct /tmp/oct-i6dwsh.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro /usr/bin/mkoctfile --verbose gamboosttrain.cc x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection gamboosttrain.cc -o /tmp/oct-QkDBWS.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o fcnnpredict.oct /tmp/oct-lrtzyD.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro /usr/bin/mkoctfile --verbose gamboostpredict.cc x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection gamboostpredict.cc -o /tmp/oct-aZJUsO.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o gamtrain.oct /tmp/oct-eTQkAQ.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro /usr/bin/mkoctfile --verbose gamboostpairs.cc x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection gamboostpairs.cc -o /tmp/oct-SLMcsN.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o gampredict.oct /tmp/oct-lZPhLB.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro /usr/bin/mkoctfile --verbose gamboostinter.cc x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection gamboostinter.cc -o /tmp/oct-NYAZTF.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o gamboostpredict.oct /tmp/oct-aZJUsO.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro /usr/bin/mkoctfile --verbose __lbfgs__.cc x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection __lbfgs__.cc -o /tmp/oct-jkkXql.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o gamboosttrain.oct /tmp/oct-QkDBWS.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro /usr/bin/mkoctfile --verbose __bhtsne__.cc x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection __bhtsne__.cc -o /tmp/oct-2fkEEm.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o gamboostpairs.oct /tmp/oct-SLMcsN.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro /usr/bin/mkoctfile --verbose __knnselect__.cc x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection __knnselect__.cc -o /tmp/oct-IMTFZz.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o __bhtsne__.oct /tmp/oct-2fkEEm.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro /usr/bin/mkoctfile --verbose __knnbrute__.cc x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection __knnbrute__.cc -o /tmp/oct-9uE75E.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o __knnselect__.oct /tmp/oct-IMTFZz.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro /usr/bin/mkoctfile --verbose treetrain.cc x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection treetrain.cc -o /tmp/oct-JRFgZm.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o __lbfgs__.oct /tmp/oct-jkkXql.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro /usr/bin/mkoctfile --verbose treepredict.cc x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection treepredict.cc -o /tmp/oct-o7cavW.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o gamboostinter.oct /tmp/oct-NYAZTF.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro /usr/bin/mkoctfile --verbose __treeprune__.cc x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection __treeprune__.cc -o /tmp/oct-JpYRtS.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o __knnbrute__.oct /tmp/oct-9uE75E.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro /usr/bin/mkoctfile --verbose __shapleytree__.cc x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection __shapleytree__.cc -o /tmp/oct-9we8nh.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o __treeprune__.oct /tmp/oct-JpYRtS.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro /usr/bin/mkoctfile --verbose __nomdist__.cc x86_64-linux-gnu-g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection __nomdist__.cc -o /tmp/oct-vjwr1Y.o x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o treepredict.oct /tmp/oct-o7cavW.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o __shapleytree__.oct /tmp/oct-9we8nh.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o treetrain.oct /tmp/oct-JRFgZm.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro x86_64-linux-gnu-g++ -I/usr/include/octave-11.3.0/octave/.. -I/usr/include/octave-11.3.0/octave -pthread -fopenmp -g -O2 -ffile-prefix-map=/build/reproducible-path/octave-statistics-2.0.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -o __nomdist__.oct /tmp/oct-vjwr1Y.o -shared -Wl,-Bsymbolic -Wl,-z,relro -flto=auto -ffat-lto-objects -Wl,-z,relro make[1]: Leaving directory '/tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src' copyfile /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/__bhtsne__.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/__knnbrute__.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/__knnselect__.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/__lbfgs__.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/__nomdist__.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/__shapleytree__.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/__treeprune__.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/editDistance.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/fcnnpredict.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/fcnntrain.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/gamboostinter.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/gamboostpairs.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/gamboostpredict.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/gamboosttrain.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/gampredict.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/gamtrain.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/libsvmread.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/libsvmwrite.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/svmpredict.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/svmtrain.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/treepredict.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/treetrain.oct /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/__knnbrute__.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/__knnselect__.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/__lbfgs__.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/__nomdist__.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/__shapleytree__.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/__treeprune__.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/editDistance.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/fcnnpredict.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/fcnntrain.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/gamboostinter.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/gamboostpairs.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/gamboostpredict.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/gamboosttrain.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/gampredict.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/gamtrain.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/libsvmread.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/libsvmwrite.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/svmpredict.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/svmtrain.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/treepredict.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/treetrain.cc-tst /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/src/doc-cache /tmp/octave-statistics-2.0-build-dir/octave-statistics-2.0.0/inst/x86_64-pc-linux-gnu-api-v61 creating file PKG_ADD creating file PKG_DEL using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0 using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Anomaly_Detection using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Clustering using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Data_Manipulation using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Descriptive_Statistics using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Dimensionality_Reduction using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Distribution_Classes using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Distribution_Fitting using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Distribution_Functions using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Distribution_Statistics using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Distribution_Wrappers using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Experimental_Design using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Hypothesis_Testing using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Machine_Learning using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Markov_Models using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Model_Evaluation using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Nearest_Neighbors using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Plotting using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Random_Sampling using package-provided doc-cache file for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Regression creating file doc-cache for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/datasets creating file doc-cache for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/demos creating file doc-cache for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/doc creating file doc-cache for directory /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/packinfo For information about changes from previous versions of the statistics package, run 'news statistics'. Please report any issues with the statistics package at "https://github.com/gnu-octave/statistics/issues" rm: cannot remove '/build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/doc': Is a directory dh_octave_check -a -O--buildsystem=octave Checking package... Run the unit tests... Checking m files ... warning: function /build/reproducible-path/octave-statistics-2.0.0/debian/tmp/usr/share/octave/packages/statistics-2.0.0/Descriptive_Statistics/corr.m shadows a core library function warning: called from /tmp/tmp.3ZzRcRi7mQ at line 12 column 1 [inst/statget.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/statget.m ***** demo ## Read an option, falling back on a default when it is unset options = statset ('nlinfit'); maxiter = statget (options, 'MaxIter') tolbnd = statget (options, 'TolBnd', 1e-6) ***** test assert_equal (statget (statset ('factoran'), 'TolX'), 1e-8); ***** test assert_equal (statget (statset ('nlinfit'), 'MaxIter'), 200); ***** test assert_equal (statget (statset ('nlinfit'), 'WgtFun'), 'bisquare'); ***** test assert_equal (statget (statset ('factoran'), 'TolBnd'), []); ***** test assert_equal (statget (statset (), 'MaxIter'), []); ***** test assert_equal (statget (statset ('factoran'), 'TolBnd', 42), 42); ***** test assert_equal (statget (statset ('factoran'), 'TolX', 42), 1e-8); ***** test assert_equal (statget (statset (), 'Display', 'final'), 'final'); ***** test assert_equal (statget (statset (), 'OutputFcn', {@sin}), {@sin}); ***** test assert_equal (statget (statset ('factoran'), 'tolx'), 1e-8); ***** test assert_equal (statget (statset ('factoran'), 'MAXITER'), 100); ***** test assert_equal (statget (statset ('factoran'), 'MaxI'), 100); ***** test assert_equal (statget (statset ('factoran'), 'Displ'), 'off'); ***** test assert_equal (statget (statset ('nlinfit'), 'Deriv'), 6.0554544523933429e-06, 1e-20); ***** test assert_equal (statget (statset ('nnmf'), 'TolX'), 1e-4); ***** test assert_equal (statget (statset ('fitnlm'), 'Robust'), 'off'); ***** test assert_equal (statget (struct ('MaxIter', 7), 'MaxIter'), 7); ***** test assert_equal (statget (struct ('MaxIter', 7), 'MaxI'), 7); ***** error statget () ***** error statget (statset ()) ***** error ... statget (1, 'MaxIter') ***** error ... statget (struct ('MaxIter', {1, 2}), 'MaxIter') ***** error ... statget (statset (), 5) ***** error ... statget (statset (), 'Tol') ***** error ... statget (statset (), 'TolT') ***** error ... statget (statset (), 'NoSuchOption') ***** error ... statget (struct ('MaxIter', 7), 'TolX') 27 tests, 27 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/BirnbaumSaundersDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/BirnbaumSaundersDistribution.m ***** demo ## Generate a data set of 5000 random samples from a Birnbaum-Saunders ## distribution with parameters β = 1 and γ = 0.5. Fit a Birnbaum-Saunders ## distribution to this data and plot a PDF of the fitted distribution ## superimposed on a histogram of the data. rng (42); randg ('state', 42); rande ('state', 42); randp ('state', 42); pd_fixed = makedist ('BirnbaumSaunders', 'beta', 1, 'gamma', 0.5) data = random (pd_fixed, 5000, 1); pd_fitted = fitdist (data, 'BirnbaumSaunders') plot (pd_fitted) msg = 'Fitted Birnbaum-Saunders distribution with beta = %0.2f and gamma = %0.2f'; title (sprintf (msg, pd_fitted.beta, pd_fitted.gamma)) ***** shared pd, t pd = prob.BirnbaumSaundersDistribution; t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0, 0.5, 0.7602, 0.8759, 0.9332, 0.9632], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 0.6687, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4, NaN]), [0.6585, 0.7602, 0.8759, 0.9332, NaN], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4, NaN]), [0, 0, 0.6687, 1, NaN], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [0, 0.4411, 0.7767, 1.2875, 2.2673, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.2293, 2.5073, 2.8567, 3.3210, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 0.7767, 1.2875, 2.2673, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.5073, 2.8567, 3.3210, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 1.4236, 1e-4); ***** assert_equal (iqr (t), 0.8968, 1e-4); ***** assert_equal (mean (pd), 1.5, eps); ***** assert_equal (mean (t), 2.7723, 1e-4); ***** assert_equal (median (pd), 1, 1e-4); ***** assert_equal (median (t), 2.6711, 1e-4); ***** assert_equal (pdf (pd, [0:5]), [0, 0.3989, 0.1648, 0.0788, 0.0405, 0.0216], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 0.9528, 0.4559, 0.2340, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1.5, NaN]), [0, 0.2497, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1.5, NaN]), [0, 0, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 1.5, eps); ***** assert_equal (std (t), 0.5528, 1e-4); ***** assert_equal (var (pd), 2.25, eps); ***** assert_equal (var (t), 0.3056, 1e-4); ***** test ## The profile over the first free parameter: 21 grid values, one row of ## OTHER per value, and the likelihood peaking at the fitted estimate. x = [1.2; 0.4; 3.1; 0.7; 2.5; 1.8; 0.3; 4.2; 1.1; 0.9; ... 2.2; 0.6; 1.5; 3.7; 0.8; 2.9; 1.3; 0.5; 2.0; 1.6]; pd = fitdist (x, 'BirnbaumSaunders'); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 21]); assert_equal (size (other), [21, 1]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); ***** error ... prob.BirnbaumSaundersDistribution (0, 1) ***** error ... prob.BirnbaumSaundersDistribution (Inf, 1) ***** error ... prob.BirnbaumSaundersDistribution (i, 1) ***** error ... prob.BirnbaumSaundersDistribution ('beta', 1) ***** error ... prob.BirnbaumSaundersDistribution ([1, 2], 1) ***** error ... prob.BirnbaumSaundersDistribution (NaN, 1) ***** error ... prob.BirnbaumSaundersDistribution (1, 0) ***** error ... prob.BirnbaumSaundersDistribution (1, -1) ***** error ... prob.BirnbaumSaundersDistribution (1, Inf) ***** error ... prob.BirnbaumSaundersDistribution (1, i) ***** error ... prob.BirnbaumSaundersDistribution (1, 'beta') ***** error ... prob.BirnbaumSaundersDistribution (1, [1, 2]) ***** error ... prob.BirnbaumSaundersDistribution (1, NaN) ***** error ... cdf (prob.BirnbaumSaundersDistribution, 2, 'uper') ***** error ... cdf (prob.BirnbaumSaundersDistribution, 2, 3) ***** shared x rand ('seed', 5); x = bisarnd (1, 1, [100, 1]); ***** error ... paramci (prob.BirnbaumSaundersDistribution.fit (x), 'alpha') ***** error ... paramci (prob.BirnbaumSaundersDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.BirnbaumSaundersDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.BirnbaumSaundersDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.BirnbaumSaundersDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.BirnbaumSaundersDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.BirnbaumSaundersDistribution.fit (x), 'parameter', ... 'beta', 'alpha', {0.05}) ***** error ... paramci (prob.BirnbaumSaundersDistribution.fit (x), ... 'parameter', {'beta', 'gamma', 'param'}) ***** error ... paramci (prob.BirnbaumSaundersDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'beta', 'gamma', 'param'}) ***** error ... paramci (prob.BirnbaumSaundersDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.BirnbaumSaundersDistribution.fit (x), 'alpha', 0.01, ... 'parameter', 'param') ***** error ... paramci (prob.BirnbaumSaundersDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.BirnbaumSaundersDistribution.fit (x), 'alpha', 0.01, ... 'NAME', 'value') ***** error ... paramci (prob.BirnbaumSaundersDistribution.fit (x), 'alpha', 0.01, ... 'parameter', 'beta', 'NAME', 'value') ***** error ... plot (prob.BirnbaumSaundersDistribution, 'Parent') ***** error ... plot (prob.BirnbaumSaundersDistribution, 'PlotType', 12) ***** error ... plot (prob.BirnbaumSaundersDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.BirnbaumSaundersDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.BirnbaumSaundersDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.BirnbaumSaundersDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.BirnbaumSaundersDistribution, 'Discrete', {true}) ***** error ... plot (prob.BirnbaumSaundersDistribution, 'Parent', 12) ***** error ... plot (prob.BirnbaumSaundersDistribution, 'Parent', 'hax') ***** error ... plot (prob.BirnbaumSaundersDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.BirnbaumSaundersDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.BirnbaumSaundersDistribution, 2) ***** error ... proflik (prob.BirnbaumSaundersDistribution.fit (x), 3) ***** error ... proflik (prob.BirnbaumSaundersDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.BirnbaumSaundersDistribution.fit (x), {1}) ***** error ... proflik (prob.BirnbaumSaundersDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.BirnbaumSaundersDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.BirnbaumSaundersDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.BirnbaumSaundersDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.BirnbaumSaundersDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.BirnbaumSaundersDistribution.fit (x), 1, 'Display', ['on'; 'on']) ***** error ... proflik (prob.BirnbaumSaundersDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.BirnbaumSaundersDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.BirnbaumSaundersDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.BirnbaumSaundersDistribution.fit (x), 1, {[1 2 3 4]}, 'Display', 'on') ***** error ... truncate (prob.BirnbaumSaundersDistribution) ***** error ... truncate (prob.BirnbaumSaundersDistribution, 2) ***** error ... truncate (prob.BirnbaumSaundersDistribution, 4, 2) ***** shared pd pd = prob.BirnbaumSaundersDistribution (1, 1); pd(2) = prob.BirnbaumSaundersDistribution (1, 3); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 97 tests, 97 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/HalfNormalDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/HalfNormalDistribution.m ***** shared pd, t pd = prob.HalfNormalDistribution (0, 1); t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0, 0.6827, 0.9545, 0.9973, 0.9999, 1], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 0.9420, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4]), [0.8664, 0.9545, 0.9973, 0.9999], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4]), [0, 0, 0.9420, 1], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [0, 0.2533, 0.5244, 0.8416, 1.2816, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.0923, 2.2068, 2.3607, 2.6064, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 0.5244, 0.8416, 1.2816, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.2068, 2.3607, 2.6064, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 0.8317, 1e-4); ***** assert_equal (iqr (t), 0.4111, 1e-4); ***** assert_equal (mean (pd), 0.7979, 1e-4); ***** assert_equal (mean (t), 2.3706, 1e-4); ***** assert_equal (median (pd), 0.6745, 1e-4); ***** assert_equal (median (t), 2.2771, 1e-4); ***** assert_equal (pdf (pd, [0:5]), [0.7979, 0.4839, 0.1080, 0.0089, 0.0003, 0], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 2.3765, 0.1951, 0.0059, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1:4, NaN]), [0, 0.4839, 0.1080, 0.0089, 0.0003, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1:4, NaN]), [0, 0, 2.3765, 0.1951, 0.0059, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 0.6028, 1e-4); ***** assert_equal (std (t), 0.3310, 1e-4); ***** assert_equal (var (pd), 0.3634, 1e-4); ***** assert_equal (var (t), 0.1096, 1e-4); ***** test ## A fixed parameter is skipped by the default PNUM and reported in OTHER at ## its own value. Verified against MATLAB. x = [1.2; 0.4; 3.1; 0.7; 2.5; 1.8; 0.3; 4.2; 1.1; 0.9; ... 2.2; 0.6; 1.5; 3.7; 0.8; 2.9; 1.3; 0.5; 2.0; 1.6]; pdh = prob.HalfNormalDistribution.fit (x, 0); [nlogL, param, other] = proflik (pdh, 2); assert_equal (size (param), [1, 101]); assert_equal (size (other), [101, 1]); assert_equal (unique (other), 0); assert_equal (proflik (pdh), nlogL); ***** error ... prob.HalfNormalDistribution (Inf, 1) ***** error ... prob.HalfNormalDistribution (i, 1) ***** error ... prob.HalfNormalDistribution ('a', 1) ***** error ... prob.HalfNormalDistribution ([1, 2], 1) ***** error ... prob.HalfNormalDistribution (NaN, 1) ***** error ... prob.HalfNormalDistribution (1, 0) ***** error ... prob.HalfNormalDistribution (1, -1) ***** error ... prob.HalfNormalDistribution (1, Inf) ***** error ... prob.HalfNormalDistribution (1, i) ***** error ... prob.HalfNormalDistribution (1, 'a') ***** error ... prob.HalfNormalDistribution (1, [1, 2]) ***** error ... prob.HalfNormalDistribution (1, NaN) ***** error ... cdf (prob.HalfNormalDistribution, 2, 'uper') ***** error ... cdf (prob.HalfNormalDistribution, 2, 3) ***** shared x x = hnrnd (1, 1, [1, 100]); ***** error ... paramci (prob.HalfNormalDistribution.fit (x, 1), 'alpha') ***** error ... paramci (prob.HalfNormalDistribution.fit (x, 1), 'alpha', 0) ***** error ... paramci (prob.HalfNormalDistribution.fit (x, 1), 'alpha', 1) ***** error ... paramci (prob.HalfNormalDistribution.fit (x, 1), 'alpha', [0.5 2]) ***** error ... paramci (prob.HalfNormalDistribution.fit (x, 1), 'alpha', '') ***** error ... paramci (prob.HalfNormalDistribution.fit (x, 1), 'alpha', {0.05}) ***** error ... paramci (prob.HalfNormalDistribution.fit (x, 1), 'parameter', 'sigma', ... 'alpha', {0.05}) ***** error ... paramci (prob.HalfNormalDistribution.fit (x, 1), ... 'parameter', {'mu', 'sigma', 'param'}) ***** error ... paramci (prob.HalfNormalDistribution.fit (x, 1), 'alpha', 0.01, ... 'parameter', {'mu', 'sigma', 'param'}) ***** error ... paramci (prob.HalfNormalDistribution.fit (x, 1), 'parameter', 'param') ***** error ... paramci (prob.HalfNormalDistribution.fit (x, 1), 'alpha', 0.01, ... 'parameter', 'param') ***** error ... paramci (prob.HalfNormalDistribution.fit (x, 1),'NAME', 'value') ***** error ... paramci (prob.HalfNormalDistribution.fit (x, 1), 'alpha', 0.01, ... 'NAME', 'value') ***** error ... paramci (prob.HalfNormalDistribution.fit (x, 1), 'alpha', 0.01, ... 'parameter', 'sigma', 'NAME', 'value') ***** error ... plot (prob.HalfNormalDistribution, 'Parent') ***** error ... plot (prob.HalfNormalDistribution, 'PlotType', 12) ***** error ... plot (prob.HalfNormalDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.HalfNormalDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.HalfNormalDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.HalfNormalDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.HalfNormalDistribution, 'Discrete', {true}) ***** error ... plot (prob.HalfNormalDistribution, 'Parent', 12) ***** error ... plot (prob.HalfNormalDistribution, 'Parent', 'hax') ***** error ... plot (prob.HalfNormalDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.HalfNormalDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.HalfNormalDistribution, 2) ***** error ... proflik (prob.HalfNormalDistribution.fit (x, 1), 3) ***** error ... proflik (prob.HalfNormalDistribution.fit (x, 1), [1, 2]) ***** error ... proflik (prob.HalfNormalDistribution.fit (x, 1), {1}) ***** error ... proflik (prob.HalfNormalDistribution.fit (x, 1), 1) ***** error ... proflik (prob.HalfNormalDistribution.fit (x, 1), 2, ones (2)) ***** error ... proflik (prob.HalfNormalDistribution.fit (x, 1), 2, 'Display') ***** error ... proflik (prob.HalfNormalDistribution.fit (x, 1), 2, 'Display', 1) ***** error ... proflik (prob.HalfNormalDistribution.fit (x, 1), 2, 'Display', {1}) ***** error ... proflik (prob.HalfNormalDistribution.fit (x, 1), 2, 'Display', {'on'}) ***** error ... proflik (prob.HalfNormalDistribution.fit (x, 1), 2, 'Display', ['on'; 'on']) ***** error ... proflik (prob.HalfNormalDistribution.fit (x, 1), 2, 'Display', 'onnn') ***** error ... proflik (prob.HalfNormalDistribution.fit (x, 1), 2, 'NAME', 'on') ***** error ... proflik (prob.HalfNormalDistribution.fit (x, 1), 2, {'NAME'}, 'on') ***** error ... proflik (prob.HalfNormalDistribution.fit (x, 1), 2, {[1 2 3 4]}, ... 'Display', 'on') ***** error ... truncate (prob.HalfNormalDistribution) ***** error ... truncate (prob.HalfNormalDistribution, 2) ***** error ... truncate (prob.HalfNormalDistribution, 4, 2) ***** shared pd pd = prob.HalfNormalDistribution (1, 1); pd(2) = prob.HalfNormalDistribution (1, 3); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 97 tests, 97 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/WeibullDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/WeibullDistribution.m ***** demo ## Generate a data set of 5000 random samples from a Weibull distribution with ## parameters A = 1 and B = 2. Fit a Weibull distribution to this data and plot ## a PDF of the fitted distribution superimposed on a histogram of a data. rng (42); randg ('state', 42); rande ('state', 42); randp ('state', 42); pd_fixed = makedist ('Weibull', 'A', 1, 'B', 2) data = random (pd_fixed, 5000, 1); pd_fitted = fitdist (data, 'Weibull') plot (pd_fitted) msg = 'Fitted Weibull distribution with A = %0.2f and B = %0.2f'; title (sprintf (msg, pd_fitted.A, pd_fitted.B)) ***** shared pd, t pd = prob.WeibullDistribution; t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0, 0.6321, 0.8647, 0.9502, 0.9817, 0.9933], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 0.7311, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4, NaN]), [0.7769, 0.8647, 0.9502, 0.9817, NaN], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4, NaN]), [0, 0, 0.7311, 1, NaN], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [0, 0.2231, 0.5108, 0.9163, 1.6094, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.1899, 2.4244, 2.7315, 3.1768, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 0.5108, 0.9163, 1.6094, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.4244, 2.7315, 3.1768, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 1.0986, 1e-4); ***** assert_equal (iqr (t), 0.8020, 1e-4); ***** assert_equal (mean (pd), 1, 1e-14); ***** assert_equal (mean (t), 2.6870, 1e-4); ***** assert_equal (median (pd), 0.6931, 1e-4); ***** assert_equal (median (t), 2.5662, 1e-4); ***** assert_equal (pdf (pd, [0:5]), [1, 0.3679, 0.1353, 0.0498, 0.0183, 0.0067], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 1.1565, 0.4255, 0.1565, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1.5, NaN]), [0, 0.2231, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1.5, NaN]), [0, 0, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 1, 1e-14); ***** assert_equal (std (t), 0.5253, 1e-4); ***** assert_equal (var (pd), 1, 1e-14); ***** assert_equal (var (t), 0.2759, 1e-4); ***** test ## The profile over the first free parameter: 21 grid values, one row of ## OTHER per value, and the likelihood peaking at the fitted estimate. x = [1.2; 0.4; 3.1; 0.7; 2.5; 1.8; 0.3; 4.2; 1.1; 0.9; ... 2.2; 0.6; 1.5; 3.7; 0.8; 2.9; 1.3; 0.5; 2.0; 1.6]; pd = fitdist (x, 'Weibull'); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 21]); assert_equal (size (other), [21, 1]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); ***** error ... prob.WeibullDistribution (0, 1) ***** error ... prob.WeibullDistribution (-1, 1) ***** error ... prob.WeibullDistribution (Inf, 1) ***** error ... prob.WeibullDistribution (i, 1) ***** error ... prob.WeibullDistribution ('a', 1) ***** error ... prob.WeibullDistribution ([1, 2], 1) ***** error ... prob.WeibullDistribution (NaN, 1) ***** error ... prob.WeibullDistribution (1, 0) ***** error ... prob.WeibullDistribution (1, -1) ***** error ... prob.WeibullDistribution (1, Inf) ***** error ... prob.WeibullDistribution (1, i) ***** error ... prob.WeibullDistribution (1, 'a') ***** error ... prob.WeibullDistribution (1, [1, 2]) ***** error ... prob.WeibullDistribution (1, NaN) ***** error ... cdf (prob.WeibullDistribution, 2, 'uper') ***** error ... cdf (prob.WeibullDistribution, 2, 3) ***** shared x x = wblrnd (1, 1, [1, 100]); ***** error ... paramci (prob.WeibullDistribution.fit (x), 'alpha') ***** error ... paramci (prob.WeibullDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.WeibullDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.WeibullDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.WeibullDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.WeibullDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.WeibullDistribution.fit (x), 'parameter', 'B', 'alpha', {0.05}) ***** error ... paramci (prob.WeibullDistribution.fit (x), 'parameter', {'A', 'B', 'param'}) ***** error ... paramci (prob.WeibullDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'A', 'B', 'param'}) ***** error ... paramci (prob.WeibullDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.WeibullDistribution.fit (x), 'alpha', 0.01, 'parameter', 'param') ***** error ... paramci (prob.WeibullDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.WeibullDistribution.fit (x), 'alpha', 0.01, 'NAME', 'value') ***** error ... paramci (prob.WeibullDistribution.fit (x), 'alpha', 0.01, 'parameter', 'B', ... 'NAME', 'value') ***** error ... plot (prob.WeibullDistribution, 'Parent') ***** error ... plot (prob.WeibullDistribution, 'PlotType', 12) ***** error ... plot (prob.WeibullDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.WeibullDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.WeibullDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.WeibullDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.WeibullDistribution, 'Discrete', {true}) ***** error ... plot (prob.WeibullDistribution, 'Parent', 12) ***** error ... plot (prob.WeibullDistribution, 'Parent', 'hax') ***** error ... plot (prob.WeibullDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.WeibullDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.WeibullDistribution, 2) ***** error ... proflik (prob.WeibullDistribution.fit (x), 3) ***** error ... proflik (prob.WeibullDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.WeibullDistribution.fit (x), {1}) ***** error ... proflik (prob.WeibullDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.WeibullDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.WeibullDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.WeibullDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.WeibullDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.WeibullDistribution.fit (x), 1, 'Display', ['on'; 'on']) ***** error ... proflik (prob.WeibullDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.WeibullDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.WeibullDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.WeibullDistribution.fit (x), 1, {[1 2 3 4]}, 'Display', 'on') ***** error ... truncate (prob.WeibullDistribution) ***** error ... truncate (prob.WeibullDistribution, 2) ***** error ... truncate (prob.WeibullDistribution, 4, 2) ***** shared pd pd = prob.WeibullDistribution (1, 1); pd(2) = prob.WeibullDistribution (1, 3); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 98 tests, 98 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/KernelDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/KernelDistribution.m ***** demo ## Fit a kernel distribution to a sample and plot its PDF over a histogram. load patients pd = fitdist (Weight, 'Kernel'); plot (pd) title ('Kernel distribution fitted to patient weights') ***** shared x, pd, pdbox, t x = [2.1 0.3 1.2 -0.7 0.9 1.5 2.8 0.1 0.4 1.1 3.2 0.6 2.0 0.9 1.7]'; pd = fitdist (x, 'Kernel'); pdbox = fitdist (x, 'Kernel', 'Kernel', 'box', 'Width', 0.5); t = truncate (pd, 0, 3); ***** assert_equal (pd.DistributionName, 'Kernel'); ***** assert_equal (pd.Kernel, 'normal'); ***** assert_equal (pd.NumParameters, 0); ***** assert_equal (pd.ParameterNames, {}); ***** assert_equal (pd.IsTruncated, false); ***** assert_equal (pd.Bandwidth, 0.639566, 1e-4); ***** assert_equal (pd.Support.range, 'unbounded'); ***** assert_equal (pdf (pd, [-1 0 0.5 1 1.5 2 2.5 3]), ... [0.0589 0.2141 0.3051 0.3394 0.3061 0.2375 0.1697 0.1166], 2e-3); ***** assert_equal (cdf (pd, [-1 0 0.5 1 1.5 2 2.5 3]), ... [0.0272 0.1538 0.2850 0.4492 0.6128 0.7494 0.8506 0.9217], 2e-3); ***** assert_equal (icdf (pd, [0.1 0.25 0.5 0.75 0.9]), ... [-0.2909 0.3820 1.1504 2.0027 2.8265], 5e-3); ***** assert_equal (size (pdf (pd, [])), [0, 0]) ***** error pdf (pd, int32 (1)) ***** error pdf (pd, true) ***** error pdf (pd, 'a') ***** error cdf (pd, int32 (1)) ***** error icdf (pd, int32 (1)) ***** assert_equal (size (cdf (pd, [])), [0, 0]) ***** assert_equal (size (icdf (pd, [])), [0, 0]) ***** assert_equal (size (random (pd, -1)), [0, 0]) ***** assert_equal (size (random (pd, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (mean (pd), 1.2067, 1e-4); ***** assert_equal (std (pd), 1.1918, 1e-3); ***** assert_equal (var (pd), 1.4203, 1e-3); ***** assert_equal (median (pd), 1.1504, 5e-3); ***** assert_equal (iqr (pd), 1.6207, 5e-3); ***** assert_equal (negloglik (pd), 21.5835, 1e-3); ***** assert_equal (pdbox.Kernel, 'box'); ***** assert_equal (pdbox.Bandwidth, 0.5); ***** assert_equal (pdf (pdbox, [0 1 2]), [0.1925 0.3464 0.2309], 2e-3); ***** assert_equal (pdf (t, [-1 0 1 2 3 4]), ... [0 0.2788 0.4420 0.3093 0.1518 0], 2e-3); ***** assert_equal (cdf (t, [-1 0 1 2 3 4]), ... [0 0 0.3846 0.7755 1 1], 2e-3); ***** assert_equal (mean (t), 1.3293, 1e-3); ***** test ## positive support (log boundary correction) y = [0.2 0.5 0.7 1.1 1.4 2 2.6 3.3 4.1 5.5]'; pdpos = fitdist (y, 'Kernel', 'Support', 'positive'); assert_equal (pdpos.Bandwidth, 0.768201, 1e-4); assert_equal (pdpos.Support.range, 'positive'); assert_equal (pdf (pdpos, [0.1 0.5 1 2 3 5]), ... [0.4302 0.3919 0.2738 0.1572 0.0999 0.0463], 2e-3); ***** test ## random values honour truncation bounds x = [2.1 0.3 1.2 -0.7 0.9 1.5 2.8 0.1 0.4 1.1 3.2 0.6 2.0 0.9 1.7]'; pd = fitdist (x, 'Kernel'); t = truncate (pd, 0, 3); r = random (t, 1000, 1); assert_equal (all (r >= 0 & r <= 3), true); assert_equal (size (random (pd, 10, 5)), [10, 5]); ***** error ... cdf (fitdist ([1 2 3 4 5]', 'Kernel'), 2, 'uper') ***** error ... truncate (fitdist ([1 2 3 4 5]', 'Kernel')) ***** error ... truncate (fitdist ([1 2 3 4 5]', 'Kernel'), 4, 2) ***** error ... fitdist ([1 2 3 4 5]', 'Kernel', 'Kernel', 'cosine') ***** error ... fitdist ([1 2 3 4 5]', 'Kernel', 'Support', 'half') ***** error ... fitdist ([1 2 3 4 5]', 'Kernel', 'Width', -1) ***** shared pd pd = prob.KernelDistribution (); pd(2) = prob.KernelDistribution (); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 52 tests, 52 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/tLocationScaleDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/tLocationScaleDistribution.m ***** demo ## Generate a data set of 5000 random samples from a t Location-Scale distribution ## with parameters mu = 0, sigma = 1, and nu = 5. Fit a t Location-Scale ## distribution to this data and plot a PDF of the fitted distribution ## superimposed on a histogram of the data. rng (42); randg ('state', 42); rande ('state', 42); randp ('state', 42); pd_fixed = makedist ('tLocationScale', 'mu', 0, 'sigma', 1, 'nu', 5); data = random (pd_fixed, 5000, 1); pd_fitted = fitdist (data, 'tLocationScale'); plot (pd_fitted); msg = 'Fitted t Location-Scale distribution with mu = %0.2f, sigma = %0.2f, nu = %0.2f'; title (sprintf (msg, pd_fitted.mu, pd_fitted.sigma, pd_fitted.nu)); ***** shared pd, t pd = prob.tLocationScaleDistribution; t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0.5, 0.8184, 0.9490, 0.9850, 0.9948, 0.9979], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 0.7841, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4, NaN]), [0.9030, 0.9490, 0.9850, 0.9948, NaN], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4, NaN]), [0, 0, 0.7841, 1, NaN], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [-Inf, -0.9195, -0.2672, 0.2672, 0.9195, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.1559, 2.3533, 2.6223, 3.0432, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, -0.2672, 0.2672, 0.9195, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.3533, 2.6223, 3.0432, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 1.4534, 1e-4); ***** assert_equal (iqr (t), 0.7139, 1e-4); ***** assert_equal (mean (pd), 0, eps); ***** assert_equal (mean (t), 2.6099, 1e-4); ***** assert_equal (median (pd), 0, eps); ***** assert_equal (median (t), 2.4758, 1e-4); ***** assert_equal (pdf (pd, [0:5]), [0.3796, 0.2197, 0.0651, 0.0173, 0.0051, 0.0018], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 1.4209, 0.3775, 0.1119, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1.5, NaN]), [0.2197, 0.1245, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1.5, NaN]), [0, 0, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 1.2910, 1e-4); ***** assert_equal (std (t), 0.4989, 1e-4); ***** assert_equal (var (pd), 1.6667, 1e-4); ***** assert_equal (var (t), 0.2489, 1e-4); ***** test ## The profile over the first free parameter: 21 grid values, one row of ## OTHER per value, and the likelihood peaking at the fitted estimate. x = [0.3; -1.2; 0.8; 1.5; -0.4; 0.2; -0.9; 1.1; 0.6; -0.3; ... 1.8; -1.5; 0.4; 0.9; -0.7; 1.2; -0.2; 0.5; -1.1; 0.7]; pd = fitdist (x, 'tLocationScale'); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 21]); assert_equal (size (other), [21, 2]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); warning: tlsfit: maximum number of iterations are exceeded. warning: called from tlsfit at line 143 column 7 fit at line 811 column 8 fitdist at line 735 column 9 __test__ at line 7 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 54 column 2 warning: tlsfit: maximum number of iterations are exceeded. warning: called from tlsfit at line 143 column 7 mle at line 506 column 10 __paramci__ at line 214 column 10 paramci at line 522 column 9 __proflik__ at line 373 column 9 proflik at line 664 column 8 __test__ at line 8 column 3 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 54 column 2 warning: tlsfit: maximum number of iterations are exceeded. warning: called from tlsfit at line 143 column 7 mle at line 506 column 10 __paramci__ at line 214 column 10 paramci at line 522 column 9 __proflik__ at line 373 column 9 proflik at line 664 column 8 __test__ at line 11 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 54 column 2 ***** error ... prob.tLocationScaleDistribution (i, 1, 1) ***** error ... prob.tLocationScaleDistribution (Inf, 1, 1) ***** error ... prob.tLocationScaleDistribution ([1, 2], 1, 1) ***** error ... prob.tLocationScaleDistribution ('a', 1, 1) ***** error ... prob.tLocationScaleDistribution (NaN, 1, 1) ***** error ... prob.tLocationScaleDistribution (0, 0, 1) ***** error ... prob.tLocationScaleDistribution (0, -1, 1) ***** error ... prob.tLocationScaleDistribution (0, Inf, 1) ***** error ... prob.tLocationScaleDistribution (0, i, 1) ***** error ... prob.tLocationScaleDistribution (0, 'a', 1) ***** error ... prob.tLocationScaleDistribution (0, [1, 2], 1) ***** error ... prob.tLocationScaleDistribution (0, NaN, 1) ***** error ... prob.tLocationScaleDistribution (0, 1, 0) ***** error ... prob.tLocationScaleDistribution (0, 1, -1) ***** error ... prob.tLocationScaleDistribution (0, 1, Inf) ***** error ... prob.tLocationScaleDistribution (0, 1, i) ***** error ... prob.tLocationScaleDistribution (0, 1, 'a') ***** error ... prob.tLocationScaleDistribution (0, 1, [1, 2]) ***** error ... prob.tLocationScaleDistribution (0, 1, NaN) ***** error ... cdf (prob.tLocationScaleDistribution, 2, 'uper') ***** error ... cdf (prob.tLocationScaleDistribution, 2, 3) ***** shared x x = tlsrnd (0, 1, 1, [1, 100]); ***** error ... paramci (prob.tLocationScaleDistribution.fit (x), 'alpha') ***** error ... paramci (prob.tLocationScaleDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.tLocationScaleDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.tLocationScaleDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.tLocationScaleDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.tLocationScaleDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.tLocationScaleDistribution.fit (x), 'parameter', 'mu', ... 'alpha', {0.05}) ***** error ... paramci (prob.tLocationScaleDistribution.fit (x), ... 'parameter', {'mu', 'sigma', 'nu', 'param'}) ***** error ... paramci (prob.tLocationScaleDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'mu', 'sigma', 'nu', 'param'}) ***** error ... paramci (prob.tLocationScaleDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.tLocationScaleDistribution.fit (x), 'alpha', 0.01, ... 'parameter', 'param') ***** error ... paramci (prob.tLocationScaleDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.tLocationScaleDistribution.fit (x), 'alpha', 0.01, 'NAME', 'value') ***** error ... paramci (prob.tLocationScaleDistribution.fit (x), 'alpha', 0.01, ... 'parameter', 'mu', 'NAME', 'value') ***** error ... plot (prob.tLocationScaleDistribution, 'Parent') ***** error ... plot (prob.tLocationScaleDistribution, 'PlotType', 12) ***** error ... plot (prob.tLocationScaleDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.tLocationScaleDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.tLocationScaleDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.tLocationScaleDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.tLocationScaleDistribution, 'Discrete', {true}) ***** error ... plot (prob.tLocationScaleDistribution, 'Parent', 12) ***** error ... plot (prob.tLocationScaleDistribution, 'Parent', 'hax') ***** error ... plot (prob.tLocationScaleDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.tLocationScaleDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.tLocationScaleDistribution, 2) ***** error ... proflik (prob.tLocationScaleDistribution.fit (x), 4) ***** error ... proflik (prob.tLocationScaleDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.tLocationScaleDistribution.fit (x), {1}) ***** error ... proflik (prob.tLocationScaleDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.tLocationScaleDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.tLocationScaleDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.tLocationScaleDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.tLocationScaleDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.tLocationScaleDistribution.fit (x), 1, 'Display', ['on'; 'on']) ***** error ... proflik (prob.tLocationScaleDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.tLocationScaleDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.tLocationScaleDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.tLocationScaleDistribution.fit (x), 1, {[1 2 3 4]}, 'Display', 'on') ***** error ... truncate (prob.tLocationScaleDistribution) ***** error ... truncate (prob.tLocationScaleDistribution, 2) ***** error ... truncate (prob.tLocationScaleDistribution, 4, 2) ***** shared pd pd = prob.tLocationScaleDistribution (0, 1, 1); pd(2) = prob.tLocationScaleDistribution (0, 1, 3); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 103 tests, 103 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/MultinomialDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/MultinomialDistribution.m ***** demo ## Generate a data set of 5000 random samples from a Multinomial distribution ## with parameters Probabilities = [0.1, 0.2, 0.3, 0.2, 0.1, 0.1]. Create ## the distribution and plot the PDF superimposed on a histogram of the data. rng (42); randg ('state', 42); rande ('state', 42); randp ('state', 42); probs = [0.1, 0.2, 0.3, 0.2, 0.1, 0.1]; pd = makedist ('Multinomial', 'Probabilities', probs); data = random (pd, 5000, 1); hist (data, length (probs)); hold on x = 1:length (probs); y = pdf (pd, x) * 5000; stem (x, y, 'r', 'LineWidth', 2); hold off msg = 'Multinomial distribution with Probabilities = [%s]'; probs_str = num2str (probs, '%0.1f '); title (sprintf (msg, probs_str)) ***** shared pd, t pd = prob.MultinomialDistribution ([0.1, 0.2, 0.3, 0.2, 0.1, 0.1]); t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [2, 3, 4]), [0.3, 0.6, 0.8], eps); ***** assert_equal (cdf (t, [2, 3, 4]), [0.2857, 0.7143, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4]), [0.1, 0.3, 0.6, 0.8], eps); ***** assert_equal (cdf (pd, [1.5, 2-eps, 3, 4]), [0.1, 0.1, 0.6, 0.8], eps); ***** assert_equal (cdf (t, [1.5, 2, 3, 4]), [0, 0.2857, 0.7143, 1], 1e-4); ***** assert_equal (cdf (t, [1.5, 2-eps, 3, 4]), [0, 0, 0.7143, 1], 1e-4); ***** assert_equal (cdf (pd, [1, 2.5, 4, 6]), [0.1, 0.3, 0.8, 1], eps); ***** assert_equal (icdf (pd, [0, 0.2857, 0.7143, 1]), [1, 2, 4, 6]); ***** assert_equal (icdf (t, [0, 0.2857, 0.7143, 1]), [2, 2, 4, 4]); ***** assert_equal (icdf (t, [0, 0.35, 0.7143, 1]), [2, 3, 4, 4]); ***** assert_equal (icdf (t, [0, 0.35, 0.7143, 1, NaN]), [2, 3, 4, 4, NaN]); ***** assert_equal (icdf (t, [-0.5, 0, 0.35, 0.7143, 1, NaN]), [NaN, 2, 3, 4, 4, NaN]); ***** assert_equal (icdf (pd, [-0.5, 0, 0.35, 0.7143, 1, NaN]), [NaN, 1, 3, 4, 6, NaN]); ***** assert_equal (iqr (pd), 2); ***** assert_equal (iqr (t), 2); ***** assert_equal (mean (pd), 3.3, 1e-14); ***** assert_equal (mean (t), 3, eps); ***** assert_equal (median (pd), 3); ***** assert_equal (median (t), 3); ***** assert_equal (pdf (pd, [-5, 1, 2.5, 4, 6, NaN, 9]), [0, 0.1, 0, 0.2, 0.1, NaN, 0]); ***** assert_equal (pdf (pd, [-5, 1, 2, 3, 4, 6, NaN, 9]), ... [0, 0.1, 0.2, 0.3, 0.2, 0.1, NaN, 0]); ***** assert_equal (pdf (t, [-5, 1, 2, 3, 4, 6, NaN, 0]), ... [0, 0, 0.2857, 0.4286, 0.2857, 0, NaN, 0], 1e-4); ***** assert_equal (pdf (t, [-5, 1, 2, 4, 6, NaN, 0]), ... [0, 0, 0.2857, 0.2857, 0, NaN, 0], 1e-4); ***** assert_equal (size (random (pd)), [1, 1]) ***** assert_equal (class (pdf (pd, int32 (2))), 'double') ***** assert_equal (class (cdf (pd, int32 (2))), 'double') ***** assert_equal (pdf (pd, int32 (2)), pdf (pd, 2)) ***** error pdf (pd, true) ***** error pdf (pd, 'a') ***** error icdf (pd, int32 (1)) ***** assert_equal (size (random (pd, 3)), [3, 3]) ***** assert_equal (size (random (pd, -1)), [0, 0]) ***** assert_equal (size (random (pd, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (unique (random (pd, 1000, 5)), [1, 2, 3, 4, 5, 6]'); ***** assert_equal (unique (random (t, 1000, 5)), [2, 3, 4]'); ***** assert_equal (std (pd), 1.4177, 1e-4); ***** assert_equal (std (t), 0.7559, 1e-4); ***** assert_equal (var (pd), 2.0100, 1e-4); ***** assert_equal (var (t), 0.5714, 1e-4); ***** error ... prob.MultinomialDistribution (0) ***** error ... prob.MultinomialDistribution (-1) ***** error ... prob.MultinomialDistribution (Inf) ***** error ... prob.MultinomialDistribution (i) ***** error ... prob.MultinomialDistribution ('a') ***** error ... prob.MultinomialDistribution ([1, 2]) ***** error ... prob.MultinomialDistribution (NaN) ***** error ... cdf (prob.MultinomialDistribution, 2, 'uper') ***** error ... cdf (prob.MultinomialDistribution, 2, 3) ***** error ... cdf (prob.MultinomialDistribution, i) ***** error ... plot (prob.MultinomialDistribution, 'Parent') ***** error ... plot (prob.MultinomialDistribution, 'PlotType', 12) ***** error ... plot (prob.MultinomialDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.MultinomialDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.MultinomialDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.MultinomialDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.MultinomialDistribution, 'Discrete', {true}) ***** error ... plot (prob.MultinomialDistribution, 'Parent', 12) ***** error ... plot (prob.MultinomialDistribution, 'Parent', 'hax') ***** error ... plot (prob.MultinomialDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.MultinomialDistribution, 'PlotType', 'probability') ***** error ... truncate (prob.MultinomialDistribution) ***** error ... truncate (prob.MultinomialDistribution, 2) ***** error ... truncate (prob.MultinomialDistribution, 4, 2) ***** shared pd pd = prob.MultinomialDistribution ([0.1, 0.2, 0.3, 0.4]); pd(2) = prob.MultinomialDistribution ([0.1, 0.2, 0.3, 0.4]); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) ***** test pd = makedist ('Multinomial', 'Probabilities', [0.2, 0.3, 0.5]); assert_equal (iscell (pd.ParameterValues), true); assert_equal (size (pd.ParameterValues), [1, 1]); assert_equal (pd.ParameterValues{1}, [0.2, 0.3, 0.5]); assert_equal (numel (pd.ParameterValues), pd.NumParameters); assert_equal (size (pd.ParameterValues), size (pd.ParameterNames)); ***** test pd = makedist ('Multinomial', 'Probabilities', [0.2; 0.3; 0.5]); assert_equal (size (pd.ParameterValues{1}), [1, 3]); pd.Probabilities = [0.5; 0.5]; assert_equal (pd.ParameterValues{1}, [0.5, 0.5]); 76 tests, 76 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/BinomialDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/BinomialDistribution.m ***** shared pd, t, t_inf pd = prob.BinomialDistribution (5, 0.5); t = truncate (pd, 2, 4); t_inf = truncate (pd, 2, Inf); ***** assert_equal (cdf (pd, [0:5]), [0.0312, 0.1875, 0.5, 0.8125, 0.9688, 1], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0.4, 0.8, 1, 1], 1e-4); ***** assert_equal (cdf (t_inf, [0:5]), [0, 0, 0.3846, 0.7692, 0.9615, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4, NaN]), [0.1875, 0.5, 0.8125, 0.9688, NaN], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4, NaN]), [0, 0.4, 0.8, 1, NaN], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [0, 2, 2, 3, 3, 5], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2, 2, 3, 3, 4], 1e-4); ***** assert_equal (icdf (t_inf, [0:0.2:1]), [2, 2, 3, 3, 4, 5], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 2, 3, 3, 5, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2, 3, 3, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 1); ***** assert_equal (iqr (t), 1); ***** assert_equal (mean (pd), 2.5, 1e-10); ***** assert_equal (mean (t), 2.8, 1e-10); ***** assert_equal (mean (t_inf), 2.8846, 1e-4); ***** assert_equal (median (pd), 2); ***** assert_equal (median (prob.BinomialDistribution (7, 0.5)), 3); ***** assert_equal (median (prob.BinomialDistribution (10, 0.5)), 5); ***** assert_equal (icdf (pd, 0.5), 2); ***** assert_equal (median (t), 3); ***** assert_equal (pdf (pd, [0:5]), [0.0312, 0.1562, 0.3125, 0.3125, 0.1562, 0.0312], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 0.4, 0.4, 0.2, 0], 1e-4); ***** assert_equal (pdf (t_inf, [0:5]), [0, 0, 0.3846, 0.3846, 0.1923, 0.0385], 1e-4); ***** assert_equal (pdf (pd, [-1, 1.5, NaN]), [0, 0, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1.5, NaN]), [0, 0, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 1.1180, 1e-4); ***** assert_equal (std (t), 0.7483, 1e-4); ***** assert_equal (std (t_inf), 0.8470, 1e-4); ***** assert_equal (var (pd), 1.2500, 1e-4); ***** assert_equal (var (t), 0.5600, 1e-4); ***** assert_equal (var (t_inf), 0.7175, 1e-4); ***** test ## paramci reports one column per parameter, N held at its own value, as ## MATLAB does; it used to return a single 1x2 row, which stopped proflik. x = [3; 1; 4; 1; 5; 2; 6; 5; 3; 5; 2; 4; 1; 3; 2; 4; 6; 2; 3; 1]; pd = fitdist (x, 'Binomial', 'NTrials', 8); assert_equal (paramci (pd), [8, 0.317538; 8, 0.473975], 1e-6); assert_equal (paramci (pd, 'Parameter', 'p'), [0.317538; 0.473975], 1e-6); assert_equal (paramci (pd, 'Parameter', 'N'), [8; 8]); ***** test ## The profile over p, the only estimated parameter, takes 101 grid values. ## OTHER reports the fixed N at its own value; MATLAB documents that and ## then returns 0 there, so this follows its documentation, not its code. x = [3; 1; 4; 1; 5; 2; 6; 5; 3; 5; 2; 4; 1; 3; 2; 4; 6; 2; 3; 1]; pd = fitdist (x, 'Binomial', 'NTrials', 8); [nlogL, param, other] = proflik (pd, 2); assert_equal (size (param), [1, 101]); assert_equal (size (other), [101, 1]); assert_equal (unique (other), 8); assert_equal (proflik (pd), nlogL); ***** error ... prob.BinomialDistribution (Inf, 0.5) ***** error ... prob.BinomialDistribution (i, 0.5) ***** error ... prob.BinomialDistribution ('a', 0.5) ***** error ... prob.BinomialDistribution ([1, 2], 0.5) ***** error ... prob.BinomialDistribution (NaN, 0.5) ***** error ... prob.BinomialDistribution (1, 1.01) ***** error ... prob.BinomialDistribution (1, -0.01) ***** error ... prob.BinomialDistribution (1, Inf) ***** error ... prob.BinomialDistribution (1, i) ***** error ... prob.BinomialDistribution (1, 'a') ***** error ... prob.BinomialDistribution (1, [1, 2]) ***** error ... prob.BinomialDistribution (1, NaN) ***** error ... cdf (prob.BinomialDistribution, 2, 'uper') ***** error ... cdf (prob.BinomialDistribution, 2, 3) ***** shared x rand ('seed', 2); x = binornd (5, 0.5, [1, 100]); ***** error ... paramci (prob.BinomialDistribution.fit (x, 6), 'alpha') ***** error ... paramci (prob.BinomialDistribution.fit (x, 6), 'alpha', 0) ***** error ... paramci (prob.BinomialDistribution.fit (x, 6), 'alpha', 1) ***** error ... paramci (prob.BinomialDistribution.fit (x, 6), 'alpha', [0.5 2]) ***** error ... paramci (prob.BinomialDistribution.fit (x, 6), 'alpha', '') ***** error ... paramci (prob.BinomialDistribution.fit (x, 6), 'alpha', {0.05}) ***** error ... paramci (prob.BinomialDistribution.fit (x, 6), 'parameter', 'p', ... 'alpha', {0.05}) ***** error ... paramci (prob.BinomialDistribution.fit (x, 6), ... 'parameter', {'N', 'p', 'param'}) ***** error ... paramci (prob.BinomialDistribution.fit (x, 6), 'alpha', 0.01, ... 'parameter', {'N', 'p', 'param'}) ***** error ... paramci (prob.BinomialDistribution.fit (x, 6), 'parameter', 'param') ***** error ... paramci (prob.BinomialDistribution.fit (x, 6), 'alpha', 0.01, ... 'parameter', 'param') ***** error ... paramci (prob.BinomialDistribution.fit (x, 6), 'NAME', 'value') ***** error ... paramci (prob.BinomialDistribution.fit (x, 6), 'alpha', 0.01, ... 'NAME', 'value') ***** error ... paramci (prob.BinomialDistribution.fit (x, 6), 'alpha', 0.01, ... 'parameter', 'p', 'NAME', 'value') ***** error ... plot (prob.BinomialDistribution, 'Parent') ***** error ... plot (prob.BinomialDistribution, 'PlotType', 12) ***** error ... plot (prob.BinomialDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.BinomialDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.BinomialDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.BinomialDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.BinomialDistribution, 'Discrete', {true}) ***** error ... plot (prob.BinomialDistribution, 'Parent', 12) ***** error ... plot (prob.BinomialDistribution, 'Parent', 'hax') ***** error ... plot (prob.BinomialDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.BinomialDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.BinomialDistribution, 2) ***** error ... proflik (prob.BinomialDistribution.fit (x, 6), 3) ***** error ... proflik (prob.BinomialDistribution.fit (x, 6), [1, 2]) ***** error ... proflik (prob.BinomialDistribution.fit (x, 6), {1}) ***** error ... proflik (prob.BinomialDistribution.fit (x, 6), 2, ones (2)) ***** error ... proflik (prob.BinomialDistribution.fit (x, 6), 2, 'Display') ***** error ... proflik (prob.BinomialDistribution.fit (x, 6), 2, 'Display', 1) ***** error ... proflik (prob.BinomialDistribution.fit (x, 6), 2, 'Display', {1}) ***** error ... proflik (prob.BinomialDistribution.fit (x, 6), 2, 'Display', {'on'}) ***** error ... proflik (prob.BinomialDistribution.fit (x, 6), 2, 'Display', ['on'; 'on']) ***** error ... proflik (prob.BinomialDistribution.fit (x, 6), 2, 'Display', 'onnn') ***** error ... proflik (prob.BinomialDistribution.fit (x, 6), 2, 'NAME', 'on') ***** error ... proflik (prob.BinomialDistribution.fit (x, 6), 2, {'NAME'}, 'on') ***** error ... proflik (prob.BinomialDistribution.fit (x, 6), 2, {[1 2 3]}, 'Display', 'on') ***** error ... truncate (prob.BinomialDistribution) ***** error ... truncate (prob.BinomialDistribution, 2) ***** error ... truncate (prob.BinomialDistribution, 4, 2) ***** shared pd pd = prob.BinomialDistribution (1, 0.5); pd(2) = prob.BinomialDistribution (1, 0.6); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 106 tests, 106 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/ExponentialDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/ExponentialDistribution.m ***** shared pd, t pd = prob.ExponentialDistribution (1); t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0, 0.6321, 0.8647, 0.9502, 0.9817, 0.9933], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 0.7311, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4]), [0.7769, 0.8647, 0.9502, 0.9817], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4]), [0, 0, 0.7311, 1], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [0, 0.2231, 0.5108, 0.9163, 1.6094, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.1899, 2.4244, 2.7315, 3.1768, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 0.5108, 0.9163, 1.6094, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.4244, 2.7315, 3.1768, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 1.0986, 1e-4); ***** assert_equal (iqr (t), 0.8020, 1e-4); ***** assert_equal (mean (pd), 1); ***** assert_equal (mean (t), 2.6870, 1e-4); ***** assert_equal (median (pd), 0.6931, 1e-4); ***** assert_equal (median (t), 2.5662, 1e-4); ***** assert_equal (pdf (pd, [0:5]), [1, 0.3679, 0.1353, 0.0498, 0.0183, 0.0067], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 1.1565, 0.4255, 0.1565, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1:4, NaN]), [0, 0.3679, 0.1353, 0.0498, 0.0183, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1:4, NaN]), [0, 0, 1.1565, 0.4255, 0.1565, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 1); ***** assert_equal (std (t), 0.5253, 1e-4); ***** assert_equal (var (pd), 1); ***** assert_equal (var (t), 0.2759, 1e-4); ***** test ## The default grid takes 101 values over the 98% confidence interval when ## the selected parameter is the only one estimated. Verified against MATLAB. x = [1.2; 0.4; 3.1; 0.7; 2.5; 1.8; 0.3; 4.2; 1.1; 0.9; ... 2.2; 0.6; 1.5; 3.7; 0.8; 2.9; 1.3; 0.5; 2.0; 1.6]; [nlogL, param, other] = proflik (prob.ExponentialDistribution.fit (x), 1); assert_equal (size (param), [1, 101]); assert_equal ([param(1), param(end)], [1.0457, 3.0048], 1e-4); assert_equal (size (other), [101, 0]); ***** test ## PNUM defaults to the first parameter that is not fixed. x = [1.2; 0.4; 3.1; 0.7; 2.5; 1.8; 0.3; 4.2; 1.1; 0.9; ... 2.2; 0.6; 1.5; 3.7; 0.8; 2.9; 1.3; 0.5; 2.0; 1.6]; pdf = prob.ExponentialDistribution.fit (x); assert_equal (proflik (pdf), proflik (pdf, 1)); ***** error ... prob.ExponentialDistribution (0) ***** error ... prob.ExponentialDistribution (-1) ***** error ... prob.ExponentialDistribution (Inf) ***** error ... prob.ExponentialDistribution (i) ***** error ... prob.ExponentialDistribution ('a') ***** error ... prob.ExponentialDistribution ([1, 2]) ***** error ... prob.ExponentialDistribution (NaN) ***** error ... cdf (prob.ExponentialDistribution, 2, 'uper') ***** error ... cdf (prob.ExponentialDistribution, 2, 3) ***** shared x x = exprnd (1, [100, 1]); ***** error ... paramci (prob.ExponentialDistribution.fit (x), 'alpha') ***** error ... paramci (prob.ExponentialDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.ExponentialDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.ExponentialDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.ExponentialDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.ExponentialDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.ExponentialDistribution.fit (x), 'parameter', 'mu', ... 'alpha', {0.05}) ***** error ... paramci (prob.ExponentialDistribution.fit (x), 'parameter', {'mu', 'param'}) ***** error ... paramci (prob.ExponentialDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'mu', 'param'}) ***** error ... paramci (prob.ExponentialDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.ExponentialDistribution.fit (x), 'alpha', 0.01, 'parameter', 'parm') ***** error ... paramci (prob.ExponentialDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.ExponentialDistribution.fit (x), 'alpha', 0.01, 'NAME', 'value') ***** error ... paramci (prob.ExponentialDistribution.fit (x), 'alpha', 0.01, ... 'parameter', 'mu', 'NAME', 'value') ***** error ... plot (prob.ExponentialDistribution, 'Parent') ***** error ... plot (prob.ExponentialDistribution, 'PlotType', 12) ***** error ... plot (prob.ExponentialDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.ExponentialDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.ExponentialDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.ExponentialDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.ExponentialDistribution, 'Discrete', {true}) ***** error ... plot (prob.ExponentialDistribution, 'Parent', 12) ***** error ... plot (prob.ExponentialDistribution, 'Parent', 'hax') ***** error ... plot (prob.ExponentialDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.ExponentialDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.ExponentialDistribution, 2) ***** error ... proflik (prob.ExponentialDistribution.fit (x), 3) ***** error ... proflik (prob.ExponentialDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.ExponentialDistribution.fit (x), {1}) ***** error ... proflik (prob.ExponentialDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.ExponentialDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.ExponentialDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.ExponentialDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.ExponentialDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.ExponentialDistribution.fit (x), 1, 'Display', ['on'; 'on']) ***** error ... proflik (prob.ExponentialDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.ExponentialDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.ExponentialDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.ExponentialDistribution.fit (x), 1, {[1 2 3 4]}, 'Display', 'on') ***** error ... truncate (prob.ExponentialDistribution) ***** error ... truncate (prob.ExponentialDistribution, 2) ***** error ... truncate (prob.ExponentialDistribution, 4, 2) ***** shared pd pd = prob.ExponentialDistribution (1); pd(2) = prob.ExponentialDistribution (3); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** test ## negloglik returns the (positive) negative log-likelihood. xdat = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; pdfit = prob.ExponentialDistribution.fit (xdat'); assert_equal (negloglik (pdfit), -sum (log (pdf (pdfit, xdat'))), 1e-9); assert_equal (negloglik (pdfit) > 0, true); ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 93 tests, 93 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/LoguniformDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/LoguniformDistribution.m ***** demo ## Generate a data set of 5000 random samples from a Log-uniform distribution with ## parameters Lower = 1 and Upper = 10. Plot a PDF of the distribution superimposed ## on a histogram of the data. rng (42); randg ('state', 42); rande ('state', 42); randp ('state', 42); pd_fixed = makedist ('Loguniform', 'Lower', 1, 'Upper', 10); data = random (pd_fixed, 5000, 1); plot (pd_fixed) hold on hist (data, 50) hold off msg = 'Log-uniform distribution with Lower = %0.2f and Upper = %0.2f'; title (sprintf (msg, pd_fixed.Lower, pd_fixed.Upper)) ***** shared pd, t pd = prob.LoguniformDistribution (1, 4); t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0, 1, 2, 3, 4, 5]), [0, 0, 0.5, 0.7925, 1, 1], 1e-4); ***** assert_equal (cdf (t, [0, 1, 2, 3, 4, 5]), [0, 0, 0, 0.5850, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4]), [0.2925, 0.5, 0.7925, 1], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4]), [0, 0, 0.5850, 1], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [1, 1.3195, 1.7411, 2.2974, 3.0314, 4], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.2974, 2.6390, 3.0314, 3.4822, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 1.7411, 2.2974, 3.0314, 4, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.6390, 3.0314, 3.4822, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 1.4142, 1e-4); ***** assert_equal (iqr (t), 0.9852, 1e-4); ***** assert_equal (mean (pd), 2.1640, 1e-4); ***** assert_equal (mean (t), 2.8854, 1e-4); ***** assert_equal (median (pd), 2); ***** assert_equal (median (t), 2.8284, 1e-4); ***** assert_equal (pdf (pd, [0, 1, 2, 3, 4, 5]), [0, 0.7213, 0.3607, 0.2404, 0.1803, 0], 1e-4); ***** assert_equal (pdf (t, [0, 1, 2, 3, 4, 5]), [0, 0, 0.7213, 0.4809, 0.3607, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1, 2, 3, 4, NaN]), [0, 0.7213, 0.3607, 0.2404, 0.1803, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1, 2, 3, 4, NaN]), [0, 0, 0.7213, 0.4809, 0.3607, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (size (random (pd)), [1, 1]) ***** error pdf (pd, int32 (2)) ***** error pdf (pd, true) ***** error cdf (pd, int32 (2)) ***** error icdf (pd, int32 (1)) ***** assert_equal (size (random (pd, 3)), [3, 3]) ***** assert_equal (size (random (pd, -1)), [0, 0]) ***** assert_equal (size (random (pd, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (any (random (pd, 1000, 1) < 1), false); ***** assert_equal (any (random (pd, 1000, 1) > 4), false); ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 0.8527, 1e-4); ***** assert_equal (std (t), 0.5751, 1e-4); ***** assert_equal (var (pd), 0.7270, 1e-4); ***** assert_equal (var (t), 0.3307, 1e-4); ***** error ... prob.LoguniformDistribution (i, 1) ***** error ... prob.LoguniformDistribution (Inf, 1) ***** error ... prob.LoguniformDistribution ([1, 2], 1) ***** error ... prob.LoguniformDistribution ('a', 1) ***** error ... prob.LoguniformDistribution (NaN, 1) ***** error ... prob.LoguniformDistribution (1, i) ***** error ... prob.LoguniformDistribution (1, Inf) ***** error ... prob.LoguniformDistribution (1, [1, 2]) ***** error ... prob.LoguniformDistribution (1, 'a') ***** error ... prob.LoguniformDistribution (1, NaN) ***** error ... prob.LoguniformDistribution (2, 1) ***** error ... cdf (prob.LoguniformDistribution, 2, 'uper') ***** error ... cdf (prob.LoguniformDistribution, 2, 3) ***** error ... plot (prob.LoguniformDistribution, 'Parent') ***** error ... plot (prob.LoguniformDistribution, 'PlotType', 12) ***** error ... plot (prob.LoguniformDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.LoguniformDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.LoguniformDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.LoguniformDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.LoguniformDistribution, 'Discrete', {true}) ***** error ... plot (prob.LoguniformDistribution, 'Parent', 12) ***** error ... plot (prob.LoguniformDistribution, 'Parent', 'hax') ***** error ... plot (prob.LoguniformDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.LoguniformDistribution, 'PlotType', 'probability') ***** error ... truncate (prob.LoguniformDistribution) ***** error ... truncate (prob.LoguniformDistribution, 2) ***** error ... truncate (prob.LoguniformDistribution, 4, 2) ***** shared pd pd = prob.LoguniformDistribution (1, 4); pd(2) = prob.LoguniformDistribution (2, 5); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 73 tests, 73 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/ExtremeValueDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/ExtremeValueDistribution.m ***** shared pd, t pd = prob.ExtremeValueDistribution (0, 1); t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0.6321, 0.9340, 0.9994, 1, 1, 1], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 1, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4]), [0.9887, 0.9994, 1, 1], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4]), [0, 0, 1, 1], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [-Inf, -1.4999, -0.6717, -0.0874, 0.4759, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.0298, 2.0668, 2.1169, 2.1971, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, -0.6717, -0.0874, 0.4759, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.0668, 2.1169, 2.1971, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 1.5725, 1e-4); ***** assert_equal (iqr (t), 0.1338, 1e-4); ***** assert_equal (mean (pd), -0.5772, 1e-4); ***** assert_equal (mean (t), 2.1206, 1e-4); ***** assert_equal (median (pd), -0.3665, 1e-4); ***** assert_equal (median (t), 2.0897, 1e-4); ***** assert_equal (pdf (pd, [0:5]), [0.3679, 0.1794, 0.0046, 0, 0, 0], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 7.3891, 0.0001, 0, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1:4, NaN]), [0.2546, 0.1794, 0.0046, 0, 0, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1:4, NaN]), [0, 0, 7.3891, 0.0001, 0, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 1.2825, 1e-4); ***** assert_equal (std (t), 0.1091, 1e-4); ***** assert_equal (var (pd), 1.6449, 1e-4); ***** assert_equal (var (t), 0.0119, 1e-4); ***** test ## The profile over the first free parameter: 21 grid values, one row of ## OTHER per value, and the likelihood peaking at the fitted estimate. x = [0.3; -1.2; 0.8; 1.5; -0.4; 0.2; -0.9; 1.1; 0.6; -0.3; ... 1.8; -1.5; 0.4; 0.9; -0.7; 1.2; -0.2; 0.5; -1.1; 0.7]; pd = fitdist (x, 'ExtremeValue'); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 21]); assert_equal (size (other), [21, 1]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); ***** error ... prob.ExtremeValueDistribution (Inf, 1) ***** error ... prob.ExtremeValueDistribution (i, 1) ***** error ... prob.ExtremeValueDistribution ('a', 1) ***** error ... prob.ExtremeValueDistribution ([1, 2], 1) ***** error ... prob.ExtremeValueDistribution (NaN, 1) ***** error ... prob.ExtremeValueDistribution (1, 0) ***** error ... prob.ExtremeValueDistribution (1, -1) ***** error ... prob.ExtremeValueDistribution (1, Inf) ***** error ... prob.ExtremeValueDistribution (1, i) ***** error ... prob.ExtremeValueDistribution (1, 'a') ***** error ... prob.ExtremeValueDistribution (1, [1, 2]) ***** error ... prob.ExtremeValueDistribution (1, NaN) ***** error ... cdf (prob.ExtremeValueDistribution, 2, 'uper') ***** error ... cdf (prob.ExtremeValueDistribution, 2, 3) ***** shared x rand ('seed', 1); x = evrnd (1, 1, [1000, 1]); ***** error ... paramci (prob.ExtremeValueDistribution.fit (x), 'alpha') ***** error ... paramci (prob.ExtremeValueDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.ExtremeValueDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.ExtremeValueDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.ExtremeValueDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.ExtremeValueDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.ExtremeValueDistribution.fit (x), ... 'parameter', 'mu', 'alpha', {0.05}) ***** error ... paramci (prob.ExtremeValueDistribution.fit (x), ... 'parameter', {'mu', 'sigma', 'param'}) ***** error ... paramci (prob.ExtremeValueDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'mu', 'sigma', 'param'}) ***** error ... paramci (prob.ExtremeValueDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.ExtremeValueDistribution.fit (x), 'alpha', 0.01, ... 'parameter', 'param') ***** error ... paramci (prob.ExtremeValueDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.ExtremeValueDistribution.fit (x), 'alpha', 0.01, 'NAME', 'value') ***** error ... paramci (prob.ExtremeValueDistribution.fit (x), 'alpha', 0.01, ... 'parameter', 'mu', 'NAME', 'value') ***** error ... plot (prob.ExtremeValueDistribution, 'Parent') ***** error ... plot (prob.ExtremeValueDistribution, 'PlotType', 12) ***** error ... plot (prob.ExtremeValueDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.ExtremeValueDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.ExtremeValueDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.ExtremeValueDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.ExtremeValueDistribution, 'Discrete', {true}) ***** error ... plot (prob.ExtremeValueDistribution, 'Parent', 12) ***** error ... plot (prob.ExtremeValueDistribution, 'Parent', 'hax') ***** error ... plot (prob.ExtremeValueDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.ExtremeValueDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.ExtremeValueDistribution, 2) ***** error ... proflik (prob.ExtremeValueDistribution.fit (x), 3) ***** error ... proflik (prob.ExtremeValueDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.ExtremeValueDistribution.fit (x), {1}) ***** error ... proflik (prob.ExtremeValueDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.ExtremeValueDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.ExtremeValueDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.ExtremeValueDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.ExtremeValueDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.ExtremeValueDistribution.fit (x), 1, 'Display', ['on'; 'on']) ***** error ... proflik (prob.ExtremeValueDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.ExtremeValueDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.ExtremeValueDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.ExtremeValueDistribution.fit (x), 1, {[1 2 3 4]}, 'Display', 'on') ***** error ... truncate (prob.ExtremeValueDistribution) ***** error ... truncate (prob.ExtremeValueDistribution, 2) ***** error ... truncate (prob.ExtremeValueDistribution, 4, 2) ***** shared pd pd = prob.ExtremeValueDistribution (1, 1); pd(2) = prob.ExtremeValueDistribution (1, 3); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 96 tests, 96 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/GammaDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/GammaDistribution.m ***** shared pd, t pd = prob.GammaDistribution (1, 1); t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0, 0.6321, 0.8647, 0.9502, 0.9817, 0.9933], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 0.7311, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4]), [0.7769, 0.8647, 0.9502, 0.9817], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4]), [0, 0, 0.7311, 1], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [0, 0.2231, 0.5108, 0.9163, 1.6094, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.1899, 2.4244, 2.7315, 3.1768, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 0.5108, 0.9163, 1.6094, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.4244, 2.7315, 3.1768, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 1.0986, 1e-4); ***** assert_equal (iqr (t), 0.8020, 1e-4); ***** assert_equal (mean (pd), 1); ***** assert_equal (mean (t), 2.6870, 1e-4); ***** assert_equal (median (pd), 0.6931, 1e-4); ***** assert_equal (median (t), 2.5662, 1e-4); ***** assert_equal (pdf (pd, [0:5]), [1, 0.3679, 0.1353, 0.0498, 0.0183, 0.0067], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 1.1565, 0.4255, 0.1565, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1:4, NaN]), [0, 0.3679, 0.1353, 0.0498, 0.0183, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1:4, NaN]), [0, 0, 1.1565, 0.4255, 0.1565, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 1); ***** assert_equal (std (t), 0.5253, 1e-4); ***** assert_equal (var (pd), 1); ***** assert_equal (var (t), 0.2759, 1e-4); ***** test ## The profile over the first free parameter: 21 grid values, one row of ## OTHER per value, and the likelihood peaking at the fitted estimate. x = [1.2; 0.4; 3.1; 0.7; 2.5; 1.8; 0.3; 4.2; 1.1; 0.9; ... 2.2; 0.6; 1.5; 3.7; 0.8; 2.9; 1.3; 0.5; 2.0; 1.6]; pd = fitdist (x, 'Gamma'); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 21]); assert_equal (size (other), [21, 1]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); ***** error ... prob.GammaDistribution (0, 1) ***** error ... prob.GammaDistribution (Inf, 1) ***** error ... prob.GammaDistribution (i, 1) ***** error ... prob.GammaDistribution ('a', 1) ***** error ... prob.GammaDistribution ([1, 2], 1) ***** error ... prob.GammaDistribution (NaN, 1) ***** error ... prob.GammaDistribution (1, 0) ***** error ... prob.GammaDistribution (1, -1) ***** error ... prob.GammaDistribution (1, Inf) ***** error ... prob.GammaDistribution (1, i) ***** error ... prob.GammaDistribution (1, 'a') ***** error ... prob.GammaDistribution (1, [1, 2]) ***** error ... prob.GammaDistribution (1, NaN) ***** error ... cdf (prob.GammaDistribution, 2, 'uper') ***** error ... cdf (prob.GammaDistribution, 2, 3) ***** shared x x = gamrnd (1, 1, [100, 1]); ***** error ... paramci (prob.GammaDistribution.fit (x), 'alpha') ***** error ... paramci (prob.GammaDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.GammaDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.GammaDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.GammaDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.GammaDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.GammaDistribution.fit (x), 'parameter', 'a', 'alpha', {0.05}) ***** error ... paramci (prob.GammaDistribution.fit (x), 'parameter', {'a', 'b', 'param'}) ***** error ... paramci (prob.GammaDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'a', 'b', 'param'}) ***** error ... paramci (prob.GammaDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.GammaDistribution.fit (x), 'alpha', 0.01, 'parameter', 'param') ***** error ... paramci (prob.GammaDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.GammaDistribution.fit (x), 'alpha', 0.01, 'NAME', 'value') ***** error ... paramci (prob.GammaDistribution.fit (x), 'alpha', 0.01, 'parameter', 'a', ... 'NAME', 'value') ***** error ... plot (prob.GammaDistribution, 'Parent') ***** error ... plot (prob.GammaDistribution, 'PlotType', 12) ***** error ... plot (prob.GammaDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.GammaDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.GammaDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.GammaDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.GammaDistribution, 'Discrete', {true}) ***** error ... plot (prob.GammaDistribution, 'Parent', 12) ***** error ... plot (prob.GammaDistribution, 'Parent', 'hax') ***** error ... plot (prob.GammaDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.GammaDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.GammaDistribution, 2) ***** error ... proflik (prob.GammaDistribution.fit (x), 3) ***** error ... proflik (prob.GammaDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.GammaDistribution.fit (x), {1}) ***** error ... proflik (prob.GammaDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.GammaDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.GammaDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.GammaDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.GammaDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.GammaDistribution.fit (x), 1, 'Display', ['on'; 'on']) ***** error ... proflik (prob.GammaDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.GammaDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.GammaDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.GammaDistribution.fit (x), 1, {[1 2 3 4]}, 'Display', 'on') ***** error ... truncate (prob.GammaDistribution) ***** error ... truncate (prob.GammaDistribution, 2) ***** error ... truncate (prob.GammaDistribution, 4, 2) ***** shared pd pd = prob.GammaDistribution (1, 1); pd(2) = prob.GammaDistribution (1, 3); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** test ## negloglik returns the (positive) negative log-likelihood. xdat = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; pdfit = prob.GammaDistribution.fit (xdat'); assert_equal (negloglik (pdfit), -sum (log (pdf (pdfit, xdat'))), 1e-9); assert_equal (negloglik (pdfit) > 0, true); ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 98 tests, 98 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/ProbabilityDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/ProbabilityDistribution.m ***** test 1 test, 1 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/NegativeBinomialDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/NegativeBinomialDistribution.m ***** demo ## Generate a data set of 5000 random samples from a Negative Binomial ## distribution with parameters R = 5 and P = 0.5. Fit a Negative Binomial ## distribution to this data and plot a PDF of the fitted distribution ## superimposed on a histogram of the data. rng (42); randg ('state', 42); rande ('state', 42); randp ('state', 42); pd_fixed = makedist ('NegativeBinomial', 'R', 5, 'P', 0.5) data = random (pd_fixed, 5000, 1); pd_fitted = fitdist (data, 'NegativeBinomial') plot (pd_fitted) msg = 'Fitted Negative Binomial distribution with R = %0.2f and P = %0.2f'; title (sprintf (msg, pd_fitted.R, pd_fitted.P)) ***** shared pd, t, t_inf pd = prob.NegativeBinomialDistribution (5, 0.5); t = truncate (pd, 2, 4); t_inf = truncate (pd, 2, Inf); ***** assert_equal (cdf (pd, [0:5]), [0.0312, 0.1094, 0.2266, 0.3633, 0.5, 0.6230], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0.3, 0.65, 1, 1], 1e-4); ***** assert_equal (cdf (t_inf, [0:5]), [0, 0, 0.1316, 0.2851, 0.4386, 0.5768], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4]), [0.1094, 0.2266, 0.3633, 0.5000], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4]), [0, 0.3, 0.65, 1], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [0, 2, 4, 5, 7, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2, 3, 3, 4, 4], 1e-4); ***** assert_equal (icdf (t_inf, [0:0.2:1]), [2, 3, 4, 6, 8, Inf], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 4, 5, 7, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 3, 3, 4, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 4); ***** assert_equal (iqr (t), 2); ***** assert_equal (mean (pd), 5); ***** assert_equal (mean (t), 3.0500, 1e-4); ***** assert_equal (mean (t_inf), 5.5263, 1e-4); ***** assert_equal (median (pd), 4); ***** assert_equal (median (t), 3); ***** assert_equal (pdf (pd, [0:5]), [0.0312, 0.0781, 0.1172, 0.1367, 0.1367, 0.1230], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 0.3, 0.35, 0.35, 0], 1e-4); ***** assert_equal (pdf (t_inf, [0:5]), [0, 0, 0.1316, 0.1535, 0.1535, 0.1382], 1e-4); ***** assert_equal (pdf (pd, [-1, 1:4, NaN]), [0, 0.0781, 0.1172, 0.1367, 0.1367, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1:4, NaN]), [0, 0, 0.3, 0.35, 0.35, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 3.1623, 1e-4); ***** assert_equal (std (t), 0.8047, 1e-4); ***** assert_equal (std (t_inf), 2.9445, 1e-4); ***** assert_equal (var (pd), 10); ***** assert_equal (var (t), 0.6475, 1e-4); ***** assert_equal (var (t_inf), 8.6704, 1e-4); ***** test ## The profile over the first free parameter: 21 grid values, one row of ## OTHER per value, and the likelihood peaking at the fitted estimate. x = [8; 2; 14; 1; 5; 22; 6; 5; 3; 9; 2; 17; 1; 3; 2; 11; 6; 2; 30; 1]; pd = fitdist (x, 'NegativeBinomial'); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 21]); assert_equal (size (other), [21, 1]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); ***** error ... prob.NegativeBinomialDistribution (Inf, 1) ***** error ... prob.NegativeBinomialDistribution (i, 1) ***** error ... prob.NegativeBinomialDistribution ('a', 1) ***** error ... prob.NegativeBinomialDistribution ([1, 2], 1) ***** error ... prob.NegativeBinomialDistribution (NaN, 1) ***** error ... prob.NegativeBinomialDistribution (1, 0) ***** error ... prob.NegativeBinomialDistribution (1, -1) ***** error ... prob.NegativeBinomialDistribution (1, Inf) ***** error ... prob.NegativeBinomialDistribution (1, i) ***** error ... prob.NegativeBinomialDistribution (1, 'a') ***** error ... prob.NegativeBinomialDistribution (1, [1, 2]) ***** error ... prob.NegativeBinomialDistribution (1, NaN) ***** error ... prob.NegativeBinomialDistribution (1, 1.2) ***** error ... cdf (prob.NegativeBinomialDistribution, 2, 'uper') ***** error ... cdf (prob.NegativeBinomialDistribution, 2, 3) ***** shared x x = nbinrnd (1, 0.5, [1, 100]); ***** error ... paramci (prob.NegativeBinomialDistribution.fit (x), 'alpha') ***** error ... paramci (prob.NegativeBinomialDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.NegativeBinomialDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.NegativeBinomialDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.NegativeBinomialDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.NegativeBinomialDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.NegativeBinomialDistribution.fit (x), 'parameter', 'R', ... 'alpha', {0.05}) ***** error ... paramci (prob.NegativeBinomialDistribution.fit (x), ... 'parameter', {'R', 'P', 'param'}) ***** error ... paramci (prob.NegativeBinomialDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'R', 'P', 'param'}) ***** error ... paramci (prob.NegativeBinomialDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.NegativeBinomialDistribution.fit (x), 'alpha', 0.01, ... 'parameter', 'param') ***** error ... paramci (prob.NegativeBinomialDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.NegativeBinomialDistribution.fit (x), 'alpha', 0.01, ... 'NAME', 'value') ***** error ... paramci (prob.NegativeBinomialDistribution.fit (x), 'alpha', 0.01, ... 'parameter', 'R', 'NAME', 'value') ***** error ... plot (prob.NegativeBinomialDistribution, 'Parent') ***** error ... plot (prob.NegativeBinomialDistribution, 'PlotType', 12) ***** error ... plot (prob.NegativeBinomialDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.NegativeBinomialDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.NegativeBinomialDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.NegativeBinomialDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.NegativeBinomialDistribution, 'Discrete', {true}) ***** error ... plot (prob.NegativeBinomialDistribution, 'Parent', 12) ***** error ... plot (prob.NegativeBinomialDistribution, 'Parent', 'hax') ***** error ... plot (prob.NegativeBinomialDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.NegativeBinomialDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.NegativeBinomialDistribution, 2) ***** error ... proflik (prob.NegativeBinomialDistribution.fit (x), 3) ***** error ... proflik (prob.NegativeBinomialDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.NegativeBinomialDistribution.fit (x), {1}) ***** error ... proflik (prob.NegativeBinomialDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.NegativeBinomialDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.NegativeBinomialDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.NegativeBinomialDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.NegativeBinomialDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.NegativeBinomialDistribution.fit (x), 1, 'Display', ['on'; 'on']) ***** error ... proflik (prob.NegativeBinomialDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.NegativeBinomialDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.NegativeBinomialDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.NegativeBinomialDistribution.fit (x), 1, {[1 2 3]}, 'Display', 'on') ***** error ... truncate (prob.NegativeBinomialDistribution) ***** error ... truncate (prob.NegativeBinomialDistribution, 2) ***** error ... truncate (prob.NegativeBinomialDistribution, 4, 2) ***** shared pd pd = prob.NegativeBinomialDistribution (1, 0.5); pd(2) = prob.NegativeBinomialDistribution (1, 0.6); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 103 tests, 103 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/LognormalDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/LognormalDistribution.m ***** demo ## Generate a data set of 5000 random samples from a Lognormal distribution with ## parameters mu = 0 and sigma = 1. Fit a Lognormal distribution to this data and plot ## a PDF of the fitted distribution superimposed on a histogram of the data. rng (42); randg ('state', 42); rande ('state', 42); randp ('state', 42); pd_fixed = makedist ('Lognormal', 'mu', 0, 'sigma', 1) data = random (pd_fixed, 5000, 1); pd_fitted = fitdist (data, 'Lognormal') plot (pd_fitted) msg = 'Fitted Lognormal distribution with mu = %0.2f and sigma = %0.2f'; title (sprintf (msg, pd_fitted.mu, pd_fitted.sigma)) ***** shared pd, t pd = prob.LognormalDistribution; t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0, 0.5, 0.7559, 0.8640, 0.9172, 0.9462], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 0.6705, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4]), [0.6574, 0.7559, 0.8640, 0.9172], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4]), [0, 0, 0.6705, 1], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [0, 0.4310, 0.7762, 1.2883, 2.3201, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.2256, 2.5015, 2.8517, 3.3199, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 0.7762, 1.2883, 2.3201, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.5015, 2.8517, 3.3199, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 1.4536, 1e-4); ***** assert_equal (iqr (t), 0.8989, 1e-4); ***** assert_equal (mean (pd), 1.6487, 1e-4); ***** assert_equal (mean (t), 2.7692, 1e-4); ***** assert_equal (median (pd), 1, 1e-4); ***** assert_equal (median (t), 2.6653, 1e-4); ***** assert_equal (pdf (pd, [0:5]), [0, 0.3989, 0.1569, 0.0727, 0.0382, 0.0219], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 0.9727, 0.4509, 0.2366, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1:4, NaN]), [0, 0.3989, 0.1569, 0.0727, 0.0382, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1:4, NaN]), [0, 0, 0.9727, 0.4509, 0.2366, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 2.1612, 1e-4); ***** assert_equal (std (t), 0.5540, 1e-4); ***** assert_equal (var (pd), 4.6708, 1e-4); ***** assert_equal (var (t), 0.3069, 1e-4); ***** test ## The profile over the first free parameter: 21 grid values, one row of ## OTHER per value, and the likelihood peaking at the fitted estimate. x = [1.2; 0.4; 3.1; 0.7; 2.5; 1.8; 0.3; 4.2; 1.1; 0.9; ... 2.2; 0.6; 1.5; 3.7; 0.8; 2.9; 1.3; 0.5; 2.0; 1.6]; pd = fitdist (x, 'Lognormal'); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 21]); assert_equal (size (other), [21, 1]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); ***** error ... prob.LognormalDistribution (Inf, 1) ***** error ... prob.LognormalDistribution (i, 1) ***** error ... prob.LognormalDistribution ('a', 1) ***** error ... prob.LognormalDistribution ([1, 2], 1) ***** error ... prob.LognormalDistribution (NaN, 1) ***** error ... prob.LognormalDistribution (1, 0) ***** error ... prob.LognormalDistribution (1, -1) ***** error ... prob.LognormalDistribution (1, Inf) ***** error ... prob.LognormalDistribution (1, i) ***** error ... prob.LognormalDistribution (1, 'a') ***** error ... prob.LognormalDistribution (1, [1, 2]) ***** error ... prob.LognormalDistribution (1, NaN) ***** error ... cdf (prob.LognormalDistribution, 2, 'uper') ***** error ... cdf (prob.LognormalDistribution, 2, 3) ***** shared x randn ('seed', 1); x = lognrnd (1, 1, [1, 100]); ***** error ... paramci (prob.LognormalDistribution.fit (x), 'alpha') ***** error ... paramci (prob.LognormalDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.LognormalDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.LognormalDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.LognormalDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.LognormalDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.LognormalDistribution.fit (x), 'parameter', 'mu', 'alpha', {0.05}) ***** error ... paramci (prob.LognormalDistribution.fit (x), 'parameter', {'mu', 'sigma', 'parm'}) ***** error ... paramci (prob.LognormalDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'mu', 'sigma', 'param'}) ***** error ... paramci (prob.LognormalDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.LognormalDistribution.fit (x), 'alpha', 0.01, 'parameter', 'param') ***** error ... paramci (prob.LognormalDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.LognormalDistribution.fit (x), 'alpha', 0.01, 'NAME', 'value') ***** error ... paramci (prob.LognormalDistribution.fit (x), 'alpha', 0.01, 'parameter', 'mu', ... 'NAME', 'value') ***** error ... plot (prob.LognormalDistribution, 'Parent') ***** error ... plot (prob.LognormalDistribution, 'PlotType', 12) ***** error ... plot (prob.LognormalDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.LognormalDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.LognormalDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.LognormalDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.LognormalDistribution, 'Discrete', {true}) ***** error ... plot (prob.LognormalDistribution, 'Parent', 12) ***** error ... plot (prob.LognormalDistribution, 'Parent', 'hax') ***** error ... plot (prob.LognormalDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.LognormalDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.LognormalDistribution, 2) ***** error ... proflik (prob.LognormalDistribution.fit (x), 3) ***** error ... proflik (prob.LognormalDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.LognormalDistribution.fit (x), {1}) ***** error ... proflik (prob.LognormalDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.LognormalDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.LognormalDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.LognormalDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.LognormalDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.LognormalDistribution.fit (x), 1, 'Display', ['on'; 'on']) ***** error ... proflik (prob.LognormalDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.LognormalDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.LognormalDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.LognormalDistribution.fit (x), 1, {[1 2 3 4]}, 'Display', 'on') ***** error ... truncate (prob.LognormalDistribution) ***** error ... truncate (prob.LognormalDistribution, 2) ***** error ... truncate (prob.LognormalDistribution, 4, 2) ***** shared pd pd = prob.LognormalDistribution (1, 1); pd(2) = prob.LognormalDistribution (1, 3); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 96 tests, 96 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/TriangularDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/TriangularDistribution.m ***** demo ## Generate a data set of 5000 random samples from a Triangular distribution ## with parameters A = 0, B = 1, C = 2. Fit a Triangular distribution to ## this data and plot a PDF of the fitted distribution superimposed on a ## histogram of the data. rng (42); randg ('state', 42); rande ('state', 42); randp ('state', 42); pd_fixed = makedist ('Triangular', 'A', 0, 'B', 1, 'C', 2); data = random (pd_fixed, 5000, 1); A = min (data); C = mean (data); B = max (data); [counts, centers] = hist (data, 50); bin_width = centers(2) - centers(1); normalized_counts = counts / (sum (counts) * bin_width); bar (centers, normalized_counts, 1); hold on; x = linspace (A, B, 100); y = (2 * (x - A) / (C - A) .* (x <= C)) + (2 * (B - x) / (B - C) .* (x > C)); plot (x, y, 'r-', 'LineWidth', 2); msg = sprintf ("Fitted Triangular distribution with A = %0.2f, C = %0.2f, B = %0.2f", A, C, B); title (msg); hold off; ***** shared pd, t pd = prob.TriangularDistribution (0, 3, 5); t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0, 0.0667, 0.2667, 0.6000, 0.9000, 1], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 0.5263, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4, NaN]), [0.1500, 0.2667, 0.6, 0.9, NaN], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4, NaN]), [0, 0, 0.5263, 1, NaN], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [0, 1.7321, 2.4495, 3, 3.5858, 5], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.4290, 2.7928, 3.1203, 3.4945, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 2.4495, 3, 3.5858, 5, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.7928, 3.1203, 3.4945, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 1.4824, 1e-4); ***** assert_equal (iqr (t), 0.8678, 1e-4); ***** assert_equal (mean (pd), 2.6667, 1e-4); ***** assert_equal (mean (t), 2.9649, 1e-4); ***** assert_equal (median (pd), 2.7386, 1e-4); ***** assert_equal (median (t), 2.9580, 1e-4); ***** assert_equal (pdf (pd, [0:5]), [0, 0.1333, 0.2667, 0.4, 0.2, 0], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 0.4211, 0.6316, 0.3158, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1.5, NaN]), [0, 0.2, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1.5, NaN]), [0, 0, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 1.0274, 1e-4); ***** assert_equal (std (t), 0.5369, 1e-4); ***** assert_equal (var (pd), 1.0556, 1e-4); ***** assert_equal (var (t), 0.2882, 1e-4); ***** error ... prob.TriangularDistribution (i, 1, 2) ***** error ... prob.TriangularDistribution (Inf, 1, 2) ***** error ... prob.TriangularDistribution ([1, 2], 1, 2) ***** error ... prob.TriangularDistribution ('a', 1, 2) ***** error ... prob.TriangularDistribution (NaN, 1, 2) ***** error ... prob.TriangularDistribution (1, i, 2) ***** error ... prob.TriangularDistribution (1, Inf, 2) ***** error ... prob.TriangularDistribution (1, [1, 2], 2) ***** error ... prob.TriangularDistribution (1, 'a', 2) ***** error ... prob.TriangularDistribution (1, NaN, 2) ***** error ... prob.TriangularDistribution (1, 2, i) ***** error ... prob.TriangularDistribution (1, 2, Inf) ***** error ... prob.TriangularDistribution (1, 2, [1, 2]) ***** error ... prob.TriangularDistribution (1, 2, 'a') ***** error ... prob.TriangularDistribution (1, 2, NaN) ***** error ... prob.TriangularDistribution (1, 1, 1) ***** error ... prob.TriangularDistribution (1, 0.5, 2) ***** error ... cdf (prob.TriangularDistribution, 2, 'uper') ***** error ... cdf (prob.TriangularDistribution, 2, 3) ***** error ... plot (prob.TriangularDistribution, 'Parent') ***** error ... plot (prob.TriangularDistribution, 'PlotType', 12) ***** error ... plot (prob.TriangularDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.TriangularDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.TriangularDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.TriangularDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.TriangularDistribution, 'Discrete', {true}) ***** error ... plot (prob.TriangularDistribution, 'Parent', 12) ***** error ... plot (prob.TriangularDistribution, 'Parent', 'hax') ***** error ... plot (prob.TriangularDistribution, 'invalidNAME', 'pdf') ***** error <'probability' PlotType is not supported for 'Triangular'.> ... plot (prob.TriangularDistribution, 'PlotType', 'probability') ***** error ... truncate (prob.TriangularDistribution) ***** error ... truncate (prob.TriangularDistribution, 2) ***** error ... truncate (prob.TriangularDistribution, 4, 2) ***** shared pd pd = prob.TriangularDistribution (0, 1, 2); pd(2) = prob.TriangularDistribution (0, 1, 2); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 69 tests, 69 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/PiecewiseLinearDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/PiecewiseLinearDistribution.m ***** demo ## Generate a data set of 5000 random samples from a Beta distribution with ## parameters a = 2 and b = 5 scaled to [0,10]. ## Compute empirical CDF, subsample, create prob.PiecewiseLinearDistribution, ## and plot the PDF superimposed on a histogram of the data. rng (42); randg ('state', 42); data = betarnd (2, 5, 5000, 1) * 10; [f, x] = ecdf (data); f = f(1:5:end); x = x(1:5:end); pd = prob.PiecewiseLinearDistribution (x, f); [counts, centers] = hist (data, 50); bin_width = centers(2) - centers(1); bar (centers, counts / (sum (counts) * bin_width), 1); hold on vals = min (data):0.1:max (data); y = pdf (pd, vals); plot (vals, y, '-r', 'LineWidth', 2) hold off title ('Piecewise Linear approximation to scaled Beta(2,5) data') legend ('Histogram', 'Piecewise PDF') ***** shared pd, t load patients [f, x] = ecdf (Weight); f = f(1:5:end); x = x(1:5:end); pd = prob.PiecewiseLinearDistribution (x, f); t = truncate (pd, 130, 180); ***** assert_equal (cdf (pd, [120, 130, 140, 150, 200]), [0.0767, 0.25, 0.4629, 0.5190, 0.9908], 1e-4); ***** assert_equal (cdf (t, [120, 130, 140, 150, 200]), [0, 0, 0.4274, 0.5403, 1], 1e-4); ***** assert_equal (cdf (pd, [100, 250, NaN]), [0, 1, NaN], 1e-4); ***** assert_equal (cdf (t, [115, 290, NaN]), [0, 1, NaN], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [111, 127.5, 136.62, 169.67, 182.17, 202], 1e-2); ***** assert_equal (icdf (t, [0:0.2:1]), [130, 134.15, 139.26, 162.5, 173.99, 180], 1e-2); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NA, 136.62, 169.67, 182.17, 202, NA], 1e-2); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NA, 139.26, 162.5, 173.99, 180, NA], 1e-2); ***** assert_equal (iqr (pd), 50.0833, 1e-4); ***** assert_equal (iqr (t), 36.8077, 1e-4); ***** assert_equal (mean (pd), 153.61, 1e-10); ***** assert_equal (mean (t), 152.30321285140542, 1e-10); ***** assert_equal (median (pd), 142, 1e-10); ***** assert_equal (median (t), 141.9462, 1e-4); ***** assert_equal (pdf (pd, [120, 130, 140, 150, 200]), [0.0133, 0.0240, 0.0186, 0.0024, 0.0004], 6e-3); ***** assert_equal (pdf (t, [120, 130, 140, 150, 200]), [0, 0.0482, 0.0373, 0.0048, 0], 1e-4); ***** assert_equal (pdf (pd, [100, 250, NaN]), [0, 0, NaN], 1e-4); ***** assert_equal (pdf (t, [100, 250, NaN]), [0, 0, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 130), false); ***** assert_equal (any (random (t, 1000, 1) > 180), false); ***** assert_equal (std (pd), 26.5196, 1e-4); ***** assert_equal (std (t), 18.293981947282326, 1e-10); ***** assert_equal (var (pd), 703.2879, 1e-4); ***** assert_equal (var (t), 334.66977548749168, 1e-10); ***** error ... prob.PiecewiseLinearDistribution ([0, i], [0, 1]) ***** error ... prob.PiecewiseLinearDistribution ([0, Inf], [0, 1]) ***** error ... prob.PiecewiseLinearDistribution (['a', 'c'], [0, 1]) ***** error ... prob.PiecewiseLinearDistribution ([NaN, 1], [0, 1]) ***** error ... prob.PiecewiseLinearDistribution ([0, 1], [0, i]) ***** error ... prob.PiecewiseLinearDistribution ([0, 1], [0, Inf]) ***** error ... prob.PiecewiseLinearDistribution ([0, 1], ['a', 'c']) ***** error ... prob.PiecewiseLinearDistribution ([0, 1], [NaN, 1]) ***** error ... prob.PiecewiseLinearDistribution ([0, 1], [0, 0.5, 1]) ***** error ... prob.PiecewiseLinearDistribution ([0], [1]) ***** error ... prob.PiecewiseLinearDistribution ([0, 0.5, 1], [0, 1, 1.5]) ***** error ... cdf (prob.PiecewiseLinearDistribution, 2, 'uper') ***** error ... cdf (prob.PiecewiseLinearDistribution, 2, 3) ***** error ... plot (prob.PiecewiseLinearDistribution, 'Parent') ***** error ... plot (prob.PiecewiseLinearDistribution, 'PlotType', 12) ***** error ... plot (prob.PiecewiseLinearDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.PiecewiseLinearDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.PiecewiseLinearDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.PiecewiseLinearDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.PiecewiseLinearDistribution, 'Discrete', {true}) ***** error ... plot (prob.PiecewiseLinearDistribution, 'Parent', 12) ***** error ... plot (prob.PiecewiseLinearDistribution, 'Parent', 'hax') ***** error ... plot (prob.PiecewiseLinearDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.PiecewiseLinearDistribution, 'PlotType', 'probability') ***** error ... truncate (prob.PiecewiseLinearDistribution) ***** error ... truncate (prob.PiecewiseLinearDistribution, 2) ***** error ... truncate (prob.PiecewiseLinearDistribution, 4, 2) ***** shared pd pd = prob.PiecewiseLinearDistribution (); pd(2) = prob.PiecewiseLinearDistribution (); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) ***** test pd = makedist ('PiecewiseLinear', 'x', [0, 1, 2], 'Fx', [0, 0.5, 1]); assert_equal (iscell (pd.ParameterValues), true); assert_equal (size (pd.ParameterValues), [1, 2]); assert_equal (pd.ParameterValues{1}, [0, 1, 2]); assert_equal (pd.ParameterValues{2}, [0, 0.5, 1]); assert_equal (numel (pd.ParameterValues), pd.NumParameters); assert_equal (size (pd.ParameterValues), size (pd.ParameterNames)); ***** test pd = makedist ('PiecewiseLinear', 'x', [0; 1; 2], 'Fx', [0; 0.5; 1]); assert_equal (size (pd.ParameterValues{1}), [1, 3]); assert_equal (size (pd.ParameterValues{2}), [1, 3]); pd.x = [0; 2; 4]; assert_equal (pd.ParameterValues{1}, [0, 2, 4]); assert_equal (pd.x, [0, 2, 4]); 65 tests, 65 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/NakagamiDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/NakagamiDistribution.m ***** demo ## Generate a data set of 5000 random samples from a Nakagami distribution with ## parameters mu = 1 and omega = 1. Fit a Nakagami distribution to this data and plot ## a PDF of the fitted distribution superimposed on a histogram of the data. rng (42); randg ('state', 42); rande ('state', 42); randp ('state', 42); pd_fixed = makedist ('Nakagami', 'mu', 1, 'omega', 1) data = random (pd_fixed, 5000, 1); pd_fitted = fitdist (data, 'Nakagami') plot (pd_fitted) msg = 'Fitted Nakagami distribution with mu = %0.2f and omega = %0.2f'; title (sprintf (msg, pd_fitted.mu, pd_fitted.omega)) ***** shared pd, t pd = prob.NakagamiDistribution; t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0, 0.6321, 0.9817, 0.9999, 1, 1], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 0.9933, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4]), [0.8946, 0.9817, 0.9999, 1], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4]), [0, 0, 0.9933, 1], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [0, 0.4724, 0.7147, 0.9572, 1.2686, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.0550, 2.1239, 2.2173, 2.3684, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 0.7147, 0.9572, 1.2686, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.1239, 2.2173, 2.3684, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 0.6411, 1e-4); ***** assert_equal (iqr (t), 0.2502, 1e-4); ***** assert_equal (mean (pd), 0.8862, 1e-4); ***** assert_equal (mean (t), 2.2263, 1e-4); ***** assert_equal (median (pd), 0.8326, 1e-4); ***** assert_equal (median (t), 2.1664, 1e-4); ***** assert_equal (pdf (pd, [0:5]), [0, 0.7358, 0.0733, 0.0007, 0, 0], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 4, 0.0404, 0, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1:4, NaN]), [0, 0.7358, 0.0733, 0.0007, 0, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1:4, NaN]), [0, 0, 4, 0.0404, 0, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 0.4633, 1e-4); ***** assert_equal (std (t), 0.2083, 1e-4); ***** assert_equal (var (pd), 0.2146, 1e-4); ***** assert_equal (var (t), 0.0434, 1e-4); ***** test ## The profile over the first free parameter: 21 grid values, one row of ## OTHER per value, and the likelihood peaking at the fitted estimate. x = [1.2; 0.4; 3.1; 0.7; 2.5; 1.8; 0.3; 4.2; 1.1; 0.9; ... 2.2; 0.6; 1.5; 3.7; 0.8; 2.9; 1.3; 0.5; 2.0; 1.6]; pd = fitdist (x, 'Nakagami'); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 21]); assert_equal (size (other), [21, 1]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); ***** error ... prob.NakagamiDistribution (Inf, 1) ***** error ... prob.NakagamiDistribution (i, 1) ***** error ... prob.NakagamiDistribution ('a', 1) ***** error ... prob.NakagamiDistribution ([1, 2], 1) ***** error ... prob.NakagamiDistribution (NaN, 1) ***** error ... prob.NakagamiDistribution (1, 0) ***** error ... prob.NakagamiDistribution (1, -1) ***** error ... prob.NakagamiDistribution (1, Inf) ***** error ... prob.NakagamiDistribution (1, i) ***** error ... prob.NakagamiDistribution (1, 'a') ***** error ... prob.NakagamiDistribution (1, [1, 2]) ***** error ... prob.NakagamiDistribution (1, NaN) ***** error ... cdf (prob.NakagamiDistribution, 2, 'uper') ***** error ... cdf (prob.NakagamiDistribution, 2, 3) ***** shared x x = nakarnd (1, 0.5, [1, 100]); ***** error ... paramci (prob.NakagamiDistribution.fit (x), 'alpha') ***** error ... paramci (prob.NakagamiDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.NakagamiDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.NakagamiDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.NakagamiDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.NakagamiDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.NakagamiDistribution.fit (x), 'parameter', 'mu', 'alpha', {0.05}) ***** error ... paramci (prob.NakagamiDistribution.fit (x), 'parameter', {'mu', 'omega', 'param'}) ***** error ... paramci (prob.NakagamiDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'mu', 'omega', 'param'}) ***** error ... paramci (prob.NakagamiDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.NakagamiDistribution.fit (x), 'alpha', 0.01, 'parameter', 'param') ***** error ... paramci (prob.NakagamiDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.NakagamiDistribution.fit (x), 'alpha', 0.01, 'NAME', 'value') ***** error ... paramci (prob.NakagamiDistribution.fit (x), 'alpha', 0.01, 'parameter', 'mu', ... 'NAME', 'value') ***** error ... plot (prob.NakagamiDistribution, 'Parent') ***** error ... plot (prob.NakagamiDistribution, 'PlotType', 12) ***** error ... plot (prob.NakagamiDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.NakagamiDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.NakagamiDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.NakagamiDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.NakagamiDistribution, 'Discrete', {true}) ***** error ... plot (prob.NakagamiDistribution, 'Parent', 12) ***** error ... plot (prob.NakagamiDistribution, 'Parent', 'hax') ***** error ... plot (prob.NakagamiDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.NakagamiDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.NakagamiDistribution, 2) ***** error ... proflik (prob.NakagamiDistribution.fit (x), 3) ***** error ... proflik (prob.NakagamiDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.NakagamiDistribution.fit (x), {1}) ***** error ... proflik (prob.NakagamiDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.NakagamiDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.NakagamiDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.NakagamiDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.NakagamiDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.NakagamiDistribution.fit (x), 1, 'Display', ['on'; 'on']) ***** error ... proflik (prob.NakagamiDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.NakagamiDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.NakagamiDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.NakagamiDistribution.fit (x), 1, {[1 2 3 4]}, 'Display', 'on') ***** error ... truncate (prob.NakagamiDistribution) ***** error ... truncate (prob.NakagamiDistribution, 2) ***** error ... truncate (prob.NakagamiDistribution, 4, 2) ***** shared pd pd = prob.NakagamiDistribution (1, 0.5); pd(2) = prob.NakagamiDistribution (1, 0.6); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 96 tests, 96 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/LogisticDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/LogisticDistribution.m ***** shared pd, t pd = prob.LogisticDistribution (0, 1); t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0.5, 0.7311, 0.8808, 0.9526, 0.9820, 0.9933], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 0.7091, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4]), [0.8176, 0.8808, 0.9526, 0.9820], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4]), [0, 0, 0.7091, 1], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [-Inf, -1.3863, -0.4055, 0.4055, 1.3863, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.2088, 2.4599, 2.7789, 3.2252, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, -0.4055, 0.4055, 1.3863, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.4599, 2.7789, 3.2252, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 2.1972, 1e-4); ***** assert_equal (iqr (t), 0.8286, 1e-4); ***** assert_equal (mean (pd), 0, 1e-4); ***** assert_equal (mean (t), 2.7193, 1e-4); ***** assert_equal (median (pd), 0); ***** assert_equal (median (t), 2.6085, 1e-4); ***** assert_equal (pdf (pd, [0:5]), [0.25, 0.1966, 0.1050, 0.0452, 0.0177, 0.0066], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 1.0373, 0.4463, 0.1745, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1:4, NaN]), [0.1966, 0.1966, 0.1050, 0.0452, 0.0177, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1:4, NaN]), [0, 0, 1.0373, 0.4463, 0.1745, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 1.8138, 1e-4); ***** assert_equal (std (t), 0.5320, 1e-4); ***** assert_equal (var (pd), 3.2899, 1e-4); ***** assert_equal (var (t), 0.2830, 1e-4); ***** test ## The profile over the first free parameter: 21 grid values, one row of ## OTHER per value, and the likelihood peaking at the fitted estimate. x = [0.3; -1.2; 0.8; 1.5; -0.4; 0.2; -0.9; 1.1; 0.6; -0.3; ... 1.8; -1.5; 0.4; 0.9; -0.7; 1.2; -0.2; 0.5; -1.1; 0.7]; pd = fitdist (x, 'Logistic'); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 21]); assert_equal (size (other), [21, 1]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); ***** error ... prob.LogisticDistribution (Inf, 1) ***** error ... prob.LogisticDistribution (i, 1) ***** error ... prob.LogisticDistribution ('a', 1) ***** error ... prob.LogisticDistribution ([1, 2], 1) ***** error ... prob.LogisticDistribution (NaN, 1) ***** error ... prob.LogisticDistribution (1, 0) ***** error ... prob.LogisticDistribution (1, -1) ***** error ... prob.LogisticDistribution (1, Inf) ***** error ... prob.LogisticDistribution (1, i) ***** error ... prob.LogisticDistribution (1, 'a') ***** error ... prob.LogisticDistribution (1, [1, 2]) ***** error ... prob.LogisticDistribution (1, NaN) ***** error ... cdf (prob.LogisticDistribution, 2, 'uper') ***** error ... cdf (prob.LogisticDistribution, 2, 3) ***** shared x x = logirnd (1, 1, [1, 100]); ***** error ... paramci (prob.LogisticDistribution.fit (x), 'alpha') ***** error ... paramci (prob.LogisticDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.LogisticDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.LogisticDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.LogisticDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.LogisticDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.LogisticDistribution.fit (x), 'parameter', 'mu', 'alpha', {0.05}) ***** error ... paramci (prob.LogisticDistribution.fit (x), 'parameter', {'mu', 'sigma', 'param'}) ***** error ... paramci (prob.LogisticDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'mu', 'sigma', 'param'}) ***** error ... paramci (prob.LogisticDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.LogisticDistribution.fit (x), 'alpha', 0.01, 'parameter', 'param') ***** error ... paramci (prob.LogisticDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.LogisticDistribution.fit (x), 'alpha', 0.01, 'NAME', 'value') ***** error ... paramci (prob.LogisticDistribution.fit (x), 'alpha', 0.01, 'parameter', 'mu', ... 'NAME', 'value') ***** error ... plot (prob.LogisticDistribution, 'Parent') ***** error ... plot (prob.LogisticDistribution, 'PlotType', 12) ***** error ... plot (prob.LogisticDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.LogisticDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.LogisticDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.LogisticDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.LogisticDistribution, 'Discrete', {true}) ***** error ... plot (prob.LogisticDistribution, 'Parent', 12) ***** error ... plot (prob.LogisticDistribution, 'Parent', 'hax') ***** error ... plot (prob.LogisticDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.LogisticDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.LogisticDistribution, 2) ***** error ... proflik (prob.LogisticDistribution.fit (x), 3) ***** error ... proflik (prob.LogisticDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.LogisticDistribution.fit (x), {1}) ***** error ... proflik (prob.LogisticDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.LogisticDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.LogisticDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.LogisticDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.LogisticDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.LogisticDistribution.fit (x), 1, 'Display', ['on'; 'on']) ***** error ... proflik (prob.LogisticDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.LogisticDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.LogisticDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.LogisticDistribution.fit (x), 1, {[1 2 3 4]}, 'Display', 'on') ***** error ... truncate (prob.LogisticDistribution) ***** error ... truncate (prob.LogisticDistribution, 2) ***** error ... truncate (prob.LogisticDistribution, 4, 2) ***** shared pd pd = prob.LogisticDistribution (1, 1); pd(2) = prob.LogisticDistribution (1, 3); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 96 tests, 96 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/BetaDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/BetaDistribution.m ***** demo ## Generate a data set of 5000 random samples from a Beta distribution with ## parameters a = 2 and b = 5. Fit a Beta distribution to this data and plot ## a PDF of the fitted distribution superimposed on a histogram of the data. rng (42); randg ('state', 42); rande ('state', 42); randp ('state', 42); pd_fixed = makedist ('Beta', 'a', 2, 'b', 5) data = random (pd_fixed, 5000, 1); pd_fitted = fitdist (data, 'Beta') plot (pd_fitted) msg = 'Fitted Beta distribution with a = %0.2f and b = %0.2f'; title (sprintf (msg, pd_fitted.a, pd_fitted.b)) ***** shared pd, t pd = prob.BetaDistribution; t = truncate (pd, 0.2, 0.8); ***** assert_equal (cdf (pd, [0:0.2:1]), [0, 0.2, 0.4, 0.6, 0.8, 1], 1e-4); ***** assert_equal (cdf (t, [0:0.2:1]), [0, 0, 0.3333, 0.6667, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [-1, 1, NaN]), [0, 1, NaN], 1e-4); ***** assert_equal (cdf (t, [-1, 1, NaN]), [0, 1, NaN], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [0, 0.2, 0.4, 0.6, 0.8, 1], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [0.2, 0.32, 0.44, 0.56, 0.68, 0.8], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 0.4, 0.6, 0.8, 1, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 0.44, 0.56, 0.68, 0.8, NaN], 1e-4); ***** assert_equal (iqr (pd), 0.5, 1e-4); ***** assert_equal (iqr (t), 0.3, 1e-4); ***** assert_equal (mean (pd), 0.5); ***** assert_equal (mean (t), 0.5, 1e-6); ***** assert_equal (median (pd), 0.5); ***** assert_equal (median (t), 0.5, 1e-6); ***** assert_equal (pdf (pd, [0:0.2:1]), [1, 1, 1, 1, 1, 1], 1e-4); ***** assert_equal (pdf (t, [0:0.2:1]), [0, 1.6667, 1.6667, 1.6667, 1.6667, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1, NaN]), [0, 1, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1, NaN]), [0, 0, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 0.2), false); ***** assert_equal (any (random (t, 1000, 1) > 0.8), false); ***** assert_equal (std (pd), 0.2887, 1e-4); ***** assert_equal (std (t), 0.1732, 1e-4); ***** assert_equal (var (pd), 0.0833, 1e-4); ***** assert_equal (var (t), 0.0300, 1e-4); ***** test ## The profile over the first free parameter: 21 grid values, one row of ## OTHER per value, and the likelihood peaking at the fitted estimate. x = [0.2; 0.5; 0.7; 0.3; 0.8; 0.4; 0.6; 0.55; 0.25; 0.75; ... 0.35; 0.65; 0.45; 0.15; 0.85; 0.5; 0.6; 0.3; 0.7; 0.4]; pd = fitdist (x, 'Beta'); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 21]); assert_equal (size (other), [21, 1]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); ***** error ... prob.BetaDistribution (0, 1) ***** error ... prob.BetaDistribution (Inf, 1) ***** error ... prob.BetaDistribution (i, 1) ***** error ... prob.BetaDistribution ('a', 1) ***** error ... prob.BetaDistribution ([1, 2], 1) ***** error ... prob.BetaDistribution (NaN, 1) ***** error ... prob.BetaDistribution (1, 0) ***** error ... prob.BetaDistribution (1, -1) ***** error ... prob.BetaDistribution (1, Inf) ***** error ... prob.BetaDistribution (1, i) ***** error ... prob.BetaDistribution (1, 'a') ***** error ... prob.BetaDistribution (1, [1, 2]) ***** error ... prob.BetaDistribution (1, NaN) ***** error ... cdf (prob.BetaDistribution, 2, 'uper') ***** error ... cdf (prob.BetaDistribution, 2, 3) ***** shared x randg ('seed', 1); x = betarnd (1, 1, [100, 1]); ***** error ... paramci (prob.BetaDistribution.fit (x), 'alpha') ***** error ... paramci (prob.BetaDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.BetaDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.BetaDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.BetaDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.BetaDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.BetaDistribution.fit (x), 'parameter', 'a', 'alpha', {0.05}) ***** error ... paramci (prob.BetaDistribution.fit (x), 'parameter', {'a', 'b', 'param'}) ***** error ... paramci (prob.BetaDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'a', 'b', 'param'}) ***** error ... paramci (prob.BetaDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.BetaDistribution.fit (x), 'alpha', 0.01, 'parameter', 'param') ***** error ... paramci (prob.BetaDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.BetaDistribution.fit (x), 'alpha', 0.01, 'NAME', 'value') ***** error ... paramci (prob.BetaDistribution.fit (x), 'alpha', 0.01, 'parameter', 'a', ... 'NAME', 'value') ***** error ... plot (prob.BetaDistribution, 'Parent') ***** error ... plot (prob.BetaDistribution, 'PlotType', 12) ***** error ... plot (prob.BetaDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.BetaDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.BetaDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.BetaDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.BetaDistribution, 'Discrete', {true}) ***** error ... plot (prob.BetaDistribution, 'Parent', 12) ***** error ... plot (prob.BetaDistribution, 'Parent', 'hax') ***** error ... plot (prob.BetaDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.BetaDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.BetaDistribution, 2) ***** error ... proflik (prob.BetaDistribution.fit (x), 3) ***** error ... proflik (prob.BetaDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.BetaDistribution.fit (x), {1}) ***** error ... proflik (prob.BetaDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.BetaDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.BetaDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.BetaDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.BetaDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.BetaDistribution.fit (x), 1, 'Display', ['on'; 'on']) ***** error ... proflik (prob.BetaDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.BetaDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.BetaDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.BetaDistribution.fit (x), 1, {[1 2 3 4]}, 'Display', 'on') ***** error ... truncate (prob.BetaDistribution) ***** error ... truncate (prob.BetaDistribution, 2) ***** error ... truncate (prob.BetaDistribution, 4, 2) ***** shared pd pd = prob.BetaDistribution (1, 1); pd(2) = prob.BetaDistribution (1, 3); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 97 tests, 97 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/LoglogisticDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/LoglogisticDistribution.m ***** demo ## Generate a data set of 5000 random samples from a Log-logistic ## distribution with parameters mu = 0 and sigma = 1. Fit a Log-logistic ## distribution to this data and plot a PDF of the fitted distribution ## superimposed on a histogram of the data. rng (42); randg ('state', 42); rande ('state', 42); randp ('state', 42); pd_fixed = makedist ('Loglogistic', 'mu', 0, 'sigma', 1) data = random (pd_fixed, 5000, 1); pd_fitted = fitdist (data, 'Loglogistic') plot (pd_fitted) msg = 'Fitted Log-logistic distribution with mu = %0.2f and sigma = %0.2f'; title (sprintf (msg, pd_fitted.mu, pd_fitted.sigma)) ***** shared pd, t pd = prob.LoglogisticDistribution; t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0, 0.5, 0.6667, 0.75, 0.8, 0.8333], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 0.625, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4]), [0.6, 0.6667, 0.75, 0.8], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4]), [0, 0, 0.625, 1], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [0, 0.25, 0.6667, 1.5, 4, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.2609, 2.5714, 2.9474, 3.4118, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 0.6667, 1.5, 4, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.5714, 2.9474, 3.4118, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 2.6667, 1e-4); ***** assert_equal (iqr (t), 0.9524, 1e-4); ***** assert_equal (mean (pd), Inf); ***** assert_equal (mean (t), 2.8312, 1e-4); ***** assert_equal (median (pd), 1, 1e-4); ***** assert_equal (median (t), 2.75, 1e-4); ***** assert_equal (pdf (pd, [0:5]), [0, 0.25, 0.1111, 0.0625, 0.04, 0.0278], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 0.8333, 0.4687, 0.3, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1:4, NaN]), [0, 0.25, 0.1111, 0.0625, 0.04, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1:4, NaN]), [0, 0, 0.8333, 0.4687, 0.3, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), Inf); ***** assert_equal (std (t), 0.5674, 1e-4); ***** assert_equal (var (pd), Inf); ***** assert_equal (var (t), 0.3220, 1e-4); ***** test ## The profile over the first free parameter: 21 grid values, one row of ## OTHER per value, and the likelihood peaking at the fitted estimate. x = [1.2; 0.4; 3.1; 0.7; 2.5; 1.8; 0.3; 4.2; 1.1; 0.9; ... 2.2; 0.6; 1.5; 3.7; 0.8; 2.9; 1.3; 0.5; 2.0; 1.6]; pd = fitdist (x, 'Loglogistic'); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 21]); assert_equal (size (other), [21, 1]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); ***** error ... prob.LoglogisticDistribution (Inf, 1) ***** error ... prob.LoglogisticDistribution (i, 1) ***** error ... prob.LoglogisticDistribution ('a', 1) ***** error ... prob.LoglogisticDistribution ([1, 2], 1) ***** error ... prob.LoglogisticDistribution (NaN, 1) ***** error ... prob.LoglogisticDistribution (1, 0) ***** error ... prob.LoglogisticDistribution (1, -1) ***** error ... prob.LoglogisticDistribution (1, Inf) ***** error ... prob.LoglogisticDistribution (1, i) ***** error ... prob.LoglogisticDistribution (1, 'a') ***** error ... prob.LoglogisticDistribution (1, [1, 2]) ***** error ... prob.LoglogisticDistribution (1, NaN) ***** error ... cdf (prob.LoglogisticDistribution, 2, 'uper') ***** error ... cdf (prob.LoglogisticDistribution, 2, 3) ***** shared x x = loglrnd (1, 1, [1, 100]); ***** error ... paramci (prob.LoglogisticDistribution.fit (x), 'alpha') ***** error ... paramci (prob.LoglogisticDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.LoglogisticDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.LoglogisticDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.LoglogisticDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.LoglogisticDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.LoglogisticDistribution.fit (x), 'parameter', 'mu', 'alpha', {0.05}) ***** error ... paramci (prob.LoglogisticDistribution.fit (x), 'parameter', {'mu', 'sigma', 'pa'}) ***** error ... paramci (prob.LoglogisticDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'mu', 'sigma', 'param'}) ***** error ... paramci (prob.LoglogisticDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.LoglogisticDistribution.fit (x), 'alpha', 0.01, 'parameter', 'parm') ***** error ... paramci (prob.LoglogisticDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.LoglogisticDistribution.fit (x), 'alpha', 0.01, 'NAME', 'value') ***** error ... paramci (prob.LoglogisticDistribution.fit (x), 'alpha', 0.01, ... 'parameter', 'mu', 'NAME', 'value') ***** error ... plot (prob.LoglogisticDistribution, 'Parent') ***** error ... plot (prob.LoglogisticDistribution, 'PlotType', 12) ***** error ... plot (prob.LoglogisticDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.LoglogisticDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.LoglogisticDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.LoglogisticDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.LoglogisticDistribution, 'Discrete', {true}) ***** error ... plot (prob.LoglogisticDistribution, 'Parent', 12) ***** error ... plot (prob.LoglogisticDistribution, 'Parent', 'hax') ***** error ... plot (prob.LoglogisticDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.LoglogisticDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.LoglogisticDistribution, 2) ***** error ... proflik (prob.LoglogisticDistribution.fit (x), 3) ***** error ... proflik (prob.LoglogisticDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.LoglogisticDistribution.fit (x), {1}) ***** error ... proflik (prob.LoglogisticDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.LoglogisticDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.LoglogisticDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.LoglogisticDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.LoglogisticDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.LoglogisticDistribution.fit (x), 1, 'Display', ['on'; 'on']) ***** error ... proflik (prob.LoglogisticDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.LoglogisticDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.LoglogisticDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.LoglogisticDistribution.fit (x), 1, {[1 2 3 4]}, 'Display', 'on') ***** error ... truncate (prob.LoglogisticDistribution) ***** error ... truncate (prob.LoglogisticDistribution, 2) ***** error ... truncate (prob.LoglogisticDistribution, 4, 2) ***** shared pd pd = prob.LoglogisticDistribution (1, 1); pd(2) = prob.LoglogisticDistribution (1, 3); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 96 tests, 96 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/RicianDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/RicianDistribution.m ***** demo ## Generate a data set of 5000 random samples from a Rician distribution with ## parameters s = 2 and sigma = 1. Fit a Rician distribution to this data and ## plot a PDF of the fitted distribution superimposed on a histogram of the data. rng (42); randg ('state', 42); rande ('state', 42); randp ('state', 42); pd_fixed = makedist ('Rician', 's', 2, 'sigma', 1) data = random (pd_fixed, 5000, 1); pd_fitted = fitdist (data, 'Rician') plot (pd_fitted) msg = 'Fitted Rician distribution with s = %0.2f and sigma = %0.2f'; title (sprintf (msg, pd_fitted.s, pd_fitted.sigma)) ***** shared pd, t pd = prob.RicianDistribution; t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0, 0.2671, 0.7310, 0.9563, 0.9971, 0.9999], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 0.8466, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4, NaN]), [0.5120, 0.7310, 0.9563, 0.9971, NaN], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4, NaN]), [0, 0, 0.8466, 1, NaN], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [0, 0.8501, 1.2736, 1.6863, 2.2011, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.1517, 2.3296, 2.5545, 2.8868, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 1.2736, 1.6863, 2.2011, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.3296, 2.5545, 2.8868, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 1.0890, 1e-4); ***** assert_equal (iqr (t), 0.5928, 1e-4); ***** assert_equal (mean (pd), 1.5486, 1e-4); ***** assert_equal (mean (t), 2.5380, 1e-4); ***** assert_equal (median (pd), 1.4755, 1e-4); ***** assert_equal (median (t), 2.4341, 1e-4); ***** assert_equal (pdf (pd, [0:5]), [0, 0.4658, 0.3742, 0.0987, 0.0092, 0.0003], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 1.4063, 0.3707, 0.0346, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1.5, NaN]), [0, 0.4864, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1.5, NaN]), [0, 0, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 0.7758, 1e-4); ***** assert_equal (std (t), 0.4294, 1e-4); ***** assert_equal (var (pd), 0.6019, 1e-4); ***** assert_equal (var (t), 0.1844, 1e-4); ***** test ## The profile over the first free parameter: 21 grid values, one row of ## OTHER per value, and the likelihood peaking at the fitted estimate. The ## sample is Rician: fitting arbitrary positive data drives s to its own ## boundary, and the confidence interval it profiles over degenerates. x = [0.584700; 0.962174; 1.201400; 1.388590; 1.548120; 1.690860; ... 1.822800; 1.947740; 2.068370; 2.186810; 2.304930; 2.424520; ... 2.547550; 2.676370; 2.814120; 2.965420; 3.137930; 3.346330; ... 3.626640; 4.133390]; pd = fitdist (x, 'Rician'); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 21]); assert_equal (size (other), [21, 1]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); ***** error ... prob.RicianDistribution (-eps, 1) ***** error ... prob.RicianDistribution (-1, 1) ***** error ... prob.RicianDistribution (Inf, 1) ***** error ... prob.RicianDistribution (i, 1) ***** error ... prob.RicianDistribution ('a', 1) ***** error ... prob.RicianDistribution ([1, 2], 1) ***** error ... prob.RicianDistribution (NaN, 1) ***** error ... prob.RicianDistribution (1, 0) ***** error ... prob.RicianDistribution (1, -1) ***** error ... prob.RicianDistribution (1, Inf) ***** error ... prob.RicianDistribution (1, i) ***** error ... prob.RicianDistribution (1, 'a') ***** error ... prob.RicianDistribution (1, [1, 2]) ***** error ... prob.RicianDistribution (1, NaN) ***** error ... cdf (prob.RicianDistribution, 2, 'uper') ***** error ... cdf (prob.RicianDistribution, 2, 3) ***** shared x x = gevrnd (1, 1, 1, [1, 100]); ***** error ... paramci (prob.RicianDistribution.fit (x), 'alpha') ***** error ... paramci (prob.RicianDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.RicianDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.RicianDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.RicianDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.RicianDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.RicianDistribution.fit (x), 'parameter', 's', 'alpha', {0.05}) ***** error ... paramci (prob.RicianDistribution.fit (x), 'parameter', {'s', 'sigma', 'param'}) ***** error ... paramci (prob.RicianDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'s', 'sigma', 'param'}) ***** error ... paramci (prob.RicianDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.RicianDistribution.fit (x), 'alpha', 0.01, 'parameter', 'param') ***** error ... paramci (prob.RicianDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.RicianDistribution.fit (x), 'alpha', 0.01, 'NAME', 'value') ***** error ... paramci (prob.RicianDistribution.fit (x), 'alpha', 0.01, 'parameter', 's', ... 'NAME', 'value') ***** error ... plot (prob.RicianDistribution, 'Parent') ***** error ... plot (prob.RicianDistribution, 'PlotType', 12) ***** error ... plot (prob.RicianDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.RicianDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.RicianDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.RicianDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.RicianDistribution, 'Discrete', {true}) ***** error ... plot (prob.RicianDistribution, 'Parent', 12) ***** error ... plot (prob.RicianDistribution, 'Parent', 'hax') ***** error ... plot (prob.RicianDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.RicianDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.RicianDistribution, 2) ***** error ... proflik (prob.RicianDistribution.fit (x), 3) ***** error ... proflik (prob.RicianDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.RicianDistribution.fit (x), {1}) ***** error ... proflik (prob.RicianDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.RicianDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.RicianDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.RicianDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.RicianDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.RicianDistribution.fit (x), 1, 'Display', ['on'; 'on']) ***** error ... proflik (prob.RicianDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.RicianDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.RicianDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.RicianDistribution.fit (x), 1, {[1 2 3 4]}, 'Display', 'on') ***** error ... truncate (prob.RicianDistribution) ***** error ... truncate (prob.RicianDistribution, 2) ***** error ... truncate (prob.RicianDistribution, 4, 2) ***** shared pd pd = prob.RicianDistribution (1, 1); pd(2) = prob.RicianDistribution (1, 3); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 98 tests, 98 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/PoissonDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/PoissonDistribution.m ***** demo ## Generate a data set of 5000 random samples from a Poisson distribution with ## parameter lambda = 5. Fit a Poisson distribution to this data and plot ## a PDF of the fitted distribution superimposed on a histogram of the data. rng (42); randg ('state', 42); rande ('state', 42); randp ('state', 42); pd_fixed = makedist ('Poisson', 'lambda', 5) data = random (pd_fixed, 5000, 1); pd_fitted = fitdist (data, 'Poisson') plot (pd_fitted) msg = 'Fitted Poisson distribution with lambda = %0.2f'; title (sprintf (msg, pd_fitted.lambda)) ***** shared pd, t, t_inf pd = prob.PoissonDistribution; t = truncate (pd, 2, 4); t_inf = truncate (pd, 2, Inf); ***** assert_equal (cdf (pd, [0:5]), [0.3679, 0.7358, 0.9197, 0.9810, 0.9963, 0.9994], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0.7059, 0.9412, 1, 1], 1e-4); ***** assert_equal (cdf (t_inf, [0:5]), [0, 0, 0.6961, 0.9281, 0.9861, 0.9978], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4]), [0.7358, 0.9197, 0.9810, 0.9963], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4]), [0, 0.7059, 0.9412, 1], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [0, 0, 1, 1, 2, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2, 2, 2, 3, 4], 1e-4); ***** assert_equal (icdf (t_inf, [0:0.2:1]), [2, 2, 2, 2, 3, Inf], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 1, 1, 2, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2, 2, 3, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 2); ***** assert_equal (iqr (t), 1); ***** assert_equal (mean (pd), 1); ***** assert_equal (mean (t), 2.3529, 1e-4); ***** assert_equal (mean (t_inf), 2.3922, 1e-4); ***** assert_equal (median (pd), 1); ***** assert_equal (median (t), 2); ***** assert_equal (median (t_inf), 2); ***** assert_equal (pdf (pd, [0:5]), [0.3679, 0.3679, 0.1839, 0.0613, 0.0153, 0.0031], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 0.7059, 0.2353, 0.0588, 0], 1e-4); ***** assert_equal (pdf (t_inf, [0:5]), [0, 0, 0.6961, 0.2320, 0.0580, 0.0116], 1e-4); ***** assert_equal (pdf (pd, [-1, 1:4, NaN]), [0, 0.3679, 0.1839, 0.0613, 0.0153, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1:4, NaN]), [0, 0, 0.7059, 0.2353, 0.0588, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 1); ***** assert_equal (std (t), 0.5882, 1e-4); ***** assert_equal (std (t_inf), 0.6738, 1e-4); ***** assert_equal (var (pd), 1); ***** assert_equal (var (t), 0.3460, 1e-4); ***** assert_equal (var (t_inf), 0.4540, 1e-4); ***** test ## The profile over the first free parameter: 101 grid values, one row of ## OTHER per value, and the likelihood peaking at the fitted estimate. x = [3; 1; 4; 1; 5; 2; 6; 5; 3; 5; 2; 4; 1; 3; 2; 4; 6; 2; 3; 1]; pd = fitdist (x, 'Poisson'); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 101]); assert_equal (size (other), [101, 0]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); ***** error ... prob.PoissonDistribution (0) ***** error ... prob.PoissonDistribution (-1) ***** error ... prob.PoissonDistribution (Inf) ***** error ... prob.PoissonDistribution (i) ***** error ... prob.PoissonDistribution ('a') ***** error ... prob.PoissonDistribution ([1, 2]) ***** error ... prob.PoissonDistribution (NaN) ***** error ... cdf (prob.PoissonDistribution, 2, 'uper') ***** error ... cdf (prob.PoissonDistribution, 2, 3) ***** shared x x = poissrnd (1, [1, 100]); ***** error ... paramci (prob.PoissonDistribution.fit (x), 'alpha') ***** error ... paramci (prob.PoissonDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.PoissonDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.PoissonDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.PoissonDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.PoissonDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.PoissonDistribution.fit (x), 'parameter', 'lambda', 'alpha', {0.05}) ***** error ... paramci (prob.PoissonDistribution.fit (x), 'parameter', {'lambda', 'param'}) ***** error ... paramci (prob.PoissonDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'lambda', 'param'}) ***** error ... paramci (prob.PoissonDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.PoissonDistribution.fit (x), 'alpha', 0.01, 'parameter', 'param') ***** error ... paramci (prob.PoissonDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.PoissonDistribution.fit (x), 'alpha', 0.01, 'NAME', 'value') ***** error ... paramci (prob.PoissonDistribution.fit (x), 'alpha', 0.01, ... 'parameter', 'lambda', 'NAME', 'value') ***** error ... plot (prob.PoissonDistribution, 'Parent') ***** error ... plot (prob.PoissonDistribution, 'PlotType', 12) ***** error ... plot (prob.PoissonDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.PoissonDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.PoissonDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.PoissonDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.PoissonDistribution, 'Discrete', {true}) ***** error ... plot (prob.PoissonDistribution, 'Parent', 12) ***** error ... plot (prob.PoissonDistribution, 'Parent', 'hax') ***** error ... plot (prob.PoissonDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.PoissonDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.PoissonDistribution, 2) ***** error ... proflik (prob.PoissonDistribution.fit (x), 3) ***** error ... proflik (prob.PoissonDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.PoissonDistribution.fit (x), {1}) ***** error ... proflik (prob.PoissonDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.PoissonDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.PoissonDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.PoissonDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.PoissonDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.PoissonDistribution.fit (x), 1, 'Display', ['on'; 'on']) ***** error ... proflik (prob.PoissonDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.PoissonDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.PoissonDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.PoissonDistribution.fit (x), 1, {[1 2 3 4]}, 'Display', 'on') ***** error ... truncate (prob.PoissonDistribution) ***** error ... truncate (prob.PoissonDistribution, 2) ***** error ... truncate (prob.PoissonDistribution, 4, 2) ***** shared pd pd = prob.PoissonDistribution (1); pd(2) = prob.PoissonDistribution (3); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 98 tests, 98 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/InverseGaussianDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/InverseGaussianDistribution.m ***** shared pd, t pd = prob.InverseGaussianDistribution (1, 1); t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0, 0.6681, 0.8855, 0.9532, 0.9791, 0.9901], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 0.7234, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4]), [0.8108, 0.8855, 0.9532, 0.9791], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4]), [0, 0, 0.7234, 1], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [0, 0.3320, 0.5411, 0.8483, 1.4479, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.1889, 2.4264, 2.7417, 3.1993, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 0.5411, 0.8483, 1.4479, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.4264, 2.7417, 3.1993, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 0.8643, 1e-4); ***** assert_equal (iqr (t), 0.8222, 1e-4); ***** assert_equal (mean (pd), 1); ***** assert_equal (mean (t), 2.6953, 1e-4); ***** assert_equal (median (pd), 0.6758, 1e-4); ***** assert_equal (median (t), 2.5716, 1e-4); ***** assert_equal (pdf (pd, [0:5]), [0, 0.3989, 0.1098, 0.0394, 0.0162, 0.0072], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 1.1736, 0.4211, 0.1730, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1:4, NaN]), [0, 0.3989, 0.1098, 0.0394, 0.0162, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1:4, NaN]), [0, 0, 1.1736, 0.4211, 0.1730, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 1); ***** assert_equal (std (t), 0.5332, 1e-4); ***** assert_equal (var (pd), 1); ***** assert_equal (var (t), 0.2843, 1e-4); ***** test ## The profile over the first free parameter: 21 grid values, one row of ## OTHER per value, and the likelihood peaking at the fitted estimate. x = [1.2; 0.4; 3.1; 0.7; 2.5; 1.8; 0.3; 4.2; 1.1; 0.9; ... 2.2; 0.6; 1.5; 3.7; 0.8; 2.9; 1.3; 0.5; 2.0; 1.6]; pd = fitdist (x, 'InverseGaussian'); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 21]); assert_equal (size (other), [21, 1]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); ***** error ... prob.InverseGaussianDistribution (0, 1) ***** error ... prob.InverseGaussianDistribution (Inf, 1) ***** error ... prob.InverseGaussianDistribution (i, 1) ***** error ... prob.InverseGaussianDistribution ('a', 1) ***** error ... prob.InverseGaussianDistribution ([1, 2], 1) ***** error ... prob.InverseGaussianDistribution (NaN, 1) ***** error ... prob.InverseGaussianDistribution (1, 0) ***** error ... prob.InverseGaussianDistribution (1, -1) ***** error ... prob.InverseGaussianDistribution (1, Inf) ***** error ... prob.InverseGaussianDistribution (1, i) ***** error ... prob.InverseGaussianDistribution (1, 'a') ***** error ... prob.InverseGaussianDistribution (1, [1, 2]) ***** error ... prob.InverseGaussianDistribution (1, NaN) ***** error ... cdf (prob.InverseGaussianDistribution, 2, 'uper') ***** error ... cdf (prob.InverseGaussianDistribution, 2, 3) ***** shared x x = invgrnd (1, 1, [1, 100]); ***** error ... paramci (prob.InverseGaussianDistribution.fit (x), 'alpha') ***** error ... paramci (prob.InverseGaussianDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.InverseGaussianDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.InverseGaussianDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.InverseGaussianDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.InverseGaussianDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.InverseGaussianDistribution.fit (x), 'parameter', 'mu', ... 'alpha', {0.05}) ***** error ... paramci (prob.InverseGaussianDistribution.fit (x), ... 'parameter', {'mu', 'lambda', 'param'}) ***** error ... paramci (prob.InverseGaussianDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'mu', 'lambda', 'param'}) ***** error ... paramci (prob.InverseGaussianDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.InverseGaussianDistribution.fit (x), 'alpha', 0.01, ... 'parameter', 'param') ***** error ... paramci (prob.InverseGaussianDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.InverseGaussianDistribution.fit (x), 'alpha', 0.01, 'NAME', 'value') ***** error ... paramci (prob.InverseGaussianDistribution.fit (x), 'alpha', 0.01, ... 'parameter', 'mu', 'NAME', 'value') ***** error ... plot (prob.InverseGaussianDistribution, 'Parent') ***** error ... plot (prob.InverseGaussianDistribution, 'PlotType', 12) ***** error ... plot (prob.InverseGaussianDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.InverseGaussianDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.InverseGaussianDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.InverseGaussianDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.InverseGaussianDistribution, 'Discrete', {true}) ***** error ... plot (prob.InverseGaussianDistribution, 'Parent', 12) ***** error ... plot (prob.InverseGaussianDistribution, 'Parent', 'hax') ***** error ... plot (prob.InverseGaussianDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.InverseGaussianDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.InverseGaussianDistribution, 2) ***** error ... proflik (prob.InverseGaussianDistribution.fit (x), 3) ***** error ... proflik (prob.InverseGaussianDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.InverseGaussianDistribution.fit (x), {1}) ***** error ... proflik (prob.InverseGaussianDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.InverseGaussianDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.InverseGaussianDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.InverseGaussianDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.InverseGaussianDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.InverseGaussianDistribution.fit (x), 1, 'Display', ['on'; 'on']) ***** error ... proflik (prob.InverseGaussianDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.InverseGaussianDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.InverseGaussianDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.InverseGaussianDistribution.fit (x), 1, {[1 2 3]}, 'Display', 'on') ***** error ... truncate (prob.InverseGaussianDistribution) ***** error ... truncate (prob.InverseGaussianDistribution, 2) ***** error ... truncate (prob.InverseGaussianDistribution, 4, 2) ***** shared pd pd = prob.InverseGaussianDistribution (1, 1); pd(2) = prob.InverseGaussianDistribution (1, 3); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 97 tests, 97 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/BurrDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/BurrDistribution.m ***** demo ## Generate a data set of 5000 random samples from a Burr type XII ## distribution with parameters alpha = 1, c = 2, and k = 1. Fit a Burr type ## XII distribution to this data and plot a PDF of the fitted distribution ## superimposed on a histogram of the data rng (42); randg ('state', 42); rande ('state', 42); randp ('state', 42); pd = makedist ('Burr', 'alpha', 1, 'c', 2, 'k', 1) data = random (pd, 5000, 1); pd = fitdist (data, 'Burr') plot (pd) msg = strcat ("Fitted Burr type XII distribution with", ... " alpha = %0.2f, c = %0.2f, and k = %0.2f"); title (sprintf (msg, pd.alpha, pd.c, pd.k)) ***** shared pd, t pd = prob.BurrDistribution; t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0, 0.5, 0.6667, 0.75, 0.8, 0.8333], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 0.625, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4]), [0.6, 0.6667, 0.75, 0.8], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4]), [0, 0, 0.625, 1], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [0, 0.25, 0.6667, 1.5, 4, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.2609, 2.5714, 2.9474, 3.4118, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 0.6667, 1.5, 4, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.5714, 2.9474, 3.4118, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 2.6667, 1e-4); ***** assert_equal (iqr (t), 0.9524, 1e-4); ***** assert_equal (mean (pd), Inf); ***** assert_equal (mean (t), 2.8312, 1e-4); ***** assert_equal (median (pd), 1, 1e-4); ***** assert_equal (median (t), 2.75, 1e-4); ***** assert_equal (pdf (pd, [0:5]), [1, 0.25, 0.1111, 0.0625, 0.04, 0.0278], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 0.8333, 0.4687, 0.3, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1:4, NaN]), [0, 0.25, 0.1111, 0.0625, 0.04, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1:4, NaN]), [0, 0, 0.8333, 0.4687, 0.3, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), Inf); ***** assert_equal (std (t), 0.5674, 1e-4); ***** assert_equal (var (pd), Inf); ***** assert_equal (var (t), 0.3220, 1e-4); ***** test ## The profile over the first free parameter: 21 grid values, one row of ## OTHER per value, and the likelihood peaking at the fitted estimate. The ## sample is Burr, drawn from burrinv at fixed quantiles. x = [0.160128; 0.284747; 0.377964; 0.460566; 0.538816; 0.615882; ... 0.693889; 0.774597; 0.859727; 0.951190; 1.051310; 1.163160; ... 1.290990; 1.441150; 1.623690; 1.855920; 2.171240; 2.645750; ... 3.511880; 6.245000]; pd = fitdist (x, 'Burr'); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 21]); assert_equal (size (other), [21, 2]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); ***** test ## The profiled-out parameters are passed to burrlike as frequencies, not as ## censoring: reading them as censoring marks every observation censored and ## the profile runs away as the second shape parameter goes to zero. x = [0.160128; 0.284747; 0.377964; 0.460566; 0.538816; 0.615882; ... 0.693889; 0.774597; 0.859727; 0.951190; 1.051310; 1.163160; ... 1.290990; 1.441150; 1.623690; 1.855920; 2.171240; 2.645750; ... 3.511880; 6.245000]; pd = fitdist (x, 'Burr'); [nlogL, param, other] = proflik (pd, 1); assert_equal (max (nlogL) <= -burrlike (pd.ParameterValues, x), true); [~, imax] = max (nlogL); assert_equal (-burrlike ([param(imax), other(imax,:)], x), nlogL(imax), 1e-6); ***** error ... prob.BurrDistribution (0, 1, 1) ***** error ... prob.BurrDistribution (-1, 1, 1) ***** error ... prob.BurrDistribution (Inf, 1, 1) ***** error ... prob.BurrDistribution (i, 1, 1) ***** error ... prob.BurrDistribution ('a', 1, 1) ***** error ... prob.BurrDistribution ([1, 2], 1, 1) ***** error ... prob.BurrDistribution (NaN, 1, 1) ***** error ... prob.BurrDistribution (1, 0, 1) ***** error ... prob.BurrDistribution (1, -1, 1) ***** error ... prob.BurrDistribution (1, Inf, 1) ***** error ... prob.BurrDistribution (1, i, 1) ***** error ... prob.BurrDistribution (1, 'a', 1) ***** error ... prob.BurrDistribution (1, [1, 2], 1) ***** error ... prob.BurrDistribution (1, NaN, 1) ***** error ... prob.BurrDistribution (1, 1, 0) ***** error ... prob.BurrDistribution (1, 1, -1) ***** error ... prob.BurrDistribution (1, 1, Inf) ***** error ... prob.BurrDistribution (1, 1, i) ***** error ... prob.BurrDistribution (1, 1, 'a') ***** error ... prob.BurrDistribution (1, 1, [1, 2]) ***** error ... prob.BurrDistribution (1, 1, NaN) ***** error ... cdf (prob.BurrDistribution, 2, 'uper') ***** error ... cdf (prob.BurrDistribution, 2, 3) ***** shared x rand ('seed', 4); x = burrrnd (1, 1, 1, [1, 100]); ***** error ... paramci (prob.BurrDistribution.fit (x), 'alpha') ***** error ... paramci (prob.BurrDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.BurrDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.BurrDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.BurrDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.BurrDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.BurrDistribution.fit (x), 'parameter', 'c', 'alpha', {0.05}) ***** error ... paramci (prob.BurrDistribution.fit (x), 'parameter', {'alpha', 'c', 'k', 'param'}) ***** error ... paramci (prob.BurrDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'alpha', 'c', 'k', 'param'}) ***** error ... paramci (prob.BurrDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.BurrDistribution.fit (x), 'alpha', 0.01, 'parameter', 'param') ***** error ... paramci (prob.BurrDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.BurrDistribution.fit (x), 'alpha', 0.01, 'NAME', 'value') ***** error ... paramci (prob.BurrDistribution.fit (x), 'alpha', 0.01, 'parameter', 'c', ... 'NAME', 'value') ***** error ... plot (prob.BurrDistribution, 'Parent') ***** error ... plot (prob.BurrDistribution, 'PlotType', 12) ***** error ... plot (prob.BurrDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.BurrDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.BurrDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.BurrDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.BurrDistribution, 'Discrete', {true}) ***** error ... plot (prob.BurrDistribution, 'Parent', 12) ***** error ... plot (prob.BurrDistribution, 'Parent', 'hax') ***** error ... plot (prob.BurrDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.BurrDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.BurrDistribution, 2) ***** error ... proflik (prob.BurrDistribution.fit (x), 4) ***** error ... proflik (prob.BurrDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.BurrDistribution.fit (x), {1}) ***** error ... proflik (prob.BurrDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.BurrDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.BurrDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.BurrDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.BurrDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.BurrDistribution.fit (x), 1, 'Display', ['on'; 'on']) ***** error ... proflik (prob.BurrDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.BurrDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.BurrDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.BurrDistribution.fit (x), 1, {[1 2 3 4]}, 'Display', 'on') ***** error ... truncate (prob.BurrDistribution) ***** error ... truncate (prob.BurrDistribution, 2) ***** error ... truncate (prob.BurrDistribution, 4, 2) ***** shared pd pd = prob.BurrDistribution (1, 1, 1); pd(2) = prob.BurrDistribution (1, 3, 1); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 106 tests, 106 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/NormalDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/NormalDistribution.m ***** demo ## Generate a data set of 5000 random samples from a Normal distribution with ## parameters mu = 0 and sigma = 1. Fit a Normal distribution to this data and plot ## a PDF of the fitted distribution superimposed on a histogram of the data. rng (42); randg ('state', 42); rande ('state', 42); randp ('state', 42); pd_fixed = makedist ('Normal', 'mu', 0, 'sigma', 1) data = random (pd_fixed, 5000, 1); pd_fitted = fitdist (data, 'Normal') plot (pd_fitted) msg = 'Fitted Normal distribution with mu = %0.2f and sigma = %0.2f'; title (sprintf (msg, pd_fitted.mu, pd_fitted.sigma)) ***** shared pd, t pd = prob.NormalDistribution; t = truncate (pd, -2, 2); ***** assert_equal (cdf (pd, [0:5]), [0.5, 0.8413, 0.9772, 0.9987, 1, 1], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0.5, 0.8576, 1, 1, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4]), [0.9332, 0.9772, 0.9987, 1], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4]), [0.9538, 1, 1, 1], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [-Inf, -0.8416, -0.2533, 0.2533, 0.8416, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [-2, -0.7938, -0.2416, 0.2416, 0.7938, 2], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, -0.2533, 0.2533, 0.8416, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, -0.2416, 0.2416, 0.7938, 2, NaN], 1e-4); ***** assert_equal (iqr (pd), 1.3490, 1e-4); ***** assert_equal (iqr (t), 1.2782, 1e-4); ***** assert_equal (mean (pd), 0); ***** assert_equal (mean (t), 0, 3e-16); ***** assert_equal (median (pd), 0); ***** assert_equal (median (t), 0, 3e-16); ***** assert_equal (pdf (pd, [0:5]), [0.3989, 0.2420, 0.0540, 0.0044, 0.0001, 0], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0.4180, 0.2535, 0.0566, 0, 0, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1:4, NaN]), [0.2420, 0.2420, 0.0540, 0.0044, 0.0001, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1:4, NaN]), [0.2535, 0.2535, 0.0566, 0, 0, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < -2), false); ***** assert_equal (any (random (t, 1000, 1) > 2), false); ***** assert_equal (std (pd), 1); ***** assert_equal (std (t), 0.8796, 1e-4); ***** assert_equal (var (pd), 1); ***** assert_equal (var (t), 0.7737, 1e-4); ***** test ## With a further parameter to profile out the default grid takes 21 values. z = [0.3; -1.2; 0.8; 1.5; -0.4; 0.2; -0.9; 1.1; 0.6; -0.3; ... 1.8; -1.5; 0.4; 0.9; -0.7; 1.2; -0.2; 0.5; -1.1; 0.7]; [nlogL, param, other] = proflik (prob.NormalDistribution.fit (z), 1); assert_equal (size (param), [1, 21]); assert_equal (size (other), [21, 1]); ***** test ## OTHER holds the profiled-out parameter maximizing the likelihood at each ## value of PARAM. Verified against MATLAB. z = [0.3; -1.2; 0.8; 1.5; -0.4; 0.2; -0.9; 1.1; 0.6; -0.3; ... 1.8; -1.5; 0.4; 0.9; -0.7; 1.2; -0.2; 0.5; -1.1; 0.7]; [nlogL, param, other] = proflik (prob.NormalDistribution.fit (z), 1, [-0.2, 0, 0.2]); assert_equal (other, [0.9937; 0.9346; 0.9162], 1e-4); ***** error ... prob.NormalDistribution (Inf, 1) ***** error ... prob.NormalDistribution (i, 1) ***** error ... prob.NormalDistribution ('a', 1) ***** error ... prob.NormalDistribution ([1, 2], 1) ***** error ... prob.NormalDistribution (NaN, 1) ***** error ... prob.NormalDistribution (1, 0) ***** error ... prob.NormalDistribution (1, -1) ***** error ... prob.NormalDistribution (1, Inf) ***** error ... prob.NormalDistribution (1, i) ***** error ... prob.NormalDistribution (1, 'a') ***** error ... prob.NormalDistribution (1, [1, 2]) ***** error ... prob.NormalDistribution (1, NaN) ***** error ... cdf (prob.NormalDistribution, 2, 'uper') ***** error ... cdf (prob.NormalDistribution, 2, 3) ***** shared x x = normrnd (1, 1, [1, 100]); ***** error ... paramci (prob.NormalDistribution.fit (x), 'alpha') ***** error ... paramci (prob.NormalDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.NormalDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.NormalDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.NormalDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.NormalDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.NormalDistribution.fit (x), 'parameter', 'mu', 'alpha', {0.05}) ***** error ... paramci (prob.NormalDistribution.fit (x), 'parameter', {'mu', 'sigma', 'param'}) ***** error ... paramci (prob.NormalDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'mu', 'sigma', 'param'}) ***** error ... paramci (prob.NormalDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.NormalDistribution.fit (x), 'alpha', 0.01, 'parameter', 'param') ***** error ... paramci (prob.NormalDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.NormalDistribution.fit (x), 'alpha', 0.01, 'NAME', 'value') ***** error ... paramci (prob.NormalDistribution.fit (x), 'alpha', 0.01, 'parameter', 'mu', ... 'NAME', 'value') ***** error ... plot (prob.NormalDistribution, 'Parent') ***** error ... plot (prob.NormalDistribution, 'PlotType', 12) ***** error ... plot (prob.NormalDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.NormalDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.NormalDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.NormalDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.NormalDistribution, 'Discrete', {true}) ***** error ... plot (prob.NormalDistribution, 'Parent', 12) ***** error ... plot (prob.NormalDistribution, 'Parent', 'hax') ***** error ... plot (prob.NormalDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.NormalDistribution, 'PlotType', 'probability') ***** test ## Profile log-likelihood values verified against MATLAB (nuisance ## parameters are profiled out, not held fixed). x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; pd = prob.NormalDistribution.fit (x'); [ll, param] = proflik (pd, 1, 2.6:0.2:4.2); ref = [-20.3706543783445, -19.2807332475991, -18.3460903001355, ... -17.6848714616926, -17.4098041938949, -17.5763530516294, ... -18.1502877476524, -19.0282120496015, -20.0892153912834]; assert_equal (ll, ref, 1e-6); assert_equal (param, 2.6:0.2:4.2, 1e-12); ***** test x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; pd = prob.NormalDistribution.fit (x'); ll = proflik (pd, 2, 0.7:0.1:1.6); ref = [-19.7905304181301, -18.3358679076856, -17.6533683093276, ... -17.4185123984561, -17.4530093494964, -17.6534891355391, ... -17.9574383057938, -18.3257710746453, -18.7333992513096, ... -19.1638879806549]; assert_equal (ll, ref, 1e-6); ***** test ## Default grid spans the 98% CI with 21 points (matching MATLAB). x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; pd = prob.NormalDistribution.fit (x'); [ll, param] = proflik (pd, 1); assert_equal (numel (param), 21); assert_equal ([param(1), param(end)], ... [2.57917008770431, 4.27082991229569], 1e-6); ***** error ... proflik (prob.NormalDistribution, 2) ***** error ... proflik (prob.NormalDistribution.fit (x), 3) ***** error ... proflik (prob.NormalDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.NormalDistribution.fit (x), {1}) ***** error ... proflik (prob.NormalDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.NormalDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.NormalDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.NormalDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.NormalDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.NormalDistribution.fit (x), 1, 'Display', ['on'; 'on']) ***** error ... proflik (prob.NormalDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.NormalDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.NormalDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.NormalDistribution.fit (x), 1, {[1 2 3 4]}, 'Display', 'on') ***** error ... truncate (prob.NormalDistribution) ***** error ... truncate (prob.NormalDistribution, 2) ***** error ... truncate (prob.NormalDistribution, 4, 2) ***** shared pd pd = prob.NormalDistribution (1, 1); pd(2) = prob.NormalDistribution (1, 3); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** test ## negloglik returns the (positive) negative log-likelihood. xdat = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; pdfit = prob.NormalDistribution.fit (xdat'); assert_equal (negloglik (pdfit), -sum (log (pdf (pdfit, xdat'))), 1e-9); assert_equal (negloglik (pdfit) > 0, true); ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 101 tests, 101 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/UniformDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/UniformDistribution.m ***** demo ## Generate a data set of 5000 random samples from a Uniform distribution with ## parameters Lower = 0 and Upper = 10. Create a Uniform distribution with these ## parameters and plot its PDF superimposed on a histogram of the data. rng (42); randg ('state', 42); rande ('state', 42); randp ('state', 42); pd = makedist ('Uniform', 'Lower', 0, 'Upper', 10); data = random (pd, 5000, 1); x = linspace (pd.Lower - 1, pd.Upper + 1, 500); y = pdf (pd, x); plot (x, y, 'r-', 'LineWidth', 2); hold on; [counts, centers] = hist (data, 50); bin_width = centers(2) - centers(1); normalized_counts = counts / (sum (counts) * bin_width); bar (centers, normalized_counts, 1); msg = 'Uniform distribution with Lower = %0.2f and Upper = %0.2f'; title (sprintf (msg, pd.Lower, pd.Upper)); legend ('PDF', 'Histogram', 'location', 'northeast'); hold off; ***** shared pd, t pd = prob.UniformDistribution (0, 5); t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0, 0.2, 0.4, 0.6, 0.8, 1], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 0.5, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4, NaN]), [0.3, 0.4, 0.6, 0.8, NaN], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4, NaN]), [0, 0, 0.5, 1, NaN], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [0, 1, 2, 3, 4, 5], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.4, 2.8, 3.2, 3.6, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 2, 3, 4, 5, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.8, 3.2, 3.6, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 2.5, 1e-14); ***** assert_equal (iqr (t), 1, 1e-14); ***** assert_equal (mean (pd), 2.5, 1e-14); ***** assert_equal (mean (t), 3, 1e-14); ***** assert_equal (median (pd), 2.5, 1e-14); ***** assert_equal (median (t), 3, 1e-14); ***** assert_equal (pdf (pd, [0:5]), [0.2, 0.2, 0.2, 0.2, 0.2, 0.2], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 0.5, 0.5, 0.5, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1.5, NaN]), [0, 0.2, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1.5, NaN]), [0, 0, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 1.4434, 1e-4); ***** assert_equal (std (t), 0.5774, 1e-4); ***** assert_equal (var (pd), 2.0833, 1e-4); ***** assert_equal (var (t), 0.3333, 1e-4); ***** error ... prob.UniformDistribution (i, 1) ***** error ... prob.UniformDistribution (Inf, 1) ***** error ... prob.UniformDistribution ([1, 2], 1) ***** error ... prob.UniformDistribution ('a', 1) ***** error ... prob.UniformDistribution (NaN, 1) ***** error ... prob.UniformDistribution (1, i) ***** error ... prob.UniformDistribution (1, Inf) ***** error ... prob.UniformDistribution (1, [1, 2]) ***** error ... prob.UniformDistribution (1, 'a') ***** error ... prob.UniformDistribution (1, NaN) ***** error ... prob.UniformDistribution (2, 1) ***** error ... cdf (prob.UniformDistribution, 2, 'uper') ***** error ... cdf (prob.UniformDistribution, 2, 3) ***** error ... plot (prob.UniformDistribution, 'Parent') ***** error ... plot (prob.UniformDistribution, 'PlotType', 12) ***** error ... plot (prob.UniformDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.UniformDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.UniformDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.UniformDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.UniformDistribution, 'Discrete', {true}) ***** error ... plot (prob.UniformDistribution, 'Parent', 12) ***** error ... plot (prob.UniformDistribution, 'Parent', 'hax') ***** error ... plot (prob.UniformDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.UniformDistribution, 'PlotType', 'probability') ***** error ... truncate (prob.UniformDistribution) ***** error ... truncate (prob.UniformDistribution, 2) ***** error ... truncate (prob.UniformDistribution, 4, 2) ***** shared pd pd = prob.UniformDistribution (0, 1); pd(2) = prob.UniformDistribution (0, 2); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 63 tests, 63 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/StableDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/StableDistribution.m ***** demo ## Create a stable distribution and plot its pdf pd = makedist ("Stable", "alpha", 1.5, "beta", 0.5, "gam", 1, "delta", 0); plot (pd); title ("Stable distribution, alpha = 1.5, beta = 0.5"); ***** shared pd pd = makedist ("Stable", "alpha", 1.5, "beta", 0.5, "gam", 1, "delta", 0); ***** test assert_equal (pd.alpha, 1.5); assert_equal (pd.beta, 0.5); assert_equal (pd.gam, 1); assert_equal (pd.delta, 0); assert_equal (pd.DistributionName, "Stable"); assert_equal (pd.NumParameters, 4); ***** test x = -5:5; exp_p = [0.00961772128347771, 0.0143422747723476, 0.0257902242195547, ... 0.0657154294128386, 0.201576145758624, 0.462186560100778, ... 0.712063555515659, 0.855535196378772, 0.921201224725992, ... 0.951409668616683, 0.966845678836178]; assert_equal (cdf (pd, x), exp_p, 1e-8); ***** test assert_equal (icdf (pd, [0.1, 0.5, 0.9]), ... [-1.63127009138493, 0.133853042315326, 2.58231785139714], 1e-6); ***** test # mean, variance, median of a skewed stable (alpha = 1.5) assert_equal (mean (pd), 0.5, 1e-12); assert_equal (isnan (var (pd)), true); assert_equal (median (pd), 0.133853042315326, 1e-6); ***** test pn = makedist ("Stable", "alpha", 2, "beta", 0, "gam", 1, "delta", 0); assert_equal (mean (pn), 0); assert_equal (var (pn), 2, 1e-12); assert_equal (std (pn), sqrt (2), 1e-12); assert_equal (pdf (pn, 0:2), normpdf (0:2, 0, sqrt (2)), 1e-12); ***** test pc = makedist ("Stable", "alpha", 0.8, "beta", 0.5, "gam", 1, "delta", 0); assert_equal (isnan (mean (pc)), true); assert_equal (isnan (var (pc)), true); assert_equal (median (pc), 0.250487323305453, 1e-5); ***** test ps = makedist ("Stable", "alpha", 1.5, "beta", 0.5, "gam", 2, "delta", 3); assert_equal (mean (ps), 4, 1e-12); assert_equal (median (ps), 3.26770608463065, 1e-6); ***** test # truncation renormalizes and bounds the support pt = truncate (pd, -1, 3); assert_equal (pt.IsTruncated, true); assert_equal (cdf (pt, [-2, 3]), [0, 1]); assert_equal (isfinite (mean (pt)), true); r = random (pt, 100, 1); assert_equal (all (r >= -1 & r <= 3, 'all'), true); ***** test ## The profile over alpha: 21 grid values, one row of OTHER per value, and ## the likelihood peaking at the fitted estimate. The sample is stable. x = [-4.481370; -2.439510; -1.787770; -1.391000; -1.095410; -0.852136; ... -0.639452; -0.445603; -0.263227; -0.087082; 0.087082; 0.263227; ... 0.445603; 0.639452; 0.852136; 1.095410; 1.391000; 1.787770; ... 2.439510; 4.481370]; pd = fitdist (x, 'Stable'); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 21]); assert_equal (size (other), [21, 3]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); ***** error ... proflik (fitdist ([0.3; -1.2; 0.8; 1.5; -0.4; 0.2; -0.9; 1.1; 0.6; -0.3; ... 1.8; -1.5; 0.4; 0.9; -0.7; 1.2; -0.2; 0.5; -1.1; 0.7], ... 'Stable'), 1) ***** error ... prob.StableDistribution (2.5, 0, 1, 0) ***** error ... prob.StableDistribution (1.5, 2, 1, 0) ***** error ... prob.StableDistribution (1.5, 0, 0, 0) ***** error ... prob.StableDistribution (1.5, 0, 1, Inf) ***** error ... cdf ([pd, pd], 1) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/GeneralizedExtremeValueDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/GeneralizedExtremeValueDistribution.m ***** shared pd, t pd = prob.GeneralizedExtremeValueDistribution; t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0.3679, 0.6922, 0.8734, 0.9514, 0.9819, 0.9933], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 0.7195, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4]), [0.8, 0.8734, 0.9514, 0.9819], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4]), [0, 0, 0.7195, 1], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [-Inf, -0.4759, 0.0874, 0.6717, 1.4999, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.1999, 2.4433, 2.7568, 3.2028, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 0.0874, 0.6717, 1.4999, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.4433, 2.7568, 3.2028, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 1.5725, 1e-4); ***** assert_equal (iqr (t), 0.8164, 1e-4); ***** assert_equal (mean (pd), 0.5772, 1e-4); ***** assert_equal (mean (t), 2.7043, 1e-4); ***** assert_equal (median (pd), 0.3665, 1e-4); ***** assert_equal (median (t), 2.5887, 1e-4); ***** assert_equal (pdf (pd, [0:5]), [0.3679, 0.2546, 0.1182, 0.0474, 0.0180, 0.0067], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 1.0902, 0.4369, 0.1659, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1:4, NaN]), [0.1794, 0.2546, 0.1182, 0.0474, 0.0180, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1:4, NaN]), [0, 0, 1.0902, 0.4369, 0.1659, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 1.2825, 1e-4); ***** assert_equal (std (t), 0.5289, 1e-4); ***** assert_equal (var (pd), 1.6449, 1e-4); ***** assert_equal (var (t), 0.2798, 1e-4); ***** test ## The profile over the first free parameter: 21 grid values, one row of ## OTHER per value, and the likelihood peaking at the fitted estimate. x = [0.3; -1.2; 0.8; 1.5; -0.4; 0.2; -0.9; 1.1; 0.6; -0.3; ... 1.8; -1.5; 0.4; 0.9; -0.7; 1.2; -0.2; 0.5; -1.1; 0.7]; pd = fitdist (x, 'GeneralizedExtremeValue'); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 21]); assert_equal (size (other), [21, 2]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); warning: matrix singular to machine precision, rcond = 6.40014e-82 warning: called from polyfit at line 178 column 3 gevfit at line 176 column 3 fit at line 807 column 8 fitdist at line 401 column 9 __test__ at line 7 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 238 column 2 warning: matrix singular to machine precision, rcond = 6.40014e-82 warning: called from polyfit at line 178 column 3 gevfit at line 176 column 3 mle at line 366 column 10 __paramci__ at line 210 column 10 paramci at line 522 column 9 __proflik__ at line 373 column 9 proflik at line 664 column 8 __test__ at line 8 column 3 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 238 column 2 warning: matrix singular to machine precision, rcond = 6.40014e-82 warning: called from polyfit at line 178 column 3 gevfit at line 176 column 3 mle at line 366 column 10 __paramci__ at line 210 column 10 paramci at line 522 column 9 __proflik__ at line 373 column 9 proflik at line 664 column 8 __test__ at line 11 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 238 column 2 ***** error ... prob.GeneralizedExtremeValueDistribution (Inf, 1, 1) ***** error ... prob.GeneralizedExtremeValueDistribution (i, 1, 1) ***** error ... prob.GeneralizedExtremeValueDistribution ('a', 1, 1) ***** error ... prob.GeneralizedExtremeValueDistribution ([1, 2], 1, 1) ***** error ... prob.GeneralizedExtremeValueDistribution (NaN, 1, 1) ***** error ... prob.GeneralizedExtremeValueDistribution (1, 0, 1) ***** error ... prob.GeneralizedExtremeValueDistribution (1, -1, 1) ***** error ... prob.GeneralizedExtremeValueDistribution (1, Inf, 1) ***** error ... prob.GeneralizedExtremeValueDistribution (1, i, 1) ***** error ... prob.GeneralizedExtremeValueDistribution (1, 'a', 1) ***** error ... prob.GeneralizedExtremeValueDistribution (1, [1, 2], 1) ***** error ... prob.GeneralizedExtremeValueDistribution (1, NaN, 1) ***** error ... prob.GeneralizedExtremeValueDistribution (1, 1, Inf) ***** error ... prob.GeneralizedExtremeValueDistribution (1, 1, i) ***** error ... prob.GeneralizedExtremeValueDistribution (1, 1, 'a') ***** error ... prob.GeneralizedExtremeValueDistribution (1, 1, [1, 2]) ***** error ... prob.GeneralizedExtremeValueDistribution (1, 1, NaN) ***** error ... cdf (prob.GeneralizedExtremeValueDistribution, 2, 'uper') ***** error ... cdf (prob.GeneralizedExtremeValueDistribution, 2, 3) ***** shared x x = gevrnd (1, 1, 1, [1, 100]); ***** error ... paramci (prob.GeneralizedExtremeValueDistribution.fit (x), 'alpha') ***** error ... paramci (prob.GeneralizedExtremeValueDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.GeneralizedExtremeValueDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.GeneralizedExtremeValueDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.GeneralizedExtremeValueDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.GeneralizedExtremeValueDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.GeneralizedExtremeValueDistribution.fit (x), ... 'parameter', 'sigma', 'alpha', {0.05}) ***** error ... paramci (prob.GeneralizedExtremeValueDistribution.fit (x), ... 'parameter', {'k', 'sigma', 'mu', 'param'}) ***** error ... paramci (prob.GeneralizedExtremeValueDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'k', 'sigma', 'mu', 'param'}) ***** error ... paramci (prob.GeneralizedExtremeValueDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.GeneralizedExtremeValueDistribution.fit (x), 'alpha', 0.01, ... 'parameter', 'param') ***** error ... paramci (prob.GeneralizedExtremeValueDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.GeneralizedExtremeValueDistribution.fit (x), 'alpha', 0.01, ... 'NAME', 'value') ***** error ... paramci (prob.GeneralizedExtremeValueDistribution.fit (x), 'alpha', 0.01, ... 'parameter', 'sigma', 'NAME', 'value') ***** error ... plot (prob.GeneralizedExtremeValueDistribution, 'Parent') ***** error ... plot (prob.GeneralizedExtremeValueDistribution, 'PlotType', 12) ***** error ... plot (prob.GeneralizedExtremeValueDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.GeneralizedExtremeValueDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.GeneralizedExtremeValueDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.GeneralizedExtremeValueDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.GeneralizedExtremeValueDistribution, 'Discrete', {true}) ***** error ... plot (prob.GeneralizedExtremeValueDistribution, 'Parent', 12) ***** error ... plot (prob.GeneralizedExtremeValueDistribution, 'Parent', 'hax') ***** error ... plot (prob.GeneralizedExtremeValueDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.GeneralizedExtremeValueDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.GeneralizedExtremeValueDistribution, 2) ***** error ... proflik (prob.GeneralizedExtremeValueDistribution.fit (x), 4) ***** error ... proflik (prob.GeneralizedExtremeValueDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.GeneralizedExtremeValueDistribution.fit (x), {1}) ***** error ... proflik (prob.GeneralizedExtremeValueDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.GeneralizedExtremeValueDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.GeneralizedExtremeValueDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.GeneralizedExtremeValueDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.GeneralizedExtremeValueDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.GeneralizedExtremeValueDistribution.fit (x), 1, ... 'Display', ['on'; 'on']) ***** error ... proflik (prob.GeneralizedExtremeValueDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.GeneralizedExtremeValueDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.GeneralizedExtremeValueDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.GeneralizedExtremeValueDistribution.fit (x), 1, {[1 2 3 4]}, ... 'Display', 'on') ***** error ... truncate (prob.GeneralizedExtremeValueDistribution) ***** error ... truncate (prob.GeneralizedExtremeValueDistribution, 2) ***** error ... truncate (prob.GeneralizedExtremeValueDistribution, 4, 2) ***** shared pd pd = prob.GeneralizedExtremeValueDistribution (1, 1, 1); pd(2) = prob.GeneralizedExtremeValueDistribution (1, 3, 1); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 101 tests, 101 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/GeneralizedParetoDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/GeneralizedParetoDistribution.m ***** shared pd, t pd = prob.GeneralizedParetoDistribution (1, 1, 1); t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0, 0, 0.5, 0.6667, 0.75, 0.8], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 0.6667, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4]), [0.3333, 0.5, 0.6667, 0.75], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4]), [0, 0, 0.6667, 1], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [1, 1.25, 1.6667, 2.5, 5, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.2222, 2.5, 2.8571, 3.3333, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 1.6667, 2.5, 5, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.5, 2.8571, 3.3333, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 2.6667, 1e-4); ***** assert_equal (iqr (t), 0.9143, 1e-4); ***** assert_equal (mean (pd), Inf); ***** assert_equal (mean (t), 2.7726, 1e-4); ***** assert_equal (median (pd), 2); ***** assert_equal (median (t), 2.6667, 1e-4); ***** assert_equal (pdf (pd, [0:5]), [0, 1, 0.25, 0.1111, 0.0625, 0.04], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 1, 0.4444, 0.25, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1:4, NaN]), [0, 1, 0.25, 0.1111, 0.0625, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1:4, NaN]), [0, 0, 1, 0.4444, 0.25, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), Inf); ***** assert_equal (std (t), 0.5592, 1e-4); ***** assert_equal (var (pd), Inf); ***** assert_equal (var (t), 0.3128, 1e-4); ***** test ## The profile over the first free parameter: 21 grid values, one row of ## OTHER per value, and the likelihood peaking at the fitted estimate. x = [1.2; 0.4; 3.1; 0.7; 2.5; 1.8; 0.3; 4.2; 1.1; 0.9; ... 2.2; 0.6; 1.5; 3.7; 0.8; 2.9; 1.3; 0.5; 2.0; 1.6] - 0.3 + 1e-8; pd = fitdist (x, 'GeneralizedPareto', 'theta', 0); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 21]); assert_equal (size (other), [21, 2]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); ***** error ... prob.GeneralizedParetoDistribution (Inf, 1, 1) ***** error ... prob.GeneralizedParetoDistribution (i, 1, 1) ***** error ... prob.GeneralizedParetoDistribution ('a', 1, 1) ***** error ... prob.GeneralizedParetoDistribution ([1, 2], 1, 1) ***** error ... prob.GeneralizedParetoDistribution (NaN, 1, 1) ***** error ... prob.GeneralizedParetoDistribution (1, 0, 1) ***** error ... prob.GeneralizedParetoDistribution (1, -1, 1) ***** error ... prob.GeneralizedParetoDistribution (1, Inf, 1) ***** error ... prob.GeneralizedParetoDistribution (1, i, 1) ***** error ... prob.GeneralizedParetoDistribution (1, 'a', 1) ***** error ... prob.GeneralizedParetoDistribution (1, [1, 2], 1) ***** error ... prob.GeneralizedParetoDistribution (1, NaN, 1) ***** error ... prob.GeneralizedParetoDistribution (1, 1, Inf) ***** error ... prob.GeneralizedParetoDistribution (1, 1, i) ***** error ... prob.GeneralizedParetoDistribution (1, 1, 'a') ***** error ... prob.GeneralizedParetoDistribution (1, 1, [1, 2]) ***** error ... prob.GeneralizedParetoDistribution (1, 1, NaN) ***** error ... cdf (prob.GeneralizedParetoDistribution, 2, 'uper') ***** error ... cdf (prob.GeneralizedParetoDistribution, 2, 3) ***** shared x x = gprnd (1, 1, 1, [1, 100]); ***** error ... paramci (prob.GeneralizedParetoDistribution.fit (x, 1), 'alpha') ***** error ... paramci (prob.GeneralizedParetoDistribution.fit (x, 1), 'alpha', 0) ***** error ... paramci (prob.GeneralizedParetoDistribution.fit (x, 1), 'alpha', 1) ***** error ... paramci (prob.GeneralizedParetoDistribution.fit (x, 1), 'alpha', [0.5 2]) ***** error ... paramci (prob.GeneralizedParetoDistribution.fit (x, 1), 'alpha', '') ***** error ... paramci (prob.GeneralizedParetoDistribution.fit (x, 1), 'alpha', {0.05}) ***** error ... paramci (prob.GeneralizedParetoDistribution.fit (x, 1), ... 'parameter', 'sigma', 'alpha', {0.05}) ***** error ... paramci (prob.GeneralizedParetoDistribution.fit (x, 1), ... 'parameter', {'k', 'sigma', 'theta', 'param'}) ***** error ... paramci (prob.GeneralizedParetoDistribution.fit (x, 1), 'alpha', 0.01, ... 'parameter', {'k', 'sigma', 'theta', 'param'}) ***** error ... paramci (prob.GeneralizedParetoDistribution.fit (x, 1), 'parameter', 'param') ***** error ... paramci (prob.GeneralizedParetoDistribution.fit (x, 1), 'alpha', 0.01, ... 'parameter', 'param') ***** error ... paramci (prob.GeneralizedParetoDistribution.fit (x, 1), 'NAME', 'value') ***** error ... paramci (prob.GeneralizedParetoDistribution.fit (x, 1), 'alpha', 0.01, ... 'NAME', 'value') ***** error ... paramci (prob.GeneralizedParetoDistribution.fit (x, 1), 'alpha', 0.01, ... 'parameter', 'sigma', 'NAME', 'value') ***** error ... plot (prob.GeneralizedParetoDistribution, 'Parent') ***** error ... plot (prob.GeneralizedParetoDistribution, 'PlotType', 12) ***** error ... plot (prob.GeneralizedParetoDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.GeneralizedParetoDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.GeneralizedParetoDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.GeneralizedParetoDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.GeneralizedParetoDistribution, 'Discrete', {true}) ***** error ... plot (prob.GeneralizedParetoDistribution, 'Parent', 12) ***** error ... plot (prob.GeneralizedParetoDistribution, 'Parent', 'hax') ***** error ... plot (prob.GeneralizedParetoDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.GeneralizedParetoDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.GeneralizedParetoDistribution, 2) ***** error ... proflik (prob.GeneralizedParetoDistribution.fit (x, 1), 3) ***** error ... proflik (prob.GeneralizedParetoDistribution.fit (x, 1), [1, 2]) ***** error ... proflik (prob.GeneralizedParetoDistribution.fit (x, 1), {1}) ***** error ... proflik (prob.GeneralizedParetoDistribution.fit (x, 1), 1, ones (2)) ***** error ... proflik (prob.GeneralizedParetoDistribution.fit (x, 1), 1, 'Display') ***** error ... proflik (prob.GeneralizedParetoDistribution.fit (x, 1), 1, 'Display', 1) ***** error ... proflik (prob.GeneralizedParetoDistribution.fit (x, 1), 1, 'Display', {1}) ***** error ... proflik (prob.GeneralizedParetoDistribution.fit (x, 1), 1, 'Display', {'on'}) ***** error ... proflik (prob.GeneralizedParetoDistribution.fit (x, 1), 1, ... 'Display', ['on'; 'on']) ***** error ... proflik (prob.GeneralizedParetoDistribution.fit (x, 1), 1, 'Display', 'onnn') ***** error ... proflik (prob.GeneralizedParetoDistribution.fit (x, 1), 1, 'NAME', 'on') ***** error ... proflik (prob.GeneralizedParetoDistribution.fit (x, 1), 1, {'NAME'}, 'on') ***** error ... proflik (prob.GeneralizedParetoDistribution.fit (x, 1), 1, {[1 2 3 4]}, ... 'Display', 'on') ***** error ... truncate (prob.GeneralizedParetoDistribution) ***** error ... truncate (prob.GeneralizedParetoDistribution, 2) ***** error ... truncate (prob.GeneralizedParetoDistribution, 4, 2) ***** shared pd pd = prob.GeneralizedParetoDistribution (1, 1, 1); pd(2) = prob.GeneralizedParetoDistribution (1, 3, 1); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 101 tests, 101 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/+prob/RayleighDistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/+prob/RayleighDistribution.m ***** demo ## Generate a data set of 5000 random samples from a Rayleigh distribution with ## parameter B = 2. Fit a Rayleigh distribution to this data and plot ## a PDF of the fitted distribution superimposed on a histogram of the data. rng (42); randg ('state', 42); rande ('state', 42); randp ('state', 42); pd_fixed = makedist ('Rayleigh', 'B', 2) data = random (pd_fixed, 5000, 1); pd_fitted = fitdist (data, 'Rayleigh') plot (pd_fitted) msg = 'Fitted Rayleigh distribution with B = %0.2f'; title (sprintf (msg, pd_fitted.B)) ***** shared pd, t pd = prob.RayleighDistribution; t = truncate (pd, 2, 4); ***** assert_equal (cdf (pd, [0:5]), [0, 0.3935, 0.8647, 0.9889, 0.9997, 1], 1e-4); ***** assert_equal (cdf (t, [0:5]), [0, 0, 0, 0.9202, 1, 1], 1e-4); ***** assert_equal (cdf (pd, [1.5, 2, 3, 4, NaN]), [0.6753, 0.8647, 0.9889, 0.9997, NaN], 1e-4); ***** assert_equal (cdf (t, [1.5, 2, 3, 4, NaN]), [0, 0, 0.9202, 1, NaN], 1e-4); ***** assert_equal (icdf (pd, [0:0.2:1]), [0, 0.6680, 1.0108, 1.3537, 1.7941, Inf], 1e-4); ***** assert_equal (icdf (t, [0:0.2:1]), [2, 2.1083, 2.2402, 2.4135, 2.6831, 4], 1e-4); ***** assert_equal (icdf (pd, [-1, 0.4:0.2:1, NaN]), [NaN, 1.0108, 1.3537, 1.7941, Inf, NaN], 1e-4); ***** assert_equal (icdf (t, [-1, 0.4:0.2:1, NaN]), [NaN, 2.2402, 2.4135, 2.6831, 4, NaN], 1e-4); ***** assert_equal (iqr (pd), 0.9066, 1e-4); ***** assert_equal (iqr (t), 0.4609, 1e-4); ***** assert_equal (mean (pd), 1.2533, 1e-4); ***** assert_equal (mean (t), 2.4169, 1e-4); ***** assert_equal (median (pd), 1.1774, 1e-4); ***** assert_equal (median (t), 2.3198, 1e-4); ***** assert_equal (pdf (pd, [0:5]), [0, 0.6065, 0.2707, 0.0333, 0.0013, 0], 1e-4); ***** assert_equal (pdf (t, [0:5]), [0, 0, 2.0050, 0.2469, 0.0099, 0], 1e-4); ***** assert_equal (pdf (pd, [-1, 1.5, NaN]), [0, 0.4870, NaN], 1e-4); ***** assert_equal (pdf (t, [-1, 1.5, NaN]), [0, 0, NaN], 1e-4); ***** assert_equal (isequal (size (random (pd, 100, 50)), [100, 50]), true) ***** assert_equal (any (random (t, 1000, 1) < 2), false); ***** assert_equal (any (random (t, 1000, 1) > 4), false); ***** assert_equal (std (pd), 0.6551, 1e-4); ***** assert_equal (std (t), 0.3591, 1e-4); ***** assert_equal (var (pd), 0.4292, 1e-4); ***** assert_equal (var (t), 0.1290, 1e-4); ***** test ## The profile over the first free parameter: 101 grid values, one row of ## OTHER per value, and the likelihood peaking at the fitted estimate. x = [1.2; 0.4; 3.1; 0.7; 2.5; 1.8; 0.3; 4.2; 1.1; 0.9; ... 2.2; 0.6; 1.5; 3.7; 0.8; 2.9; 1.3; 0.5; 2.0; 1.6]; pd = fitdist (x, 'Rayleigh'); [nlogL, param, other] = proflik (pd, 1); assert_equal (size (param), [1, 101]); assert_equal (size (other), [101, 0]); assert_equal (proflik (pd), nlogL); [~, imax] = max (nlogL); assert_equal (abs (param(imax) - pd.ParameterValues(1)) <= param(2) - param(1), true); ***** error ... prob.RayleighDistribution (0) ***** error ... prob.RayleighDistribution (-1) ***** error ... prob.RayleighDistribution (Inf) ***** error ... prob.RayleighDistribution (i) ***** error ... prob.RayleighDistribution ('a') ***** error ... prob.RayleighDistribution ([1, 2]) ***** error ... prob.RayleighDistribution (NaN) ***** error ... cdf (prob.RayleighDistribution, 2, 'uper') ***** error ... cdf (prob.RayleighDistribution, 2, 3) ***** shared x x = raylrnd (1, [1, 100]); ***** error ... paramci (prob.RayleighDistribution.fit (x), 'alpha') ***** error ... paramci (prob.RayleighDistribution.fit (x), 'alpha', 0) ***** error ... paramci (prob.RayleighDistribution.fit (x), 'alpha', 1) ***** error ... paramci (prob.RayleighDistribution.fit (x), 'alpha', [0.5 2]) ***** error ... paramci (prob.RayleighDistribution.fit (x), 'alpha', '') ***** error ... paramci (prob.RayleighDistribution.fit (x), 'alpha', {0.05}) ***** error ... paramci (prob.RayleighDistribution.fit (x), 'parameter', 'B', 'alpha', {0.05}) ***** error ... paramci (prob.RayleighDistribution.fit (x), 'parameter', {'B', 'param'}) ***** error ... paramci (prob.RayleighDistribution.fit (x), 'alpha', 0.01, ... 'parameter', {'B', 'param'}) ***** error ... paramci (prob.RayleighDistribution.fit (x), 'parameter', 'param') ***** error ... paramci (prob.RayleighDistribution.fit (x), 'alpha', 0.01, 'parameter', 'param') ***** error ... paramci (prob.RayleighDistribution.fit (x), 'NAME', 'value') ***** error ... paramci (prob.RayleighDistribution.fit (x), 'alpha', 0.01, 'NAME', 'value') ***** error ... paramci (prob.RayleighDistribution.fit (x), 'alpha', 0.01, ... 'parameter', 'B', 'NAME', 'value') ***** error ... plot (prob.RayleighDistribution, 'Parent') ***** error ... plot (prob.RayleighDistribution, 'PlotType', 12) ***** error ... plot (prob.RayleighDistribution, 'PlotType', {'pdf', 'cdf'}) ***** error ... plot (prob.RayleighDistribution, 'PlotType', 'pdfcdf') ***** error ... plot (prob.RayleighDistribution, 'Discrete', 'pdfcdf') ***** error ... plot (prob.RayleighDistribution, 'Discrete', [1, 0]) ***** error ... plot (prob.RayleighDistribution, 'Discrete', {true}) ***** error ... plot (prob.RayleighDistribution, 'Parent', 12) ***** error ... plot (prob.RayleighDistribution, 'Parent', 'hax') ***** error ... plot (prob.RayleighDistribution, 'invalidNAME', 'pdf') ***** error ... plot (prob.RayleighDistribution, 'PlotType', 'probability') ***** error ... proflik (prob.RayleighDistribution, 2) ***** error ... proflik (prob.RayleighDistribution.fit (x), 3) ***** error ... proflik (prob.RayleighDistribution.fit (x), [1, 2]) ***** error ... proflik (prob.RayleighDistribution.fit (x), {1}) ***** error ... proflik (prob.RayleighDistribution.fit (x), 1, ones (2)) ***** error ... proflik (prob.RayleighDistribution.fit (x), 1, 'Display') ***** error ... proflik (prob.RayleighDistribution.fit (x), 1, 'Display', 1) ***** error ... proflik (prob.RayleighDistribution.fit (x), 1, 'Display', {1}) ***** error ... proflik (prob.RayleighDistribution.fit (x), 1, 'Display', {'on'}) ***** error ... proflik (prob.RayleighDistribution.fit (x), 1, 'Display', ['on'; 'on']) ***** error ... proflik (prob.RayleighDistribution.fit (x), 1, 'Display', 'onnn') ***** error ... proflik (prob.RayleighDistribution.fit (x), 1, 'NAME', 'on') ***** error ... proflik (prob.RayleighDistribution.fit (x), 1, {'NAME'}, 'on') ***** error ... proflik (prob.RayleighDistribution.fit (x), 1, {[1 2 3 4]}, 'Display', 'on') ***** error ... truncate (prob.RayleighDistribution) ***** error ... truncate (prob.RayleighDistribution, 2) ***** error ... truncate (prob.RayleighDistribution, 4, 2) ***** shared pd pd = prob.RayleighDistribution (1); pd(2) = prob.RayleighDistribution (3); ***** error cdf (pd, 1) ***** error icdf (pd, 0.5) ***** error iqr (pd) ***** error mean (pd) ***** error median (pd) ***** error negloglik (pd) ***** error paramci (pd) ***** error pdf (pd, 1) ***** error plot (pd) ***** error proflik (pd, 2) ***** error random (pd) ***** error std (pd) ***** error ... truncate (pd, 2, 4) ***** error var (pd) 91 tests, 91 passed, 0 known failure, 0 skipped [inst/Distribution_Classes/paretotails.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Classes/paretotails.m ***** demo ## Fit Pareto tails to a normal sample and compare the tail cdf to the data x = norminv (((1:100) - 0.5) / 100); pt = paretotails (x, 0.1, 0.9); lowerparams (pt) [p, q] = boundary (pt) cdf (pt, [-2.5, 0, 2.5]) ***** shared x, pt x = norminv (((1:100) - 0.5) / 100); pt = paretotails (x, 0.1, 0.9); ***** test assert_equal (lowerparams (pt), ... [-0.381277950146653, 0.652296030248444], 1e-5); assert_equal (upperparams (pt), ... [-0.381277950146658, 0.652296030248448], 1e-5); ***** test [p, q] = boundary (pt); assert_equal (p, [0.1; 0.9], 1e-12); assert_equal (q, [-1.28207227531929; 1.28207227531929], 1e-10); ***** test assert_equal (nsegments (pt), 3); assert_equal (pt.NumSegments, 3); ***** test xq = [-2.8, -2.3, -1.8, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 1.8, 2.3, 2.8]; ref = [0.000326503983434112, 0.00934245750239852, 0.0388388580428329, ... 0.0699512617277107, 0.158702922884361, 0.308553672872447, 0.5, ... 0.691446327127553, 0.84129707711564, 0.930048738272289, ... 0.961161141957167, 0.990657542497602, 0.999673496016566]; assert_equal (cdf (pt, xq), ref, 1e-5); ***** test xq = [-2.8, -2.3, -1.8, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 1.8, 2.3, 2.8]; ref = [0.00443959395367343, 0.0353636322020254, 0.0853936076680005, ... 0.122892916352678, 0.243260728154123, 0.352775902406303, ... 0.398931835816165, 0.352775902406307, 0.243260728154123, ... 0.122892916352677, 0.0853936076680006, 0.0353636322020256, ... 0.00443959395367328]; assert_equal (pdf (pt, xq), ref, 1e-5); ***** test pq = [0.005, 0.01, 0.02, 0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95, 0.98, ... 0.99, 0.995]; ref = [-2.44694213045116, -2.28179640154802, -2.06669489811039, ... -1.67939673030492, -1.28207227531929, -0.674573258334612, 0, ... 0.67457325833461, 1.28207227531929, 1.67939673030492, ... 2.06669489811039, 2.28179640154802, 2.44694213045116]; assert_equal (icdf (pt, pq), ref, 1e-5); ***** test xq = [-2.8, -2.3, -1.8, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 1.8, 2.3, 2.8]; ref = [1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3]; assert_equal (segment (pt, xq, []), ref); ***** test p = [0.02, 0.2, 0.5, 0.8, 0.98]; assert_equal (cdf (pt, icdf (pt, p)), p, 1e-6); ***** test r = random (pt, 3, 4); assert_equal (size (r), [3, 4]); assert_equal (size (random (pt, -1)), [0, 0]); assert_equal (size (random (pt, 2, -1, 5)), [2, 0, 5]); ***** test assert_equal (icdf (pt, [-0.1, 1.1]), [NaN, NaN]); ***** test ## The lower tail far below the resolution of 1 - gpcdf pd = paretotails (tan (pi * ((1:200)' / 201 - 0.5)), 0.1, 0.9); [pb, qb] = boundary (pd); lp = lowerparams (pd); q = qb(1) - 1e20; assert_equal (cdf (pd, q), ... pb(1) * (1 + lp(1) * (qb(1) - q) / lp(2)) ^ (-1 / lp(1)), ... -1e-12); ***** error paretotails (1) ***** error paretotails ("a", 0.1, 0.9) ***** error ... paretotails (1, 0.1, 0.9) ***** error ... paretotails (1:10, -0.1, 0.9) ***** error ... paretotails (1:10, 0.1, 1.5) ***** error paretotails (1:10, 0.9, 0.1) ***** error ... paretotails (1:10, 0.1, 0.9, "kernel") ***** error ... paretotails (1:10, 0.1, 0.9, "foo") 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Markov_Models/hmmgenerate.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Markov_Models/hmmgenerate.m ***** demo ## Generate an output sequence and its hidden states from a two-state model ## (a fair and a loaded die). transprob = [0.95, 0.05; 0.10, 0.90]; outprob = [1/6, 1/6, 1/6, 1/6, 1/6, 1/6; 1/10, 1/10, 1/10, 1/10, 1/10, 1/2]; [sequence, states] = hmmgenerate (15, transprob, outprob, ... "statenames", {"fair", "loaded"}) ***** test len = 25; transprob = [0.8, 0.2; 0.4, 0.6]; outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]; [sequence, states] = hmmgenerate (len, transprob, outprob); assert_equal (length (sequence), len); assert_equal (length (states), len); assert_equal (all ((min (sequence) >= 1)(:)), true); assert_equal (all ((max (sequence) <= columns (outprob))(:)), true); assert_equal (all ((min (states) >= 1)(:)), true); assert_equal (all ((max (states) <= rows (transprob))(:)), true); ***** test len = 25; transprob = [0.8, 0.2; 0.4, 0.6]; outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]; symbols = {'A', 'B', 'C'}; statenames = {'One', 'Two'}; [sequence, states] = hmmgenerate (len, transprob, outprob, ... 'symbols', symbols, 'statenames', statenames); assert_equal (length (sequence), len); assert_equal (length (states), len); assert_equal (all ((strcmp (sequence, 'A') + strcmp (sequence, 'B') + ... strcmp (sequence, 'C') == ones (1, len))(:)), true); assert_equal (all ((strcmp (states, 'One') + strcmp (states, 'Two') == ones (1, len))(:)), true); 2 tests, 2 passed, 0 known failure, 0 skipped [inst/Markov_Models/hmmviterbi.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Markov_Models/hmmviterbi.m ***** demo ## Most likely (Viterbi) state path for a two-state, three-symbol model. transprob = [0.8, 0.2; 0.4, 0.6]; outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]; sequence = [1, 2, 1, 1, 3, 2, 3, 1, 2, 3]; vpath = hmmviterbi (sequence, transprob, outprob) ***** demo ## The state path can also be reported using custom state names. transprob = [0.95, 0.05; 0.10, 0.90]; outprob = [1/6, 1/6, 1/6, 1/6, 1/6, 1/6; 1/10, 1/10, 1/10, 1/10, 1/10, 1/2]; [sequence, states] = hmmgenerate (12, transprob, outprob, ... "statenames", {"fair", "loaded"}); vpath = hmmviterbi (sequence, transprob, outprob, ... "statenames", {"fair", "loaded"}) ***** test sequence = [1, 2, 1, 1, 1, 2, 2, 1, 2, 3, 3, 3, ... 3, 2, 3, 1, 1, 1, 1, 3, 3, 2, 3, 1, 3]; transprob = [0.8, 0.2; 0.4, 0.6]; outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]; vpath = hmmviterbi (sequence, transprob, outprob); expected = [1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, ... 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1]; assert_equal (vpath, expected); ***** test sequence = {'A', 'B', 'A', 'A', 'A', 'B', 'B', 'A', 'B', 'C', 'C', 'C', ... 'C', 'B', 'C', 'A', 'A', 'A', 'A', 'C', 'C', 'B', 'C', 'A', 'C'}; transprob = [0.8, 0.2; 0.4, 0.6]; outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]; symbols = {'A', 'B', 'C'}; statenames = {'One', 'Two'}; vpath = hmmviterbi (sequence, transprob, outprob, 'symbols', symbols, ... 'statenames', statenames); expected = {'One', 'One', 'Two', 'Two', 'Two', 'One', 'One', 'One', ... 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'Two', ... 'Two', 'Two', 'Two', 'One', 'One', 'One', 'One', 'One', 'One'}; assert_equal (vpath, expected); ***** test ## The returned path is the true maximum-probability path. A former bug ## scored a spurious transition out of the last state, biasing the final ## states of the path; these cases guard against a regression. transprob = [0.1854, 0.8146; 0.5948, 0.4052]; outprob = [0.5536, 0.4464; 0.2712, 0.7288]; assert_equal (hmmviterbi ([1, 2], transprob, outprob), [2, 2]); ***** test transprob = [0.6056, 0.3944; 0.2036, 0.7964]; outprob = [0.6525, 0.3475; 0.2878, 0.7122]; assert_equal (hmmviterbi ([1, 1, 2, 1], transprob, outprob), [1, 1, 1, 1]); ***** test ## An empty sequence yields an empty path vpath = hmmviterbi ([], [0.8, 0.2; 0.4, 0.6], [0.5, 0.5; 0.3, 0.7]); assert_equal (vpath, zeros (1, 0)); 5 tests, 5 passed, 0 known failure, 0 skipped [inst/Markov_Models/hmmestimate.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Markov_Models/hmmestimate.m ***** demo ## Recover the transition and output matrices of a model from a long ## sequence together with its known sequence of hidden states. transprob = [0.8, 0.2; 0.4, 0.6]; outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]; [sequence, states] = hmmgenerate (1000, transprob, outprob); [transest, outest] = hmmestimate (sequence, states) ***** test sequence = [1, 2, 1, 1, 1, 2, 2, 1, 2, 3, 3, ... 3, 3, 2, 3, 1, 1, 1, 1, 3, 3, 2, 3, 1, 3]; states = [1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, ... 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1]; [transprobest, outprobest] = hmmestimate (sequence, states); expectedtransprob = [0.88235, 0.11765; 0.28571, 0.71429]; expectedoutprob = [0.16667, 0.33333, 0.50000; 1.00000, 0.00000, 0.00000]; assert_equal (transprobest, expectedtransprob, 0.001); assert_equal (outprobest, expectedoutprob, 0.001); ***** test sequence = {'A', 'B', 'A', 'A', 'A', 'B', 'B', 'A', 'B', 'C', 'C', 'C', ... 'C', 'B', 'C', 'A', 'A', 'A', 'A', 'C', 'C', 'B', 'C', 'A', 'C'}; states = {'One', 'One', 'Two', 'Two', 'Two', 'One', 'One', 'One', 'One', ... 'One', 'One', 'One', 'One', 'One', 'One', 'Two', 'Two', 'Two', ... 'Two', 'One', 'One', 'One', 'One', 'One', 'One'}; symbols = {'A', 'B', 'C'}; statenames = {'One', 'Two'}; [transprobest, outprobest] = hmmestimate (sequence, states, 'symbols', ... symbols, 'statenames', statenames); expectedtransprob = [0.88235, 0.11765; 0.28571, 0.71429]; expectedoutprob = [0.16667, 0.33333, 0.50000; 1.00000, 0.00000, 0.00000]; assert_equal (transprobest, expectedtransprob, 0.001); assert_equal (outprobest, expectedoutprob, 0.001); ***** test sequence = [1, 2, 1, 1, 1, 2, 2, 1, 2, 3, 3, 3, ... 3, 2, 3, 1, 1, 1, 1, 3, 3, 2, 3, 1, 3]; states = [1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, ... 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1]; pseudotransitions = [8, 2; 4, 6]; pseudoemissions = [2, 4, 4; 7, 2, 1]; [transprobest, outprobest] = hmmestimate (sequence, states, ... 'pseudotransitions', pseudotransitions, 'pseudoemissions', pseudoemissions); expectedtransprob = [0.851852, 0.148148; 0.352941, 0.647059]; expectedoutprob = [0.178571, 0.357143, 0.464286; ... 0.823529, 0.117647, 0.058824]; assert_equal (transprobest, expectedtransprob, 0.001); assert_equal (outprobest, expectedoutprob, 0.001); 3 tests, 3 passed, 0 known failure, 0 skipped [inst/Markov_Models/hmmtrain.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Markov_Models/hmmtrain.m ***** demo ## Re-estimate a model with Baum-Welch, starting from rough initial guesses. transprob = [0.95, 0.05; 0.10, 0.90]; outprob = [1/6, 1/6, 1/6, 1/6, 1/6, 1/6; 1/10, 1/10, 1/10, 1/10, 1/10, 1/2]; sequence = hmmgenerate (1000, transprob, outprob); transguess = [0.8, 0.2; 0.2, 0.8]; outguess = [1/6, 1/6, 1/6, 1/6, 1/6, 1/6; 1/8, 1/8, 1/8, 1/8, 1/8, 3/8]; [esttr, estout] = hmmtrain (sequence, transguess, outguess) ***** test ## Baum-Welch recovers matrices close to the generating model transprob = [0.9, 0.1; 0.1, 0.9]; outprob = [0.9, 0.1; 0.1, 0.9]; rand ("seed", 42); sequence = hmmgenerate (500, transprob, outprob); transguess = [0.8, 0.2; 0.2, 0.8]; outguess = [0.7, 0.3; 0.3, 0.7]; [esttr, estout] = hmmtrain (sequence, transguess, outguess); assert_equal (size (esttr), [2, 2]); assert_equal (size (estout), [2, 2]); assert_equal (all (abs (sum (esttr, 2) - 1) < 1e-10), true); assert_equal (all (abs (sum (estout, 2) - 1) < 1e-10), true); ***** test ## Baum-Welch never decreases the data log-likelihood transprob = [0.8, 0.2; 0.4, 0.6]; outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]; rand ("seed", 7); sequence = hmmgenerate (200, transprob, outprob); transguess = [0.5, 0.5; 0.5, 0.5]; outguess = [0.4, 0.3, 0.3; 0.2, 0.4, 0.4]; [~, ll0] = hmmdecode (sequence, transguess, outguess); [esttr, estout] = hmmtrain (sequence, transguess, outguess); [~, ll1] = hmmdecode (sequence, esttr, estout); assert_equal (ll1 >= ll0 - 1e-8, true); warning: hmmtrain: algorithm did not converge to within tolerance 1e-06 in 500 iterations. warning: called from hmmtrain at line 375 column 5 __test__ at line 11 column 3 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 294 column 2 ***** test ## Multiple sequences supplied as a cell array transprob = [0.8, 0.2; 0.4, 0.6]; outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]; rand ("seed", 11); s1 = hmmgenerate (60, transprob, outprob); s2 = hmmgenerate (80, transprob, outprob); transguess = [0.6, 0.4; 0.5, 0.5]; outguess = [0.3, 0.3, 0.4; 0.5, 0.3, 0.2]; [esttr, estout] = hmmtrain ({s1, s2}, transguess, outguess); assert_equal (all (abs (sum (esttr, 2) - 1) < 1e-10), true); assert_equal (all (abs (sum (estout, 2) - 1) < 1e-10), true); warning: hmmtrain: algorithm did not converge to within tolerance 1e-06 in 500 iterations. warning: called from hmmtrain at line 375 column 5 __test__ at line 11 column 3 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 294 column 2 ***** test ## Viterbi training runs and returns stochastic matrices. Distinguishable ## states keep both visited; pseudo-counts guard against empty rows. transprob = [0.9, 0.1; 0.2, 0.8]; outprob = [0.8, 0.2; 0.2, 0.8]; rand ("seed", 3); sequence = hmmgenerate (300, transprob, outprob); transguess = [0.8, 0.2; 0.3, 0.7]; outguess = [0.7, 0.3; 0.3, 0.7]; [esttr, estout] = hmmtrain (sequence, transguess, outguess, ... 'algorithm', 'Viterbi', ... 'pseudotransitions', [1, 1; 1, 1], ... 'pseudoemissions', [1, 1; 1, 1]); assert_equal (all (abs (sum (esttr, 2) - 1) < 1e-10), true); assert_equal (all (abs (sum (estout, 2) - 1) < 1e-10), true); ***** test ## Symbols form matches the integer form transprob = [0.8, 0.2; 0.4, 0.6]; outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]; intseq = [1, 2, 1, 1, 3, 2, 2, 1, 3, 3, 1, 2, 1, 1, 2]; symbseq = {'A', 'B', 'A', 'A', 'C', 'B', 'B', 'A', 'C', 'C', ... 'A', 'B', 'A', 'A', 'B'}; transguess = [0.6, 0.4; 0.5, 0.5]; outguess = [0.3, 0.3, 0.4; 0.5, 0.3, 0.2]; [t1, o1] = hmmtrain (intseq, transguess, outguess, 'maxiterations', 5); [t2, o2] = hmmtrain (symbseq, transguess, outguess, 'maxiterations', 5, ... 'symbols', {'A', 'B', 'C'}); assert_equal (t1, t2, 1e-12); assert_equal (o1, o2, 1e-12); warning: hmmtrain: algorithm did not converge to within tolerance 1e-06 in 5 iterations. warning: called from hmmtrain at line 375 column 5 __test__ at line 11 column 3 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 294 column 2 warning: hmmtrain: algorithm did not converge to within tolerance 1e-06 in 5 iterations. warning: called from hmmtrain at line 375 column 5 __test__ at line 12 column 3 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 294 column 2 ***** test ## Several sequences pool their counts, so the estimate follows sequence ## length. MATLAB averages the per-sequence estimates (deviation). s1 = [1, 2, 2, 3, 3, 3, 3, 3]; s2 = [2, 2, 2, 3, 2, 2, 1, 1, 1, 2, 1, 1, 3, 1, 1, 1, 2, 2, 3, 3, 3, 2, 3, 2]; transguess = [0.7, 0.3; 0.4, 0.6]; outguess = [0.5, 0.3, 0.2; 0.2, 0.3, 0.5]; [esttr, estout] = hmmtrain ({s1, s2}, transguess, outguess, ... 'algorithm', 'Viterbi', 'maxiterations', 1, ... 'tolerance', 1e6); assert_equal (esttr, [19/21, 2/21; 0, 1], 1e-14); assert_equal (estout, [9/21, 10/21, 2/21; 0, 2/11, 9/11], 1e-14); ***** test ## Pseudo-counts stay counts on every iteration. MATLAB adds them to the ## normalized estimate from its second iteration on (deviation). seq = [2, 2, 2, 2, 3, 2, 3, 3, 1, 2, 3, 3, 3, 2, 3, 1, 2, 2, 1, 2, ... 3, 3, 1, 2, 3, 1, 3, 3, 2, 1]; transguess = [0.7, 0.3; 0.4, 0.6]; outguess = [0.5, 0.3, 0.2; 0.2, 0.3, 0.5]; [esttr, estout] = hmmtrain (seq, transguess, outguess, ... 'algorithm', 'Viterbi', ... 'pseudotransitions', [2, 1; 1, 3], ... 'pseudoemissions', [1, 2, 1; 3, 1, 2]); assert_equal (esttr, [5/7, 2/7; 1/29, 28/29], 1e-14); assert_equal (estout, [1/8, 6/8, 1/8; 9/32, 9/32, 14/32], 1e-14); ***** warning ... transprob = [0.8, 0.2; 0.4, 0.6]; outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]; rand ("seed", 1); sequence = hmmgenerate (50, transprob, outprob); hmmtrain (sequence, [0.5, 0.5; 0.5, 0.5], [0.4, 0.3, 0.3; 0.2, 0.4, 0.4], ... 'maxiterations', 1); ***** error hmmtrain ([1, 2], [0.8, 0.2; 0.4, 0.6]) ***** error ... hmmtrain ([1, 2], [0.8, 0.2; 0.4, 0.6; 0.1, 0.9], [0.5, 0.5; 0.1, 0.9]) ***** error ... hmmtrain ([1, 2], [0.8, 0.2; 0.4, 0.6], [0.5, 0.5]) ***** error ... hmmtrain ([1, 2], [0.8, 0.2; 0.4, 0.6], [0.5, 0.5; 0.1, 0.9], ... 'algorithm', 'nope') ***** error ... hmmtrain ([1, 5], [0.8, 0.2; 0.4, 0.6], [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]) 13 tests, 13 passed, 0 known failure, 0 skipped [inst/Markov_Models/hmmdecode.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Markov_Models/hmmdecode.m ***** demo ## Posterior probability of each state at every step of an observed sequence. transprob = [0.95, 0.05; 0.10, 0.90]; outprob = [1/6, 1/6, 1/6, 1/6, 1/6, 1/6; 1/10, 1/10, 1/10, 1/10, 1/10, 1/2]; sequence = hmmgenerate (10, transprob, outprob); [pstates, logpseq] = hmmdecode (sequence, transprob, outprob) ***** test transprob = [0.8, 0.2; 0.4, 0.6]; outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]; sequence = [1, 2, 1, 1, 1, 2, 2, 1, 2, 3]; pstates = hmmdecode (sequence, transprob, outprob); assert_equal (size (pstates), [2, 10]); assert_equal (all (abs (sum (pstates, 1) - 1) < 1e-10), true); assert_equal (all (pstates(:) >= 0 & pstates(:) <= 1), true); ***** test transprob = [0.8, 0.2; 0.4, 0.6]; outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]; sequence = [1, 2, 1, 1, 1, 2, 2, 1, 2, 3]; [pstates, logpseq] = hmmdecode (sequence, transprob, outprob); ## Independent brute-force forward algorithm for the log probability nstate = 2; alpha = transprob(1, :) .* outprob(:, sequence(1))'; for t = 2:numel (sequence) alpha = (alpha * transprob) .* outprob(:, sequence(t))'; endfor assert_equal (logpseq, log (sum (alpha)), 1e-10); ***** test ## Symbols form must match the integer form transprob = [0.8, 0.2; 0.4, 0.6]; outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]; sequence = [1, 2, 1, 1, 1, 2, 2, 1, 2, 3]; symbseq = {'A', 'B', 'A', 'A', 'A', 'B', 'B', 'A', 'B', 'C'}; p1 = hmmdecode (sequence, transprob, outprob); p2 = hmmdecode (symbseq, transprob, outprob, 'symbols', {'A', 'B', 'C'}); assert_equal (p1, p2, 1e-12); ***** test ## Scaled forward/backward reproduce the posterior gamma transprob = [0.9, 0.1; 0.3, 0.7]; outprob = [0.5, 0.5; 0.1, 0.9]; sequence = [1, 2, 2, 1, 2]; [pstates, logpseq, fs, bs, s] = hmmdecode (sequence, transprob, outprob); recovered = fs .* bs; recovered(:, 1) = []; assert_equal (recovered, pstates, 1e-12); assert_equal (logpseq, sum (log (s)), 1e-12); ***** test ## Empty sequence: no columns in the posterior, unit probability transprob = [0.8, 0.2; 0.4, 0.6]; outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]; [pstates, logpseq] = hmmdecode ([], transprob, outprob); assert_equal (size (pstates), [2, 0]); assert_equal (logpseq, 0, 1e-12); ***** error hmmdecode ([1, 2]) ***** error ... hmmdecode ([1, 2], [0.8, 0.2; 0.4, 0.6; 0.1, 0.9], [0.5, 0.5; 0.1, 0.9]) ***** error ... hmmdecode ([1, 2], [0.8, 0.2; 0.4, 0.6], [0.5, 0.5]) ***** error ... hmmdecode ([1, 5], [0.8, 0.2; 0.4, 0.6], [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]) ***** error ... hmmdecode ([1, 2], [0.8, 0.2; 0.4, 0.6], [0.2, 0.4, 0.4; 0.7, 0.2, 0.1], ... 'symbols', {'A', 'B'}) 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Random_Sampling/mhsample.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Random_Sampling/mhsample.m ***** demo ## Define function to sample rng (42); d = 2; mu = [-1; 2]; Sigma = rand (d); Sigma = (Sigma + Sigma'); Sigma += eye (d) * abs (eigs (Sigma, 1, 'sa')) * 1.1; pdf = @(x)(2*pi)^(-d/2)*det (Sigma)^-.5*exp (-.5*sum ((x.'-mu).*(Sigma\(x.'-mu)),1)); ## Inputs start = ones (1, 2); nsamples = 500; sym = true; K = 500; m = 10; proprnd = @(x) (rand (size (x)) - .5) * 3 + x; [smpl, accept] = mhsample (start, nsamples, 'pdf', pdf, 'proprnd', proprnd, ... 'symmetric', sym, 'burnin', K, 'thin', m); figure; hold on; plot (smpl(:, 1), smpl(:, 2), 'x'); [x, y] = meshgrid (linspace (-6, 4), linspace (-3, 7)); z = reshape (pdf ([x(:), y(:)]), size (x)); mesh (x, y, z, 'facecolor', 'None'); ## Using sample points to find the volume of half a sphere with radius of .5 f = @(x) ((.25-(x(:,1)+1).^2-(x(:,2)-2).^2).^.5.*(((x(:,1)+1).^2+(x(:,2)-2).^2)<.25)).'; int = mean (f(smpl) ./ pdf (smpl)); errest = std (f(smpl) ./ pdf (smpl)) / nsamples ^ .5; trueerr = abs (2 / 3 * pi * .25 ^ (3 / 2) - int); printf ("Monte Carlo integral estimate int f(x) dx = %f\n", int); printf ("Monte Carlo integral error estimate %f\n", errest); printf ("The actual error %f\n", trueerr); mesh (x, y, reshape (f([x(:), y(:)]), size (x)), 'facecolor', 'None'); ***** demo ## Integrate truncated normal distribution to find normalization constant rng (42); pdf = @(x) exp (-.5*x.^2)/(pi^.5*2^.5); nsamples = 1e3; proprnd = @(x) (rand (size (x)) - .5) * 3 + x; [smpl, accept] = mhsample (1, nsamples, 'pdf', pdf, 'proprnd', proprnd, ... 'symmetric', true, 'thin', 4); f = @(x) exp (-.5 * x .^ 2) .* (x >= -2 & x <= 2); x = linspace (-3, 3, 1000); area (x, f(x)); xlabel ('x'); ylabel ('f(x)'); int = mean (f(smpl) ./ pdf (smpl)); errest = std (f(smpl) ./ pdf (smpl)) / nsamples^ .5; trueerr = abs (erf (2 ^ .5) * 2 ^ .5 * pi ^ .5 - int); printf ("Monte Carlo integral estimate int f(x) dx = %f\n", int); printf ("Monte Carlo integral error estimate %f\n", errest); printf ("The actual error %f\n", trueerr); ***** test nchain = 1e4; start = rand (nchain, 1); nsamples = 1e3; pdf = @(x) exp (-.5*(x-1).^2)/(2*pi)^.5; proppdf = @(x, y) 1/3; proprnd = @(x) 3 * (rand (size (x)) - .5) + x; [smpl, accept] = mhsample (start, nsamples, 'pdf', pdf, 'proppdf', proppdf, ... 'proprnd', proprnd, 'thin', 2, 'nchain', nchain, ... 'burnin', 0); assert_equal (mean (mean (smpl, 1), 3), 1, .01); assert_equal (mean (var (smpl, 1), 3), 1, .01) ***** error mhsample (); ***** error mhsample (1); ***** error mhsample (1, 1); ***** error mhsample (1, 1, 'pdf', @(x)x); ***** error mhsample (1, 1, 'pdf', @(x)x, 'proprnd', @(x)x+rand (size (x))); 6 tests, 6 passed, 0 known failure, 0 skipped [inst/Random_Sampling/pearsrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Random_Sampling/pearsrnd.m ***** demo ## Identify the Pearson type matching a set of moments rng (42); randg ('state', 42); [r, type, coefs] = pearsrnd (0, 1, 0.75, 4) ***** demo ## Draw a sample with a target mean, sd, skewness, and kurtosis rng (42); randg ('state', 42); r = pearsrnd (10, 2, 1, 5, 1, 1000); [mean(r), std(r)] ***** test [~, type, coefs] = pearsrnd (0, 1, 0, 3); assert_equal (type, 0); assert_equal (coefs, [1, 0, 0], 1e-12); ***** test [~, type, coefs] = pearsrnd (0, 1, 0, 4.5); assert_equal (type, 7); assert_equal (coefs, [0.666666666666667, 0, 0.111111111111111], 1e-12); ***** test [~, type, coefs] = pearsrnd (0, 1, 0, 2.5); assert_equal (type, 2); assert_equal (coefs, [1.42857142857143, 0, -0.142857142857143], 1e-12); ***** test [~, type, coefs] = pearsrnd (0, 1, 0.5, 3.5); assert_equal (type, 4); assert_equal (coefs, ... [0.946428571428571, 0.232142857142857, 0.0178571428571429], 1e-12); ***** test [~, type, coefs] = pearsrnd (0, 1, 0.75, 4); assert_equal (type, 6); assert_equal (coefs, ... [0.938524590163934, 0.344262295081967, 0.0204918032786885], 1e-12); ***** test [~, type, coefs] = pearsrnd (2, 3, 1, 5); assert_equal (type, 4); assert_equal (coefs, [0.85, 0.4, 0.05], 1e-12); ***** test [~, type, coefs] = pearsrnd (0, 1, 1, 4.5); assert_equal (type, 3); assert_equal (coefs, [1, 0.5, 0], 1e-12); ***** test [~, type, coefs] = pearsrnd (0, 1, 2, 9); assert_equal (type, 3); assert_equal (coefs, [1, 1, 0], 1e-12); ***** test cases = [0 1 0 3; 0 1 0 4.5; 0 1 0 2.5; 0 1 0.5 3.5; 0 1 0.75 4; ... 2 3 1 5; 0 1 1 4.5; 0 1 2 9]; ## Seed per case, not once for the run: a single seed at the top leaves each ## case starting wherever the ones before it left the stream, so the sample ## moments below are only as reproducible as the number of draws every ## earlier case happens to take. randg needs seeding too: the Pearson ## types are drawn through betarnd, gamrnd and trnd, and seeding rand and ## randn alone leaves that stream running on from wherever it was. for i = 1:rows (cases) rand ("state", 42); randn ("state", 42); randg ("state", 42); m = cases(i,1); s = cases(i,2); sk = cases(i,3); ku = cases(i,4); r = pearsrnd (m, s, sk, ku, 200000, 1); mr = mean (r); sr = std (r); g1 = mean (((r - mr) ./ sr) .^ 3); g2 = mean (((r - mr) ./ sr) .^ 4); assert_equal (mr, m, 0.05 .* s + 0.02); assert_equal (sr, s, 0.05 .* s + 0.02); assert_equal (g1, sk, 0.1); assert_equal (g2, ku, 0.4); endfor ***** test rand ("state", 7); randn ("state", 7); r = pearsrnd (0, 1, -1, 5, 100000, 1); assert_equal (mean (((r - mean (r)) ./ std (r)) .^ 3), -1, 0.1); ***** test assert_equal (size (pearsrnd (0, 1, 0, 3, 3, 4)), [3, 4]); assert_equal (size (pearsrnd (0, 1, 0, 3, [2, 5])), [2, 5]); assert_equal (isscalar (pearsrnd (0, 1, 0, 3)), true); assert_equal (size (pearsrnd (0, 1, 0, 3, -1)), [0, 0]); assert_equal (size (pearsrnd (0, 1, 0, 3, 2, -1, 5)), [2, 0, 5]); ***** error pearsrnd (0, 1, 0) ***** error ... pearsrnd (0, 1, 0, [3, 4]) ***** error pearsrnd (0, -1, 0, 3) ***** error ... pearsrnd (0, 1, 1, 1.5) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Random_Sampling/qrandn.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Random_Sampling/qrandn.m ***** demo z = qrandn (-5, 5e6); [c x] = hist (z,linspace (-1.5,1.5,200),1); figure (1) plot (x,c,'r.'); axis tight; axis ([-1.5,1.5]); z = qrandn (-0.14286, 5e6); [c x] = hist (z,linspace (-2,2,200),1); figure (2) plot (x,c,'r.'); axis tight; axis ([-2,2]); z = qrandn (2.75, 5e6); [c x] = hist (z,linspace (-1e3,1e3,1e3),1); figure (3) semilogy (x,c,'r.'); axis tight; axis ([-100,100]); # --------- # Figures from the reference paper. ***** error qrandn ([1 2], 1) ***** error qrandn (4, 1) ***** error qrandn (3, 1) ***** error qrandn (2.5, 1, 2, 3) ***** error qrandn (2.5) ***** test q = 1.5; s = [2, 3]; z = qrandn (q, s); assert_equal (isnumeric (z) && isequal (size (z), s), true); 6 tests, 6 passed, 0 known failure, 0 skipped [inst/Random_Sampling/johnsrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Random_Sampling/johnsrnd.m ***** demo ## Fit a Johnson distribution to four quantiles and identify its type rng (42); [r, type, coefs] = johnsrnd ([-1, -0.25, 0.75, 3]) ***** demo ## Draw a sample and check its shape rng (42); r = johnsrnd ([-1, -0.25, 0.75, 3], 1, 1000); hist (r, 50); ***** test [~, type, coefs] = johnsrnd ([-1.5, -0.5, 0.5, 1.5]); assert_equal (type, "SN"); assert_equal (coefs, [0, 1, 0, 1], 1e-12); ***** test [~, type, coefs] = johnsrnd ([-1, -0.25, 0.75, 3]); assert_equal (type, "SU"); assert_equal (coefs, [-0.843945656908448, 1.03904346061751, ... -0.5, 0.741619848709566], 1e-10); ***** test [~, type, coefs] = johnsrnd ([0.2, 0.9, 1.4, 1.8]); assert_equal (type, "SU"); assert_equal (coefs, ... [1.76613094093528, 2.25444447413448, 1.9, 0.845154254728516], 1e-10); ***** test [~, type, coefs] = johnsrnd ([1, 2, 4, 9]); assert_equal (type, "SU"); assert_equal (coefs, [-1.5, 1.03904346061751, 1, 0.894427190999916], 1e-10); ***** test [~, type, coefs] = johnsrnd ([-3, -0.75, 0.25, 1]); assert_equal (type, "SU"); assert_equal (coefs, [0.843945656908448, 1.03904346061751, ... 0.5, 0.741619848709566], 1e-10); ***** test q = [0.1, 0.3, 0.8, 0.95]; [~, type, c] = johnsrnd (q); assert_equal (type, "SB"); z = [-1.5, -0.5, 0.5, 1.5]; xz = c(3) + c(4) ./ (1 + exp (-(z - c(1)) ./ c(2))); assert_equal (xz, q, 1e-12); ***** test q = [0, 1, 3, 7]; [~, type, c] = johnsrnd (q); assert_equal (type, "SL"); z = [-1.5, -0.5, 0.5, 1.5]; xz = c(3) + c(4) .* exp ((z - c(1)) ./ c(2)); assert_equal (xz, q, 1e-10); ***** test r = johnsrnd ([-1, -0.25, 0.75, 3], 3, 4); assert_equal (size (r), [3, 4]); assert_equal (all (isfinite (r), 'all'), true); assert_equal (size (johnsrnd ([-1, -0.25, 0.75, 3], -1)), [0, 0]); assert_equal (size (johnsrnd ([-1, -0.25, 0.75, 3], 2, -1, 5)), [2, 0, 5]); ***** test [r, ~, c] = johnsrnd ([0.1, 0.3, 0.8, 0.95], 1, 500); assert_equal (all (r > c(3) & r < c(3) + c(4), 'all'), true); ***** test [~, type, coefs] = johnsrnd ([-7, -3, -1, 0]); assert_equal (type, "SL"); assert_equal (coefs, [1.5, -1.44269504088896, 1, -1], 1e-10); assert_equal (isreal (coefs), true); ***** test qnorm = [.5, 1, 1.5, 2]; q = [16.7000, 18.2086, 19.5376, 21.7263]; [r, type, coefs] = johnsrnd ([qnorm; q], 0); assert_equal (r, []); assert_equal (type, "SU"); assert_equal (coefs, [1.0920, 0.5829, 18.4382, 1.4493], 1e-4); ***** test [~, type, coefs] = johnsrnd ([-1.5, -0.5, 0.5, 1.5; -1, -0.25, 0.75, 3], 0); [~, type2, coefs2] = johnsrnd ([-1, -0.25, 0.75, 3]); assert_equal (type, type2); assert_equal (coefs, coefs2, 1e-12); ***** error johnsrnd () ***** error ... johnsrnd ([1, 2, 3]) ***** error ... johnsrnd ("abcd") ***** error ... johnsrnd (ones (3, 4)) ***** error ... johnsrnd ([1, 2, 2, 3]) ***** error ... johnsrnd ([4, 3, 2, 1]) ***** error ... johnsrnd ([1, NaN, 3, 4]) ***** error ... johnsrnd ([1.5, 0.5, -0.5, -1.5; -1, -0.25, 0.75, 3]) ***** error ... johnsrnd ([-1.5, -0.5, 0.5, 1; -1, -0.25, 0.75, 3]) 21 tests, 21 passed, 0 known failure, 0 skipped [inst/Random_Sampling/slicesample.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Random_Sampling/slicesample.m ***** demo ## Define function to sample rng (42); rande ('state', 42); d = 2; mu = [-1; 2]; Sigma = rand (d); Sigma = (Sigma + Sigma'); Sigma += eye (d)*abs (eigs (Sigma, 1, 'sa')) * 1.1; pdf = @(x)(2*pi)^(-d/2)*det (Sigma)^-.5*exp (-.5*sum ((x.'-mu).*(Sigma\(x.'-mu)),1)); ## Inputs start = ones (1,2); nsamples = 500; K = 500; m = 10; [smpl, accept] = slicesample (start, nsamples, 'pdf', pdf, 'burnin', K, 'thin', m, 'width', [20, 30]); figure; hold on; plot (smpl(:,1), smpl(:,2), 'x'); [x, y] = meshgrid (linspace (-6,4), linspace (-3,7)); z = reshape (pdf ([x(:), y(:)]), size (x)); mesh (x, y, z, 'facecolor', 'None'); ## Using sample points to find the volume of half a sphere with radius of .5 f = @(x) ((.25-(x(:,1)+1).^2-(x(:,2)-2).^2).^.5.*(((x(:,1)+1).^2+(x(:,2)-2).^2)<.25)).'; int = mean (f(smpl) ./ pdf (smpl)); errest = std (f(smpl) ./ pdf (smpl)) / nsamples^.5; trueerr = abs (2/3*pi*.25^(3/2)-int); fprintf ("Monte Carlo integral estimate int f(x) dx = %f\n", int); fprintf ("Monte Carlo integral error estimate %f\n", errest); fprintf ("The actual error %f\n", trueerr); mesh (x,y,reshape (f([x(:), y(:)]), size (x)), 'facecolor', 'None'); ***** demo ## Integrate truncated normal distribution to find normalization constant rng (42); rande ('state', 42); pdf = @(x) exp (-.5*x.^2)/(pi^.5*2^.5); nsamples = 1e3; [smpl, accept] = slicesample (1, nsamples, 'pdf', pdf, 'thin', 4); f = @(x) exp (-.5 * x .^ 2) .* (x >= -2 & x <= 2); x = linspace (-3, 3, 1000); area (x, f(x)); xlabel ('x'); ylabel ('f(x)'); int = mean (f(smpl) ./ pdf (smpl)); errest = std (f(smpl) ./ pdf (smpl)) / nsamples ^ 0.5; trueerr = abs (erf (2 ^ 0.5) * 2 ^ 0.5 * pi ^ 0.5 - int); fprintf ("Monte Carlo integral estimate int f(x) dx = %f\n", int); fprintf ("Monte Carlo integral error estimate %f\n", errest); fprintf ("The actual error %f\n", trueerr); ***** test start = 0.5; nsamples = 1e3; pdf = @(x) exp (-.5*(x-1).^2)/(2*pi)^.5; [smpl, accept] = slicesample (start, nsamples, 'pdf', pdf, 'thin', 2, 'burnin', 0, 'width', 5); assert_equal (mean (smpl, 1), 1, .15); assert_equal (var (smpl, 1), 1, .25); ***** test rand ('twister', 42); s1 = slicesample (0, 2000, 'logpdf', @(z) -z .^ 2 / 2, 'width', 5); assert_equal (mean (s1), 0, 0.15); assert_equal (std (s1), 1, 0.15); ***** test ## the same target given as a density must agree to within sampling error rand ('twister', 42); sp = slicesample (0, 2000, 'pdf', @(z) exp (-z .^ 2 / 2), 'width', 5); rand ('twister', 42); sl = slicesample (0, 2000, 'logpdf', @(z) -z .^ 2 / 2, 'width', 5); assert_equal (mean (sp), mean (sl), 0.15); assert_equal (std (sp), std (sl), 0.15); ***** test ## MATLAB accepts both, so this must produce a usable chain rather than ## the log of a log rand ('twister', 7); sb = slicesample (1, 500, 'pdf', @(z) exp (-z .^ 2 / 2), ... 'logpdf', @(z) -z .^ 2 / 2, 'width', 5); assert_equal (size (sb), [500, 1]); assert_equal (mean (sb), 0, 0.25); ***** test assert_equal (size (slicesample (1, 0, 'pdf', @(z) exp (-z .^ 2 / 2))), [0, 1]); assert_equal (size (slicesample (1, -5, 'pdf', @(z) exp (-z .^ 2 / 2))), [0, 1]); ***** error ... slicesample (1, 50, 'pdf', @(z) exp (-z .^ 2 / 2), 'nosuch', 1) ***** error ... slicesample (1, 50, 'pdf', @(z) exp (-z .^ 2 / 2), 'width', -1) ***** error ... slicesample (1, 50, 'pdf', @(z) exp (-z .^ 2 / 2), 'width', 0) ***** error slicesample (); ***** error slicesample (1); ***** error slicesample (1, 1); 11 tests, 11 passed, 0 known failure, 0 skipped [inst/Dimensionality_Reduction/rica.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Dimensionality_Reduction/rica.m ***** demo ## Learn two features from data with the default (random) start. X = [1, 2, 3, 4; 2, 3, 4, 5; -1, 0, 1, 2; 3, 1, 4, 1; 0, 2, 1, 3]; Mdl = rica (X, 2, "IterationLimit", 200); Z = transform (Mdl, X) ***** shared X, W0 X = reshape (mod ((1:60)*7, 13), 12, 5) - 6; W0 = reshape (mod ((1:15)*3, 7), 5, 3) - 3; ***** test Mdl = rica (X, 3, "InitialTransformWeights", W0, "Lambda", 1, ... "Standardize", false, "IterationLimit", 1000); ## transform is X * TransformWeights, with unit-length weight columns assert_equal (transform (Mdl, X), X * Mdl.TransformWeights, 1e-12); assert_equal (sqrt (sum (Mdl.TransformWeights .^ 2, 1)), [1, 1, 1], 1e-10); assert_equal (size (Mdl.TransformWeights), [5, 3]); ***** test ## The solver reaches a low objective value (MATLAB's is 194.5156). Mdl = rica (X, 3, "InitialTransformWeights", W0, "Lambda", 1, ... "Standardize", false, "IterationLimit", 1000); assert_equal (Mdl.FitInfo.Objective(end) < 195, true); ***** test ## The objective value stored in FitInfo matches a direct evaluation. Mdl = rica (X, 3, "InitialTransformWeights", W0, "Lambda", 1, ... "Standardize", false, "IterationLimit", 1000); W = Mdl.TransformWeights; Z = X * W; f = sum (sumsq (X * (W * W') - X)) + sum (sum (0.5 * log (cosh (2 * Z)))); assert_equal (Mdl.FitInfo.Objective(end), f, 1e-6); ***** test ## The 'exp' contrast objective matches a direct evaluation. Mdl = rica (X, 3, "InitialTransformWeights", W0, "Lambda", 1, ... "Standardize", false, "IterationLimit", 200, ... "ContrastFcn", "exp"); W = Mdl.TransformWeights; Z = X * W; f = sum (sumsq (X * (W * W') - X)) + sum (sum (-exp (-Z .^ 2 / 2))); assert_equal (Mdl.FitInfo.Objective(end), f, 1e-6); ***** test ## The 'sqrt' contrast objective matches a direct evaluation, the smoothing ## constant included. Mdl = rica (X, 3, "InitialTransformWeights", W0, "Lambda", 1, ... "Standardize", false, "IterationLimit", 200, ... "ContrastFcn", "sqrt"); W = Mdl.TransformWeights; Z = X * W; f = sum (sumsq (X * (W * W') - X)) + sum (sum (sqrt (Z .^ 2 + 1e-8))); assert_equal (Mdl.FitInfo.Objective(end), f, 1e-6); ***** test ## The smoothing constant is visible only where a projection is zero, so it ## is pinned there: one column of X projected onto a weight orthogonal to it. Xz = [1 0; -2 0; 3 0; 0 0]; Wz = [0; 1]; M = rica (Xz, 1, "InitialTransformWeights", Wz, "IterationLimit", 0, ... "Standardize", false, "ContrastFcn", "sqrt"); assert_equal (M.FitInfo.Objective(1), 14 + 4 * sqrt (1e-8), 1e-12); ***** test ## Each contrast gives its own objective; they are not interchangeable. args = {"InitialTransformWeights", W0, "Standardize", false, ... "IterationLimit", 0}; f1 = rica (X, 3, args{:}, "ContrastFcn", "logcosh").FitInfo.Objective(1); f2 = rica (X, 3, args{:}, "ContrastFcn", "exp").FitInfo.Objective(1); f3 = rica (X, 3, args{:}, "ContrastFcn", "sqrt").FitInfo.Objective(1); assert_equal (f1 != f2 && f2 != f3 && f1 != f3, true); ***** test ## Standardize centers and scales the data before transforming. Mdl = rica (X, 2, "Standardize", true, "IterationLimit", 100, ... "InitialTransformWeights", W0(:,1:2)); assert_equal (size (Mdl.Mu), [5, 1]); assert_equal (size (Mdl.Sigma), [5, 1]); ***** test ## FitInfo carries the whole trajectory, not just its final value: two ## columns of equal length, Iteration the 0-based index, Objective the ## objective at the starting weights first and the solution last Mdl = rica (X, 3, "InitialTransformWeights", W0, "Lambda", 1, ... "Standardize", false, "IterationLimit", 1000); it = Mdl.FitInfo.Iteration; ob = Mdl.FitInfo.Objective; assert_equal (columns (it), 1); assert_equal (size (ob), size (it)); assert_equal (it, (0:numel (ob) - 1)'); assert_equal (all (diff (ob) <= 1e-10), true); ## the first entry is the objective at the starting weights, which is what ## a fit allowed no iterations at all reports M0 = rica (X, 3, "InitialTransformWeights", W0, "Lambda", 1, ... "Standardize", false, "IterationLimit", 0); assert_equal (numel (M0.FitInfo.Objective), 1); assert_equal (ob(1), M0.FitInfo.Objective(1), 1e-12); ***** test ## a capped run stops with one entry per iteration plus the starting point Mdl = rica (X, 3, "InitialTransformWeights", W0, "Lambda", 1, ... "Standardize", false, "IterationLimit", 5); assert_equal (numel (Mdl.FitInfo.Objective) <= 6, true); assert_equal (Mdl.FitInfo.Iteration(1), 0); ***** test ## 'lbfgs' reaches the optimum the default solver reaches args = {"InitialTransformWeights", W0, "Lambda", 1, ... "Standardize", false, "IterationLimit", 1000}; Mq = rica (X, 3, args{:}); Ml = rica (X, 3, args{:}, "Solver", "lbfgs"); assert_equal (Ml.FitInfo.Objective(end), Mq.FitInfo.Objective(end), 1e-6); ***** test ## The trajectory starts at the initial weights whichever solver ran args = {"InitialTransformWeights", W0, "IterationLimit", 20}; Mq = rica (X, 3, args{:}); Ml = rica (X, 3, args{:}, "Solver", "lbfgs"); assert_equal (Ml.FitInfo.Iteration(1), 0); assert_equal (Ml.FitInfo.Objective(1), Mq.FitInfo.Objective(1), 1e-10); ***** test ## The solver that ran is recorded Mdl = rica (X, 3, "InitialTransformWeights", W0, "Solver", "lbfgs"); assert_equal (Mdl.ModelParameters.Solver, "lbfgs"); ***** error ... rica (X, 3, "Solver", "bogus") ***** error ... rica (X, 3, "Solver", 5) ***** error rica (ones (5, 3)) ***** error rica ({1, 2}, 1) ***** error rica ([1, Inf; 2, 3], 1) ***** error rica (ones (5, 3), 0) ***** error rica (ones (5, 3), 1.5) ***** error ... rica (ones (4, 5), 2, "InitialTransformWeights", ones (3, 3)) ***** test ## The NonGaussianityIndicator pair reaches the model through rica. Mdl = rica (X, 3, "InitialTransformWeights", W0, "IterationLimit", 100, ... "NonGaussianityIndicator", [1; -1; 1]); assert_equal (Mdl.NonGaussianityIndicator, [1; -1; 1]); ***** error ... rica (ones (4, 5), 2, "ContrastFcn", "bogus", "InitialTransformWeights", ones (5, 2)) ***** error ... rica (ones (4, 5), 2, "bogus", 1) 24 tests, 24 passed, 0 known failure, 0 skipped [inst/Dimensionality_Reduction/princomp.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Dimensionality_Reduction/princomp.m ***** shared COEFF,SCORE,latent,tsquare,m,x,R,V,lambda,i,S,F ***** test x=[7 4 3 4 1 8 6 3 5 8 6 1 8 5 7 7 2 9 5 3 3 9 5 8 7 4 5 8 2 2]; R = corrcoef (x); [V, lambda] = eig (R); [~, i] = sort (diag (lambda), 'descend'); #arrange largest PC first S = V(:, i) * diag (sqrt (diag (lambda)(i))); ## contribution of first 2 PCs to each original variable ***** assert_equal (diag (S(:, 1:2)*S(:, 1:2)'), [0.8662; 0.8420; 0.9876], 1E-4); B = V(:, i) * diag ( 1./ sqrt (diag (lambda)(i))); F = zscore (x)*B; [COEFF,SCORE,latent,tsquare] = princomp (zscore (x, 1)); ***** assert_equal (tsquare,sumsq (F, 2),1E4*eps); ***** test x=[1,2,3;2,1,3]'; [COEFF,SCORE,latent,tsquare] = princomp (x); m=[sqrt(2),sqrt(2);sqrt(2),-sqrt(2);-2*sqrt(2),0]/2; m(:,1) = m(:,1)*sign (COEFF(1,1)); m(:,2) = m(:,2)*sign (COEFF(1,2)); ***** assert_equal (COEFF,m(1:2,:),10*eps); ***** assert_equal (SCORE,-m,10*eps); ***** assert_equal (latent,[1.5;.5],10*eps); ***** assert_equal (tsquare,[4;4;4]/3,10*eps); ***** test x=x'; [COEFF,SCORE,latent,tsquare] = princomp (x); m=[sqrt(2),sqrt(2),0;-sqrt(2),sqrt(2),0;0,0,2]/2; m(:,1) = m(:,1)*sign (COEFF(1,1)); m(:,2) = m(:,2)*sign (COEFF(1,2)); m(:,3) = m(:,3)*sign (COEFF(3,3)); ***** assert_equal (COEFF,m,10*eps); ***** assert_equal (SCORE(:,1),-m(1:2,1),10*eps); ***** assert_equal (SCORE(:,2:3),zeros (2),10*eps); ***** assert_equal (latent,[1;0;0],10*eps); ***** assert_equal (tsquare,[0.5;0.5],10*eps) ***** test [COEFF,SCORE,latent,tsquare] = princomp (x, 'econ'); ***** assert_equal (COEFF,m(:, 1),10*eps); ***** assert_equal (SCORE,-m(1:2,1),10*eps); ***** assert_equal (latent,[1],10*eps); ***** assert_equal (tsquare,[0.5;0.5],10*eps) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Dimensionality_Reduction/ReconstructionICA.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Dimensionality_Reduction/ReconstructionICA.m ***** shared X, W0 X = reshape (mod ((1:60)*7, 13), 12, 5) - 6; W0 = reshape (mod ((1:15)*3, 7), 5, 3) - 3; ***** test ## Construct the object directly and check its properties. Mdl = ReconstructionICA (X, 3, "InitialTransformWeights", W0, ... "Lambda", 1, "IterationLimit", 500); assert_equal (isa (Mdl, "ReconstructionICA"), true); assert_equal (Mdl.NumPredictors, 5); assert_equal (Mdl.NumLearnedFeatures, 3); assert_equal (size (Mdl.TransformWeights), [5, 3]); assert_equal (Mdl.InitialTransformWeights, W0); assert_equal (isfield (Mdl.FitInfo, "Objective"), true); ***** test ## The transform method projects onto the (unit-column) weights. Mdl = ReconstructionICA (X, 3, "InitialTransformWeights", W0, ... "IterationLimit", 500); Z = transform (Mdl, X); assert_equal (Z, X * Mdl.TransformWeights, 1e-12); assert_equal (sqrt (sum (Mdl.TransformWeights .^ 2, 1)), [1, 1, 1], 1e-10); ***** test ## The transform method standardizes new data when the model does. Mdl = ReconstructionICA (X, 2, "Standardize", true, "IterationLimit", 100, ... "InitialTransformWeights", W0(:,1:2)); Z = transform (Mdl, X); Xs = (X - Mdl.Mu') ./ Mdl.Sigma'; assert_equal (Z, Xs * Mdl.TransformWeights, 1e-12); ***** test ## Mu and Sigma are columns, one entry per predictor, as MATLAB reports them Mdl = ReconstructionICA (X, 2, "Standardize", true, "IterationLimit", 100, ... "InitialTransformWeights", W0(:,1:2)); assert_equal (size (Mdl.Mu), [5, 1]); assert_equal (size (Mdl.Sigma), [5, 1]); assert_equal (Mdl.Mu, mean (X)', 1e-12); assert_equal (Mdl.Sigma, std (X)', 1e-12); ***** test ## The default constructor returns an empty model. Mdl = ReconstructionICA (); assert_equal (isempty (Mdl.TransformWeights), true); ***** test ## NonGaussianityIndicator defaults to one per feature, all +1. Mdl = ReconstructionICA (X, 3, "InitialTransformWeights", W0, ... "IterationLimit", 100); assert_equal (Mdl.NonGaussianityIndicator, [1; 1; 1]); ***** test ## A given indicator is held as a column, whatever shape it arrives in. Mdl = ReconstructionICA (X, 3, "InitialTransformWeights", W0, ... "IterationLimit", 100, ... "NonGaussianityIndicator", [1, -1, 1]); assert_equal (Mdl.NonGaussianityIndicator, [1; -1; 1]); ***** test ## The indicator signs each feature's contrast term, so it moves the fit. args = {"InitialTransformWeights", W0, "IterationLimit", 200}; Mdl = ReconstructionICA (X, 3, args{:}); Neg = ReconstructionICA (X, 3, args{:}, ... "NonGaussianityIndicator", [-1; 1; 1]); assert_equal (isequal (Mdl.TransformWeights, Neg.TransformWeights), false); ***** test ## All +1 is the default, so it must reproduce the default fit exactly. args = {"InitialTransformWeights", W0, "IterationLimit", 200}; Mdl = ReconstructionICA (X, 3, args{:}); Pos = ReconstructionICA (X, 3, args{:}, ... "NonGaussianityIndicator", [1; 1; 1]); assert_equal (Pos.TransformWeights, Mdl.TransformWeights); ***** test ## Objective against MATLAB R2024a: 801.1816174574 and 197.5588279632. t = (1:80)'; Xr = double ([mod(t*7,11)-5, mod(t*13,17)-8, mod(t*5,7)-3]); args = {"InitialTransformWeights", [1, 0; 0, 1; 1, 1], "Lambda", 1, ... "ContrastFcn", "logcosh", "IterationLimit", 1000, ... "Solver", "lbfgs", "GradientTolerance", 1e-10, ... "StepTolerance", 1e-10}; Mdl = ReconstructionICA (Xr, 2, args{:}); Neg = ReconstructionICA (Xr, 2, args{:}, ... "NonGaussianityIndicator", [-1; 1]); assert_equal (Mdl.FitInfo.Objective(end), 801.1816174574, 1e-6); assert_equal (Neg.FitInfo.Objective(end), 197.5588279632, 1e-6); ***** error ... ReconstructionICA (ones (6, 5), 2, "NonGaussianityIndicator", [1; 1; 1]) ***** error ... ReconstructionICA (ones (6, 5), 2, "NonGaussianityIndicator", [1; 0]) ***** error ... ReconstructionICA (ones (6, 5), 2, "NonGaussianityIndicator", {1, -1}) ***** error ... ReconstructionICA (ones (6, 5), 2, "ContrastFcn", "bogus") ***** error ... ReconstructionICA (ones (6, 5), 2, "bogus", 1) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Dimensionality_Reduction/pcacov.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Dimensionality_Reduction/pcacov.m ***** demo x = [ 7 26 6 60; 1 29 15 52; 11 56 8 20; 11 31 8 47; 7 52 6 33; 11 55 9 22; 3 71 17 6; 1 31 22 44; 2 54 18 22; 21 47 4 26; 1 40 23 34; 11 66 9 12; 10 68 8 12 ]; Kxx = cov (x); [coeff, latent, explained] = pcacov (Kxx) ***** test load hald Kxx = cov (ingredients); [coeff,latent,explained] = pcacov (Kxx); c_out = [-0.0678, -0.6460, 0.5673, 0.5062; ... -0.6785, -0.0200, -0.5440, 0.4933; ... 0.0290, 0.7553, 0.4036, 0.5156; ... 0.7309, -0.1085, -0.4684, 0.4844]; l_out = [517.7969; 67.4964; 12.4054; 0.2372]; e_out = [ 86.5974; 11.2882; 2.0747; 0.0397]; assert_equal (coeff, c_out, 1e-4); assert_equal (latent, l_out, 1e-4); assert_equal (explained, e_out, 1e-4); ***** error pcacov (ones (2, 3)) ***** error pcacov (ones (3, 3, 3)) ***** error pcacov ([1, 2; 0, 1]) ***** error pcacov ([10, 0; 0, -1]) 5 tests, 5 passed, 0 known failure, 0 skipped [inst/Dimensionality_Reduction/factoran.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Dimensionality_Reduction/factoran.m ***** demo ## Six measured variables built from two underlying factors, plus noise. ## Factor analysis recovers the structure without being told it: the first ## three variables load on one factor and the last three on the other. rng (42); F = randn (300, 2); X = F * [0.8 0.1; 0.7 0.2; 0.75 0.15; 0.15 0.8; 0.2 0.7; 0.1 0.75]' ... + 0.6 * randn (300, 6); lambda = factoran (X, 2); printf ("loadings on the two rotated factors:\n"); disp (round (lambda * 1000) / 1000); ***** demo ## How many factors do the data support? The likelihood ratio test in ## stats answers it. These data were built from two factors, and the test ## rejects one factor while accepting two. Three factors leave no degrees ## of freedom, so there is nothing left to test with. rng (42); F = randn (300, 2); X = F * [0.8 0.1; 0.7 0.2; 0.75 0.15; 0.15 0.8; 0.2 0.7; 0.1 0.75]' ... + 0.6 * randn (300, 6); for m = 1:3 [~, ~, ~, stats] = factoran (X, m); if (isfield (stats, "p")) printf ("%d factor(s): chisq = %8.3f, dfe = %d, p = %.4f\n", ... m, stats.chisq, stats.dfe, stats.p); else printf ("%d factor(s): nothing to test against (dfe = %d)\n", ... m, stats.dfe); endif endfor ***** demo ## Rotation decides how a fit is presented, not how good it is. The ## unrotated solution puts most of the variance on a general first factor; ## varimax turns it so each variable loads mainly on one factor, which is ## easier to read. The specific variances are untouched either way. rng (42); F = randn (300, 2); X = F * [0.8 0.1; 0.7 0.2; 0.75 0.15; 0.15 0.8; 0.2 0.7; 0.1 0.75]' ... + 0.6 * randn (300, 6); [Lnone, psi_none] = factoran (X, 2, "Rotate", "none"); [Lvari, psi_vari, T] = factoran (X, 2, "Rotate", "varimax"); printf ("unrotated:\n"); disp (round (Lnone * 100) / 100); printf ("varimax:\n"); disp (round (Lvari * 100) / 100); printf ("the rotation matrix takes one to the other: %d\n", ... max (max (abs (Lnone * T - Lvari))) < 1e-10); printf ("specific variances unchanged: %d\n", ... max (abs (psi_none - psi_vari)) < 1e-10); ***** demo ## Factor scores place each observation on the factors, so they can be ## plotted or used as inputs downstream. The two predictors optimise ## different things and are not equal, but they agree closely on the ## ordering of observations. rng (42); F = randn (300, 2); X = F * [0.8 0.1; 0.7 0.2; 0.75 0.15; 0.15 0.8; 0.2 0.7; 0.1 0.75]' ... + 0.6 * randn (300, 6); [~, ~, ~, ~, Fwls] = factoran (X, 2, "Scores", "wls"); [~, ~, ~, ~, Freg] = factoran (X, 2, "Scores", "regression"); printf ("first three observations, weighted least squares:\n"); disp (round (Fwls(1:3,:) * 1000) / 1000); printf ("first three observations, regression:\n"); disp (round (Freg(1:3,:) * 1000) / 1000); printf ("the two agree on factor 1 to a correlation of %.4f\n", ... corr (Fwls(:,1), Freg(:,1))); ***** demo ## Two ways to estimate the same model. Maximum likelihood is the default ## and is what MATLAB does; principal axis factoring is an Octave ## extension that assumes no distribution. They agree closely when the ## model fits, so a large gap between them is a warning about the fit. ## Only maximum likelihood carries a test. rng (42); F = randn (300, 2); X = F * [0.8 0.1; 0.7 0.2; 0.75 0.15; 0.15 0.8; 0.2 0.7; 0.1 0.75]' ... + 0.6 * randn (300, 6); Lml = factoran (X, 2, "Extraction", "ml"); Lpaf = factoran (X, 2, "Extraction", "paf"); printf ("largest loading difference between the extractions: %.4f\n", ... max (abs (abs (Lml(:)) - abs (Lpaf(:))))); [~, ~, ~, sml] = factoran (X, 2, "Extraction", "ml"); [~, ~, ~, spaf] = factoran (X, 2, "Extraction", "paf"); printf ("ml reports: %s\n", strjoin (fieldnames (sml)', ", ")); printf ("paf reports: %s\n", strjoin (fieldnames (spaf)', ", ")); ***** shared X, Lref, Pref, Tref s = 7; u = zeros (3200, 1); for k = 1:3200 s = mod (16807 * s, 2147483647); u(k) = s / 2147483647; endfor u = min (max (u, 1e-12), 1 - 1e-12); a = u(1:2:end); b = u(2:2:end); r = sqrt (-2 * log (a)); z = zeros (3200, 1); z(1:2:end) = r .* cos (2 * pi * b); z(2:2:end) = r .* sin (2 * pi * b); Z = reshape (z(1:1600), 200, 8); X = Z(:,1:2) * [0.7 0.1; 0.6 0.2; 0.65 0.15; ... 0.15 0.7; 0.2 0.65; 0.1 0.6]' + 0.75 * Z(:,3:8); Lref = [0.23744646899123, 0.62572191026907; ... 0.1948126299518, 0.57314527421474; ... 0.038102881086025, 0.63721347868091; ... 0.76535682403077, 0.15782050760078; ... 0.54869037618166, 0.1041708573065; ... 0.52204369118599, 0.15800651296731]; Pref = [0.55209126537284; 0.63355253385654; 0.59250715304029; ... 0.38932161929025; 0.68808730357355; 0.70250432635276]; Tref = [0.78348287808137, 0.62141337268628; ... -0.62141337268628, 0.78348287808137]; ***** test # the maximum likelihood fit, its rotation and its statistics [L, psi, T, stats] = factoran (X, 2); assert_equal (L, Lref, 1e-6); assert_equal (psi, Pref, 1e-6); assert_equal (T, Tref, 1e-6); assert_equal (stats.loglike, -0.0043677316938693, 1e-9); assert_equal (stats.dfe, 4); assert_equal (stats.chisq, 0.8509797250222, 1e-6); assert_equal (stats.p, 0.93148578937045, 1e-8); ***** test # a single factor, where the model does not fit and the test says so [L, psi, T, stats] = factoran (X, 1); assert_equal (L, [0.58734985138995; 0.52528039923063; 0.42927173838555; ... 0.5943390974845; 0.47167200636347; ... 0.49418848792238], 1e-6); assert_equal (stats.dfe, 9); assert_equal (stats.chisq, 51.130175056732, 1e-5); assert_equal (stats.p < 1e-6, true); assert_equal (T, 1); ***** test # rotation changes the loadings but not the fit [Ln, psin, Tn] = factoran (X, 2, "Rotate", "none"); assert_equal (Ln, [0.57486720553951, 0.34268999200789; ... 0.50879249789022, 0.32799033558027; ... 0.42582593184473, 0.47556821038442; ... 0.69771574115811, -0.3519532998141; ... 0.49462267888081, -0.25934745412885; ... 0.50719965378403, -0.20060953329425], 1e-6); assert_equal (Tn, eye (2)); assert_equal (psin, Pref, 1e-6); [~, psiv] = factoran (X, 2, "Rotate", "varimax"); assert_equal (psiv, psin, 1e-10); ***** test # the rotation matrix is the one that was applied [Ln, ~, ~] = factoran (X, 2, "Rotate", "none"); [Lv, ~, T] = factoran (X, 2, "Rotate", "varimax"); assert_equal (Ln * T, Lv, 1e-8); ***** test # quartimax, another orthogonal rotation L = factoran (X, 2, "Rotate", "quartimax"); assert_equal (L, [0.24417499900219, 0.62312703719984; ... 0.20097710825146, 0.57101284407823; ... 0.044966808556795, 0.63676591702752; ... 0.76701294807206, 0.14956442825637; ... 0.54978098993064, 0.098252529419005; ... 0.52371594497243, 0.15237218456401], 1e-5); ***** test # communality and specific variance partition the unit variance [L, psi] = factoran (X, 2); assert_equal (sum (L .^ 2, 2) + psi, ones (6, 1), 1e-10); ***** test # both score predictors, and the default is the weighted least squares [~, ~, ~, ~, Fw] = factoran (X, 2, "Scores", "wls"); assert_equal (Fw(1:2,:), [0.8685910477393, 3.3629807100209; ... -0.03713794537533, -1.9311992150794], 1e-5); [~, ~, ~, ~, Fr] = factoran (X, 2, "Scores", "regression"); assert_equal (Fr(1:2,:), [0.94397703443356, 2.2276228684448; ... -0.22623256144569, -1.2312105486235], 1e-5); [~, ~, ~, ~, Fd] = factoran (X, 2); assert_equal (Fd, Fw, 1e-12); [~, ~, ~, ~, Fb] = factoran (X, 2, "Scores", "Bartlett"); assert_equal (Fb, Fw, 1e-12); [~, ~, ~, ~, Ft] = factoran (X, 2, "Scores", "Thomson"); assert_equal (Ft, Fr, 1e-12); ***** test # a correlation matrix gives the same fit as the data behind it [L, psi, T, stats] = factoran (corr (X), 2, "Xtype", "covariance", ... "Nobs", 200); assert_equal (L, Lref, 1e-6); assert_equal (psi, Pref, 1e-6); assert_equal (stats.chisq, 0.85097972502237, 1e-6); ***** test # principal axis factoring is available and agrees where the fit is good Lml = factoran (X, 2, "Extraction", "ml"); Lpaf = factoran (X, 2, "Extraction", "paf"); assert_equal (size (Lpaf), [6, 2]); assert_equal (max (abs (abs (Lml(:)) - abs (Lpaf(:)))) < 0.15, true); ***** test # but it reports no likelihood, so no test comes with it [~, ~, ~, s] = factoran (X, 2, "Extraction", "paf"); assert_equal (isnan (s.loglike), true); assert_equal (s.dfe, 4); assert_equal (isfield (s, "chisq"), false); assert_equal (isfield (s, "p"), false); ***** test # the degrees of freedom follow the variable and factor counts for m = 1:3 [~, ~, ~, s] = factoran (X, m); assert_equal (s.dfe, ((6 - m) ^ 2 - 6 - m) / 2); endfor warning: factoran: some specific variances are at their lower bound; the fit is a Heywood case. warning: called from factoran at line 309 column 5 __test__ at line 4 column 5 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 382 column 2 ***** test # with no degrees of freedom there is nothing to test [~, ~, ~, s] = factoran (X, 3); assert_equal (s.dfe, 0); assert_equal (isfield (s, "chisq"), false); warning: factoran: some specific variances are at their lower bound; the fit is a Heywood case. warning: called from factoran at line 309 column 5 __test__ at line 3 column 3 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 382 column 2 ***** test # no common factors is a model too, and it tests independence [L, psi, T, stats] = factoran (X, 0); assert_equal (size (L), [6, 0]); assert_equal (psi, ones (6, 1)); assert_equal (stats.dfe, 15); assert_equal (stats.loglike, log (det (corr (X))), 1e-10); assert_equal (stats.p < 1e-6, true); ***** test # the loadings do not change sign between runs L1 = factoran (X, 2); L2 = factoran (X, 2); assert_equal (L1, L2); ***** error factoran (1) ***** error ... factoran (rand (20, 5), 1.5) ***** error ... factoran (rand (20, 5), -1) ***** error factoran (rand (30, 6), 4) ***** error factoran ("abc", 1) ***** error ... factoran ([rand(20, 4); NaN(1, 4)], 1) ***** error ... factoran ([rand(20, 3), ones(20, 1)], 1) ***** error ... factoran (rand (1, 5), 1) ***** error ... factoran (rand (20, 5), 1, "Rotate") ***** error ... factoran (rand (20, 5), 1, "bogus", 1) ***** error <'nosuch' is not a valid value for Extraction.> ... factoran (rand (20, 5), 1, "Extraction", "nosuch") ***** error <'nosuch' is not a valid value for Rotate.> ... factoran (rand (20, 5), 1, "Rotate", "nosuch") ***** error <'nosuch' is not a valid value for Scores.> ... factoran (rand (20, 5), 1, "Scores", "nosuch") ***** error ... factoran (rand (20, 5), 1, "Delta", 1) ***** error ... factoran (rand (5, 4), 1, "Xtype", "covariance") ***** error ... [a, b, c, d, e] = factoran (corr (rand (20, 5)), 1, "Xtype", "covariance"); 30 tests, 30 passed, 0 known failure, 0 skipped [inst/Dimensionality_Reduction/pcares.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Dimensionality_Reduction/pcares.m ***** demo x = [ 7 26 6 60; 1 29 15 52; 11 56 8 20; 11 31 8 47; 7 52 6 33; 11 55 9 22; 3 71 17 6; 1 31 22 44; 2 54 18 22; 21 47 4 26; 1 40 23 34; 11 66 9 12; 10 68 8 12]; ## As we increase the number of principal components, the norm ## of the residuals matrix will decrease r1 = pcares (x,1); n1 = norm (r1) r2 = pcares (x,2); n2 = norm (r2) r3 = pcares (x,3); n3 = norm (r3) r4 = pcares (x,4); n4 = norm (r4) ***** test load hald r1 = pcares (ingredients,1); r2 = pcares (ingredients,2); r3 = pcares (ingredients,3); assert_equal (r1(1,:), [2.0350, 2.8304, -6.8378, 3.0879], 1e-4); assert_equal (r2(1,:), [-2.4037, 2.6930, -1.6482, 2.3425], 1e-4); assert_equal (r3(1,:), [ 0.2008, 0.1957, 0.2045, 0.1921], 1e-4); ***** error pcares (ones (20, 3)) ***** error ... pcares (ones (30, 2), 3) 3 tests, 3 passed, 0 known failure, 0 skipped [inst/Dimensionality_Reduction/sparsefilt.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Dimensionality_Reduction/sparsefilt.m ***** demo ## Learn two sparse features from data with the default (random) start. X = [1, 2, 3, 4; 2, 3, 4, 5; -1, 0, 1, 2; 3, 1, 4, 1; 0, 2, 1, 3]; Mdl = sparsefilt (X, 2, "IterationLimit", 200); Z = transform (Mdl, X) ***** shared X, W0 X = reshape (mod ((1:60)*7, 13), 12, 5) - 6; W0 = reshape (mod ((1:15)*3, 7), 5, 3) - 3; ***** test Mdl = sparsefilt (X, 3, "InitialTransformWeights", W0, "Lambda", 1, ... "Standardize", false, "IterationLimit", 1000); Z = transform (Mdl, X); ## features are in [0, 1] and each observation (row) is essentially unit length assert_equal (size (Z), [12, 3]); assert_equal (all (Z(:) >= 0) && all (Z(:) <= 1 + 1e-12), true); ## rows are unit length up to the 1e-8 normalization regularizer assert_equal (sqrt (sum (Z .^ 2, 2)), ones (12, 1), 1e-3); ***** test ## The objective at the initial weights matches MATLAB (73.171833). A = X * W0; F = sqrt (A .^ 2 + 1e-8); F = F ./ sqrt (sum (F .^ 2, 1) + 1e-8); F = F ./ sqrt (sum (F .^ 2, 2) + 1e-8); f0 = sum (F(:)) + sum (W0(:) .^ 2); assert_equal (f0, 73.171833042485730, 1e-9); ***** test ## The solver drives the objective well below its value at the start ## (73.17) -- reaching a good local minimum of the sparse filtering cost. Mdl = sparsefilt (X, 3, "InitialTransformWeights", W0, "Lambda", 1, ... "Standardize", false, "IterationLimit", 1000); assert_equal (Mdl.FitInfo.Objective(end) < 20, true); ***** test ## Lambda is an L2 penalty on the weights: FitInfo.Objective is ## sum(features) + Lambda * ||W||^2 at the solution. Mdl = sparsefilt (X, 3, "InitialTransformWeights", W0, "Lambda", 1, ... "Standardize", false, "IterationLimit", 1000); W = Mdl.TransformWeights; Z = transform (Mdl, X); assert_equal (Mdl.FitInfo.Objective(end), sum (Z(:)) + sum (W(:) .^ 2), 1e-6); ***** test ## FitInfo carries the whole trajectory, not just its final value Mdl = sparsefilt (X, 3, "InitialTransformWeights", W0, "Lambda", 1, ... "Standardize", false, "IterationLimit", 1000); it = Mdl.FitInfo.Iteration; ob = Mdl.FitInfo.Objective; assert_equal (columns (it), 1); assert_equal (size (ob), size (it)); assert_equal (it, (0:numel (ob) - 1)'); assert_equal (all (diff (ob) <= 1e-10), true); ***** test ## the comparison broadcasts over the history, as MATLAB's does Mdl = sparsefilt (X, 3, "InitialTransformWeights", W0, "Lambda", 1, ... "Standardize", false, "IterationLimit", 1000); assert_equal (size (Mdl.FitInfo.Objective < 20), size (Mdl.FitInfo.Objective)); ***** test ## The lbfgs solver reaches a low objective value (MATLAB's is 12.2532). ## It does not land where the default solver lands: this objective is far ## from convex and the two take different steps from the same weights. ## Both tolerances are tightened because the step reaches 1e-6 here while ## the gradient is still well above it, so the default stops the fit ## early; that is StepTolerance doing exactly what it says. Mdl = sparsefilt (X, 3, "InitialTransformWeights", W0, "Lambda", 1, ... "Standardize", false, "IterationLimit", 1000, ... "Solver", "lbfgs", "GradientTolerance", 1e-8, ... "StepTolerance", 1e-8); assert_equal (Mdl.FitInfo.Objective(end) < 12.5, true); ***** test ## The trajectory starts at the initial weights whichever solver ran args = {"InitialTransformWeights", W0, "IterationLimit", 20}; Mq = sparsefilt (X, 3, args{:}); Ml = sparsefilt (X, 3, args{:}, "Solver", "lbfgs"); assert_equal (Ml.FitInfo.Iteration(1), 0); assert_equal (Ml.FitInfo.Objective(1), Mq.FitInfo.Objective(1), 1e-10); ***** test ## The solver that ran is recorded Mdl = sparsefilt (X, 3, "InitialTransformWeights", W0, "Solver", "lbfgs"); assert_equal (Mdl.ModelParameters.Solver, "lbfgs"); ***** error ... sparsefilt (X, 3, "Solver", "bogus") ***** error ... sparsefilt (X, 3, "Solver", 5) ***** error sparsefilt (ones (5, 3)) ***** error sparsefilt ({1, 2}, 1) ***** error sparsefilt ([1, Inf; 2, 3], 1) ***** error sparsefilt (ones (5, 3), 0) ***** error sparsefilt (ones (5, 3), 1.5) ***** error ... sparsefilt (ones (4, 5), 2, "InitialTransformWeights", ones (3, 3)) ***** error ... sparsefilt (ones (4, 5), 2, "bogus", 1) 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Dimensionality_Reduction/SparseFiltering.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Dimensionality_Reduction/SparseFiltering.m ***** shared X, W0 X = reshape (mod ((1:60)*7, 13), 12, 5) - 6; W0 = reshape (mod ((1:15)*3, 7), 5, 3) - 3; ***** test ## Construct the object directly and check its properties. Mdl = SparseFiltering (X, 3, "InitialTransformWeights", W0, ... "Lambda", 1, "IterationLimit", 500); assert_equal (isa (Mdl, "SparseFiltering"), true); assert_equal (Mdl.NumPredictors, 5); assert_equal (Mdl.NumLearnedFeatures, 3); assert_equal (size (Mdl.TransformWeights), [5, 3]); assert_equal (Mdl.InitialTransformWeights, W0); assert_equal (isfield (Mdl.FitInfo, "Objective"), true); ***** test ## The transform method returns nonnegative features in [0, 1]. Mdl = SparseFiltering (X, 3, "InitialTransformWeights", W0, ... "IterationLimit", 500); Z = transform (Mdl, X); assert_equal (size (Z), [12, 3]); assert_equal (all (Z(:) >= 0) && all (Z(:) <= 1 + 1e-12), true); ***** test ## The transform method standardizes new data when the model does. Mdl = SparseFiltering (X, 2, "Standardize", true, "IterationLimit", 100, ... "InitialTransformWeights", W0(:,1:2)); Z = transform (Mdl, X); assert_equal (size (Z), [12, 2]); assert_equal (isempty (Mdl.Mu), false); assert_equal (size (Mdl.Mu), [5, 1]); assert_equal (size (Mdl.Sigma), [5, 1]); ***** test ## The default constructor returns an empty model. Mdl = SparseFiltering (); assert_equal (isempty (Mdl.TransformWeights), true); ***** error ... SparseFiltering (ones (6, 5), 2, "bogus", 1) 5 tests, 5 passed, 0 known failure, 0 skipped [inst/Dimensionality_Reduction/rotatefactors.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Dimensionality_Reduction/rotatefactors.m ***** demo ## Rotate a three-factor loading matrix to the varimax criterion and ## recover the rotation matrix. A = [ 0.8, 0.2, 0.1; 0.7, 0.3, 0.0; ... 0.1, 0.9, 0.2; 0.2, 0.8, 0.1; ... 0.1, 0.2, 0.9; 0.0, 0.1, 0.8]; [B, T] = rotatefactors (A, 'Method', 'varimax'); B ## T is orthonormal and reconstructs B from A. max (abs (vec (A * T - B))) ***** test A = reshape (mod ((1:18)*5, 11), 6, 3) - 5; B = rotatefactors (A, 'Method', 'varimax'); Bref = [ -0.590343326670958, -5.399542278328798, 2.120480592034490; ... 5.301191898681203, 1.349821193720584, -0.274494441363606; ... -1.789611374449118, -5.388780549360982, 0.870824505437868; ... 4.101923850903043, 1.360582922688400, -1.524150527960228; ... -2.988879422227277, -5.378018820393167, -0.378831581158754; ... 2.902655803124883, 1.371344651656216, -2.773806614556851]; assert_equal (B, Bref, 1e-10); ***** test A = reshape (mod ((1:18)*5, 11), 6, 3) - 5; [B, T] = rotatefactors (A, 'Method', 'varimax'); assert_equal (A * T, B, 1e-12); assert_equal (T' * T, eye (3), 1e-12); ***** test A = reshape (mod ((1:18)*5, 11), 6, 3) - 5; B = rotatefactors (A, 'Method', 'quartimax'); Bref = [ -1.079871632250411, 1.331921409298459, 5.573137591816050; ... 5.135643864717125, 1.382567861335108, -1.309071504386449; ... -1.872731015323443, -0.201056474219368, 5.427011593724494; ... 4.342784481644092, -0.150410022182719, -1.455197502478006; ... -2.665590398396474, -1.734034357737195, 5.280885595632937; ... 3.549925098571060, -1.683387905700547, -1.601323500569563]; assert_equal (B, Bref, 1e-10); ***** test A = reshape (mod ((1:18)*5, 11), 6, 3) - 5; B = rotatefactors (A, 'Method', 'equamax'); Bref = [ -0.163528146620418, -5.392883888956456, 2.211348436021980; ... 4.856598298899028, 0.925912265845965, -2.357146461102300; ... -1.752970474391914, -5.249881056555078, 1.538129841051886; ... 3.267155971127525, 1.068915098247334, -3.030365056072396; ... -3.342412802163413, -5.106878224153711, 0.864911246081789; ... 1.677713643356028, 1.211917930648702, -3.703583651042488]; assert_equal (B, Bref, 1e-6); ***** test A = reshape (mod ((1:18)*5, 11), 6, 3) - 5; B = rotatefactors (A, 'Method', 'parsimax'); Bref = [ -0.209779706669808, -5.381270194314001, 2.235603625524279; ... 4.824100779801576, 0.835974617312815, -2.455442547795920; ... -1.809538067356745, -5.214183987228857, 1.593065387896242; ... 3.224342419114638, 1.003060824397959, -3.097980785423958; ... -3.409296428043682, -5.047097780143712, 0.950527150268203; ... 1.624584058427703, 1.170147031483100, -3.740519023051994]; assert_equal (B, Bref, 1e-6); ***** test ## orthomax with Coeff 1 equals varimax. A = reshape (mod ((1:18)*5, 11), 6, 3) - 5; B1 = rotatefactors (A, 'Method', 'orthomax', 'Coeff', 1); B2 = rotatefactors (A, 'Method', 'varimax'); assert_equal (B1, B2, 1e-12); ***** test ## orthomax with Coeff 0 equals quartimax. A = reshape (mod ((1:18)*5, 11), 6, 3) - 5; B1 = rotatefactors (A, 'Method', 'orthomax', 'Coeff', 0); B2 = rotatefactors (A, 'Method', 'quartimax'); assert_equal (B1, B2, 1e-12); ***** test ## Kaiser normalization 'off'. A = reshape (mod ((1:18)*5, 11), 6, 3) - 5; B = rotatefactors (A, 'Method', 'orthomax', 'Coeff', 0.5, 'Normalize', 'off'); Bref = [ -0.018655295494772, -5.634517554136197, 1.500621175407379; ... 5.076579678301866, 2.027215443018021, 0.344581365488290; ... -1.109307774177549, -5.634304393877173, 0.155081460160809; ... 3.985927199619089, 2.027428603277046, -1.000958349758279; ... -2.199960252860326, -5.634091233618149, -1.190458255085760; ... 2.895274720936312, 2.027641763536070, -2.346498065004848]; assert_equal (B, Bref, 1e-10); ***** test A = reshape (mod ((1:18)*5, 11), 6, 3) - 5; [B, T] = rotatefactors (A, 'Method', 'promax', 'Power', 3); Bref = [ 1.224548928356429, -5.243438188632538, 2.071368824506429; ... 5.402710851790721, 0.067482009256478, -0.106948752887073; ... -0.495720593244403, -5.226782837470801, 0.630342425004671; ... 3.682441330189890, 0.084137360418215, -1.547975152388831; ... -2.215990114845235, -5.210127486309064, -0.810683974497087; ... 1.962171808589059, 0.100792711579952, -2.989001551890589]; assert_equal (B, Bref, 1e-10); assert_equal (A * T, B, 1e-10); ***** test A = reshape (mod ((1:18)*5, 11), 6, 3) - 5; Target = reshape (mod ((1:18)*3, 7), 6, 3) - 3; [B, T] = rotatefactors (A, 'Method', 'procrustes', 'Target', Target, ... 'Type', 'orthogonal'); Bref = [ -1.222902114166934, 5.164166701208014, -2.415759239100699; ... 5.403127504320427, -0.893247624515622, -0.091224192807273; ... -2.313297220899559, 5.148157805250635, -1.070106153619982; ... 4.312732397587801, -0.909256520473001, 1.254428892673443; ... -3.403692327632185, 5.132148909293257, 0.275546931860735; ... 3.222337290855177, -0.925265416430380, 2.600081978154161]; assert_equal (B, Bref, 1e-10); assert_equal (T' * T, eye (3), 1e-12); ***** test A = reshape (mod ((1:18)*5, 11), 6, 3) - 5; Target = reshape (mod ((1:18)*3, 7), 6, 3) - 3; ## 'oblique' is the default, so naming it must change nothing B = rotatefactors (A, 'Method', 'procrustes', 'Target', Target, ... 'Type', 'oblique'); assert_equal (B, rotatefactors (A, 'Method', 'procrustes', ... 'Target', Target), 1e-10); Bref = [ 0.000000000000002, -4.619308411881804, -10.370742303151150; ... 94.640566010004221, -97.005476649517561, -1.152304700350133; ... -31.546855336668067, 36.954467295054300, 0.000000000000000; ... 63.093710673336162, -55.431700942581458, 9.218437602801021; ... -63.093710673336133, 78.528243001990404, 10.370742303151154; ... 31.546855336668081, -13.857925235645340, 19.589179905952172]; assert_equal (B, Bref, 1e-8); ***** test ## Single-factor input is returned unchanged. A = [1; 2; 3; 4]; [B, T] = rotatefactors (A); assert_equal (B, A); assert_equal (T, 1); ***** test ## Default method is varimax. A = reshape (mod ((1:18)*5, 11), 6, 3) - 5; assert_equal (rotatefactors (A), rotatefactors (A, 'Method', 'varimax')); ***** error rotatefactors () ***** error rotatefactors ({1, 2}) ***** error rotatefactors (ones (2, 2, 2)) ***** error rotatefactors ([1+2i; 3]) ***** error rotatefactors (ones (3), 'Method', 'foo') ***** error ... rotatefactors (ones (3), 'Method', 5) ***** error ... rotatefactors (ones (3), 'Normalize', 'yes') ***** error ... rotatefactors (ones (3), 'Reltol', -1) ***** error ... rotatefactors (ones (3), 'Maxit', 2.5) ***** error ... rotatefactors (ones (3), 'Method', 'orthomax', 'Coeff', [1, 2]) ***** error ... rotatefactors (ones (3), 'Method', 'promax', 'Power', 0.5) ***** error ... rotatefactors (ones (3), 'Method', 'procrustes') ***** error ... rotatefactors (ones (6, 3), 'Method', 'procrustes', 'Target', ones (4, 2)) ***** error ... rotatefactors (ones (6, 3), 'Method', 'procrustes', 'Target', ones (6, 3), 'Type', 'x') ***** error ... rotatefactors (ones (3), 'Bogus', 1) 28 tests, 28 passed, 0 known failure, 0 skipped [inst/Dimensionality_Reduction/canoncorr.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Dimensionality_Reduction/canoncorr.m ***** shared X, Y, A, B, r, U, V, k, Cuv k = 10; X = [1:k; sin(1:k); cos(1:k)]'; Y = [tan(1:k); tanh((1:k)/k)]'; [A, B, r, U, V, stats] = canoncorr (X, Y); Cuv = (U' * V) / (k - 1); ***** assert_equal (diag (Cuv)', r, 10 * eps); ***** assert_equal (diag (diag (Cuv)), Cuv, 2 * eps); ***** assert_equal (r, [0.99590, 0.26754], 1E-5); ***** assert_equal (U, center (X) * A, 10 * eps); ***** assert_equal (V, center (Y) * B, 10 * eps); ***** assert_equal (cov (U), eye (size (U, 2)), 10 * eps); ***** assert_equal (cov (V), eye (size (V, 2)), 10 * eps); rand ('state', 1); [A, B, r] = canoncorr (rand (5, 10), rand (5, 20)); ## Four, not five: centring a five-row matrix leaves rank at most four, so ## there is no fifth canonical correlation to report. The count used to ## come from the number of rows rather than the rank. warning: canoncorr: X is not full rank. warning: called from canoncorr at line 53 column 5 __test__ at line 3 column 22 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 422 column 2 warning: canoncorr: Y is not full rank. warning: called from canoncorr at line 63 column 5 __test__ at line 3 column 22 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 422 column 2 ***** assert_equal (r, ones (1, 4), 10*eps); ***** test Xr = [X(:,1), X(:,1), X(:,2)]; warning ("off", "canoncorr:NotFullRank", "local"); [Ar, Br, rr] = canoncorr (Xr, Y); ## the duplicated column contributes nothing assert_equal (Ar(2,:), zeros (1, columns (Ar))); ## and the coefficients stay finite, where they used to reach 1e15 assert_equal (all (isfinite (Ar(:))), true); assert_equal (max (abs (Ar(:))) < 1e3, true); ## dropping the duplicate leaves the same fit as never having had it [A2, B2, r2] = canoncorr (X(:,1:2), Y); assert_equal (rr, r2, 1e-12); assert_equal (Ar([1, 3], :), A2, 1e-10); ***** test # a constant column carries no information and is dropped Xc = [X(:,1:2), ones(rows (X), 1)]; warning ("off", "canoncorr:NotFullRank", "local"); [Ac, Bc, rc] = canoncorr (Xc, Y); assert_equal (Ac(3,:), zeros (1, columns (Ac))); [A2, B2, r2] = canoncorr (X(:,1:2), Y); assert_equal (rc, r2, 1e-12); ***** test # the deficiency is reported Xr = [X(:,1), X(:,1), X(:,2)]; fail ("canoncorr (Xr, Y)", "warning", "X is not full rank"); ***** test # the returned coefficients satisfy the definition whatever the rank Xr = [X(:,1), X(:,1), X(:,2)]; warning ("off", "canoncorr:NotFullRank", "local"); [Ar, Br, rr, Ur, Vr] = canoncorr (Xr, Y); kk = rows (Xr); assert_equal ((Ur' * Ur) / (kk - 1), eye (numel (rr)), 1e-10); assert_equal ((Vr' * Vr) / (kk - 1), eye (numel (rr)), 1e-10); assert_equal ((Ur' * Vr) / (kk - 1), diag (rr), 1e-10); ***** test ## Below the resolution of 1 - chi2cdf and 1 - fcdf, values from MATLAB ## R2024a u = (1:30)'; [~, ~, ~, ~, ~, st] = canoncorr (u, u + 0.01 * sin (u)); assert_equal ([st.pChisq, st.pF], ... [6.27210601481829e-87, 6.68262095310285e-88], -1e-7); ***** error ... canoncorr (ones (10, 2), [tan(1:10); tanh((1:10)/10)]') 14 tests, 14 passed, 0 known failure, 0 skipped [inst/Dimensionality_Reduction/nnmf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Dimensionality_Reduction/nnmf.m ***** demo ## Factor a nonnegative matrix into two rank-2 nonnegative factors. A = [1, 2, 3; 2, 4, 6; 3, 5, 7; 4, 8, 12]; [W, H, D] = nnmf (A, 2); D ## W * H approximates A. W * H ***** shared A, W0, H0, opt A = reshape (mod ((1:20)*7, 13), 5, 4) + 1; W0 = reshape (mod ((1:10)*3, 7), 5, 2) + 1; H0 = reshape (mod ((1:8)*3, 7), 2, 4) + 1; opt = struct ("MaxIter", 500, "TolFun", 1e-12, "TolX", 1e-12); ***** test [W, H, D] = nnmf (A, 2, "Algorithm", "als", "W0", W0, "H0", H0, "Options", opt); Wref = [11.808229123411982, 9.049993647167147; ... 3.212266148150507, 12.092875848976247; ... 13.853561873197318, 1.116057457895120; ... 4.618299368228214, 13.176478328920602; ... 15.259595093275024, 2.199659937839474]; Href = [0.657913952127586, 0.187993469755446, 0.140048330155150, 0.715677407877266; ... 0, 0.730839581652543, 0.680241675322826, 0.056078240378338]; assert_equal (W, Wref, 1e-4); assert_equal (H, Href, 1e-5); assert_equal (D, 1.882172868745145, 1e-8); ***** test [W, H, D] = nnmf (A, 2, "Algorithm", "mult", "W0", W0, "H0", H0, "Options", opt); Wref = [11.221742977568461, 8.713876463682844; ... 2.176215667360621, 12.316408085448018; ... 14.030193052240865, 0.411019822854590; ... 3.511868529923804, 13.360184914158390; ... 15.365861312580710, 1.454761030110911]; Href = [0.647958006689051, 0.222457058550383, 0.172654918585345, 0.707710080299095; ... 0.057102252901681, 0.727300231504821, 0.673915159707622, 0.116670748188381]; assert_equal (W, Wref, 1e-3); assert_equal (H, Href, 1e-4); assert_equal (D, 1.882172868753092, 1e-8); ***** test ## Factors are nonnegative, correctly sized, and H rows are unit length. [W, H] = nnmf (A, 2, "W0", W0, "H0", H0, "Options", opt); assert_equal (size (W), [5, 2]); assert_equal (size (H), [2, 4]); assert_equal (all (W(:) >= 0) && all (H(:) >= 0), true); assert_equal (sqrt (sum (H .^ 2, 2)), [1; 1], 1e-10); ***** test ## Columns of W are ordered by decreasing length. [W, H] = nnmf (A, 2, "W0", W0, "H0", H0, "Options", opt); assert_equal (norm (W(:,1)) >= norm (W(:,2)), true); ***** test ## The residual D matches the direct computation. [W, H, D] = nnmf (A, 2, "W0", W0, "H0", H0, "Options", opt); assert_equal (D, norm (A - W * H, "fro") / sqrt (numel (A)), 1e-12); ***** error nnmf (ones (4, 3)) ***** error nnmf ({1, 2}, 1) ***** error nnmf ([1, Inf; 2, 3], 1) ***** error nnmf ([1+2i, 3; 4, 5], 1) ***** error nnmf (ones (4, 3), 'd') ***** error nnmf (ones (4, 3), [1, 2]) ***** error nnmf (ones (4, 3), 1.5) ***** error nnmf (ones (4, 3), 0) ***** error nnmf (ones (4, 3), -1) ***** error ... nnmf (ones (4, 3), 5) ***** error ... nnmf (ones (4, 3), 4) ***** error ... nnmf (ones (4, 3), 2, "Algorithm", "foo") ***** error ... nnmf (ones (4, 3), 2, "W0", ones (3, 3)) ***** error ... nnmf (ones (4, 3), 2, "H0", ones (2, 2)) ***** error ... nnmf (ones (4, 3), 2, "Replicates", 0) ***** error nnmf (ones (4, 3), 2, "bogus", 1) ***** error nnmf (ones (4, 3), 2, "Options", 5) ***** error ... nnmf ([], 1) ***** error ... nnmf (zeros (0, 3), 1) 24 tests, 24 passed, 0 known failure, 0 skipped [inst/Dimensionality_Reduction/procrustes.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Dimensionality_Reduction/procrustes.m ***** demo ## Create some random points in two dimensions rng (42); n = 10; X = normrnd (0, 1, [n, 2]); ## Those same points, rotated, scaled, translated, plus some noise S = [0.5, -sqrt(3)/2; sqrt(3)/2, 0.5]; # rotate 60 degrees Y = normrnd (0.5*X*S + 2, 0.05, n, 2); ## Conform Y to X, plot original X and Y, and transformed Y [d, Z] = procrustes (X, Y); plot (X(:,1), X(:,2), 'rx', Y(:,1), Y(:,2), 'b.', Z(:,1), Z(:,2), 'bx'); ***** demo ## Find Procrustes distance and plot superimposed shape X = [40 88; 51 88; 35 78; 36 75; 39 72; 44 71; 48 71; 52 74; 55 77]; Y = [36 43; 48 42; 31 26; 33 28; 37 30; 40 31; 45 30; 48 28; 51 24]; plot (X(:,1),X(:,2),'x'); hold on plot (Y(:,1),Y(:,2),'o'); xlim ([0 100]); ylim ([0 100]); legend ('Target shape (X)', 'Source shape (Y)'); [d, Z] = procrustes (X, Y) plot (Z(:,1), Z(:,2), 's'); legend ('Target shape (X)', 'Source shape (Y)', 'Transformed shape (Z)'); hold off ***** demo ## Apply Procrustes transformation to larger set of points ## Create matrices with landmark points for two triangles X = [5, 0; 5, 5; 8, 5]; # target Y = [0, 0; 1, 0; 1, 1]; # source ## Create a matrix with more points on the source triangle Y_mp = [linspace(Y(1,1),Y(2,1),10)', linspace(Y(1,2),Y(2,2),10)'; ... linspace(Y(2,1),Y(3,1),10)', linspace(Y(2,2),Y(3,2),10)'; ... linspace(Y(3,1),Y(1,1),10)', linspace(Y(3,2),Y(1,2),10)']; ## Plot both shapes, including the larger set of points for the source shape plot ([X(:,1); X(1,1)], [X(:,2); X(1,2)], 'bx-'); hold on plot ([Y(:,1); Y(1,1)], [Y(:,2); Y(1,2)], 'ro-', 'MarkerFaceColor', 'r'); plot (Y_mp(:,1), Y_mp(:,2), 'ro'); xlim ([-1 10]); ylim ([-1 6]); legend ('Target shape (X)', 'Source shape (Y)', ... 'More points on Y', 'Location', 'northwest'); hold off ## Obtain the Procrustes transformation [d, Z, transform] = procrustes (X, Y) ## Use the Procrustes transformation to superimpose the more points (Y_mp) ## on the source shape onto the target shape, and then visualize the results. Z_mp = transform.b * Y_mp * transform.T + transform.c(1,:); figure plot ([X(:,1); X(1,1)], [X(:,2); X(1,2)], 'bx-'); hold on plot ([Y(:,1); Y(1,1)], [Y(:,2); Y(1,2)], 'ro-', 'MarkerFaceColor', 'r'); plot (Y_mp(:,1), Y_mp(:,2), 'ro'); xlim ([-1 10]); ylim ([-1 6]); plot ([Z(:,1); Z(1,1)],[Z(:,2); Z(1,2)],'ks-','MarkerFaceColor','k'); plot (Z_mp(:,1),Z_mp(:,2),'ks'); legend ('Target shape (X)', 'Source shape (Y)', ... 'More points on Y', 'Transformed source shape (Z)', ... 'Transformed additional points', 'Location', 'northwest'); hold off ***** demo ## Compare shapes without reflection T = [33, 93; 33, 87; 33, 80; 31, 72; 32, 65; 32, 58; 30, 72; ... 28, 72; 25, 69; 22, 64; 23, 59; 26, 57; 30, 57]; S = [48, 83; 48, 77; 48, 70; 48, 65; 49, 59; 49, 56; 50, 66; ... 52, 66; 56, 65; 58, 61; 57, 57; 54, 56; 51, 55]; plot (T(:,1), T(:,2), 'x-'); hold on plot (S(:,1), S(:,2), 'o-'); legend ('Target shape (d)', 'Source shape (b)'); hold off d_false = procrustes (T, S, 'reflection', false); printf ("Procrustes distance without reflection: %f\n", d_false); d_true = procrustes (T, S, 'reflection', true); printf ("Procrustes distance with reflection: %f\n", d_true); d_best = procrustes (T, S, 'reflection', 'best'); printf ("Procrustes distance with best fit: %f\n", d_true); ***** error procrustes (); ***** error procrustes (1); ***** error procrustes (1, 2, 3, 4, 5, 6, 7); ***** error ... procrustes (ones (2, 2, 2), ones (2, 2, 2)); ***** error ... procrustes ([1, 2; -3, 4; 2, 3], [1, 2; -3, 4; 2, 3+i]); ***** error ... procrustes ([1, 2; -3, 4; 2, 3], [1, 2; -3, 4; 2, NaN]); ***** error ... procrustes ([1, 2; -3, 4; 2, 3], [1, 2; -3, 4; 2, Inf]); ***** error ... procrustes (ones (10 ,3), ones (11, 3)); ***** error ... procrustes (ones (10 ,3), ones (10, 4)); ***** error ... procrustes (ones (10 ,3), ones (10, 3), 'reflection'); ***** error ... procrustes (ones (10 ,3), ones (10, 3), true); ***** error ... procrustes (ones (10 ,3), ones (10, 3), 'scaling', 0); ***** error ... procrustes (ones (10 ,3), ones (10, 3), 'scaling', [true true]); ***** error ... procrustes (ones (10 ,3), ones (10, 3), 'reflection', 1); ***** error ... procrustes (ones (10 ,3), ones (10, 3), 'reflection', 'some'); ***** error ... procrustes (ones (10 ,3), ones (10, 3), 'param1', 'some'); 16 tests, 16 passed, 0 known failure, 0 skipped [inst/Dimensionality_Reduction/ppca.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Dimensionality_Reduction/ppca.m ***** demo ## Fit a two-component PPCA model and reconstruct the data. Y = [ 1.0, 2.0, 0.5; 2.1, 3.9, 1.2; ... -1.0, -2.2, -0.4; -2.0, -3.8, -1.1; ... 0.5, 1.1, 0.9; 1.6, 2.8, -0.2]; [coeff, score, pcvar, mu, v] = ppca (Y, 2); coeff pcvar ## The scores reconstruct the data through the coefficients. max (abs (vec (score * coeff' + mu - Y))) ***** test Y = reshape (mod ((1:40)*7, 17), 10, 4) - 8; opt = struct ("MaxIter", 2000, "TolFun", 1e-12, "TolX", 1e-12); [coeff, score, pcvar, mu, v] = ppca (Y, 2, "Options", opt); coeff_ref = [ 0.543716564044483, -0.391810693220729; ... 0.599330273587830, 0.314784124203745; ... 0.302509942024958, 0.761619894252268; ... -0.503649934101907, 0.409060475365608]; assert_equal (coeff, coeff_ref, 1e-6); assert_equal (pcvar, [49.558237292069599; 30.960532427249241], 1e-4); assert_equal (mu, [-0.1, 0.2, 0.5, -0.9], 1e-10); assert_equal (v, 10.623960883864141, 1e-4); ***** test Y = reshape (mod ((1:40)*7, 17), 10, 4) - 8; [coeff, score] = ppca (Y, 2); score_ref = [ -2.225140840148114, 4.921963749319239; ... 7.787588722827117, -7.324026640834169; ... -5.050861878994857, 1.641002156881092; ... 10.104537612540948, 2.342550721115434; ... -7.876582917841600, -1.639959435557055; ... -1.283233827199200, 6.015617613465288; ... -1.459120725735530, -11.581703199267448; ... -4.108954866045941, 2.734656021027141; ... 11.046444625489862, 3.436204585261484; ... -6.934675904892686, -0.546305571411006]; assert_equal (score, score_ref, 1e-4); ***** test ## coeff is orthonormal and score is the projection of the centred data. Y = reshape (mod ((1:40)*7, 17), 10, 4) - 8; [coeff, score, pcvar, mu] = ppca (Y, 2); assert_equal (coeff' * coeff, eye (2), 1e-10); assert_equal (score, (Y - mu) * coeff, 1e-10); ***** test ## Missing-data (NaN) case fitted by expectation-maximization. Y = reshape (mod ((1:40)*7, 17), 10, 4) - 8; Y(3,2) = NaN; Y(7,4) = NaN; opt = struct ("MaxIter", 5000, "TolFun", 1e-12, "TolX", 1e-12); [coeff, score, pcvar, mu, v] = ppca (Y, 2, "Options", opt); coeff_ref = [ 0.489878122099491, -0.455706110813571; ... 0.631344835584810, 0.254329922477782; ... 0.331227809703440, 0.763974559487245; ... -0.501708343709497, 0.379461596944783]; assert_equal (coeff, coeff_ref, 1e-4); assert_equal (pcvar, [49.932943652722741; 28.917799526089862], 1e-3); assert_equal (mu, [-0.099999999999924, 0.225205294055629, ... 0.500000000000008, -0.683793705409387], 1e-4); assert_equal (v, 10.684669221332555, 1e-3); ***** test ## Output sizes. Y = reshape (mod ((1:40)*7, 17), 10, 4) - 8; [coeff, score, pcvar, mu, v, S] = ppca (Y, 3); assert_equal (size (coeff), [4, 3]); assert_equal (size (score), [10, 3]); assert_equal (size (pcvar), [3, 1]); assert_equal (size (mu), [1, 4]); assert_equal (isscalar (v), true); assert_equal (isfield (S, "W") && isfield (S, "Recon"), true); ***** error ppca (ones (5, 3)) ***** error ppca ({1, 2}, 1) ***** error ppca ([1+2i, 3; 4, 5], 1) ***** error ppca (ones (5, 3), 0) ***** error ppca (ones (5, 3), 1.5) ***** error ppca (ones (5, 3), 3) ***** error ppca (ones (5, 3), 1, "W0") ***** error ppca (ones (5, 3), 1, "foo", 1) ***** error ppca (ones (5, 3), 1, "W0", ones (2, 2)) ***** error ppca (ones (5, 3), 1, "Options", 5) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Dimensionality_Reduction/cmdscale.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Dimensionality_Reduction/cmdscale.m ***** test m = randi (100) + 1; n = randi (100) + 1; X = rand (m, n); D = pdist (X); assert_equal (norm (pdist (cmdscale (D))), norm (D), sqrt (eps)); assert_equal (norm (pdist (cmdscale (squareform (D)))), norm (D), sqrt (eps)); ***** test ## test output X = [ 0.8147, 0.1576, 0.6557, 0.7060; 0.9058, 0.9706, 0.0357, 0.0318; 0.1270, 0.9572, 0.8491, 0.2769; 0.9134, 0.4854, 0.9340, 0.0462; 0.6324, 0.8003, 0.6787, 0.0971 ]; D = pdist (X); p = 2; [Y, e] = cmdscale (D, p); expected_Y = [ 0.635444598081665, -0.209808014423477; -0.558655450609184, -0.457908993032377; -0.158680352453745, 0.622280326562354; 0.222509398493731, -0.047804408953240; -0.140618193512467, 0.093241089846740 ]; expected_e = [0.810349112746116; 0.651912015993974]; assert_equal (Y, expected_Y, 1e-14); assert_equal (e, expected_e, 1e-14); ***** test ## basic dimentionality reduction D = [0 2 3; 2 0 4; 3 4 0]; [Y, e] = cmdscale (D, 2); assert_equal (size (Y, 2), 2); assert_equal (length (e), 2); ***** test ## oversized dimension X = [0 0; 1 0; 0 1; 1 1]; D = pdist (X); [Y, e] = cmdscale (D, 3); assert_equal (size (Y, 2), 2); assert_equal (length (e), 3); ***** test ## non euclidean distance. X = [1 2; 3 4; 5 6; 7 8; 9 10]; D = pdist (X, 'cityblock'); [Y, e] = cmdscale (D, 2); assert_equal (size (Y, 2), 1); assert_equal (length (e), 2); ***** test ## compatability with p X = rand (10, 4); D = pdist (X); [Y, e] = cmdscale (D, 3); assert_equal (size (Y, 2), 3); assert_equal (length (e), 3); assert_equal (size (Y, 1), 10); ***** test ## sign convention. rng (0, 'twister'); X = rand (10, 3); D = pdist (X); Y = cmdscale (D); [~, maxind] = max (abs (Y), [], 1); d = size (Y, 2); n = size (Y, 1); idx = maxind + (0 : n : (d - 1) * n); assert_equal (all (Y(idx) >= 0), true); ***** test ## testing with p = n and without p rng (1, 'twister'); X = rand (10, 4); D = pdist (X); n_points = size (X, 1); [Y1, e1] = cmdscale (D); [Y2, e2] = cmdscale (D, n_points); assert_equal (size (Y1, 2), size (Y2, 2)); ***** test ## Test that all coincident points (n_pos == 0) still give a single ## zero-filled column instead of an n-by-0 empty matrix D = zeros (4, 4); [Y, e] = cmdscale (D); assert_equal (size (Y), [4, 1]); assert_equal (Y, zeros (4, 1)); assert_equal (e, zeros (4, 1)); ***** test ## Same boundary case at the smallest possible input, a single point [Y, e] = cmdscale (0); assert_equal (Y, zeros (2, 1)); assert_equal (e, zeros (2, 1)); ***** test ## Coincident points give one column whatever p asks for [Y, e] = cmdscale (zeros (4, 4), 2); assert_equal (size (Y), [4, 1]); assert_equal (size (e), [2, 1]); ***** test ## A similarity matrix of all ones is coincident after conversion [Y, e] = cmdscale (ones (3, 3)); assert_equal (Y, zeros (3, 1)); assert_equal (e, zeros (3, 1)); ***** error cmdscale ({'not', 'a', 'matrix'}) ***** error cmdscale (rand (3, 4)) ***** error cmdscale (-ones (3)) ***** error

cmdscale (eye (3), 0) ***** error

cmdscale (eye (3), 4) ***** error

cmdscale (eye (3), 1.5) ***** error

cmdscale (eye (3), [1, 2]) ***** error

cmdscale (eye (3), 2 + 1i) 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Dimensionality_Reduction/mdscale.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Dimensionality_Reduction/mdscale.m ***** demo ## Recover a 2-D map of 8 points from their pairwise distances. rng = [0 0; 5 0; 5 4; 0 4; 8 2; -3 2; 2 7; 2 -3]; D = pdist (rng); [Y, stress] = mdscale (D, 2, 'Criterion', 'metricstress'); stress ## Y reproduces the pairwise distances closely. max (abs (pdist (Y)' - D')) ***** shared C, D, Y0, opt C = [0 0 0; 5 1 2; 2 6 1; 1 2 7; 7 3 4; 3 8 5; 6 4 9; 4 9 3]; D = pdist (C); Y0 = [1 -1; -1 1; 2 2; -2 -2; 3 1; 1 3; -3 -1; -1 -3]; opt = struct ("MaxIter", 1000, "TolFun", 1e-10, "TolX", 1e-10); ***** test [Y, s] = mdscale (D, 2, "Criterion", "metricstress", "Start", Y0, "Options", opt); Yref = [ 6.810767239317778, -0.733620649959338; ... 3.071301239764592, 1.094132882710339; ... 1.065313739387755, -3.760130869234625; ... 0.623478915333739, 4.891508042741564; ... -0.674391648191895, 1.443596654184263; ... -3.493671563292435, -2.348293046078109; ... -4.559656269176627, 3.674896334304512; ... -2.843141653142908, -4.262089348668606]; assert_equal (Y, Yref, 1e-4); assert_equal (s, 0.144654108154698, 1e-8); ***** test [Y, s] = mdscale (D, 2, "Criterion", "metricsstress", "Start", Y0, "Options", opt); Yref = [ 6.635327214692762, 0.792856204849063; ... 3.228563095536443, -1.334104353307981; ... 1.003358563030293, 3.760704781755182; ... 0.699645585641474, -3.784555012990314; ... -1.079052104978016, -2.376723256450389; ... -3.223960839101638, 2.563657848313004; ... -4.268551283289842, -3.733948071746559; ... -2.995330231531478, 4.112111859577994]; assert_equal (Y, Yref, 1e-4); assert_equal (s, 0.190937534497622, 1e-8); ***** test [Y, s] = mdscale (D, 2, "Criterion", "sammon", "Start", Y0, "Options", opt); Yref = [ 6.933279805420950, -0.419508440326684; ... 3.008163425596839, 1.373357387532562; ... 1.273453983125238, -3.707332917059666; ... 0.101742369038229, 5.027798678525714; ... -0.450738847427944, 1.372181450811530; ... -3.390706238135306, -2.442042299704407; ... -4.908058626481512, 3.317873521951261; ... -2.567135871136496, -4.522327381730312]; assert_equal (Y, Yref, 1e-4); assert_equal (s, 0.023119816166763, 1e-8); ***** test ## 'strain' is classical scaling: configuration and value are reproducible. [Y, s] = mdscale (D, 2, "Criterion", "strain", "Start", Y0, "Options", opt); Yref = [ 6.572163580404339, -0.496338025399502; ... 2.719997306646783, 1.496763413554223; ... 1.036596577326041, -3.598999625596409; ... 0.538361534877868, 2.777882896586096; ... -0.658048085951181, 1.901764558503386; ... -3.170613455894927, -2.220122324409574; ... -4.005398518313616, 4.052005597122571; ... -3.033058939095310, -3.912956490360791]; assert_equal (Y, Yref, 1e-3); assert_equal (s, 1.930074461959919e+02, 1e-6); ***** test ## Nonmetric 'stress': the stress value matches MATLAB (configuration is ## only defined up to the local minimum -- see the non-uniqueness note). [Y, s, dsp] = mdscale (D, 2, "Criterion", "stress", "Start", Y0, "Options", opt); assert_equal (s, 0.078131057459269, 1e-6); assert_equal (size (Y), [8, 2]); assert_equal (numel (dsp), 28); ## disparities are monotone in the dissimilarities [~, ord] = sort (D(:)); assert_equal (all (diff (dsp(ord)) >= -1e-9), true); ***** test ## Nonmetric 'sstress' stress value. [Y, s] = mdscale (D, 2, "Criterion", "sstress", "Start", Y0, "Options", opt); assert_equal (s <= 0.089488341028430 + 1e-6, true); ***** test ## Near-collinear data: the nonmetric fit is perfect, so the residuals are ## exactly zero and the criterion gradient is 0/0. R2024a returns ## 1.122356541711999e-16 here and does not raise. A = [1, 2; 2, 4.1; 3, 5.9; 4, 8.2; 5, 9.8; 6, 12.1; 7, 13.9; 8, 16.2]; [Y, s] = mdscale (pdist (A), 2, 'Criterion', 'stress'); assert_equal (size (Y), [8, 2]); assert_equal (s < 1e-9, true); ***** test ## The same degeneracy under 'sstress'; R2024a returns 2.0818624071994747e-16. A = [1, 2; 2, 4.1; 3, 5.9; 4, 8.2; 5, 9.8; 6, 12.1; 7, 13.9; 8, 16.2]; [Y, s] = mdscale (pdist (A), 2, 'Criterion', 'sstress'); assert_equal (size (Y), [8, 2]); assert_equal (s < 1e-9, true); ***** test ## The default criterion is 'stress'. No other block calls mdscale without ## naming a criterion, so this is the only cover of the default path. A = [1, 2; 2, 4.1; 3, 5.9; 4, 8.2; 5, 9.8; 6, 12.1; 7, 13.9; 8, 16.2]; [Y1, s1] = mdscale (pdist (A), 2); [Y2, s2] = mdscale (pdist (A), 2, 'Criterion', 'stress'); assert_equal (s1, s2, 1e-12); ***** test ## Accepts a square dissimilarity matrix as well as a vector. [Y1, s1] = mdscale (D, 2, "Criterion", "metricstress", "Start", Y0, "Options", opt); [Y2, s2] = mdscale (squareform (D), 2, "Criterion", "metricstress", ... "Start", Y0, "Options", opt); assert_equal (Y1, Y2, 1e-12); ***** test ## Returned configuration is centred and on principal axes. Y = mdscale (D, 2, "Criterion", "metricstress", "Start", Y0, "Options", opt); assert_equal (mean (Y), [0, 0], 1e-10); c = cov (Y); assert_equal (c(1,2), 0, 1e-8); ***** error mdscale (D) ***** error mdscale (1:4, 2) ***** error ... mdscale (ones (3, 4), 2) ***** error ... mdscale ([1, -2, 3], 1) ***** error mdscale (D, 8) ***** error mdscale (D, 0) ***** error mdscale (D, 2, "Criterion", "foo") ***** error mdscale (D, 2, "bogus", 1) ***** error ... mdscale (D, 2, "Weights", [1, 2, 3]) ***** error ... mdscale (D, 2, "Replicates", 0) ***** error mdscale (D, 2, "Start", "bad") ***** error mdscale (D, 2, "Options", 5) 23 tests, 23 passed, 0 known failure, 0 skipped [inst/Dimensionality_Reduction/pca.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Dimensionality_Reduction/pca.m ***** shared COEFF,SCORE,latent,tsquare,m,x,R,V,lambda,i,S,F ***** test x = [7, 4, 3; 4, 1, 8; 6, 3, 5; 8, 6, 1; 8, 5, 7; ... 7, 2, 9; 5, 3, 3; 9, 5, 8; 7, 4, 5; 8, 2, 2]; R = corrcoef (x); [V, lambda] = eig (R); [~, i] = sort (diag (lambda), 'descend'); #arrange largest PC first S = V(:, i) * diag (sqrt (diag (lambda)(i))); ***** assert_equal (diag (S(:, 1:2) * S(:, 1:2)'), [0.8662; 0.8420; 0.9876], 1E-4); B = V(:, i) * diag ( 1./ sqrt (diag (lambda)(i))); F = zscore (x) * B; [COEFF, SCORE, latent, tsquare] = pca (zscore (x, 1)); ***** assert_equal (tsquare, sumsq (F, 2), 1E4*eps); ***** test x = [1, 2, 3; 2, 1, 3]'; [COEFF, SCORE, latent, tsquare] = pca (x, 'Economy', false); m = [sqrt(2), sqrt(2); sqrt(2), -sqrt(2); -2*sqrt(2), 0] / 2; m(:,1) = m(:,1) * sign (COEFF(1,1)); m(:,2) = m(:,2) * sign (COEFF(1,2)); ***** assert_equal (COEFF, m(1:2,:), 10*eps); ***** assert_equal (SCORE, -m, 10*eps); ***** assert_equal (latent, [1.5;.5], 10*eps); ***** assert_equal (tsquare, [4;4;4]/3, 10*eps); [COEFF, SCORE, latent, tsquare] = pca (x, 'Economy', false, 'weights', ... [1 2 1], 'variableweights', ... 'variance'); ***** assert_equal (COEFF, [0.632455532033676, -0.632455532033676; ... 0.741619848709566, 0.741619848709566], 10 * eps); ***** assert_equal (SCORE, [-0.622019449426284, 0.959119380657905; ... -0.505649896847432, -0.505649896847431; 1.633319243121148, 0.052180413036957], 10 * eps); ***** assert_equal (latent, [1.783001790889027; 0.716998209110974], 10 * eps); ***** test assert_equal (tsquare, [1.5; 0.5; 1.5], 10 * eps); ***** test x = [1,2,3;2,1,3]'; [COEFF, SCORE, latent, tsquare] = pca (x, 'Economy', false, 'weights', ... [2 1 2], 'variableweights', ... 'variance'); COEFF_exp = [0.7906, 0.7906; 0.6614, -0.6614]; SCORE_exp = [-0.7836, -0.4813; -0.9071, 0.9071; 1.2372, 0.0277]; latent_exp = [2.5562; 0.6438]; tsquare_exp = [0.6000; 1.6000; 0.6000]; assert_equal (COEFF, COEFF_exp, 1e-4); assert_equal (SCORE, SCORE_exp, 1e-4); assert_equal (latent, latent_exp, 1e-4); assert_equal (tsquare, tsquare_exp, 1e-4); ***** test x = [1,2,3;2,1,3]'; [COEFF, SCORE, latent, tsquare] = pca (x, 'Economy', false, 'weights', ... [1 3 2], 'variableweights', ... 'variance'); COEFF_exp = [0.6216, -0.6216; 0.8118, 0.8118]; SCORE_exp = [-0.8358, 1.0411; -0.6473, -0.3792; 1.3889, 0.0482]; latent_exp = [2.9067; 0.7599]; tsquare_exp = [1.6667; 0.3333; 0.6667]; assert_equal (COEFF, COEFF_exp, 1e-4); assert_equal (SCORE, SCORE_exp, 1e-4); assert_equal (latent, latent_exp, 1e-4); assert_equal (tsquare, tsquare_exp, 1e-4); ***** test x = [1,2,3;2,1,3]'; [COEFF, SCORE, latent, tsquare] = pca (x, 'Economy', false, 'weights', ... [1 0.5 1.5], 'variableweights', ... 'variance'); COEFF_exp = [0.8118, 0.8118; 0.6742, -0.6742]; SCORE_exp = [-0.9657, -0.4713; -1.0915, 0.8862; 1.0076, 0.0188]; latent_exp = [1.5257; 0.3077]; tsquare_exp = [1.3333; 3.3333; 0.6667]; assert_equal (COEFF, COEFF_exp, 1e-4); assert_equal (SCORE, SCORE_exp, 1e-4); assert_equal (latent, latent_exp, 1e-4); assert_equal (tsquare, tsquare_exp, 1e-4); ***** test x = [1,2,3;2,1,3]'; [COEFF, SCORE, latent, tsquare] = pca (x, 'Economy', true, 'weights', ... [2 1 2], 'variableweights', ... 'variance'); COEFF_exp = [0.7906, 0.7906; 0.6614, -0.6614]; SCORE_exp = [-0.7836, -0.4813; -0.9071, 0.9071; 1.2372, 0.0277]; latent_exp = [2.5562; 0.6438]; tsquare_exp = [0.6000; 1.6000; 0.6000]; assert_equal (COEFF, COEFF_exp, 1e-4); assert_equal (SCORE, SCORE_exp, 1e-4); assert_equal (latent, latent_exp, 1e-4); assert_equal (tsquare, tsquare_exp, 1e-4); ***** test x = [1,2,3;2,1,3]'; [COEFF, SCORE, latent, tsquare] = pca (x, 'Economy', true, 'weights', ... [1 3 2], 'variableweights', ... 'variance'); COEFF_exp = [0.6216, -0.6216; 0.8118, 0.8118]; SCORE_exp = [-0.8358, 1.0411; -0.6473, -0.3792; 1.3889, 0.0482]; latent_exp = [2.9067; 0.7599]; tsquare_exp = [1.6667; 0.3333; 0.6667]; assert_equal (COEFF, COEFF_exp, 1e-4); assert_equal (SCORE, SCORE_exp, 1e-4); assert_equal (latent, latent_exp, 1e-4); assert_equal (tsquare, tsquare_exp, 1e-4); ***** test x = [1,2,3;2,1,3]'; [COEFF, SCORE, latent, tsquare] = pca (x, 'Economy', true, 'weights', ... [1 0.5 1.5], 'variableweights', ... 'variance'); COEFF_exp = [0.8118, 0.8118; 0.6742, -0.6742]; SCORE_exp = [-0.9657, -0.4713; -1.0915, 0.8862; 1.0076, 0.0188]; latent_exp = [1.5257; 0.3077]; tsquare_exp = [1.3333; 3.3333; 0.6667]; assert_equal (COEFF, COEFF_exp, 1e-4); assert_equal (SCORE, SCORE_exp, 1e-4); assert_equal (latent, latent_exp, 1e-4); assert_equal (tsquare, tsquare_exp, 1e-4); ***** test x = x'; [COEFF, SCORE, latent, tsquare] = pca (x, 'Economy', false); m = [sqrt(2), sqrt(2), 0; -sqrt(2), sqrt(2), 0; 0, 0, 2] / 2; m(:,1) = m(:,1) * sign (COEFF(1,1)); m(:,2) = m(:,2) * sign (COEFF(1,2)); m(:,3) = m(:,3) * sign (COEFF(3,3)); ***** assert_equal (COEFF, m, 10*eps); ***** assert_equal (SCORE(:,1), -m(1:2,1), 10*eps); ***** assert_equal (SCORE(:,2:3), zeros (2), 10*eps); ***** assert_equal (latent, [1;0;0], 10*eps); ***** ## two centered observations carry one degree of freedom, so no component ***** ## counts and T-square is 0, as R2024a returns it ***** assert_equal (tsquare, [0;0], 10*eps) ***** test [COEFF, SCORE, latent, tsquare] = pca (x); ***** assert_equal (COEFF, m(:, 1), 10*eps); ***** assert_equal (SCORE, -m(1:2,1), 10*eps); ***** assert_equal (latent, [1], 10*eps); ***** assert_equal (tsquare, [0;0], 10*eps) ***** test ## Complex missing data test x = [ 0.8147 0.2785 0.9575 0.9058 0.5469 0.9649 0.1270 0.9575 0.1576 0.9134 0.9649 0.9706 0.6324 0.1576 0.9572 0.0975 0.9706 0.4854 0.2785 0.9575 0.8003 0.5469 0.1419 0.1419 ]; x_nan = x; x_nan(2, 3) = NaN; x_nan(5, 1) = NaN; [COEFF, SCORE, latent, tsquare] = pca (x_nan, 'Economy', false); ## Verify NaNs are correctly placed in SCORE and tsquare assert_equal (all (isnan (SCORE(2, :))), true); assert_equal (all (isnan (SCORE(5, :))), true); assert_equal (isnan (tsquare(2)), true); assert_equal (isnan (tsquare(5)), true); ## Verify other rows do not have NaNs assert_equal (any (isnan (SCORE([1 3 4 6 7 8], :))(:)), false); assert_equal (any (isnan (tsquare([1 3 4 6 7 8]))), false); ***** error pca ([1 2; 3 4], 'Algorithm', 'xxx') ***** error pca ([1 NaN; 3 4], 'Rows', 'all') ***** error <'centered' requires a boolean value> pca ([1 2; 3 4], 'Centered', 'xxx') ***** error pca ([1 2; 3 4], 'NumComponents', -4) ***** error pca ([1 2; 3 4], 'Rows', 1) ***** error pca ([1 2; 3 4], 'Weights', [1 2 3]) ***** error pca ([1 2; 3 4], 'Weights', [-1 2]) ***** error pca ([1 2; 3 4], 'VariableWeights', [-1 2]) ***** error pca ([1 2; 3 4], 'VariableWeights', 'xxx') ***** error pca ([1 2; 3 4], 'XXX', 1) ***** test [c, s, l, t, e, m] = pca ([]); assert_equal (size (c), [0 0]); assert_equal (size (s), [0 0]); assert_equal (size (l), [0 1]); assert_equal (size (t), [0 1]); assert_equal (size (e), [0 0]); assert_equal (size (m), [0 0]); ***** test [c, s, l, t, e, m] = pca (zeros (0, 3)); assert_equal (size (c), [3 0]); assert_equal (size (s), [0 0]); assert_equal (size (l), [0 1]); assert_equal (size (t), [0 1]); assert_equal (size (e), [0 0]); assert_equal (size (m), [0 0]); ***** test [c, s, l, t, e, m] = pca (zeros (3, 0)); assert_equal (size (c), [0 0]); assert_equal (size (s), [3 0]); assert_equal (size (l), [0 1]); assert_equal (size (t), [3 1]); assert_equal (size (e), [0 0]); assert_equal (size (m), [0 0]); 43 tests, 43 passed, 0 known failure, 0 skipped [inst/Dimensionality_Reduction/tsne.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Dimensionality_Reduction/tsne.m ***** demo ## Embed a small five-dimensional data set into two dimensions. rng (42); X = [randn(20, 5); randn(20, 5) + 5]; Y = tsne (X, "Perplexity", 10); plot (Y(1:20,1), Y(1:20,2), "bo", Y(21:end,1), Y(21:end,2), "rx"); title ("t-SNE embedding"); ***** test X = reshape (mod ((1:60)*7, 13), 12, 5) - 6; Y0 = reshape (mod ((1:24)*3, 7), 12, 2) - 3; opt = struct ("MaxIter", 20, "TolFun", 0); [Y, loss] = tsne (X, "Algorithm", "exact", "Distance", "euclidean", ... "NumDimensions", 2, "Perplexity", 3, "Exaggeration", 1, ... "LearnRate", 100, "Standardize", false, "InitialY", Y0, ... "Options", opt); Yref = [-11.087464047262014, 26.776776669616648; ... 4.015876079561814, 4.314538936119215; ... -10.791976288780955, -28.890539694879799; ... -6.197553982245900, 11.136429372335288; ... -4.791764519072724, -29.162528702965172; ... -0.506807464921708, 13.209994463821561; ... -1.097171761767460, -24.062824347518902; ... 0.108706666197103, 21.076444386535410; ... 1.270590904095503, -17.709227609503525; ... 7.840024872376860, 19.937127571156172; ... 6.043642805354078, -19.531582453041814; ... 13.753383923495731, 22.678754729129128]; assert_equal (Y, Yref, 1e-8); assert_equal (loss, 0.298069770937047, 1e-10); ***** test ## Output sizes and reproducibility with a fixed initial embedding. X = reshape (mod ((1:60)*7, 13), 12, 5) - 6; Y0 = reshape (mod ((1:24)*3, 7), 12, 2) - 3; Y1 = tsne (X, "Perplexity", 3, "InitialY", Y0, ... "Options", struct ("MaxIter", 50)); Y2 = tsne (X, "Perplexity", 3, "InitialY", Y0, ... "Options", struct ("MaxIter", 50)); assert_equal (size (Y1), [12, 2]); assert_equal (Y1, Y2, 1e-12); ***** test ## NumDimensions controls the embedding dimension. X = reshape (mod ((1:60)*7, 13), 12, 5) - 6; Y = tsne (X, "NumDimensions", 3, "Perplexity", 3, ... "Options", struct ("MaxIter", 20)); assert_equal (size (Y), [12, 3]); ***** test ## The Barnes-Hut tree reproduces the exact pairwise repulsion when nothing ## is collapsed, which is what pins the summation without an oracle. Y = reshape (mod ((1:60)*7, 13), 30, 2) - 6; [F, Z] = __bhtsne__ (Y, 0); n = rows (Y); Fe = zeros (n, 2); Ze = 0; for i = 1:n d = Y(i,:) - Y; q = 1 ./ (1 + sum (d .^ 2, 2)); q(i) = 0; Ze += sum (q); Fe(i,:) = sum ((q .^ 2) .* d, 1); endfor assert_equal (F, Fe, 1e-12); assert_equal (Z, Ze, 1e-10); ***** test ## A larger Theta collapses cells, so it approximates rather than reproduces. Y = reshape (mod ((1:60)*7, 13), 30, 2) - 6; [F0, Z0] = __bhtsne__ (Y, 0); [F5, Z5] = __bhtsne__ (Y, 0.5); assert_equal (norm (F5 - F0, "fro") / norm (F0, "fro") < 0.1, true); assert_equal (abs (Z5 - Z0) / Z0 < 0.1, true); assert_equal (isequal (F5, F0), false); ***** test ## The tree handles coincident points, which an embedding starts out full ## of and which a subdivision to one point per cell never separates. Y = zeros (12, 2); [F, Z] = __bhtsne__ (Y, 0.5); assert_equal (F, zeros (12, 2), 1e-12); assert_equal (Z, 132, 1e-10); ***** test ## 'barneshut' returns an embedding of the right shape and a finite loss. X = [reshape(mod((1:100)*7, 13), 20, 5) - 6; ... reshape(mod((1:100)*7, 13), 20, 5) + 30]; [Y, loss] = tsne (X, "Algorithm", "barneshut", "Perplexity", 3, ... "NumDimensions", 2, "Options", struct ("MaxIter", 200)); assert_equal (size (Y), [40, 2]); assert_equal (all (isfinite (Y(:))), true); assert_equal (isfinite (loss) && loss > 0, true); ***** test ## It optimizes: the divergence falls as the iterations run. X = [reshape(mod((1:100)*7, 13), 20, 5) - 6; ... reshape(mod((1:100)*7, 13), 20, 5) + 30]; args = {"Algorithm", "barneshut", "Perplexity", 3, ... "InitialY", reshape(mod((1:80)*3, 7), 40, 2) - 3}; [~, l1] = tsne (X, args{:}, "Options", struct ("MaxIter", 120)); [~, l2] = tsne (X, args{:}, "Options", struct ("MaxIter", 400)); assert_equal (l2 < l1, true); ***** test ## It tracks the exact algorithm it approximates, from the same start. X = [reshape(mod((1:100)*7, 13), 20, 5) - 6; ... reshape(mod((1:100)*7, 13), 20, 5) + 30]; o = struct ("MaxIter", 400); args = {"Perplexity", 3, "InitialY", reshape(mod((1:80)*3, 7), 40, 2) - 3, ... "Options", o}; [~, lb] = tsne (X, args{:}, "Algorithm", "barneshut"); [~, le] = tsne (X, args{:}, "Algorithm", "exact"); assert_equal (abs (lb - le) / le < 0.3, true); ***** test ## Theta reaches the fit: two values give two embeddings. X = reshape (mod ((1:100)*7, 13), 20, 5) - 6; o = struct ("MaxIter", 50); args = {"Algorithm", "barneshut", "Perplexity", 4, "NumDimensions", 2, ... "InitialY", reshape(mod((1:40)*3, 7), 20, 2) - 3, "Options", o}; Ya = tsne (X, args{:}, "Theta", 0); Yb = tsne (X, args{:}, "Theta", 0.8); assert_equal (isequal (Ya, Yb), false); ***** test ## 'barneshut' takes the same NumDimensions the tree is built for. X = reshape (mod ((1:100)*7, 13), 20, 5) - 6; for d = 1:3 Y = tsne (X, "Algorithm", "barneshut", "NumDimensions", d, ... "Perplexity", 4, "Options", struct ("MaxIter", 20)); assert_equal (size (Y), [20, d]); endfor ***** error tsne () ***** error tsne ({1, 2}) ***** error tsne ([1, Inf; 2, 3]) ***** error ... tsne (ones (5, 3), "Algorithm", "bogus") ***** error ... tsne (ones (5, 3), "Algorithm", "barneshut", "Theta", -1) ***** error ... tsne (ones (5, 3), "Algorithm", "barneshut", "Theta", [1, 2]) ***** error ... tsne (ones (8, 5), "Algorithm", "barneshut", "NumDimensions", 4, "Perplexity", 2) ***** error ... tsne (ones (5, 3), "Perplexity", 5) ***** error ... tsne (ones (5, 3), "Perplexity", 2, "Exaggeration", 0) ***** error ... tsne (ones (5, 3), "Perplexity", 2, "LearnRate", -1) ***** error tsne (ones (5, 3), "bogus", 1) ***** error ... tsne (ones (5, 3), "Perplexity", 2, "NumDimensions", 0) ***** error ... tsne (ones (5, 3), "Perplexity", 2, "NumDimensions", -1) ***** error ... tsne (ones (5, 3), "Perplexity", 2, "NumDimensions", 2.5) ***** error ... tsne (ones (5, 3), "Perplexity", 2, "NumDimensions", [2, 3]) ***** error ... tsne (ones (5, 3), "Perplexity", 2, "NumDimensions", "a") ***** error ... tsne (ones (5, 3), "Perplexity", 2, "NumDimensions", true) ***** error ... tsne (ones (5, 3), "Perplexity", 2, "NumDimensions", Inf) ***** error ... tsne (ones (5, 3), "Perplexity", 2, "NumDimensions", 4) ***** test X = [1 2 3; 2 4 6; 3 5 9; 4 8 11; 5 9 14; 6 11 17]; Y = tsne (X, "Perplexity", 2, "NumDimensions", []); assert_equal (columns (Y), 2); Y = tsne (X, "Perplexity", 2, "NumDimensions", int32 (2)); assert_equal (columns (Y), 2); Y = tsne (X, "Perplexity", 2, "NumDimensions", 3); assert_equal (columns (Y), 3); 31 tests, 31 passed, 0 known failure, 0 skipped [inst/Clustering/inconsistent.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Clustering/inconsistent.m ***** error inconsistent () ***** error inconsistent ([1 2 1], 2, 3) ***** error inconsistent (ones (2, 2)) ***** error inconsistent ([1 2 1], -1) ***** error inconsistent ([1 2 1], 1.3) ***** error inconsistent ([1 2 1], [1 1]) ***** error inconsistent (ones (2, 3)) ***** test load fisheriris; Z = linkage (meas, 'average', 'chebychev'); assert_equal (cond (inconsistent (Z)), 39.9, 1e-3); 8 tests, 8 passed, 0 known failure, 0 skipped [inst/Clustering/linkage.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Clustering/linkage.m ***** shared x, t x = reshape (mod (magic (6),5), [], 3); t = 1e-6; ***** test Z = linkage (pdist (x)); assert_equal (Z(:,3), [1; 1; 1; 1.414214; 1.414214; 1.414214; ... 2.236068; 2.236068; 2.236068; 2.236068; 3], t); ***** test Z = linkage (pdist (x), 'complete'); assert_equal (Z(:,3), [1; 1; 1.414214; 1.414214; 1.414214; 2.236068; ... 2.236068; 3.162278; 3.741657; 4.690416; 6], t); ***** test Z = linkage (pdist (x), 'average'); assert_equal (Z(:,3), [1; 1; 1.207107; 1.414214; 1.414214; 1.962117; ... 2.236068; 2.948887; 3.081139; 3.515667; ... 4.177650], t); ***** test Z = linkage (pdist (x), 'weighted'); assert_equal (Z(1:7,3), [1; 1; 1.207107; 1.414214; 1.414214; ... 2.030604; 2.236068], t); assert_equal (all (diff (Z(:,3)) >= -eps), true); lastwarn (); # Clear last warning before the test ***** warning linkage (pdist (x), 'centroid'); ***** test warning off Octave:clustering Z = linkage (pdist (x), 'centroid'); assert_equal (Z(:,3), [1; 1; 1.118034; 1.414214; 1.224745; 1.885618; ... 2.236068; 2.708013; 2.980378; 3.041381; ... 3.529418], t); warning on Octave:clustering ***** warning linkage (pdist (x), 'median'); ***** test warning off Octave:clustering Z = linkage (pdist (x), 'median'); assert_equal (Z(:,3), [1; 1; 1.118034; 1.414214; 1.224745; 1.952562; ... 2.236068; 2.452677; 3.041381; 3.057394; ... 3.163667], t); warning on Octave:clustering ***** test Z = linkage (pdist (x), 'ward'); assert_equal (Z(:,3), [1; 1; 1.290994; 1.414214; 1.414214; 2.236068; ... 2.309401; 3.511885; 4.690416; 5.228129; ... 7.713624], t); ***** test Z = linkage (pdist (x), 'ward'); assert_equal (linkage (x, 'ward', 'euclidean'), Z); assert_equal (linkage (x, 'ward', {'euclidean'}), Z); assert_equal (linkage (x, 'ward', {'minkowski', 2}), Z); ***** test Z = linkage (pdist (x)); assert_equal (sort ([Z(:,1); Z(:,2)])', 1:22); assert_equal (all (Z(:,1) < Z(:,2)), true); ***** test y = [1 2; 3 5; 4 6; 7 8; 9 11]; L = linkage (y, 'single', 'cityblock'); assert_equal (size (L), [4, 3]); assert_equal (all (L(:,3) >= 0), true); # distances non-negative ***** test y = [1 2; 3 5; 4 6; 7 8; 9 11]; L = linkage (y, 'complete', 'cityblock'); assert_equal (size (L), [4, 3]); assert_equal (all (diff (L(:,3)) >= -eps), true); # monotonically increasing ***** test y = [1 2; 3 5; 4 6; 7 8; 9 11]; L = linkage (y, 'average', 'chebychev'); assert_equal (size (L), [4, 3]); assert_equal (all (L(:,3) >= 0), true); ***** test y = [1 2 3; 4 5 6; 7 8 9; 10 11 12]; L = linkage (y, 'weighted', {'minkowski', 3}); assert_equal (size (L), [3, 3]); assert_equal (all (L(:,3) >= 0), true); ***** test y = [1 0 1; 0 1 1; 1 1 0; 0 0 1]; L = linkage (y, 'single', 'cosine'); assert_equal (size (L), [3, 3]); assert_equal (all (L(:,3) >= 0), true); ***** test y = [1 2 3; 2 3 4; 5 6 7]; L = linkage (y, 'complete', 'correlation'); assert_equal (size (L), [2, 3]); assert_equal (all (L(:,3) >= 0), true); ***** test y = [1 2; 3 4]; L = linkage (y, 'single', 'euclidean'); assert_equal (size (L), [1, 3]); assert_equal (L(1,1:2), [1, 2]); ***** test y = rand (6, 3); L = linkage (y, 'average', 'euclidean'); assert_equal (all (L(:,1) >= 1 & L(:,1) <= 11), true); # valid cluster refs assert_equal (all (L(:,2) >= 1 & L(:,2) <= 11), true); assert_equal (all (L(:,1) < L(:,2)), true); # sorted within rows ***** assert_equal (linkage ([1, Inf, 2], 'average'), [1, 2, 1; 3, 4, Inf]) ***** assert_equal (linkage ([1, Inf, 2], 'complete'), [1, 2, 1; 3, 4, Inf]) ***** assert_equal (linkage ([1, Inf, 2], 'single'), [1, 2, 1; 3, 4, 2]) ***** assert_equal (linkage ([Inf, Inf, Inf], 'average'), [2, 3, Inf; 1, 4, Inf]) ***** assert_equal (linkage ([1, 2, 3, Inf, Inf, 4], 'average'), ... [1, 2, 1; 3, 4, 4; 5, 6, Inf]) ***** assert_equal (linkage ([1, NaN, 2], 'average'), [1, 2, 1; 3, 4, NaN]) ***** assert_equal (linkage ([NaN, NaN, NaN], 'average'), [1, 2, NaN; 3, 4, NaN]) ***** assert_equal (linkage (NaN (1, 10), 'average'), ... [1, 2, NaN; 3, 6, NaN; 4, 7, NaN; 5, 8, NaN]) ***** assert_equal (linkage ([NaN, NaN, NaN, NaN, NaN, 1], 'average'), ... [3, 4, 1; 1, 2, NaN; 5, 6, NaN]) ***** assert_equal (linkage ([NaN, 1, NaN(1, 8)], 'average'), ... [1, 3, 1; 2, 6, NaN; 4, 7, NaN; 5, 8, NaN]) ***** assert_equal (linkage ([Inf, NaN(1, 5)], 'average'), ... [1, 2, Inf; 3, 5, NaN; 4, 6, NaN]) 30 tests, 30 passed, 0 known failure, 0 skipped [inst/Clustering/SilhouetteEvaluation.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Clustering/SilhouetteEvaluation.m ***** test load fisheriris eva = evalclusters (meas, 'kmeans', 'silhouette', 'KList', [1:6]); assert_equal (class (eva), "SilhouetteEvaluation"); ***** function C = count_calls_silhouette (X, k) global count_calls_silhouette_n; count_calls_silhouette_n += 1; C = mod ((0 : rows (X) - 1)', k) + 1; ***** endfunction ***** test ## custom function must be called exactly once per inspected K global count_calls_silhouette_n; count_calls_silhouette_n = 0; evalclusters (rand (20, 2), @count_calls_silhouette, ... 'silhouette', 'KList', [2, 3]); assert_equal (count_calls_silhouette_n, 2); clear -global count_calls_silhouette_n; 2 tests, 2 passed, 0 known failure, 0 skipped [inst/Clustering/gmdistribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Clustering/gmdistribution.m ***** test mu = eye (2); Sigma = eye (2); GM = gmdistribution (mu, Sigma); density = GM.pdf ([0 0; 1 1]); assert_equal (density(1) - density(2), 0, 1e-6); [idx, nlogl, P, logpdf,M] = cluster (GM, eye (2)); assert_equal (idx, [1; 2]); [idx2,nlogl2,P2,logpdf2] = GM.cluster (eye (2)); assert_equal (nlogl - nlogl2, 0, 1e-6); [idx3,nlogl3,P3] = cluster (GM, eye (2)); assert_equal (P - P3, zeros (2), 1e-6); [idx4,nlogl4] = cluster (GM, eye (2)); assert_equal (size (nlogl4), [1 1]); idx5 = cluster (GM, eye (2)); assert_equal (idx - idx5, zeros (2,1)); D = GM.mahal ([1;0]); assert_equal (D - M(1,:), zeros (1,2), 1e-6); P = GM.posterior ([0 1]); assert_equal (P - P2(2,:), zeros (1,2), 1e-6); R = GM.random(20); assert_equal (size (R), [20, 2]); R = GM.random(); assert_equal (size (R), [1, 2]); 1 test, 1 passed, 0 known failure, 0 skipped [inst/Clustering/kmeans.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Clustering/kmeans.m ***** demo ## Generate a two-cluster problem rng (42); C1 = randn (100, 2) + 1; C2 = randn (100, 2) - 1; data = [C1; C2]; ## Perform clustering [idx, centers] = kmeans (data, 2); ## Plot the result figure; plot (data(idx==1, 1), data(idx==1, 2), 'ro'); hold on; plot (data(idx==2, 1), data(idx==2, 2), 'bs'); plot (centers(:, 1), centers(:, 2), 'kv', 'markersize', 10); title ('A simple two-clusters example'); hold off; ***** demo ## Cluster data using k-means clustering, then plot the cluster regions ## Load Fisher's iris data set and use the petal lengths and widths as ## predictors rng (42); load fisheriris X = meas(:,3:4); plot (X(:,1), X(:,2), 'k*', 'MarkerSize', 5); title ('Fisher''s Iris Data'); xlabel ('Petal Lengths (cm)'); ylabel ('Petal Widths (cm)'); ## Cluster the data. Specify k = 3 clusters [idx, C] = kmeans (X, 3); x1 = min (X(:,1)):0.01:max (X(:,1)); x2 = min (X(:,2)):0.01:max (X(:,2)); [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; idx2Region = kmeans (XGrid, 3, 'MaxIter', 10, 'Start', C); figure; gscatter (XGrid(:,1), XGrid(:,2), idx2Region, ... [0, 0.75, 0.75; 0.75, 0, 0.75; 0.75, 0.75, 0], '..'); hold on; plot (X(:,1), X(:,2), 'k*', 'MarkerSize', 5); title ('Fisher''s Iris Data'); xlabel ('Petal Lengths (cm)'); ylabel ('Petal Widths (cm)'); legend ('Region 1', 'Region 2', 'Region 3', 'Data', 'Location', 'SouthEast'); hold off ***** demo ## Partition Data into Two Clusters rng (42); r1 = randn (100, 2) * 0.75 + ones (100, 2); r2 = randn (100, 2) * 0.5 - ones (100, 2); X = [r1; r2]; plot (X(:,1), X(:,2), '.'); title ('Randomly Generated Data'); [idx, C] = kmeans (X, 2, 'Distance', 'cityblock', ... 'Replicates', 5, 'Display', 'final'); figure; plot (X(idx==1,1), X(idx==1,2), 'r.', 'MarkerSize', 12); hold on plot (X(idx==2,1), X(idx==2,2), 'b.', 'MarkerSize', 12); plot (C(:,1), C(:,2), 'kx', 'MarkerSize', 15, 'LineWidth', 3); legend ('Cluster 1', 'Cluster 2', 'Centroids', 'Location', 'NorthWest'); title ('Cluster Assignments and Centroids'); hold off ***** demo ## Assign New Data to Existing Clusters ## Generate a training data set using three distributions rng (42); r1 = randn (100, 2) * 0.75 + ones (100, 2); r2 = randn (100, 2) * 0.5 - ones (100, 2); r3 = randn (100, 2) * 0.75; X = [r1; r2; r3]; ## Partition the training data into three clusters by using kmeans [idx, C] = kmeans (X, 3); ## Plot the clusters and the cluster centroids gscatter (X(:,1), X(:,2), idx, 'bgm', '***'); hold on plot (C(:,1), C(:,2), 'kx'); legend ('Cluster 1', 'Cluster 2', 'Cluster 3', 'Cluster Centroid') ## Generate a test data set r1 = randn (100, 2) * 0.75 + ones (100, 2); r2 = randn (100, 2) * 0.5 - ones (100, 2); r3 = randn (100, 2) * 0.75; Xtest = [r1; r2; r3]; ## Classify the test data set using the existing clusters ## Find the nearest centroid from each test data point by using pdist2 D = pdist2 (C, Xtest, 'euclidean'); [group, ~] = find (D == min (D)); ## Plot the test data and label the test data using idx_test with gscatter gscatter (Xtest(:,1), Xtest(:,2), group, 'bgm', 'ooo'); box on; legend ('Cluster 1', 'Cluster 2', 'Cluster 3', 'Cluster Centroid', ... 'Data classified to Cluster 1', 'Data classified to Cluster 2', ... 'Data classified to Cluster 3', 'Location', 'NorthWest'); title ('Assign New Data to Existing Clusters'); ***** test samples = 4; dims = 3; k = 2; [cls, c, d, z] = kmeans (rand (samples,dims), k, 'start', rand (k,dims, 5), 'emptyAction', 'singleton'); assert_equal (size (cls), [samples, 1]); assert_equal (size (c), [k, dims]); assert_equal (size (d), [k, 1]); assert_equal (size (z), [samples, k]); ***** test samples = 4; dims = 3; k = 2; [cls, c, d, z] = kmeans (rand (samples,dims), [], 'start', rand (k,dims, 5), 'emptyAction', 'singleton'); assert_equal (size (cls), [samples, 1]); assert_equal (size (c), [k, dims]); assert_equal (size (d), [k, 1]); assert_equal (size (z), [samples, k]); ***** test [cls, c] = kmeans ([1 0; 2 0], 2, 'start', [8,0;0,8], 'emptyaction', 'drop'); assert_equal (cls, [1; 1]); assert_equal (c, [1.5, 0; NA, NA]); ***** test kmeans (rand (4,3), 2, 'start', rand (2,3, 5), 'replicates', 5, 'emptyAction', 'singleton'); ***** test kmeans (rand (3,4), 2, 'start', 'sample', 'emptyAction', 'singleton'); ***** test kmeans (rand (3,4), 2, 'start', 'plus', 'emptyAction', 'singleton'); ***** test kmeans (rand (3,4), 2, 'start', 'cluster', 'emptyAction', 'singleton'); ***** test kmeans (rand (3,4), 2, 'start', 'uniform', 'emptyAction', 'singleton'); ***** test kmeans (rand (4,3), 2, 'distance', 'sqeuclidean', 'emptyAction', 'singleton'); ***** test kmeans (rand (4,3), 2, 'distance', 'cityblock', 'emptyAction', 'singleton'); ***** test kmeans (rand (4,3), 2, 'distance', 'cosine', 'emptyAction', 'singleton'); ***** test kmeans (rand (4,3), 2, 'distance', 'correlation', 'emptyAction', 'singleton'); ***** test kmeans (rand (4,3), 2, 'distance', 'hamming', 'emptyAction', 'singleton'); ***** test kmeans ([1 0; 1.1 0], 2, 'start', eye (2), 'emptyaction', 'singleton'); ***** test x = [1 1; 1.2 1.1; 8 8; 8.3 8.1]; idx = kmeans (x, 2, 'Replicates', []); assert_equal (numel (idx), 4); assert_equal (numel (unique (idx)), 2); ***** test x = [1 1; 1.2 1.1; 8 8; 8.3 8.1]; idx = kmeans (x, 2, 'MaxIter', []); assert_equal (numel (idx), 4); assert_equal (numel (unique (idx)), 2); ***** test idx = kmeans ([NaN; 3; 4; NaN], 2); assert_equal (numel (idx), 4); assert_equal (isna (idx([1, 4])), [true; true]); assert_equal (isna (idx([2, 3])), [false; false]); assert_equal (numel (unique (idx([2, 3]))), 2); ***** test idx = kmeans ([1 1; NaN NaN; 8 8; 9 9], 2); assert_equal (isna (idx), [false; true; false; false]); assert_equal (idx(3), idx(4)); ***** warning ... kmeans ([1 1; 1.2 1.1; 8 8; 8.3 8.1], 2, 'OnlinePhase', 'on'); ***** warning ... kmeans ([1 1; 1.2 1.1; 8 8; 8.3 8.1], 2, 'Options', struct ()); ***** warning ... kmeans ([1 1; 2 2; 3 3; 9 9; 9.5 9.6; 20 20], 3, 'MaxIter', 1, ... 'Start', [1 1; 2 2; 3 3]); ***** error ... kmeans ('a', 1) ***** error ... kmeans (rand (2, 2, 2), 1) ***** error ... kmeans ([2i; 2; 2], 1) ***** error kmeans ([], 1) ***** error kmeans (NaN (5, 2), 3) ***** error ... kmeans (rand (5, 2), []) ***** error ... kmeans (rand (5, 2), [], 'start', 'plus') ***** error kmeans (rand (5, 2), {3}) ***** error kmeans (rand (5, 2), 't') ***** error kmeans (rand (5, 2), 1.5) ***** error kmeans (rand (5, 2), 0) ***** error kmeans (rand (5, 2), -1) ***** error ... kmeans ([NaN; 3; 4; NaN], 3) ***** error ... kmeans (rand (3, 2), 5) ***** error ... kmeans (rand (4, 3), 2, 'Distance') ***** error kmeans (rand (4, 3), 2, 'bogus', 1) ***** error ... kmeans (rand (4, 3), 2, 42) ***** error ... kmeans (rand (4, 3), 2, 'Start', rand (3, 3)) ***** error ... kmeans (rand (4, 3), 2, 'Display', 'verbose') ***** error ... kmeans ([1 0; 1.1 0], 2, 'start', eye (2), 'emptyaction', 'panic') ***** error ... kmeans (rand (4,3), 2, 'start', rand (2,3, 5), 'replicates', 1) ***** error ... kmeans (rand (4,3), 2, 'start', rand (2,2)) ***** error ... kmeans (rand (4,3), 2, 'distance', 'manhattan') ***** error ... kmeans (rand (3,4), 2, 'start', 'normal') ***** error ... kmeans (rand (4,3), 2, 'replicates', i) ***** error ... kmeans (rand (4,3), 2, 'replicates', -1) ***** error ... kmeans (rand (4,3), 2, 'replicates', [1 2]) ***** error ... kmeans (rand (4,3), 2, 'replicates', 'one') ***** error ... kmeans (rand (4,3), 2, 'MAXITER', i) ***** error ... kmeans (rand (4,3), 2, 'MaxIter', -1) ***** error ... kmeans (rand (4,3), 2, 'maxiter', [1 2]) ***** error ... kmeans (rand (4,3), 2, 'maxiter', 'one') ***** error ... kmeans ([1 0; 1.1 0], 2, 'start', eye (2), 'emptyaction', 'error') 54 tests, 54 passed, 0 known failure, 0 skipped [inst/Clustering/clusterdata.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Clustering/clusterdata.m ***** demo rng (42); r1 = randn (10, 2) * 0.25 + 1; r2 = randn (20, 2) * 0.5 - 1; X = [r1; r2]; wnl = warning ("off", 'Octave:linkage_savemem', 'local'); T = clusterdata (X, 'linkage', 'ward', 'MaxClust', 2); scatter (X(:,1), X(:,2), 36, T, 'filled'); ***** error ... clusterdata () ***** error ... clusterdata (1) ***** error clusterdata ([1 1], 'Bogus', 1) ***** error clusterdata ([1 1], 'Depth', 1) ***** test assert_equal (numel (unique (clusterdata (ones (5, 2), "MaxClust", 2))), 2); assert_equal (numel (unique (clusterdata (ones (5, 2), "MaxClust", 4))), 4); warning: linkage: option 'savememory' not implemented warning: called from linkage at line 105 column 5 clusterdata at line 93 column 3 __test__ at line 3 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 526 column 2 warning: linkage: option 'savememory' not implemented warning: called from linkage at line 105 column 5 clusterdata at line 93 column 3 __test__ at line 4 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 526 column 2 ***** test # the depth reaches the result, as it does in cluster X = [0, 0; 0.1, 0.1; 0.2, 0; 5, 5; 5.1, 5.2; 5.2, 5.0; 10, 0; ... 10.1, 0.2; 20, 20; 0.05, 0.3]; t2 = clusterdata (X, "Cutoff", 0.9, "Depth", 2); t3 = clusterdata (X, "Cutoff", 0.9, "Depth", 3); assert_equal (numel (unique (t2)), 4); assert_equal (numel (unique (t3)), 5); t = clusterdata (X, "MaxClust", 3); assert_equal (numel (unique (t)), 3); assert_equal (numel (unique (t([7, 8]))), 1); warning: linkage: option 'savememory' not implemented warning: called from linkage at line 105 column 5 clusterdata at line 93 column 3 __test__ at line 5 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 526 column 2 warning: linkage: option 'savememory' not implemented warning: called from linkage at line 105 column 5 clusterdata at line 93 column 3 __test__ at line 6 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 526 column 2 warning: linkage: option 'savememory' not implemented warning: called from linkage at line 105 column 5 clusterdata at line 93 column 3 __test__ at line 9 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 526 column 2 6 tests, 6 passed, 0 known failure, 0 skipped [inst/Clustering/ClusterCriterion.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Clustering/ClusterCriterion.m ***** test ## compact drops everything held per observation and keeps every ## result, returning an object of the same class. Verified against ## R2024a. X = [1, 1; 1.2, 1.1; 3, 3; 3.2, 3.1; 6, 6; 6.1, 6.2; 1.1, 1.3; 3.1, 3.2]; e = evalclusters (X, 'kmeans', 'CalinskiHarabasz', 'KList', 2:3); c = compact (e); assert_equal (class (c), class (e)); assert_equal (isempty (c.X), true); assert_equal (isempty (c.Missing), true); assert_equal (isempty (c.OptimalY), true); ## the results survive assert_equal (c.NumObservations, e.NumObservations); assert_equal (c.InspectedK, e.InspectedK); assert_equal (c.CriterionValues, e.CriterionValues); assert_equal (c.OptimalK, e.OptimalK); ***** test ## the object compacted from is left alone: these are value classes, ## as MATLAB's are, so compact hands back a compacted copy X = [1, 1; 1.2, 1.1; 3, 3; 3.2, 3.1; 6, 6; 6.1, 6.2; 1.1, 1.3; 3.1, 3.2]; e = evalclusters (X, 'kmeans', 'CalinskiHarabasz', 'KList', 2:3); c = compact (e); assert_equal (size (e.X), [8, 2]); ## and compacting twice is harmless assert_equal (isempty (getfield (compact (c), 'X')), true); ***** test ## a compacted object still plots, since plotting needs no observations X = [1, 1; 1.2, 1.1; 3, 3; 3.2, 3.1; 6, 6; 6.1, 6.2; 1.1, 1.3; 3.1, 3.2]; c = compact (evalclusters (X, 'kmeans', 'CalinskiHarabasz', 'KList', 2:3)); hf = figure ('visible', 'off'); unwind_protect h = plot (c); assert_equal (all (isaxes (h), 'all'), true); unwind_protect_cleanup close (hf); end_unwind_protect warning: using the gnuplot graphics toolkit is discouraged The gnuplot graphics toolkit is not actively maintained and has a number of limitations that are unlikely to be fixed. Communication with gnuplot uses a one-directional pipe and limited information is passed back to the Octave interpreter so most changes made interactively in the plot window will not be reflected in the graphics properties managed by Octave. For example, if the plot window is closed with a mouse click, Octave will not be notified and will not update its internal list of open figure windows. The qt toolkit is recommended instead. ***** error ... addK (compact (evalclusters ([1, 1; 1.2, 1.1; 3, 3; 3.2, 3.1; 6, 6; ... 6.1, 6.2; 1.1, 1.3; 3.1, 3.2], 'kmeans', 'CalinskiHarabasz', ... 'KList', 2:3)), 4) ***** error ... CalinskiHarabaszEvaluation ('1', 'kmeans', [1:6]) ***** error ... CalinskiHarabaszEvaluation ([1, 2, 1, 3, 2, 4, 3], 'k', [1:6]) ***** error ... CalinskiHarabaszEvaluation ([1, 2, 1; 3, 2, 4], 1, [1:6]) ***** error ... CalinskiHarabaszEvaluation ([1, 2, 1; 3, 2, 4], ones (2, 2, 2), [1:6]) ***** error ... ClusterCriterion ([1, 2, 1; 3, 2, 4], 'kmeans', [1:6]) 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Clustering/dbscan.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Clustering/dbscan.m ***** demo ## Cluster a set of points with two dense blobs and scattered noise. rng (42); X = [randn(30,2)*0.3 + 2; randn(30,2)*0.3 - 2; 5*(rand(6,2)-0.5)]; idx = dbscan (X, 0.6, 4); gscatter (X(:,1), X(:,2), idx); title ("dbscan: clusters (>=0) and noise (-1)"); ***** test X = [0 0; 0 1; 1 0; 1 1; 10 10; 10 11; 11 10; 5 5]; [idx, cp] = dbscan (X, 1.5, 3); assert_equal (idx, [1; 1; 1; 1; 2; 2; 2; -1]); assert_equal (cp, logical ([1; 1; 1; 1; 1; 1; 1; 0])); ***** test X = [0; 0.3; 0.6; 0.9; 2.5; 2.8; 3.1; 3.4; 1.7]; [idx, cp] = dbscan (X, 1, 4); assert_equal (idx, [1; 1; 1; 1; 2; 2; 2; 2; 1]); assert_equal (cp, logical ([1; 1; 1; 1; 1; 1; 1; 1; 0])); ***** test X = [2.5; 2.8; 3.1; 3.4; 0; 0.3; 0.6; 0.9; 1.7]; idx = dbscan (X, 1, 4); assert_equal (idx, [1; 1; 1; 1; 2; 2; 2; 2; 1]); ***** test X = [0; 1; 2]; [idx, cp] = dbscan (X, 1, 2); assert_equal (idx, [1; 1; 1]); assert_equal (cp, logical ([1; 1; 1])); ***** test X = [0; 0; 5; 5; 10]; [idx, cp] = dbscan (X, 0.5, 1); assert_equal (idx, [1; 1; 2; 2; 3]); assert_equal (cp, logical ([1; 1; 1; 1; 1])); ***** test X = [0 0; 0 1; 1 0; 1 1; 10 10; 10 11; 11 10; 5 5]; D = pdist2 (X, X); [idx, cp] = dbscan (D, 1.5, 3, "Distance", "precomputed"); assert_equal (idx, [1; 1; 1; 1; 2; 2; 2; -1]); assert_equal (cp, logical ([1; 1; 1; 1; 1; 1; 1; 0])); ***** test X = [0 0; 0 1; 1 0; 1 1; 10 10; 10 11; 11 10; 5 5]; idx = dbscan (X, 2, 3, "Distance", "cityblock"); assert_equal (idx, [1; 1; 1; 1; 2; 2; 2; -1]); ***** test X = [0; 10; 20; 30]; [idx, cp] = dbscan (X, 1, 2); assert_equal (idx, [-1; -1; -1; -1]); assert_equal (cp, logical ([0; 0; 0; 0])); ***** error dbscan (1) ***** error dbscan (1, 1) ***** error dbscan ([], 1, 1) ***** error dbscan ("a", 1, 1) ***** error dbscan (i, 1, 1) ***** error dbscan (ones (3,2), [1 2], 1) ***** error dbscan (ones (3,2), -1, 1) ***** error dbscan (ones (3,2), "a", 1) ***** error dbscan (ones (3,2), 1, 0) ***** error dbscan (ones (3,2), 1, 1.5) ***** error dbscan (ones (3,2), 1, [1 2]) ***** error ... dbscan (ones (3,2), 1, 1, "Distance", "precomputed") ***** error ... dbscan (ones (3,3), 1, 1, "Distance", "precomputed", "P", 3) 21 tests, 21 passed, 0 known failure, 0 skipped [inst/Clustering/evalclusters.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Clustering/evalclusters.m ***** demo load fisheriris; eva = evalclusters (meas, 'kmeans', 'calinskiharabasz', 'KList', [1:6]) plot (eva) ***** error evalclusters () ***** error evalclusters ([1 1;0 1]) ***** error evalclusters ([1 1;0 1], 'kmeans') ***** error ... evalclusters ('abc', 'kmeans', 'gap') ***** error evalclusters ([1 1;0 1], 'xxx', 'gap') ***** error evalclusters ([1 1;0 1], [1 2], 'gap') ***** error evalclusters ([1 1;0 1], 1.2, 'gap') ***** error evalclusters ([1 1;0 1], [1; 2], 123) ***** error evalclusters ([1 1;0 1], [1; 2], 'xxx') ***** error <'KList' can be empty*> evalclusters ([1 1;0 1], 'kmeans', 'gap') ***** error evalclusters ([1 1;0 1], [1; 2], 'gap', 1) ***** error evalclusters ([1 1;0 1], [1; 2], 'gap', 1, 1) ***** error evalclusters ([1 1;0 1], [1; 2], 'gap', 'xxx', 1) ***** error <'KList'*> evalclusters ([1 1;0 1], [1; 2], 'gap', 'KList', [-1 0]) ***** error <'KList'*> evalclusters ([1 1;0 1], [1; 2], 'gap', 'KList', [1 .5]) ***** error <'KList'*> evalclusters ([1 1;0 1], [1; 2], 'gap', 'KList', [1 1; 1 1]) ***** error evalclusters ([1 1;0 1], [1; 2], 'gap', ... 'distance', 'a') ***** error evalclusters ([1 1;0 1], [1; 2], 'daviesbouldin', ... 'distance', 'a') ***** error evalclusters ([1 1;0 1], [1; 2], 'gap', ... 'clusterpriors', 'equal') ***** error evalclusters ([1 1;0 1], [1; 2], ... 'silhouette', 'clusterpriors', 'xxx') ***** error <'clust' must be a clustering*> evalclusters ([1 1;0 1], [1; 2], 'gap') ***** test load fisheriris; eva = evalclusters (meas, 'kmeans', 'calinskiharabasz', 'KList', [1:6]); assert_equal (isa (eva, 'CalinskiHarabaszEvaluation'), true); assert_equal (eva.NumObservations, 150); assert_equal (eva.OptimalK, 3); assert_equal (eva.InspectedK, [1 2 3 4 5 6]); ***** test x = [randn(20,2); 6 + randn(20,2); [12, 0] + randn(20,2)]; k2 = [ones(30,1); 2*ones(30,1)]; k3 = [ones(20,1); 2*ones(20,1); 3*ones(20,1)]; k4 = [ones(15,1); 2*ones(15,1); 3*ones(15,1); 4*ones(15,1)]; sols = [k2, k3, k4]; for crit = {'CalinskiHarabasz', 'DaviesBouldin', 'silhouette'} eva = evalclusters (x, sols, crit{1}); assert_equal (eva.InspectedK, [2, 3, 4]); assert_equal (any (isnan (eva.CriterionValues)), false); ## an explicit KList naming the same sizes must give the same answer ref = evalclusters (x, sols, crit{1}, 'KList', [2, 3, 4]); assert_equal (eva.CriterionValues, ref.CriterionValues); assert_equal (eva.OptimalK, ref.OptimalK); endfor ***** test x = [randn(20,2); 6 + randn(20,2); [12, 0] + randn(20,2)]; k4 = [ones(15,1); 2*ones(15,1); 3*ones(15,1); 4*ones(15,1)]; k2 = [ones(30,1); 2*ones(30,1)]; fwd = evalclusters (x, [k2, k4], 'CalinskiHarabasz'); rev = evalclusters (x, [k4, k2], 'CalinskiHarabasz'); assert_equal (rev.InspectedK, [2, 4]); assert_equal (rev.CriterionValues, fwd.CriterionValues); assert_equal (rev.OptimalK, fwd.OptimalK); ***** error ... evalclusters ([randn(20,2); 6 + randn(20,2)], ... [[ones(20,1); 2*ones(20,1)], [2*ones(20,1); ones(20,1)]], ... 'CalinskiHarabasz') ***** shared X, sols randn ("seed", 11); X = [randn(20, 2); 6 + randn(20, 2); [12, 0] + randn(20, 2)]; sols = [[ones(30,1); 2*ones(30,1)], ... [ones(20,1); 2*ones(20,1); 3*ones(20,1)], ... [ones(15,1); 2*ones(15,1); 3*ones(15,1); 4*ones(15,1)]]; ***** test # given the clusterings, the object does not echo them back e = evalclusters (X, sols, "CalinskiHarabasz"); assert_equal (isempty (e.OptimalY), true); assert_equal (isempty (e.ClusteringFunction), true); assert_equal (class (e.ClusteringFunction), "double"); ***** test # asked to cluster, it reports both the solution and the function e = evalclusters (X, "kmeans", "CalinskiHarabasz", "KList", 2:4); assert_equal (size (e.OptimalY), [60, 1]); assert_equal (e.ClusteringFunction, "kmeans"); ***** test # Missing carries one flag per observation, shaped like the observations e = evalclusters (X, sols, "CalinskiHarabasz"); assert_equal (size (e.Missing), [60, 1]); assert_equal (class (e.Missing), "logical"); Xn = X; Xn(5,1) = NaN; e = evalclusters (Xn, sols, "CalinskiHarabasz"); assert_equal (find (e.Missing), 5); assert_equal (e.NumObservations, 59); ***** test # a criterion that is undefined everywhere leaves no optimal K e = evalclusters (X, ones (60, 1), "CalinskiHarabasz"); assert_equal (isnan (e.CriterionValues), true); assert_equal (isnan (e.OptimalK), true); assert_equal (isempty (e.OptimalY), true); ***** test # criterion and option names are reported as MATLAB spells them assert_equal (evalclusters (X, sols, "CalinskiHarabasz").CriterionName, ... "CalinskiHarabasz"); assert_equal (evalclusters (X, sols, "DaviesBouldin").CriterionName, ... "DaviesBouldin"); assert_equal (evalclusters (X, sols, "silhouette").CriterionName, ... "Silhouette"); e = evalclusters (X, sols, "silhouette", "Distance", "sqeuclidean"); assert_equal (e.Distance, "sqEuclidean"); e = evalclusters (X, sols, "silhouette", "Distance", "cityblock"); assert_equal (e.Distance, "cityblock"); ***** test # ClusterSilhouettes holds one mean per cluster, not one per observation e = evalclusters (X, sols, "silhouette"); assert_equal (numel (e.ClusterSilhouettes), 3); assert_equal (size (e.ClusterSilhouettes{1}), [2, 1]); assert_equal (size (e.ClusterSilhouettes{2}), [3, 1]); assert_equal (size (e.ClusterSilhouettes{3}), [4, 1]); ***** test # the silhouette criterion honours the metric it was given a = evalclusters (X, sols, "silhouette", "Distance", "sqeuclidean"); b = evalclusters (X, sols, "silhouette", "Distance", "cityblock"); c = evalclusters (X, sols, "silhouette", "Distance", "cosine"); assert_equal (isequal (a.CriterionValues, b.CriterionValues), false); assert_equal (isequal (b.CriterionValues, c.CriterionValues), false); ## each cluster mean is the mean of that cluster's silhouette values si = silhouette (X, sols(:,2), "cityblock", "DoNotPlot"); m = [mean(si(sols(:,2) == 1)); mean(si(sols(:,2) == 2)); ... mean(si(sols(:,2) == 3))]; assert_equal (b.ClusterSilhouettes{2}, m, 1e-12); 32 tests, 32 passed, 0 known failure, 0 skipped [inst/Clustering/kmedoids.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Clustering/kmedoids.m ***** demo ## Cluster three noisy blobs and mark the medoids. rng (42); X = [randn(20,2)*0.4 + 3; randn(20,2)*0.4; randn(20,2)*0.4 + [3 -3]]; [idx, C] = kmedoids (X, 3); gscatter (X(:,1), X(:,2), idx); hold on; plot (C(:,1), C(:,2), "kp", "MarkerSize", 14, "MarkerFaceColor", "y"); hold off; title ("kmedoids: three clusters with their medoids"); ***** test X = [1 1; 1.2 0.8; 0.8 1.1; 10 10; 10.2 9.8; 9.8 10.1; 1 10; 1.1 10.2; ... 0.9 9.8]; S = [1 1; 10 10; 1 10]; [idx, C, sumd, D, midx] = kmedoids (X, 3, "Start", S); assert_equal (idx, [1; 1; 1; 2; 2; 2; 3; 3; 3]); assert_equal (midx, [1; 4; 7]); assert_equal (C, [1 1; 10 10; 1 10]); assert_equal (sumd, [0.13; 0.13; 0.10], 1e-12); assert_equal (C, X(midx,:)); assert_equal (D(6,:), [160.25 0.05 77.45], 1e-12); assert_equal (size (D), [9 3]); ***** test X = [1 1; 1.2 0.8; 0.8 1.1; 10 10; 10.2 9.8; 9.8 10.1; 1 10; 1.1 10.2; ... 0.9 9.8]; [idx, C, sumd, D, midx, info] = kmedoids (X, 3); assert_equal (sort (midx), [1; 4; 7]); assert_equal (sort (sumd), [0.10; 0.13; 0.13], 1e-12); assert_equal (arrayfun (@(c) numel (unique (idx(idx == c))), 1:3), [1 1 1]); assert_equal (info.algorithm, "pam"); assert_equal (info.start, "plus"); assert_equal (info.distance, "sqeuclidean"); ***** test X = [1 1; 1.2 0.8; 0.8 1.1; 10 10; 10.2 9.8; 9.8 10.1; 1 10; 1.1 10.2; ... 0.9 9.8]; S = [1 1; 10 10; 1 10]; [idx, C, sumd, D, midx] = kmedoids (X, 3, "Start", S, "Distance", ... "euclidean"); assert_equal (midx, [1; 4; 7]); assert_equal (sumd, [sqrt(0.08)+sqrt(0.05); sqrt(0.08)+sqrt(0.05); ... 2*sqrt(0.05)], 1e-12); ***** test X = [1 1; 1.2 0.8; 0.8 1.1; 10 10; 10.2 9.8; 9.8 10.1; 1 10; 1.1 10.2; ... 0.9 9.8]; S = [1 1; 10 10; 1 10]; [idx, C, sumd, D, midx] = kmedoids (X, 3, "Start", S, "Distance", ... "cityblock"); assert_equal (midx, [1; 4; 7]); assert_equal (sumd, [0.7; 0.7; 0.6], 1e-12); assert_equal (D(1,:), [0 18 9], 1e-12); ***** test X = [1 1; 1.2 0.8; 0.8 1.1; 10 10; 10.2 9.8; 9.8 10.1; 1 10; 1.1 10.2; ... 0.9 9.8]; S = [1 1; 10 10; 1 10]; [idx, C, sumd, D, midx, info] = kmedoids (X, 3, "Start", S, "Algorithm", ... "small"); assert_equal (midx, [1; 4; 7]); assert_equal (sumd, [0.13; 0.13; 0.10], 1e-12); assert_equal (info.algorithm, "small"); ***** test X = [randn(10,2) - 5; randn(10,2) + 5]; [idx, C, sumd, D, midx] = kmedoids (X, 2, "Replicates", 3); assert_equal (numel (idx), 20); assert_equal (all (idx >= 1 & idx <= 2, 'all'), true); assert_equal (C, X(midx,:)); assert_equal (size (D), [20 2]); ***** test X = [0; 5; 9]; [idx, C, sumd, D, midx] = kmedoids (X, 3, "Start", X); assert_equal (sort (midx), [1; 2; 3]); assert_equal (sumd, [0; 0; 0], 1e-12); ***** error kmedoids (1) ***** error kmedoids ([], 2) ***** error kmedoids ("a", 2) ***** error kmedoids (ones (4,2), 0) ***** error kmedoids (ones (4,2), 1.5) ***** error ... kmedoids (ones (3,2), 4) ***** error ... kmedoids (ones (4,2), 2, "Distance") ***** error ... kmedoids (ones (4,2), 2, "foo", "bar") ***** error ... kmedoids (ones (4,2), 2, "Distance", "taxicab") ***** error ... kmedoids (ones (4,2), 2, "Algorithm", "clara") ***** error ... kmedoids (ones (4,2), 2, "Algorithm", "foo") ***** error ... kmedoids (ones (4,2), 2, "Start", "middle") ***** error ... kmedoids (ones (4,2), 2, "Start", [1 1; 2 2; 3 3]) ***** error ... kmedoids (ones (4,2), 2, "Start", [1 1 1; 2 2 2]) ***** error ... kmedoids (ones (4,2), 2, "Replicates", 0) ***** error ... kmedoids (ones (4,2), 2, "Options", 5) 23 tests, 23 passed, 0 known failure, 0 skipped [inst/Clustering/cophenet.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Clustering/cophenet.m ***** demo rng (42); X = randn (10,2); y = pdist (X); Z = linkage (y, 'average'); cophenet (Z, y) ***** error cophenet () ***** error cophenet (1) ***** error ... cophenet (ones (2,2), 1) ***** error ... cophenet ([1 2 1], 'a') ***** error ... cophenet ([1 2 1], [1 2]) 5 tests, 5 passed, 0 known failure, 0 skipped [inst/Clustering/CalinskiHarabaszEvaluation.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Clustering/CalinskiHarabaszEvaluation.m ***** test load fisheriris eva = evalclusters (meas, 'kmeans', 'calinskiharabasz', 'KList', [1:6]); assert_equal (class (eva), "CalinskiHarabaszEvaluation"); ***** function C = count_calls_calinskiharabasz (X, k) global count_calls_calinskiharabasz_n; count_calls_calinskiharabasz_n += 1; C = mod ((0 : rows (X) - 1)', k) + 1; ***** endfunction ***** test ## custom function must be called exactly once per inspected K global count_calls_calinskiharabasz_n; count_calls_calinskiharabasz_n = 0; evalclusters (rand (20, 2), @count_calls_calinskiharabasz, ... 'CalinskiHarabasz', 'KList', [2, 3]); assert_equal (count_calls_calinskiharabasz_n, 2); clear -global count_calls_calinskiharabasz_n; 2 tests, 2 passed, 0 known failure, 0 skipped [inst/Clustering/cluster.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Clustering/cluster.m ***** error cluster () ***** error cluster ([1 1], 'Cutoff', 1) ***** error cluster ([1 2 1], 'Bogus', 1) ***** error cluster ([1 2 1], 'Cutoff', -1) ***** error cluster ([1 2 1], 'Cutoff', 1, 'Bogus', 1) ***** shared X, Z X = [0, 0; 0.1, 0.1; 0.2, 0; 5, 5; 5.1, 5.2; 5.2, 5.0; 10, 0; ... 10.1, 0.2; 20, 20; 0.05, 0.3]; Z = linkage (pdist (X), "single"); ***** test # MaxClust returns exactly the number of clusters asked for for n = 1:5 assert_equal (numel (unique (cluster (Z, "MaxClust", n))), n); endfor ***** test # and the groupings are MATLAB's t = cluster (Z, "MaxClust", 3); assert_equal (numel (unique (t([1, 2, 3, 4, 5, 6, 10]))), 1); assert_equal (numel (unique (t([7, 8]))), 1); assert_equal (t(9) != t(1) && t(7) != t(1), true); ***** test # merges at equal heights still divide: a height threshold cannot ## split a tree whose every merge sits at the same height, which is what ## five identical observations produce. Zflat = linkage (pdist (ones (5, 2)), "single"); assert_equal (all (Zflat(:,3) == 0), true); for n = 1:5 assert_equal (numel (unique (cluster (Zflat, "MaxClust", n))), n); endfor ***** test # a tie at the cut does not cost a cluster either Ztie = [1, 2, 1; 3, 4, 2; 6, 7, 2; 5, 8, 3]; for n = 1:5 assert_equal (numel (unique (cluster (Ztie, "MaxClust", n))), n); endfor ***** test # a cluster is a node whose whole subtree is under the cutoff assert_equal (numel (unique (cluster (Z, "Cutoff", 0.5))), 6); assert_equal (numel (unique (cluster (Z, "Cutoff", 0.8))), 4); assert_equal (numel (unique (cluster (Z, "Cutoff", 1.2))), 1); ***** test # the depth the inconsistency is measured over reaches the result assert_equal (numel (unique (cluster (Z, "Cutoff", 0.9, "Depth", 2))), 4); assert_equal (numel (unique (cluster (Z, "Cutoff", 0.9, "Depth", 3))), 5); t = cluster (Z, "Cutoff", 0.9, "Depth", 3); assert_equal (numel (unique (t([1, 2, 3]))), 1); assert_equal (numel (unique (t([4, 5, 6]))), 1); assert_equal (t(10) != t(1), true); ***** test # the distance criterion is unchanged assert_equal (numel (unique (cluster (Z, "Cutoff", 1, ... "Criterion", "distance"))), 4); assert_equal (numel (unique (cluster (Z, "Cutoff", 30, ... "Criterion", "distance"))), 1); ***** test # a vector of cutoffs gives one column per cutoff T = cluster (Z, "MaxClust", [2, 3, 4]); assert_equal (size (T), [10, 3]); assert_equal (max (T), [2, 3, 4]); ***** test # well separated groups come out whole Xs = [randn(10, 2) * 0.05 + 1; randn(10, 2) * 0.05 - 1]; t = cluster (linkage (pdist (Xs), "ward"), "MaxClust", 2); assert_equal (numel (unique (t)), 2); assert_equal (numel (unique (t(1:10))), 1); assert_equal (numel (unique (t(11:20))), 1); assert_equal (t(1) != t(11), true); 14 tests, 14 passed, 0 known failure, 0 skipped [inst/Clustering/DaviesBouldinEvaluation.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Clustering/DaviesBouldinEvaluation.m ***** test load fisheriris eva = evalclusters (meas, 'kmeans', 'DaviesBouldin', 'KList', [1:6]); assert_equal (class (eva), "DaviesBouldinEvaluation"); ***** test ## Verify DB index for a known 2-cluster case X = [ones(5,1); 5 * ones(5,1)]; clust = [ones(5,1); 2 * ones(5,1)]; eva = evalclusters (X, clust, 'DaviesBouldin', 'KList', 2); assert_equal (eva.CriterionValues, 0, 1); ***** test ## Deterministic 1-D example; expected value is 7/30 (matches MATLAB) rand ('seed', 1); randn ('seed', 1); X = [0; 1; 4; 5; 9; 10]; eva = evalclusters (X, 'kmeans', 'DaviesBouldin', 'KList', 3); assert_equal (eva.CriterionValues, 7 / 30, 1e-12); ***** test ## Verify aggregation uses all cluster rows in Dij rand ('seed', 1); randn ('seed', 1); X = [0; 1; 4; 5; 9; 10]; eva = evalclusters (X, 'kmeans', 'DaviesBouldin', 'KList', 3); idx = eva.OptimalY; k = 3; vD = zeros (k, 1); C = zeros (k, 1); for i = 1:k Xi = X(idx == i); C(i) = mean (Xi); vD(i) = mean (abs (Xi - C(i))); endfor Dij = zeros (k); for i = 1:(k - 1) for j = (i + 1):k Dij(i, j) = (vD(i) + vD(j)) / abs (C(i) - C(j)); endfor endfor Dij = Dij + Dij'; expected = sum (max (Dij, [], 2)) / k; assert_equal (eva.CriterionValues, expected, 1e-12); ***** test ## MATLAB reference case: well-separated tight clusters rand ('seed', 1); randn ('seed', 1); X = [0; 0.1; 0.2; 5; 5.1; 5.2]; X = horzcat (X, zeros (rows (X), 1)); eva = evalclusters (X, 'kmeans', 'DaviesBouldin', 'KList', 2); assert_equal (eva.CriterionValues, 0.0267, 1e-4); ***** test ## MATLAB reference case: uneven spread clusters rand ('seed', 1); randn ('seed', 1); X = [0; 0.1; 0.2; 10; 20; 30]; X = horzcat (X, zeros (rows (X), 1)); eva = evalclusters (X, 'kmeans', 'DaviesBouldin', 'KList', 2); assert_equal (eva.CriterionValues, 0.3885, 1e-4); 6 tests, 6 passed, 0 known failure, 0 skipped [inst/Clustering/fitgmdist.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Clustering/fitgmdist.m ***** demo ## Generate a two-cluster problem rng (42); C1 = randn (100, 2) + 2; C2 = randn (100, 2) - 2; data = [C1; C2]; ## Perform clustering GMModel = fitgmdist (data, 2); ## Plot the result figure [heights, bins] = hist3 ([C1; C2]); [xx, yy] = meshgrid (bins{1}, bins{2}); bbins = [xx(:), yy(:)]; contour (reshape (GMModel.pdf (bbins), size (heights))); ***** demo rng (42); Angle_Theta = [ 30 + 10 * randn(1, 10), 60 + 10 * randn(1, 10) ]'; nbOrientations = 2; initial_orientations = [38.0; 18.0]; initial_weights = ones (1, nbOrientations) / nbOrientations; initial_Sigma = 10 * ones (1, 1, nbOrientations); start = struct ('mu', initial_orientations, 'Sigma', initial_Sigma, ... 'ComponentProportion', initial_weights); GMModel_Theta = fitgmdist (Angle_Theta, nbOrientations, 'Start', start , ... 'RegularizationValue', 0.0001) ***** test load fisheriris classes = unique (species); [~, score] = pca (meas, 'NumComponents', 2); options.MaxIter = 1000; options.TolFun = 1e-6; options.Display = 'off'; GMModel = fitgmdist (score, 2, 'Options', options); assert_equal (isa (GMModel, 'gmdistribution'), true); assert_equal (GMModel.mu, [1.3212, -0.0954; -2.6424, 0.1909], 1e-4); 1 test, 1 passed, 0 known failure, 0 skipped [inst/Clustering/optimalleaforder.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Clustering/optimalleaforder.m ***** demo rng (42); X = randn (10, 2); D = pdist (X); tree = linkage (D, 'average'); optimalleaforder (tree, D, 'Transformation', 'linear') ***** error optimalleaforder () ***** error optimalleaforder (1) ***** error optimalleaforder (ones (2, 2), 1) ***** error optimalleaforder ([1 2 3], [1 2; 3 4], 'criteria', 5) ***** error optimalleaforder ([1 2 1], [1 2 3]) ***** error optimalleaforder ([1 2 1], 1, 'xxx', 'xxx') ***** error optimalleaforder ([1 2 1], 1, 'Transformation', 'xxx') ***** shared X, D, Z X = [0, 0; 0.2, 0.1; 3, 3; 3.1, 3.4; 6, 0; 6.2, 0.3; 9, 9; 9.1, 9.2; ... 1, 5; 5, 1]; D = pdist (X); Z = linkage (D, "average"); ***** test # a custom transformation is a documented input and now reaches the fit o = optimalleaforder (Z, D, "Transformation", @(x) 1 ./ (1 + x)); assert_equal (sort (o), 1:10); assert_equal (o(end:-1:1), [1, 2, 9, 4, 3, 10, 6, 5, 7, 8]); ***** test # the named transformations are unchanged o = optimalleaforder (Z, D, "Transformation", "linear"); assert_equal (o(end:-1:1), [1, 2, 9, 4, 3, 10, 5, 6, 7, 8]); o = optimalleaforder (Z, D, "Transformation", "inverse"); assert_equal (o(end:-1:1), [1, 2, 9, 4, 3, 10, 6, 5, 7, 8]); ***** test # two leaves have a single ordering, where the tables used to run off ## the end of the similarity array for n = 2:5 o = optimalleaforder (linkage (pdist (X(1:n,:))), pdist (X(1:n,:))); assert_equal (sort (o), 1:n); endfor assert_equal (optimalleaforder (linkage (pdist (X(1:2,:))), ... pdist (X(1:2,:))), [1, 2]); ***** test # the ordering is optimal: no reordering that keeps the tree beats it o = optimalleaforder (Z, D); Dsq = squareform (D); obj = @(p) sum (Dsq(sub2ind (size (Dsq), p(1:end-1), p(2:end)))); assert_equal (obj (o), obj (o(end:-1:1)), 1e-12); assert_equal (obj (o) <= obj (1:10), true); ***** error ... optimalleaforder (Z, D, @(x) x, "linear") ***** error ... optimalleaforder ([1 2 1], 1, 'Criteria', 5) ***** error ... optimalleaforder ([1 2 1], 1, 'Transformation', 5) 14 tests, 14 passed, 0 known failure, 0 skipped [inst/Clustering/GapEvaluation.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Clustering/GapEvaluation.m ***** test load fisheriris eva = evalclusters (meas([1:50],:), 'kmeans', 'gap', 'KList', [1:3], ... 'referencedistribution', 'uniform'); assert_equal (class (eva), "GapEvaluation"); ***** function C = count_calls_gap (X, k) global count_calls_gap_n; count_calls_gap_n += 1; C = mod ((0 : rows (X) - 1)', k) + 1; ***** endfunction ***** test ## custom function must be called exactly once per inspected K per run global count_calls_gap_n; count_calls_gap_n = 0; evalclusters (rand (20, 2), @count_calls_gap, 'gap', ... 'KList', [2, 3], 'B', 2); assert_equal (count_calls_gap_n, 6); clear -global count_calls_gap_n; warning: GapEvaluation: 'PCA' distribution not implemented, defaulting to 'uniform'. warning: called from GapEvaluation at line 253 column 9 evalclusters at line 335 column 7 __test__ at line 6 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 614 column 2 2 tests, 2 passed, 0 known failure, 0 skipped [inst/Clustering/spectralcluster.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Clustering/spectralcluster.m ***** demo ## Two concentric rings are not separable by kmeans but are by spectral ## clustering. rng (42); t = linspace (0, 2*pi, 100)'; Xin = [cos(t), sin(t)] + randn (100, 2) * 0.05; Xout = 4 * [cos(t), sin(t)] + randn (100, 2) * 0.05; X = [Xin; Xout]; idx = spectralcluster (X, 2, "NumNeighbors", 10); gscatter (X(:,1), X(:,2), idx); axis equal; title ("spectralcluster: two concentric rings"); ***** test S = [0 1 1 0 0 0; 1 0 1 0 0 0; 1 1 0 0.1 0 0; 0 0 0.1 0 1 1; ... 0 0 0 1 0 1; 0 0 0 1 1 0]; [idx, V, D] = spectralcluster (S, 2, "Distance", "precomputed"); assert_equal (abs (D(1)) < 1e-9, true); assert_equal (D(2), 0.0314065796348158, 1e-12); assert_equal (size (V), [6 2]); assert_equal (idx(1) == idx(2) && idx(2) == idx(3), true); assert_equal (idx(4) == idx(5) && idx(5) == idx(6), true); assert_equal (idx(1) != idx(4), true); ***** test S = [0 1 1 0 0 0; 1 0 1 0 0 0; 1 1 0 0.1 0 0; 0 0 0.1 0 1 1; ... 0 0 0 1 0 1; 0 0 0 1 1 0]; [~, ~, D] = spectralcluster (S, 2, "Distance", "precomputed", ... "LaplacianNormalization", "symmetric"); assert_equal (D(2), 0.0314065796348156, 1e-12); ***** test S = [0 1 1 0 0 0; 1 0 1 0 0 0; 1 1 0 0.1 0 0; 0 0 0.1 0 1 1; ... 0 0 0 1 0 1; 0 0 0 1 1 0]; [~, ~, D] = spectralcluster (S, 2, "Distance", "precomputed", ... "LaplacianNormalization", "none"); assert_equal (D(2), 0.0637708504262773, 1e-12); ***** test Sc = [0 0.5 0 0; 0.5 0 0.2 0; 0 0.2 0 0.5; 0 0 0.5 0]; [idx, ~, D] = spectralcluster (Sc, 2, "Distance", "precomputed"); assert_equal (D(2), 2/7, 1e-12); assert_equal (idx(1) == idx(2), true); assert_equal (idx(3) == idx(4), true); assert_equal (idx(1) != idx(3), true); ***** test X = [0 0; 0.1 0; 0 0.1; 5 0; 5.1 0; 5 0.1]; [idx, ~, D] = spectralcluster (X, 2, "NumNeighbors", 3, "KernelScale", 2); assert_equal (D(2), 0.00358001836237202, 1e-11); assert_equal (idx(1) == idx(2) && idx(2) == idx(3), true); assert_equal (idx(4) == idx(5) && idx(5) == idx(6), true); assert_equal (idx(1) != idx(4), true); ***** test X = (1:8)'; [~, ~, Ddef] = spectralcluster (X, 2); [~, ~, D3] = spectralcluster (X, 2, "NumNeighbors", 3); assert_equal (Ddef(2), D3(2), 1e-12); assert_equal (Ddef(2), 0.113482181378817, 1e-11); ***** test X = [0 0; 0.2 0; 0 0.2; 0.2 0.2; 10 10; 10.2 10; 10 10.2; 10.2 10.2]; idx = spectralcluster (X, 2); assert_equal (numel (unique (idx(1:4))) == 1, true); assert_equal (numel (unique (idx(5:8))) == 1, true); assert_equal (idx(1) != idx(5), true); ***** test X = [0 0; 0.2 0; 0 0.2; 0.2 0.2; 10 10; 10.2 10; 10 10.2; 10.2 10.2]; idx = spectralcluster (X, 2, "ClusterMethod", "kmedoids"); assert_equal (numel (unique (idx(1:4))) == 1, true); assert_equal (numel (unique (idx(5:8))) == 1, true); ***** test X = [0 0; 0.2 0; 0 0.2; 0.2 0.2; 10 10; 10.2 10; 10 10.2; 10.2 10.2]; [idx, ~, D] = spectralcluster (X, 2, "SimilarityGraph", "epsilon", ... "Radius", 1); assert_equal (numel (idx), 8); assert_equal (idx(1) != idx(5), true); ***** test X = [0 0; 0.2 0; 0 0.2; 10 10; 10.2 10; 10 10.2; 0 10; 0.2 10; 0 10.2]; [idx, V, D] = spectralcluster (X, 3, "NumNeighbors", 2, ... "KNNGraphType", "mutual"); assert_equal (size (V), [9 3]); assert_equal (size (D), [3 1]); assert_equal (numel (unique (idx(1:3))) == 1, true); assert_equal (numel (unique (idx(4:6))) == 1, true); assert_equal (numel (unique (idx(7:9))) == 1, true); ***** error spectralcluster (1) ***** error ... spectralcluster ([], 2) ***** error ... spectralcluster (ones (4,2), 0) ***** error ... spectralcluster (ones (3,2), 4) ***** error ... spectralcluster (ones (4,2), 2, "Distance") ***** error ... spectralcluster (ones (4,2), 2, "foo", "bar") ***** error ... spectralcluster (ones (4,2), 2, "Distance", "taxicab") ***** error ... spectralcluster (ones (4,2), 2, "SimilarityGraph", "tree") ***** error ... spectralcluster (ones (4,2), 2, "KNNGraphType", "partial") ***** error ... spectralcluster (ones (4,2), 2, "ClusterMethod", "dbscan") ***** error ... spectralcluster (ones (4,2), 2, "KernelScale", 0) ***** error ... spectralcluster (ones (4,2), 2, "SimilarityGraph", "epsilon") ***** error ... spectralcluster (ones (4,2), 2, "Distance", "precomputed") ***** error ... spectralcluster ([0 0; 10 10], 2, "SimilarityGraph", "epsilon", "Radius", 1) 24 tests, 24 passed, 0 known failure, 0 skipped [inst/statset.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/statset.m ***** demo ## The default options of a given function options = statset ('nlinfit') ***** demo ## Raise the iteration limit of an existing options structure options = statset ('nlinfit'); options = statset (options, 'MaxIter', 500); [options.MaxIter, options.TolFun] ***** test options = statset (); assert_equal (isstruct (options), true); assert_equal (numel (fieldnames (options)), 20); ***** test assert_equal (fieldnames (statset ())', {'Display', 'MaxFunEvals', ... 'MaxIter', 'TolBnd', 'TolFun', 'TolTypeFun', 'TolX', 'TolTypeX', ... 'GradObj', 'Jacobian', 'DerivStep', 'FunValCheck', 'Robust', ... 'RobustWgtFun', 'WgtFun', 'Tune', 'UseParallel', 'UseSubstreams', ... 'Streams', 'OutputFcn'}); ***** test options = statset (); assert_equal (options.MaxIter, []); assert_equal (options.Streams, {}); ***** test options = statset ('nlinfit'); assert_equal (options.Display, 'off'); assert_equal (options.MaxIter, 200); assert_equal (options.TolFun, 1e-8); assert_equal (options.TolX, 1e-8); assert_equal (options.DerivStep, 6.0554544523933429e-06, 1e-20); assert_equal (options.FunValCheck, 'on'); assert_equal (options.Robust, 'off'); assert_equal (options.WgtFun, 'bisquare'); ***** test assert_equal (statset ('fitnlm'), statset ('nlinfit')); ***** test options = statset ('factoran'); assert_equal (options.MaxFunEvals, 400); assert_equal (options.MaxIter, 100); assert_equal (options.TolFun, 1e-8); assert_equal (options.TolX, 1e-8); assert_equal (options.TolBnd, []); ***** test options = statset ('fitlme'); assert_equal (options.MaxIter, 10000); assert_equal (options.TolFun, 1e-6); assert_equal (options.TolX, 1e-12); ***** test options = statset ('tsne'); assert_equal (options.MaxIter, 1000); assert_equal (options.TolFun, 1e-10); assert_equal (options.OutputFcn, ''); ***** test options = statset ('nnmf'); assert_equal (options.TolFun, 1e-4); assert_equal (options.UseParallel, false); ***** test options = statset ('mlecov'); assert_equal (options.GradObj, 'off'); assert_equal (options.DerivStep, 0.0001220703125); ***** test options = statset ('coxphfit'); assert_equal (options.MaxFunEvals, 200); assert_equal (options.MaxIter, 100); assert_equal (options.TolFun, 1e-8); assert_equal (options.TolX, 1e-8); ***** test assert_equal (statset ('fitcox'), statset ('coxphfit')); ***** test options = statset ('mvncdf'); assert_equal (options.MaxFunEvals, 1e7); ***** test options = statset ('kmedoids'); assert_equal (options.MaxIter, 100); assert_equal (options.UseSubstreams, false); ***** test assert_equal (statset ('NLINFIT'), statset ('nlinfit')); ***** test assert_equal (statset ('LinearMixedModel'), statset ('fitlme')); ***** test options = statset ('MaxIter', 100); assert_equal (options.MaxIter, 100); assert_equal (options.TolX, []); ***** test options = statset ('maxiter', 50); assert_equal (options.MaxIter, 50); ***** test options = statset ('MaxIter', 10, 'TolX', 1e-3); assert_equal (options.MaxIter, 10); assert_equal (options.TolX, 1e-3); ***** test assert_equal (statset ('MaxIter', []), statset ()); ***** test assert_equal (statset ('MaxIter', 2.5).MaxIter, 2.5); ***** test assert_equal (statset ('MaxIter', Inf).MaxIter, Inf); ***** test old = statset ('nlinfit'); new = statset (old, 'MaxIter', 999); assert_equal (new.MaxIter, 999); assert_equal (old.MaxIter, 200); assert_equal (new.TolFun, 1e-8); ***** test old = statset ('nlinfit'); new = statset (old, statset ('MaxIter', 777)); assert_equal (new.MaxIter, 777); assert_equal (new.TolFun, 1e-8); ***** test old = statset ('nlinfit'); assert_equal (statset (old, statset ()), old); ***** test assert_equal (statset ([]), statset ()); ***** test assert_equal (statset ({}), statset ()); ***** test assert_equal (statset (zeros (1, 0)), statset ()); ***** test assert_equal (statset (struct ([])), statset ()); ***** test assert_equal (statset ([], 'Display', 'iter').Display, 'iter'); ***** test old = statset ('nlinfit'); assert_equal (statset ([], old), old); ***** test old = statset ('nlinfit'); assert_equal (statset (old, []), old); ***** test options = statset (statset ('nlinfit'), [], 'MaxIter', 5); assert_equal (options.MaxIter, 5); assert_equal (options.TolFun, 1e-8); ***** test assert_equal (statset ([], [], [], 'MaxIter', 5).MaxIter, 5); ***** test options = statset (struct ('MaxIter', {}), 'TolX', 1); assert_equal (options.MaxIter, []); assert_equal (options.TolX, 1); ***** test options = statset (statset ('nlinfit'), statset ('MaxIter', 7), ... statset ('TolX', 1)); assert_equal (options.MaxIter, 7); assert_equal (options.TolX, 1); assert_equal (options.TolFun, 1e-8); ***** test options = statset (struct ('NotAnOption', 1), 'MaxIter', 5); assert_equal (options.MaxIter, 5); assert_equal (numel (fieldnames (options)), 20); ***** test assert_equal (statset (struct ('NotAnOption', 1)), statset ()); ***** test options = statset ('RobustWgtFun', 'bisquare'); assert_equal (options.RobustWgtFun, 'bisquare'); assert_equal (options.Tune, 4.685); ***** test assert_equal (statset ('RobustWgtFun', 'huber').Tune, 1.345); ***** test options = statset ('RobustWgtFun', 'bisquare', 'Tune', 3); assert_equal (options.Tune, 3); ***** test options = statset ('RobustWgtFun', 'bisquare', 'Tune', 3); assert_equal (statset (options, 'MaxIter', 50).Tune, 3); assert_equal (statset (options, struct ('MaxIter', 50)).Tune, 3); assert_equal (statset (options, 'RobustWgtFun', 'huber').Tune, 3); assert_equal (statset (options, struct ('RobustWgtFun', 'huber')).Tune, 3); assert_equal (statset (options, 'RobustWgtFun', 'huber', 'Tune', 9).Tune, 9); ***** test options = statset ('RobustWgtFun', 'andrews'); assert_equal (statset (options, 'Display', 'off').Tune, 1.339); ***** test assert_equal (statset (struct ('RobustWgtFun', 'andrews')).Tune, 1.339); ***** test options = statset ('RobustWgtFun', @(r) 1 ./ (1 + r .^ 2)); assert_equal (is_function_handle (options.RobustWgtFun), true); assert_equal (options.Tune, []); ***** test assert_equal (statset ('Display', 'ITER').Display, 'iter'); ***** test assert_equal (statset ('TolTypeFun', 'REL').TolTypeFun, 'rel'); ***** test options = statset ('UseParallel', 1); assert_equal (islogical (options.UseParallel), true); assert_equal (options.UseParallel, true); ***** error ... statset ('nosuchfun') ***** error ... statset ('MaxIter') ***** error ... statset ('TreeBagger') ***** error ... statset (1, 2) ***** error ... statset ([], 'MaxIter') ***** error ... statset ('MaxIter', 5, 'TolX') ***** error ... statset (statset (), 'MaxIter') ***** error ... statset ('NoSuchOption', 1) ***** error ... statset ('MaxIter', 'abc') ***** error ... statset ('MaxIter', -1) ***** error ... statset ('MaxIter', int32 (5)) ***** error ... statset ('TolX', -1) ***** error ... statset ('Tune', 0) ***** error ... statset ('Display', 'bogus') ***** error ... statset ('GradObj', 'maybe') ***** error ... statset ('UseParallel', 'maybe') ***** error ... statset ('DerivStep', -1) ***** error ... statset ('OutputFcn', 'notafunction') ***** error ... statset ('Streams', 5) ***** error ... statset ('RobustWgtFun', 'nosuchweight') ***** error ... statset (struct ('MaxIter', {1, 2}), 'TolX', 1) 69 tests, 69 passed, 0 known failure, 0 skipped [inst/probit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/probit.m ***** assert_equal (probit ([-1, 0, 0.5, 1, 2]), [NaN, -Inf, 0, Inf, NaN]) ***** assert_equal (probit ([0.2, 0.99]), norminv ([0.2, 0.99])) ***** error probit () ***** error probit (1, 2) 4 tests, 4 passed, 0 known failure, 0 skipped [inst/Experimental_Design/ff2n.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Experimental_Design/ff2n.m ***** error ff2n (); ***** error ff2n (2, 5); ***** error ff2n ([]) ***** error ff2n ([1, 2]) ***** error ff2n ('a') ***** error ff2n (2.5) ***** error ff2n (-3) ***** error ff2n (3+2i) ***** error ff2n (Inf) ***** error ff2n (NaN) ***** assert_equal (ff2n (0), zeros (1, 0)) ***** assert_equal (ff2n (true), [0; 1]) ***** assert_equal (ff2n (int8 (2)), [0, 0; 0, 1; 1, 0; 1, 1]) ***** test A = ff2n (3); assert_equal (A, [0, 0, 0; 0, 0, 1; 0, 1, 0; 0, 1, 1; ... 1, 0, 0; 1, 0, 1; 1, 1, 0; 1, 1, 1]); ***** test A = ff2n (2); assert_equal (A, [0, 0; 0, 1; 1, 0; 1, 1]); 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Experimental_Design/x2fx.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Experimental_Design/x2fx.m ***** test X = [1, 10; 2, 20; 3, 10; 4, 20; 5, 15; 6, 15]; D = x2fx (X,'quadratic'); assert_equal (D(1,:), [1, 1, 10, 10, 1, 100]); assert_equal (D(2,:), [1, 2, 20, 40, 4, 400]); ***** test X = [1, 10; 2, 20; 3, 10; 4, 20; 5, 15; 6, 15]; model = [0, 0; 1, 0; 0, 1; 1, 1; 2, 0]; D = x2fx (X,model); assert_equal (D(1,:), [1, 1, 10, 10, 1]); assert_equal (D(2,:), [1, 2, 20, 40, 4]); assert_equal (D(4,:), [1, 4, 20, 80, 16]); ***** test x = [1, 2, 3; 2, 3, 4; 3, 4, 5]; D = x2fx (x, 'linear'); assert_equal (D, [1, 1, 2, 3; 1, 2, 3, 4;, 1, 3, 4, 5]); D = x2fx (x, 'interaction'); assert_equal (D(1,:), [1, 1, 2, 3, 2, 3, 6]); assert_equal (D(2,:), [1, 2, 3, 4, 6, 8, 12]); assert_equal (D(3,:), [1, 3, 4, 5, 12, 15, 20]); D = x2fx (x, 'quadratic'); assert_equal (D(1,:), [1, 1, 2, 3, 2, 3, 6, 1, 4, 9]); assert_equal (D(2,:), [1, 2, 3, 4, 6, 8, 12, 4, 9, 16]); assert_equal (D(3,:), [1, 3, 4, 5, 12, 15, 20, 9, 16, 25]); D = x2fx (x, 'purequadratic'); assert_equal (D(1,:), [1, 1, 2, 3, 1, 4, 9]); assert_equal (D(2,:), [1, 2, 3, 4, 4, 9, 16]); assert_equal (D(3,:), [1, 3, 4, 5, 9, 16, 25]); ***** test x = [1, 2, 3; 2, 3, 4; 3, 4, 5]; D = x2fx (x, [0, 0, 1; 1, 0, 2]); assert_equal (D, [3, 9; 4, 32; 5, 75]); ***** test x = [1, 2, 3; 2, 3, 4; 3, 4, 5]; D = x2fx (x, 'linear', [1, 3]); assert_equal (D, [1, 1, 0, 2, 1, 0; 1, 0, 1, 3, 0, 1; 1, 0, 0, 4, 0, 0]); ***** test x = [1, 2, 3; 2, 3, 4; 3, 4, 5]; D = x2fx (x, 'quadratic', [1, 3]); assert_equal (D(1,:), [1, 1, 0, 2, 1, 0, 2, 0, 1, 0, 0, 0, 2, 0, 4]); assert_equal (D(2,:), [1, 0, 1, 3, 0, 1, 0, 3, 0, 0, 0, 1, 0, 3, 9]); assert_equal (D(3,:), [1, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16]); ***** test x = [1, 2, 3; 2, 3, 4; 3, 4, 5]; D = x2fx (x, 'cos'); assert_equal (D(1,:), [0.5403, -0.4161, -0.9900], 1e-4); assert_equal (D(2,:), [-0.4161, -0.9900, -0.6536], 1e-4); assert_equal (D(3,:), [-0.9900, -0.6536, 0.2837], 1e-4); ***** error ... x2fx ([1, 2, 3; 2, 3, 4], 'quadratic', [1, 4]) ***** error ... D = x2fx ([1, 2, 3; 2, 3, 4; 3, 4, 5], 'cosine') ***** error ... x2fx ([1, 10; 2, 20; 3, 10], [0; 1]); ***** error ... x2fx ([1, 10, 15; 2, 20, 40; 3, 10, 25], [0, 0; 1, 0; 0, 1; 1, 1; 2, 0]); 11 tests, 11 passed, 0 known failure, 0 skipped [inst/Experimental_Design/sampsizepwr.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Experimental_Design/sampsizepwr.m ***** demo ## Compute the mean closest to 100 that can be determined to be ## significantly different from 100 using a t-test with a sample size ## of 60 and a power of 0.8. mu1 = sampsizepwr ('t', [100, 10], [], 0.8, 60); disp (mu1); ***** demo ## Compute the sample sizes required to distinguish mu0 = 100 from ## mu1 = 110 by a two-sample t-test with a ratio of the larger and the ## smaller sample sizes of 1.5 and a power of 0.6. [N1,N2] = sampsizepwr ('t2', [100, 10], 110, 0.6, [], 'ratio', 1.5) ***** demo ## Compute the sample size N required to distinguish p=.26 from p=.2 ## with a binomial test. The result is approximate, so make a plot to ## see if any smaller N values also have the required power of 0.6. Napprox = sampsizepwr ('p', 0.2, 0.26, 0.6); nn = 1:250; pwr = sampsizepwr ('p', 0.2, 0.26, [], nn); Nexact = min (nn(pwr >= 0.6)); plot (nn,pwr,'b-', [Napprox Nexact],pwr([Napprox Nexact]),'ro'); grid on ***** demo ## The company must test 52 bottles to detect the difference between a mean ## volume of 100 mL and 102 mL with a power of 0.80. Generate a power curve ## to visualize how the sample size affects the power of the test. nout = sampsizepwr ('t',[100 5],102,0.80); nn = 1:100; pwrout = sampsizepwr ('t',[100 5],102,[],nn); figure; plot (nn, pwrout, 'b-', nout, 0.8, 'ro') title ('Power versus Sample Size') xlabel ('Sample Size') ylabel ('Power') ***** error ... out = sampsizepwr ([], [100, 10], [], 0.8, 60); ***** error ... out = sampsizepwr (3, [100, 10], [], 0.8, 60); ***** error ... out = sampsizepwr ({'t', 't2'}, [100, 10], [], 0.8, 60); ***** error ... out = sampsizepwr ('reg', [100, 10], [], 0.8, 60); ***** error ... out = sampsizepwr ('t', ['a', 'e'], [], 0.8, 60); ***** error ... out = sampsizepwr ('z', 100, [], 0.8, 60); ***** error ... out = sampsizepwr ('t', 100, [], 0.8, 60); ***** error ... out = sampsizepwr ('t2', 60, [], 0.8, 60); ***** error ... out = sampsizepwr ('var', [100, 10], [], 0.8, 60); ***** error ... out = sampsizepwr ('p', [100, 10], [], 0.8, 60); ***** error ... out = sampsizepwr ('r', [100, 10], [], 0.8, 60); ***** error ... [out, N1] = sampsizepwr ('z', [100, 10], [], 0.8, 60); ***** error ... [out, N1] = sampsizepwr ('t', [100, 10], [], 0.8, 60); ***** error ... [out, N1] = sampsizepwr ('var', 2, [], 0.8, 60); ***** error ... [out, N1] = sampsizepwr ('p', 0.1, [], 0.8, 60); ***** error ... [out, N1] = sampsizepwr ('r', 0.5, [], 0.8, 60); ***** error ... out = sampsizepwr ('z', [100, 0], [], 0.8, 60); ***** error ... out = sampsizepwr ('z', [100, -5], [], 0.8, 60); ***** error ... out = sampsizepwr ('t', [100, 0], [], 0.8, 60); ***** error ... out = sampsizepwr ('t', [100, -5], [], 0.8, 60); ***** error ... [out, N1] = sampsizepwr ('t2', [100, 0], [], 0.8, 60); ***** error ... [out, N1] = sampsizepwr ('t2', [100, -5], [], 0.8, 60); ***** error ... out = sampsizepwr ('var', 0, [], 0.8, 60); ***** error ... out = sampsizepwr ('var', -5, [], 0.8, 60); ***** error ... out = sampsizepwr ('p', 0, [], 0.8, 60); ***** error ... out = sampsizepwr ('p', 1.2, [], 0.8, 60); ***** error ... out = sampsizepwr ('r', -1.5, [], 0.8, 60); ***** error ... out = sampsizepwr ('r', -1, [], 0.8, 60); ***** error ... out = sampsizepwr ('r', 1.2, [], 0.8, 60); ***** error ... out = sampsizepwr ('r', 0.2, [], 0.8, 60, 'alpha', -0.2); ***** error ... out = sampsizepwr ('r', 0.2, [], 0.8, 60, 'alpha', 0); ***** error ... out = sampsizepwr ('r', 0.2, [], 0.8, 60, 'alpha', 1.5); ***** error ... out = sampsizepwr ('r', 0.2, [], 0.8, 60, 'alpha', 'zero'); ***** error ... out = sampsizepwr ('r', 0.2, [], 0.8, 60, 'tail', 1.5); ***** error ... out = sampsizepwr ('r', 0.2, [], 0.8, 60, 'tail', {'both', 'left'}); ***** error ... out = sampsizepwr ('r', 0.2, [], 0.8, 60, 'tail', 'other'); ***** error ... out = sampsizepwr ('r', 0.2, [], 0.8, 60, 'ratio', 'some'); ***** error ... out = sampsizepwr ('r', 0.2, [], 0.8, 60, 'ratio', 0.5); ***** error ... out = sampsizepwr ('r', 0.2, [], 0.8, 60, 'ratio', [2, 1.3, 0.3]); ***** error ... out = sampsizepwr ('z', [100, 5], [], [], 60); ***** error ... out = sampsizepwr ('z', [100, 5], 110, [], []); ***** error ... out = sampsizepwr ('z', [100, 5], [], 0.8, []); ***** error ... out = sampsizepwr ('z', [100, 5], 110, 0.8, 60); ***** error ... out = sampsizepwr ('z', [100, 5], 'mu', [], 60); ***** error ... out = sampsizepwr ('var', 5, -1, [], 60); ***** error ... out = sampsizepwr ('p', 0.8, 1.2, [], 60, 'tail', 'right'); ***** error ... out = sampsizepwr ('r', 0.8, 1.2, [], 60); ***** error ... out = sampsizepwr ('r', 0.8, -1.2, [], 60); ***** error ... out = sampsizepwr ('z', [100, 5], 110, 1.2); ***** error ... out = sampsizepwr ('z', [100, 5], 110, 0); ***** error ... out = sampsizepwr ('z', [100, 5], 110, 0.05, [], 'alpha', 0.1); ***** error ... out = sampsizepwr ('z', [100, 5], [], [0.8, 0.7], [60, 80, 100]); ***** error ... out = sampsizepwr ('t', [100, 5], 100, 0.8, []); ***** error ... out = sampsizepwr ('t', [100, 5], 110, 0.8, [], 'tail', 'left'); ***** error ... out = sampsizepwr ('t', [100, 5], 90, 0.8, [], 'tail', 'right'); ***** warning ... Napprox = sampsizepwr ('p', 0.2, 0.26, 0.6); ***** warning ... Napprox = sampsizepwr ('p', 0.30, 0.36, 0.8); ***** test ## sample size, against the Fisher z formula worked out here n = sampsizepwr ('r', 0.1, 0.5); C = abs (atanh (0.5) - atanh (0.1)); assert_equal (n, ceil (((norminv (0.025) + norminv (0.10)) / C) ^ 2 + 3)); ***** test ## power at a given sample size, likewise pwr = sampsizepwr ('r', 0.1, 0.5, [], 60); d = abs (atanh (0.5) - atanh (0.1)) * sqrt (60 - 3); zc = - norminv (0.025); assert_equal (pwr, normcdf (-zc + d) + normcdf (-zc - d), 1e-12); ***** test ## a null correlation of zero is the usual null and must be accepted assert_equal (sampsizepwr ('r', 0, 0.4, 0.90), 62); assert_equal (sampsizepwr ('r', 0, 0.3, 0.80), 85); ***** test ## asking for a power must yield a sample size that delivers it for pw = [0.7, 0.8, 0.9] n = sampsizepwr ('r', 0, 0.4, pw); assert_equal (sampsizepwr ('r', 0, 0.4, [], n) >= pw, true); endfor ***** test ## power must rise with the sample size and with the effect size p20 = sampsizepwr ('r', 0, 0.4, [], 20); p40 = sampsizepwr ('r', 0, 0.4, [], 40); p80 = sampsizepwr ('r', 0, 0.4, [], 80); assert_equal (p20 < p40 && p40 < p80, true); assert_equal (sampsizepwr ('r', 0, 0.2, [], 40) < p40, true); assert_equal (sampsizepwr ('r', 0, 0.6, [], 40) > p40, true); ***** test ## a correlation and its negative need the same sample size assert_equal (sampsizepwr ('r', 0, -0.4, 0.90), ... sampsizepwr ('r', 0, 0.4, 0.90)); ***** test ## the alternative correlation can be recovered from N and the power, ## to the precision of the search findP1r runs r1 = sampsizepwr ('r', 0, [], 0.80, 60); assert_equal (sampsizepwr ('r', 0, r1, [], 60), 0.80, 5e-3); ***** test mu1 = sampsizepwr ('t', [100, 10], [], 0.8, 60); assert_equal (mu1, 103.67704316, 1e-8); ***** test [N1,N2] = sampsizepwr ('t2', [100, 10], 110, 0.6, [], 'ratio', 1.5); assert_equal (N1, 9); assert_equal (N2, 14); ***** test nn = 1:250; pwr = sampsizepwr ('p', 0.2, 0.26, [], nn); pwr_out = [0, 0.0676, 0.0176, 0.0566, 0.0181, 0.0431, 0.0802, 0.0322]; assert_equal (pwr([1:8]), pwr_out, 1e-4 * ones (1,8)); pwr_out = [0.59275, 0.6073, 0.62166, 0.6358, 0.6497, 0.6087, 0.6229, 0.6369]; assert_equal (pwr([243:end]), pwr_out, 1e-4 * ones (1,8)); ***** test nout = sampsizepwr ('t', [100, 5], 102, 0.80); assert_equal (nout, 52); ***** test power = sampsizepwr ('t', [20, 5], 25, [], 5, 'Tail', 'right'); assert_equal (power, 0.5797373588621888, 1e-14); ***** test nout = sampsizepwr ('t', [20, 5], 25, 0.99, [], 'Tail', 'right'); assert_equal (nout, 18); ***** test p1out = sampsizepwr ('t', [20, 5], [], 0.95, 10, 'Tail', 'right'); assert_equal (p1out, 25.65317979360237, 5e-14); ***** test pwr = sampsizepwr ('t2', [1.4, 0.2], 1.7, [], 5, 'Ratio', 2); assert_equal (pwr, 0.716504004686586, 1e-14); ***** test n = sampsizepwr ('t2', [1.4, 0.2], 1.7, 0.9, []); assert_equal (n, 11); ***** test [n1, n2] = sampsizepwr ('t2', [1.4, 0.2], 1.7, 0.9, [], 'Ratio', 2); assert_equal ([n1, n2], [8, 16]); 74 tests, 74 passed, 0 known failure, 0 skipped [inst/Experimental_Design/fullfact.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Experimental_Design/fullfact.m ***** demo ## Full factorial design with 3 ordinal variables fullfact ([2, 3, 4]) ***** error fullfact (); ***** error ... fullfact (Inf); ***** error ... fullfact (NaN); ***** error ... fullfact (ones (2)); ***** error ... fullfact ([1, 2, NaN]); ***** error ... fullfact ([1, 2, Inf]); ***** error fullfact (2.5); ***** error fullfact (0); ***** error fullfact (-3); ***** error fullfact (3+2i); ***** error fullfact ([1, 2, -3]); ***** error fullfact ([0, 1, 2]); ***** test A = fullfact (1); assert_equal (A, 1); ***** test A = fullfact (2); assert_equal (A, [1; 2]); ***** test ***** test A = fullfact (3); assert_equal (A, [1; 2; 3]); ***** test A = fullfact ([1, 2, 4]); A_out = [1, 1, 1; 1, 2, 1; 1, 1, 2; 1, 2, 2; ... 1, 1, 3; 1, 2, 3; 1, 1, 4; 1, 2, 4]; assert_equal (A, A_out); ***** test A = fullfact ([2, 2]); assert_equal (A, [1, 1; 2, 1; 1, 2; 2, 2]); ***** test A = fullfact ([2, 2, 4]); A_out = [1, 1, 1; 2, 1, 1; 1, 2, 1; 2, 2, 1; ... 1, 1, 2; 2, 1, 2; 1, 2, 2; 2, 2, 2; ... 1, 1, 3; 2, 1, 3; 1, 2, 3; 2, 2, 3; ... 1, 1, 4; 2, 1, 4; 1, 2, 4; 2, 2, 4]; assert_equal (A, A_out); ***** test A = fullfact ([3, 2, 4]); A_out = [1, 1, 1; 2, 1, 1; 3, 1, 1; 1, 2, 1; 2, 2, 1; 3, 2, 1; ... 1, 1, 2; 2, 1, 2; 3, 1, 2; 1, 2, 2; 2, 2, 2; 3, 2, 2; ... 1, 1, 3; 2, 1, 3; 3, 1, 3; 1, 2, 3; 2, 2, 3; 3, 2, 3; ... 1, 1, 4; 2, 1, 4; 3, 1, 4; 1, 2, 4; 2, 2, 4; 3, 2, 4]; assert_equal (A, A_out); ***** test A = fullfact ([4, 2]); assert_equal (A, [1, 1; 2, 1; 3, 1; 4, 1; 1, 2; 2, 2; 3, 2; 4, 2]); 21 tests, 21 passed, 0 known failure, 0 skipped [inst/Experimental_Design/sigma_pts.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Experimental_Design/sigma_pts.m ***** demo K = [1 0.5; 0.5 1]; # covariance matrix # calculate and build associated ellipse [R,S,~] = svd (K); theta = atan2 (R(2,1), R(1,1)); v = sqrt (diag (S)); v = v .* [cos(theta) sin(theta); -sin(theta) cos(theta)]; t = linspace (0, 2*pi, 100).'; xe = v(1,1) * cos (t) + v(2,1) * sin (t); ye = v(1,2) * cos (t) + v(2,2) * sin (t); figure (1); clf; hold on # Plot ellipse and axes line ([0 0; v(:,1).'],[0 0; v(:,2).']) plot (xe,ye,'-r'); col = 'rgb'; l = [-1.8 -1 1.5]; for li = 1:3 p = sigma_pts (2, [], K, l(li)); tmp = plot (p(2:end,1), p(2:end,2), ['x' col(li)], ... p(1,1), p(1,2), ['o' col(li)]); h(li) = tmp(1); endfor hold off axis image legend (h, arrayfun (@(x) sprintf ("l:%.2g", x), l, 'unif', 0)); ***** test p = sigma_pts (5); assert_equal (mean (p), zeros (1,5), sqrt (eps)); assert_equal (cov (p), eye (5), sqrt (eps)); ***** test m = randn (1, 5); p = sigma_pts (5, m); assert_equal (mean (p), m, sqrt (eps)); assert_equal (cov (p), eye (5), sqrt (eps)); ***** test x = linspace (0,1,5); K = exp (- (x.' - x).^2/ 0.5); p = sigma_pts (5, [], K); assert_equal (mean (p), zeros (1,5), sqrt (eps)); assert_equal (cov (p), K, sqrt (eps)); ***** error sigma_pts (2,1); ***** error sigma_pts (2,[],1); ***** error sigma_pts (2,1,1); ***** error sigma_pts (2,[0.5 0.5],[-1 0; 0 0]); 7 tests, 7 passed, 0 known failure, 0 skipped [inst/Experimental_Design/parseWilkinsonFormula.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Experimental_Design/parseWilkinsonFormula.m ***** demo ## Simple Linear Regression : ## This example models a continuous response (Height) as a linear function ## of a single continuous predictor (Age). The 'equation' mode returns the ## symbolic representation, while 'model_matrix' generates the design matrix. Age = [10; 12; 14; 16; 18]; Height = [140; 148; 155; 162; 170]; t = table (Height, Age); formula = 'Height ~ Age'; disp (['Formula: ', formula]); equation = parseWilkinsonFormula (formula, 'equation') [X, y, names] = parseWilkinsonFormula (formula, 'model_matrix', t) ***** demo ## Multiple Regression : ## Here we model House Price based on two independent predictors: Area and ## number of Rooms. The '+' operator adds terms to the model without assuming ## any interaction between them. Price = [300; 350; 400; 450]; Area = [1500; 1800; 2200; 2500]; Rooms = [3; 3; 4; 5]; t = table (Price, Area, Rooms); formula = 'Price ~ Area + Rooms'; disp (['Formula: ', formula]); equation = parseWilkinsonFormula (formula, 'equation') [X, y, names] = parseWilkinsonFormula (formula, 'model_matrix', t) ***** demo ## Interaction Effects : ## We analyze Relief Score based on Drug Type and Dosage Level. ## The '*' operator expands to the main effects PLUS the interaction term. ## Categorical variables are automatically created. Relief = [5; 7; 6; 8]; Drug = {'Placebo'; 'Placebo'; 'Active'; 'Active'}; Dose = {'Low'; 'High'; 'Low'; 'High'}; t = table (Relief, Drug, Dose); formula = 'Relief ~ Drug * Dose'; disp (['Formula: ', formula]); equation = parseWilkinsonFormula (formula, 'equation') [X, y, names] = parseWilkinsonFormula (formula, 'model_matrix', t) ***** demo ## Polynomial Regression : ## Uses the power operator (^) to model non-linear relationships. Distance = [20; 45; 80; 125]; Speed = [30; 50; 70; 90]; Speed_2 = Speed .^ 2; t = table (Distance, Speed, Speed_2, 'VariableNames', {'Distance', 'Speed', 'Speed^2'}); formula = 'Distance ~ Speed^2'; disp (['Formula: ', formula]); equation = parseWilkinsonFormula (formula, 'equation') [X, y, names] = parseWilkinsonFormula (formula, 'model_matrix', t) ***** demo ## Hierarchical Design. ## Common in psychometrics. Here, 'Class' is nested within 'School'. ## The '/' operator implies School + School:Class. Score = [88; 92; 75; 80]; School = {'North'; 'North'; 'South'; 'South'}; Class = {'Rm101'; 'Rm102'; 'Rm201'; 'Rm202'}; t = table (Score, School, Class); formula = 'Score ~ School / Class'; disp (['Formula: ', formula]); equation = parseWilkinsonFormula (formula, 'equation') terms = parseWilkinsonFormula (formula, 'expand') ***** demo ## Explicit Nesting : ## The parser also supports the explicit 'B(A)' syntax, which means ## 'B is nested within A'. This is equivalent to the interaction 'A:B' ## but often used to denote random effects or specific hierarchy. formula = 'y ~ Class(School)'; disp (['Formula: ', formula]); equation = parseWilkinsonFormula (formula, 'equation') terms = parseWilkinsonFormula (formula, 'expand') ***** demo ## Excluding Terms : ## Demonstrates building a complex model and then simplifying it. ## We define a full 3-way interaction (A*B*C) but explicitly remove the ## three-way term (A:B:C) using the minus operator. formula = 'y ~ (A + B + C)^3 - A:B:C'; disp (['Formula: ', formula]); equation = parseWilkinsonFormula (formula, 'equation') terms = parseWilkinsonFormula (formula, 'expand') ***** demo ## Repeated Measures : ## This allows predicting multiple outcomes simultaneously. ## The range operator '-' selects all variables between 'T1' and 'T3' ## as the response matrix Y. T1 = [10; 11]; T2 = [12; 13]; T3 = [14; 15]; Treatment = {'Control'; 'Treated'}; t = table (T1, T2, T3, Treatment); formula = 'T1 - T3 ~ Treatment'; disp (['Formula: ', formula]); equations = parseWilkinsonFormula (formula, 'equation') [X, Y, names] = parseWilkinsonFormula (formula, 'model_matrix', t) ***** test ## Test : Identifiers with numbers and underscores tokens = parseWilkinsonFormula ('Yield ~ Var_1 + A2_B', 'tokenize'); vals = {tokens.value}; assert_equal (vals, {'Yield', '~', 'Var_1', '+', 'A2_B', 'EOF'}); ***** test ## Test : Floating point numbers tokens = parseWilkinsonFormula ('y ~ 0.5 * A', 'tokenize'); vals = {tokens.value}; assert_equal (vals, {'y', '~', '0.5', '*', 'A', 'EOF'}); ***** test ## Test : Whitespace insensitivity t1 = parseWilkinsonFormula ('A*B', 'tokenize'); t2 = parseWilkinsonFormula ('A * B', 'tokenize'); assert_equal ({t1.value}, {t2.value}); ***** test ## Test : Precedence t = parseWilkinsonFormula ('A + B * C . D', 'expand'); terms = cellfun (@(x) strjoin (sort (x), ':'), t, 'UniformOutput', false); assert_equal (sort (terms), sort ({'A', 'B', 'C:D', 'B:C:D'})); ***** test ## Test : Parentheses Override t = parseWilkinsonFormula ('(A + B) . C', 'expand'); terms = cellfun (@(x) strjoin (sort (x), ':'), t, 'UniformOutput', false); assert_equal (sort (terms), sort ({'A:C', 'B:C'})); ***** test ## Test : Crossing Operator (*) t = parseWilkinsonFormula ('A * B', 'expand'); assert_equal (length (t), 3); t3 = parseWilkinsonFormula ('A * B * C', 'expand'); assert_equal (length (t3), 7); ***** test ## Test : Nesting Operator (/) t = parseWilkinsonFormula ('Field / Plot', 'expand'); terms = cellfun (@(x) strjoin (sort (x), ':'), t, 'UniformOutput', false); assert_equal (sort (terms), sort ({'Field', 'Field:Plot'})); ***** test ## Test : Multi-level Nesting t = parseWilkinsonFormula ('Block / Plot / Subplot', 'expand'); terms = cellfun (@(x) strjoin (sort (x), ':'), t, 'UniformOutput', false); assert_equal (sort (terms), sort ({'Block', 'Block:Plot', 'Block:Plot:Subplot'})); ***** test ## Test : Interaction Operator (.) t = parseWilkinsonFormula ('A . B', 'expand'); assert_equal (length (t), 1); assert_equal (t{1}, {'A', 'B'}); ***** test ## Test : Power operator on cube. t = parseWilkinsonFormula ('(A + B + C)^3', 'expand'); terms = cellfun (@(x) strjoin (sort (x), ':'), t, 'UniformOutput', false); expected = sort ({'A', 'B', 'C', 'A:B', 'A:C', 'B:C', 'A:B:C'}); assert_equal (sort (terms), expected); ***** test ## Test : Power Operator. t = parseWilkinsonFormula ('(A + B + C)^2', 'expand'); terms = cellfun (@(x) strjoin (sort (x), ':'), t, 'UniformOutput', false); assert_equal (! ismember ('A:B:C', terms), true); assert_equal (ismember ('A:B', terms), true); ***** test ## Test : Redundancy Check t1 = parseWilkinsonFormula ('A + A', 'expand'); assert_equal (length (t1), 1); t2 = parseWilkinsonFormula ('A * A', 'expand'); assert_equal (length (t2), 1); ***** test ## Test : Deletion - Exact (-) t = parseWilkinsonFormula ('A * B - A', 'expand'); terms = cellfun (@(x) strjoin (sort (x), ':'), t, 'UniformOutput', false); assert_equal (sort (terms), sort ({'B', 'A:B'})); ***** test ## Test : Deletion - Clean (-*) t = parseWilkinsonFormula ('A * B -* A', 'expand'); terms = cellfun (@(x) strjoin (sort (x), ':'), t, 'UniformOutput', false); assert_equal (sort (terms), {'B'}); ***** test ## Test : Deletion - Marginal (-/) t = parseWilkinsonFormula ('A * B -/ A', 'expand'); terms = cellfun (@(x) strjoin (sort (x), ':'), t, 'UniformOutput', false); assert_equal (sort (terms), sort ({'A', 'B'})); ***** test ## Test : Deletion - Complex Sequence t = parseWilkinsonFormula ('A*B*C - A:B:C', 'expand'); assert_equal (length (t), 6); terms = cellfun (@(x) strjoin (sort (x), ':'), t, 'UniformOutput', false); assert_equal (! ismember ('A:B:C', terms), true); assert_equal (ismember ('A:B', terms), true); ***** test ## Test : LHS and RHS Identification s = parseWilkinsonFormula ('logY ~ A + B', 'matrix'); assert_equal (s.VariableNames{s.ResponseIdx}, 'logY'); assert_equal (any (strcmp ('A', s.VariableNames)), true); ***** test ## Test : No Response Variable s = parseWilkinsonFormula ('~ A + B', 'matrix'); assert_equal (isempty (s.ResponseIdx), true); ***** test ## Test : Intercept Handling s1 = parseWilkinsonFormula ('~ A', 'matrix'); assert_equal (any (all (s1.Terms == 0, 2)), true); s2 = parseWilkinsonFormula ('~ A - 1', 'matrix'); assert_equal (! any (all (s2.Terms == 0, 2)), true); ***** test ## Test : Numeric Interaction y = [1;2;3;4;5]; X1 = [1;2;1;2;1]; X2 = [10;10;20;20;10]; d = table (y, X1, X2); [M, ~, ~] = parseWilkinsonFormula ('y ~ X1:X2', 'model_matrix', d); assert_equal (size (M), [5, 2]); assert_equal (M(:, 2), d.X1 .* d.X2); ***** test ## Test : Categorical Expansion y = [1;1;1]; G = {'A'; 'B'; 'C'}; d = table (y, G); [M, ~, names] = parseWilkinsonFormula ('~ G', 'model_matrix', d); assert_equal (size (M, 2), 3); assert_equal (names, {'(Intercept)'; 'G_B'; 'G_C'}); ***** test ## Test : Categorical * Categorical Rank y = [1;2;3;4]; F1 = {'a';'b';'a';'b'}; F2 = {'x';'x';'y';'y'}; d = table (y, F1, F2); [M, ~, ~] = parseWilkinsonFormula ('~ F1 * F2', 'model_matrix', d); assert_equal (size (M, 2), 4); assert_equal (rank (M), 4); ***** test ## Test : Numeric * Categorical Naming ## The terms follow the data's variable order, and the omitted reference ## level of a character grouping column is the one the data shows first. y = [1;2]; N = [10; 20]; C = {'lo'; 'hi'}; d = table (y, N, C); [M, ~, names] = parseWilkinsonFormula ('~ N * C', 'model_matrix', d); assert_equal (names(:)', {'(Intercept)', 'N', 'C_hi', 'N:C_hi'}); ***** test ## Test : the variable order of the data drives the term order y = [1;2]; N = [10; 20]; C = {'lo'; 'hi'}; d = table (y, C, N); [M, ~, names] = parseWilkinsonFormula ('~ N * C', 'model_matrix', d); assert_equal (names(:)', {'(Intercept)', 'C_hi', 'N', 'C_hi:N'}); ***** test ## Test : Intercept Only Model y = [1; 2; 3]; d = table (y); [X, ~, names] = parseWilkinsonFormula ('y ~ 1', 'model_matrix', d); assert_equal (size (X, 2), 1); assert_equal (names, {'(Intercept)'}); assert_equal (all (X == 1), true); ***** test ## Test : NaNs and Missing Data y = [1; 2; 3; 4]; A = [1; 1; NaN; 1]; B = [10; 20; 30; NaN]; d = table (y, A, B); [X, y_out, ~] = parseWilkinsonFormula ('y ~ A', 'model_matrix', d); assert_equal (length (y_out), 3); assert_equal (y_out(3), 4); assert_equal (size (X, 1), 3); ***** test ## Test : Nesting with Groups t = parseWilkinsonFormula ('A / (B + C)', 'expand'); terms = cellfun (@(x) strjoin (sort (x), ':'), t, 'UniformOutput', false); expected = sort ({'A', 'A:B', 'A:C'}); assert_equal (sort (terms), expected); ## Test : Variable Name Collision Var = [1; 1]; Var_1 = [2; 2]; d = table (Var, Var_1); [~, ~, names] = parseWilkinsonFormula ('~ Var + Var_1', 'model_matrix', d); assert_equal (any (strcmp (names, 'Var')), true); assert_equal (any (strcmp (names, 'Var_1')), true); ***** test ## Test : One-argument call result = parseWilkinsonFormula ('A * B'); expected = sort ({'A', 'B', 'A:B'}); actual = cellfun (@(x) strjoin (sort (x), ':'), result, 'UniformOutput', false); assert_equal (sort (actual), expected); ***** test ## Test : Compatibility with Table Data Age = [25; 30; 35; 40; 45]; Weight = [70; 75; 80; 85; 90]; BP = [120; 122; 128; 130; 135]; T = table (Age, Weight, BP); formula = 'BP ~ Age * Weight'; [X, y, names] = parseWilkinsonFormula (formula, 'model_matrix', T); assert_equal (size (X), [5, 4]); assert_equal (y, BP); assert_equal (any (strcmp ('Age', names)), true); assert_equal (any (strcmp ('Weight', names)), true); assert_equal (names{1}, '(Intercept)'); ***** test ## Test : Multi-variable List y1 = [1; 2; 3]; y2 = [4; 5; 6]; x = [1; 0; 1]; d = table (y1, y2, x); [X, y, ~] = parseWilkinsonFormula ('y1, y2 ~ x', 'model_matrix', d); assert_equal (size (y), [3, 2]); assert_equal (y(:,1), d.y1); assert_equal (y(:,2), d.y2); ***** test ***** test ## Test : multivariable range. A = [10;20]; B = [30;40]; C = [50;60]; x = [1;2]; d = table (A, B, C, x); [X, y, ~] = parseWilkinsonFormula ('A - C ~ x', 'model_matrix', d); assert_equal (size (y), [2, 3]); assert_equal (y(:,1), d.A); assert_equal (y(:,2), d.B); assert_equal (y(:,3), d.C); ***** test ## Test : multivariable list + range. y1 = [1]; y2 = [2]; y3 = [3]; y4 = [4]; y5 = [5]; x1 = [10]; x2 = [2]; d = table (y1, y2, y3, y4, y5, x1, x2); [X, y, names] = parseWilkinsonFormula ('y1, y3 - y5 ~ x1:x2', 'model_matrix', d); expected_y = [d.y1, d.y3, d.y4, d.y5]; assert_equal (isequal (y, expected_y), true); assert_equal (size (X, 2), 2); assert_equal (any (strcmp (names, 'x1:x2')), true); ***** test ## Test : reverse range. A = [1]; B = [2]; C = [3]; x = [10]; d = table (A, B, C, x); [X, y, names] = parseWilkinsonFormula ('C - A ~ x - 1', 'model_matrix', d); assert_equal (size (y), [1, 3]); assert_equal (y(:,1), d.A); assert_equal (y(:,3), d.C); assert_equal (size (X, 2), 1); assert_equal (! any (strcmp (names, '(Intercept)')), true); ***** test ## Test : nans in multi-y. yA = {1; 2; 3; 4}; yB = [10; 20; NaN; 40]; x = [1; 1; 1; 1]; d = table (yA, yB, x); [X, y, ~] = parseWilkinsonFormula ('yA, yB ~ x', 'model_matrix', d); assert_equal (size (y), [3, 2]); assert_equal (y(3, 1), 4); assert_equal (y(3, 2), 40); assert_equal (size (X, 1), 3); ***** test ## Test : basic. eq = parseWilkinsonFormula ('y ~ x1 + x2 - 9', 'equation'); expected = string ('y = c1 + c2*x1 + c3*x2'); assert_equal (isequal (eq, expected), true); ***** test ## Test : explicit intercept. eq = parseWilkinsonFormula ('y ~ x1 + x2', 'equation'); expected = string ('y = c1 + c2*x1 + c3*x2'); assert_equal (isequal (eq, expected), true); ***** test ## Test : interaction. eq = parseWilkinsonFormula ('y ~ x1:x2:x3:x4', 'equation'); expected = string ('y = c1 + c2*x1*x2*x3*x4'); assert_equal (isequal (eq, expected), true); ***** test ## Test : crossing/factorial. eq = parseWilkinsonFormula ('y ~ A * B', 'equation'); expected = string ('y = c1 + c2*A + c3*B + c4*A*B'); assert_equal (isequal (eq, expected), true); ***** test ## Test : polynomials. eq = parseWilkinsonFormula ('y ~ x^4 - x^2', 'equation'); expected = string ('y = c1 + c2*x^3 + c3*x^4'); assert_equal (isequal (eq, expected), true); ***** test ## Test : repeated measures eq = parseWilkinsonFormula ('y1-y3 ~ x', 'equation'); expected = string (['y1 = c1 + c2*x'; ... 'y2 = c3 + c4*x'; ... 'y3 = c5 + c6*x']); assert_equal (isequal (eq, expected), true); ***** test ## Test : nesting syntax. eq = parseWilkinsonFormula ('y ~ x2(x1)', 'equation'); expected = string ('y = c1 + c2*x2(x1)'); assert_equal (isequal (eq, expected), true); ***** test ## Test : nesting with interaction. eq = parseWilkinsonFormula ('y ~ x3:x2(x1)', 'equation'); expected = string ('y = c1 + c2*x2(x1)*x3'); assert_equal (isequal (eq, expected), true); ***** test ## Test : multiple nesting. eq = parseWilkinsonFormula ('y ~ Var(A, B)', 'equation'); expected = string ('y = c1 + c2*Var(A,B)'); assert_equal (isequal (eq, expected), true); ***** test ## Test : nested factors eq = parseWilkinsonFormula ('y ~ x2(x1) + x3(x4)', 'equation'); expected = string ('y = c1 + c2*x2(x1) + c3*x3(x4)'); assert_equal (isequal (eq, expected), true); ***** test ## Test : polynomial and nesting. eq = parseWilkinsonFormula ('y ~ x^2 + Effect(Group)', 'equation'); expected = string ('y = c1 + c2*x + c3*x^2 + c4*Effect(Group)'); assert_equal (isequal (eq, expected), true); ***** test ## Test : symbolic resolution of LHS list eq = parseWilkinsonFormula ('A, B ~ x', 'equation'); expected = string (['A = c1 + c2*x'; 'B = c3 + c4*x']); assert_equal (isequal (eq, expected), true); ***** test ## Test : intercept only. eq = parseWilkinsonFormula ('y ~ 1', 'equation'); expected = string ('y = c1'); assert_equal (isequal (eq, expected), true); ***** test ## Test : empty model. eq = parseWilkinsonFormula ('y ~ A - A', 'equation'); expected = string ('y = c1'); assert_equal (isequal (eq, expected), true); ***** test ## Test : term row sorting. eq = parseWilkinsonFormula ('Y ~ x1 * x2 * x3', 'matrix'); expected_terms = [0, 0, 0, 0; 0, 1, 0, 0; 0, 0, 1, 0; 0, 0, 0, 1; 0, 1, 1, 0; 0, 1, 0, 1; 0, 0, 1, 1; 0, 1, 1, 1]; assert_equal (eq.VariableNames, {'Y', 'x1', 'x2', 'x3'}); assert_equal (eq.Terms, expected_terms); ***** test ## Test : polynomial term Weight^2 resolves from base column not as table variable name Weight = [2000; 2500; 3000; 3500; 4000]; MPG = [30; 28; 25; 22; 18]; d = table (Weight, MPG); [X, yout, names] = parseWilkinsonFormula ('MPG ~ Weight^2', 'model_matrix', d); assert_equal (size (X), [5, 3]); assert_equal (names{1}, '(Intercept)'); assert_equal (any (strcmp (names, 'Weight')), true); assert_equal (any (strcmp (names, 'Weight^2')), true); w2i = find (strcmp (names, 'Weight^2')); assert_equal (X(:, w2i), Weight .^ 2, 1e-10); assert_equal (yout, MPG); ***** test ## Test : squared term sorts after a categorical term Weight = [2000;2500;3000;3500;4000;4500;2200;2700;3200;3700;4200;4700]; MPG = [30;28;25;22;18;16;29;26;23;20;17;15]; Year = {'70';'70';'70';'70';'76';'76';'76';'76';'82';'82';'82';'82'}; d = table (MPG, Weight, Year); [~, ~, n1] = parseWilkinsonFormula ('MPG ~ Year + Weight^2', 'model_matrix', d); [~, ~, n2] = parseWilkinsonFormula ('MPG ~ Weight^2 + Year', 'model_matrix', d); assert_equal (n1, {'(Intercept)'; 'Weight'; 'Year_76'; 'Year_82'; 'Weight^2'}); assert_equal (n2, n1); ***** error parseWilkinsonFormula () ***** error parseWilkinsonFormula ('y ~ x', 'invalid_mode') ***** error parseWilkinsonFormula ('', 'parse') ***** error parseWilkinsonFormula ('A +', 'parse') ***** error parseWilkinsonFormula ('A *', 'parse') ***** error parseWilkinsonFormula ('A .', 'parse') ***** error parseWilkinsonFormula ('A /', 'parse') ***** error parseWilkinsonFormula ('(A+B)^C', 'expand') ***** error parseWilkinsonFormula ('(A + B', 'parse') ***** error parseWilkinsonFormula ('A + B)', 'parse') ***** error parseWilkinsonFormula ('( )', 'parse') ***** error parseWilkinsonFormula ('A + * B', 'parse') ***** error parseWilkinsonFormula ('y ~ x ~ z', 'parse') ***** error <'model_matrix' mode requires a Data Table> parseWilkinsonFormula ('~ A', 'model_matrix') ***** error d=table ([1], 'VariableNames', {'x'}); parseWilkinsonFormula ('~ Z', 'model_matrix', d) ***** error d=table ([1], [1], 'VariableNames', {'x', 'y'}); parseWilkinsonFormula ('Z ~ x', 'model_matrix', d) ***** error d=table ([1], [1], 'VariableNames', {'x', 'y'}); parseWilkinsonFormula ('A - y ~ x', 'model_matrix', d) ***** error d=table ([1], [1], 'VariableNames', {'x', 'y'}); parseWilkinsonFormula ('y - B ~ x', 'model_matrix', d) ***** error d=table ([1], 'VariableNames', {'y'}); parseWilkinsonFormula ('y - y - y ~ x', 'model_matrix', d) ***** error S={'a';'b'}; x=[1;2]; d=table (S, x); parseWilkinsonFormula ('S ~ x', 'model_matrix', d) ***** error parseWilkinsonFormula ('y ~ x', 'model_matrix', [1,2,3]) ***** error parseWilkinsonFormula ('y1-yA ~ x', 'equation') ***** error parseWilkinsonFormula ('yA-y1 ~ x', 'equation') ***** error parseWilkinsonFormula ('A-B ~ x', 'equation') ***** error parseWilkinsonFormula ('y1- ~ x', 'equation') ***** error parseWilkinsonFormula () ***** test # random intercept: basic decomposition S = parseWilkinsonFormula ('y ~ x + z + (1|g)', 'mixed'); assert_equal (S.HasRandom, true); assert_equal (S.FixedIntercept, true); assert_equal (numel (S.FixedTerms), 2); assert_equal (numel (S.Random), 1); assert_equal (S.Random(1).Intercept, true); assert_equal (isempty (S.Random(1).Terms), true); assert_equal (S.Random(1).GroupVars, {'g'}); assert_equal (S.Random(1).Group, 'g'); assert_equal (S.Response, 'y'); ***** test # (x|g) carries an implicit intercept, like the fixed-effects rule S = parseWilkinsonFormula ('y ~ x + (x|g)', 'mixed'); assert_equal (S.Random(1).Intercept, true); assert_equal (numel (S.Random(1).Terms), 1); assert_equal (S.Random(1).Terms{1}, {'x'}); ***** test # explicit (1 + x|g) matches the implicit form S = parseWilkinsonFormula ('y ~ x + (1 + x|g)', 'mixed'); assert_equal (S.Random(1).Intercept, true); assert_equal (S.Random(1).Terms, {{'x'}}); ***** test # all four intercept-suppression spellings agree: slope only, no int for f = {'(x-1|g)', '(-1 + x|g)', '(0 + x|g)', '(x + 0|g)'} S = parseWilkinsonFormula (['y ~ x + ' f{1}], 'mixed'); assert_equal (! S.Random(1).Intercept, true); assert_equal (S.Random(1).Terms, {{'x'}}); endfor ***** test # two random blocks on the same grouping factor S = parseWilkinsonFormula ('y ~ x + (1|g) + (x-1|g)', 'mixed'); assert_equal (numel (S.Random), 2); assert_equal (S.Random(1).Intercept && isempty (S.Random(1).Terms), true); assert_equal (! S.Random(2).Intercept, true); assert_equal (S.Random(2).Terms, {{'x'}}); assert_equal (S.Random(1).GroupVars, {'g'}); assert_equal (S.Random(2).GroupVars, {'g'}); ***** test # crossed grouping factors S = parseWilkinsonFormula ('y ~ x + (1|g) + (1|g2)', 'mixed'); assert_equal (numel (S.Random), 2); assert_equal (S.Random(1).GroupVars, {'g'}); assert_equal (S.Random(2).GroupVars, {'g2'}); ***** test # interaction (nested) grouping g:g2 S = parseWilkinsonFormula ('y ~ x + (1|g:g2)', 'mixed'); assert_equal (S.Random(1).GroupVars, {'g', 'g2'}); assert_equal (S.Random(1).Group, 'g:g2'); ***** test # triple interaction grouping S = parseWilkinsonFormula ('y ~ (1|a:b:c)', 'mixed'); assert_equal (S.Random(1).GroupVars, {'a', 'b', 'c'}); ***** test # multi-term random slopes (1 + x + z|g) S = parseWilkinsonFormula ('y ~ x + (1 + x + z|g)', 'mixed'); assert_equal (S.Random(1).Intercept, true); assert_equal (numel (S.Random(1).Terms), 2); ***** test # interaction in the random design (1 + x:z|g) S = parseWilkinsonFormula ('y ~ x + (1 + x:z|g)', 'mixed'); assert_equal (numel (S.Random(1).Terms), 1); assert_equal (sort (S.Random(1).Terms{1}), {'x', 'z'}); ***** test # crossing '*' expands in the random design to x + z + x:z S = parseWilkinsonFormula ('y ~ x + (x*z|g)', 'mixed'); assert_equal (S.Random(1).Intercept, true); assert_equal (numel (S.Random(1).Terms), 3); ***** test # intercept-only fixed part: y ~ (1|g) S = parseWilkinsonFormula ('y ~ (1|g)', 'mixed'); assert_equal (S.FixedIntercept, true); assert_equal (isempty (S.FixedTerms), true); assert_equal (numel (S.Random), 1); ***** test # suppressed fixed intercept coexists with a random term S = parseWilkinsonFormula ('y ~ x - 1 + (1|g)', 'mixed'); assert_equal (! S.FixedIntercept, true); assert_equal (numel (S.FixedTerms), 1); ***** test # fixed interaction via '*' expands independently of the random part S = parseWilkinsonFormula ('y ~ x*z + (1|g)', 'mixed'); assert_equal (numel (S.FixedTerms), 3); assert_equal (numel (S.Random), 1); ***** test # precedence parentheses in the fixed part are NOT random terms S = parseWilkinsonFormula ('y ~ (x + z) + (1|g)', 'mixed'); assert_equal (numel (S.FixedTerms), 2); assert_equal (numel (S.Random), 1); ***** test # nesting in the fixed part coexists with a random term S = parseWilkinsonFormula ('y ~ a/b + (1|g)', 'mixed'); assert_equal (S.FixedIntercept, true); assert_equal (numel (S.Random), 1); ***** test # 'mixed' mode degrades gracefully on a fixed-only formula S = parseWilkinsonFormula ('y ~ x + z', 'mixed'); assert_equal (! S.HasRandom, true); assert_equal (isempty (S.Random), true); assert_equal (numel (S.FixedTerms), 2); ***** test # FixedFormula reconstructs the fixed-only formula string S = parseWilkinsonFormula ('y ~ x + x2 + (1 + x|g)', 'mixed'); assert_equal (strtrim (S.FixedFormula), 'y ~ x + x2'); S2 = parseWilkinsonFormula ('y ~ (1|g)', 'mixed'); assert_equal (strtrim (S2.FixedFormula), 'y ~ 1'); ***** test # one-sided (no response) formula S = parseWilkinsonFormula ('~ x + (1|g)', 'mixed'); assert_equal (S.Response, ''); assert_equal (numel (S.Random), 1); ***** test # random design widths q reproduce the MATLAB-verified reference forms chk = { 'y ~ x + x2 + (1|g)', [1]; ... 'y ~ x + x2 + (1 + x|g)', [2]; ... 'y ~ x + x2 + (1|g) + (x-1|g)', [1 1]; ... 'y ~ x + x2 + (x-1|g)', [1]; ... 'y ~ x + x2 + (-1 + x|g)', [1]; ... 'y ~ x + x2 + (1|g) + (1|g2)', [1 1]; ... 'y ~ x + x2 + (1|g:g2)', [1]; ... 'y ~ x + x2 + (1 + x + x2|g)', [3] }; for k = 1:rows (chk) S = parseWilkinsonFormula (chk{k,1}, 'mixed'); q = arrayfun (@(r) r.Intercept + numel (r.Terms), S.Random); assert_equal (q, chk{k,2}); endfor ***** error parseWilkinsonFormula ('y ~ x + (1|g)', 'expand') ***** error parseWilkinsonFormula ('y ~ (1|g)') ***** error parseWilkinsonFormula ('y ~ x + (1|g)', 'model_matrix', table ()) ***** error parseWilkinsonFormula ('y ~ x + (1|g', 'mixed') ***** error parseWilkinsonFormula ('y ~ (1|)', 'mixed') ***** error parseWilkinsonFormula ('y ~ (|g)', 'mixed') ***** test # the variables are reported alphabetically unless asked otherwise r = parseWilkinsonFormula ('y ~ b + a', 'matrix'); assert_equal (r.VariableNames, {'a', 'b', 'y'}); assert_equal (r.ResponseIdx, 3); ***** test # 'stable' reports them in the order the formula wrote them r = parseWilkinsonFormula ('y ~ b + a', 'matrix', 'stable'); assert_equal (r.VariableNames, {'y', 'b', 'a'}); assert_equal (r.ResponseIdx, 1); ***** test a = parseWilkinsonFormula ('y ~ b + a', 'matrix'); b = parseWilkinsonFormula ('y ~ b + a', 'matrix', 'stable'); an = arrayfun (@(r) a.VariableNames{find(a.Terms(r,:), 1)}, ... 2:rows (a.Terms), 'UniformOutput', false); bn = arrayfun (@(r) b.VariableNames{find(b.Terms(r,:), 1)}, ... 2:rows (b.Terms), 'UniformOutput', false); assert_equal (an, {'a', 'b'}); assert_equal (bn, {'b', 'a'}); assert_equal (sum (a.Terms(:)), sum (b.Terms(:))); ***** test # 'sorted' may be named, and is what the default does a = parseWilkinsonFormula ('y ~ b + a', 'matrix'); b = parseWilkinsonFormula ('y ~ b + a', 'matrix', 'sorted'); assert_equal (a.VariableNames, b.VariableNames); assert_equal (a.Terms, b.Terms); ***** test # the order is taken whatever the mode, the default one included r = parseWilkinsonFormula ('y ~ b + a', 'stable'); assert_equal (isfield (r, 'response'), true); assert_equal (cellstr (r.response), {'y'}); ***** test # it comes last, after the data a mode of its own takes b = [1; 2; 3; 4]; a = [4; 3; 2; 1]; y = [1; 0; 1; 0]; T = table (b, a, y); [X1, y1, n1] = parseWilkinsonFormula ('y ~ a + b', 'model_matrix', T); [X2, y2, n2] = parseWilkinsonFormula ('y ~ a + b', 'model_matrix', T, ... {}, 'stable'); assert_equal (y1, y2); assert_equal (size (X1), size (X2)); assert_equal (numel (n1), numel (n2)); ***** test # a formula whose names are already in order reads the same either way a = parseWilkinsonFormula ('y ~ a + b', 'matrix', 'stable'); assert_equal (a.VariableNames, {'y', 'a', 'b'}); ***** error ... parseWilkinsonFormula ('y ~ a', 'matrix', 1, 2, 3, 'stable') ***** error ... parseWilkinsonFormula ('y ~ a', 'model_matrix', 'stable') 113 tests, 113 passed, 0 known failure, 0 skipped [inst/Distribution_Wrappers/random.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Wrappers/random.m ***** assert_equal (size (random ('Beta', 5, 2, 2, 10)), size (betarnd (5, 2, 2, 10))) ***** assert_equal (size (random ('beta', 5, 2, 2, 10)), size (betarnd (5, 2, 2, 10))) ***** assert_equal (size (random ('Binomial', 5, 2, [10, 20])), size (binornd (5, 2, 10, 20))) ***** assert_equal (size (random ('bino', 5, 2, [10, 20])), size (binornd (5, 2, 10, 20))) ***** assert_equal (size (random ('Birnbaum-Saunders', 5, 2, [10, 20])), size (bisarnd (5, 2, 10, 20))) ***** assert_equal (size (random ('bisa', 5, 2, [10, 20])), size (bisarnd (5, 2, 10, 20))) ***** assert_equal (size (random ('Burr', 5, 2, 2, [10, 20])), size (burrrnd (5, 2, 2, 10, 20))) ***** assert_equal (size (random ('burr', 5, 2, 2, [10, 20])), size (burrrnd (5, 2, 2, 10, 20))) ***** assert_equal (size (random ('Cauchy', 5, 2, [10, 20])), size (cauchyrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('cauchy', 5, 2, [10, 20])), size (cauchyrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('Chi-squared', 5, [10, 20])), size (chi2rnd (5, 10, 20))) ***** assert_equal (size (random ('chi2', 5, [10, 20])), size (chi2rnd (5, 10, 20))) ***** assert_equal (size (random ('Extreme Value', 5, 2, [10, 20])), size (evrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('ev', 5, 2, [10, 20])), size (evrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('Exponential', 5, [10, 20])), size (exprnd (5, 10, 20))) ***** assert_equal (size (random ('exp', 5, [10, 20])), size (exprnd (5, 10, 20))) ***** assert_equal (size (random ('F-Distribution', 5, 2, [10, 20])), size (frnd (5, 2, 10, 20))) ***** assert_equal (size (random ('f', 5, 2, [10, 20])), size (frnd (5, 2, 10, 20))) ***** assert_equal (size (random ('Gamma', 5, 2, [10, 20])), size (gamrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('gam', 5, 2, [10, 20])), size (gamrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('Geometric', 5, [10, 20])), size (geornd (5, 10, 20))) ***** assert_equal (size (random ('geo', 5, [10, 20])), size (geornd (5, 10, 20))) ***** assert_equal (size (random ('Generalized Extreme Value', 5, 2, 2, [10, 20])), size (gevrnd (5, 2, 2, 10, 20))) ***** assert_equal (size (random ('gev', 5, 2, 2, [10, 20])), size (gevrnd (5, 2, 2, 10, 20))) ***** assert_equal (size (random ('Generalized Pareto', 5, 2, 2, [10, 20])), size (gprnd (5, 2, 2, 10, 20))) ***** assert_equal (size (random ('gp', 5, 2, 2, [10, 20])), size (gprnd (5, 2, 2, 10, 20))) ***** assert_equal (size (random ('Gumbel', 5, 2, [10, 20])), size (gumbelrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('gumbel', 5, 2, [10, 20])), size (gumbelrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('Half-normal', 5, 2, [10, 20])), size (hnrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('hn', 5, 2, [10, 20])), size (hnrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('Hypergeometric', 5, 2, 2, [10, 20])), size (hygernd (5, 2, 2, 10, 20))) ***** assert_equal (size (random ('hyge', 5, 2, 2, [10, 20])), size (hygernd (5, 2, 2, 10, 20))) ***** assert_equal (size (random ('Inverse Gaussian', 5, 2, [10, 20])), size (invgrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('invg', 5, 2, [10, 20])), size (invgrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('Laplace', 5, 2, [10, 20])), size (laplacernd (5, 2, 10, 20))) ***** assert_equal (size (random ('laplace', 5, 2, [10, 20])), size (laplacernd (5, 2, 10, 20))) ***** assert_equal (size (random ('Logistic', 5, 2, [10, 20])), size (logirnd (5, 2, 10, 20))) ***** assert_equal (size (random ('logi', 5, 2, [10, 20])), size (logirnd (5, 2, 10, 20))) ***** assert_equal (size (random ('Log-Logistic', 5, 2, [10, 20])), size (loglrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('logl', 5, 2, [10, 20])), size (loglrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('Lognormal', 5, 2, [10, 20])), size (lognrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('logn', 5, 2, [10, 20])), size (lognrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('Nakagami', 5, 2, [10, 20])), size (nakarnd (5, 2, 10, 20))) ***** assert_equal (size (random ('naka', 5, 2, [10, 20])), size (nakarnd (5, 2, 10, 20))) ***** assert_equal (size (random ('Negative Binomial', 5, 2, [10, 20])), size (nbinrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('nbin', 5, 2, [10, 20])), size (nbinrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('Noncentral F-Distribution', 5, 2, 2, [10, 20])), size (ncfrnd (5, 2, 2, 10, 20))) ***** assert_equal (size (random ('ncf', 5, 2, 2, [10, 20])), size (ncfrnd (5, 2, 2, 10, 20))) ***** assert_equal (size (random ('Noncentral Student T', 5, 2, [10, 20])), size (nctrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('nct', 5, 2, [10, 20])), size (nctrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('Noncentral Chi-Squared', 5, 2, [10, 20])), size (ncx2rnd (5, 2, 10, 20))) ***** assert_equal (size (random ('ncx2', 5, 2, [10, 20])), size (ncx2rnd (5, 2, 10, 20))) ***** assert_equal (size (random ('Normal', 5, 2, [10, 20])), size (normrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('norm', 5, 2, [10, 20])), size (normrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('Poisson', 5, [10, 20])), size (poissrnd (5, 10, 20))) ***** assert_equal (size (random ('poiss', 5, [10, 20])), size (poissrnd (5, 10, 20))) ***** assert_equal (size (random ('Rayleigh', 5, [10, 20])), size (raylrnd (5, 10, 20))) ***** assert_equal (size (random ('rayl', 5, [10, 20])), size (raylrnd (5, 10, 20))) ***** assert_equal (size (random ('Rician', 5, 1, [10, 20])), size (ricernd (5, 1, 10, 20))) ***** assert_equal (size (random ('rice', 5, 1, [10, 20])), size (ricernd (5, 1, 10, 20))) ***** assert_equal (size (random ('Student T', 5, [10, 20])), size (trnd (5, 10, 20))) ***** assert_equal (size (random ('t', 5, [10, 20])), size (trnd (5, 10, 20))) ***** assert_equal (size (random ('location-scale T', 5, 1, 2, [10, 20])), size (tlsrnd (5, 1, 2, 10, 20))) ***** assert_equal (size (random ('tls', 5, 1, 2, [10, 20])), size (tlsrnd (5, 1, 2, 10, 20))) ***** assert_equal (size (random ('Triangular', 5, 2, 2, [10, 20])), size (trirnd (5, 2, 2, 10, 20))) ***** assert_equal (size (random ('tri', 5, 2, 2, [10, 20])), size (trirnd (5, 2, 2, 10, 20))) ***** assert_equal (size (random ('Discrete Uniform', 5, [10, 20])), size (unidrnd (5, 10, 20))) ***** assert_equal (size (random ('unid', 5, [10, 20])), size (unidrnd (5, 10, 20))) ***** assert_equal (size (random ('Uniform', 5, 2, [10, 20])), size (unifrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('unif', 5, 2, [10, 20])), size (unifrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('Von Mises', 5, 2, [10, 20])), size (vmrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('vm', 5, 2, [10, 20])), size (vmrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('Weibull', 5, 2, [10, 20])), size (wblrnd (5, 2, 10, 20))) ***** assert_equal (size (random ('wbl', 5, 2, [10, 20])), size (wblrnd (5, 2, 10, 20))) ***** error random (1) ***** error random ({'beta'}) ***** error ... random ('Beta', 'a', 2) ***** error ... random ('Beta', 5, '') ***** error ... random ('Beta', 5, {2}) ***** error ... random ('Beta', 'a', 2, 2, 10) ***** error ... random ('Beta', 5, '', 2, 10) ***** error ... random ('Beta', 5, {2}, 2, 10) ***** error ... random ('Beta', 5, '', 2, 10) ***** error random ('chi2') ***** error random ('Beta', 5) ***** error random ('Burr', 5) ***** error random ('Burr', 5, 2) 87 tests, 87 passed, 0 known failure, 0 skipped [inst/Distribution_Wrappers/mle.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Wrappers/mle.m ***** demo ## Fit a custom (normal) distribution by maximum likelihood and return the ## asymptotic 95% confidence intervals of the estimates. x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; pdf = @(x, mu, sigma) normpdf (x, mu, sigma); [phat, pci] = mle (x, 'pdf', pdf, 'start', [mean(x), std(x)]) ***** test x = [1 0 1 0 1 1 0 1]; assert_equal (mle (x, 'distribution', 'bernoulli'), mean (x), 1e-12); ***** test x = [1 0 1 0 1 1 0 1]; [phat, pci] = mle (x, 'distribution', 'bernoulli'); [bp, bci] = binofit (sum (x), numel (x), 0.05); assert_equal (phat, bp); assert_equal (pci, bci); ***** test ## a frequency vector expands the sample, and a zero frequency drops it assert_equal (mle ([1, 0], 'distribution', 'bernoulli', ... 'frequency', [3, 5]), 3/8, 1e-12); assert_equal (mle ([1, 0], 'distribution', 'bernoulli', ... 'frequency', [2, 0]), 1, 1e-12); ***** test ## a column vector must work as well as a row assert_equal (mle ([1;0;1;1], 'distribution', 'bernoulli'), 0.75, 1e-12); ***** test ## the uniform MLE is the sample range u = [0.2, 0.5, 0.7, 0.9, 0.35]; assert_equal (mle (u, 'distribution', 'unif'), [min(u), max(u)]); assert_equal (mle (u, 'distribution', 'uniform'), [min(u), max(u)]); assert_equal (mle (u, 'distribution', 'continuous uniform'), ... [min(u), max(u)]); ***** test u = [0.2, 0.5, 0.7, 0.9, 0.35]; [phat, pci] = mle (u, 'distribution', 'uniform'); [ahat, bhat, aci, bci] = unifit (u, 0.05); assert_equal (phat, [ahat, bhat]); assert_equal (pci, [aci, bci]); ***** test x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]'; phat = mle (x, 'distribution', 'normal'); assert_equal (phat(1), mean (x), 1e-12); assert_equal (phat(2), std (x, 1), 1e-12); assert_equal (isequal (abs (phat(2) - std (x, 0)) < 1e-12, true), false); ***** test ## the named path and the equivalent custom pdf must agree x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]'; a = mle (x, 'distribution', 'normal'); b = mle (x, 'pdf', @(v, m, s) normpdf (v, m, s), 'start', [3, 1]); assert_equal (a, b, 1e-4); ***** test ## lognfit is a normal fit on the logs, so it carried the same bias x = [1.2, 2.4, 0.9, 3.2, 1.1, 2.8, 1.3, 4.7, 2.2, 0.6, 3.0, 1.5]'; phat = mle (x, 'distribution', 'lognormal'); assert_equal (phat(2), std (log (x), 1), 1e-12); ***** test ## a frequency vector scales the effective sample size x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8]'; f = [1, 2, 1, 3, 1, 2]'; phat = mle (x, 'distribution', 'normal', 'frequency', f); xx = repelem (x, f); assert_equal (phat(2), std (xx, 1), 1e-10); ***** test ## with censoring normfit already maximises the likelihood: no correction x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]'; c = [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0]'; ref = normfit (x, 0.05, c); [~, s] = normfit (x, 0.05, c); phat = mle (x, 'distribution', 'normal', 'censoring', c); assert_equal (phat(2), s, 1e-12); ***** test ## the confidence interval is normfit's and must not shift x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]'; [~, pci] = mle (x, 'distribution', 'normal'); [~, ~, muci, sci] = normfit (x); assert_equal (pci, [muci, sci], 1e-12); ***** test x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; [phat, pci] = mle (x, 'pdf', @(x, mu, s) normpdf (x, mu, s), ... 'start', [mean(x), std(x)]); assert_equal (phat, [3.42499970800201, 1.03208912390818], 1e-4); assert_equal (pci, [2.8410510441517, 0.619175174501268; ... 4.00894837185232, 1.44500307331509], 1e-4); ***** test x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; nll = @(p, d, c, f) -sum (log (normpdf (d, p(1), p(2)))); phat = mle (x, 'nloglf', nll, 'start', [3, 1]); assert_equal (phat, [3.42499959294639, 1.03208933560634], 1e-4); ***** test x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; phat = mle (x, 'logpdf', @(x, mu, s) log (normpdf (x, mu, s)), ... 'start', [3, 1]); assert_equal (phat, [3.42499959294639, 1.03208933560634], 1e-4); ***** test ## Alpha propagates into the Wald interval x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; [~, pci] = mle (x, 'pdf', @(x, mu, s) normpdf (x, mu, s), ... 'start', [mean(x), std(x)], 'alpha', 0.10); assert_equal (pci, [2.93493454085403, 0.685560813868748; ... 3.91506487514999, 1.37861743394761], 1e-4); ***** test ## Frequency-weighted fit x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; f = [1, 2, 1, 1, 3, 1, 2, 1, 1, 1, 2, 1]; phat = mle (x, 'pdf', @(x, mu, s) normpdf (x, mu, s), ... 'start', [mean(x), std(x)], 'frequency', f); assert_equal (phat, [3.47058837030174, 0.902783454993327], 1e-4); ***** test ## Right-censored fit (needs a cdf) x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; c = [0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0]; phat = mle (x, 'pdf', @(x, mu, s) normpdf (x, mu, s), ... 'cdf', @(x, mu, s) normcdf (x, mu, s), ... 'start', [mean(x), std(x)], 'censoring', c); assert_equal (phat, [3.62195934926527, 1.03307264832117], 1e-4); ***** test ## Bounded fit via reparameterization (lower bound inactive at the optimum) x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; phat = mle (x, 'pdf', @(x, mu) exppdf (x, mu), 'start', 3, 'lowerbound', 0); assert_equal (phat, 3.42499980926514, 1e-4); ***** test ## Truncated fit on [1, 6] x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; phat = mle (x, 'pdf', @(x, mu, s) normpdf (x, mu, s), ... 'cdf', @(x, mu, s) normcdf (x, mu, s), ... 'start', [mean(x), std(x)], 'truncationbounds', [1, 6]); assert_equal (phat, [3.41148048015442, 1.12176348358835], 1e-4); ***** test ## The BirnbaumSaunders distribution is reachable by its full name, not only ## by 'bisa'; the name is matched after tolower, so a mixed-case label was ## never matched by anything. x = [1.2; 0.4; 3.1; 0.7; 2.5; 1.8; 0.3; 4.2; 1.1; 0.9; ... 2.2; 0.6; 1.5; 3.7; 0.8; 2.9; 1.3; 0.5; 2.0; 1.6]; assert_equal (mle (x, 'distribution', 'BirnbaumSaunders'), ... mle (x, 'distribution', 'bisa')); assert_equal (mle (x, 'distribution', 'birnbaumsaunders'), ... mle (x, 'distribution', 'bisa')); ***** test ## the Generalized Pareto location defaults to zero and is not returned x = [2.2196, 11.9301, 4.3673, 1.0949, 6.5626, ... 1.2109, 1.8576, 1.0039, 12.7917, 2.2590]; assert_equal (mle (x, 'distribution', 'gp'), ... [-0.163107819293798, 5.305483917184919], 1e-4); ***** test ## a known location shifts the data, leaving two parameters estimated x = [2.2196, 11.9301, 4.3673, 1.0949, 6.5626, ... 1.2109, 1.8576, 1.0039, 12.7917, 2.2590]; assert_equal (mle (x, 'distribution', 'gp', 'theta', 1), ... [0.893710299404345, 1.322962458731574], 1e-6); ***** test ## the Continuous Uniform interval holds one endpoint per column u = [0.2, 0.5, 0.7, 0.9, 0.35]; [phat, pci] = mle (u, 'distribution', 'unif'); assert_equal (phat, [0.2, 0.9], 1e-12); assert_equal (pci, [-0.374394942118256, 0.9; ... 0.2, 1.474394942118256], 1e-12); ***** error mle (ones (2)) ***** error mle ('text') ***** error mle ([1, 2, 3, i, 5]) ***** error ... mle ([1:50], 'distribution') ***** error ... mle ([1:50], 'censoring', logical ([1,0,1,0])) ***** error ... mle ([1:50], 'frequency', [1,0,1,0]) ***** error ... mle ([1 0 1 0], 'frequency', [-1 1 0 0]) ***** error ... mle ([1 0 1 0], 'distribution', 'nbin', 'frequency', [-1 1 0 0]) ***** error mle ([1:50], 'alpha', [0.05, 0.01]) ***** error mle ([1:50], 'alpha', 1) ***** error mle ([1:50], 'alpha', -1) ***** error mle ([1:50], 'alpha', i) ***** error ... mle ([1:50], 'ntrials', -1) ***** error ... mle ([1:50], 'ntrials', [20, 50]) ***** error ... mle ([1:50], 'ntrials', [20.3]) ***** error ... mle ([1:50], 'ntrials', 3i) ***** error ... mle ([1:50], 'options', 4) ***** error ... mle ([1:50], 'options', struct ('x', 3)) ***** error mle ([1:50], 'NAME', 'value') ***** error ... mle ([1 0 1 0], 'distribution', 'bernoulli', 'censoring', [1 1 0 0]) ***** error ... mle ([1 2 1 0], 'distribution', 'bernoulli') ***** error ... mle ([1 0 1 0], 'distribution', 'beta', 'censoring', [1 1 0 0]) ***** error ... mle ([1 0 1 0], 'distribution', 'bino', 'censoring', [1 1 0 0]) ***** error ... mle ([1 0 1 0], 'distribution', 'bino') ***** error ... mle ([1 0 1 0], 'distribution', 'geo', 'censoring', [1 1 0 0]) ***** error ... mle ([1 0 1 0], 'distribution', 'gev', 'censoring', [1 1 0 0]) ***** error ... mle ([1 0 1 0], 'distribution', 'gp', 'censoring', [1 1 0 0]) ***** error ... mle ([1 0 -1 0], 'distribution', 'gp') ***** error ... mle ([1 0 1 0], 'distribution', 'hn', 'censoring', [1 1 0 0]) ***** error ... mle ([1 0 -1 0], 'distribution', 'hn') ***** error ... mle ([1 0 1 0], 'distribution', 'nbin', 'censoring', [1 1 0 0]) ***** error ... mle ([1 0 1 0], 'distribution', 'poisson', 'censoring', [1 1 0 0]) ***** error ... mle ([1 0 1 0], 'distribution', 'unid', 'censoring', [1 1 0 0]) ***** error ... mle ([1 0 1 0], 'distribution', 'unif', 'censoring', [1 1 0 0]) ***** error mle ([1:50], 'distribution', 'value') ***** error ... mle ([1 0 1 0], 'distribution', 'unif', 'censoring', [1 1 0 0]) ***** error ... mle ([1:50], 'distribution', 'normal', 'pdf', @(x, a, b) normpdf (x, a, b)) ***** error ... mle ([1:50], 'pdf', @sin, 'nloglf', @cos) ***** error ... mle ([1:50], 'pdf', @(x, a, b) normpdf (x, a, b)) ***** error ... mle ([1:50], 'pdf', @(x, a, b) normpdf (x, a, b), 'start', 'text') ***** error ... mle ([1:50], 'pdf', 5, 'start', [0, 1]) ***** error ... mle ([1:50], 'nloglf', 5, 'start', [0, 1]) ***** error ... mle ([1:50], 'pdf', @(x, a, b) normpdf (x, a, b), 'cdf', 5, 'start', [0, 1]) ***** error ... mle ([1:50], 'pdf', @(x, a, b) normpdf (x, a, b), 'start', [0, 1], ... 'censoring', [1, zeros(1, 49)]) ***** error ... mle ([1:50], 'pdf', @(x, a, b) normpdf (x, a, b), ... 'cdf', @(x, a, b) normcdf (x, a, b), 'start', [0, 1], ... 'truncationbounds', [6, 1]) ***** error ... mle ([1:50], 'pdf', @(x, a, b) normpdf (x, a, b), 'start', [0, 1], ... 'lowerbound', [0, 2], 'upperbound', [0, 5]) ***** error ... mle ([1:50], 'pdf', @(x, a, b) normpdf (x, a, b), 'start', [0, 1], ... 'lowerbound', [1, 0]) ***** error ... mle ([1:50], 'pdf', @(x, a, b) normpdf (x, a, b), 'start', [0, 1], ... 'optimfun', 'fmincon') 72 tests, 72 passed, 0 known failure, 0 skipped [inst/Distribution_Wrappers/pdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Wrappers/pdf.m ***** shared x x = [1:5]; ***** assert_equal (pdf ('Beta', x, 5, 2), betapdf (x, 5, 2)) ***** assert_equal (pdf ('beta', x, 5, 2), betapdf (x, 5, 2)) ***** assert_equal (pdf ('Binomial', x, 5, 2), binopdf (x, 5, 2)) ***** assert_equal (pdf ('bino', x, 5, 2), binopdf (x, 5, 2)) ***** assert_equal (pdf ('Birnbaum-Saunders', x, 5, 2), bisapdf (x, 5, 2)) ***** assert_equal (pdf ('bisa', x, 5, 2), bisapdf (x, 5, 2)) ***** assert_equal (pdf ('Burr', x, 5, 2, 2), burrpdf (x, 5, 2, 2)) ***** assert_equal (pdf ('burr', x, 5, 2, 2), burrpdf (x, 5, 2, 2)) ***** assert_equal (pdf ('Cauchy', x, 5, 2), cauchypdf (x, 5, 2)) ***** assert_equal (pdf ('cauchy', x, 5, 2), cauchypdf (x, 5, 2)) ***** assert_equal (pdf ('Chi-squared', x, 5), chi2pdf (x, 5)) ***** assert_equal (pdf ('chi2', x, 5), chi2pdf (x, 5)) ***** assert_equal (pdf ('Extreme Value', x, 5, 2), evpdf (x, 5, 2)) ***** assert_equal (pdf ('ev', x, 5, 2), evpdf (x, 5, 2)) ***** assert_equal (pdf ('Exponential', x, 5), exppdf (x, 5)) ***** assert_equal (pdf ('exp', x, 5), exppdf (x, 5)) ***** assert_equal (pdf ('F-Distribution', x, 5, 2), fpdf (x, 5, 2)) ***** assert_equal (pdf ('f', x, 5, 2), fpdf (x, 5, 2)) ***** assert_equal (pdf ('Gamma', x, 5, 2), gampdf (x, 5, 2)) ***** assert_equal (pdf ('gam', x, 5, 2), gampdf (x, 5, 2)) ***** assert_equal (pdf ('Geometric', x, 5), geopdf (x, 5)) ***** assert_equal (pdf ('geo', x, 5), geopdf (x, 5)) ***** assert_equal (pdf ('Generalized Extreme Value', x, 5, 2, 2), gevpdf (x, 5, 2, 2)) ***** assert_equal (pdf ('gev', x, 5, 2, 2), gevpdf (x, 5, 2, 2)) ***** assert_equal (pdf ('Generalized Pareto', x, 5, 2, 2), gppdf (x, 5, 2, 2)) ***** assert_equal (pdf ('gp', x, 5, 2, 2), gppdf (x, 5, 2, 2)) ***** assert_equal (pdf ('Gumbel', x, 5, 2), gumbelpdf (x, 5, 2)) ***** assert_equal (pdf ('gumbel', x, 5, 2), gumbelpdf (x, 5, 2)) ***** assert_equal (pdf ('Half-normal', x, 5, 2), hnpdf (x, 5, 2)) ***** assert_equal (pdf ('hn', x, 5, 2), hnpdf (x, 5, 2)) ***** assert_equal (pdf ('Hypergeometric', x, 5, 2, 2), hygepdf (x, 5, 2, 2)) ***** assert_equal (pdf ('hyge', x, 5, 2, 2), hygepdf (x, 5, 2, 2)) ***** assert_equal (pdf ('Inverse Gaussian', x, 5, 2), invgpdf (x, 5, 2)) ***** assert_equal (pdf ('invg', x, 5, 2), invgpdf (x, 5, 2)) ***** assert_equal (pdf ('Laplace', x, 5, 2), laplacepdf (x, 5, 2)) ***** assert_equal (pdf ('laplace', x, 5, 2), laplacepdf (x, 5, 2)) ***** assert_equal (pdf ('Logistic', x, 5, 2), logipdf (x, 5, 2)) ***** assert_equal (pdf ('logi', x, 5, 2), logipdf (x, 5, 2)) ***** assert_equal (pdf ('Log-Logistic', x, 5, 2), loglpdf (x, 5, 2)) ***** assert_equal (pdf ('logl', x, 5, 2), loglpdf (x, 5, 2)) ***** assert_equal (pdf ('Lognormal', x, 5, 2), lognpdf (x, 5, 2)) ***** assert_equal (pdf ('logn', x, 5, 2), lognpdf (x, 5, 2)) ***** assert_equal (pdf ('Nakagami', x, 5, 2), nakapdf (x, 5, 2)) ***** assert_equal (pdf ('naka', x, 5, 2), nakapdf (x, 5, 2)) ***** assert_equal (pdf ('Negative Binomial', x, 5, 2), nbinpdf (x, 5, 2)) ***** assert_equal (pdf ('nbin', x, 5, 2), nbinpdf (x, 5, 2)) ***** assert_equal (pdf ('Noncentral F-Distribution', x, 5, 2, 2), ncfpdf (x, 5, 2, 2)) ***** assert_equal (pdf ('ncf', x, 5, 2, 2), ncfpdf (x, 5, 2, 2)) ***** assert_equal (pdf ('Noncentral Student T', x, 5, 2), nctpdf (x, 5, 2)) ***** assert_equal (pdf ('nct', x, 5, 2), nctpdf (x, 5, 2)) ***** assert_equal (pdf ('Noncentral Chi-Squared', x, 5, 2), ncx2pdf (x, 5, 2)) ***** assert_equal (pdf ('ncx2', x, 5, 2), ncx2pdf (x, 5, 2)) ***** assert_equal (pdf ('Normal', x, 5, 2), normpdf (x, 5, 2)) ***** assert_equal (pdf ('norm', x, 5, 2), normpdf (x, 5, 2)) ***** assert_equal (pdf ('Poisson', x, 5), poisspdf (x, 5)) ***** assert_equal (pdf ('poiss', x, 5), poisspdf (x, 5)) ***** assert_equal (pdf ('Rayleigh', x, 5), raylpdf (x, 5)) ***** assert_equal (pdf ('rayl', x, 5), raylpdf (x, 5)) ***** assert_equal (pdf ('Rician', x, 5, 1), ricepdf (x, 5, 1)) ***** assert_equal (pdf ('rice', x, 5, 1), ricepdf (x, 5, 1)) ***** assert_equal (pdf ('Student T', x, 5), tpdf (x, 5)) ***** assert_equal (pdf ('t', x, 5), tpdf (x, 5)) ***** assert_equal (pdf ('location-scale T', x, 5, 1, 2), tlspdf (x, 5, 1, 2)) ***** assert_equal (pdf ('tls', x, 5, 1, 2), tlspdf (x, 5, 1, 2)) ***** assert_equal (pdf ('Triangular', x, 5, 2, 2), tripdf (x, 5, 2, 2)) ***** assert_equal (pdf ('tri', x, 5, 2, 2), tripdf (x, 5, 2, 2)) ***** assert_equal (pdf ('Discrete Uniform', x, 5), unidpdf (x, 5)) ***** assert_equal (pdf ('unid', x, 5), unidpdf (x, 5)) ***** assert_equal (pdf ('Uniform', x, 5, 2), unifpdf (x, 5, 2)) ***** assert_equal (pdf ('unif', x, 5, 2), unifpdf (x, 5, 2)) ***** assert_equal (pdf ('Von Mises', x, 5, 2), vmpdf (x, 5, 2)) ***** assert_equal (pdf ('vm', x, 5, 2), vmpdf (x, 5, 2)) ***** assert_equal (pdf ('Weibull', x, 5, 2), wblpdf (x, 5, 2)) ***** assert_equal (pdf ('wbl', x, 5, 2), wblpdf (x, 5, 2)) ***** test ## Every spelling of a name reaches the same distribution: case, spaces, ## hyphens and underscores are all ignored. for n = {'Extreme Value', 'ExtremeValue', 'extreme-value', 'EXTREME VALUE'} assert_equal (pdf (n{1}, 1, 2, 3), pdf ('ev', 1, 2, 3)); endfor ***** test ## The name that makedist uses is accepted here too, and the reverse assert_equal (pdf ('tLocationScale', 1, 2, 3, 4), pdf ('tls', 1, 2, 3, 4)); ***** error pdf (1) ***** error pdf ({'beta'}) ***** error pdf ('beta', {[1 2 3 4 5]}) ***** error pdf ('beta', 'text') ***** error pdf ('beta', 1+i) ***** error ... pdf ('Beta', x, 'a', 2) ***** error ... pdf ('Beta', x, 5, '') ***** error ... pdf ('Beta', x, 5, {2}) ***** error pdf ('chi2', x) ***** error pdf ('Beta', x, 5) ***** error pdf ('Burr', x, 5) ***** error pdf ('Burr', x, 5, 2) 88 tests, 88 passed, 0 known failure, 0 skipped [inst/Distribution_Wrappers/icdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Wrappers/icdf.m ***** shared p p = [0.05:0.05:0.5]; ***** assert_equal (icdf ('Beta', p, 5, 2), betainv (p, 5, 2)) ***** assert_equal (icdf ('beta', p, 5, 2), betainv (p, 5, 2)) ***** assert_equal (icdf ('Binomial', p, 5, 2), binoinv (p, 5, 2)) ***** assert_equal (icdf ('bino', p, 5, 2), binoinv (p, 5, 2)) ***** assert_equal (icdf ('Birnbaum-Saunders', p, 5, 2), bisainv (p, 5, 2)) ***** assert_equal (icdf ('bisa', p, 5, 2), bisainv (p, 5, 2)) ***** assert_equal (icdf ('Burr', p, 5, 2, 2), burrinv (p, 5, 2, 2)) ***** assert_equal (icdf ('burr', p, 5, 2, 2), burrinv (p, 5, 2, 2)) ***** assert_equal (icdf ('Cauchy', p, 5, 2), cauchyinv (p, 5, 2)) ***** assert_equal (icdf ('cauchy', p, 5, 2), cauchyinv (p, 5, 2)) ***** assert_equal (icdf ('Chi-squared', p, 5), chi2inv (p, 5)) ***** assert_equal (icdf ('chi2', p, 5), chi2inv (p, 5)) ***** assert_equal (icdf ('Extreme Value', p, 5, 2), evinv (p, 5, 2)) ***** assert_equal (icdf ('ev', p, 5, 2), evinv (p, 5, 2)) ***** assert_equal (icdf ('Exponential', p, 5), expinv (p, 5)) ***** assert_equal (icdf ('exp', p, 5), expinv (p, 5)) ***** assert_equal (icdf ('F-Distribution', p, 5, 2), finv (p, 5, 2)) ***** assert_equal (icdf ('f', p, 5, 2), finv (p, 5, 2)) ***** assert_equal (icdf ('Gamma', p, 5, 2), gaminv (p, 5, 2)) ***** assert_equal (icdf ('gam', p, 5, 2), gaminv (p, 5, 2)) ***** assert_equal (icdf ('Geometric', p, 5), geoinv (p, 5)) ***** assert_equal (icdf ('geo', p, 5), geoinv (p, 5)) ***** assert_equal (icdf ('Generalized Extreme Value', p, 5, 2, 2), gevinv (p, 5, 2, 2)) ***** assert_equal (icdf ('gev', p, 5, 2, 2), gevinv (p, 5, 2, 2)) ***** assert_equal (icdf ('Generalized Pareto', p, 5, 2, 2), gpinv (p, 5, 2, 2)) ***** assert_equal (icdf ('gp', p, 5, 2, 2), gpinv (p, 5, 2, 2)) ***** assert_equal (icdf ('Gumbel', p, 5, 2), gumbelinv (p, 5, 2)) ***** assert_equal (icdf ('gumbel', p, 5, 2), gumbelinv (p, 5, 2)) ***** assert_equal (icdf ('Half-normal', p, 5, 2), hninv (p, 5, 2)) ***** assert_equal (icdf ('hn', p, 5, 2), hninv (p, 5, 2)) ***** assert_equal (icdf ('Hypergeometric', p, 5, 2, 2), hygeinv (p, 5, 2, 2)) ***** assert_equal (icdf ('hyge', p, 5, 2, 2), hygeinv (p, 5, 2, 2)) ***** assert_equal (icdf ('Inverse Gaussian', p, 5, 2), invginv (p, 5, 2)) ***** assert_equal (icdf ('invg', p, 5, 2), invginv (p, 5, 2)) ***** assert_equal (icdf ('Laplace', p, 5, 2), laplaceinv (p, 5, 2)) ***** assert_equal (icdf ('laplace', p, 5, 2), laplaceinv (p, 5, 2)) ***** assert_equal (icdf ('Logistic', p, 5, 2), logiinv (p, 5, 2)) ***** assert_equal (icdf ('logi', p, 5, 2), logiinv (p, 5, 2)) ***** assert_equal (icdf ('Log-Logistic', p, 5, 2), loglinv (p, 5, 2)) ***** assert_equal (icdf ('logl', p, 5, 2), loglinv (p, 5, 2)) ***** assert_equal (icdf ('Lognormal', p, 5, 2), logninv (p, 5, 2)) ***** assert_equal (icdf ('logn', p, 5, 2), logninv (p, 5, 2)) ***** assert_equal (icdf ('Nakagami', p, 5, 2), nakainv (p, 5, 2)) ***** assert_equal (icdf ('naka', p, 5, 2), nakainv (p, 5, 2)) ***** assert_equal (icdf ('Negative Binomial', p, 5, 2), nbininv (p, 5, 2)) ***** assert_equal (icdf ('nbin', p, 5, 2), nbininv (p, 5, 2)) ***** assert_equal (icdf ('Noncentral F-Distribution', p, 5, 2, 2), ncfinv (p, 5, 2, 2)) ***** assert_equal (icdf ('ncf', p, 5, 2, 2), ncfinv (p, 5, 2, 2)) ***** assert_equal (icdf ('Noncentral Student T', p, 5, 2), nctinv (p, 5, 2)) ***** assert_equal (icdf ('nct', p, 5, 2), nctinv (p, 5, 2)) ***** assert_equal (icdf ('Noncentral Chi-Squared', p, 5, 2), ncx2inv (p, 5, 2)) ***** assert_equal (icdf ('ncx2', p, 5, 2), ncx2inv (p, 5, 2)) ***** assert_equal (icdf ('Normal', p, 5, 2), norminv (p, 5, 2)) ***** assert_equal (icdf ('norm', p, 5, 2), norminv (p, 5, 2)) ***** assert_equal (icdf ('Poisson', p, 5), poissinv (p, 5)) ***** assert_equal (icdf ('poiss', p, 5), poissinv (p, 5)) ***** assert_equal (icdf ('Rayleigh', p, 5), raylinv (p, 5)) ***** assert_equal (icdf ('rayl', p, 5), raylinv (p, 5)) ***** assert_equal (icdf ('Rician', p, 5, 1), riceinv (p, 5, 1)) ***** assert_equal (icdf ('rice', p, 5, 1), riceinv (p, 5, 1)) ***** assert_equal (icdf ('Student T', p, 5), tinv (p, 5)) ***** assert_equal (icdf ('t', p, 5), tinv (p, 5)) ***** assert_equal (icdf ('location-scale T', p, 5, 1, 2), tlsinv (p, 5, 1, 2)) ***** assert_equal (icdf ('tls', p, 5, 1, 2), tlsinv (p, 5, 1, 2)) ***** assert_equal (icdf ('Triangular', p, 5, 2, 2), triinv (p, 5, 2, 2)) ***** assert_equal (icdf ('tri', p, 5, 2, 2), triinv (p, 5, 2, 2)) ***** assert_equal (icdf ('Discrete Uniform', p, 5), unidinv (p, 5)) ***** assert_equal (icdf ('unid', p, 5), unidinv (p, 5)) ***** assert_equal (icdf ('Uniform', p, 5, 2), unifinv (p, 5, 2)) ***** assert_equal (icdf ('unif', p, 5, 2), unifinv (p, 5, 2)) ***** assert_equal (icdf ('Von Mises', p, 5, 2), vminv (p, 5, 2)) ***** assert_equal (icdf ('vm', p, 5, 2), vminv (p, 5, 2)) ***** assert_equal (icdf ('Weibull', p, 5, 2), wblinv (p, 5, 2)) ***** assert_equal (icdf ('wbl', p, 5, 2), wblinv (p, 5, 2)) ***** test ## Every spelling of a name reaches the same distribution: case, spaces, ## hyphens and underscores are all ignored. for n = {'Extreme Value', 'ExtremeValue', 'extreme-value', 'EXTREME VALUE'} assert_equal (icdf (n{1}, 0.5, 2, 3), icdf ('ev', 0.5, 2, 3)); endfor ***** test ## The name that makedist uses is accepted here too, and the reverse assert_equal (icdf ('tLocationScale', 0.5, 2, 3, 4), ... icdf ('tls', 0.5, 2, 3, 4)); ***** error icdf (1) ***** error icdf ({'beta'}) ***** error icdf ('beta', {[1 2 3 4 5]}) ***** error icdf ('beta', 'text') ***** error icdf ('beta', 1+i) ***** error ... icdf ('Beta', p, 'a', 2) ***** error ... icdf ('Beta', p, 5, '') ***** error ... icdf ('Beta', p, 5, {2}) ***** error icdf ('chi2', p) ***** error icdf ('Beta', p, 5) ***** error icdf ('Burr', p, 5) ***** error icdf ('Burr', p, 5, 2) 88 tests, 88 passed, 0 known failure, 0 skipped [inst/Distribution_Wrappers/cdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Wrappers/cdf.m ***** shared x x = [1:5]; ***** assert_equal (cdf ('Beta', x, 5, 2), betacdf (x, 5, 2)) ***** assert_equal (cdf ('beta', x, 5, 2, 'upper'), betacdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Binomial', x, 5, 2), binocdf (x, 5, 2)) ***** assert_equal (cdf ('bino', x, 5, 2, 'upper'), binocdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Birnbaum-Saunders', x, 5, 2), bisacdf (x, 5, 2)) ***** assert_equal (cdf ('bisa', x, 5, 2, 'upper'), bisacdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Burr', x, 5, 2, 2), burrcdf (x, 5, 2, 2)) ***** assert_equal (cdf ('burr', x, 5, 2, 2, 'upper'), burrcdf (x, 5, 2, 2, 'upper')) ***** assert_equal (cdf ('Cauchy', x, 5, 2), cauchycdf (x, 5, 2)) ***** assert_equal (cdf ('cauchy', x, 5, 2, 'upper'), cauchycdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Chi-squared', x, 5), chi2cdf (x, 5)) ***** assert_equal (cdf ('chi2', x, 5, 'upper'), chi2cdf (x, 5, 'upper')) ***** assert_equal (cdf ('Extreme Value', x, 5, 2), evcdf (x, 5, 2)) ***** assert_equal (cdf ('ev', x, 5, 2, 'upper'), evcdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Exponential', x, 5), expcdf (x, 5)) ***** assert_equal (cdf ('exp', x, 5, 'upper'), expcdf (x, 5, 'upper')) ***** assert_equal (cdf ('F-Distribution', x, 5, 2), fcdf (x, 5, 2)) ***** assert_equal (cdf ('f', x, 5, 2, 'upper'), fcdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Gamma', x, 5, 2), gamcdf (x, 5, 2)) ***** assert_equal (cdf ('gam', x, 5, 2, 'upper'), gamcdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Geometric', x, 5), geocdf (x, 5)) ***** assert_equal (cdf ('geo', x, 5, 'upper'), geocdf (x, 5, 'upper')) ***** assert_equal (cdf ('Generalized Extreme Value', x, 5, 2, 2), gevcdf (x, 5, 2, 2)) ***** assert_equal (cdf ('gev', x, 5, 2, 2, 'upper'), gevcdf (x, 5, 2, 2, 'upper')) ***** assert_equal (cdf ('Generalized Pareto', x, 5, 2, 2), gpcdf (x, 5, 2, 2)) ***** assert_equal (cdf ('gp', x, 5, 2, 2, 'upper'), gpcdf (x, 5, 2, 2, 'upper')) ***** assert_equal (cdf ('Gumbel', x, 5, 2), gumbelcdf (x, 5, 2)) ***** assert_equal (cdf ('gumbel', x, 5, 2, 'upper'), gumbelcdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Half-normal', x, 5, 2), hncdf (x, 5, 2)) ***** assert_equal (cdf ('hn', x, 5, 2, 'upper'), hncdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Hypergeometric', x, 5, 2, 2), hygecdf (x, 5, 2, 2)) ***** assert_equal (cdf ('hyge', x, 5, 2, 2, 'upper'), hygecdf (x, 5, 2, 2, 'upper')) ***** assert_equal (cdf ('Inverse Gaussian', x, 5, 2), invgcdf (x, 5, 2)) ***** assert_equal (cdf ('invg', x, 5, 2, 'upper'), invgcdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Laplace', x, 5, 2), laplacecdf (x, 5, 2)) ***** assert_equal (cdf ('laplace', x, 5, 2, 'upper'), laplacecdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Logistic', x, 5, 2), logicdf (x, 5, 2)) ***** assert_equal (cdf ('logi', x, 5, 2, 'upper'), logicdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Log-Logistic', x, 5, 2), loglcdf (x, 5, 2)) ***** assert_equal (cdf ('logl', x, 5, 2, 'upper'), loglcdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Lognormal', x, 5, 2), logncdf (x, 5, 2)) ***** assert_equal (cdf ('logn', x, 5, 2, 'upper'), logncdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Nakagami', x, 5, 2), nakacdf (x, 5, 2)) ***** assert_equal (cdf ('naka', x, 5, 2, 'upper'), nakacdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Negative Binomial', x, 5, 2), nbincdf (x, 5, 2)) ***** assert_equal (cdf ('nbin', x, 5, 2, 'upper'), nbincdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Noncentral F-Distribution', x, 5, 2, 2), ncfcdf (x, 5, 2, 2)) ***** assert_equal (cdf ('ncf', x, 5, 2, 2, 'upper'), ncfcdf (x, 5, 2, 2, 'upper')) ***** assert_equal (cdf ('Noncentral Student T', x, 5, 2), nctcdf (x, 5, 2)) ***** assert_equal (cdf ('nct', x, 5, 2, 'upper'), nctcdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Noncentral Chi-Squared', x, 5, 2), ncx2cdf (x, 5, 2)) ***** assert_equal (cdf ('ncx2', x, 5, 2, 'upper'), ncx2cdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Normal', x, 5, 2), normcdf (x, 5, 2)) ***** assert_equal (cdf ('norm', x, 5, 2, 'upper'), normcdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Poisson', x, 5), poisscdf (x, 5)) ***** assert_equal (cdf ('poiss', x, 5, 'upper'), poisscdf (x, 5, 'upper')) ***** assert_equal (cdf ('Rayleigh', x, 5), raylcdf (x, 5)) ***** assert_equal (cdf ('rayl', x, 5, 'upper'), raylcdf (x, 5, 'upper')) ***** assert_equal (cdf ('Rician', x, 5, 1), ricecdf (x, 5, 1)) ***** assert_equal (cdf ('rice', x, 5, 1, 'upper'), ricecdf (x, 5, 1, 'upper')) ***** assert_equal (cdf ('Student T', x, 5), tcdf (x, 5)) ***** assert_equal (cdf ('t', x, 5, 'upper'), tcdf (x, 5, 'upper')) ***** assert_equal (cdf ('location-scale T', x, 5, 1, 2), tlscdf (x, 5, 1, 2)) ***** assert_equal (cdf ('tls', x, 5, 1, 2, 'upper'), tlscdf (x, 5, 1, 2, 'upper')) ***** assert_equal (cdf ('Triangular', x, 5, 2, 2), tricdf (x, 5, 2, 2)) ***** assert_equal (cdf ('tri', x, 5, 2, 2, 'upper'), tricdf (x, 5, 2, 2, 'upper')) ***** assert_equal (cdf ('Discrete Uniform', x, 5), unidcdf (x, 5)) ***** assert_equal (cdf ('unid', x, 5, 'upper'), unidcdf (x, 5, 'upper')) ***** assert_equal (cdf ('Uniform', x, 5, 2), unifcdf (x, 5, 2)) ***** assert_equal (cdf ('unif', x, 5, 2, 'upper'), unifcdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Von Mises', x, 5, 2), vmcdf (x, 5, 2)) ***** assert_equal (cdf ('vm', x, 5, 2, 'upper'), vmcdf (x, 5, 2, 'upper')) ***** assert_equal (cdf ('Weibull', x, 5, 2), wblcdf (x, 5, 2)) ***** assert_equal (cdf ('wbl', x, 5, 2, 'upper'), wblcdf (x, 5, 2, 'upper')) ***** test ## Every spelling of a name reaches the same distribution: case, spaces, ## hyphens and underscores are all ignored. for n = {'Extreme Value', 'ExtremeValue', 'extreme-value', 'EXTREME VALUE'} assert_equal (cdf (n{1}, 1, 2, 3), cdf ('ev', 1, 2, 3)); endfor ***** test ## The name that makedist uses is accepted here too, and the reverse assert_equal (cdf ('tLocationScale', 1, 2, 3, 4), cdf ('tls', 1, 2, 3, 4)); ***** error cdf (1) ***** error cdf ({'beta'}) ***** error cdf ('beta', {[1 2 3 4 5]}) ***** error cdf ('beta', 'text') ***** error cdf ('beta', 1+i) ***** error ... cdf ('Beta', x, 'a', 2) ***** error ... cdf ('Beta', x, 5, '') ***** error ... cdf ('Beta', x, 5, {2}) ***** error cdf ('chi2', x) ***** error cdf ('Beta', x, 5) ***** error cdf ('Burr', x, 5) ***** error cdf ('Burr', x, 5, 2) 88 tests, 88 passed, 0 known failure, 0 skipped [inst/Distribution_Wrappers/makedist.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Wrappers/makedist.m ***** test pd = makedist ('beta'); assert_equal (class (pd), "prob.BetaDistribution"); assert_equal (pd.a, 1); assert_equal (pd.b, 1); ***** test pd = makedist ('beta', 'a', 5); assert_equal (pd.a, 5); assert_equal (pd.b, 1); ***** test pd = makedist ('beta', 'b', 5); assert_equal (pd.a, 1); assert_equal (pd.b, 5); ***** test pd = makedist ('beta', 'a', 3, 'b', 5); assert_equal (pd.a, 3); assert_equal (pd.b, 5); ***** test pd = makedist ('binomial'); assert_equal (class (pd), "prob.BinomialDistribution"); assert_equal (pd.N, 1); assert_equal (pd.p, 0.5); ***** test pd = makedist ('binomial', 'N', 5); assert_equal (pd.N, 5); assert_equal (pd.p, 0.5); ***** test pd = makedist ('binomial', 'p', 0.2); assert_equal (pd.N, 1); assert_equal (pd.p, 0.2); ***** test pd = makedist ('binomial', 'N', 3, 'p', 0.3); assert_equal (pd.N, 3); assert_equal (pd.p, 0.3); ***** test pd = makedist ('birnbaumsaunders'); assert_equal (class (pd), "prob.BirnbaumSaundersDistribution"); assert_equal (pd.beta, 1); assert_equal (pd.gamma, 1); ***** test pd = makedist ('birnbaumsaunders', 'beta', 5); assert_equal (pd.beta, 5); assert_equal (pd.gamma, 1); ***** test pd = makedist ('birnbaumsaunders', 'gamma', 5); assert_equal (pd.beta, 1); assert_equal (pd.gamma, 5); ***** test pd = makedist ('birnbaumsaunders', 'beta', 3, 'gamma', 5); assert_equal (pd.beta, 3); assert_equal (pd.gamma, 5); ***** test pd = makedist ('burr'); assert_equal (class (pd), "prob.BurrDistribution"); assert_equal (pd.alpha, 1); assert_equal (pd.c, 1); assert_equal (pd.k, 1); ***** test pd = makedist ('burr', 'k', 5); assert_equal (pd.alpha, 1); assert_equal (pd.c, 1); assert_equal (pd.k, 5); ***** test pd = makedist ('burr', 'c', 5); assert_equal (pd.alpha, 1); assert_equal (pd.c, 5); assert_equal (pd.k, 1); ***** test pd = makedist ('burr', 'alpha', 3, 'c', 5); assert_equal (pd.alpha, 3); assert_equal (pd.c, 5); assert_equal (pd.k, 1); ***** test pd = makedist ('burr', 'k', 3, 'c', 5); assert_equal (pd.alpha, 1); assert_equal (pd.c, 5); assert_equal (pd.k, 3); ***** test pd = makedist ('exponential'); assert_equal (class (pd), "prob.ExponentialDistribution"); assert_equal (pd.mu, 1); ***** test pd = makedist ('exponential', 'mu', 5); assert_equal (pd.mu, 5); ***** test pd = makedist ('extremevalue'); assert_equal (class (pd), "prob.ExtremeValueDistribution"); assert_equal (pd.mu, 0); assert_equal (pd.sigma, 1); ***** test pd = makedist ('extremevalue', 'mu', 5); assert_equal (class (pd), "prob.ExtremeValueDistribution"); assert_equal (pd.mu, 5); assert_equal (pd.sigma, 1); ***** test pd = makedist ('ev', 'sigma', 5); assert_equal (class (pd), "prob.ExtremeValueDistribution"); assert_equal (pd.mu, 0); assert_equal (pd.sigma, 5); ***** test pd = makedist ('ev', 'mu', -3, 'sigma', 5); assert_equal (class (pd), "prob.ExtremeValueDistribution"); assert_equal (pd.mu, -3); assert_equal (pd.sigma, 5); ***** test pd = makedist ('gamma'); assert_equal (class (pd), "prob.GammaDistribution"); assert_equal (pd.a, 1); assert_equal (pd.b, 1); ***** test pd = makedist ('gamma', 'a', 5); assert_equal (pd.a, 5); assert_equal (pd.b, 1); ***** test pd = makedist ('gamma', 'b', 5); assert_equal (pd.a, 1); assert_equal (pd.b, 5); ***** test pd = makedist ('gamma', 'a', 3, 'b', 5); assert_equal (pd.a, 3); assert_equal (pd.b, 5); ***** test pd = makedist ('GeneralizedExtremeValue'); assert_equal (class (pd), "prob.GeneralizedExtremeValueDistribution"); assert_equal (pd.k, 0); assert_equal (pd.sigma, 1); assert_equal (pd.mu, 0); ***** test pd = makedist ('GeneralizedExtremeValue', 'k', 5); assert_equal (pd.k, 5); assert_equal (pd.sigma, 1); assert_equal (pd.mu, 0); ***** test pd = makedist ('GeneralizedExtremeValue', 'sigma', 5); assert_equal (pd.k, 0); assert_equal (pd.sigma, 5); assert_equal (pd.mu, 0); ***** test pd = makedist ('GeneralizedExtremeValue', 'k', 3, 'sigma', 5); assert_equal (pd.k, 3); assert_equal (pd.sigma, 5); assert_equal (pd.mu, 0); ***** test pd = makedist ('GeneralizedExtremeValue', 'mu', 3, 'sigma', 5); assert_equal (pd.k, 0); assert_equal (pd.sigma, 5); assert_equal (pd.mu, 3); ***** test pd = makedist ('GeneralizedPareto'); assert_equal (class (pd), "prob.GeneralizedParetoDistribution"); assert_equal (pd.k, 1); assert_equal (pd.sigma, 1); assert_equal (pd.theta, 1); ***** test pd = makedist ('GeneralizedPareto', 'k', 5); assert_equal (pd.k, 5); assert_equal (pd.sigma, 1); assert_equal (pd.theta, 1); ***** test pd = makedist ('GeneralizedPareto', 'sigma', 5); assert_equal (pd.k, 1); assert_equal (pd.sigma, 5); assert_equal (pd.theta, 1); ***** test pd = makedist ('GeneralizedPareto', 'k', 3, 'sigma', 5); assert_equal (pd.k, 3); assert_equal (pd.sigma, 5); assert_equal (pd.theta, 1); ***** test pd = makedist ('GeneralizedPareto', 'theta', 3, 'sigma', 5); assert_equal (pd.k, 1); assert_equal (pd.sigma, 5); assert_equal (pd.theta, 3); ***** test pd = makedist ('HalfNormal'); assert_equal (class (pd), "prob.HalfNormalDistribution"); assert_equal (pd.mu, 0); assert_equal (pd.sigma, 1); ***** test pd = makedist ('HalfNormal', 'mu', 5); assert_equal (pd.mu, 5); assert_equal (pd.sigma, 1); ***** test pd = makedist ('HalfNormal', 'sigma', 5); assert_equal (pd.mu, 0); assert_equal (pd.sigma, 5); ***** test pd = makedist ('HalfNormal', 'mu', 3, 'sigma', 5); assert_equal (pd.mu, 3); assert_equal (pd.sigma, 5); ***** test pd = makedist ('InverseGaussian'); assert_equal (class (pd), "prob.InverseGaussianDistribution"); assert_equal (pd.mu, 1); assert_equal (pd.lambda, 1); ***** test pd = makedist ('InverseGaussian', 'mu', 5); assert_equal (pd.mu, 5); assert_equal (pd.lambda, 1); ***** test pd = makedist ('InverseGaussian', 'lambda', 5); assert_equal (pd.mu, 1); assert_equal (pd.lambda, 5); ***** test pd = makedist ('InverseGaussian', 'mu', 3, 'lambda', 5); assert_equal (pd.mu, 3); assert_equal (pd.lambda, 5); ***** test pd = makedist ('logistic'); assert_equal (class (pd), "prob.LogisticDistribution"); assert_equal (pd.mu, 0); assert_equal (pd.sigma, 1); ***** test pd = makedist ('logistic', 'mu', 5); assert_equal (pd.mu, 5); assert_equal (pd.sigma, 1); ***** test pd = makedist ('logistic', 'sigma', 5); assert_equal (pd.mu, 0); assert_equal (pd.sigma, 5); ***** test pd = makedist ('logistic', 'mu', 3, 'sigma', 5); assert_equal (pd.mu, 3); assert_equal (pd.sigma, 5); ***** test pd = makedist ('loglogistic'); assert_equal (class (pd), "prob.LoglogisticDistribution"); assert_equal (pd.mu, 0); assert_equal (pd.sigma, 1); ***** test pd = makedist ('loglogistic', 'mu', 5); assert_equal (pd.mu, 5); assert_equal (pd.sigma, 1); ***** test pd = makedist ('loglogistic', 'sigma', 5); assert_equal (pd.mu, 0); assert_equal (pd.sigma, 5); ***** test pd = makedist ('loglogistic', 'mu', 3, 'sigma', 5); assert_equal (pd.mu, 3); assert_equal (pd.sigma, 5); ***** test pd = makedist ('Lognormal'); assert_equal (class (pd), "prob.LognormalDistribution"); assert_equal (pd.mu, 0); assert_equal (pd.sigma, 1); ***** test pd = makedist ('Lognormal', 'mu', 5); assert_equal (pd.mu, 5); assert_equal (pd.sigma, 1); ***** test pd = makedist ('Lognormal', 'sigma', 5); assert_equal (pd.mu, 0); assert_equal (pd.sigma, 5); ***** test pd = makedist ('Lognormal', 'mu', -3, 'sigma', 5); assert_equal (pd.mu, -3); assert_equal (pd.sigma, 5); ***** test pd = makedist ('Loguniform'); assert_equal (class (pd), "prob.LoguniformDistribution"); assert_equal (pd.Lower, 1); assert_equal (pd.Upper, 4); ***** test pd = makedist ('Loguniform', 'Lower', 2); assert_equal (pd.Lower, 2); assert_equal (pd.Upper, 4); ***** test pd = makedist ('Loguniform', 'Lower', 1, 'Upper', 3); assert_equal (pd.Lower, 1); assert_equal (pd.Upper, 3); ***** test pd = makedist ('Multinomial'); assert_equal (class (pd), "prob.MultinomialDistribution"); assert_equal (pd.Probabilities, [0.5, 0.5]); ***** test pd = makedist ('Multinomial', 'Probabilities', [0.2, 0.3, 0.1, 0.4]); assert_equal (class (pd), "prob.MultinomialDistribution"); assert_equal (pd.Probabilities, [0.2, 0.3, 0.1, 0.4]); ***** test pd = makedist ('Nakagami'); assert_equal (class (pd), "prob.NakagamiDistribution"); assert_equal (pd.mu, 1); assert_equal (pd.omega, 1); ***** test pd = makedist ('Nakagami', 'mu', 5); assert_equal (class (pd), "prob.NakagamiDistribution"); assert_equal (pd.mu, 5); assert_equal (pd.omega, 1); ***** test pd = makedist ('Nakagami', 'omega', 0.3); assert_equal (class (pd), "prob.NakagamiDistribution"); assert_equal (pd.mu, 1); assert_equal (pd.omega, 0.3); ***** test pd = makedist ('NegativeBinomial'); assert_equal (class (pd), "prob.NegativeBinomialDistribution"); assert_equal (pd.R, 1); assert_equal (pd.P, 0.5); ***** test pd = makedist ('NegativeBinomial', 'R', 5); assert_equal (class (pd), "prob.NegativeBinomialDistribution"); assert_equal (pd.R, 5); assert_equal (pd.P, 0.5); ***** test pd = makedist ('NegativeBinomial', 'p', 0.3); assert_equal (class (pd), "prob.NegativeBinomialDistribution"); assert_equal (pd.R, 1); assert_equal (pd.P, 0.3); ***** test pd = makedist ('Normal'); assert_equal (class (pd), "prob.NormalDistribution"); assert_equal (pd.mu, 0); assert_equal (pd.sigma, 1); ***** test pd = makedist ('Normal', 'mu', 5); assert_equal (class (pd), "prob.NormalDistribution"); assert_equal (pd.mu, 5); assert_equal (pd.sigma, 1); ***** test pd = makedist ('Normal', 'sigma', 5); assert_equal (class (pd), "prob.NormalDistribution"); assert_equal (pd.mu, 0); assert_equal (pd.sigma, 5); ***** test pd = makedist ('Normal', 'mu', -3, 'sigma', 5); assert_equal (class (pd), "prob.NormalDistribution"); assert_equal (pd.mu, -3); assert_equal (pd.sigma, 5); ***** test pd = makedist ('PiecewiseLinear'); assert_equal (class (pd), "prob.PiecewiseLinearDistribution"); assert_equal (pd.x, [0, 1]); assert_equal (pd.Fx, [0, 1]); ***** test pd = makedist ('PiecewiseLinear', 'x', [0, 1, 2], 'Fx', [0, 0.5, 1]); assert_equal (pd.x, [0, 1, 2]); assert_equal (pd.Fx, [0, 0.5, 1]); ***** test ## a column is stored the same way, as MATLAB stores it pd = makedist ('PiecewiseLinear', 'x', [0; 1; 2], 'Fx', [0; 0.5; 1]); assert_equal (pd.x, [0, 1, 2]); assert_equal (pd.Fx, [0, 0.5, 1]); ***** test ## Multinomial already agreed with MATLAB and is unchanged pd = makedist ('Multinomial', 'Probabilities', [0.2, 0.3, 0.5]); assert_equal (pd.Probabilities, [0.2, 0.3, 0.5]); assert_equal (size (pd.Probabilities), [1, 3]); ***** test pd = makedist ('Poisson'); assert_equal (class (pd), "prob.PoissonDistribution"); assert_equal (pd.lambda, 1); ***** test pd = makedist ('Poisson', 'lambda', 5); assert_equal (pd.lambda, 5); ***** test pd = makedist ('Rayleigh'); assert_equal (class (pd), "prob.RayleighDistribution"); assert_equal (pd.B, 1); ***** test pd = makedist ('Rayleigh', 'sigma', 5); assert_equal (pd.B, 5); ***** test pd = makedist ('Rician'); assert_equal (class (pd), "prob.RicianDistribution"); assert_equal (pd.s, 1); assert_equal (pd.sigma, 1); ***** test pd = makedist ('Rician', 's', 3); assert_equal (pd.s, 3); assert_equal (pd.sigma, 1); ***** test pd = makedist ('Rician', 'sigma', 3); assert_equal (pd.s, 1); assert_equal (pd.sigma, 3); ***** test pd = makedist ('Rician', 's', 2, 'sigma', 3); assert_equal (pd.s, 2); assert_equal (pd.sigma, 3); ***** test pd = makedist ('stable'); assert_equal (class (pd), "prob.StableDistribution"); assert_equal (pd.alpha, 2); assert_equal (pd.beta, 0); ***** test pd = makedist ('tlocationscale'); assert_equal (class (pd), "prob.tLocationScaleDistribution"); assert_equal (pd.mu, 0); assert_equal (pd.sigma, 1); assert_equal (pd.nu, 5); ***** test pd = makedist ('tlocationscale', 'mu', 5); assert_equal (pd.mu, 5); assert_equal (pd.sigma, 1); assert_equal (pd.nu, 5); ***** test pd = makedist ('tlocationscale', 'sigma', 2); assert_equal (pd.mu, 0); assert_equal (pd.sigma, 2); assert_equal (pd.nu, 5); ***** test pd = makedist ('tlocationscale', 'mu', 5, 'sigma', 2); assert_equal (pd.mu, 5); assert_equal (pd.sigma, 2); assert_equal (pd.nu, 5); ***** test pd = makedist ('tlocationscale', 'nu', 1, 'sigma', 2); assert_equal (pd.mu, 0); assert_equal (pd.sigma, 2); assert_equal (pd.nu, 1); ***** test pd = makedist ('tlocationscale', 'mu', -2, 'sigma', 3, 'nu', 1); assert_equal (pd.mu, -2); assert_equal (pd.sigma, 3); assert_equal (pd.nu, 1); ***** test pd = makedist ('Triangular'); assert_equal (class (pd), "prob.TriangularDistribution"); assert_equal (pd.A, 0); assert_equal (pd.B, 0.5); assert_equal (pd.C, 1); ***** test pd = makedist ('Triangular', 'A', -2); assert_equal (pd.A, -2); assert_equal (pd.B, 0.5); assert_equal (pd.C, 1); ***** test pd = makedist ('Triangular', 'A', 0.5, 'B', 0.9); assert_equal (pd.A, 0.5); assert_equal (pd.B, 0.9); assert_equal (pd.C, 1); ***** test pd = makedist ('Triangular', 'A', 1, 'B', 2, 'C', 5); assert_equal (pd.A, 1); assert_equal (pd.B, 2); assert_equal (pd.C, 5); ***** test pd = makedist ('Uniform'); assert_equal (class (pd), "prob.UniformDistribution"); assert_equal (pd.Lower, 0); assert_equal (pd.Upper, 1); ***** test pd = makedist ('Uniform', 'Lower', -2); assert_equal (pd.Lower, -2); assert_equal (pd.Upper, 1); ***** test pd = makedist ('Uniform', 'Lower', 1, 'Upper', 3); assert_equal (pd.Lower, 1); assert_equal (pd.Upper, 3); ***** test pd = makedist ('Weibull'); assert_equal (class (pd), "prob.WeibullDistribution"); assert_equal (pd.A, 1); assert_equal (pd.B, 1); ***** test pd = makedist ('Weibull', 'lambda', 3); assert_equal (pd.A, 3); assert_equal (pd.B, 1); ***** test pd = makedist ('Weibull', 'lambda', 3, 'k', 2); assert_equal (pd.A, 3); assert_equal (pd.B, 2); ***** error makedist (1) ***** error makedist (['as';'sd']) ***** error makedist ('some') ***** error ... makedist ('Beta', 'a') ***** error ... makedist ('Beta', 'a', 1, 'Q', 23) ***** error ... makedist ('Binomial', 'N', 1, 'Q', 23) ***** error ... makedist ('BirnbaumSaunders', 'N', 1) ***** error ... makedist ('Burr', 'lambda', 1, 'sdfs', 34) ***** error ... makedist ('extremevalue', 'mu', 1, 'sdfs', 34) ***** error ... makedist ('exponential', 'mu', 1, 'sdfs', 34) ***** error ... makedist ('Gamma', 'k', 1, 'sdfs', 34) ***** error ... makedist ('GeneralizedExtremeValue', 'k', 1, 'sdfs', 34) ***** error ... makedist ('GeneralizedPareto', 'k', 1, 'sdfs', 34) ***** error ... makedist ('HalfNormal', 'k', 1, 'sdfs', 34) ***** error ... makedist ('InverseGaussian', 'k', 1, 'sdfs', 34) ***** error ... makedist ('Logistic', 'k', 1, 'sdfs', 34) ***** error ... makedist ('Loglogistic', 'k', 1, 'sdfs', 34) ***** error ... makedist ('Lognormal', 'k', 1, 'sdfs', 34) ***** error ... makedist ('Loguniform', 'k', 1, 'sdfs', 34) ***** error ... makedist ('Multinomial', 'k', 1, 'sdfs', 34) ***** error ... makedist ('Nakagami', 'mu', 1, 'sdfs', 34) ***** error ... makedist ('NegativeBinomial', 'mu', 1, 'sdfs', 34) ***** error ... makedist ('Normal', 'mu', 1, 'sdfs', 34) ***** error ... makedist ('PiecewiseLinear', 'mu', 1, 'sdfs', 34) ***** error ... makedist ('Poisson', 'mu', 1, 'sdfs', 34) ***** error ... makedist ('Rayleigh', 'mu', 1, 'sdfs', 34) ***** error ... makedist ('Rician', 'mu', 1, 'sdfs', 34) ***** error ... makedist ('Stable', 'mu', 1, 'sdfs', 34) ***** error ... makedist ('tLocationScale', 'mu', 1, 'sdfs', 34) ***** error ... makedist ('Triangular', 'mu', 1, 'sdfs', 34) ***** error ... makedist ('Uniform', 'mu', 1, 'sdfs', 34) ***** error ... makedist ('Weibull', 'mu', 1, 'sdfs', 34) 133 tests, 133 passed, 0 known failure, 0 skipped [inst/Distribution_Wrappers/fitdist.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Wrappers/fitdist.m ***** test ## fitdist returns a fitted prob.KernelDistribution object x = [2.1 0.3 1.2 -0.7 0.9 1.5 2.8 0.1 0.4 1.1 3.2 0.6 2.0 0.9 1.7]'; pd = fitdist (x, 'Kernel'); assert_equal (class (pd), 'prob.KernelDistribution'); assert_equal (pd.Kernel, 'normal'); assert_equal (pd.Bandwidth, 0.639566, 1e-4); assert_equal (pd.InputData.data, x); ***** test ## grouped kernel fit returns a cell of prob.KernelDistribution objects x = [2.1 0.3 1.2 -0.7 0.9 1.5 2.8 0.1 0.4 1.1 3.2 0.6 2.0 0.9 1.7]'; [pd, gn] = fitdist (x, 'Kernel', 'By', [ones(8, 1); 2*ones(7, 1)]); assert_equal (numel (pd), 2); assert_equal (class (pd{1}), 'prob.KernelDistribution'); assert_equal (class (pd{2}), 'prob.KernelDistribution'); ***** test x = betarnd (1, 1, 100, 1); pd = fitdist (x, 'Beta'); [phat, pci] = betafit (x); assert_equal ([pd.a, pd.b], phat); assert_equal (paramci (pd), pci); ***** test x1 = betarnd (1, 1, 100, 1); x2 = betarnd (5, 2, 100, 1); pd = fitdist ([x1; x2], 'Beta', 'By', [ones(100, 1); 2*ones(100, 1)]); [phat, pci] = betafit (x1); assert_equal ([pd{1}.a, pd{1}.b], phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = betafit (x2); assert_equal ([pd{2}.a, pd{2}.b], phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([betarnd(1, 1, 100, 1); nan(100, 1)], 'Beta', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test N = 1; x = binornd (N, 0.5, 100, 1); pd = fitdist (x, 'binomial'); [phat, pci] = binofit (sum (x), numel (x)); assert_equal ([pd.N, pd.p], [N, phat]); assert_equal (paramci (pd), [N, pci(1); N, pci(2)]); ***** test N = 3; x = binornd (N, 0.4, 100, 1); pd = fitdist (x, 'binomial', 'ntrials', N); [phat, pci] = binofit (sum (x), numel (x) * N); assert_equal ([pd.N, pd.p], [N, phat]); assert_equal (paramci (pd), [N, pci(1); N, pci(2)]); ***** test N = 1; x1 = binornd (N, 0.5, 100, 1); x2 = binornd (N, 0.7, 100, 1); pd = fitdist ([x1; x2], 'binomial', 'By', [ones(100, 1); 2*ones(100, 1)]); [phat, pci] = binofit (sum (x1), numel (x1)); assert_equal ([pd{1}.N, pd{1}.p], [N, phat]); assert_equal (paramci (pd{1}), [N, pci(1); N, pci(2)]); [phat, pci] = binofit (sum (x2), numel (x2)); assert_equal ([pd{2}.N, pd{2}.p], [N, phat]); assert_equal (paramci (pd{2}), [N, pci(1); N, pci(2)]); ***** warning ... fitdist ([binornd(1, 0.5, 100, 1); nan(100, 1)], 'binomial', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test N = 5; x1 = binornd (N, 0.5, 100, 1); x2 = binornd (N, 0.8, 100, 1); pd = fitdist ([x1; x2], 'binomial', 'ntrials', N, ... 'By', [ones(100, 1); 2*ones(100, 1)]); [phat, pci] = binofit (sum (x1), numel (x1) * N); assert_equal ([pd{1}.N, pd{1}.p], [N, phat]); assert_equal (paramci (pd{1}), [N, pci(1); N, pci(2)]); [phat, pci] = binofit (sum (x2), numel (x2) * N); assert_equal ([pd{2}.N, pd{2}.p], [N, phat]); assert_equal (paramci (pd{2}), [N, pci(1); N, pci(2)]); ***** warning ... fitdist ([binornd(5, 0.5, 100, 1); nan(100, 1)], 'binomial', 'ntrials', 5, ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test x = bisarnd (1, 1, 100, 1); pd = fitdist (x, 'BirnbaumSaunders'); [phat, pci] = bisafit (x); assert_equal ([pd.beta, pd.gamma], phat); assert_equal (paramci (pd), pci); ***** test x1 = bisarnd (1, 1, 100, 1); x2 = bisarnd (5, 2, 100, 1); pd = fitdist ([x1; x2], 'bisa', 'By', [ones(100,1); 2*ones(100,1)]); [phat, pci] = bisafit (x1); assert_equal ([pd{1}.beta, pd{1}.gamma], phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = bisafit (x2); assert_equal ([pd{2}.beta, pd{2}.gamma], phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([bisarnd(1, 1, 100, 1); nan(100, 1)], 'bisa', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test x = burrrnd (1, 2, 1, 100, 1); pd = fitdist (x, 'Burr'); [phat, pci] = burrfit (x); assert_equal ([pd.alpha, pd.c, pd.k], phat); assert_equal (paramci (pd), pci); ***** test rand ('seed', 4); # for reproducibility x1 = burrrnd (1, 2, 1, 100, 1); rand ('seed', 3); # for reproducibility x2 = burrrnd (1, 0.5, 2, 100, 1); pd = fitdist ([x1; x2], 'burr', 'By', [ones(100,1); 2*ones(100,1)]); [phat, pci] = burrfit (x1); assert_equal ([pd{1}.alpha, pd{1}.c, pd{1}.k], phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = burrfit (x2); assert_equal ([pd{2}.alpha, pd{2}.c, pd{2}.k], phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([burrrnd(1, 2, 1, 100, 1); nan(100, 1)], 'burr', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test x = exprnd (1, 100, 1); pd = fitdist (x, 'exponential'); [muhat, muci] = expfit (x); assert_equal ([pd.mu], muhat); assert_equal (paramci (pd), muci); ***** test x1 = exprnd (1, 100, 1); x2 = exprnd (5, 100, 1); pd = fitdist ([x1; x2], 'exponential', 'By', [ones(100,1); 2*ones(100,1)]); [muhat, muci] = expfit (x1); assert_equal ([pd{1}.mu], muhat); assert_equal (paramci (pd{1}), muci); [muhat, muci] = expfit (x2); assert_equal ([pd{2}.mu], muhat); assert_equal (paramci (pd{2}), muci); ***** warning ... fitdist ([exprnd(1, 100, 1); nan(100, 1)], 'exponential', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test x = evrnd (1, 1, 100, 1); pd = fitdist (x, 'ev'); [phat, pci] = evfit (x); assert_equal ([pd.mu, pd.sigma], phat); assert_equal (paramci (pd), pci); ***** test x1 = evrnd (1, 1, 100, 1); x2 = evrnd (5, 2, 100, 1); pd = fitdist ([x1; x2], 'extremevalue', 'By', [ones(100,1); 2*ones(100,1)]); [phat, pci] = evfit (x1); assert_equal ([pd{1}.mu, pd{1}.sigma], phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = evfit (x2); assert_equal ([pd{2}.mu, pd{2}.sigma], phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([evrnd(1, 1, 100, 1); nan(100, 1)], 'extremevalue', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test x = gamrnd (1, 1, 100, 1); pd = fitdist (x, 'Gamma'); [phat, pci] = gamfit (x); assert_equal ([pd.a, pd.b], phat); assert_equal (paramci (pd), pci); ***** test x1 = gamrnd (1, 1, 100, 1); x2 = gamrnd (5, 2, 100, 1); pd = fitdist ([x1; x2], 'Gamma', 'By', [ones(100,1); 2*ones(100,1)]); [phat, pci] = gamfit (x1); assert_equal ([pd{1}.a, pd{1}.b], phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = gamfit (x2); assert_equal ([pd{2}.a, pd{2}.b], phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([gamrnd(1, 1, 100, 1); nan(100, 1)], 'Gamma', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test rand ('seed', 4); # for reproducibility x = gevrnd (-0.5, 1, 2, 1000, 1); pd = fitdist (x, 'generalizedextremevalue'); [phat, pci] = gevfit (x); assert_equal ([pd.k, pd.sigma, pd.mu], phat); assert_equal (paramci (pd), pci); ***** test rand ('seed', 5); # for reproducibility x1 = gevrnd (-0.5, 1, 2, 1000, 1); rand ('seed', 9); # for reproducibility x2 = gevrnd (0, 1, -4, 1000, 1); pd = fitdist ([x1; x2], 'gev', 'By', [ones(1000,1); 2*ones(1000,1)]); [phat, pci] = gevfit (x1); assert_equal ([pd{1}.k, pd{1}.sigma, pd{1}.mu], phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = gevfit (x2); assert_equal ([pd{2}.k, pd{2}.sigma, pd{2}.mu], phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([gevrnd(-0.5, 1, 2, 1000, 1); nan(1000, 1)], 'gev', ... 'By', [ones(1000, 1); 2*ones(1000, 1)]); ***** test x = gprnd (1, 1, 1, 100, 1); pd = fitdist (x, 'GeneralizedPareto', 'theta', 1); [phat, pci] = gpfit (x - 1); assert_equal ([pd.k, pd.sigma, pd.theta], [phat, 1]); assert_equal (paramci (pd), [pci, [1; 1]]); ***** test x = gprnd (1, 1, 2, 100, 1); pd = fitdist (x, 'GeneralizedPareto', 'theta', 2); [phat, pci] = gpfit (x - 2); assert_equal ([pd.k, pd.sigma, pd.theta], [phat, 2]); assert_equal (paramci (pd), [pci, [2; 2]]); ***** test x1 = gprnd (1, 1, 1, 100, 1); x2 = gprnd (0, 2, 1, 100, 1); pd = fitdist ([x1; x2], 'gp', 'theta', 1, ... 'By', [ones(100,1); 2*ones(100,1)]); [phat, pci] = gpfit (x1 - 1); assert_equal ([pd{1}.k, pd{1}.sigma, pd{1}.theta], [phat, 1]); assert_equal (paramci (pd{1}), [pci, [1; 1]]); [phat, pci] = gpfit (x2 - 1); assert_equal ([pd{2}.k, pd{2}.sigma, pd{2}.theta], [phat, 1]); assert_equal (paramci (pd{2}), [pci, [1; 1]]); ***** warning ... fitdist ([gprnd(1, 1, 1, 100, 1); nan(100, 1)], 'gp', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test x1 = gprnd (3, 2, 2, 100, 1); x2 = gprnd (2, 3, 2, 100, 1); pd = fitdist ([x1; x2], 'GeneralizedPareto', 'theta', 2, ... 'By', [ones(100,1); 2*ones(100,1)]); [phat, pci] = gpfit (x1 - 2); assert_equal ([pd{1}.k, pd{1}.sigma, pd{1}.theta], [phat, 2]); assert_equal (paramci (pd{1}), [pci, [2; 2]]); [phat, pci] = gpfit (x2 - 2); assert_equal ([pd{2}.k, pd{2}.sigma, pd{2}.theta], [phat, 2]); assert_equal (paramci (pd{2}), [pci, [2; 2]]); ***** warning ... fitdist ([gprnd(3, 2, 2, 100, 1); nan(100, 1)], 'gp', 'theta', 2, ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test x = hnrnd (0, 1, 100, 1); pd = fitdist (x, 'HalfNormal'); [phat, pci] = hnfit (x, 0); assert_equal ([pd.mu, pd.sigma], phat); assert_equal (paramci (pd), pci); ***** test x = hnrnd (1, 1, 100, 1); pd = fitdist (x, 'HalfNormal', 'mu', 1); [phat, pci] = hnfit (x, 1); assert_equal ([pd.mu, pd.sigma], phat); assert_equal (paramci (pd), pci); ***** test x1 = hnrnd (0, 1, 100, 1); x2 = hnrnd (0, 2, 100, 1); pd = fitdist ([x1; x2], 'HalfNormal', 'By', [ones(100,1); 2*ones(100,1)]); [phat, pci] = hnfit (x1, 0); assert_equal ([pd{1}.mu, pd{1}.sigma], phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = hnfit (x2, 0); assert_equal ([pd{2}.mu, pd{2}.sigma], phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([hnrnd(0, 1, 100, 1); nan(100, 1)], 'HalfNormal', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test x1 = hnrnd (2, 1, 100, 1); x2 = hnrnd (2, 2, 100, 1); pd = fitdist ([x1; x2], 'HalfNormal', 'mu', 2, ... 'By', [ones(100,1); 2*ones(100,1)]); [phat, pci] = hnfit (x1, 2); assert_equal ([pd{1}.mu, pd{1}.sigma], phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = hnfit (x2, 2); assert_equal ([pd{2}.mu, pd{2}.sigma], phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([hnrnd(2, 1, 100, 1); nan(100, 1)], 'HalfNormal', 'mu', 2, ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test x = invgrnd (1, 1, 100, 1); pd = fitdist (x, 'InverseGaussian'); [phat, pci] = invgfit (x); assert_equal ([pd.mu, pd.lambda], phat); assert_equal (paramci (pd), pci); ***** test x1 = invgrnd (1, 1, 100, 1); x2 = invgrnd (5, 2, 100, 1); pd = fitdist ([x1; x2], 'InverseGaussian', 'By', [ones(100,1); 2*ones(100,1)]); [phat, pci] = invgfit (x1); assert_equal ([pd{1}.mu, pd{1}.lambda], phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = invgfit (x2); assert_equal ([pd{2}.mu, pd{2}.lambda], phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([invgrnd(1, 1, 100, 1); nan(100, 1)], 'InverseGaussian', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test x = logirnd (1, 1, 100, 1); pd = fitdist (x, 'logistic'); [phat, pci] = logifit (x); assert_equal ([pd.mu, pd.sigma], phat); assert_equal (paramci (pd), pci); ***** test x1 = logirnd (1, 1, 100, 1); x2 = logirnd (5, 2, 100, 1); pd = fitdist ([x1; x2], 'logistic', 'By', [ones(100,1); 2*ones(100,1)]); [phat, pci] = logifit (x1); assert_equal ([pd{1}.mu, pd{1}.sigma], phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = logifit (x2); assert_equal ([pd{2}.mu, pd{2}.sigma], phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([logirnd(1, 1, 100, 1); nan(100, 1)], 'logistic', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test x = loglrnd (1, 1, 100, 1); pd = fitdist (x, 'loglogistic'); [phat, pci] = loglfit (x); assert_equal ([pd.mu, pd.sigma], phat); assert_equal (paramci (pd), pci); ***** test x1 = loglrnd (1, 1, 100, 1); x2 = loglrnd (5, 2, 100, 1); pd = fitdist ([x1; x2], 'loglogistic', 'By', [ones(100,1); 2*ones(100,1)]); [phat, pci] = loglfit (x1); assert_equal ([pd{1}.mu, pd{1}.sigma], phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = loglfit (x2); assert_equal ([pd{2}.mu, pd{2}.sigma], phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([loglrnd(1, 1, 100, 1); nan(100, 1)], 'loglogistic', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test x = lognrnd (1, 1, 100, 1); pd = fitdist (x, 'lognormal'); [phat, pci] = lognfit (x); assert_equal ([pd.mu, pd.sigma], phat); assert_equal (paramci (pd), pci); ***** test x1 = lognrnd (1, 1, 100, 1); x2 = lognrnd (5, 2, 100, 1); pd = fitdist ([x1; x2], 'lognormal', 'By', [ones(100,1); 2*ones(100,1)]); [phat, pci] = lognfit (x1); assert_equal ([pd{1}.mu, pd{1}.sigma], phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = lognfit (x2); assert_equal ([pd{2}.mu, pd{2}.sigma], phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([lognrnd(1, 1, 100, 1); nan(100, 1)], 'lognormal', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test x = nakarnd (2, 0.5, 100, 1); pd = fitdist (x, 'Nakagami'); [phat, pci] = nakafit (x); assert_equal ([pd.mu, pd.omega], phat); assert_equal (paramci (pd), pci); ***** test x1 = nakarnd (2, 0.5, 100, 1); x2 = nakarnd (5, 0.8, 100, 1); pd = fitdist ([x1; x2], 'Nakagami', 'By', [ones(100,1); 2*ones(100,1)]); [phat, pci] = nakafit (x1); assert_equal ([pd{1}.mu, pd{1}.omega], phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = nakafit (x2); assert_equal ([pd{2}.mu, pd{2}.omega], phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([nakarnd(2, 0.5, 100, 1); nan(100, 1)], 'Nakagami', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test randp ('seed', 123); randg ('seed', 321); x = nbinrnd (2, 0.5, 100, 1); pd = fitdist (x, 'negativebinomial'); [phat, pci] = nbinfit (x); assert_equal ([pd.R, pd.P], phat); assert_equal (paramci (pd), pci); ***** test randp ('seed', 345); randg ('seed', 543); x1 = nbinrnd (2, 0.5, 100, 1); randp ('seed', 432); randg ('seed', 234); x2 = nbinrnd (5, 0.8, 100, 1); pd = fitdist ([x1; x2], 'nbin', 'By', [ones(100,1); 2*ones(100,1)]); [phat, pci] = nbinfit (x1); assert_equal ([pd{1}.R, pd{1}.P], phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = nbinfit (x2); assert_equal ([pd{2}.R, pd{2}.P], phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([nbinrnd(2, 0.5, 100, 1); nan(100, 1)], 'nbin', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test x = normrnd (1, 1, 100, 1); pd = fitdist (x, 'normal'); [muhat, sigmahat, muci, sigmaci] = normfit (x); assert_equal ([pd.mu, pd.sigma], [muhat, sigmahat]); assert_equal (paramci (pd), [muci, sigmaci]); ***** test x1 = normrnd (1, 1, 100, 1); x2 = normrnd (5, 2, 100, 1); pd = fitdist ([x1; x2], 'normal', 'By', [ones(100,1); 2*ones(100,1)]); [muhat, sigmahat, muci, sigmaci] = normfit (x1); assert_equal ([pd{1}.mu, pd{1}.sigma], [muhat, sigmahat]); assert_equal (paramci (pd{1}), [muci, sigmaci]); [muhat, sigmahat, muci, sigmaci] = normfit (x2); assert_equal ([pd{2}.mu, pd{2}.sigma], [muhat, sigmahat]); assert_equal (paramci (pd{2}), [muci, sigmaci]); ***** warning ... fitdist ([normrnd(1, 1, 100, 1); nan(100, 1)], 'normal', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test x = poissrnd (1, 100, 1); pd = fitdist (x, 'poisson'); [phat, pci] = poissfit (x); assert_equal (pd.lambda, phat); assert_equal (paramci (pd), pci); ***** test x1 = poissrnd (1, 100, 1); x2 = poissrnd (5, 100, 1); pd = fitdist ([x1; x2], 'poisson', 'By', [ones(100,1); 2*ones(100,1)]); [phat, pci] = poissfit (x1); assert_equal (pd{1}.lambda, phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = poissfit (x2); assert_equal (pd{2}.lambda, phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([poissrnd(1, 100, 1); nan(100, 1)], 'poisson', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test x = raylrnd (1, 100, 1); pd = fitdist (x, 'rayleigh'); [phat, pci] = raylfit (x); assert_equal (pd.B, phat); assert_equal (paramci (pd), pci); ***** test x1 = raylrnd (1, 100, 1); x2 = raylrnd (5, 100, 1); pd = fitdist ([x1; x2], 'rayleigh', 'By', [ones(100,1); 2*ones(100,1)]); [phat, pci] = raylfit (x1); assert_equal (pd{1}.B, phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = raylfit (x2); assert_equal (pd{2}.B, phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([raylrnd(1, 100, 1); nan(100, 1)], 'rayleigh', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test x = ricernd (1, 1, 100, 1); pd = fitdist (x, 'rician'); [phat, pci] = ricefit (x); assert_equal ([pd.s, pd.sigma], phat); assert_equal (paramci (pd), pci); ***** test x1 = ricernd (1, 1, 100, 1); x2 = ricernd (5, 2, 100, 1); pd = fitdist ([x1; x2], 'rician', 'By', [ones(100,1); 2*ones(100,1)]); [phat, pci] = ricefit (x1); assert_equal ([pd{1}.s, pd{1}.sigma], phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = ricefit (x2); assert_equal ([pd{2}.s, pd{2}.sigma], phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([ricernd(1, 1, 100, 1); nan(100, 1)], 'rician', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test ## fitdist returns a fitted prob.StableDistribution object rand ("seed", 2718); randn ("seed", 2718); x = stblrnd (1.5, 0.5, 2, 1, 150, 1); pd = fitdist (x, 'Stable'); assert_equal (class (pd), 'prob.StableDistribution'); assert_equal (! any (pd.ParameterIsFixed, 'all'), true); assert_equal (pd.alpha, 1.5, 0.4); assert_equal (pd.gam, 2, 0.5); ***** test x = tlsrnd (0, 1, 1, 100, 1); pd = fitdist (x, 'tlocationscale'); [phat, pci] = tlsfit (x); assert_equal ([pd.mu, pd.sigma, pd.nu], phat); assert_equal (paramci (pd), pci); ***** test x1 = tlsrnd (0, 1, 1, 100, 1); x2 = tlsrnd (5, 2, 1, 100, 1); pd = fitdist ([x1; x2], 'tlocationscale', 'By', [ones(100,1); 2*ones(100,1)]); [phat, pci] = tlsfit (x1); assert_equal ([pd{1}.mu, pd{1}.sigma, pd{1}.nu], phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = tlsfit (x2); assert_equal ([pd{2}.mu, pd{2}.sigma, pd{2}.nu], phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([tlsrnd(0, 1, 1, 100, 1); nan(100, 1)], 'tlocationscale', ... 'By', [ones(100, 1); 2*ones(100, 1)]); ***** test x = [1 2 3 4 5]; pd = fitdist (x, 'weibull'); [phat, pci] = wblfit (x); assert_equal ([pd.A, pd.B], phat); assert_equal (paramci (pd), pci); ***** test x = [1 2 3 4 5 6 7 8 9 10]; pd = fitdist (x, 'weibull', 'By', [1 1 1 1 1 2 2 2 2 2]); [phat, pci] = wblfit (x(1:5)); assert_equal ([pd{1}.A, pd{1}.B], phat); assert_equal (paramci (pd{1}), pci); [phat, pci] = wblfit (x(6:10)); assert_equal ([pd{2}.A, pd{2}.B], phat); assert_equal (paramci (pd{2}), pci); ***** warning ... fitdist ([1 2 3 4 5 NaN NaN NaN NaN NaN], 'weibull', 'By', [1 1 1 1 1 2 2 2 2 2]); ***** error fitdist (1) ***** error fitdist (1, ['as';'sd']) ***** error fitdist (1, 'some') ***** error ... fitdist (ones (2), 'normal') ***** error ... fitdist ([i, 2, 3], 'normal') ***** error ... fitdist (['a', 's', 'd'], 'normal') ***** error ... fitdist ([1, 2, 3], 'normal', 'By') ***** error ... fitdist ([1, 2, 3], 'normal', 'By', [1, 2]) ***** error ... fitdist ([1, 2, 3], 'normal', 'Censoring', [1, 2]) ***** error ... fitdist ([1, 2, 3], 'normal', 'frequency', [1, 2]) ***** error ... fitdist ([1, 2, 3], 'negativebinomial', 'frequency', [1, -2, 3]) ***** error ... fitdist ([1, 2, 3], 'normal', 'alpha', [1, 2]) ***** error ... fitdist ([1, 2, 3], 'normal', 'alpha', i) ***** error ... fitdist ([1, 2, 3], 'normal', 'alpha', -0.5) ***** error ... fitdist ([1, 2, 3], 'normal', 'alpha', 1.5) ***** error ... fitdist ([1, 2, 3], 'normal', 'ntrials', [1, 2]) ***** error ... fitdist ([1, 2, 3], 'normal', 'ntrials', 0) ***** error ... fitdist ([1, 2, 3], 'normal', 'options', 0) ***** error ... fitdist ([1, 2, 3], 'normal', 'options', struct ('options', 1)) ***** error ... fitdist ([1, 2, 3]', 'kernel', 'Censoring', [1, 0, 0]'); ***** error ... fitdist ([1, 2, 3]', 'Stable', 'Censoring', [1, 0, 0]'); ***** error ... fitdist ([1, 2, 3], 'normal', 'param', struct ('options', 1)) ***** error ... fitdist (nan (100,1), 'normal'); ***** error ... [pdca, gn, gl] = fitdist ([1, 2, 3], 'normal'); ***** error ... fitdist ([1, 2, 3], 'generalizedpareto', 'theta', 2); ***** error ... fitdist ([1, 2, 3], 'halfnormal', 'mu', 2); 104 tests, 104 passed, 0 known failure, 0 skipped [inst/Distribution_Wrappers/mlecov.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Wrappers/mlecov.m ***** demo ## Asymptotic covariance matrix of the ML estimates for a normal fit. x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; phat = mle (x); acov = mlecov (phat, x, 'pdf', @(x, mu, sigma) normpdf (x, mu, sigma)) ***** test x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; phat = [mean(x), std(x, 1)]; nll = @(p, data, cens, freq) -sum (log (normpdf (data, p(1), p(2)))); acov = mlecov (phat, x, 'nloglf', nll); assert_equal (acov, [0.0887673606073251, 0; 0, 0.0443836789388774], 1e-6); ***** test x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; phat = [3.5, 1.0]; nll = @(p, data, cens, freq) -sum (log (normpdf (data, p(1), p(2)))); acov = mlecov (phat, x, 'nloglf', nll); ref = [0.0841894975321553, 0.00570776282157731; ... 0.00570776282157731, 0.0380517511049636]; assert_equal (acov, ref, 1e-6); ***** test x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; phat = gamfit (x); nll = @(p, data, cens, freq) -sum (log (gampdf (data, p(1), p(2)))); acov = mlecov (phat, x, 'nloglf', nll); ref = [17.6711714212941, -0.553235139352906; ... -0.553235139352906, 0.0181745610037496]; assert_equal (acov, ref, 5e-4); ***** test x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; f = [1, 2, 1, 1, 3, 1, 2, 1, 1, 1, 2, 1]; phat = [mean(x), std(x, 1)]; nll = @(p, data, cens, freq) -sum (freq .* log (normpdf (data, p(1), p(2)))); acov = mlecov (phat, x, 'nloglf', nll, 'Frequency', f); ref = [0.0630373869314514, -0.00427967204059965; ... -0.00427967204059965, 0.0484445550668851]; assert_equal (acov, ref, 1e-6); ***** test x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; c = [0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0]; phat = [mean(x), std(x, 1)]; nll = @(p, data, cens, freq) -sum ((1 - cens) .* ... log (normpdf (data, p(1), p(2))) + ... cens .* log (1 - normcdf (data, p(1), p(2)))); acov = mlecov (phat, x, 'nloglf', nll, 'Censoring', c); ref = [0.100361972376949, -0.0148199117431384; ... -0.0148199117431384, 0.054254671056408]; assert_equal (acov, ref, 1e-6); ***** test x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; phat = [mean(x), std(x, 1)]; a_pdf = mlecov (phat, x, 'pdf', @(x, mu, s) normpdf (x, mu, s)); a_logpdf = mlecov (phat, x, 'logpdf', @(x, mu, s) log (normpdf (x, mu, s))); a_nloglf = mlecov (phat, x, 'nloglf', ... @(p, d, c, f) -sum (log (normpdf (d, p(1), p(2))))); assert_equal (a_pdf, a_nloglf, 1e-10); assert_equal (a_logpdf, a_nloglf, 1e-10); assert_equal (a_pdf, [0.0887673606073251, 0; 0, 0.0443836789388774], 1e-6); ***** test x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; acov = mlecov (mean (x), x, 'pdf', @(x, mu) exppdf (x, mu)); assert_equal (acov, 0.977552156166645, 1e-6); ***** test x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; c = [0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0]; phat = [mean(x), std(x, 1)]; acov = mlecov (phat, x, 'pdf', @(x, mu, s) normpdf (x, mu, s), ... 'cdf', @(x, mu, s) normcdf (x, mu, s), 'Censoring', c); ref = [0.100361972376949, -0.0148199117431384; ... -0.0148199117431384, 0.054254671056408]; assert_equal (acov, ref, 1e-6); ***** test x = [2.1, 3.4, 1.9, 5.2, 4.1, 2.8, 3.3, 4.7, 2.2, 3.9, 3.0, 4.5]; phat = [mean(x), std(x, 1)]; nll = @(p, data, cens, freq) -sum (log (normpdf (data, p(1), p(2)))); acov = mlecov (phat, x, 'nloglf', nll, ... 'Options', struct ('DerivStep', 1e-4)); assert_equal (acov, [0.0887673606073251, 0; 0, 0.0443836789388774], 1e-5); ***** warning ... mlecov (1, [1, 2, 3, 4, 5], 'nloglf', @(p, d, c, f) -sum (p(1) .* d)); ***** test warning ("off", "all", "local"); acov = mlecov (1, [1, 2, 3, 4, 5], 'nloglf', @(p, d, c, f) -sum (p(1) .* d)); assert_equal (all (isnan (acov), 'all'), true); ***** error mlecov (1, [1, 2, 3]) ***** error ... mlecov ([1, 2; 3, 4], [1, 2, 3], 'pdf', @(x, a) x) ***** error ... mlecov ([1, 2i], [1, 2, 3], 'pdf', @(x, a, b) x) ***** error ... mlecov ([1, 2], ones (2, 2), 'pdf', @(x, a, b) x) ***** error ... mlecov ([1, 2], [1, 2, 3], 'pdf') ***** error ... mlecov ([1, 2], [1, 2, 3], 5, @sin) ***** error ... mlecov ([1, 2], [1, 2, 3], 'Frequency', [1, 1, 1]) ***** error ... mlecov ([1, 2], [1, 2, 3], 'pdf', @sin, 'nloglf', @cos) ***** error ... mlecov ([1, 2], [1, 2, 3], 'pdf', 5) ***** error ... mlecov ([1, 2], [1, 2, 3], 'nloglf', 'text') ***** error ... mlecov ([1, 2], [1, 2, 3], 'pdf', @sin, 'bogus', 1) ***** error ... mlecov ([1, 2], [1, 2, 3], 'nloglf', @(varargin) 1, 'Frequency', [1, 1]) ***** error ... mlecov ([1, 2], [1, 2, 3], 'nloglf', @(varargin) 1, 'Frequency', [1, 0.5, 1]) ***** error ... mlecov ([1, 2], [1, 2, 3], 'nloglf', @(varargin) 1, 'Censoring', [1, 0]) ***** error ... mlecov ([1, 2], [1, 2, 3], 'pdf', @(x, a, b) x, 'Censoring', [1, 0, 0]) ***** error ... mlecov ([1, 2], [1, 2, 3], 'logpdf', @(x, a, b) x, 'Censoring', [1, 0, 0]) ***** error ... mlecov ([1, 2], [1, 2, 3], 'nloglf', @(varargin) 1, 'Options', 5) ***** error ... mlecov ([1, 2], [1, 2, 3], 'nloglf', @(varargin) 1, ... 'Options', struct ('DerivStep', -1)) 29 tests, 29 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/nanmedian.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/nanmedian.m ***** demo ## Find the column medians for a matrix with missing values. x = magic (3); x([1, 6:9]) = NaN m = nanmedian (x) ***** demo ## Find the median of all elements, ignoring missing values. x = reshape (1:30, [2, 5, 3]); x([10:12, 25]) = NaN m = nanmedian (x, 'all') ***** assert_equal (nanmedian ([]), NaN) ***** assert_equal (nanmedian (zeros (0, 3)), [NaN, NaN, NaN]) ***** assert_equal (nanmedian (zeros (3, 0)), zeros (1, 0)) ***** assert_equal (nanmedian ([], 1), zeros (1, 0)) ***** assert_equal (nanmedian ([], 2), zeros (0, 1)) ***** assert_equal (size (nanmedian (ones (2, 0, 3, 2), 2)), [2, 1, 3, 2]) ***** assert_equal (nanmedian (ones (2, 0, 3, 2), 'all'), NaN) ***** assert_equal (size (nanmedian (ones (2, 0, 3, 2), [1, 2])), [1, 1, 3, 2]) ***** assert_equal (nanmedian (NaN), NaN) ***** assert_equal (nanmedian (5), 5) ***** assert_equal (nanmedian ([2, 4, NaN, 8]), 4) ***** assert_equal (nanmedian ([1 2 NaN; 4 NaN 6; 7 8 9; 10 11 12]), [5.5, 8, 9]) ***** assert_equal (nanmedian ([1 2 NaN; 4 NaN 6; 7 8 9; 10 11 12], 2), ... [1.5; 5; 8; 11]) ***** assert_equal (nanmedian ([1 NaN; NaN NaN; 3 NaN]), [2, NaN]) ***** assert_equal (nanmedian (reshape (1:12, [2, 3, 2])(:)), 6.5) ***** test x = reshape (1:24, [2, 4, 3]); x([5:6, 20]) = NaN; assert_equal (nanmedian (x, 'all'), nanmedian (x(! isnan (x))(:))); assert_equal (nanmedian (x, [1, 2, 3]), nanmedian (x, 'all')); ***** test x = magic (4); x([1, 6, 11, 16]) = NaN; assert_equal (nanmedian (x, 2), [3; 8; 9; 14]); ***** error nanmedian () ***** error nanmedian ({3}) ***** error nanmedian (ones (3), 0) ***** error nanmedian (ones (3), 1.5) ***** error ... nanmedian (ones (3, 3, 3), [2, 2, 3]) 22 tests, 22 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/partialcorr.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/partialcorr.m ***** demo ## Partial correlations among four variables, each pair adjusted for the ## other two. x = [0.42 1.30 -0.85 0.11; 1.15 -0.47 0.33 1.82; -0.98 0.55 1.21 -0.34; ... 0.63 2.10 -0.19 0.48; 1.88 -1.02 0.74 0.05; -0.31 0.86 -1.44 1.29; ... 0.77 0.14 0.58 -0.71; -1.52 1.77 0.02 0.94; 0.29 -0.63 1.36 0.37]; rho = partialcorr (x) ***** shared D, X, Y, Z D = [ 0.42 1.30 -0.85 0.11 2.04 1.15 -0.47 0.33 1.82 -0.62 -0.98 0.55 1.21 -0.34 0.77 0.63 2.10 -0.19 0.48 -1.15 1.88 -1.02 0.74 0.05 0.39 -0.31 0.86 -1.44 1.29 0.92 0.77 0.14 0.58 -0.71 1.63 -1.52 1.77 0.02 0.94 -0.28 0.29 -0.63 1.36 0.37 0.51 2.01 0.48 -0.77 -1.08 0.14 -0.44 1.05 0.91 0.66 -0.83 0.90 -0.29 -0.36 1.47 1.22]; X = D(:,1:2); Y = D(:,3); Z = D(:,4:5); ***** test rho = partialcorr (D); assert_equal (diag (rho), ones (5, 1), 1e-12); assert_equal (rho, rho', 1e-12); assert_equal (rho(1,2), -0.8399, 1e-4); assert_equal (rho(1,5), -0.6172, 1e-4); assert_equal (rho(3,4), -0.6763, 1e-4); ***** test [rho, p] = partialcorr (D); assert_equal (diag (p), zeros (5, 1), 1e-12); assert_equal (p, p', 1e-12); assert_equal (p(1,2), 0.0046, 1e-4); assert_equal (p(1,5), 0.0766, 1e-4); ***** test [rho, p] = partialcorr (X, Z); assert_equal (rho, [1 -0.5888; -0.5888 1], 1e-4); assert_equal (p, [0 0.0733; 0.0733 0], 1e-4); ***** test [r, p] = partialcorr (X, Y, Z); assert_equal (r, [-0.2073; -0.5273], 1e-4); assert_equal (p, [0.5656; 0.1173], 1e-4); ***** test r = partialcorr (X, Y, Z, 'Type', 'Spearman'); assert_equal (r, [-0.3079; -0.4984], 1e-4); ***** test [~, pr] = partialcorr (X, Y, Z, 'Tail', 'right'); [~, pl] = partialcorr (X, Y, Z, 'Tail', 'left'); assert_equal (pr, [0.7172; 0.9414], 1e-4); assert_equal (pl, [0.2828; 0.0586], 1e-4); ***** test DN = D; DN(3,2) = NaN; assert_equal (all (isnan (partialcorr (DN)), 'all'), true); rc = partialcorr (DN, 'Rows', 'complete'); assert_equal (rc(1,2), -0.8311, 1e-4); assert_equal (rc(4,5), -0.6163, 1e-4); ***** test XN = X; XN(3,1) = NaN; rc = partialcorr (XN, Y, Z, 'Rows', 'complete'); [rp, pp] = partialcorr (XN, Y, Z, 'Rows', 'pairwise'); assert_equal (rc, [-0.0116; -0.5849], 1e-4); assert_equal (rp, [-0.0116; -0.5273], 1e-4); assert_equal (pp, [0.9764; 0.1173], 1e-4); ***** test X = [1 2; 3 4; 5 5]; Z = [2; 4; 6]; [rho, pval] = partialcorr (X, Z); assert_equal (isnan (rho(1,:)), [true, true]); assert_equal (isnan (rho(:,1)), [true; true]); assert_equal (rho(2,2), 1); assert_equal (all (isnan (pval(:))), true); ***** test Z = [1; 2; 3; 4; 5; 6]; X = [Z + 1e-12 * [1; -2; 1; 0; 0; 0], [3; 1; 4; 1; 5; 9]]; rho = partialcorr (X, Z); assert_equal (isnan (rho(1,2)), false); ***** test Z = [1; 2; 3; 4; 5; 6]; X = [Z + 1e-16 * [1; -2; 1; 0; 0; 0], [3; 1; 4; 1; 5; 9]]; rho = partialcorr (X, Z); assert_equal (isnan (rho(1,2)), true); ***** test Z = [1; 2; 3; 4; 5; 6]; v = 1e-3 * [1; -2; 1; 0; 0; 0]; Y = [3; 1; 4; 1; 5; 9]; assert_equal (isnan (partialcorr ([Z + v, Y], Z)(1,2)), false); assert_equal (isnan (partialcorr ([1e12 + Z + v, Y], Z)(1,2)), true); ***** test t = linspace (-1, 1, 50)'; X = [sin(3*t) + 0.2*cos(11*t), cos(5*t) - 0.1*sin(13*t)]; r0 = partialcorr (X, [t, t.^2]); rt = partialcorr (X, [1e8 + t, t.^2]); assert_equal (rt(1,2), r0(1,2), 1e-8); ***** test t = linspace (-1, 1, 50)'; X = [sin(3*t) + 0.2*cos(11*t), cos(5*t) - 0.1*sin(13*t)]; r0 = partialcorr (X, [t, t.^2]); rs = partialcorr (X, [t, 1e-16 * t.^2]); assert_equal (rs(1,2), r0(1,2), 1e-12); ***** test t = linspace (-1, 1, 50)'; X = [sin(3*t) + 0.2*cos(11*t), cos(5*t) - 0.1*sin(13*t)]; Z = [t, t.^2]; r0 = partialcorr (X, Z); rs = partialcorr ([1e200 * X(:,1), 1e-200 * X(:,2)], Z); assert_equal (rs(1,2), r0(1,2), 1e-12); ***** error ... partialcorr (ones (5), ones (5), ones (5), ones (5)) ***** error ... partialcorr (ones (10, 3), 'Type', 'Kendall') ***** error partialcorr (ones (10, 3), 'Type', 'foo') ***** error partialcorr (ones (10, 3), 'Rows', 'foo') ***** error ... partialcorr (ones (10, 2), ones (8, 1), ones (10, 2)) 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/nanmin.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/nanmin.m ***** demo ## Find the column minimum values and their indices ## for matrix data with missing values. x = magic (3); x([1, 6:9]) = NaN [y, ind] = nanmin (x) ***** demo ## Find the minimum of all the values in an array, ignoring missing values. ## Create a 2-by-5-by-3 array x with some missing values. x = reshape (1:30, [2, 5, 3]); x([10:12, 25]) = NaN ## Find the minimum of the elements of x. y = nanmin (x, [], 'all') ***** assert_equal (nanmin ([]), []) ***** assert_equal (nanmin (zeros (0, 3)), zeros (0, 3)) ***** assert_equal (nanmin (zeros (3, 0)), zeros (1, 0)) ***** assert_equal (size (nanmin (ones (2, 0, 3, 2))), [1, 0, 3, 2]) ***** assert_equal (nanmin ([], [], 1), []) ***** assert_equal (nanmin ([], [], 2), []) ***** assert_equal (size (nanmin (ones (2, 0, 3, 2), [], 1)), [1, 0, 3, 2]) ***** assert_equal (size (nanmin (ones (2, 0, 3, 2), [], 2)), [2, 0, 3, 2]) ***** assert_equal (size (nanmin (ones (2, 0, 3, 2), [], 'all')), [0, 1]) ***** assert_equal (size (nanmin (ones (2, 0, 3, 2), [], [1, 2])), [0, 1, 3, 2]) ***** assert_equal (nanmin ([NaN, NaN, NaN]), NaN) ***** assert_equal (nanmin ([2, 4, NaN, 7]), 2) ***** assert_equal (nanmin ([2, 4, NaN, -Inf]), -Inf) ***** assert_equal (nanmin ([1, NaN, 3; NaN, 5, 6; 7, 8, NaN]), [1, 5, 3]) ***** assert_equal (nanmin ([1, NaN, 3; NaN, 5, 6; 7, 8, NaN]'), [1, 5, 7]) ***** assert_equal (nanmin (single ([1, NaN, 3; NaN, 5, 6; 7, 8, NaN])), single ([1, 5, 3])) ***** shared x, y x(:,:,1) = [1.77, -0.005, NaN, -2.95; NaN, 0.34, NaN, 0.19]; x(:,:,2) = [1.77, -0.005, NaN, -2.95; NaN, 0.34, NaN, 0.19] + 5; y = x; y(2,3,1) = 0.51; ***** assert_equal (nanmin (x, [], [1, 2])(:), [-2.95; 2.05]) ***** assert_equal (nanmin (x, [], [1, 3])(:), [1.77; -0.005; NaN; -2.95]) ***** assert_equal (nanmin (x, [], [2, 3])(:), [-2.95; 0.19]) ***** assert_equal (nanmin (x, [], [1, 2, 3]), -2.95) ***** assert_equal (nanmin (x, [], 'all'), -2.95) ***** assert_equal (nanmin (y, [], [1, 3])(:), [1.77; -0.005; 0.51; -2.95]) ***** assert_equal (nanmin (x(1,:,1), x(2,:,1)), [1.77, -0.005, NaN, -2.95]) ***** assert_equal (nanmin (x(1,:,2), x(2,:,2)), [6.77, 4.995, NaN, 2.05]) ***** assert_equal (nanmin (y(1,:,1), y(2,:,1)), [1.77, -0.005, 0.51, -2.95]) ***** assert_equal (nanmin (y(1,:,2), y(2,:,2)), [6.77, 4.995, NaN, 2.05]) ***** test xx = repmat ([1:20;6:25], [5 2 6 3]); assert_equal (size (nanmin (xx, [], [3, 2])), [10, 1, 1, 3]); assert_equal (size (nanmin (xx, [], [1, 2])), [1, 1, 6, 3]); assert_equal (size (nanmin (xx, [], [1, 2, 4])), [1, 1, 6]); assert_equal (size (nanmin (xx, [], [1, 4, 3])), [1, 40]); assert_equal (size (nanmin (xx, [], [1, 2, 3, 4])), [1, 1]); ***** assert_equal (nanmin (ones (2), [], 3), ones (2, 2)) ***** assert_equal (nanmin (ones (2, 2, 2), [], 99), ones (2, 2, 2)) ***** assert_equal (nanmin (magic (3), [], 3), magic (3)) ***** assert_equal (nanmin (magic (3), [], [1, 3]), [3, 1, 2]) ***** assert_equal (nanmin (magic (3), [], [1, 99]), [3, 1, 2]) ***** assert_equal (nanmin (ones (2), 3), ones (2,2)) ***** error ... nanmin (y, [], [1, 1, 2]) ***** error ... [v, idx] = nanmin (x, y, [1 2]) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/ecdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/ecdf.m ***** demo rande ('state', 42); y = exprnd (10, 50, 1); ## random failure times are exponential(10) d = exprnd (20, 50, 1); ## drop-out times are exponential(20) t = min (y, d); ## we observe the minimum of these times censored = (y > d); ## we also observe whether the subject failed ## Calculate and plot the empirical cdf and confidence bounds [f, x, flo, fup] = ecdf (t, 'censoring', censored); stairs (x, f); hold on; stairs (x, flo, 'r:'); stairs (x, fup, 'r:'); ## Superimpose a plot of the known true cdf xx = 0:.1:max (t); yy = 1 - exp (-xx / 10); plot (xx, yy, 'g-'); hold off; ***** demo rande ('state', 42); R = wblrnd (100, 2, 100, 1); ecdf (R, 'Function', 'survivor', 'Alpha', 0.01, 'Bounds', 'on'); hold on x = 1:1:250; wblsurv = 1 - cdf ('weibull', x, 100, 2); plot (x, wblsurv, 'g-', 'LineWidth', 2) legend ('Empirical survivor function', 'Lower confidence bound', ... 'Upper confidence bound', 'Weibull survivor function', ... 'Location', 'northeast'); hold off ***** error ecdf (); ***** error ecdf (randi (15,2)); ***** error ecdf ([3,2,4,3+2i,5]); ***** error kstest ([2,3,4,5,6],'tail'); ***** error kstest ([2,3,4,5,6],'tail', 'whatever'); ***** error kstest ([2,3,4,5,6],'function', ''); ***** error kstest ([2,3,4,5,6],'badoption', 0.51); ***** error kstest ([2,3,4,5,6],'tail', 0); ***** error kstest ([2,3,4,5,6],'alpha', 0); ***** error kstest ([2,3,4,5,6],'alpha', NaN); ***** error kstest ([NaN,NaN,NaN,NaN,NaN],'tail', 'unequal'); ***** error kstest ([2,3,4,5,6],'alpha', 0.05, 'CDF', [2,3,4;1,3,4;1,2,1]); ***** test hf = figure ('visible', 'off'); unwind_protect x = [2, 3, 4, 3, 5, 4, 6, 5, 8, 3, 7, 8, 9, 0]; [F, x, Flo, Fup] = ecdf (x); F_out = [0; 0.0714; 0.1429; 0.3571; 0.5; 0.6429; 0.7143; 0.7857; 0.9286; 1]; assert_equal (F, F_out, ones (10,1) * 1e-4); x_out = [0 0 2 3 4 5 6 7 8 9]'; assert_equal (x, x_out); Flo_out = [NaN, 0, 0, 0.1061, 0.2381, 0.3919, 0.4776, 0.5708, 0.7937, NaN]'; assert_equal (Flo, Flo_out, ones (10,1) * 1e-4); Fup_out = [NaN, 0.2063, 0.3262, 0.6081, 0.7619, 0.8939, 0.9509, 1, 1, NaN]'; assert_equal (Fup, Fup_out, ones (10,1) * 1e-4); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect x = [2, 3, 4, 3, 5, 4, 6, 5, 8, 3, 7, 8, 9, 0]; ecdf (x); unwind_protect_cleanup close (hf); end_unwind_protect 14 tests, 14 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/nancov.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/nancov.m ***** demo ## Covariance matrix of a data set with missing values (complete-case). x = [1 2 3; 4 5 NaN; 7 NaN 9; 10 11 12; NaN 14 15] c = nancov (x) ***** demo ## The same data set using pairwise deletion of missing values. x = [1 2 3; 4 5 NaN; 7 NaN 9; 10 11 12; NaN 14 15] c = nancov (x, 'pairwise') ***** assert_equal (nancov ([1 2 3; 4 5 NaN; 7 NaN 9; 10 11 12; NaN 14 15]), ... 40.5 * ones (3)) ***** assert_equal (nancov ([1 2 3; 4 5 NaN; 7 NaN 9; 10 11 12; NaN 14 15], 1), ... 20.25 * ones (3)) ***** assert_equal (nancov ([1 2 3; 4 5 NaN; 7 NaN 9; 10 11 12; NaN 14 15], ... 'pairwise'), [15, 21, 21; 21, 30, 39; 21, 39, 26.25]) ***** assert_equal (nancov ([1 2 3; 4 5 NaN; 7 NaN 9; 10 11 12; NaN 14 15], 1, ... 'pairwise'), [11.25, 14, 14; 14, 22.5, 26; 14, 26, 19.6875]) ***** assert_equal (nancov ([1 2 3 NaN 5]', [2 NaN 6 8 10]'), [4, 8; 8, 16]) ***** assert_equal (nancov ([1 2 3 4 5]'), 2.5) ***** assert_equal (nancov (5), 0) ***** assert_equal (nancov (NaN (3, 2)), NaN (2, 2)) ***** assert_equal (nancov ([], []), NaN (2, 2)) ***** error nancov () ***** error nancov ({1}) ***** error ... nancov ([1 2; 3 4], 'bogus') ***** error ... nancov ([1 2 3], [1 2]) ***** error nancov ([1 2], [3 4], 0, 1) ***** assert_equal (nancov ([]), NaN) ***** assert_equal (nancov (zeros (0, 3)), NaN (3, 3)) ***** assert_equal (nancov (zeros (3, 0)), zeros (0, 0)) ***** assert_equal (nancov ([NaN, NaN, NaN]), NaN) ***** assert_equal (nancov ([1, NaN, 3; NaN, NaN, NaN]), NaN (3, 3)) ***** assert_equal (nancov (zeros (0, 3), zeros (0, 3)), NaN (2, 2)) ***** error nancov (ones (2, 0, 3, 2)) 21 tests, 21 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/geomean.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/geomean.m ***** test x = [0:10]; y = [x;x+5;x+10]; assert_equal (geomean (x), 0); m = [0 9.462942809849169 14.65658770861967]; assert_equal (geomean (y, 2), m', 4e-14); assert_equal (geomean (y, 'all'), 0); y(2,4) = NaN; m(2) = 9.623207231679554; assert_equal (geomean (y, 2), [0 NaN m(3)]', 4e-14); assert_equal (geomean (y', 'omitnan'), m, 4e-14); z = y + 20; assert_equal (geomean (z, 'all'), NaN); assert_equal (geomean (z, 'all', 'includenan'), NaN); assert_equal (geomean (z, 'all', 'omitnan'), 29.59298474535024, 4e-14); m = [24.79790781765634 NaN 34.85638839503932]; assert_equal (geomean (z'), m, 4e-14); assert_equal (geomean (z', 'includenan'), m, 4e-14); m(2) = 30.02181156156319; assert_equal (geomean (z', 'omitnan'), m, 4e-14); assert_equal (geomean (z, 2, 'omitnan'), m', 4e-14); ***** test x = repmat ([1:20;6:25], [5 2 6 3]); assert_equal (size (geomean (x, [3 2])), [10 1 1 3]); assert_equal (size (geomean (x, [1 2])), [1 1 6 3]); assert_equal (size (geomean (x, [1 2 4])), [1 1 6]); assert_equal (size (geomean (x, [1 4 3])), [1 40]); assert_equal (size (geomean (x, [1 2 3 4])), [1 1]); ***** test x = repmat ([1:20;6:25], [5 2 6 3]); m = repmat ([8.304361203739333;14.3078118884256], [5 1 1 3]); assert_equal (geomean (x, [3 2]), m, 4e-13); x(2,5,6,3) = NaN; m(2,3) = NaN; assert_equal (geomean (x, [3 2]), m, 4e-13); m(2,3) = 14.3292729579901; assert_equal (geomean (x, [3 2], 'omitnan'), m, 4e-13); ***** error geomean ('char') ***** error geomean ([1 -1 3]) ***** error ... geomean (repmat ([1:20;6:25], [5 2 6 3 5]), -1) ***** error ... geomean (repmat ([1:20;6:25], [5 2 6 3 5]), 0) ***** error ... geomean ([1 2 4], Inf) ***** error ... geomean ([1 2 4], [1 Inf]) ***** error ... geomean ([1 2 4], [Inf 1]) ***** error ... geomean (repmat ([1:20;6:25], [5 2 6 3 5]), [1 1]) ***** test a = geomean ([]); assert_equal (isnan (a), true); assert_equal (size (a), [1, 1]); ***** assert_equal (geomean (ones (2, 0, 3, 2)), ones (1, 0, 3, 2)) ***** assert_equal (geomean (ones (2, 0, 3, 2), [1, 2]), NaN (1, 1, 3, 2)) ***** assert_equal (geomean (ones (2, 0, 3, 2), 'all'), NaN) ***** assert_equal (geomean (ones (2, 0, 3, 2), 1), ones (1, 0, 3, 2)) ***** assert_equal (geomean (ones (2, 0, 3, 2), 2), NaN (2, 1, 3, 2)) ***** assert_equal (geomean (ones (2, 0, 3, 2), 3), ones (2, 0, 1, 2)) ***** assert_equal (geomean (ones (2, 0, 3, 2), 4), ones (2, 0, 3)) ***** assert_equal (geomean ([], 1), ones (1, 0)) ***** assert_equal (geomean ([], 2), ones (0, 1)) ***** assert_equal (geomean ([], 3), []) ***** assert_equal (geomean (zeros (0, 3)), NaN (1, 3)) ***** assert_equal (geomean (zeros (3, 0)), ones (1, 0)) ***** assert_equal (geomean ([], 'all'), NaN) 25 tests, 25 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/nanmax.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/nanmax.m ***** demo ## Find the column maximum values and their indices ## for matrix data with missing values. x = magic (3); x([1, 6:9]) = NaN [y, ind] = nanmax (x) ***** demo ## Find the maximum of all the values in an array, ignoring missing values. ## Create a 2-by-5-by-3 array x with some missing values. x = reshape (1:30, [2, 5, 3]); x([10:12, 25]) = NaN ## Find the maximum of the elements of x. y = nanmax (x, [], 'all') ***** assert_equal (nanmax ([]), []) ***** assert_equal (nanmax (zeros (0, 3)), zeros (0, 3)) ***** assert_equal (nanmax (zeros (3, 0)), zeros (1, 0)) ***** assert_equal (size (nanmax (ones (2, 0, 3, 2))), [1, 0, 3, 2]) ***** assert_equal (nanmax ([], [], 1), []) ***** assert_equal (nanmax ([], [], 2), []) ***** assert_equal (size (nanmax (ones (2, 0, 3, 2), [], 1)), [1, 0, 3, 2]) ***** assert_equal (size (nanmax (ones (2, 0, 3, 2), [], 2)), [2, 0, 3, 2]) ***** assert_equal (size (nanmax (ones (2, 0, 3, 2), [], 'all')), [0, 1]) ***** assert_equal (size (nanmax (ones (2, 0, 3, 2), [], [1, 2])), [0, 1, 3, 2]) ***** assert_equal (nanmax ([NaN, NaN, NaN]), NaN) ***** assert_equal (nanmax ([2, 4, NaN, 7]), 7) ***** assert_equal (nanmax ([2, 4, NaN, Inf]), Inf) ***** assert_equal (nanmax ([1, NaN, 3; NaN, 5, 6; 7, 8, NaN]), [7, 8, 6]) ***** assert_equal (nanmax ([1, NaN, 3; NaN, 5, 6; 7, 8, NaN]'), [3, 6, 8]) ***** assert_equal (nanmax (single ([1, NaN, 3; NaN, 5, 6; 7, 8, NaN])), single ([7, 8, 6])) ***** shared x, y x(:,:,1) = [1.77, -0.005, NaN, -2.95; NaN, 0.34, NaN, 0.19]; x(:,:,2) = [1.77, -0.005, NaN, -2.95; NaN, 0.34, NaN, 0.19] + 5; y = x; y(2,3,1) = 0.51; ***** assert_equal (nanmax (x, [], [1, 2])(:), [1.77;6.77]) ***** assert_equal (nanmax (x, [], [1, 3])(:), [6.77;5.34;NaN;5.19]) ***** assert_equal (nanmax (x, [], [2, 3])(:), [6.77;5.34]) ***** assert_equal (nanmax (x, [], [1, 2, 3]), 6.77) ***** assert_equal (nanmax (x, [], 'all'), 6.77) ***** assert_equal (nanmax (y, [], [1, 3])(:), [6.77;5.34;0.51;5.19]) ***** assert_equal (nanmax (x(1,:,1), x(2,:,1)), [1.77, 0.34, NaN, 0.19]) ***** assert_equal (nanmax (x(1,:,2), x(2,:,2)), [6.77, 5.34, NaN, 5.19]) ***** assert_equal (nanmax (y(1,:,1), y(2,:,1)), [1.77, 0.34, 0.51, 0.19]) ***** assert_equal (nanmax (y(1,:,2), y(2,:,2)), [6.77, 5.34, NaN, 5.19]) ***** test xx = repmat ([1:20;6:25], [5 2 6 3]); assert_equal (size (nanmax (xx, [], [3, 2])), [10, 1, 1, 3]); assert_equal (size (nanmax (xx, [], [1, 2])), [1, 1, 6, 3]); assert_equal (size (nanmax (xx, [], [1, 2, 4])), [1, 1, 6]); assert_equal (size (nanmax (xx, [], [1, 4, 3])), [1, 40]); assert_equal (size (nanmax (xx, [], [1, 2, 3, 4])), [1, 1]); ***** assert_equal (nanmax (ones (2), [], 3), ones (2, 2)) ***** assert_equal (nanmax (ones (2, 2, 2), [], 99), ones (2, 2, 2)) ***** assert_equal (nanmax (magic (3), [], 3), magic (3)) ***** assert_equal (nanmax (magic (3), [], [1, 3]), [8, 9, 7]) ***** assert_equal (nanmax (magic (3), [], [1, 99]), [8, 9, 7]) ***** assert_equal (nanmax (ones (2), 3), 3 * ones (2,2)) ***** error ... nanmax (y, [], [1, 1, 2]) ***** error ... [v, idx] = nanmax (x, y, [1 2]) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/grpstats.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/grpstats.m ***** demo load carsmall; [m, p, g] = grpstats (Weight, Model_Year, {'mean', 'predci', 'gname'}) n = length (m); errorbar ((1:n)',m,p(:,2)-m); set (gca, 'xtick', 1:n, 'xticklabel', g); title ('95% prediction intervals for mean weight by year'); ***** demo load carsmall; [m, p, g] = grpstats ([Acceleration,Weight/1000],Cylinders, ... {'mean', 'meanci', 'gname'}, 0.05) [c, r] = size (m); errorbar ((1:c)'.*ones (c,r),m,p(:,[(1:r)])-m); set (gca, 'xtick', 1:c, 'xticklabel', g); title ('95% prediction intervals for mean weight by year'); ***** demo ## Plot mean and 95% CI for a single grouping variable load carsmall; grpstats (Weight, Model_Year, 0.05); title ('Mean Weight by Model Year'); ***** demo ## Plot mean and 95% CI for two grouping variables load carsmall; grpstats (Weight, {Origin, Cylinders}, 0.05); title ('Mean Weight by Origin and Number of Cylinders'); ***** test load carsmall means = grpstats (Acceleration, Origin); assert_equal (means, [14.4377; 18.0500; 15.8867; 16.3778; 16.6000; 15.5000], 0.001); ***** test load carsmall [grpMin, grpMax, grp] = grpstats (Acceleration, Origin, {'min', 'max', ... 'gname'}); assert_equal (grpMin, [8.0; 15.3; 13.9; 12.2; 15.7; 15.5]); assert_equal (grpMax, [22.2; 21.9; 18.2; 24.6; 17.5; 15.5]); ***** test load carsmall [grpMin, grpMax, grp] = grpstats (Acceleration, Origin, {'min', 'max', ... 'gname'}); assert_equal (grp', {'USA', 'France', 'Japan', 'Germany', 'Sweden', 'Italy'}); ***** test load carsmall [m, p, g] = grpstats ([Acceleration, Weight/1000], Cylinders, ... {'mean', 'meanci', 'gname'}, 0.05); ## check meanci lower bounds (first slice) with tolerance expected_lower = [15.9163; 15.6622; 10.7968]; expected_upper = [17.4249; 17.2907; 12.4845]; assert_equal (abs (p(:,1,1)), expected_lower, 1e-3); assert_equal (abs (p(:,1,2)), expected_upper, 1e-3); ***** test [mC, g] = grpstats ([], []); assert_equal (isempty (mC), true); assert_equal (isempty (g), true); ***** test ## column vector, no group x = [1; 2; 3; 4; 5]; m = grpstats (x); expected = 3; assert_equal (m, expected); ***** test ## row vector, no group x = [1 2 3 4 5]; m = grpstats (x); expected = 3; assert_equal (m, expected); ***** test ## matrix, no group x = [1 2; 3 4; 5 6]; m = grpstats (x); expected = [3 4]; assert_equal (m, expected); ***** test ## vector, numeric groups x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; m = grpstats (x, g); expected = [15; 35; 55]; assert_equal (m, expected); ***** test ## vector, cellstr groups x = [10; 20; 30; 40; 50; 60]; g = {'A'; 'A'; 'B'; 'B'; 'C'; 'C'}; m = grpstats (x, g); expected = [15; 35; 55]; assert_equal (m, expected); ***** test ## matrix, numeric groups x = [1 10; 2 20; 3 30; 4 40; 5 50; 6 60]; g = [1; 1; 2; 2; 3; 3]; m = grpstats (x, g); expected = [1.5 15; 3.5 35; 5.5 55]; assert_equal (m, expected); ***** test ## NaN handling x = [1; NaN; 3; 4; NaN; 6]; g = [1; 1; 2; 2; 3; 3]; m = grpstats (x, g); expected = [1; 3.5; 6]; assert_equal (m, expected); ***** test ## single group x = [1; 2; 3; 4; 5]; g = ones (5, 1); m = grpstats (x, g); expected = 3; assert_equal (m, expected); ***** test ## single statistic x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; m = grpstats (x, g, 'mean'); expected = [15; 35; 55]; assert_equal (m, expected); ***** test ## single statistic x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; m = grpstats (x, g, 'median'); expected = [15; 35; 55]; assert_equal (m, expected); ***** test ## single statistic x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; s = grpstats (x, g, 'std'); expected = [7.07106781186548; 7.07106781186548; 7.07106781186548]; assert_equal (s, expected, 1e-14); ***** test ## single statistic x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; v = grpstats (x, g, 'var'); expected = [50; 50; 50]; assert_equal (v, expected); ***** test ## single statistic x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; s = grpstats (x, g, 'sem'); expected = [5; 5; 5]; assert_equal (s, expected); ***** test ## single statistic x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; mn = grpstats (x, g, 'min'); expected = [10; 30; 50]; assert_equal (mn, expected); ***** test ## single statistic x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; mx = grpstats (x, g, 'max'); expected = [20; 40; 60]; assert_equal (mx, expected); ***** test ## single statistic x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; r = grpstats (x, g, 'range'); expected = [10; 10; 10]; assert_equal (r, expected); ***** test ## single statistic x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; n = grpstats (x, g, 'numel'); expected = [2; 2; 2]; assert_equal (n, expected); ***** test ## single statistic x = [10; 20; 30; 40; 50; 60]; g = {'A'; 'A'; 'B'; 'B'; 'C'; 'C'}; names = grpstats (x, g, 'gname'); expected = {'A'; 'B'; 'C'}; assert_equal (names, expected); ***** test ## single statistic (default alpha) x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; ci = grpstats (x, g, 'meanci'); expected = [-48.5310236808735 78.5310236808735; -28.5310236808735 ... 98.5310236808735; -8.53102368087348 118.531023680873]; assert_equal (ci, expected, 1e-12); ***** test ## single statistic (default alpha) x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; ci = grpstats (x, g, 'predci'); expected = [-95.0389608721344 125.038960872134; -75.0389608721344 ... 145.038960872134; -55.0389608721344 165.038960872134]; assert_equal (ci, expected, 1e-12); ***** test ## mean + std x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; [m, s] = grpstats (x, g, {'mean', 'std'}); expected_m = [15; 35; 55]; expected_s = [7.07106781186548; 7.07106781186548; 7.07106781186548]; assert_equal (m, expected_m, 1e-14); assert_equal (s, expected_s, 1e-14); ***** test ## min + max + range x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; [mn, mx, r] = grpstats (x, g, {'min', 'max', 'range'}); expected_mn = [10; 30; 50]; expected_mx = [20; 40; 60]; expected_r = [10; 10; 10]; assert_equal (mn, expected_mn); assert_equal (mx, expected_mx); assert_equal (r, expected_r); ***** test ## mean + median + numel + gname x = [10; 20; 30; 40; 50; 60]; g = {'A'; 'A'; 'B'; 'B'; 'C'; 'C'}; [m, med, n, names] = grpstats (x, g, {'mean', 'median', 'numel', 'gname'}); expected_m = [15; 35; 55]; expected_med = [15; 35; 55]; expected_n = [2; 2; 2]; expected_names = {'A'; 'B'; 'C'}; assert_equal (m, expected_m); assert_equal (med, expected_med); assert_equal (n, expected_n); assert_equal (names, expected_names); ***** test ## all basic statistics x = [10; 20; 30; 40; 50; 60; 70; 80]; g = [1; 1; 2; 2; 2; 2; 3; 3]; [m, med, s, v, se, mn, mx, r, n] = grpstats (x, g, {'mean', 'median', ... 'std', 'var', 'sem', ... 'min', 'max', 'range', ... 'numel'}); expected_m = [15; 45; 75]; expected_med = [15; 45; 75]; expected_s = [7.07106781186548; 12.9099444873581; 7.07106781186548]; expected_v = [50; 166.666666666667; 50]; expected_se = [5; 6.45497224367903; 5]; expected_mn = [10; 30; 70]; expected_mx = [20; 60; 80]; expected_r = [10; 30; 10]; expected_n = [2; 4; 2]; assert_equal (m, expected_m); assert_equal (med, expected_med); assert_equal (s, expected_s, 1e-13); assert_equal (v, expected_v, 1e-12); assert_equal (se, expected_se, 1e-14); assert_equal (mn, expected_mn); assert_equal (mx, expected_mx); assert_equal (r, expected_r); assert_equal (n, expected_n); ***** test ## meanci-alpha-0.1 x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; ci = grpstats (x, g, 'meanci', 0.1); expected = [-16.5687575733752 46.5687575733752; 3.4312424266248 ... 66.5687575733752; 23.4312424266248 86.5687575733752]; assert_equal (ci, expected, 1e-13); ***** test ## predci-alpha-0.1 x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; ci = grpstats (x, g, 'predci', 0.1); expected = [-39.6786920489106 69.6786920489106; -19.6786920489106 ... 89.6786920489106; 0.321307951089366 109.678692048911]; assert_equal (ci, expected, 1e-12); ***** test ## meanci-alpha-0.01 x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; ci = grpstats (x, g, 'meanci', 0.01); expected = [-303.283705814358 333.283705814358; -283.283705814358 ... 353.283705814358; -263.283705814358 373.283705814358]; assert_equal (ci, expected, 3e-8); ***** test ## predci-alpha-0.01 x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; ci = grpstats (x, g, 'predci', 0.01); expected = [-536.283549691775 566.283549691775; -516.283549691775 ... 586.283549691775; -496.283549691775 606.283549691775]; assert_equal (ci, expected, 3e-8); ***** test ## meanci-alpha-0.2 x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; ci = grpstats (x, g, 'meanci', 0.2); expected = [-0.388417685876263 30.3884176858763; 19.6115823141237 ... 50.3884176858763; 39.6115823141237 70.3884176858763]; assert_equal (ci, expected, 1e-13); ***** test ## predci-alpha-0.2 x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; ci = grpstats (x, g, 'predci', 0.2); expected = [-11.6535212800292 41.6535212800292; 8.34647871997083 ... 61.6535212800292; 28.3464787199708 81.6535212800292]; assert_equal (ci, expected, 1e-13); ***** test ## meanci, name-value alpha=0.2 x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; ci = grpstats (x, g, 'meanci', 'alpha', 0.2); expected = [-0.388417685876263 30.3884176858763; 19.6115823141237 ... 50.3884176858763; 39.6115823141237 70.3884176858763]; assert_equal (ci, expected, 1e-13); ***** test ## meanci + predci, alpha=0.01 x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 2; 2; 3; 3]; [ci_m, ci_p] = grpstats (x, g, {'meanci', 'predci'}, 0.01); expected_m = [-303.283705814358 333.283705814358; -283.283705814358 ... 353.283705814358; -263.283705814358 373.283705814358]; expected_p = [-536.283549691775 566.283549691775; -516.283549691775 ... 586.283549691775; -496.283549691775 606.283549691775]; assert_equal (ci_m, expected_m, 3e-8); assert_equal (ci_p, expected_p, 3e-8); ***** test ## matrix, mean+std+numel x = [1 10; 2 20; 3 30; 4 40; 5 50; 6 60]; g = [1; 1; 2; 2; 3; 3]; [m, s, n] = grpstats (x, g, {'mean', 'std', 'numel'}); expected_m = [1.5 15; 3.5 35; 5.5 55]; expected_s = [0.707106781186548 7.07106781186548; 0.707106781186548 ... 7.07106781186548; 0.707106781186548 7.07106781186548]; expected_n = [2 2; 2 2; 2 2]; assert_equal (m, expected_m); assert_equal (s, expected_s, 1e-14); assert_equal (n, expected_n); ***** test ## matrix with NaN, mean+numel x = [1 10; NaN 20; 3 NaN; 4 40; 5 50; 6 60]; g = [1; 1; 2; 2; 3; 3]; [m, n] = grpstats (x, g, {'mean', 'numel'}); expected_m = [1 15; 3.5 40; 5.5 55]; expected_n = [1 2; 2 1; 2 2]; assert_equal (m, expected_m); assert_equal (n, expected_n); ***** test ## 3-column matrix, mean+min+max x = [1 100 1000; 2 200 2000; 3 300 3000; 4 400 4000]; g = [1; 1; 2; 2]; [m, mn, mx] = grpstats (x, g, {'mean', 'min', 'max'}); expected_m = [1.5 150 1500; 3.5 350 3500]; expected_mn = [1 100 1000; 3 300 3000]; expected_mx = [2 200 2000; 4 400 4000]; assert_equal (m, expected_m); assert_equal (mn, expected_mn); assert_equal (mx, expected_mx); ***** test ## one element per group x = [1; 2; 3]; g = [1; 2; 3]; [m, s, n] = grpstats (x, g, {'mean', 'std', 'numel'}); expected_m = [1; 2; 3]; expected_s = [0; 0; 0]; expected_n = [1; 1; 1]; assert_equal (m, expected_m); assert_equal (s, expected_s); assert_equal (n, expected_n); ***** test ## group with all NaN x = [1; 2; NaN; NaN; 5; 6]; g = [1; 1; 2; 2; 3; 3]; [m, s, n] = grpstats (x, g, {'mean', 'std', 'numel'}); expected_m = [1.5; NaN; 5.5]; expected_s = [0.707106781186548; NaN; 0.707106781186548]; expected_n = [2; 0; 2]; assert_equal (m, expected_m); assert_equal (s, expected_s, 1e-14); assert_equal (n, expected_n); ***** test ## unequal group sizes x = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10]; g = [1; 1; 1; 1; 2; 2; 2; 3; 3; 3]; [m, v, n] = grpstats (x, g, {'mean', 'var', 'numel'}); expected_m = [2.5; 6; 9]; expected_v = [1.66666666666667; 1; 1]; expected_n = [4; 3; 3]; assert_equal (m, expected_m); assert_equal (v, expected_v, 1e-14); assert_equal (n, expected_n); ***** test ## non-consecutive numeric groups x = [10; 20; 30; 40; 50; 60]; g = [1; 1; 5; 5; 10; 10]; [m, names] = grpstats (x, g, {'mean', 'gname'}); expected_m = [15; 35; 55]; expected_names = {'1'; '5'; '10'}; assert_equal (m, expected_m); assert_equal (names, expected_names); ***** test ## unsorted string groups x = [30; 10; 40; 20; 60; 50]; g = {'C'; 'A'; 'C'; 'A'; 'B'; 'B'}; [m, names] = grpstats (x, g, {'mean', 'gname'}); expected_m = [35; 15; 55]; expected_names = {'C'; 'A'; 'B'}; assert_equal (m, expected_m); assert_equal (names, expected_names); ***** test ## 20 groups, one element each x = (1:20)'; g = (1:20)'; [m, n] = grpstats (x, g, {'mean', 'numel'}); expected_m = (1:20)'; expected_n = ones (20, 1); assert_equal (m, expected_m); assert_equal (n, expected_n); ***** test ## large sample meanci x = (1:50)'; g = [ones(25, 1); 2 * ones(25, 1)]; ci = grpstats (x, g, 'meanci'); expected = [9.96202357522388 16.0379764247761; 34.9620235752239 ... 41.0379764247761]; assert_equal (ci, expected, 1e-13); ***** test ## large sample predci x = (1:50)'; g = [ones(25, 1); 2 * ones(25, 1)]; ci = grpstats (x, g, 'predci'); expected = [-2.49070107176829 28.4907010717683; 22.5092989282317 ... 53.4907010717683]; assert_equal (ci, expected, 2e-14); ***** test Y = [5; 6; 7; 4; 9; 8]; X = [1; 2; 3; 4; 5; 6]; Group = categorical ({'A'; 'A'; 'B'; 'B'; 'C'; 'C'}); tbl = table (Y, X, Group); stats_tbl = grpstats (tbl, 'Group', {'mean', 'numel'}); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Y', 'numel_Y', ... 'mean_X', 'numel_X'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'; 'C'}); assert_equal (stats_tbl.GroupCount, [2; 2; 2]); assert_equal (stats_tbl.mean_Y, [5.5; 5.5; 8.5]); assert_equal (stats_tbl.numel_Y, [2; 2; 2]); assert_equal (stats_tbl.mean_X, [1.5; 3.5; 5.5]); assert_equal (stats_tbl.numel_X, [2; 2; 2]); ***** test Y = [5; 6; 7; 4; 9; 8]; Group = categorical ({'A'; 'A'; 'B'; 'B'; 'C'; 'C'}); tbl = table (Y, Group); stats_tbl = grpstats (tbl, 'Group', 'mean'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Y'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'; 'C'}); assert_equal (stats_tbl.GroupCount, [2; 2; 2]); assert_equal (stats_tbl.mean_Y, [5.5; 5.5; 8.5]); ***** test Y = [10; 20; 30; 40]; X = [100; 200; 300; 400]; Z = [1000; 2000; 3000; 4000]; Group = categorical ({'A'; 'A'; 'B'; 'B'}); tbl = table (Y, X, Z, Group); stats_tbl = grpstats (tbl, 'Group', {'mean', 'numel'}); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Y', 'numel_Y', 'mean_X', 'numel_X', 'mean_Z', 'numel_Z'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'}); assert_equal (stats_tbl.GroupCount, [2; 2]); assert_equal (stats_tbl.mean_Y, [15; 35]); assert_equal (stats_tbl.numel_Y, [2; 2]); assert_equal (stats_tbl.mean_X, [150; 350]); assert_equal (stats_tbl.numel_X, [2; 2]); assert_equal (stats_tbl.mean_Z, [1500; 3500]); assert_equal (stats_tbl.numel_Z, [2; 2]); ***** test Y = [1; 2; 3; 4; 5; 6; 7; 8]; Group = categorical ({'A'; 'A'; 'A'; 'A'; 'B'; 'B'; 'B'; 'B'}); tbl = table (Y, Group); stats_tbl = grpstats (tbl, 'Group', 'mean'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Y'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'}); assert_equal (stats_tbl.GroupCount, [4; 4]); assert_equal (stats_tbl.mean_Y, [2.5; 6.5]); ***** test Y = [1; 2; 3; 4; 5; 6; 7]; Group = categorical ({'A'; 'A'; 'A'; 'A'; 'A'; 'B'; 'B'}); tbl = table (Y, Group); stats_tbl = grpstats (tbl, 'Group', {'mean', 'numel'}); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Y', 'numel_Y'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'}); assert_equal (stats_tbl.GroupCount, [5; 2]); assert_equal (stats_tbl.mean_Y, [3; 6.5]); assert_equal (stats_tbl.numel_Y, [5; 2]); ***** test Y = [10; 20; 30]; Group = categorical ({'A'; 'B'; 'C'}); tbl = table (Y, Group); stats_tbl = grpstats (tbl, 'Group', 'mean'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Y'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'; 'C'}); assert_equal (stats_tbl.GroupCount, [1; 1; 1]); assert_equal (stats_tbl.mean_Y, [10; 20; 30]); ***** test Y = [5; 5; 5; 5]; Group = categorical ({'A'; 'A'; 'B'; 'B'}); tbl = table (Y, Group); stats_tbl = grpstats (tbl, 'Group', 'mean'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Y'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'}); assert_equal (stats_tbl.GroupCount, [2; 2]); assert_equal (stats_tbl.mean_Y, [5; 5]); ***** test Y = [1; NaN; 3; 4; NaN; 6]; X = [10; 20; NaN; 40; 50; NaN]; Group = categorical ({'A'; 'A'; 'B'; 'B'; 'C'; 'C'}); tbl = table (Y, X, Group); stats_tbl = grpstats (tbl, 'Group', 'mean'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Y', 'mean_X'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'; 'C'}); assert_equal (stats_tbl.GroupCount, [2; 2; 2]); assert_equal (stats_tbl.mean_Y, [1; 3.5; 6]); assert_equal (stats_tbl.mean_X, [15; 40; 50]); ***** test Y = [1; NaN; 3; 4; 5; 6]; Group = categorical ({'A'; 'A'; 'B'; 'B'; 'C'; 'C'}); tbl = table (Y, Group); stats_tbl = grpstats (tbl, 'Group', {'mean', 'numel'}); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Y', 'numel_Y'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'; 'C'}); assert_equal (stats_tbl.GroupCount, [2; 2; 2]); assert_equal (stats_tbl.mean_Y, [1; 3.5; 5.5]); assert_equal (stats_tbl.numel_Y, [1; 2; 2]); ***** test Y = [100; 200; 300; 400; 500; 600]; Group = categorical ({'Group1'; 'Group1'; 'Group2'; 'Group2'; ... 'Group3'; 'Group3'}); tbl = table (Y, Group); stats_tbl = grpstats (tbl, 'Group', 'mean'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Y'}); assert_equal (stats_tbl.Properties.RowNames, {'Group1'; 'Group2'; 'Group3'}); assert_equal (stats_tbl.GroupCount, [2; 2; 2]); assert_equal (stats_tbl.mean_Y, [150; 350; 550]); ***** test Var1 = [1; 2; 3; 4]; Var2 = [10; 20; 30; 40]; Var3 = [100; 200; 300; 400]; Var4 = [1000; 2000; 3000; 4000]; Group = categorical ({'A'; 'A'; 'B'; 'B'}); tbl = table (Var1, Var2, Var3, Var4, Group); stats_tbl = grpstats (tbl, 'Group', 'mean'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Var1', 'mean_Var2', 'mean_Var3', 'mean_Var4'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'}); assert_equal (stats_tbl.GroupCount, [2; 2]); assert_equal (stats_tbl.mean_Var1, [1.5; 3.5]); assert_equal (stats_tbl.mean_Var2, [15; 35]); assert_equal (stats_tbl.mean_Var3, [150; 350]); assert_equal (stats_tbl.mean_Var4, [1500; 3500]); ***** test Y = [1.5; 2.5; 3.5; 4.5; 5.5; 6.5]; Group = categorical ({'A'; 'A'; 'B'; 'B'; 'C'; 'C'}); tbl = table (Y, Group); stats_tbl = grpstats (tbl, 'Group', 'mean'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Y'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'; 'C'}); assert_equal (stats_tbl.GroupCount, [2; 2; 2]); assert_equal (stats_tbl.mean_Y, [2; 4; 6]); ***** test Y = [-10; -20; 30; 40; 50; 60]; Group = categorical ({'A'; 'A'; 'B'; 'B'; 'C'; 'C'}); tbl = table (Y, Group); stats_tbl = grpstats (tbl, 'Group', 'mean'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Y'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'; 'C'}); assert_equal (stats_tbl.GroupCount, [2; 2; 2]); assert_equal (stats_tbl.mean_Y, [-15; 35; 55]); ***** test Y = [0; 0; 0; 0; 0; 0]; Group = categorical ({'A'; 'A'; 'B'; 'B'; 'C'; 'C'}); tbl = table (Y, Group); stats_tbl = grpstats (tbl, 'Group', 'mean'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Y'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'; 'C'}); assert_equal (stats_tbl.GroupCount, [2; 2; 2]); assert_equal (stats_tbl.mean_Y, [0; 0; 0]); ***** test Y = [1e6; 2e6; 3e6; 4e6; 5e6; 6e6]; Group = categorical ({'A'; 'A'; 'B'; 'B'; 'C'; 'C'}); tbl = table (Y, Group); stats_tbl = grpstats (tbl, 'Group', 'mean'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Y'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'; 'C'}); assert_equal (stats_tbl.GroupCount, [2; 2; 2]); assert_equal (stats_tbl.mean_Y, [1.5e6; 3.5e6; 5.5e6]); ***** test Y = (1:10)'; Group = categorical (repmat ({'A'; 'B'}, 5, 1)); tbl = table (Y, Group); stats_tbl = grpstats (tbl, 'Group', {'mean', 'numel'}); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, ... {'Group', 'GroupCount', 'mean_Y', 'numel_Y'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'}); assert_equal (stats_tbl.GroupCount, [5; 5]); assert_equal (stats_tbl.mean_Y, [5; 6]); assert_equal (stats_tbl.numel_Y, [5; 5]); ***** test Y = (1:20)'; Group = categorical (repmat ({'A'; 'B'; 'C'; 'D'}, 5, 1)); tbl = table (Y, Group); stats_tbl = grpstats (tbl, 'Group', 'mean'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Y'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'; 'C'; 'D'}); assert_equal (stats_tbl.GroupCount, [5; 5; 5; 5]); assert_equal (stats_tbl.mean_Y, [9; 10; 11; 12]); ***** test Y = [1; 2; 3; 4; 5]; Group = categorical ({'A'; 'B'; 'C'; 'D'; 'E'}); tbl = table (Y, Group); stats_tbl = grpstats (tbl, 'Group', 'mean'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Y'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'; 'C'; 'D'; 'E'}); assert_equal (stats_tbl.GroupCount, [1; 1; 1; 1; 1]); assert_equal (stats_tbl.mean_Y, [1; 2; 3; 4; 5]); ***** test Score1 = [85; 90; 78; 92; 88; 76]; Score2 = [82; 88; 75; 90; 85; 73]; Group = categorical ({'High'; 'High'; 'Med'; 'Med'; 'Low'; 'Low'}); tbl = table (Score1, Score2, Group); stats_tbl = grpstats (tbl, 'Group', 'mean'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Score1', 'mean_Score2'}); assert_equal (stats_tbl.Properties.RowNames, {'High'; 'Low'; 'Med'}); assert_equal (stats_tbl.GroupCount, [2; 2; 2]); assert_equal (stats_tbl.mean_Score1, [87.5; 82; 85]); assert_equal (stats_tbl.mean_Score2, [85; 79; 82.5]); ***** test Height = [170; 175; 165; 180; 160; 185]; Weight = [70; 75; 65; 80; 60; 85]; Category = categorical ({'M'; 'M'; 'F'; 'F'; 'M'; 'M'}); tbl = table (Height, Weight, Category); stats_tbl = grpstats (tbl, 'Category', {'mean', 'numel'}); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Category', 'GroupCount', ... 'mean_Height', 'numel_Height', 'mean_Weight', 'numel_Weight'}); assert_equal (stats_tbl.Properties.RowNames, {'F'; 'M'}); assert_equal (stats_tbl.GroupCount, [2; 4]); assert_equal (stats_tbl.mean_Height, [172.5; 172.5]); assert_equal (stats_tbl.numel_Height, [2; 4]); assert_equal (stats_tbl.mean_Weight, [72.5; 72.5]); assert_equal (stats_tbl.numel_Weight, [2; 4]); ***** test Value = [10.5; 11.2; 9.8; 10.1; 11.5; 10.8]; Type = categorical ({'A'; 'A'; 'A'; 'B'; 'B'; 'B'}); tbl = table (Value, Type); stats_tbl = grpstats (tbl, 'Type', 'numel'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Type', 'GroupCount', ... 'numel_Value'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'}); assert_equal (stats_tbl.GroupCount, [3; 3]); assert_equal (stats_tbl.numel_Value, [3; 3]); ***** test Data = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10]; Label = categorical ({'A'; 'A'; 'A'; 'A'; 'A'; 'B'; 'B'; 'B'; 'B'; 'B'}); tbl = table (Data, Label); stats_tbl = grpstats (tbl, 'Label', {'mean', 'numel'}); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Label', 'GroupCount', ... 'mean_Data', 'numel_Data'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'}); assert_equal (stats_tbl.GroupCount, [5; 5]); assert_equal (stats_tbl.mean_Data, [3; 8]); assert_equal (stats_tbl.numel_Data, [5; 5]); ***** test X1 = [1; 2; 3; 4]; X2 = [5; 6; 7; 8]; G = categorical ({'A'; 'A'; 'B'; 'B'}); tbl = table (X1, X2, G); stats_tbl = grpstats (tbl, 'G', 'mean'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'G', 'GroupCount', ... 'mean_X1', 'mean_X2'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'}); assert_equal (stats_tbl.GroupCount, [2; 2]); assert_equal (stats_tbl.mean_X1, [1.5; 3.5]); assert_equal (stats_tbl.mean_X2, [5.5; 7.5]); ***** test Measurement = [100; 150; 200; 250; 300; 350]; GroupVar = categorical ({'Control'; 'Control'; 'Treatment'; 'Treatment'; ... 'Placebo'; 'Placebo'}); tbl = table (Measurement, GroupVar); stats_tbl = grpstats (tbl, 'GroupVar', 'mean'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'GroupVar', 'GroupCount', ... 'mean_Measurement'}); assert_equal (stats_tbl.Properties.RowNames, {'Control'; 'Placebo'; 'Treatment'}); assert_equal (stats_tbl.GroupCount, [2; 2; 2]); assert_equal (stats_tbl.mean_Measurement, [125; 325; 225]); ***** test Y = [NaN; NaN; 3; 4; 5; 6]; Group = categorical ({'A'; 'A'; 'B'; 'B'; 'C'; 'C'}); tbl = table (Y, Group); stats_tbl = grpstats (tbl, 'Group', 'mean'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Y'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'; 'C'}); assert_equal (stats_tbl.GroupCount, [2; 2; 2]); assert_equal (isequaln (stats_tbl.mean_Y, [NaN; 3.5; 5.5]), true); ***** test Y = [1; 2; NaN; NaN; NaN; NaN]; Group = categorical ({'A'; 'A'; 'B'; 'B'; 'C'; 'C'}); tbl = table (Y, Group); stats_tbl = grpstats (tbl, 'Group', {'mean', 'numel'}); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Group', 'GroupCount', ... 'mean_Y', 'numel_Y'}); assert_equal (stats_tbl.Properties.RowNames, {'A'; 'B'; 'C'}); assert_equal (stats_tbl.GroupCount, [2; 2; 2]); assert_equal (isequaln (stats_tbl.mean_Y, [1.5; NaN; NaN]), true); assert_equal (stats_tbl.numel_Y, [2; 0; 0]); ***** test Val = [5.5; 6.5; 7.5; 8.5]; Cat = categorical ({'X'; 'X'; 'Y'; 'Y'}); tbl = table (Val, Cat); stats_tbl = grpstats (tbl, 'Cat', 'numel'); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Cat', 'GroupCount', ... 'numel_Val'}); assert_equal (stats_tbl.Properties.RowNames, {'X'; 'Y'}); assert_equal (stats_tbl.GroupCount, [2; 2]); assert_equal (stats_tbl.numel_Val, [2; 2]); ***** test A = [1; 2; 3; 4; 5; 6]; B = [10; 20; 30; 40; 50; 60]; C = [100; 200; 300; 400; 500; 600]; Grp = categorical ({'G1'; 'G1'; 'G2'; 'G2'; 'G3'; 'G3'}); tbl = table (A, B, C, Grp); stats_tbl = grpstats (tbl, 'Grp', {'mean', 'numel'}); assert_equal (istable (stats_tbl), true); assert_equal (stats_tbl.Properties.VariableNames, {'Grp', 'GroupCount', ... 'mean_A', 'numel_A', 'mean_B', 'numel_B', 'mean_C', 'numel_C'}); assert_equal (stats_tbl.Properties.RowNames, {'G1'; 'G2'; 'G3'}); assert_equal (stats_tbl.GroupCount, [2; 2; 2]); assert_equal (stats_tbl.mean_A, [1.5; 3.5; 5.5]); assert_equal (stats_tbl.numel_A, [2; 2; 2]); assert_equal (stats_tbl.mean_B, [15; 35; 55]); assert_equal (stats_tbl.numel_B, [2; 2; 2]); assert_equal (stats_tbl.mean_C, [150; 350; 550]); assert_equal (stats_tbl.numel_C, [2; 2; 2]); ***** test x = [1; NaN; 3; 4]; g = [1; 1; 2; 2]; muci = grpstats (x, g, 'meanci'); assert_equal (muci, [NaN, NaN; -2.8531, 9.8531], 1e-4); ***** test x = [1; NaN; 3; 4; 5; 6]; g = [1; 1; 1; 2; 2; 2]; predci = grpstats (x, g, 'predci'); assert_equal (predci, [-20.0078, 24.0078; 0.0317, 9.9683], 1e-4); ***** test ## An empty X keeps its columns and has no groups assert_equal (grpstats (zeros (0, 3), zeros (0, 1)), zeros (0, 3)); assert_equal (grpstats (zeros (0, 1), zeros (0, 1)), zeros (0, 1)); assert_equal (grpstats (zeros (0, 3)), zeros (0, 3)); assert_equal (grpstats ([], []), []); ***** test ## Every reducing statistic keeps the columns of an empty X g = zeros (0, 1); assert_equal (grpstats (zeros (0, 3), g, 'sem'), zeros (0, 3)); assert_equal (grpstats (zeros (0, 3), g, 'std'), zeros (0, 3)); assert_equal (grpstats (zeros (0, 3), g, 'var'), zeros (0, 3)); assert_equal (grpstats (zeros (0, 3), g, 'min'), zeros (0, 3)); assert_equal (grpstats (zeros (0, 3), g, 'max'), zeros (0, 3)); assert_equal (grpstats (zeros (0, 3), g, 'range'), zeros (0, 3)); assert_equal (grpstats (zeros (0, 3), g, 'numel'), zeros (0, 3)); ***** test ## meanci and predci of an empty X keep the columns and the bound pair g = zeros (0, 1); assert_equal (size (grpstats (zeros (0, 3), g, 'meanci')), [0, 3, 2]); assert_equal (size (grpstats (zeros (0, 3), g, 'predci')), [0, 3, 2]); assert_equal (size (grpstats (zeros (0, 1), g, 'meanci')), [0, 2]); assert_equal (size (grpstats ([], [], 'meanci')), [0, 0, 2]); ***** test ## gname of an empty X is an empty cell column assert_equal (grpstats (zeros (0, 3), zeros (0, 1), 'gname'), cell (0, 1)); assert_equal (grpstats ([], [], 'gname'), cell (0, 1)); ***** test ## Without a grouping variable X is a single group named '1' assert_equal (grpstats ([1; 2; 3], [], 'gname'), {'1'}); assert_equal (grpstats ([1; 2; 3], [], 'mean'), 2); ***** test ## A grouping variable that is entirely missing leaves no groups assert_equal (grpstats ([1; 2; 3], [NaN; NaN; NaN]), zeros (0, 1)); assert_equal (grpstats ([1; 2; 3], [NaN; NaN; NaN], 'std'), zeros (0, 1)); assert_equal (grpstats ([1; 2; 3], [NaN; NaN; NaN], 'gname'), cell (0, 1)); assert_equal (grpstats ([1; 2; 3], {''; ''; ''}), zeros (0, 1)); ***** test ## A row missing in any of several grouping variables belongs to no group y = [1; 2; 3; 4]; assert_equal (grpstats (y, {[NaN; 1; 2; 2], [1; 2; 1; 2]}), [2; 3; 4]); gone = {[NaN; NaN; NaN; NaN], [1; 2; 1; 2]}; assert_equal (grpstats (y, gone), zeros (0, 1)); ***** test ## gname over several grouping variables has one column per variable y = [1; 2; 3; 4]; gn = grpstats (y, {[NaN; NaN; NaN; NaN], [1; 2; 1; 2]}, 'gname'); assert_equal (gn, cell (0, 2)); gn = grpstats (y, {[1; 1; 2; 2], [1; 2; 1; 2]}, 'gname'); assert_equal (gn, {'1', '1'; '1', '2'; '2', '1'; '2', '2'}); ***** test ## Several empty grouping variables keep the columns of X g = zeros (0, 1); assert_equal (grpstats (zeros (0, 3), {g, g}), zeros (0, 3)); assert_equal (grpstats (zeros (0, 3), {g, g}, 'gname'), cell (0, 2)); ***** test ## Without WHICHSTATS the outputs are mean, sem, counts and names [m, s, n, g] = grpstats ([1; 2; 3; 4], [1; 1; 2; 2]); assert_equal (m, [1.5; 3.5]); assert_equal (s, [0.5; 0.5]); assert_equal (n, [2; 2]); assert_equal (g, {'1'; '2'}); ***** test ## The default counts and standard error ignore NaNs [m, s, n] = grpstats ([1; 2; NaN; 4], [1; 1; 2; 2]); assert_equal (m, [1.5; 4]); assert_equal (s, [0.5; 0]); assert_equal (n, [2; 1]); ***** test ## The default outputs are computed column by column [m, s, n] = grpstats ([1, 10; 3, 20; 5, 30; 7, 40], [1; 1; 2; 2]); assert_equal (m, [2, 15; 6, 35]); assert_equal (s, [1, 5; 1, 5], 1e-14); assert_equal (n, [2, 2; 2, 2]); ***** test ## The default outputs of an empty X keep its columns [m, s, n, g] = grpstats (zeros (0, 3), zeros (0, 1)); assert_equal (m, zeros (0, 3)); assert_equal (s, zeros (0, 3)); assert_equal (n, zeros (0, 3)); assert_equal (g, cell (0, 1)); ***** test ## The standard error is taken column by column assert_equal (grpstats ([1, 10; 2, 20; 3, 30], [1; 1; 1], 'sem'), ... [0.5773502691896258, 5.773502691896258], 1e-14); ***** test ## The standard error divides each column by its own count assert_equal (grpstats ([1, 10; 2, NaN; 3, 30], [1; 1; 1], 'sem'), ... [0.5773502691896258, 10], 1e-14); ***** test ## 'VarNames' renames every variable of the output table Y = [1; 2; 3; 4]; Z = [10; 20; 30; 40]; G = {'a'; 'a'; 'b'; 'b'}; tbl = grpstats (table (Y, Z, G), 'G', 'mean', ... 'VarNames', {'grp', 'n', 'avgY', 'avgZ'}); assert_equal (tbl.Properties.VariableNames, {'grp', 'n', 'avgY', 'avgZ'}); assert_equal (tbl.n, [2; 2]); assert_equal (tbl.avgY, [1.5; 3.5]); assert_equal (tbl.avgZ, [15; 35]); ***** test ## Without 'VarNames' the output table keeps the default names Y = [1; 2; 3; 4]; G = {'a'; 'a'; 'b'; 'b'}; tbl = grpstats (table (Y, G), 'G', 'mean'); assert_equal (tbl.Properties.VariableNames, {'G', 'GroupCount', 'mean_Y'}); ***** test ## A function handle is applied to each column of each group assert_equal (grpstats ([1; 2; 3; 4], [1; 1; 2; 2], @mean), [1.5; 3.5]); x = [1, 10; 3, 20; 5, 30; 7, 40]; assert_equal (grpstats (x, [1; 1; 2; 2], @mean), [2, 15; 6, 35]); ***** test ## A function handle sees only the values that are not NaN assert_equal (grpstats ([1; 2; NaN; 4], [1; 1; 2; 2], @mean), [1.5; 4]); assert_equal (grpstats ([1; 2; NaN; 4], [1; 1; 2; 2], @numel), [2; 1]); x = [1, 10; 2, NaN; 3, 30; 4, 40]; assert_equal (grpstats (x, [1; 1; 1; 1], @mean), [2.5, 80/3], 1e-14); ***** test ## A function handle may be mixed with named statistics [m, s] = grpstats ([1; 2; 3; 4], [1; 1; 2; 2], {@mean, 'sem'}); assert_equal (m, [1.5; 3.5]); assert_equal (s, [0.5; 0.5]); ***** test ## An anonymous handle is applied like any other fcn = @(v) max (v) - min (v); assert_equal (grpstats ([1; 2; 3; 4], [1; 1; 2; 2], fcn), [1; 1]); assert_equal (size (grpstats (zeros (0, 3), zeros (0, 1), @mean)), [0, 3]); ***** test ## A table variable takes the handle by its own name, NaNs removed Y = [1; 2; NaN; 4]; G = {'a'; 'a'; 'b'; 'b'}; tbl = grpstats (table (Y, G), 'G', @mean); assert_equal (tbl.Properties.VariableNames, {'G', 'GroupCount', 'mean_Y'}); assert_equal (tbl.mean_Y, [1.5; 4]); tbl = grpstats (table (Y, G), 'G', @numel); assert_equal (tbl.numel_Y, [2; 1]); ***** test ## A table with no grouping variable is a single group named 'All' tbl = grpstats (table ([1; 2; 3], 'VariableNames', {'v'})); assert_equal (tbl.Properties.VariableNames, {'GroupCount', 'mean_v'}); assert_equal (tbl.Properties.RowNames, {'All'}); assert_equal (tbl.GroupCount, 3); assert_equal (tbl.mean_v, 2); ***** test ## Every variable of an ungrouped table is a data variable Y = [1; 2; 3; 4]; Z = [10; 20; 30; 40]; tbl = grpstats (table (Y, Z)); assert_equal (tbl.Properties.VariableNames, ... {'GroupCount', 'mean_Y', 'mean_Z'}); assert_equal (tbl.mean_Y, 2.5); assert_equal (tbl.mean_Z, 25); ***** test ## An ungrouped table takes WHICHSTATS and 'DataVars' as a grouped one does Y = [1; 2; 3; 4]; Z = [10; 20; 30; 40]; tbl = grpstats (table (Y, Z), [], {'mean', 'sem'}); assert_equal (tbl.Properties.VariableNames, ... {'GroupCount', 'mean_Y', 'sem_Y', 'mean_Z', 'sem_Z'}); assert_equal (tbl.sem_Y, 0.6454972243679028, 1e-14); tbl = grpstats (table (Y, Z), [], 'mean', 'DataVars', 'Y'); assert_equal (tbl.Properties.VariableNames, {'GroupCount', 'mean_Y'}); ***** test # MATLAB parity: a group per category, in category order, used or not g = categorical ({'hi'; 'hi'; 'lo'; 'lo'; 'hi'; 'lo'}, {'mid', 'lo', 'hi'}); m = grpstats ([1; 2; 5; 6; 3; 7], g); assert_equal (m, [NaN; 6; 2]); ***** error grpstats (ones (2, 2, 2)) ***** error ... [a, b] = grpstats (table (1)) ***** error ... grpstats (ones (6, 2), [1; 1; 1; 2; 2; 2], {'mean', 1.5}) ***** error ... grpstats (ones (6, 2), [1; 1; 1; 2; 2; 2], 1.5) ***** error ... grpstats (ones (6, 2), [1; 1; 1; 2; 2; 2], 'some_function') ***** error ... grpstats (ones (6, 2), [1; 1; 1; 2; 2; 2], 'mean', 35) ***** error ... grpstats ([1:4]', {'A'; 'B'; 'A'; 'B'}, 'predci', 'somename', -0.1); ***** error ... grpstats (ones (6, 2), [1; 1; 1; 2; 2; 2], 'mean', 'VarNames', 3) ***** error ... grpstats ({ones(6, 2)}, [], 0.05) ***** error ... grpstats ([1:4]', {'A'; 'B'; 'A'; 'B'}, 'predci', 'alpha', -0.1); ***** error ... grpstats (table ([1:5]'), {'Var_5'}) ***** error ... grpstats (table ([1:5]'), {'Var1'}, [], 'DataVars', 'Var5') ***** error ... grpstats (table ([1:5]', [1:5]'), {'Var1'}, [], 'VarNames', {'A', 'B'}) ***** error ... grpstats ([1:5]', {'A'; 'B'; 'A'; 'B'}) ***** error ... m = grpstats ([1:4]', {'A'; 'B'; 'A'; 'B'}, {'mean', 'std'}) ***** error ... [a, b, c, d, e] = grpstats ([1; 2; 3; 4], [1; 1; 2; 2]) ***** error ... grpstats (zeros (0, 3), zeros (0, 1), 0.05) ***** error ... grpstats ([1; 2; 3], [NaN; NaN; NaN], 0.05) ***** error ... grpstats ([1; 2; 3; 4], [1; 1; 2; 2], @(v) [min(v), max(v)]) 123 tests, 123 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/corr.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/corr.m ***** demo ## Correlation between the columns of a matrix, with p-values x = [1 2; 3 5; 4 4; 7 8; 9 6]; [rho, pval] = corr (x) ***** demo ## Spearman's rank correlation, which a monotone relation makes exact x = [1; 2; 3; 4; 5]; y = [1; 4; 9; 16; 25]; [rho, pval] = corr (x, y, 'Type', 'Spearman') ***** test # Pearson, one matrix x = [1 2; 3 5; 4 4; 7 8; 9 6]; [rho, pval] = corr (x); assert_equal (rho, [1, 0.80516104831610558; 0.80516104831610558, 1], 1e-14); assert_equal (pval, [1, 0.10016803410643096; 0.10016803410643096, 1], 1e-14); ***** test # Pearson, two matrices x = [1 2; 3 5; 4 4; 7 8; 9 6]; y = [2 1; 5 4; 4 3; 6 9; 8 7]; [rho, pval] = corr (x, y); assert_equal (rho, [0.94518905671890663, 0.87745098039215708; ... 0.79999999999999993, 0.98019605881960692], 1e-14); assert_equal (pval, [0.015276771734465051, 0.050541693400160549; ... 0.10408803866182803, 0.0033355462806318316], 1e-14); ***** test # the one-sided tails of the Pearson test x = [1; 3; 4; 7; 9]; y = [2; 5; 4; 8; 6]; [~, pboth] = corr (x, y); [~, pright] = corr (x, y, 'Tail', 'right'); [~, pleft] = corr (x, y, 'Tail', 'left'); assert_equal (pboth, 0.10016803410643098, 1e-14); assert_equal (pright, 0.050084017053215489, 1e-14); assert_equal (pleft, 0.94991598294678448, 1e-14); ***** test # Kendall's tau-b, exact below ten observations x = [1 2; 3 5; 4 4; 7 8; 9 6]; [rho, pval] = corr (x, 'Type', 'Kendall'); assert_equal (rho, [1, 0.6; 0.6, 1], 1e-14); assert_equal (pval, [1, 0.23333333333333334; 0.23333333333333334, 1], 1e-14); ***** test # Spearman's rho, exact below ten observations x = [1 2; 3 5; 4 4; 7 8; 9 6]; [rho, pval] = corr (x, 'Type', 'Spearman'); assert_equal (rho, [1, 0.79999999999999993; 0.79999999999999993, 1], 1e-14); assert_equal (pval, [1, 0.13333333333333333; 0.13333333333333333, 1], 1e-14); ***** test # the one-sided tails of the exact rank tests x = [1; 3; 4; 7; 9]; y = [2; 5; 4; 8; 6]; [~, pk] = corr (x, y, 'Type', 'Kendall', 'Tail', 'right'); [~, ps] = corr (x, y, 'Type', 'Spearman', 'Tail', 'left'); assert_equal (pk, 0.11666666666666667, 1e-14); assert_equal (ps, 0.95833333333333337, 1e-14); ***** test # tied values, where the exact p-value needs no correction x = [1 1; 2 1; 2 3; 4 3; 5 6; 5 6]; [rhok, pk] = corr (x, 'Type', 'Kendall'); [rhos, ps] = corr (x, 'Type', 'Spearman'); assert_equal (rhok(1,2), 0.88070484592797926, 1e-14); assert_equal (pk(1,2), 0.044444444444444446, 1e-14); assert_equal (rhos(1,2), 0.92318618234499539, 1e-14); assert_equal (ps(1,2), 0.044444444444444446, 1e-14); ***** test # nine observations, the largest sample the exact route covers x = (1:9)'; y = [3; 1; 4; 6; 5; 9; 2; 8; 7]; [rk, pk] = corr (x, y, 'Type', 'Kendall'); [rs, ps] = corr (x, y, 'Type', 'Spearman'); assert_equal (pk, 0.11943893298059964, 1e-14); assert_equal (ps, 0.096797839506172836, 1e-14); ***** test # twenty untied observations: Kendall is still exact, Spearman is AS 89 x = (1:20)'; y = mod ((1:20) * 7, 101)'; [~, pk] = corr (x, y, 'Type', 'Kendall'); [~, ps] = corr (x, y, 'Type', 'Spearman'); assert_equal (pk, 0.098330218734756586, 1e-12); assert_equal (ps, 0.65798513768943223, 1e-12); ***** test # sixty untied observations: the normal approximation takes over x = (1:60)'; y = mod ((1:60) * 7, 101)'; [~, pk] = corr (x, y, 'Type', 'Kendall'); [~, pkr] = corr (x, y, 'Type', 'Kendall', 'Tail', 'right'); assert_equal (pk, 0.15127746350184884, 1e-12); assert_equal (pkr, 0.075638731750924421, 1e-12); ***** test # AS 89 and its one-sided tails x = (1:60)'; y = mod ((1:60) * 7, 101)'; [~, ps] = corr (x, y, 'Type', 'Spearman'); [~, psr] = corr (x, y, 'Type', 'Spearman', 'Tail', 'right'); [~, psl] = corr (x, y, 'Type', 'Spearman', 'Tail', 'left'); assert_equal (ps, 0.49214166036069795, 1e-12); assert_equal (psr, 0.24607083018034898, 1e-12); assert_equal (psl, 0.75406296187189426, 1e-12); ***** test # tied values above the exact route: normal for tau, Student t for rho x = (1:30)'; y = mod ((1:30) * 7, 5)'; [~, pk] = corr (x, y, 'Type', 'Kendall'); [~, ps] = corr (x, y, 'Type', 'Spearman'); assert_equal (pk, 0.67454343834388397, 1e-12); assert_equal (ps, 0.66780132080922749, 1e-12); ***** test # 'Rows' 'complete' drops every row holding a NaN x = [1 2; NaN 5; 4 4; 7 NaN; 9 6]; [rho, pval] = corr (x, 'Rows', 'complete'); assert_equal (rho, [1, 0.98974331861078702; 0.98974331861078702, 1], 1e-14); assert_equal (pval, ... [1, 0.091257896685979945; 0.091257896685979945, 1], 1e-14); ***** test # 'Rows' 'pairwise' uses the rows each pair of columns shares x = [1 2; NaN 5; 4 4; 7 NaN; 9 6]; y = [2 1; 5 4; 4 3; 6 9; 8 7]; [rho, pval] = corr (x, y, 'Rows', 'pairwise'); assert_equal (rho, [0.99591000331047852, 0.88678890262741183; ... 0.95638207148956245, 0.95638207148956245], 1e-14); assert_equal (pval, [0.0040899966895214749, 0.11321109737258821; ... 0.043617928510437588, 0.043617928510437588], 1e-14); ***** test # the default keeps every row, so a NaN reaches its whole row and column x = [1 2; NaN 5; 4 4; 7 8; 9 6]; rho = corr (x); assert_equal (rho, [NaN, NaN; NaN, 1], 1e-14); ***** test # 'Weights' gives a weighted Pearson coefficient x = [1 2; 3 5; 4 4; 7 8; 9 6]; w = [0.5; 1.25; 2; 0.75; 1]; rho = corr (x, 'Weights', w); assert_equal (rho(1,2), 0.7498537417425275, 1e-14); ***** test # 'Weights' applies to the rank coefficients too x = [1 2; 3 5; 4 4; 7 8; 9 6]; w = [0.5; 1.25; 2; 0.75; 1]; rk = corr (x, 'Weights', w, 'Type', 'Kendall'); rs = corr (x, 'Weights', w, 'Type', 'Spearman'); assert_equal (rk(1,2), 0.43169398907103823, 1e-14); assert_equal (rs(1,2), 0.63438256658595638, 1e-14); ***** test # a weighted correlation has no p-value x = [1 2; 3 5; 4 4; 7 8; 9 6]; [~, pval] = corr (x, 'Weights', [0.5; 1.25; 2; 0.75; 1]); assert_equal (isnan (pval), true (2)); ***** test # a constant column has no correlation, its diagonal entry included x = [1 4; 3 4; 4 4; 7 4; 9 4]; [rho, pval] = corr (x); assert_equal (rho, [1, NaN; NaN, NaN], 1e-14); assert_equal (pval, [1, NaN; NaN, NaN], 1e-14); ***** test # two observations leave no degrees of freedom [rho, pval] = corr ([1; 2], [1; 3]); assert_equal (rho, 0.99999999999999989, 1e-14); assert_equal (isnan (pval), true); ***** test # single input gives a single result x = single ([1 2; 3 5; 4 4; 7 8; 9 6]); [rho, pval] = corr (x); assert_equal (class (rho), 'single'); assert_equal (class (pval), 'single'); assert_equal (rho, single ([1, 0.80516105890274048; ... 0.80516105890274048, 1]), single (1e-7)); ***** test # logical input is correlated as the numbers it stands for x = [1 2; 3 5; 4 4; 7 8; 9 6]; rho = corr (x > 4); assert_equal (rho(1,2), 0.66666666666666641, 1e-14); ***** test # an option value may be abbreviated and is matched without case x = [1 2; 3 5; 4 4; 7 8; 9 6]; assert_equal (corr (x, 'type', 'spear'), corr (x, 'Type', 'Spearman')); assert_equal (corr (x, 'Type', 'P'), corr (x)); ***** test # a Y without columns gives a result without columns x = [1 2; 3 5; 4 4; 7 8; 9 6]; [rho, pval] = corr (x, zeros (5, 0)); assert_equal (size (rho), [2, 0]); assert_equal (size (pval), [2, 0]); ***** test # a row vector is one observation of several variables, as in MATLAB assert_equal (corr ([1 2 3]), NaN (3)); assert_equal (corr (5), NaN); ***** error corr () ***** error corr ({1, 2, 3}) ***** error corr ('abcde') ***** error corr (ones (2, 2, 2)) ***** error corr (zeros (5, 0)) ***** error corr ([]) ***** error corr ([1; 2], {1, 2}) ***** error corr ([1; 2], ones (2, 2, 2)) ***** error ... corr (ones (5, 2), ones (4, 2)) ***** error ... corr (ones (5, 2), 'Foo', 1) ***** error ... corr (ones (5, 2), 'Type') ***** error ... corr (ones (5, 2), 'Type', 'foo') ***** error ... corr (ones (5, 2), 'Type', 5) ***** error ... corr (ones (5, 2), 'Rows', 'foo') ***** error ... corr (ones (5, 2), 'Tail', 'foo') ***** error ... corr (ones (5, 2), 'Weights', [1; 2]) ***** error ... corr (ones (5, 2), 'Weights', ones (1, 5)) ***** error ... corr (ones (5, 2), 'Weights', [1; -1; 1; 1; 1]) 43 tests, 43 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/partialcorri.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/partialcorri.m ***** demo ## Partial correlation of a response with each of two predictors, each ## adjusted for the other predictor. y = [-0.85; 0.33; 1.21; -0.19; 0.74; -1.44; 0.58; 0.02; 1.36]; x = [0.42 1.30; 1.15 -0.47; -0.98 0.55; 0.63 2.10; 1.88 -1.02; ... -0.31 0.86; 0.77 0.14; -1.52 1.77; 0.29 -0.63]; rho = partialcorri (y, x) ***** shared D, X, Y, Z D = [ 0.42 1.30 -0.85 0.11 2.04 1.15 -0.47 0.33 1.82 -0.62 -0.98 0.55 1.21 -0.34 0.77 0.63 2.10 -0.19 0.48 -1.15 1.88 -1.02 0.74 0.05 0.39 -0.31 0.86 -1.44 1.29 0.92 0.77 0.14 0.58 -0.71 1.63 -1.52 1.77 0.02 0.94 -0.28 0.29 -0.63 1.36 0.37 0.51 2.01 0.48 -0.77 -1.08 0.14 -0.44 1.05 0.91 0.66 -0.83 0.90 -0.29 -0.36 1.47 1.22]; X = D(:,1:2); Y = D(:,3); Z = D(:,4:5); ***** test [r, p] = partialcorri (Y, X, Z); assert_equal (r, [-0.7539, -0.8212], 1e-4); assert_equal (p, [0.0189, 0.0066], 1e-4); ***** test rho = partialcorr (D); assert_equal (partialcorri (Y, X, Z), rho(3,1:2), 1e-12); ***** test r = partialcorri (Y, X, Z, 'Type', 'Spearman'); assert_equal (r, [-0.8381, -0.8677], 1e-4); ***** test r1 = partialcorri ([D(:,3), D(:,4)], X, D(:,5)); assert_equal (r1, [-0.5444, -0.6714; -0.3517, -0.2830], 1e-4); r2 = partialcorri ([D(:,3), D(:,4)], X); assert_equal (r2, [-0.4740, -0.5784; -0.3098, -0.1934], 1e-4); ***** error ... partialcorri (ones (5), ones (5), ones (5), ones (5)) ***** error ... partialcorri (ones (10, 1), ones (10, 2), 'Type', 'Kendall') ***** error ... partialcorri (ones (10, 1), ones (8, 2)) 7 tests, 7 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/tabulate.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/tabulate.m ***** demo ## Generate a frequency table for a vector of data in a cell array load patients ## Display the first seven entries of the Gender variable gender = Gender(1:7) ## Compute the frequency table that shows the number and ## percentage of Male and Female patients tabulate (Gender) ***** demo ## Create a frequency table for a vector of positive integers load patients ## Display the first seven entries of the Gender variable height = Height(1:7) ## Create a frequency table that shows, in its second and third columns, ## the number and percentage of patients with a particular height. table = tabulate (Height); ## Display the first and last seven entries of the frequency table first = table(1:7,:) last = table(end-6:end,:) ***** demo ## Create a frequency table from a character array load carsmall ## Tabulate the data in the Origin variable, which shows the ## country of origin of each car in the data set tabulate (Origin) ***** demo ## Create a frequency table from a numeric vector with NaN values load carsmall ## The carsmall dataset contains measurements of 100 cars total_cars = length (MPG) ## For six cars, the MPG value is missing missingMPG = length (MPG(isnan (MPG))) ## Create a frequency table using MPG tabulate (MPG) table = tabulate (MPG); ## Only 94 cars were used valid_cars = sum (table(:,2)) ***** test load patients table = tabulate (Gender); assert_equal (table{1,1}, "Male"); assert_equal (table{2,1}, "Female"); assert_equal (table{1,2}, 47); assert_equal (table{2,2}, 53); ***** test load patients table = tabulate (Height); assert_equal (table(end-4,:), [68, 15, 15]); assert_equal (table(end-3,:), [69, 8, 8]); assert_equal (table(end-2,:), [70, 11, 11]); assert_equal (table(end-1,:), [71, 10, 10]); assert_equal (table(end,:), [72, 4, 4]); ***** test ## Test numeric vector including NaNs x = [1; 1; 2; 3; 1; NaN; 2]; tbl = tabulate (x); assert_equal (isnumeric (tbl), true); assert_equal (size (tbl), [3, 3]); assert_equal (tbl(:,1), [1; 2; 3]); assert_equal (tbl(:,2), [3; 2; 1]); assert_equal (tbl(:,3), [50; 33.3333; 16.6667], 3e-4); ***** test ## Test positive integers with gaps x = [1; 3; 3]; tbl = tabulate (x); assert_equal (isnumeric (tbl), true); assert_equal (size (tbl), [3, 3]); assert_equal (tbl(:,1), [1; 2; 3]); assert_equal (tbl(:,2), [1; 0; 2]); assert_equal (tbl(:,3), [33.3333; 0; 66.6667], 3e-4); ***** test ## Test logical inputs (should return cell array with '0'/'1') x = [true; false; true; true]; tbl = tabulate (x); assert_equal (iscell (tbl), true); assert_equal (size (tbl), [2, 3]); assert_equal (tbl(:,1), {'0'; '1'}); assert_equal ([tbl{:,2}]', [1; 3]); assert_equal ([tbl{:,3}]', [25; 75]); ***** test ## Test character array x = ['a'; 'b'; 'a']; tbl = tabulate (x); assert_equal (iscell (tbl), true); assert_equal (size (tbl), [2, 3]); assert_equal (tbl(:,1), {'a'; 'b'}); assert_equal ([tbl{:,2}]', [2; 1]); ***** test ## Test cell array of character vectors x = {'a', 'b', 'a'}; tbl = tabulate (x); assert_equal (iscell (tbl), true); assert_equal (size (tbl), [2, 3]); assert_equal (tbl(:,1), {'a'; 'b'}); assert_equal ([tbl{:,2}]', [2; 1]); ***** test ## Test string array with missing values x = string ({'a', 'b', 'a'}); x(4) = missing; tbl = tabulate (x); assert_equal (iscell (tbl), true); assert_equal (size (tbl), [2, 3]); assert_equal (tbl(:,1), {'a'; 'b'}); assert_equal ([tbl{:,2}]', [2; 1]); ***** test ## Test categorical array with undefined values and vacuous levels x = categorical ({'a', 'a', 'b'}, {'a', 'b', 'c'}); tbl = tabulate (x); assert_equal (iscell (tbl), true); assert_equal (size (tbl), [3, 3]); assert_equal (tbl(:,1), {'a'; 'b'; 'c'}); assert_equal ([tbl{:,2}]', [2; 1; 0]); assert_equal ([tbl{:,3}]', [66.6667; 33.3333; 0], 1e-3); ***** test ## Test empty input tbl = tabulate ([]); assert_equal (isempty (tbl), true); ***** test ## fisheriris (Categorical/CellStr) load fisheriris; tbl = tabulate (species); assert_equal (size (tbl), [3, 3]); assert_equal (tbl(:,1), {'setosa'; 'versicolor'; 'virginica'}); assert_equal ([tbl{:,2}]', [50; 50; 50]); assert_equal ([tbl{:,3}]', [33.3333; 33.3333; 33.3333], 1e-4); ***** test ## carsmall (Char/CellStr) load carsmall; tbl = tabulate (Origin); origins = tbl(:,1); counts = [tbl{:,2}]; assert_equal (counts(strcmp (origins, 'USA')), 69); assert_equal (counts(strcmp (origins, 'Japan')), 15); assert_equal (counts(strcmp (origins, 'Germany')), 9); assert_equal (counts(strcmp (origins, 'France')), 4); assert_equal (counts(strcmp (origins, 'Sweden')), 2); assert_equal (counts(strcmp (origins, 'Italy')), 1); ***** test ## patients (Logical) load patients; tbl = tabulate (Smoker); assert_equal (size (tbl), [2, 3]); assert_equal (tbl(:,1), {'0'; '1'}); assert_equal ([tbl{:,2}]', [66; 34]); ***** test ## patients (String) load patients; tbl = tabulate (Gender); vals = tbl(:,1); counts = [tbl{:,2}]; assert_equal (counts(strcmp (vals, 'Male')), 47); assert_equal (counts(strcmp (vals, 'Female')), 53); ***** test x = categorical ({'a','b','c'}); x(:) = categorical (missing); tbl = tabulate (x); assert_equal (iscell (tbl), true); assert_equal (size (tbl), [3, 3]); assert_equal ([tbl{:,2}]', [0; 0; 0]); assert_equal ([tbl{:,3}]', [NaN; NaN; NaN]); ***** test ## a zero count against a nonzero total is 0 per cent, not NaN x = categorical ({'a','b','c','a'}); x(2) = categorical (missing); tbl = tabulate (x); assert_equal ([tbl{:,2}]', [2; 0; 1]); assert_equal ([tbl{:,3}]', [200/3; 0; 100/3], 1e-12); ***** test x = categorical ({}, {'low','med','high'}); tbl = tabulate (x); assert_equal (iscell (tbl), true); assert_equal ([tbl{:,2}]', [0; 0; 0]); assert_equal ([tbl{:,3}]', [NaN; NaN; NaN]); ***** test x = string ({'a','b'}); x(:) = missing; tbl = tabulate (x); assert_equal (iscell (tbl), true); assert_equal (isempty (tbl), true); ***** test x = ['yes'; 'no'; 'yes']; tbl = tabulate (x); assert_equal (iscell (tbl), true); assert_equal (size (tbl), [2, 3]); assert_equal (tbl(:,1), {'yes'; 'no'}); assert_equal ([tbl{:,2}]', [2; 1]); assert_equal ([tbl{:,3}]', [66.6667; 33.3333], 1e-4); ***** error ... tabulate (repmat ('a', 3, 3, 3)) ***** error ... tabulate ([3, 3; 3, 3]) ***** error ... tabulate ({'3', '3'; '3', '3'}) ***** error ... tabulate ([true, true; false, true]) ***** error ... tabulate (categorical ([true, true; false, true])) ***** error ... tabulate (string ({'a', 'b'; 'a', 'c'})) ***** error ... tabulate ({3, 3, 3, 3}) 26 tests, 26 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/nansum.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/nansum.m ***** demo ## Find the column sums for a matrix with missing values., x = magic (3); x([1, 4, 7:9]) = NaN s = nansum (x) ***** demo ## Find the row sums for a matrix with missing values., x = magic (3); x([1, 4, 7:9]) = NaN s = nansum (x, 2) ***** demo ## Find the sum of all the values in a multidimensional array ## with missing values. x = reshape (1:30, [2, 5, 3]); x([10:12, 25]) = NaN s = nansum (x, 'all') ***** demo ## Find the sum of a multidimensional array with missing values over ## multiple dimensions. x = reshape (1:30, [2, 5, 3]); x([10:12, 25]) = NaN s = nansum (x, [2, 3]) ***** assert_equal (nansum ([]), 0) ***** assert_equal (nansum (zeros (0, 3)), [0, 0, 0]) ***** assert_equal (nansum (zeros (3, 0)), zeros (1, 0)) ***** assert_equal (nansum ([], 1), zeros (1, 0)) ***** assert_equal (nansum ([], 2), zeros (0, 1)) ***** assert_equal (size (nansum (ones (2, 0, 3, 2), 2)), [2, 1, 3, 2]) ***** assert_equal (nansum (NaN), 0) ***** assert_equal (nansum (NaN (3)), [0, 0, 0]) ***** assert_equal (nansum ([2 4 NaN 7]), 13) ***** assert_equal (nansum ([2 4 NaN Inf]), Inf) ***** assert_equal (nansum ([1 NaN 3; NaN 5 6; 7 8 NaN]), [8 13 9]) ***** assert_equal (nansum ([1 NaN 3; NaN 5 6; 7 8 NaN], 2), [4; 11; 15]) ***** assert_equal (nansum (uint8 ([2 4 1 7])), 14) ***** test x = magic (3); x([1 6:9]) = NaN; assert_equal (nansum (x), [7, 6, 0]) assert_equal (nansum (x, 2), [1; 8; 4]) ***** test x = reshape (1:24, [2, 4, 3]); x([5:6, 20]) = NaN; assert_equal (nansum (x, 'all'), 269) ***** test x = reshape (1:24,[2, 4, 3]); x([5:6, 20]) = NaN; assert_equal (squeeze (nansum (x, [1, 2])), [25; 100; 144]) assert_equal (nansum (x, [2, 3]), [139; 130]) ***** error nansum ({3}) ***** error nansum (ones (3), 0) ***** error nansum (ones (3), 1.5) ***** error nansum (ones (3), 1.5) ***** error ... nansum (ones (3, 3, 3), [2, 2.5]) ***** error ... nansum (ones (3, 3, 3), [-1, 2]) ***** error ... nansum (ones (3, 3, 3), [2, 2, 3]) 23 tests, 23 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/cdfcalc.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/cdfcalc.m ***** test x = [2, 4, 3, 2, 4, 3, 2, 5, 6, 4]; [yCDF, xCDF, n, emsg, eid] = cdfcalc (x); assert_equal (yCDF, [0, 0.3, 0.5, 0.8, 0.9, 1]'); assert_equal (xCDF, [2, 3, 4, 5, 6]'); assert_equal (n, 10); ***** shared x x = [2, 4, 3, 2, 4, 3, 2, 5, 6, 4]; ***** error yCDF = cdfcalc (x); ***** error [yCDF, xCDF] = cdfcalc (); ***** error [yCDF, xCDF] = cdfcalc (x, x); ***** warning [yCDF, xCDF] = cdfcalc (ones (10,2)); 5 tests, 5 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/ksdensity.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/ksdensity.m ***** demo ## Kernel density estimate of a small sample, with a histogram for reference x = [1 1.5 2 2 2.5 3 3.5 3.5 4 6]; [f, xi] = ksdensity (x); hist (x, 6, 6 / numel (x)); hold on; plot (xi, f, 'r-', 'LineWidth', 2); hold off; ***** test # density integrates to ~1 over a wide grid (normal kernel) x = [2.1 0.3 1.2 -0.7 0.9 1.5 2.8 0.1 0.4 1.1 3.2 0.6 2.0 0.9 1.7]; [f, xi] = ksdensity (x, "NumPoints", 4000); assert_equal (trapz (xi, f), 1, 5e-3); ***** test # every named compact kernel integrates to ~1 x = randn (1, 200); for k = {"box", "triangle", "epanechnikov"} xi = linspace (-8, 8, 6000)'; f = ksdensity (x, xi, "Kernel", k{1}); assert_equal (trapz (xi, f), 1, 1e-2); endfor ***** test # cdf is monotone from 0 to 1 and matches the analytic normal-kernel sum x = [2.1 0.3 1.2 -0.7 0.9 1.5 2.8 0.1 0.4 1.1 3.2 0.6 2.0 0.9 1.7]; [F, xi] = ksdensity (x, "Function", "cdf", "NumPoints", 500); assert_equal (all (diff (F) >= -1e-12), true); assert_equal (F(1), 0, 5e-3); assert_equal (F(end), 1, 5e-3); [~, ~, bw] = ksdensity (x); Fdirect = mean (normcdf ((xi(:) - x) / bw), 2)'; assert_equal (F, Fdirect, 1e-12); ***** test x = [2.1 0.3 1.2 -0.7 0.9 1.5 2.8 0.1 0.4 1.1 3.2 0.6 2.0 0.9 1.7]; [f, xi] = ksdensity (x); assert_equal (size (f), [1, 100]); assert_equal (size (xi), [1, 100]); ***** test ## a column of data still gives a row grid x = [2.1 0.3 1.2 -0.7 0.9 1.5 2.8 0.1 0.4 1.1 3.2 0.6 2.0 0.9 1.7]'; [f, xi] = ksdensity (x, 'NumPoints', 500); assert_equal (size (f), [1, 500]); assert_equal (size (xi), [1, 500]); ***** test ## supplied points keep their own orientation, and F follows them x = [2.1 0.3 1.2 -0.7 0.9 1.5 2.8 0.1 0.4 1.1 3.2 0.6 2.0 0.9 1.7]; [f, xi] = ksdensity (x, [0 0.5 1 1.5 2]); assert_equal (size (f), [1, 5]); assert_equal (size (xi), [1, 5]); [f, xi] = ksdensity (x, [0; 0.5; 1; 1.5; 2]); assert_equal (size (f), [5, 1]); assert_equal (size (xi), [5, 1]); ***** test # survivor and cumhazard are consistent with the cdf x = [2.1 0.3 1.2 -0.7 0.9 1.5 2.8 0.1 0.4 1.1 3.2 0.6 2.0 0.9 1.7]; pts = [-1 0 1 2 3]'; F = ksdensity (x, pts, "Function", "cdf"); S = ksdensity (x, pts, "Function", "survivor"); H = ksdensity (x, pts, "Function", "cumhazard"); assert_equal (S, 1 - F, 1e-12); assert_equal (H, -log (1 - F), 1e-12); ***** test # icdf inverts the cdf x = [2.1 0.3 1.2 -0.7 0.9 1.5 2.8 0.1 0.4 1.1 3.2 0.6 2.0 0.9 1.7]; p = [0.1 0.25 0.5 0.75 0.9]'; q = ksdensity (x, p, "Function", "icdf"); Fq = ksdensity (x, q, "Function", "cdf"); assert_equal (Fq, p, 5e-3); ***** test # evaluation at supplied points preserves shape x = randn (1, 50); pts = [-1 0 1]; f = ksdensity (x, pts); assert_equal (size (f), size (pts)); ***** test # weights: a duplicated point equals a doubled weight x = [0 1 2 3]; pts = linspace (-2, 5, 40)'; f1 = ksdensity ([x, 3], pts, "Bandwidth", 0.5); f2 = ksdensity (x, pts, "Bandwidth", 0.5, "Weights", [1 1 1 2]); assert_equal (f1, f2, 1e-12); ***** test # MATLAB parity: the bandwidth when the robust scale vanishes load fisheriris pw = meas(strcmp (species, 'setosa'), 4); assert_equal (median (abs (pw - median (pw))), 0); [~, ~, bw] = ksdensity (pw); assert_equal (bw, 0.242194206816745, 1e-12); [~, ~, bw] = ksdensity ([1; 1; 1; 1; 1; 1; 1; 2; 3; 0]); assert_equal (bw, 2.004975185874807, 1e-12); [~, ~, bw] = ksdensity ([5; 5; 5; 5; 5; 5; 5; 5; 5; 9]); assert_equal (bw, 2.673300247833076, 1e-12); ***** test # MATLAB parity: data with no spread at all takes a bandwidth of one [~, ~, bw] = ksdensity (repmat (2, 10, 1)); assert_equal (bw, 1); ***** test # MATLAB parity: default bandwidth, grid size and range x = [2.1 0.3 1.2 -0.7 0.9 1.5 2.8 0.1 0.4 1.1 3.2 0.6 2.0 0.9 1.7]; [~, xi, bw] = ksdensity (x); assert_equal (bw, 0.6396, 5e-4); assert_equal (numel (xi), 100); assert_equal ([xi(1), xi(end)], [-2.6187, 5.1187], 1e-3); ***** test # MATLAB parity: pdf (normal and box kernels) and cdf at fixed points x = [2.1 0.3 1.2 -0.7 0.9 1.5 2.8 0.1 0.4 1.1 3.2 0.6 2.0 0.9 1.7]; pts = [-0.5 0 0.5 1 1.5 2 2.5 3]; assert_equal (ksdensity (x, pts), ... [0.1214 0.2141 0.3051 0.3394 0.3061 0.2375 0.1697 0.1166], 2e-3); assert_equal (ksdensity (x, pts, "Kernel", "box"), ... [0.1505 0.2407 0.2708 0.3611 0.3009 0.2708 0.1805 0.1204], 2e-3); assert_equal (ksdensity (x, pts, "Function", "cdf"), ... [0.0710 0.1538 0.2850 0.4492 0.6128 0.7494 0.8506 0.9217], 2e-3); ***** test # MATLAB parity: positive support (log) bandwidth, grid and pdf y = [0.2 0.5 0.7 1.1 1.4 2 2.6 3.3 4.1 5.5]; ypts = [0.1 0.3 0.6 1 2 3 4 5]; [~, xy, by] = ksdensity (y, "Support", "positive"); assert_equal (by, 0.7682, 5e-4); assert_equal ([xy(1), xy(end)], [0.0200, 55.1111], 1e-3); assert_equal (ksdensity (y, ypts, "Support", "positive"), ... [0.4300 0.4620 0.3620 0.2740 0.1570 0.0990 0.0660 0.0450], 2e-3); ***** test # MATLAB parity: positive support with reflection boundary correction y = [0.2 0.5 0.7 1.1 1.4 2 2.6 3.3 4.1 5.5]; ypts = [0.1 0.3 0.6 1 2 3 4 5]; f = ksdensity (y, ypts, "Support", "positive", ... "BoundaryCorrection", "reflection"); assert_equal (f, [0.2920 0.2900 0.2810 0.2620 0.2010 0.1470 0.1070 0.0740], 2e-3); ***** test # bounded support integrates to ~1 and vanishes outside the bounds y = [0.2 0.5 0.7 1.1 1.4 2 2.6 3.3]; [f, xi] = ksdensity (y, "Support", [0 4], "NumPoints", 4000); assert_equal (trapz (xi, f), 1, 5e-3); assert_equal (all (xi >= 0 & xi <= 4), true); ***** test # reflection density is confined to the support y = [0.2 0.5 0.7 1.1 1.4 2 2.6 3.3]; f = ksdensity (y, [-1 -0.1 5], "Support", "positive", ... "BoundaryCorrection", "reflection"); assert_equal (f(1:2), [0 0]); ***** test ## The lower tail with an upper bound only, below the resolution of 1 - cdf f = ksdensity (1:5, -60, 'Support', [-Inf, 10], 'Function', 'cdf'); I = integral (@(t) ksdensity (1:5, t, 'Support', [-Inf, 10]), -Inf, -60); assert_equal (f, I, -1e-8); ***** error ksdensity () ***** error ksdensity (ones (3, 3)) ***** error ... ksdensity (5) ***** error ... ksdensity (1:10, "Kernel", "cosine") ***** error ... ksdensity (1:10, "Function", "hazard") ***** error ... ksdensity (1:10, "Bandwidth", -1) ***** error ... ksdensity (1:10, "Weights", [1 2 3]) ***** error ... ksdensity (1:10, "Support", "half") ***** error ... ksdensity (1:10, "Support", [2 1]) ***** error ... ksdensity ([-1 1 2 3], "Support", "positive") ***** error ... ksdensity (1:10, "Support", "positive", "BoundaryCorrection", "linear") ***** error ... ksdensity (1:10, "Censoring", ones (1, 10)) 31 tests, 31 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/nanstd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/nanstd.m ***** demo ## Find the column standard deviations for a matrix with missing values. x = magic (3); x([1, 6:9]) = NaN s = nanstd (x) ***** demo ## Find the row standard deviations, normalized by N instead of N-1. x = magic (3); x([1, 6:9]) = NaN s = nanstd (x, 1, 2) ***** assert_equal (nanstd ([]), NaN) ***** assert_equal (nanstd (NaN), NaN) ***** assert_equal (nanstd (5), 0) ***** assert_equal (nanstd ([1 2 NaN; 4 NaN 6; 7 8 9; 10 11 12]), ... sqrt ([15, 21, 9]), 1e-14) ***** assert_equal (nanstd ([1 2 NaN; 4 NaN 6; 7 8 9; 10 11 12], 1), ... sqrt ([11.25, 14, 6]), 1e-14) ***** assert_equal (nanstd ([1 2 NaN; 4 NaN 6; 7 8 9; 10 11 12], 0, 2), ... sqrt ([0.5; 2; 1; 1]), 1e-14) ***** assert_equal (nanstd (NaN (2, 3)), [NaN, NaN, NaN]) ***** assert_equal (nanstd (zeros (0, 3)), [NaN, NaN, NaN]) ***** assert_equal (nanstd (zeros (3, 0)), zeros (1, 0)) ***** assert_equal (nanstd ([], 1), NaN) ***** assert_equal (nanstd ([], [], 1), zeros (1, 0)) ***** assert_equal (size (nanstd (ones (2, 0, 3, 2), 0, 2)), [2, 1, 3, 2]) ***** error nanstd () ***** error nanstd ({3}) 14 tests, 14 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/harmmean.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/harmmean.m ***** test x = [0:10]; y = [x;x+5;x+10]; assert_equal (harmmean (x), 0); m = [0 8.907635160795225 14.30854471766802]; assert_equal (harmmean (y, 2), m', 4e-14); assert_equal (harmmean (y, 'all'), 0); y(2,4) = NaN; m(2) = 9.009855936313949; assert_equal (harmmean (y, 2), [0 NaN m(3)]', 4e-14); assert_equal (harmmean (y', 'omitnan'), m, 4e-14); z = y + 20; assert_equal (harmmean (z, 'all'), NaN); assert_equal (harmmean (z, 'all', 'includenan'), NaN); assert_equal (harmmean (z, 'all', 'omitnan'), 29.1108719858295, 4e-14); m = [24.59488458841874 NaN 34.71244385944397]; assert_equal (harmmean (z'), m, 4e-14); assert_equal (harmmean (z', 'includenan'), m, 4e-14); m(2) = 29.84104075528277; assert_equal (harmmean (z', 'omitnan'), m, 4e-14); assert_equal (harmmean (z, 2, 'omitnan'), m', 4e-14); ***** test x = repmat ([1:20;6:25], [5 2 6 3]); assert_equal (size (harmmean (x, [3 2])), [10 1 1 3]); assert_equal (size (harmmean (x, [1 2])), [1 1 6 3]); assert_equal (size (harmmean (x, [1 2 4])), [1 1 6]); assert_equal (size (harmmean (x, [1 4 3])), [1 40]); assert_equal (size (harmmean (x, [1 2 3 4])), [1 1]); ***** test x = repmat ([1:20;6:25], [5 2 6 3]); m = repmat ([5.559045930488016;13.04950789021461], [5 1 1 3]); assert_equal (harmmean (x, [3 2]), m, 4e-14); x(2,5,6,3) = NaN; m(2,3) = NaN; assert_equal (harmmean (x, [3 2]), m, 4e-14); m(2,3) = 13.06617961315406; assert_equal (harmmean (x, [3 2], 'omitnan'), m, 4e-14); ***** test assert_equal (harmmean ([Inf, Inf]), Inf); assert_equal (harmmean ([Inf, Inf], 'all'), Inf); assert_equal (harmmean ([Inf, Inf], 2), Inf); assert_equal (harmmean ([NaN, Inf], 'omitnan'), Inf); assert_equal (harmmean ([NaN, Inf], 'includenan'), NaN); assert_equal (harmmean ([0, Inf]), 0); ***** test assert_equal (harmmean ([0, NaN]), NaN); assert_equal (harmmean ([0, NaN], 'all'), NaN); assert_equal (harmmean ([0, NaN], [1, 2]), NaN); assert_equal (harmmean ([0, NaN], 'omitnan'), 0); assert_equal (harmmean ([0, NaN], 'all', 'omitnan'), 0); ***** test a = harmmean ([]); assert_equal (isnan (a), true); assert_equal (size (a), [1, 1]); ***** assert_equal (harmmean (ones (2, 0, 3, 2)), ones (1, 0, 3, 2)) ***** assert_equal (harmmean (ones (2, 0, 3, 2), [1, 2]), NaN (1, 1, 3, 2)) ***** assert_equal (harmmean (ones (2, 0, 3, 2), 'all'), NaN) ***** assert_equal (harmmean (ones (2, 0, 3, 2), 1), ones (1, 0, 3, 2)) ***** assert_equal (harmmean (ones (2, 0, 3, 2), 2), NaN (2, 1, 3, 2)) ***** assert_equal (harmmean (ones (2, 0, 3, 2), 3), ones (2, 0, 1, 2)) ***** assert_equal (harmmean (ones (2, 0, 3, 2), 4), ones (2, 0, 3)) ***** assert_equal (harmmean ([], 1), ones (1, 0)) ***** assert_equal (harmmean ([], 2), ones (0, 1)) ***** assert_equal (harmmean ([], 3), []) ***** error harmmean ('char') ***** error harmmean ([1 -1 3]) ***** error ... harmmean (repmat ([1:20;6:25], [5 2 6 3 5]), -1) ***** error ... harmmean (repmat ([1:20;6:25], [5 2 6 3 5]), 0) ***** error ... harmmean (repmat ([1:20;6:25], [5 2 6 3 5]), [1 1]) ***** error ... harmmean ([1, 2; 3, 4], 1, 'all') ***** error ... harmmean ([1, 2; 3, 4], [1, 2], 'all') ***** error ... harmmean ([1 2 4], Inf) ***** error ... harmmean ([1 2 4], [1 Inf]) ***** error ... harmmean ([1 2 4], [Inf 1]) ***** error ... harmmean ([1 2 4], [Inf Inf]) 27 tests, 27 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/nanvar.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/nanvar.m ***** demo ## Find the column variances for a matrix with missing values. x = magic (3); x([1, 6:9]) = NaN v = nanvar (x) ***** demo ## Find the row variances, normalized by N instead of N-1. x = magic (3); x([1, 6:9]) = NaN v = nanvar (x, 1, 2) ***** assert_equal (nanvar ([]), NaN) ***** assert_equal (nanvar (NaN), NaN) ***** assert_equal (nanvar (5), 0) ***** assert_equal (nanvar ([2, 4, NaN, 8]), 9.333333333333334, 1e-14) ***** assert_equal (nanvar ([1 2 NaN; 4 NaN 6; 7 8 9; 10 11 12]), [15, 21, 9]) ***** assert_equal (nanvar ([1 2 NaN; 4 NaN 6; 7 8 9; 10 11 12], 1), [11.25, 14, 6]) ***** assert_equal (nanvar ([1 2 NaN; 4 NaN 6; 7 8 9; 10 11 12], 0, 2), ... [0.5; 2; 1; 1]) ***** assert_equal (nanvar ([1 2 NaN; 4 NaN 6; 7 8 9; 10 11 12], [1 2 3 4]'), ... [9, 8.4375, 50/9], 1e-13) ***** assert_equal (nanvar (NaN (2, 3)), [NaN, NaN, NaN]) ***** assert_equal (nanvar (zeros (0, 3)), [NaN, NaN, NaN]) ***** assert_equal (nanvar (zeros (3, 0)), zeros (1, 0)) ***** assert_equal (nanvar ([], 1), NaN) ***** assert_equal (nanvar ([], [], 1), zeros (1, 0)) ***** assert_equal (size (nanvar (ones (2, 0, 3, 2), 0, 2)), [2, 1, 3, 2]) ***** test x = reshape (1:24, [2, 4, 3]); x([5:6, 20]) = NaN; assert_equal (nanvar (x, 0, 'all'), nanvar (x(! isnan (x))(:)), 1e-12) ***** error nanvar () ***** error nanvar ({3}) ***** error nanvar (ones (3), 2) ***** error ... nanvar (ones (1, 3), [1, -1, 2]) ***** error nanvar (ones (3), 0, 1.5) ***** error ... nanvar (ones (3, 3, 3), 0, [2, 2, 3]) ***** error ... nanvar (ones (2, 3), [1, 2], 'all') ***** error ... nanvar (ones (2, 3), [1, 2, 3], 1) 23 tests, 23 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/trimmean.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/trimmean.m ***** test x = reshape (1:40, [5, 4, 2]); x([3, 37]) = -100; assert_equal (trimmean (x, 10, 'all'), 19.4722, 1e-4); ***** test x = reshape (1:40, [5, 4, 2]); x([3, 37]) = -100; out = trimmean (x, 10, [1, 2]); assert_equal (out(1,1,1), 10.3889, 1e-4); assert_equal (out(1,1,2), 29.6111, 1e-4); ***** test x = reshape (1:40, [5, 4, 2]); x([3, 37]) = -100; x([4, 38]) = NaN; assert_equal (trimmean (x, 10, 'all'), 19.3824, 1e-4); ***** test x = reshape (1:40, [5, 4, 2]); x([3, 37]) = -100; out = trimmean (x, 10, 1); assert_equal (out(:,:,1), [-17.6, 8, 13, 18]); assert_equal (out(:,:,2), [23, 28, 33, 10.6]); ***** test x = reshape (1:40, [5, 4, 2]); x([3, 37]) = -100; x([4, 38]) = NaN; out = trimmean (x, 10, 1); assert_equal (out(:,:,1), [-23, 8, 13, 18]); assert_equal (out(:,:,2), [23, 28, 33, 3.75]); ***** test x = reshape (1:40, [5, 4, 2]); x([3, 37]) = -100; out = trimmean (x, 10, 2); assert_equal (out(:,:,1), [8.5; 9.5; -15.25; 11.5; 12.5]); assert_equal (out(:,:,2), [28.5; -4.75; 30.5; 31.5; 32.5]); ***** test x = reshape (1:40, [5, 4, 2]); x([3, 37]) = -100; x([4, 38]) = NaN; out = trimmean (x, 10, 2); assert_equal (out(:,:,1), [8.5; 9.5; -15.25; 14; 12.5]); assert_equal (out(:,:,2), [28.5; -4.75; 28; 31.5; 32.5]); ***** test x = reshape (1:40, [5, 4, 2]); x([3, 37]) = -100; out = trimmean (x, 10, [1, 2, 3]); assert_equal (out, trimmean (x, 10, 'all')); ***** test x = reshape (1:40, [5, 4, 2]); x([3, 37]) = -100; x([4, 38]) = NaN; out = trimmean (x, 10, [1, 2]); assert_equal (out(1,1,1), 10.7647, 1e-4); assert_equal (out(1,1,2), 29.1176, 1e-4); ***** test x = reshape (1:40, [5, 4, 2]); x([3, 37]) = -100; x([4, 38]) = NaN; out = trimmean (x, 10, [1, 3]); assert_equal (out, [2.5556, 18, 23, 11.6667], 1e-4); ***** test x = reshape (1:40, [5, 4, 2]); x([3, 37]) = -100; x([4, 38]) = NaN; out = trimmean (x, 10, [2, 3]); assert_equal (out, [18.5; 2.3750; 3.2857; 24; 22.5], 1e-4); ***** test x = reshape (1:40, [5, 4, 2]); x([3, 37]) = -100; x([4, 38]) = NaN; out = trimmean (x, 10, [1, 2, 3]); assert_equal (out, trimmean (x, 10, 'all')); ***** test x = reshape (1:40, [5, 4, 2]); x([3, 37]) = -100; x([4, 38]) = NaN; out = trimmean (x, 10, [2, 3, 5]); assert_equal (out, [18.5; 2.3750; 3.2857; 24; 22.5], 1e-4); ***** assert_equal (trimmean ([1, 2, 3, 4, 5], 40), 3) ***** assert_equal (trimmean (reshape (1:40, [5, 4, 2]), 10, 4), reshape (1:40, [5, 4, 2])) ***** assert_equal (trimmean ([], 10), NaN) ***** assert_equal (trimmean ([1;2;3;4;5], 10, 2), [1;2;3;4;5]) ***** test ## Row vector with explicit dimension 1 assert_equal (trimmean ([1, 2, 3], 10, 1), [1, 2, 3]); ***** test ## Row vector with explicit dimension 2 assert_equal (trimmean ([1, 2, 3], 10, 2), 2); ***** test ## Empty array with non-operating dimension preserved (dim=1) assert_equal (trimmean (zeros (0, 5), 10, 1), NaN (1, 5)); ***** test ## Empty array with non-operating dimension preserved (dim=2) assert_equal (trimmean (zeros (2, 0), 10, 2), NaN (2, 1)); ***** error trimmean (1) ***** error trimmean (1,2,3,4,5) ***** error ... trimmean ([1 2 3 4], -10) ***** error ... trimmean ([1 2 3 4], 100) ***** error ... trimmean ([1 2 3 4], [10, 20]) ***** error ... trimmean ([1 2 3 4], []) ***** error ... trimmean ([1 2 3 4], 10 + 2i) ***** error trimmean ([1 2 3 4], 10, 'flag') ***** error trimmean ([1 2 3 4], 10, 'flag', 1) ***** error ... trimmean ([1 2 3 4], 10, -1) ***** error ... trimmean ([1 2 3 4], 10, 'floor', -1) ***** error ... trimmean (reshape (1:40, [5, 4, 2]), 10, [-1, 2]) ***** error ... trimmean (reshape (1:40, [5, 4, 2]), 10, [1, 2, 2]) 34 tests, 34 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/cl_multinom.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/cl_multinom.m ***** demo CL = cl_multinom ([27; 43; 19; 11], 10000, 0.05) ***** error cl_multinom (); ***** error cl_multinom (1, 2, 3, 4, 5); ***** error ... cl_multinom (1, 2, 3, 4); ***** error ... cl_multinom (1, 2, 3, 'some string'); 4 tests, 4 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/dcov.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/dcov.m ***** demo rng (42); base=@(x) (x- min (x))./(max (x)-min (x)); N = 5e2; x = randn (N,1); x = base(x); z = randn (N,1); z = base(z); # Linear relations cy = [1 0.55 0.3 0 -0.3 -0.55 -1]; ly = x .* cy; ly(:,[1:3 5:end]) = base(ly(:,[1:3 5:end])); # Correlated Gaussian cz = 1 - abs (cy); gy = base( ly + cz.*z); # Shapes sx = repmat (x,1,7); sy = zeros (size (ly)); v = 2 * rand (size (x,1),2) - 1; sx(:,1) = v(:,1); sy(:,1) = cos (2*pi*sx(:,1)) + 0.5*v(:,2).*exp (-sx(:,1).^2/0.5); R =@(d) [cosd(d) sind(d); -sind(d) cosd(d)]; tmp = R(35) * v.'; sx(:,2) = tmp(1,:); sy(:,2) = tmp(2,:); tmp = R(45) * v.'; sx(:,3) = tmp(1,:); sy(:,3) = tmp(2,:); sx(:,4) = v(:,1); sy(:,4) = sx(:,4).^2 + 0.5*v(:,2); sx(:,5) = v(:,1); sy(:,5) = 3*sign (v(:,2)).*(sx(:,5)).^2 + v(:,2); sx(:,6) = cos (2*pi*v(:,1)) + 0.5*(x-0.5); sy(:,6) = sin (2*pi*v(:,1)) + 0.5*(z-0.5); sx(:,7) = x + sign (v(:,1)); sy(:,7) = z + sign (v(:,2)); sy = base(sy); sx = base(sx); # scaled shape sc = 1/3; ssy = (sy-0.5) * sc + 0.5; n = size (ly,2); ym = 1.2; xm = 0.5; fmt={'horizontalalignment','center'}; ff = '% .2f'; figure (1) for i=1:n subplot (4,n,i); plot (x, gy(:,i), '.b'); axis tight axis off text (xm,ym,sprintf (ff, dcov (x,gy(:,i))),fmt{:}) subplot (4,n,i+n); plot (x, ly(:,i), '.b'); axis tight axis off text (xm,ym,sprintf (ff, dcov (x,ly(:,i))),fmt{:}) subplot (4,n,i+2*n); plot (sx(:,i), sy(:,i), '.b'); axis tight axis off text (xm,ym,sprintf (ff, dcov (sx(:,i),sy(:,i))),fmt{:}) v = axis (); subplot (4,n,i+3*n); plot (sx(:,i), ssy(:,i), '.b'); axis (v) axis off text (xm,ym,sprintf (ff, dcov (sx(:,i),ssy(:,i))),fmt{:}) endfor ***** error dcov (randn (30, 5), randn (25,5)) 1 test, 1 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/jackknife.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/jackknife.m ***** demo rng (42); for k = 1:1000 x = rand (10, 1); s(k) = std (x); jackstat = jackknife (@std, x); j(k) = 10 * std (x) - 9 * mean (jackstat); endfor figure (); hist ([s', j'], 0:sqrt (1/12)/10:2*sqrt (1/12)) ***** demo rng (42); for k = 1:1000 x = randn (1, 50); y = rand (1, 50); jackstat = jackknife (@(x) std (x{1})/std (x{2}), y, x); j(k) = 50 * std (y) / std (x) - 49 * mean (jackstat); v(k) = sumsq ((50 * std (y) / std (x) - 49 * jackstat) - j(k)) / (50 * 49); endfor t = (j - sqrt (1 / 12)) ./ sqrt (v); figure (); plot (sort (tcdf (t, 49)), ... '-;Almost linear mapping indicates good fit with t-distribution.;') ***** demo ## Jackknife the correlation of two samples, each handed to the estimator ## as an argument of its own, and correct it for bias rng (42); x = randn (30, 1); y = x + randn (30, 1); n = numel (x); r = corr (x, y); jackstat = jackknife (@(a, b) corr (a, b), x, y); bias = (n - 1) * (mean (jackstat) - r) se = sqrt ((n - 1) / n * sumsq (jackstat - mean (jackstat))) r_corrected = r - bias ***** test ##Example from Quenouille, Table 1 d=[0.18 4.00 1.04 0.85 2.14 1.01 3.01 2.33 1.57 2.19]; jackstat = jackknife ( @(x) 1/mean (x), d ); assert_equal ( 10 / mean (d) - 9 * mean (jackstat), 0.5240, 1e-5 ); ***** test ## Empty input assert_equal (jackknife (@mean, []), NaN); ***** test ## Single-element input assert_equal (jackknife (@mean, 5), 5); ***** test ## Estimator returning multiple values expected = [2.5, sqrt(0.5); 2.0, sqrt(2); 1.5, sqrt(0.5)]; jackstat = jackknife (@(x) [mean(x); std(x)], [1 2 3]); assert_equal (jackstat, expected, 1e-5); ***** test ## Each row of a matrix is an observation assert_equal (jackknife (@mean, magic (3)), ... [3.5, 7, 4.5; 6, 5, 4; 5.5, 3, 6.5]); ***** test assert_equal (jackknife (@mean, [1, 2; 3, 4; 5, 7]), ... [4, 5.5; 3, 4.5; 2, 3]); ***** test ## A row vector is a column of observations assert_equal (jackknife (@mean, [1, 2, 3]), [2.5; 2; 1.5]); ***** test ## An estimate is reshaped to a row x = [1, 2, 3; 4, 5, 6; 7, 8, 10]; assert_equal (jackknife (@(v) [v(1), v(end)], x), [4, 10; 1, 10; 1, 6]); ***** test assert_equal (jackknife (@(v) sum (v(:)) * ones (2, 2), [1, 2, 3, 4]), ... [9, 9, 9, 9; 8, 8, 8, 8; 7, 7, 7, 7; 6, 6, 6, 6]); ***** test assert_equal (jackknife (@mean, zeros (1, 0)), NaN); ***** test assert_equal (jackknife (@(x) [mean(x); std(x)], []), [NaN, NaN]); ***** test assert_equal (jackknife (@(x) [mean(x); std(x)], 5), [5, 0]); ***** test assert_equal (jackknife (@(x) mean (x) > 2, [1, 2, 3]), ... [true; false; false]); ***** test assert_equal (jackknife (@mean, single ([1, 2, 3])), single ([2.5; 2; 1.5])); ***** test assert_equal (jackknife ('mean', [1, 2, 3]), [2.5; 2; 1.5]); ***** test assert_equal (jackknife (@mean, [1, 2, 3], 'Options', statset ()), ... [2.5; 2; 1.5]); ***** test ## Several samples reach a one-input estimator as a cell array assert_equal (jackknife (@(x) mean (x{1}) - mean (x{2}), [1, 2, 3], ... [4, 5, 7]), [-3.5; -3.5; -3]); ***** test ## and any other estimator as arguments of their own assert_equal (jackknife (@(a, b) mean (a) - mean (b), [1, 2, 3], ... [4; 5; 7]), [-3.5; -3.5; -3]); ***** test assert_equal (jackknife (@(varargin) numel (varargin), [1, 2, 3], ... [4, 5, 7]), [2; 2; 2]); ***** test ## A scalar is passed unchanged assert_equal (jackknife (@(a, b) a + mean (b), 5, [1, 2, 3]), ... [7.5; 7; 6.5]); ***** test assert_equal (jackknife (@(a, b, c) mean (a) * b + mean (c), ... [1, 2, 3], 2, [4, 5, 7]), [11; 9.5; 7.5]); ***** test x = [1, 2; 3, 4; 5, 6]; assert_equal (jackknife (@(a, b) mean (a, 1) + b, x, 10), ... [14, 15; 13, 14; 12, 13]); ***** test assert_equal (jackknife (@(a, b) [mean(a), mean(b)], [1, 2, 3], ... [4, 5, 7]), [2.5, 6; 2, 5.5; 1.5, 4.5]); ***** test assert_equal (jackknife (@(a, b) a + b, 5, 6), 11); ***** test assert_equal (jackknife (@(a, b) sum (a) + b, [], 1), 1); ***** test assert_equal (jackknife (@(a, b) mean (a) - mean (b), [1, 2, 3], ... [4, 5, 7], 'Options', statset ()), ... [-3.5; -3.5; -3]); ***** test assert_equal (jackknife (@(x) mean (x{1}) + mean (x{2}), 5, 6), 11); ***** error jackknife (@mean) ***** error ... jackknife (1, [1, 2, 3]) ***** error ... jackknife (@mean, [1, 2, 3], 'Options', 1) ***** error ... jackknife (@(x) mean (x{1}), [1, 2, 3], [4, 5]) ***** error ... jackknife (@(a, b) mean (a), [1, 2], [4; 5; 7]) ***** error ... jackknife (@(v) v, [1, 2, 3]) 33 tests, 33 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/nanmean.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/nanmean.m ***** demo ## Find the column means for a matrix with missing values., x = magic (3); x([1, 4, 7:9]) = NaN y = nanmean (x) ***** demo ## Find the row means for a matrix with missing values., x = magic (3); x([1, 4, 7:9]) = NaN y = nanmean (x, 2) ***** demo ## Find the mean of all the values in a multidimensional array ## with missing values. x = reshape (1:30, [2, 5, 3]); x([10:12, 25]) = NaN y = nanmean (x, 'all') ***** demo ## Find the mean of a multidimensional array with missing values over ## multiple dimensions. x = reshape (1:30, [2, 5, 3]); x([10:12, 25]) = NaN y = nanmean (x, [2, 3]) ***** assert_equal (nanmean ([]), NaN) ***** assert_equal (nanmean (zeros (0, 3)), [NaN, NaN, NaN]) ***** assert_equal (nanmean (zeros (3, 0)), zeros (1, 0)) ***** assert_equal (nanmean ([], 1), zeros (1, 0)) ***** assert_equal (nanmean ([], 2), zeros (0, 1)) ***** assert_equal (size (nanmean (ones (2, 0, 3, 2), 2)), [2, 1, 3, 2]) ***** assert_equal (nanmean (NaN), NaN) ***** assert_equal (nanmean (NaN (3)), [NaN, NaN, NaN]) ***** assert_equal (nanmean ([3 2 NaN 7]), 4) ***** assert_equal (nanmean ([2 4 NaN Inf]), Inf) ***** assert_equal (nanmean ([1 NaN 3; NaN 4 6; 7 8 NaN]), [4 6 4.5]) ***** assert_equal (nanmean ([1 NaN 3; NaN 5 6; 7 8 NaN], 2), [2; 5.5; 7.5]) ***** assert_equal (nanmean (uint8 ([2 4 1 7])), 3.5) ***** test x = magic (3); x([1 6:9]) = NaN; assert_equal (nanmean (x), [3.5, 3, NaN]) assert_equal (nanmean (x, 2), [1; 4; 4]) ***** test x = reshape (1:24, [2, 4, 3]); x([5:6, 20]) = NaN; assert_equal (nanmean (x, 'all'), 269/21) ***** test x = reshape (1:24,[2, 4, 3]); x([5:6, 20]) = NaN; assert_equal (squeeze (nanmean (x, [1, 2])), [25/6; 100/8; 144/7]) assert_equal (nanmean (x, [2, 3]), [139/11; 13]) ***** error nanmean () ***** error nanmean ("str") ***** error nanmean (ones (3), 0) ***** error nanmean (ones (3), "invalid") ***** error nanmean (ones (3), [1, -1]) 21 tests, 21 passed, 0 known failure, 0 skipped [inst/Descriptive_Statistics/mvksdensity.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Descriptive_Statistics/mvksdensity.m ***** demo ## Bivariate kernel density estimate over a grid, drawn as a contour plot. rng (42); x = [randn(60, 2); randn(40, 2) + 3]; [gx, gy] = meshgrid (linspace (-4, 7, 60)); f = mvksdensity (x, [gx(:), gy(:)]); contourf (gx, gy, reshape (f, size (gx))); hold on; plot (x(:,1), x(:,2), 'k.'); hold off; title ('Bivariate kernel density estimate'); ***** shared X, pts X = [1 1; 2 1; 1 2; 3 2; 2 3; 4 3; 3 4; 5 4]; pts = [2 2; 3 3; 1 1; 4 4]; ***** test ## MATLAB parity: default (robust normal-reference) bandwidth assert_equal (mvksdensity (X, pts), ... [0.0569998; 0.0520004; 0.0448930; 0.0382812], 1e-6); ***** test ## MATLAB parity: fixed vector and scalar bandwidth (normal kernel) assert_equal (mvksdensity (X, pts, "Bandwidth", [1 1]), ... [0.0589; 0.0535; 0.0474; 0.0395], 1e-3); assert_equal (mvksdensity (X, pts, "Bandwidth", 1), ... mvksdensity (X, pts, "Bandwidth", [1 1])); ***** test ## MATLAB parity: box and epanechnikov product kernels assert_equal (mvksdensity (X, pts, "Bandwidth", [1 1], "Kernel", "box"), ... [0.0521; 0.0417; 0.0313; 0.0313], 1e-3); assert_equal (mvksdensity (X, pts, "Bandwidth", [1 1], ... "Kernel", "epanechnikov"), [0.0585; 0.0523; 0.0411; 0.0383], 1e-3); ***** test ## MATLAB parity: cumulative distribution and weighted estimate assert_equal (mvksdensity (X, pts, "Bandwidth", [1 1], "Function", "cdf"), ... [0.2144; 0.4504; 0.0520; 0.6893], 1e-3); assert_equal (mvksdensity (X, pts, "Bandwidth", [1 1], ... "Weights", [2 1 1 1 1 1 1 1]), [0.0588; 0.0479; 0.0598; 0.0351], 1e-3); ***** test ## the density integrates to ~1 over a wide grid [gx, gy] = meshgrid (linspace (-6, 11, 220)); f = mvksdensity (X, [gx(:), gy(:)]); dx = gx(1,2) - gx(1,1); assert_equal (sum (f) * dx ^ 2, 1, 1e-2); ***** test xz = [1, 2.3; 1, 3.1; 1, 4.8; 1, 5.5; 1, 6.1; 3, 7.9; 5, 8.2; 9, 9.4]; f = mvksdensity (xz, [3, 4; 5, 6]); assert_equal (f, [0.006520360257529; 0.006588943731769], 1e-12); ***** test xc = [2, 2.3; 2, 3.1; 2, 4.8; 2, 5.5; 2, 6.1; 2, 7.9; 2, 8.2; 2, 9.4]; f = mvksdensity (xc, [3, 4; 5, 6]); assert_equal (f, [0.024910428037417; 0.000582734811254], 1e-12); assert_equal (f, mvksdensity (xc, [3, 4; 5, 6], 'Bandwidth', [1, 1]), 1e-12); ***** test xh = [1.1, 2.3; 2.4, 3.1; 3.9, 4.8; 4.2, 5.5; 5.7, 6.1; 6.3, 7.9; ... 7.1, 8.2; 8.8, 9.4]; assert_equal (mvksdensity (xh, [3, 4; 5, 6]), ... [0.014366107896069; 0.016985761603336], 1e-12); ***** test x3 = [1.1, 5.2, 2.3; 2.4, 6.1, 3.1; 3.9, 4.4, 4.8; 4.2, 7.7, 5.5; ... 5.7, 5.9, 6.1; 6.3, 8.3, 7.9; 7.1, 6.6, 8.2; 8.8, 9.1, 9.4]; f = mvksdensity (x3, [3, 6, 4; 5, 7, 6]); assert_equal (size (f), [2, 1]); assert_equal (all (f > 0), true); ***** error mvksdensity (ones (3, 2)) ***** error ... mvksdensity (ones (2, 2, 2), [1 1]) ***** error ... mvksdensity ([1 2], [1 1]) ***** error ... mvksdensity ([1 1; 2 2], [1 1 1]) ***** error ... mvksdensity ([1 1; 2 2], [1 1], "Bandwidth") ***** error ... mvksdensity ([1 1; 2 2], [1 1], "Kernel", "cosine") ***** error ... mvksdensity ([1 1; 2 2], [1 1], "Function", "icdf") ***** error ... mvksdensity ([1 1; 2 2], [1 1], "Bandwidth", [1 2 3]) ***** error ... mvksdensity ([1 1; 2 2], [1 1], "Bandwidth", -1) ***** error ... mvksdensity ([1 1; 2 2], [1 1], "Weights", [1 2 3]) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/ricelike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/ricelike.m ***** test nlogL = ricelike ([15.3057344, 17.6668458], [1:50]); assert_equal (nlogL, 204.5230311010569, 1e-12); ***** test nlogL = ricelike ([2.312346885, 1.681228265], [1:5]); assert_equal (nlogL, 8.65562164930058, 1e-12); ***** error ricelike (3.25) ***** error ricelike ([5, 0.2], ones (2)) ***** error ... ricelike ([1, 0.2, 3], [1, 3, 5, 7]) ***** error ... ricelike ([1.5, 0.2], [1:5], [0, 0, 0]) ***** error ... ricelike ([1.5, 0.2], [1:5], [0, 0, 0, 0, 0], [1, 1, 1]) ***** error ... ricelike ([1.5, 0.2], [1:5], [], [1, 1, 1]) ***** error ... ricelike ([1.5, 0.2], [1:5], [], [1, 1, 1, 0, -1]) 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/betafit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/betafit.m ***** demo ## Sample 2 populations from different Beta distributions randg ('state', 42); r1 = betarnd (2, 5, 500, 1); r2 = betarnd (2, 2, 500, 1); r = [r1, r2]; ## Plot them normalized and fix their colors hist (r, 12, 15); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); hold on ## Estimate their shape parameters a_b_A = betafit (r(:,1)); a_b_B = betafit (r(:,2)); ## Plot their estimated PDFs x = [min(r(:)):0.01:max(r(:))]; y = betapdf (x, a_b_A(1), a_b_A(2)); plot (x, y, '-pr'); y = betapdf (x, a_b_B(1), a_b_B(2)); plot (x, y, '-sg'); ylim ([0, 4]) legend ({'Normalized HIST of sample 1 with α=2 and β=5', ... 'Normalized HIST of sample 2 with α=2 and β=2', ... sprintf("PDF for sample 1 with estimated α=%0.2f and β=%0.2f", ... a_b_A(1), a_b_A(2)), ... sprintf("PDF for sample 2 with estimated α=%0.2f and β=%0.2f", ... a_b_B(1), a_b_B(2))}) title ('Two population samples from different Beta distributions') hold off ***** test x = 0.01:0.02:0.99; [paramhat, paramci] = betafit (x); paramhat_out = [1.0199, 1.0199]; paramci_out = [0.6947, 0.6947; 1.4974, 1.4974]; assert_equal (paramhat, paramhat_out, 1e-4); assert_equal (paramci, paramci_out, 1e-4); ***** test x = 0.01:0.02:0.99; [paramhat, paramci] = betafit (x, 0.01); paramci_out = [0.6157, 0.6157; 1.6895, 1.6895]; assert_equal (paramci, paramci_out, 1e-4); ***** test x = 0.00:0.02:1; [paramhat, paramci] = betafit (x); paramhat_out = [0.0875, 0.1913]; paramci_out = [0.0822, 0.1490; 0.0931, 0.2455]; assert_equal (paramhat, paramhat_out, 1e-4); assert_equal (paramci, paramci_out, 1e-4); ***** error betafit ([0.2, 0.5+i]); ***** error betafit (ones (2,2) * 0.5); ***** error betafit ([0.5, 1.2]); ***** error betafit ([0.1, 0.1]); ***** error betafit ([0.01:0.1:0.99], 1.2); ***** error ... betafit ([0.01:0.01:0.05], 0.05, [1, 2, 3, 2]); ***** error ... betafit ([0.01:0.01:0.05], 0.05, [1, 2, 3, 2, -1]); ***** error ... betafit ([0.01:0.01:0.05], 0.05, [1, 2, 3, 2, 1.5]); ***** error ... betafit ([0.01:0.01:0.05], 0.05, struct ('option', 234)); ***** error ... betafit ([0.01:0.01:0.05], 0.05, ones (1,5), struct ('option', 234)); 13 tests, 13 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/gamlike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/gamlike.m ***** test [nlogL, acov] = gamlike ([2, 3], [2, 3, 4, 5, 6, 7, 8, 9]); assert_equal (nlogL, 19.4426, 1e-4); assert_equal (acov, [2.7819, -5.0073; -5.0073, 9.6882], 1e-4); ***** test [nlogL, acov] = gamlike ([2, 3], [5:45]); assert_equal (nlogL, 305.8070, 1e-4); assert_equal (acov, [0.0423, -0.0087; -0.0087, 0.0167], 1e-4); ***** test [nlogL, acov] = gamlike ([2, 13], [5:45]); assert_equal (nlogL, 163.2261, 1e-4); assert_equal (acov, [0.2362, -1.6631; -1.6631, 13.9440], 1e-4); ***** error ... gamlike ([12, 15]) ***** error gamlike ([12, 15, 3], [1:50]) ***** error gamlike ([12, 3], ones (10, 2)) ***** error ... gamlike ([12, 15], [1:50], [1, 2, 3]) ***** error ... gamlike ([12, 15], [1:50], [], [1, 2, 3]) 8 tests, 8 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/lognfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/lognfit.m ***** demo ## Sample 3 populations from 3 different log-normal distributions rng (42); r1 = lognrnd (0, 0.25, 1000, 1); r2 = lognrnd (0, 0.5, 1000, 1); r3 = lognrnd (0, 1, 1000, 1); r = [r1, r2, r3]; ## Plot them normalized and fix their colors hist (r, 30, 2); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); set (h(3), 'facecolor', 'r'); hold on ## Estimate their mu and sigma parameters mu_sigmaA = lognfit (r(:,1)); mu_sigmaB = lognfit (r(:,2)); mu_sigmaC = lognfit (r(:,3)); ## Plot their estimated PDFs x = [0:0.1:6]; y = lognpdf (x, mu_sigmaA(1), mu_sigmaA(2)); plot (x, y, '-pr'); y = lognpdf (x, mu_sigmaB(1), mu_sigmaB(2)); plot (x, y, '-sg'); y = lognpdf (x, mu_sigmaC(1), mu_sigmaC(2)); plot (x, y, '-^c'); ylim ([0, 2]) xlim ([0, 6]) hold off legend ({'Normalized HIST of sample 1 with mu=0, σ=0.25', ... 'Normalized HIST of sample 2 with mu=0, σ=0.5', ... 'Normalized HIST of sample 3 with mu=0, σ=1', ... sprintf("PDF for sample 1 with estimated mu=%0.2f and σ=%0.2f", ... mu_sigmaA(1), mu_sigmaA(2)), ... sprintf("PDF for sample 2 with estimated mu=%0.2f and σ=%0.2f", ... mu_sigmaB(1), mu_sigmaB(2)), ... sprintf("PDF for sample 3 with estimated mu=%0.2f and σ=%0.2f", ... mu_sigmaC(1), mu_sigmaC(2))}, 'location', 'northeast') title ('Three population samples from different log-normal distributions') hold off ***** test randn ('seed', 1); x = lognrnd (3, 5, [1000, 1]); [paramhat, paramci] = lognfit (x, 0.01); assert_equal (paramci(1,1) < 3, true); assert_equal (paramci(1,2) > 3, true); assert_equal (paramci(2,1) < 5, true); assert_equal (paramci(2,2) > 5, true); ***** error ... lognfit (ones (20,3)) ***** error ... lognfit ({1, 2, 3, 4, 5}) ***** error ... lognfit ([-1, 2, 3, 4, 5]) ***** error lognfit (ones (20,1), 0) ***** error lognfit (ones (20,1), -0.3) ***** error lognfit (ones (20,1), 1.2) ***** error lognfit (ones (20,1), [0.05, 0.1]) ***** error lognfit (ones (20,1), 0.02+i) ***** error ... lognfit (ones (20,1), [], zeros (15,1)) ***** error ... lognfit (ones (20,1), [], zeros (20,1), ones (25,1)) ***** error lognfit (ones (20,1), [], zeros (20,1), ones (20,1), 'options') 12 tests, 12 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/nbinlike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/nbinlike.m ***** assert_equal (nbinlike ([2.42086, 0.0867043], [1:50]), 205.5942, 1e-4) ***** assert_equal (nbinlike ([3.58823, 0.254697], [1:20]), 63.6435, 1e-4) ***** assert_equal (nbinlike ([8.80671, 0.615565], [1:10]), 24.7410, 1e-4) ***** assert_equal (nbinlike ([22.1756, 0.831306], [1:8]), 17.9528, 1e-4) ***** assert_equal (nbinlike ([22.1756, 0.831306], [1:9], [ones(1,8), 0]), 17.9528, 1e-4) ***** error nbinlike (3.25) ***** error nbinlike ([5, 0.2], ones (2)) ***** error nbinlike ([5, 0.2], [-1, 3]) ***** error ... nbinlike ([1, 0.2, 3], [1, 3, 5, 7]) ***** error nbinlike ([-5, 0.2], [1:15]) ***** error nbinlike ([0, 0.2], [1:15]) ***** error nbinlike ([5, 1.2], [3, 5]) ***** error nbinlike ([5, -0.2], [3, 5]) ***** error ... nbinlike ([5, 0.2], ones (10, 1), ones (8,1)) ***** error ... nbinlike ([5, 0.2], ones (1, 8), [1 1 1 1 1 1 1 -1]) ***** error ... nbinlike ([5, 0.2], ones (1, 8), [1 1 1 1 1 1 1 1.5]) 16 tests, 16 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/gpfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/gpfit.m ***** demo ## Sample 2 populations from different generalized Pareto distributions ## Assume location parameter θ is known rng (42); theta = 0; r1 = gprnd (1, 2, theta, 20000, 1); r2 = gprnd (3, 1, theta, 20000, 1); r = [r1, r2]; ## Plot them normalized and fix their colors hist (r, [0.1:0.2:100], 5); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'r'); set (h(2), 'facecolor', 'c'); ylim ([0, 1]); xlim ([0, 5]); hold on ## Estimate their α and β parameters k_sigmaA = gpfit (r(:,1)); k_sigmaB = gpfit (r(:,2)); ## Plot their estimated PDFs x = [0.01, 0.1:0.2:18]; y = gppdf (x, k_sigmaA(1), k_sigmaA(2), theta); plot (x, y, '-pc'); y = gppdf (x, k_sigmaB(1), k_sigmaB(2), theta); plot (x, y, '-sr'); hold off legend ({'Normalized HIST of sample 1 with k=1 and σ=2', ... 'Normalized HIST of sample 2 with k=2 and σ=2', ... sprintf("PDF for sample 1 with estimated k=%0.2f and σ=%0.2f", ... k_sigmaA(1), k_sigmaA(2)), ... sprintf("PDF for sample 3 with estimated k=%0.2f and σ=%0.2f", ... k_sigmaB(1), k_sigmaB(2))}) title ('Two population samples from different generalized Pareto distributions') text (2, 0.7, 'Known location parameter θ = 0') hold off ***** shared x x = [2.2196, 11.9301, 4.3673, 1.0949, 6.5626, ... 1.2109, 1.8576, 1.0039, 12.7917, 2.2590]; ***** test [hat, ci] = gpfit (x); assert_equal (hat, [-0.163107819293798, 5.305483917184919], 1e-4); assert_equal (ci, [-1.174106637867584, 1.627748133572634; ... 0.847890999279987, 17.292699659699391], 1e-4); ***** test [hat, ci] = gpfit (x, 0.10); assert_equal (ci, [-1.011564773958192, 1.968276868273005; ... 0.685349135370595, 14.300914698146826], 1e-4); ***** test ## a known location is fitted by shifting the data, and only shifts the fit [hat, ci] = gpfit (x - 1); assert_equal (hat, [0.893710299404345, 1.322962458731574], 1e-6); assert_equal (ci, [-0.774991092191746, 0.243695078371714; ... 2.562411691000436, 7.182047659343478], 1e-5); ***** assert_equal (size (gpfit (x)), [1, 2]) ***** test [~, ci] = gpfit (x); assert_equal (size (ci), [2, 2]); ***** test ## the default confidence level is 95% [h1, c1] = gpfit (x); [h2, c2] = gpfit (x, 0.05); assert_equal (h1, h2); assert_equal (c1, c2); ***** test ## FREQ counts repeated observations assert_equal (gpfit (x, [], [], [2, ones(1,9)]), gpfit ([x(1), x]), 1e-10); ***** test ## non-finite data propagates into the estimates instead of being dropped assert_equal (gpfit ([x, NaN]), [NaN, NaN]); warning: gpfit: reached evaluation limit. warning: called from gpfit at line 199 column 7 __test__ at line 4 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 982 column 2 ***** test assert_equal (gpfit ([x, Inf]), [NaN, NaN]); warning: gpfit: reached evaluation limit. warning: called from gpfit at line 199 column 7 __test__ at line 3 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 982 column 2 ***** test assert_equal (gpfit ([x, NaN, Inf]), [NaN, NaN]); warning: gpfit: reached evaluation limit. warning: called from gpfit at line 199 column 7 __test__ at line 3 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 982 column 2 ***** test ## below a shape of -1 the likelihood is unbounded, but the estimate still ## keeps every observation strictly inside the fitted support xb = [1.2 2.3 0.5 3.1 2.2 1.8 0.9 2.7 1.1 3.3]; warning ('off', 'all'); p = gpfit (xb); warning ('on', 'all'); assert_equal (p(1) < -1, true); assert_equal (max (xb) < -p(2) / p(1), true); assert_equal (isfinite (gplike (p, xb)), true); warning: concatenation of single and double quoted string objects creates a single quoted string object warning: called from assert_equal at line 93 column 3 __test__ at line 9 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 982 column 2 warning: concatenation of single and double quoted string objects creates a single quoted string object warning: called from assert_equal at line 93 column 3 __test__ at line 10 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 982 column 2 warning: concatenation of single and double quoted string objects creates a single quoted string object warning: called from assert_equal at line 93 column 3 __test__ at line 11 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 982 column 2 ***** test ## the confidence intervals are withheld there warning ('off', 'all'); [~, ci] = gpfit ([1.2 2.3 0.5 3.1 2.2 1.8 0.9 2.7 1.1 3.3]); warning ('on', 'all'); assert_equal (ci, [NaN, NaN; NaN, NaN]); warning: concatenation of single and double quoted string objects creates a single quoted string object warning: called from assert_equal at line 93 column 3 __test__ at line 7 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 982 column 2 ***** warning ... gpfit ([1.2 2.3 0.5 3.1 2.2 1.8 0.9 2.7 1.1 3.3]); ***** error gpfit () ***** error gpfit ([0.2, 0.5+i]); ***** error gpfit (ones (2,2) * 0.5); ***** error gpfit ([-1, 2, 3]); ***** error gpfit ([0.01:0.1:0.99], 1.2); ***** error gpfit ([0.01:0.1:0.99], i); ***** error gpfit ([0.01:0.1:0.99], -1); ***** error gpfit ([0.01:0.1:0.99], [0.05, 0.01]); ***** error ... gpfit ([1 2 3], [], [], [1 5]) ***** error ... gpfit ([1 2 3], [], [], [1 5 -1]) ***** error ... gpfit ([1:10], 0.05, 5) 24 tests, 24 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/nakalike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/nakalike.m ***** test nlogL = nakalike ([0.735504, 858.5], [1:50]); assert_equal (nlogL, 202.8689, 1e-4); ***** test nlogL = nakalike ([1.17404, 11], [1:5]); assert_equal (nlogL, 8.6976, 1e-4); ***** test nlogL = nakalike ([1.17404, 11], [1:5], [], [1, 1, 1, 1, 1]); assert_equal (nlogL, 8.6976, 1e-4); ***** test nlogL = nakalike ([1.17404, 11], [1:6], [], [1, 1, 1, 1, 1, 0]); assert_equal (nlogL, 8.6976, 1e-4); ***** error nakalike (3.25) ***** error nakalike ([5, 0.2], ones (2)) ***** error ... nakalike ([1, 0.2, 3], [1, 3, 5, 7]) ***** error ... nakalike ([1.5, 0.2], [1:5], [0, 0, 0]) ***** error ... nakalike ([1.5, 0.2], [1:5], [0, 0, 0, 0, 0], [1, 1, 1]) ***** error ... nakalike ([1.5, 0.2], [1:5], [], [1, 1, 1]) ***** error ... nakalike ([1.5, 0.2], [1:5], [], [1, 1, 1, 1, -1]) 11 tests, 11 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/tlsfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/tlsfit.m ***** demo ## Sample 3 populations from 3 different location-scale T distributions rng (42); randg ('state', 42); r1 = tlsrnd (-4, 3, 1, 2000, 1); r2 = tlsrnd (0, 3, 1, 2000, 1); r3 = tlsrnd (5, 5, 4, 2000, 1); r = [r1, r2, r3]; ## Plot them normalized and fix their colors hist (r, [-21:21], [1, 1, 1]); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); set (h(3), 'facecolor', 'r'); ylim ([0, 0.25]); xlim ([-20, 20]); hold on ## Estimate their lambda parameter mu_sigma_nuA = tlsfit (r(:,1)); mu_sigma_nuB = tlsfit (r(:,2)); mu_sigma_nuC = tlsfit (r(:,3)); ## Plot their estimated PDFs x = [-20:0.1:20]; y = tlspdf (x, mu_sigma_nuA(1), mu_sigma_nuA(2), mu_sigma_nuA(3)); plot (x, y, '-pr'); y = tlspdf (x, mu_sigma_nuB(1), mu_sigma_nuB(2), mu_sigma_nuB(3)); plot (x, y, '-sg'); y = tlspdf (x, mu_sigma_nuC(1), mu_sigma_nuC(2), mu_sigma_nuC(3)); plot (x, y, '-^c'); hold off legend ({'Normalized HIST of sample 1 with μ=0, σ=2 and nu=1', ... 'Normalized HIST of sample 2 with μ=5, σ=2 and nu=1', ... 'Normalized HIST of sample 3 with μ=3, σ=4 and nu=3', ... sprintf("PDF for sample 1 with estimated μ=%0.2f, σ=%0.2f, and ν=%0.2f", ... mu_sigma_nuA(1), mu_sigma_nuA(2), mu_sigma_nuA(3)), ... sprintf("PDF for sample 2 with estimated μ=%0.2f, σ=%0.2f, and ν=%0.2f", ... mu_sigma_nuB(1), mu_sigma_nuB(2), mu_sigma_nuB(3)), ... sprintf("PDF for sample 3 with estimated μ=%0.2f, σ=%0.2f, and ν=%0.2f", ... mu_sigma_nuC(1), mu_sigma_nuC(2), mu_sigma_nuC(3))}) title ('Three population samples from different location-scale T distributions') hold off ***** test x = [-1.2352, -0.2741, 0.1726, 7.4356, 1.0392, 16.4165]; [paramhat, paramci] = tlsfit (x); paramhat_out = [0.035893, 0.862711, 0.649261]; paramci_out = [-0.949034, 0.154655, 0.181080; 1.02082, 4.812444, 2.327914]; assert_equal (paramhat, paramhat_out, 1e-6); assert_equal (paramci, paramci_out, 1e-5); ***** test x = [-1.2352, -0.2741, 0.1726, 7.4356, 1.0392, 16.4165]; [paramhat, paramci] = tlsfit (x, 0.01); paramci_out = [-1.2585, 0.0901, 0.1212; 1.3303, 8.2591, 3.4771]; assert_equal (paramci, paramci_out, 1e-4); ***** error tlsfit (ones (2,5)); ***** error tlsfit ([1, 2, 3, 4, 5], 1.2); ***** error tlsfit ([1, 2, 3, 4, 5], 0); ***** error tlsfit ([1, 2, 3, 4, 5], 'alpha'); ***** error ... tlsfit ([1, 2, 3, 4, 5], 0.05, [1 1 0]); ***** error ... tlsfit ([1, 2, 3, 4, 5], [], [1 1 0 1 1]'); ***** error ... tlsfit ([1, 2, 3, 4, 5], 0.05, zeros (1,5), [1 1 0]); ***** error ... tlsfit ([1, 2, 3, 4, 5], [], [], [1 1 0 1 1]'); ***** error ... tlsfit ([1, 2, 3, 4, 5], [], [], [1 1 0 1 -1]); ***** error ... tlsfit ([1, 2, 3, 4, 5], 0.05, [], [], 2); ***** warning ... opt = struct ('Display', 'off', 'MaxFunEvals', 1, 'MaxIter', 200, ... 'TolX', 1e-6); tlsfit ([1, 2, 3, 4, 5, 6, 7, 8], 0.05, [], [], opt); ***** warning ... opt = struct ('Display', 'off', 'MaxFunEvals', 400, 'MaxIter', 1, ... 'TolX', 1e-6); tlsfit ([1, 2, 3, 4, 5, 6, 7, 8], 0.05, [], [], opt); 14 tests, 14 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/unidfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/unidfit.m ***** demo ## Sample 2 populations from different discrete uniform distributions rng (42); r1 = unidrnd (5, 1000, 1); r2 = unidrnd (9, 1000, 1); r = [r1, r2]; ## Plot them normalized and fix their colors hist (r, 0:0.5:20.5, 1); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); hold on ## Estimate their probability of success NhatA = unidfit (r(:,1)); NhatB = unidfit (r(:,2)); ## Plot their estimated PDFs x = [0:10]; y = unidpdf (x, NhatA); plot (x, y, '-pg'); y = unidpdf (x, NhatB); plot (x, y, '-sc'); xlim ([0, 10]) ylim ([0, 0.4]) legend ({'Normalized HIST of sample 1 with N=5', ... 'Normalized HIST of sample 2 with N=9', ... sprintf("PDF for sample 1 with estimated N=%0.2f", NhatA), ... sprintf("PDF for sample 2 with estimated N=%0.2f", NhatB)}) title ('Two population samples from different discrete uniform distributions') hold off ***** test x = 0:5; [Nhat, Nci] = unidfit (x); assert_equal (Nhat, 5); assert_equal (Nci, [5; 9]); ***** test x = 0:5; [Nhat, Nci] = unidfit (x, [], [1 1 1 1 1 1]); assert_equal (Nhat, 5); assert_equal (Nci, [5; 9]); ***** assert_equal (unidfit ([1 1 2 3]), unidfit ([1 2 3], [] ,[2 1 1])) ***** error unidfit () ***** error unidfit (-1, [1 2 3 3]) ***** error unidfit (1, 0) ***** error unidfit (1, 1.2) ***** error unidfit (1, [0.02 0.05]) ***** error ... unidfit ([1.5, 0.2], [], [0, 0, 0, 0, 0]) ***** error ... unidfit ([1.5, 0.2], [], [1, 1, 1]) ***** error ... unidfit ([1.5, 0.2], [], [1, -1]) 11 tests, 11 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/hnlike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/hnlike.m ***** test x = 1:20; paramhat = hnfit (x, 0); [nlogL, acov] = hnlike (paramhat, x); assert_equal (nlogL, 64.179177404891300, 1e-14); ***** test x = 1:20; paramhat = hnfit (x, 0); [nlogL, acov] = hnlike (paramhat, x, ones (1, 20)); assert_equal (nlogL, 64.179177404891300, 1e-14); ***** error ... hnlike ([12, 15]); ***** error hnlike ([12, 15, 3], [1:50]); ***** error hnlike ([3], [1:50]); ***** error ... hnlike ([0, 3], ones (2)); ***** error ... hnlike ([0, 3], [1, 2, 3, 4, 5+i]); ***** error ... hnlike ([1, 2], ones (10, 1), ones (8,1)) ***** error ... hnlike ([1, 2], ones (1, 8), [1 1 1 1 1 1 1 -1]) 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/explike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/explike.m ***** test x = 12; beta = 5; [L, V] = explike (beta, x); expected_L = 4.0094; expected_V = 6.5789; assert_equal (L, expected_L, 0.001); assert_equal (V, expected_V, 0.001); ***** test x = 1:5; beta = 2; [L, V] = explike (beta, x); expected_L = 10.9657; expected_V = 0.4; assert_equal (L, expected_L, 0.001); assert_equal (V, expected_V, 0.001); ***** error explike () ***** error explike (2) ***** error explike ([12, 3], [1:50]) ***** error explike (3, ones (10, 2)) ***** error ... explike (3, [1:50], [1, 2, 3]) ***** error ... explike (3, [1:50], [], [1, 2, 3]) 8 tests, 8 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/expfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/expfit.m ***** demo ## Sample 3 populations from 3 different exponential distributions rande ('state', 42); r1 = exprnd (2, 4000, 1); r2 = exprnd (5, 4000, 1); r3 = exprnd (12, 4000, 1); r = [r1, r2, r3]; ## Plot them normalized and fix their colors hist (r, 48, 0.52); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); set (h(3), 'facecolor', 'r'); hold on ## Estimate their mu parameter muhat = expfit (r); ## Plot their estimated PDFs x = [0:max(r(:))]; y = exppdf (x, muhat(1)); plot (x, y, '-pr'); y = exppdf (x, muhat(2)); plot (x, y, '-sg'); y = exppdf (x, muhat(3)); plot (x, y, '-^c'); ylim ([0, 0.6]) xlim ([0, 40]) legend ({'Normalized HIST of sample 1 with μ=2', ... 'Normalized HIST of sample 2 with μ=5', ... 'Normalized HIST of sample 3 with μ=12', ... sprintf("PDF for sample 1 with estimated μ=%0.2f", muhat(1)), ... sprintf("PDF for sample 2 with estimated μ=%0.2f", muhat(2)), ... sprintf("PDF for sample 3 with estimated μ=%0.2f", muhat(3))}) title ('Three population samples from different exponential distributions') hold off ***** assert_equal (expfit (1), 1) ***** assert_equal (expfit (1:3), 2) ***** assert_equal (expfit ([1:3]'), 2) ***** assert_equal (expfit (1:3, []), 2) ***** assert_equal (expfit (1:3, [], [], []), 2) ***** assert_equal (expfit (magic (3)), [5 5 5]) ***** assert_equal (expfit (cat (3, magic (3), 2*magic (3))), cat (3,[5 5 5], [10 10 10])) ***** assert_equal (expfit (1:3, 0.1, [0 0 0], [1 1 1]), 2) ***** assert_equal (expfit ([1:3]', 0.1, [0 0 0]', [1 1 1]'), 2) ***** assert_equal (expfit (1:3, 0.1, [0 0 0]', [1 1 1]'), 2) ***** assert_equal (expfit (1:3, 0.1, [1 0 0], [1 1 1]), 3) ***** assert_equal (expfit (1:3, 0.1, [0 0 0], [4 1 1]), 1.5) ***** assert_equal (expfit (1:3, 0.1, [1 0 0], [4 1 1]), 4.5) ***** assert_equal (expfit (1:3, 0.1, [1 0 1], [4 1 1]), 9) ***** assert_equal (expfit (1:3, 0.1, [], [-1 1 1]), 4) ***** assert_equal (expfit (1:3, 0.1, [], [0.5 1 1]), 2.2) ***** assert_equal (expfit (1:3, 0.1, [1 1 1]), NaN) ***** assert_equal (expfit (1:3, 0.1, [], [0 0 0]), NaN) ***** assert_equal (expfit (reshape (1:9, [3 3])), [2 5 8]) ***** assert_equal (expfit (reshape (1:9, [3 3]), [], eye (3)), [3 7.5 12]) ***** assert_equal (expfit (reshape (1:9, [3 3]), [], 2*eye (3)), [3 7.5 12]) ***** assert_equal (expfit (reshape (1:9, [3 3]), [], [], [2 2 2; 1 1 1; 1 1 1]), ... [1.75 4.75 7.75]) ***** assert_equal (expfit (reshape (1:9, [3 3]), [], [], [2 2 2; 1 1 1; 1 1 1]), ... [1.75 4.75 7.75]) ***** assert_equal (expfit (reshape (1:9, [3 3]), [], eye (3), [2 2 2; 1 1 1; 1 1 1]), ... [3.5 19/3 31/3]) ***** assert_equal ([~,muci] = expfit (1:3, 0), [0; Inf]) ***** assert_equal ([~,muci] = expfit (1:3, 2), [Inf; 0]) ***** assert_equal ([~,muci] = expfit (1:3, 0.1, [1 1 1]), [NaN; NaN]) ***** assert_equal ([~,muci] = expfit (1:3, 0.1, [], [0 0 0]), [NaN; NaN]) ***** assert_equal ([~,muci] = expfit (1:3, -1), [NaN; NaN]) ***** assert_equal ([~,muci] = expfit (1:3, 5), [NaN; NaN]) ***** assert_equal ([~,muci] = expfit (1:3), [0.830485728373393; 9.698190330474096], ... 1000*eps) ***** assert_equal ([~,muci] = expfit (1:3, 0.1), ... [0.953017262058213; 7.337731146400207], 1000*eps) ***** assert_equal ([~,muci] = expfit ([1:3;2:4]), ... [0.538440777613095, 0.897401296021825, 1.256361814430554; ... 12.385982973214016, 20.643304955356694, 28.900626937499371], ... 1000*eps) ***** assert_equal ([~,muci] = expfit ([1:3;2:4], [], [1 1 1; 0 0 0]), ... 100*[0.008132550920455, 0.013554251534091, 0.018975952147727; ... 1.184936706156216, 1.974894510260360, 2.764852314364504], ... 1000*eps) ***** assert_equal ([~,muci] = expfit ([1:3;2:4], [], [], [3 3 3; 1 1 1]), ... [0.570302756652583, 1.026544961974649, 1.482787167296715; ... 4.587722594914109, 8.257900670845396, 11.928078746776684], ... 1000*eps) ***** assert_equal ([~,muci] = expfit ([1:3;2:4], [], [0 0 0; 1 1 1], [3 3 3; 1 1 1]), ... [0.692071440311161, 1.245728592560089, 1.799385744809018; ... 8.081825275395081, 14.547285495711145, 21.012745716027212], ... 1000*eps) ***** test x = reshape (1:8, [4 2]); x(4) = NaN; [muhat,muci] = expfit (x); assert_equal ({muhat, muci}, {[NaN, 6.5], ... [NaN, 2.965574334593430;NaN, 23.856157493553368]}, 1000*eps); ***** test x = magic (3); censor = [0 1 0; 0 1 0; 0 1 0]; freq = [1 1 0; 1 1 0; 1 1 0]; [muhat,muci] = expfit (x, [], censor, freq); assert_equal ({muhat, muci}, {[5 NaN NaN], ... [[2.076214320933482; 24.245475826185242],NaN(2)]}, 1000*eps); ***** error expfit () ***** error expfit (1,2,3,4,5) ***** error [a b censor] = expfit (1) ***** error expfit (1, [1 2]) ***** error expfit ([-1 2 3 4 5]) ***** error expfit ([1:5], [], 'test') ***** error expfit ([1:5], [], [], 'test') ***** error expfit ([1:5], [], [0 0 0 0]) ***** error expfit ([1:5], [], [], [1 1 1 1]) 47 tests, 47 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/poisslike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/poisslike.m ***** test x = [1 3 2 4 5 4 3 4]; [nlogL, avar] = poisslike (3.25, x); assert_equal (nlogL, 13.9533, 1e-4) ***** test x = [1 2 3 4 5]; f = [1 1 2 3 1]; [nlogL, avar] = poisslike (3.25, x, f); assert_equal (nlogL, 13.9533, 1e-4) ***** error poisslike (1) ***** error poisslike ([1 2 3], [1 2]) ***** error ... poisslike (3.25, ones (10, 2)) ***** error ... poisslike (3.25, [1 2 3 -4 5]) ***** error ... poisslike (3.25, ones (10, 1), ones (8,1)) ***** error ... poisslike (3.25, ones (1, 8), [1 1 1 1 1 1 1 -1]) 8 tests, 8 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/bisafit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/bisafit.m ***** demo ## Sample 3 populations from different Birnbaum-Saunders distributions rng (42); r1 = bisarnd (1, 0.5, 2000, 1); r2 = bisarnd (2, 0.3, 2000, 1); r3 = bisarnd (4, 0.5, 2000, 1); r = [r1, r2, r3]; ## Plot them normalized and fix their colors hist (r, 80, 4.2); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); set (h(3), 'facecolor', 'r'); ylim ([0, 1.1]); xlim ([0, 8]); hold on ## Estimate their α and β parameters beta_gammaA = bisafit (r(:,1)); beta_gammaB = bisafit (r(:,2)); beta_gammaC = bisafit (r(:,3)); ## Plot their estimated PDFs x = [0:0.1:8]; y = bisapdf (x, beta_gammaA(1), beta_gammaA(2)); plot (x, y, '-pr'); y = bisapdf (x, beta_gammaB(1), beta_gammaB(2)); plot (x, y, '-sg'); y = bisapdf (x, beta_gammaC(1), beta_gammaC(2)); plot (x, y, '-^c'); hold off legend ({'Normalized HIST of sample 1 with β=1 and γ=0.5', ... 'Normalized HIST of sample 2 with β=2 and γ=0.3', ... 'Normalized HIST of sample 3 with β=4 and γ=0.5', ... sprintf("PDF for sample 1 with estimated β=%0.2f and γ=%0.2f", ... beta_gammaA(1), beta_gammaA(2)), ... sprintf("PDF for sample 2 with estimated β=%0.2f and γ=%0.2f", ... beta_gammaB(1), beta_gammaB(2)), ... sprintf("PDF for sample 3 with estimated β=%0.2f and γ=%0.2f", ... beta_gammaC(1), beta_gammaC(2))}) title ('Three population samples from different Birnbaum-Saunders distributions') hold off ***** test paramhat = bisafit ([1:50]); paramhat_out = [16.2649, 1.0156]; assert_equal (paramhat, paramhat_out, 1e-4); ***** test paramhat = bisafit ([1:5]); paramhat_out = [2.5585, 0.5839]; assert_equal (paramhat, paramhat_out, 1e-4); ***** error bisafit (ones (2,5)); ***** error bisafit ([-1 2 3 4]); ***** error bisafit ([1, 2, 3, 4, 5], 1.2); ***** error bisafit ([1, 2, 3, 4, 5], 0); ***** error bisafit ([1, 2, 3, 4, 5], 'alpha'); ***** error ... bisafit ([1, 2, 3, 4, 5], 0.05, [1 1 0]); ***** error ... bisafit ([1, 2, 3, 4, 5], [], [1 1 0 1 1]'); ***** error ... bisafit ([1, 2, 3, 4, 5], 0.05, zeros (1,5), [1 1 0]); ***** error ... bisafit ([1, 2, 3, 4, 5], [], [], [1 1 0 1 1]'); ***** error ... bisafit ([1, 2, 3, 4, 5], 0.05, [], [], 2); 12 tests, 12 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/invglike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/invglike.m ***** test nlogL = invglike ([25.5, 19.6973], [1:50]); assert_equal (nlogL, 219.1516, 1e-4); ***** test nlogL = invglike ([3, 8.1081], [1:5]); assert_equal (nlogL, 9.0438, 1e-4); ***** error invglike (3.25) ***** error invglike ([5, 0.2], ones (2)) ***** error invglike ([5, 0.2], [-1, 3]) ***** error ... invglike ([1, 0.2, 3], [1, 3, 5, 7]) ***** error ... invglike ([1.5, 0.2], [1:5], [0, 0, 0]) ***** error ... invglike ([1.5, 0.2], [1:5], [0, 0, 0, 0, 0], [1, 1, 1]) ***** error ... invglike ([1.5, 0.2], [1:5], [], [1, 1, 1]) 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/raylfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/raylfit.m ***** demo ## Sample 3 populations from 3 different Rayleigh distributions rng (42); r1 = raylrnd (1, 1000, 1); r2 = raylrnd (2, 1000, 1); r3 = raylrnd (4, 1000, 1); r = [r1, r2, r3]; ## Plot them normalized and fix their colors hist (r, [0.5:0.5:10.5], 2); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); set (h(3), 'facecolor', 'r'); hold on ## Estimate their lambda parameter sigmaA = raylfit (r(:,1)); sigmaB = raylfit (r(:,2)); sigmaC = raylfit (r(:,3)); ## Plot their estimated PDFs x = [0:0.1:10]; y = raylpdf (x, sigmaA); plot (x, y, '-pr'); y = raylpdf (x, sigmaB); plot (x, y, '-sg'); y = raylpdf (x, sigmaC); plot (x, y, '-^c'); xlim ([0, 10]) ylim ([0, 0.7]) legend ({'Normalized HIST of sample 1 with σ=1', ... 'Normalized HIST of sample 2 with σ=2', ... 'Normalized HIST of sample 3 with σ=4', ... sprintf("PDF for sample 1 with estimated σ=%0.2f", ... sigmaA), ... sprintf("PDF for sample 2 with estimated σ=%0.2f", ... sigmaB), ... sprintf("PDF for sample 3 with estimated σ=%0.2f", ... sigmaC)}) title ('Three population samples from different Rayleigh distributions') hold off ***** test x = [1 3 2 4 5 4 3 4]; [shat, sci] = raylfit (x); assert_equal (shat, 2.4495, 1e-4) assert_equal (sci, [1.8243; 3.7279], 1e-4) ***** test x = [1 3 2 4 5 4 3 4]; [shat, sci] = raylfit (x, 0.01); assert_equal (shat, 2.4495, 1e-4) assert_equal (sci, [1.6738; 4.3208], 1e-4) ***** test x = [1 2 3 4 5]; f = [1 1 2 3 1]; [shat, sci] = raylfit (x, [], [], f); assert_equal (shat, 2.4495, 1e-4) assert_equal (sci, [1.8243; 3.7279], 1e-4) ***** test x = [1 2 3 4 5]; f = [1 1 2 3 1]; [shat, sci] = raylfit (x, 0.01, [], f); assert_equal (shat, 2.4495, 1e-4) assert_equal (sci, [1.6738; 4.3208], 1e-4) ***** test x = [1 2 3 4 5 6]; c = [0 0 0 0 0 1]; f = [1 1 2 3 1 1]; [shat, sci] = raylfit (x, 0.01, c, f); assert_equal (shat, 2.4495, 1e-4) assert_equal (sci, [1.6738; 4.3208], 1e-4) ***** error raylfit (ones (2,5)); ***** error raylfit ([1 2 -1 3]) ***** error raylfit ([1 2 3], 0) ***** error raylfit ([1 2 3], 1.2) ***** error raylfit ([1 2 3], [0.02 0.05]) ***** error ... raylfit ([1, 2, 3, 4, 5], 0.05, [1 1 0]); ***** error ... raylfit ([1, 2, 3, 4, 5], [], [1 1 0 1 1]'); ***** error ... raylfit ([1, 2, 3, 4, 5], 0.05, zeros (1,5), [1 1 0]); ***** error ... raylfit ([1, 2, 3, 4, 5], [], [], [1 1 0 1 1]'); ***** error raylfit ([1 2 3], [], [], [1 5]) ***** error raylfit ([1 2 3], [], [], [1 5 -1]) 16 tests, 16 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/binofit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/binofit.m ***** demo ## Sample 2 populations from different binomial distributions rng (42); r1 = binornd (50, 0.15, 1000, 1); r2 = binornd (100, 0.5, 1000, 1); r = [r1, r2]; ## Plot them normalized and fix their colors hist (r, 23, 0.35); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); hold on ## Estimate their probability of success pshatA = binofit (r(:,1), 50); pshatB = binofit (r(:,2), 100); ## Plot their estimated PDFs x = [min(r(:,1)):max(r(:,1))]; y = binopdf (x, 50, mean (pshatA)); plot (x, y, '-pg'); x = [min(r(:,2)):max(r(:,2))]; y = binopdf (x, 100, mean (pshatB)); plot (x, y, '-sc'); ylim ([0, 0.2]) legend ({'Normalized HIST of sample 1 with ps=0.15', ... 'Normalized HIST of sample 2 with ps=0.50', ... sprintf("PDF for sample 1 with estimated ps=%0.2f", ... mean (pshatA)), ... sprintf("PDF for sample 2 with estimated ps=%0.2f", ... mean (pshatB))}) title ('Two population samples from different binomial distributions') hold off ***** test x = 0:3; [pshat, psci] = binofit (x, 3); assert_equal (pshat, [0, 0.3333, 0.6667, 1], 1e-4); assert_equal (psci(1,:), [0, 0.7076], 1e-4); assert_equal (psci(2,:), [0.0084, 0.9057], 1e-4); assert_equal (psci(3,:), [0.0943, 0.9916], 1e-4); assert_equal (psci(4,:), [0.2924, 1.0000], 1e-4); ***** error ... binofit ([1 2 3 4]) ***** error ... binofit ([-1, 4, 3, 2], [1, 2, 3, 3]) ***** error binofit (ones (2), [1, 2, 3, 3]) ***** error ... binofit ([1, 4, 3, 2], [1, 2, -1, 3]) ***** error ... binofit ([1, 4, 3, 2], [5, 5, 5]) ***** error ... binofit ([1, 4, 3, 2], [5, 3, 5, 5]) ***** error binofit ([1, 2, 1], 3, 1.2); ***** error binofit ([1, 2, 1], 3, 0); ***** error binofit ([1, 2, 1], 3, 'alpha'); 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/ricefit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/ricefit.m ***** demo ## Sample 3 populations from different Gamma distributions randg ('state', 42); randp ('state', 42); r1 = ricernd (1, 2, 3000, 1); r2 = ricernd (2, 4, 3000, 1); r3 = ricernd (7.5, 1, 3000, 1); r = [r1, r2, r3]; ## Plot them normalized and fix their colors hist (r, 75, 4); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); set (h(3), 'facecolor', 'r'); ylim ([0, 0.7]); xlim ([0, 12]); hold on ## Estimate their α and β parameters s_sigmaA = ricefit (r(:,1)); s_sigmaB = ricefit (r(:,2)); s_sigmaC = ricefit (r(:,3)); ## Plot their estimated PDFs x = [0.01,0.1:0.2:18]; y = ricepdf (x, s_sigmaA(1), s_sigmaA(2)); plot (x, y, '-pr'); y = ricepdf (x, s_sigmaB(1), s_sigmaB(2)); plot (x, y, '-sg'); y = ricepdf (x, s_sigmaC(1), s_sigmaC(2)); plot (x, y, '-^c'); hold off legend ({'Normalized HIST of sample 1 with s=1 and σ=2', ... 'Normalized HIST of sample 2 with s=2 and σ=4', ... 'Normalized HIST of sample 3 with s=7.5 and σ=1', ... sprintf("PDF for sample 1 with estimated s=%0.2f and σ=%0.2f", ... s_sigmaA(1), s_sigmaA(2)), ... sprintf("PDF for sample 2 with estimated s=%0.2f and σ=%0.2f", ... s_sigmaB(1), s_sigmaB(2)), ... sprintf("PDF for sample 3 with estimated s=%0.2f and σ=%0.2f", ... s_sigmaC(1), s_sigmaC(2))}) title ('Three population samples from different Rician distributions') hold off ***** test [paramhat, paramci] = ricefit ([1:50]); assert_equal (paramhat, [15.3057, 17.6668], 1e-4); assert_equal (paramci, [9.5468, 11.7802; 24.5383, 26.4952], 1e-4); ***** test [paramhat, paramci] = ricefit ([1:50], 0.01); assert_equal (paramhat, [15.3057, 17.6668], 1e-4); assert_equal (paramci, [8.2309, 10.3717; 28.4615, 30.0934], 1e-4); ***** test [paramhat, paramci] = ricefit ([1:5]); assert_equal (paramhat, [2.3123, 1.6812], 1e-4); assert_equal (paramci, [1.0819, 0.6376; 4.9424, 4.4331], 1e-4); ***** test [paramhat, paramci] = ricefit ([1:5], 0.01); assert_equal (paramhat, [2.3123, 1.6812], 1e-4); assert_equal (paramci, [0.8521, 0.4702; 6.2747, 6.0120], 1e-4); ***** test freq = [1 1 1 1 5]; [paramhat, paramci] = ricefit ([1:5], [], [], freq); assert_equal (paramhat, [3.5181, 1.5565], 1e-4); assert_equal (paramci, [2.5893, 0.9049; 4.7801, 2.6772], 1e-4); ***** test censor = [1 0 0 0 0]; [paramhat, paramci] = ricefit ([1:5], [], censor); assert_equal (paramhat, [3.2978, 1.1527], 1e-4); assert_equal (paramci, [2.3192, 0.5476; 4.6895, 2.4261], 1e-4); ***** assert_equal (class (ricefit (single ([1:50]))), "single") ***** error ricefit (ones (2)) ***** error ricefit ([1:50], 1) ***** error ricefit ([1:50], -1) ***** error ricefit ([1:50], {0.05}) ***** error ricefit ([1:50], 'k') ***** error ricefit ([1:50], i) ***** error ricefit ([1:50], [0.01 0.02]) ***** error ricefit ([1:50], [], [1 1]) ***** error ricefit ([1:50], [], [], [1 1]) ***** error ... ricefit ([1:5], [], [], [1, 1, 2, 1, -1]) ***** error ricefit ([1 2 3 -4]) ***** error ricefit ([1 2 0], [], [1 0 0]) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/burrfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/burrfit.m ***** demo ## Sample 3 populations from different Burr type XII distributions rng (42); r1 = burrrnd (3.5, 2, 2.5, 10000, 1); r2 = burrrnd (1, 3, 1, 10000, 1); r3 = burrrnd (0.5, 2, 3, 10000, 1); r = [r1, r2, r3]; ## Plot them normalized and fix their colors hist (r, [0.1:0.2:20], [18, 5, 3]); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); set (h(3), 'facecolor', 'r'); ylim ([0, 3]); xlim ([0, 5]); hold on ## Estimate their α and β parameters lambda_c_kA = burrfit (r(:,1)); lambda_c_kB = burrfit (r(:,2)); lambda_c_kC = burrfit (r(:,3)); ## Plot their estimated PDFs x = [0.01:0.15:15]; y = burrpdf (x, lambda_c_kA(1), lambda_c_kA(2), lambda_c_kA(3)); plot (x, y, '-pr'); y = burrpdf (x, lambda_c_kB(1), lambda_c_kB(2), lambda_c_kB(3)); plot (x, y, '-sg'); y = burrpdf (x, lambda_c_kC(1), lambda_c_kC(2), lambda_c_kC(3)); plot (x, y, '-^c'); hold off legend ({'Normalized HIST of sample 1 with λ=3.5, c=2, and k=2.5', ... 'Normalized HIST of sample 2 with λ=1, c=3, and k=1', ... 'Normalized HIST of sample 3 with λ=0.5, c=2, and k=3', ... sprintf("PDF for sample 1 with estimated λ=%0.2f, c=%0.2f, and k=%0.2f", ... lambda_c_kA(1), lambda_c_kA(2), lambda_c_kA(3)), ... sprintf("PDF for sample 2 with estimated λ=%0.2f, c=%0.2f, and k=%0.2f", ... lambda_c_kB(1), lambda_c_kB(2), lambda_c_kB(3)), ... sprintf("PDF for sample 3 with estimated λ=%0.2f, c=%0.2f, and k=%0.2f", ... lambda_c_kC(1), lambda_c_kC(2), lambda_c_kC(3))}) title ('Three population samples from different Burr type XII distributions') hold off ***** test l = 1; c = 2; k = 3; r = burrrnd (l, c, k, 100000, 1); lambda_c_kA = burrfit (r); assert_equal (lambda_c_kA(1), l, 0.2); assert_equal (lambda_c_kA(2), c, 0.2); assert_equal (lambda_c_kA(3), k, 0.3); ***** test l = 0.5; c = 1; k = 3; r = burrrnd (l, c, k, 100000, 1); lambda_c_kA = burrfit (r); assert_equal (lambda_c_kA(1), l, 0.2); assert_equal (lambda_c_kA(2), c, 0.2); assert_equal (lambda_c_kA(3), k, 0.3); ***** test l = 1; c = 3; k = 1; r = burrrnd (l, c, k, 100000, 1); lambda_c_kA = burrfit (r); assert_equal (lambda_c_kA(1), l, 0.2); assert_equal (lambda_c_kA(2), c, 0.2); assert_equal (lambda_c_kA(3), k, 0.3); ***** test l = 3; c = 2; k = 1; r = burrrnd (l, c, k, 100000, 1); lambda_c_kA = burrfit (r); assert_equal (lambda_c_kA(1), l, 0.2); assert_equal (lambda_c_kA(2), c, 0.2); assert_equal (lambda_c_kA(3), k, 0.3); ***** test l = 4; c = 2; k = 4; r = burrrnd (l, c, k, 100000, 1); lambda_c_kA = burrfit (r); assert_equal (lambda_c_kA(1), l, 0.2); assert_equal (lambda_c_kA(2), c, 0.2); assert_equal (lambda_c_kA(3), k, 0.3); ***** error burrfit (ones (2,5)); ***** error burrfit ([-1 2 3 4]); ***** error burrfit ([1, 2, 3, 4, 5], 1.2); ***** error burrfit ([1, 2, 3, 4, 5], 0); ***** error burrfit ([1, 2, 3, 4, 5], 'alpha'); ***** error ... burrfit ([1, 2, 3, 4, 5], 0.05, [1 1 0]); ***** error ... burrfit ([1, 2, 3, 4, 5], [], [1 1 0 1 1]'); ***** error burrfit ([1, 2, 3, 4, 5], 0.05, [], [1, 1, 5]) ***** error burrfit ([1, 2, 3, 4, 5], 0.05, [], [1, 5, 1, 1, -1]) ***** error ... burrfit ([1:10], 0.05, [], [], 5) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/normlike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/normlike.m ***** error normlike ([12, 15]); ***** error normlike ([12, 15], ones (2)); ***** error ... normlike ([12, 15, 3], [1:50]); ***** error ... normlike ([12, 15], [1:50], [1, 2, 3]); ***** error ... normlike ([12, 15], [1:50], [], [1, 2, 3]); ***** error ... normlike ([12, 15], [1:5], [], [1, 2, 3, 2, -1]); ***** test x = 1:50; [nlogL, avar] = normlike ([2.3, 1.2], x); avar_out = [7.5767e-01, -1.8850e-02; -1.8850e-02, 4.8750e-04]; assert_equal (nlogL, 13014.95883783327, 1e-10); assert_equal (avar, avar_out, 1e-4); ***** test x = 1:50; [nlogL, avar] = normlike ([2.3, 1.2], x * 0.5); avar_out = [3.0501e-01, -1.5859e-02; -1.5859e-02, 9.1057e-04]; assert_equal (nlogL, 2854.802587833265, 1e-10); assert_equal (avar, avar_out, 1e-4); ***** test x = 1:50; [nlogL, avar] = normlike ([21, 15], x); avar_out = [5.460474308300396, -1.600790513833993; ... -1.600790513833993, 2.667984189723321]; assert_equal (nlogL, 206.738325604233, 1e-12); assert_equal (avar, avar_out, 1e-14); ***** test x = 1:50; censor = ones (1, 50); censor([2, 4, 6, 8, 12, 14]) = 0; [nlogL, avar] = normlike ([2.3, 1.2], x, censor); avar_out = [3.0501e-01, -1.5859e-02; -1.5859e-02, 9.1057e-04]; assert_equal (nlogL, Inf); assert_equal (avar, [NaN, NaN; NaN, NaN]); ***** test x = 1:50; censor = ones (1, 50); censor([2, 4, 6, 8, 12, 14]) = 0; [nlogL, avar] = normlike ([21, 15], x, censor); avar_out = [24.4824488866131, -10.6649544179636; ... -10.6649544179636, 6.22827849965737]; assert_equal (nlogL, 86.9254371829733, 1e-12); assert_equal (avar, avar_out, 8e-14); 11 tests, 11 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/unifit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/unifit.m ***** demo ## Sample 2 populations from different continuous uniform distributions rng (42); r1 = unifrnd (2, 5, 2000, 1); r2 = unifrnd (3, 9, 2000, 1); r = [r1, r2]; ## Plot them normalized and fix their colors hist (r, 0:0.5:10, 2); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); hold on ## Estimate their probability of success a_bA = unifit (r(:,1)); a_bB = unifit (r(:,2)); ## Plot their estimated PDFs x = [0:10]; y = unifpdf (x, a_bA(1), a_bA(2)); plot (x, y, '-pg'); y = unifpdf (x, a_bB(1), a_bB(2)); plot (x, y, '-sc'); xlim ([1, 10]) ylim ([0, 0.5]) legend ({'Normalized HIST of sample 1 with a=2 and b=5', ... 'Normalized HIST of sample 2 with a=3 and b=9', ... sprintf("PDF for sample 1 with estimated a=%0.2f and b=%0.2f", ... a_bA(1), a_bA(2)), ... sprintf("PDF for sample 2 with estimated a=%0.2f and b=%0.2f", ... a_bB(1), a_bB(2))}) title ('Two population samples from different continuous uniform distributions') hold off ***** test [ahat, bhat] = unifit (0:5); assert_equal (ahat, 0); assert_equal (bhat, 5); ***** test [ahat, bhat, aci, bci] = unifit (0:5); assert_equal (aci, [-3.237744862210329; 0], 1e-12); assert_equal (bci, [5; 8.237744862210329], 1e-12); ***** test [~, ~, aci, bci] = unifit (0:5, 0.10); assert_equal (aci, [-2.338996338110347; 0], 1e-12); assert_equal (bci, [5; 7.338996338110347], 1e-12); ***** test ## a column vector is the same single sample as a row [ahat, bhat, aci, bci] = unifit ((0:5)'); assert_equal ([ahat, bhat], [0, 5]); assert_equal (aci, [-3.237744862210329; 0], 1e-12); ***** test ## a matrix is fitted column by column [ahat, bhat, aci, bci] = unifit ([0 10; 1 11; 2 12; 3 13; 4 14; 5 15]); assert_equal (ahat, [0, 10]); assert_equal (bhat, [5, 15]); assert_equal (aci, [-3.237744862210329, 6.762255137789671; 0, 10], 1e-12); assert_equal (bci, [5, 15; 8.237744862210329, 18.237744862210327], 1e-12); ***** test ## negative data is ordinary for a uniform distribution [ahat, bhat, aci, bci] = unifit ([-2, -1, 0, 1, 2]); assert_equal ([ahat, bhat], [-2, 2]); assert_equal (aci, [-5.282256812104322; -2], 1e-12); assert_equal (bci, [2; 5.282256812104322], 1e-12); ***** test ## a one-element sample has no width [ahat, bhat, aci, bci] = unifit (5); assert_equal ([ahat, bhat], [5, 5]); assert_equal (aci, [5; 5]); assert_equal (bci, [5; 5]); ***** test ## empty data gives empty estimates [ahat, bhat, aci, bci] = unifit ([]); assert_equal (isempty (ahat), true); assert_equal (isempty (bhat), true); assert_equal (isempty (aci), true); ***** test ## the endpoints ignore NaN [ahat, bhat] = unifit ([0 1 NaN 3]); assert_equal ([ahat, bhat], [0, 3]); ***** test ## FREQ counts repeated observations [a1, b1] = unifit ([1 1 2 3]); [a2, b2] = unifit ([1 2 3], [], [2 1 1]); assert_equal ([a1, b1], [a2, b2]); ***** error unifit () ***** error unifit ({1, 2}) ***** error unifit (1+2i) ***** error unifit (1, 0) ***** error unifit (1, 1.2) ***** error unifit (1, [0.02 0.05]) ***** error ... unifit ([1 2; 3 4], [], [1 1; 1 1]) ***** error ... unifit ([1.5, 0.2], [], [0, 0, 0, 0, 0]) ***** error ... unifit ([1.5, 0.2], [], [1, -1]) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/nbinfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/nbinfit.m ***** demo ## Sample 2 populations from different negative binomial distributions randg ('state', 42); randp ('state', 42); r1 = nbinrnd (2, 0.15, 5000, 1); r2 = nbinrnd (5, 0.2, 5000, 1); r = [r1, r2]; ## Plot them normalized and fix their colors hist (r, [0:51], 1); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); hold on ## Estimate their probability of success r_psA = nbinfit (r(:,1)); r_psB = nbinfit (r(:,2)); ## Plot their estimated PDFs x = [0:40]; y = nbinpdf (x, r_psA(1), r_psA(2)); plot (x, y, '-pg'); x = [min(r(:,2)):max(r(:,2))]; y = nbinpdf (x, r_psB(1), r_psB(2)); plot (x, y, '-sc'); ylim ([0, 0.1]) xlim ([0, 50]) legend ({'Normalized HIST of sample 1 with r=2 and ps=0.15', ... 'Normalized HIST of sample 2 with r=5 and ps=0.2', ... sprintf("PDF for sample 1 with estimated r=%0.2f and ps=%0.2f", ... r_psA(1), r_psA(2)), ... sprintf("PDF for sample 2 with estimated r=%0.2f and ps=%0.2f", ... r_psB(1), r_psB(2))}) title ('Two population samples from negative different binomial distributions') hold off ***** test [paramhat, paramci] = nbinfit ([1:50]); assert_equal (paramhat, [2.420857, 0.086704], 1e-6); assert_equal (paramci(:,1), [1.382702; 3.459012], 1e-6); assert_equal (paramci(:,2), [0.049676; 0.123732], 1e-6); ***** test [paramhat, paramci] = nbinfit ([1:20]); assert_equal (paramhat, [3.588233, 0.254697], 1e-6); ## The interval is a normal approximation over a numerical Hessian, and ## agrees with R2024a to a few parts in a million rather than exactly. assert_equal (paramci(:,1), [0.451693; 6.724772], 1e-5); assert_equal (paramci(:,2), [0.081143; 0.428251], 1e-5); ***** test [paramhat, paramci] = nbinfit ([1:10]); assert_equal (paramhat, [8.8067, 0.6156], 1e-4); assert_equal (paramci(:,1), [-13.0934; 30.7068], 1e-4); assert_equal (paramci(:,2), [0.0217; 1.2094], 1e-4); ***** test [paramhat, paramci] = nbinfit ([1:10], 0.05, ones (1, 10)); assert_equal (paramhat, [8.8067, 0.6156], 1e-4); assert_equal (paramci(:,1), [-13.0934; 30.7068], 1e-4); assert_equal (paramci(:,2), [0.0217; 1.2094], 1e-4); ***** test [paramhat, paramci] = nbinfit ([1:11], 0.05, [ones(1, 10), 0]); assert_equal (paramhat, [8.8067, 0.6156], 1e-4); assert_equal (paramci(:,1), [-13.0934; 30.7068], 1e-4); assert_equal (paramci(:,2), [0.0217; 1.2094], 1e-4); ***** test ## a bound outside the parameter space is reported, not clamped away [~, paramci] = nbinfit ([1:10]); assert_equal (paramci(1,1) < 0, true); assert_equal (paramci(2,2) > 1, true); assert_equal (paramci(1,1), -13.093353591937408, 1e-5); assert_equal (paramci(2,2), 1.209414934623099, 1e-5); ***** error nbinfit ([-1 2 3 3]) ***** error nbinfit (ones (2)) ***** error nbinfit ([1 2 1.2 3]) ***** error nbinfit ([1 2 3], 0) ***** error nbinfit ([1 2 3], 1.2) ***** error nbinfit ([1 2 3], [0.02 0.05]) ***** error ... nbinfit ([1, 2, 3, 4, 5], 0.05, [1, 2, 3, 2]); ***** error ... nbinfit ([1, 2, 3, 4, 5], 0.05, [1, 2, 3, 2, -1]); ***** error ... nbinfit ([1, 2, 3, 4, 5], 0.05, [1, 2, 3, 2, 1.5]); ***** error ... nbinfit ([1, 2, 3, 4, 5], 0.05, struct ('option', 234)); ***** error ... nbinfit ([1, 2, 3, 4, 5], 0.05, ones (1,5), struct ('option', 234)); 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/binolike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/binolike.m ***** assert_equal (binolike ([3, 0.333], [0:3]), 6.8302, 1e-4) ***** assert_equal (binolike ([3, 0.333], 0), 1.2149, 1e-4) ***** assert_equal (binolike ([3, 0.333], 1), 0.8109, 1e-4) ***** assert_equal (binolike ([3, 0.333], 2), 1.5056, 1e-4) ***** assert_equal (binolike ([3, 0.333], 3), 3.2988, 1e-4) ***** test [nlogL, acov] = binolike ([3, 0.333], 3); assert_equal (acov(4), 0.0740, 1e-4) ***** error binolike (3.25) ***** error binolike ([5, 0.2], ones (2)) ***** error ... binolike ([1, 0.2, 3], [1, 3, 5, 7]) ***** error binolike ([1.5, 0.2], 1) ***** error binolike ([-1, 0.2], 1) ***** error binolike ([Inf, 0.2], 1) ***** error binolike ([5, 1.2], [3, 5]) ***** error binolike ([5, -0.2], [3, 5]) ***** error ... binolike ([5, 0.5], ones (10, 1), ones (8,1)) ***** error ... binolike ([5, 0.5], ones (1, 8), [1 1 1 1 1 1 1 -1]) ***** error binolike ([5, 0.2], [-1, 3]) ***** error binolike ([5, 0.2], [3, 5, 7]) 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/rayllike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/rayllike.m ***** test x = [1 3 2 4 5 4 3 4]; [nlogL, acov] = rayllike (3.25, x); assert_equal (nlogL, 14.7442, 1e-4) ***** test x = [1 2 3 4 5]; f = [1 1 2 3 1]; [nlogL, acov] = rayllike (3.25, x, [], f); assert_equal (nlogL, 14.7442, 1e-4) ***** test x = [1 2 3 4 5 6]; f = [1 1 2 3 1 0]; [nlogL, acov] = rayllike (3.25, x, [], f); assert_equal (nlogL, 14.7442, 1e-4) ***** test x = [1 2 3 4 5 6]; c = [0 0 0 0 0 1]; f = [1 1 2 3 1 0]; [nlogL, acov] = rayllike (3.25, x, c, f); assert_equal (nlogL, 14.7442, 1e-4) ***** error rayllike (1) ***** error rayllike ([1 2 3], [1 2]) ***** error ... rayllike (3.25, ones (10, 2)) ***** error ... rayllike (3.25, [1 2 3 -4 5]) ***** error ... rayllike (3.25, [1, 2, 3, 4, 5], [1 1 0]); ***** error ... rayllike (3.25, [1, 2, 3, 4, 5], [1 1 0 1 1]'); ***** error ... rayllike (3.25, [1, 2, 3, 4, 5], zeros (1,5), [1 1 0]); ***** error ... rayllike (3.25, [1, 2, 3, 4, 5], [], [1 1 0 1 1]'); ***** error ... rayllike (3.25, ones (1, 8), [], [1 1 1 1 1 1 1 -1]) 13 tests, 13 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/gevfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/gevfit.m ***** demo ## Sample 2 populations from 2 different exponential distributions rng (42); r1 = gevrnd (-0.5, 1, 2, 5000, 1); r2 = gevrnd (0, 1, -4, 5000, 1); r = [r1, r2]; ## Plot them normalized and fix their colors hist (r, 50, 5); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); hold on ## Estimate their k, sigma, and mu parameters k_sigma_muA = gevfit (r(:,1)); k_sigma_muB = gevfit (r(:,2)); ## Plot their estimated PDFs x = [-10:0.5:20]; y = gevpdf (x, k_sigma_muA(1), k_sigma_muA(2), k_sigma_muA(3)); plot (x, y, '-pr'); y = gevpdf (x, k_sigma_muB(1), k_sigma_muB(2), k_sigma_muB(3)); plot (x, y, '-sg'); ylim ([0, 0.7]) xlim ([-7, 5]) legend ({'Normalized HIST of sample 1 with k=-0.5, σ=1, μ=2', ... 'Normalized HIST of sample 2 with k=0, σ=1, μ=-4', sprintf("PDF for sample 1 with estimated k=%0.2f, σ=%0.2f, μ=%0.2f", ... k_sigma_muA(1), k_sigma_muA(2), k_sigma_muA(3)), ... sprintf("PDF for sample 3 with estimated k=%0.2f, σ=%0.2f, μ=%0.2f", ... k_sigma_muB(1), k_sigma_muB(2), k_sigma_muB(3))}) title ('Two population samples from different exponential distributions') hold off ***** test x = 1:50; [pfit, pci] = gevfit (x); pfit_out = [-0.4407, 15.1923, 21.5309]; pci_out = [-0.7532, 11.5878, 16.5686; -0.1282, 19.9183, 26.4926]; assert_equal (pfit, pfit_out, 1e-3); assert_equal (pci, pci_out, 1e-3); ***** test x = 1:2:50; [pfit, pci] = gevfit (x); pfit_out = [-0.4434, 15.2024, 21.0532]; pci_out = [-0.8904, 10.3439, 14.0168; 0.0035, 22.3429, 28.0896]; assert_equal (pfit, pfit_out, 1e-3); assert_equal (pci, pci_out, 1e-3); ***** error gevfit (ones (2,5)); ***** error gevfit ([1, 2, 3, 4, 5], 1.2); ***** error gevfit ([1, 2, 3, 4, 5], 0); ***** error gevfit ([1, 2, 3, 4, 5], 'alpha'); ***** error ... gevfit ([1, 2, 3, 4, 5], 0.05, [1, 2, 3, 2]); ***** error ... gevfit ([1, 2, 3, 4, 5], 0.05, [1, 2, 3, 2, -1]); ***** error ... gevfit ([1, 2, 3, 4, 5], 0.05, [1, 2, 3, 2, 1.5]); ***** error ... gevfit ([1, 2, 3, 4, 5], 0.05, struct ('option', 234)); ***** error ... gevfit ([1, 2, 3, 4, 5], 0.05, ones (1,5), struct ('option', 234)); 11 tests, 11 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/logifit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/logifit.m ***** demo ## Sample 3 populations from different logistic distributions rng (42); r1 = logirnd (2, 1, 2000, 1); r2 = logirnd (5, 2, 2000, 1); r3 = logirnd (9, 4, 2000, 1); r = [r1, r2, r3]; ## Plot them normalized and fix their colors hist (r, [-6:20], 1); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); set (h(3), 'facecolor', 'r'); ylim ([0, 0.3]); xlim ([-5, 20]); hold on ## Estimate their MU and LAMBDA parameters mu_sA = logifit (r(:,1)); mu_sB = logifit (r(:,2)); mu_sC = logifit (r(:,3)); ## Plot their estimated PDFs x = [-5:0.5:20]; y = logipdf (x, mu_sA(1), mu_sA(2)); plot (x, y, '-pr'); y = logipdf (x, mu_sB(1), mu_sB(2)); plot (x, y, '-sg'); y = logipdf (x, mu_sC(1), mu_sC(2)); plot (x, y, '-^c'); hold off legend ({'Normalized HIST of sample 1 with μ=1 and s=0.5', ... 'Normalized HIST of sample 2 with μ=2 and s=0.3', ... 'Normalized HIST of sample 3 with μ=4 and s=0.5', ... sprintf("PDF for sample 1 with estimated μ=%0.2f and s=%0.2f", ... mu_sA(1), mu_sA(2)), ... sprintf("PDF for sample 2 with estimated μ=%0.2f and s=%0.2f", ... mu_sB(1), mu_sB(2)), ... sprintf("PDF for sample 3 with estimated μ=%0.2f and s=%0.2f", ... mu_sC(1), mu_sC(2))}) title ('Three population samples from different logistic distributions') hold off ***** test paramhat = logifit ([1:50]); paramhat_out = [25.5, 8.7724]; assert_equal (paramhat, paramhat_out, 1e-4); ***** test paramhat = logifit ([1:5]); paramhat_out = [3, 0.8645]; assert_equal (paramhat, paramhat_out, 1e-4); ***** test paramhat = logifit ([1:6], [], [], [1 1 1 1 1 0]); paramhat_out = [3, 0.8645]; assert_equal (paramhat, paramhat_out, 1e-4); ***** test paramhat = logifit ([1:5], [], [], [1 1 1 1 2]); paramhat_out = logifit ([1:5, 5]); assert_equal (paramhat, paramhat_out, 1e-4); ***** error logifit (ones (2,5)); ***** error logifit ([1, 2, 3, 4, 5], 1.2); ***** error logifit ([1, 2, 3, 4, 5], 0); ***** error logifit ([1, 2, 3, 4, 5], 'alpha'); ***** error ... logifit ([1, 2, 3, 4, 5], 0.05, [1 1 0]); ***** error ... logifit ([1, 2, 3, 4, 5], [], [1 1 0 1 1]'); ***** error ... logifit ([1, 2, 3, 4, 5], 0.05, zeros (1,5), [1 1 0]); ***** error ... logifit ([1, 2, 3, 4, 5], [], [], [1 1 0 1 1]'); ***** error ... logifit ([1, 2, 3, 4, 5], 0.05, [], [], 2); 13 tests, 13 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/gevfit_lmom.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/gevfit_lmom.m ***** xtest <31070> data = 1:50; [pfit, pci] = gevfit_lmom (data); expected_p = [-0.28 15.01 20.22]'; assert_equal (pfit, expected_p, 0.1); 1 test, 1 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/gplike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/gplike.m ***** test k = 0.893710299404345; sigma = 1.322962458731574; x = [2.2196, 11.9301, 4.3673, 1.0949, 6.5626, ... 1.2109, 1.8576, 1.0039, 12.7917, 2.2590] - 1; [nlogL, acov] = gplike ([k, sigma], x); assert_equal (nlogL, 21.735838309709596, 1e-12); assert_equal (acov, [ 0.724871582460845, -0.735076013984010; ... -0.735076013984010, 1.303920812049488], 1e-12); ***** test ## the covariance covers the two estimated parameters only [~, acov] = gplike ([2, 3], [1:10]); assert_equal (size (acov), [2, 2]); ***** test ## a known location is handled by shifting the data assert_equal (gplike ([2, 3], ([1:10] + 2) - 2), ... gplike ([2, 3], [1:10]), 1e-14); ***** assert_equal (gplike ([2, 3], 4), 3.047536764863501, 1e-14) ***** assert_equal (gplike ([1, 2], 4), 2.890371757896165, 1e-14) ***** assert_equal (gplike ([2, 3], [1:10]), 32.57864322725392, 1e-14) ***** assert_equal (gplike ([1, 2], [1:10]), 31.65666282460443, 1e-14) ***** assert_equal (gplike ([2, 3], [1:10], ones (1,10)), 32.57864322725392, 1e-14) ***** assert_equal (gplike ([1, 2], [1:10], ones (1,10)), 31.65666282460443, 1e-14) ***** assert_equal (gplike ([1, NaN], [1:10]), NaN) ***** error gplike () ***** error gplike (1) ***** error gplike ([1, 2], []) ***** error gplike ([1, 2], ones (2)) ***** error gplike (2, [1:10]) ***** error gplike ([1, 2, 0], [1:10]) ***** error ... gplike ([1, 2], ones (10, 1), ones (8,1)) ***** error ... gplike ([1, 2], ones (1, 8), [1 1 1 1 1 1 1 -1]) 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/evfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/evfit.m ***** demo ## Sample 3 populations from different extreme value distributions rng (42); r1 = evrnd (2, 5, 400, 1); r2 = evrnd (-5, 3, 400, 1); r3 = evrnd (14, 8, 400, 1); r = [r1, r2, r3]; ## Plot them normalized and fix their colors hist (r, 25, 0.4); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); set (h(3), 'facecolor', 'r'); ylim ([0, 0.28]) xlim ([-30, 30]); hold on ## Estimate their MU and SIGMA parameters mu_sigmaA = evfit (r(:,1)); mu_sigmaB = evfit (r(:,2)); mu_sigmaC = evfit (r(:,3)); ## Plot their estimated PDFs x = [min(r(:)):max(r(:))]; y = evpdf (x, mu_sigmaA(1), mu_sigmaA(2)); plot (x, y, '-pr'); y = evpdf (x, mu_sigmaB(1), mu_sigmaB(2)); plot (x, y, '-sg'); y = evpdf (x, mu_sigmaC(1), mu_sigmaC(2)); plot (x, y, '-^c'); legend ({'Normalized HIST of sample 1 with μ=2 and σ=5', ... 'Normalized HIST of sample 2 with μ=-5 and σ=3', ... 'Normalized HIST of sample 3 with μ=14 and σ=8', ... sprintf("PDF for sample 1 with estimated μ=%0.2f and σ=%0.2f", ... mu_sigmaA(1), mu_sigmaA(2)), ... sprintf("PDF for sample 2 with estimated μ=%0.2f and σ=%0.2f", ... mu_sigmaB(1), mu_sigmaB(2)), ... sprintf("PDF for sample 3 with estimated μ=%0.2f and σ=%0.2f", ... mu_sigmaC(1), mu_sigmaC(2))}) title ('Three population samples from different extreme value distributions') hold off ***** test x = 1:50; [paramhat, paramci] = evfit (x); paramhat_out = [32.6811, 13.0509]; paramci_out = [28.8504, 10.5294; 36.5118, 16.1763]; assert_equal (paramhat, paramhat_out, 1e-4); assert_equal (paramci, paramci_out, 1e-4); ***** test x = 1:50; [paramhat, paramci] = evfit (x, 0.01); paramci_out = [27.6468, 9.8426; 37.7155, 17.3051]; assert_equal (paramci, paramci_out, 1e-4); ***** error evfit (ones (2,5)); ***** error evfit (single (ones (1,5))); ***** error evfit ([1, 2, 3, 4, NaN]); ***** error evfit ([1, 2, 3, 4, 5], 1.2); ***** error evfit ([1 2 3], 0.05, [], [1 5]) ***** error evfit ([1 2 3], 0.05, [], [1 5 -1]) ***** error ... evfit ([1:10], 0.05, [], [], 5) 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/evlike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/evlike.m ***** test x = 1:50; [nlogL, acov] = evlike ([2.3, 1.2], x); avar_out = [-1.2778e-13, 3.1859e-15; 3.1859e-15, -7.9430e-17]; assert_equal (nlogL, 3.242264755689906e+17, 1e-14); assert_equal (acov, avar_out, 1e-3); ***** test x = 1:50; [nlogL, acov] = evlike ([2.3, 1.2], x * 0.5); avar_out = [-7.6094e-05, 3.9819e-06; 3.9819e-06, -2.0836e-07]; assert_equal (nlogL, 481898704.0472211, 1e-6); assert_equal (acov, avar_out, 1e-3); ***** test x = 1:50; [nlogL, acov] = evlike ([21, 15], x); avar_out = [11.73913876598908, -5.9546128523121216; ... -5.954612852312121, 3.708060045170236]; assert_equal (nlogL, 223.7612479380652, 1e-13); assert_equal (acov, avar_out, 1e-14); ***** error evlike ([12, 15]) ***** error evlike ([12, 15, 3], [1:50]) ***** error evlike ([12, 3], ones (10, 2)) ***** error ... evlike ([12, 15], [1:50], [1, 2, 3]) ***** error ... evlike ([12, 15], [1:50], [], [1, 2, 3]) 8 tests, 8 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/wbllike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/wbllike.m ***** test x = 1:50; [nlogL, acov] = wbllike ([2.3, 1.2], x); avar_out = [0.0250, 0.0062; 0.0062, 0.0017]; assert_equal (nlogL, 945.9589180651594, 1e-12); assert_equal (acov, avar_out, 1e-4); ***** test x = 1:50; [nlogL, acov] = wbllike ([2.3, 1.2], x * 0.5); avar_out = [-0.3238, -0.1112; -0.1112, -0.0376]; assert_equal (nlogL, 424.9879809704742, 6e-14); assert_equal (acov, avar_out, 1e-4); ***** test x = 1:50; [nlogL, acov] = wbllike ([21, 15], x); avar_out = [-0.00001236, -0.00001166; -0.00001166, -0.00001009]; assert_equal (nlogL, 1635190.328991511, 1e-8); assert_equal (acov, avar_out, 1e-8); ***** error wbllike ([12, 15]); ***** error wbllike ([12, 15, 3], [1:50]); ***** error wbllike ([12, 3], ones (10, 2)); ***** error wbllike ([12, 15], [1:50], [1, 2, 3]); ***** error wbllike ([12, 15], [1:50], [], [1, 2, 3]); ***** error ... wbllike ([12, 15], [1:5], [], [1, 2, 3, -1, 0]); 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/normfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/normfit.m ***** demo ## Sample 3 populations from 3 different normal distributions rng (42); r1 = normrnd (2, 5, 5000, 1); r2 = normrnd (5, 2, 5000, 1); r3 = normrnd (9, 4, 5000, 1); r = [r1, r2, r3]; ## Plot them normalized and fix their colors hist (r, 15, 0.4); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); set (h(3), 'facecolor', 'r'); hold on ## Estimate their mu and sigma parameters [muhat, sigmahat] = normfit (r); ## Plot their estimated PDFs x = [min(r(:)):max(r(:))]; y = normpdf (x, muhat(1), sigmahat(1)); plot (x, y, '-pr'); y = normpdf (x, muhat(2), sigmahat(2)); plot (x, y, '-sg'); y = normpdf (x, muhat(3), sigmahat(3)); plot (x, y, '-^c'); ylim ([0, 0.5]) xlim ([-20, 20]) hold off legend ({'Normalized HIST of sample 1 with mu=2, σ=5', ... 'Normalized HIST of sample 2 with mu=5, σ=2', ... 'Normalized HIST of sample 3 with mu=9, σ=4', ... sprintf("PDF for sample 1 with estimated mu=%0.2f and σ=%0.2f", ... muhat(1), sigmahat(1)), ... sprintf("PDF for sample 2 with estimated mu=%0.2f and σ=%0.2f", ... muhat(2), sigmahat(2)), ... sprintf("PDF for sample 3 with estimated mu=%0.2f and σ=%0.2f", ... muhat(3), sigmahat(3))}, 'location', 'northwest') title ('Three population samples from different normal distributions') hold off ***** test load lightbulb idx = find (lightbulb(:,2) == 0); censoring = lightbulb(idx,3) == 1; [muHat, sigmaHat] = normfit (lightbulb(idx,1), [], censoring); assert_equal (muHat, 9496.59586737857, 1e-11); assert_equal (sigmaHat, 3064.021012796456, 2e-12); ***** test randn ('seed', 234); x = normrnd (3, 5, [1000, 1]); [muHat, sigmaHat, muCI, sigmaCI] = normfit (x, 0.01); assert_equal (muCI(1) < 3, true); assert_equal (muCI(2) > 3, true); assert_equal (sigmaCI(1) < 5, true); assert_equal (sigmaCI(2) > 5, true); ***** error ... normfit (ones (3,3,3)) ***** error ... normfit (ones (20,3), [], zeros (20,1)) ***** error normfit (ones (20,1), 0) ***** error normfit (ones (20,1), -0.3) ***** error normfit (ones (20,1), 1.2) ***** error normfit (ones (20,1), [0.05 0.1]) ***** error normfit (ones (20,1), 0.02+i) ***** error ... normfit (ones (20,1), [], zeros (15,1)) ***** error ... normfit (ones (20,1), [], zeros (20,1), ones (25,1)) ***** error ... normfit (ones (5,1), [], zeros (5,1), [1, 2, 1, 2, -1]') ***** error normfit (ones (20,1), [], zeros (20,1), ones (20,1), 'options') 13 tests, 13 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/hnfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/hnfit.m ***** demo ## Sample 2 populations from different half-normal distributions rng (42); r1 = hnrnd (0, 5, 5000, 1); r2 = hnrnd (0, 2, 5000, 1); r = [r1, r2]; ## Plot them normalized and fix their colors hist (r, [0.5:20], 1); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); hold on ## Estimate their shape parameters mu_sigmaA = hnfit (r(:,1), 0); mu_sigmaB = hnfit (r(:,2), 0); ## Plot their estimated PDFs x = [0:0.2:10]; y = hnpdf (x, mu_sigmaA(1), mu_sigmaA(2)); plot (x, y, '-pr'); y = hnpdf (x, mu_sigmaB(1), mu_sigmaB(2)); plot (x, y, '-sg'); xlim ([0, 10]) ylim ([0, 0.5]) legend ({'Normalized HIST of sample 1 with μ=0 and σ=5', ... 'Normalized HIST of sample 2 with μ=0 and σ=2', ... sprintf("PDF for sample 1 with estimated μ=%0.2f and σ=%0.2f", ... mu_sigmaA(1), mu_sigmaA(2)), ... sprintf("PDF for sample 2 with estimated μ=%0.2f and σ=%0.2f", ... mu_sigmaB(1), mu_sigmaB(2))}) title ('Two population samples from different half-normal distributions') hold off ***** test x = 1:20; [paramhat, paramci] = hnfit (x, 0); assert_equal (paramhat, [0, 11.9791], 1e-4); assert_equal (paramci, [0, 9.1648; 0, 17.2987], 1e-4); ***** test x = 1:20; [paramhat, paramci] = hnfit (x, 0, 0.01); assert_equal (paramci, [0, 8.4709; 0, 19.6487], 1e-4); ***** error hnfit () ***** error hnfit (1) ***** error hnfit ([0.2, 0.5+i], 0); ***** error hnfit (ones (2,2) * 0.5, 0); ***** error ... hnfit ([0.5, 1.2], [0, 1]); ***** error ... hnfit ([0.5, 1.2], 5+i); ***** error ... hnfit ([1:5], 2); ***** error hnfit ([0.01:0.1:0.99], 0, 1.2); ***** error hnfit ([0.01:0.1:0.99], 0, i); ***** error hnfit ([0.01:0.1:0.99], 0, -1); ***** error hnfit ([0.01:0.1:0.99], 0, [0.05, 0.01]); ***** error hnfit ([1 2 3], 0, [], [1 5]) ***** error hnfit ([1 2 3], 0, [], [1 5 -1]) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/nakafit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/nakafit.m ***** demo ## Sample 3 populations from different Nakagami distributions randg ('state', 42); r1 = nakarnd (0.5, 1, 2000, 1); r2 = nakarnd (5, 1, 2000, 1); r3 = nakarnd (2, 2, 2000, 1); r = [r1, r2, r3]; ## Plot them normalized and fix their colors hist (r, [0.05:0.1:3.5], 10); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); set (h(3), 'facecolor', 'r'); ylim ([0, 2.5]); xlim ([0, 3.0]); hold on ## Estimate their MU and LAMBDA parameters mu_omegaA = nakafit (r(:,1)); mu_omegaB = nakafit (r(:,2)); mu_omegaC = nakafit (r(:,3)); ## Plot their estimated PDFs x = [0.01:0.1:3.01]; y = nakapdf (x, mu_omegaA(1), mu_omegaA(2)); plot (x, y, '-pr'); y = nakapdf (x, mu_omegaB(1), mu_omegaB(2)); plot (x, y, '-sg'); y = nakapdf (x, mu_omegaC(1), mu_omegaC(2)); plot (x, y, '-^c'); legend ({'Normalized HIST of sample 1 with μ=0.5 and ω=1', ... 'Normalized HIST of sample 2 with μ=5 and ω=1', ... 'Normalized HIST of sample 3 with μ=2 and ω=2', ... sprintf("PDF for sample 1 with estimated μ=%0.2f and ω=%0.2f", ... mu_omegaA(1), mu_omegaA(2)), ... sprintf("PDF for sample 2 with estimated μ=%0.2f and ω=%0.2f", ... mu_omegaB(1), mu_omegaB(2)), ... sprintf("PDF for sample 3 with estimated μ=%0.2f and ω=%0.2f", ... mu_omegaC(1), mu_omegaC(2))}) title ('Three population samples from different Nakagami distributions') hold off ***** test paramhat = nakafit ([1:50]); paramhat_out = [0.7355, 858.5]; assert_equal (paramhat, paramhat_out, 1e-4); ***** test paramhat = nakafit ([1:5]); paramhat_out = [1.1740, 11]; assert_equal (paramhat, paramhat_out, 1e-4); ***** test paramhat = nakafit ([1:6], [], [], [1 1 1 1 1 0]); paramhat_out = [1.1740, 11]; assert_equal (paramhat, paramhat_out, 1e-4); ***** test paramhat = nakafit ([1:5], [], [], [1 1 1 1 2]); paramhat_out = nakafit ([1:5, 5]); assert_equal (paramhat, paramhat_out, 1e-4); ***** error nakafit (ones (2,5)); ***** error nakafit ([1, 2, 3, 4, 5], 1.2); ***** error nakafit ([1, 2, 3, 4, 5], 0); ***** error nakafit ([1, 2, 3, 4, 5], 'alpha'); ***** error ... nakafit ([1, 2, 3, 4, 5], 0.05, [1 1 0]); ***** error ... nakafit ([1, 2, 3, 4, 5], [], [1 1 0 1 1]'); ***** error ... nakafit ([1, 2, 3, 4, 5], 0.05, zeros (1,5), [1 1 0]); ***** error ... nakafit ([1, 2, 3, 4, 5], [], [], [1 1 0 1 1]'); ***** error ... nakafit ([1, 2, 3, 4, 5], [], [], [1 1 -1 1 1]); ***** error ... nakafit ([1, 2, 3, 4, 5], [], [], [1 1 1.5 1 1]); ***** error ... nakafit ([1, 2, 3, 4, 5], 0.05, [], [], 2); 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/geofit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/geofit.m ***** demo ## Sample 2 populations from different geometric distributions rande ('state', 42); r1 = geornd (0.15, 1000, 1); r2 = geornd (0.5, 1000, 1); r = [r1, r2]; ## Plot them normalized and fix their colors hist (r, 0:0.5:20.5, 1); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); hold on ## Estimate their probability of success pshatA = geofit (r(:,1)); pshatB = geofit (r(:,2)); ## Plot their estimated PDFs x = [0:15]; y = geopdf (x, pshatA); plot (x, y, '-pg'); y = geopdf (x, pshatB); plot (x, y, '-sc'); xlim ([0, 15]) ylim ([0, 0.6]) legend ({'Normalized HIST of sample 1 with ps=0.15', ... 'Normalized HIST of sample 2 with ps=0.50', ... sprintf("PDF for sample 1 with estimated ps=%0.2f", ... mean (pshatA)), ... sprintf("PDF for sample 2 with estimated ps=%0.2f", ... mean (pshatB))}) title ('Two population samples from different geometric distributions') hold off ***** test x = 0:5; [pshat, psci] = geofit (x); assert_equal (pshat, 0.2857, 1e-4); assert_equal (psci, [0.092499; 0.478929], 1e-5); ***** test x = 0:5; [pshat, psci] = geofit (x, [], [1 1 1 1 1 1]); assert_equal (pshat, 0.2857, 1e-4); assert_equal (psci, [0.092499; 0.478929], 1e-5); ***** assert_equal (geofit ([1 1 2 3]), geofit ([1 2 3], [] ,[2 1 1])) ***** error geofit () ***** error geofit (-1, [1 2 3 3]) ***** error geofit (1, 0) ***** error geofit (1, 1.2) ***** error geofit (1, [0.02 0.05]) ***** error ... geofit ([1.5, 0.2], [], [0, 0, 0, 0, 0]) ***** error ... geofit ([1.5, 0.2], [], [1, 1, 1]) 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/stblfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/stblfit.m ***** demo ## Fit a stable distribution to simulated data rng (42); x = stblrnd (1.5, 0.5, 2, 1, 150, 1); [paramhat, paramci] = stblfit (x) ***** test # recovery + MATLAB parity # Our fast integrator reproduces the exact stblpdf MLE to ~2e-5. MATLAB's # stable density is a Nolan interpolation approximation, so its fit # deviates from the exact MLE by ~1e-2; we ship the exact (more accurate) # estimate and document the deviation (as for the copula family). rand ("seed", 2718); randn ("seed", 2718); x = stblrnd (1.5, 0.5, 2, 1, 150, 1); [phat, pci] = stblfit (x); ## Exact-density estimate on this sample (recovers the generating [1.5 0.5 2 1]) assert_equal (phat, [1.5469000, 0.4732298, 2.0097077, 1.1640279], 1e-3); ## MATLAB fitdist (x, 'Stable') on the same data agrees to ~1.5e-2 assert_equal (phat, [1.5449145, 0.4693139, 2.0000225, 1.1646526], 1.5e-2); ## Confidence intervals bracket the estimate; gam CI is positive assert_equal (all (pci(1,:) <= phat, 'all') ... && all (pci(2,:) >= phat, 'all'), true); assert_equal (pci(1,3) > 0, true); ***** error stblfit (ones (2, 2)) ***** error stblfit ([1, 2, NaN, 4]) ***** error ... stblfit ([2, 2, 2, 2]) ***** error stblfit ([1, 2, 3, 4], 1.5) ***** error stblfit ([1, 2, 3, 4], -0.5) ***** error ... stblfit ([1, 2, 3, 4], 0.05, [1, 2, 3]) ***** error ... stblfit ([1, 2, 3, 4], 0.05, [1, -1, 2, 1]) ***** error ... stblfit ([1, 2, 3, 4], 0.05, [1, 1.5, 2, 1]) 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/burrlike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/burrlike.m ***** error burrlike (3.25) ***** error burrlike ([1, 2, 3], ones (2)) ***** error burrlike ([1, 2, 3], [-1, 3]) ***** error ... burrlike ([1, 2], [1, 3, 5, 7]) ***** error ... burrlike ([1, 2, 3, 4], [1, 3, 5, 7]) ***** error ... burrlike ([1, 2, 3], [1:5], [0, 0, 0]) ***** error ... burrlike ([1, 2, 3], [1:5], [0, 0, 0, 0, 0], [1, 1, 1]) ***** error ... burrlike ([1, 2, 3], [1:5], [], [1, 1, 1]) 8 tests, 8 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/gumbellike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/gumbellike.m ***** test x = 1:50; [nlogL, avar] = gumbellike ([2.3, 1.2], x); avar_out = [-1.2778e-13, 3.1859e-15; 3.1859e-15, -7.9430e-17]; assert_equal (nlogL, 3.242264755689906e+17, 1e-14); assert_equal (avar, avar_out, 1e-3); ***** test x = 1:50; [nlogL, avar] = gumbellike ([2.3, 1.2], x * 0.5); avar_out = [-7.6094e-05, 3.9819e-06; 3.9819e-06, -2.0836e-07]; assert_equal (nlogL, 481898704.0472211, 1e-6); assert_equal (avar, avar_out, 1e-3); ***** test x = 1:50; [nlogL, avar] = gumbellike ([21, 15], x); avar_out = [11.73913876598908, -5.9546128523121216; ... -5.954612852312121, 3.708060045170236]; assert_equal (nlogL, 223.7612479380652, 1e-13); assert_equal (avar, avar_out, 1e-14); ***** error gumbellike ([12, 15]); ***** error gumbellike ([12, 15, 3], [1:50]); ***** error gumbellike ([12, 3], ones (10, 2)); ***** error gumbellike ([12, 15], [1:50], [1, 2, 3]); ***** error gumbellike ([12, 15], [1:50], [], [1, 2, 3]); 8 tests, 8 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/lognlike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/lognlike.m ***** test x = 1:50; [nlogL, avar] = lognlike ([0, 0.25], x); avar_out = [-5.4749e-03, 2.8308e-04; 2.8308e-04, -1.1916e-05]; assert_equal (nlogL, 3962.330333301793, 1e-10); assert_equal (avar, avar_out, 1e-7); ***** test x = 1:50; [nlogL, avar] = lognlike ([0, 0.25], x * 0.5); avar_out = [-7.6229e-03, 4.8722e-04; 4.8722e-04, -2.6754e-05]; assert_equal (nlogL, 2473.183051225747, 1e-10); assert_equal (avar, avar_out, 1e-7); ***** test x = 1:50; [nlogL, avar] = lognlike ([0, 0.5], x); avar_out = [-2.1152e-02, 2.2017e-03; 2.2017e-03, -1.8535e-04]; assert_equal (nlogL, 1119.072424020455, 1e-12); assert_equal (avar, avar_out, 1e-6); ***** test x = 1:50; censor = ones (1, 50); censor([2, 4, 6, 8, 12, 14]) = 0; [nlogL, avar] = lognlike ([0, 0.5], x, censor); avar_out = [-1.9823e-02, 2.0370e-03; 2.0370e-03, -1.6618e-04]; assert_equal (nlogL, 1091.746371145497, 1e-12); assert_equal (avar, avar_out, 1e-6); ***** test x = 1:50; censor = ones (1, 50); censor([2, 4, 6, 8, 12, 14]) = 0; [nlogL, avar] = lognlike ([0, 1], x, censor); avar_out = [-6.8634e-02, 1.3968e-02; 1.3968e-02, -2.1664e-03]; assert_equal (nlogL, 349.3969104144271, 1e-12); assert_equal (avar, avar_out, 1e-6); ***** error ... lognlike ([12, 15]); ***** error lognlike ([12, 15], ones (2)); ***** error ... lognlike ([12, 15, 3], [1:50]); ***** error ... lognlike ([12, 15], [1:50], [1, 2, 3]); ***** error ... lognlike ([12, 15], [1:50], [], [1, 2, 3]); 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/logllike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/logllike.m ***** test [nlogL, acov] = logllike ([3.09717, 0.468525], [1:50]); assert_equal (nlogL, 211.2965, 1e-4); assert_equal (acov, [0.0131, -0.0007; -0.0007, 0.0031], 1e-4); ***** test [nlogL, acov] = logllike ([1.01124, 0.336449], [1:5]); assert_equal (nlogL, 9.2206, 1e-4); assert_equal (acov, [0.0712, -0.0032; -0.0032, 0.0153], 1e-4); ***** error logllike (3.25) ***** error logllike ([5, 0.2], ones (2)) ***** error ... logllike ([1, 0.2, 3], [1, 3, 5, 7]) ***** error ... logllike ([1.5, 0.2], [1:5], [0, 0, 0]) ***** error ... logllike ([1.5, 0.2], [1:5], [0, 0, 0, 0, 0], [1, 1, 1]) ***** error ... logllike ([1.5, 0.2], [1:5], [], [1, 1, 1]) 8 tests, 8 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/loglfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/loglfit.m ***** demo ## Sample 3 populations from different log-logistic distributions rng (42); r1 = loglrnd (0, 1, 2000, 1); r2 = loglrnd (0, 0.5, 2000, 1); r3 = loglrnd (0, 0.125, 2000, 1); r = [r1, r2, r3]; ## Plot them normalized and fix their colors hist (r, [0.05:0.1:2.5], 10); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); set (h(3), 'facecolor', 'r'); ylim ([0, 3.5]); xlim ([0, 2.0]); hold on ## Estimate their MU and LAMBDA parameters a_bA = loglfit (r(:,1)); a_bB = loglfit (r(:,2)); a_bC = loglfit (r(:,3)); ## Plot their estimated PDFs x = [0.01:0.1:2.01]; y = loglpdf (x, a_bA(1), a_bA(2)); plot (x, y, '-pr'); y = loglpdf (x, a_bB(1), a_bB(2)); plot (x, y, '-sg'); y = loglpdf (x, a_bC(1), a_bC(2)); plot (x, y, '-^c'); legend ({'Normalized HIST of sample 1 with α=1 and β=1', ... 'Normalized HIST of sample 2 with α=1 and β=2', ... 'Normalized HIST of sample 3 with α=1 and β=8', ... sprintf("PDF for sample 1 with estimated α=%0.2f and β=%0.2f", ... a_bA(1), a_bA(2)), ... sprintf("PDF for sample 2 with estimated α=%0.2f and β=%0.2f", ... a_bB(1), a_bB(2)), ... sprintf("PDF for sample 3 with estimated α=%0.2f and β=%0.2f", ... a_bC(1), a_bC(2))}) title ('Three population samples from different log-logistic distributions') hold off ***** test [paramhat, paramci] = loglfit ([1:50]); paramhat_out = [3.09717, 0.468525]; paramci_out = [2.87261, 0.370616; 3.32174, 0.5923]; assert_equal (paramhat, paramhat_out, 1e-5); assert_equal (paramci, paramci_out, 1e-5); ***** test paramhat = loglfit ([1:5]); paramhat_out = [1.01124, 0.336449]; assert_equal (paramhat, paramhat_out, 1e-5); ***** test paramhat = loglfit ([1:6], [], [], [1 1 1 1 1 0]); paramhat_out = [1.01124, 0.336449]; assert_equal (paramhat, paramhat_out, 1e-4); ***** test paramhat = loglfit ([1:5], [], [], [1 1 1 1 2]); paramhat_out = loglfit ([1:5, 5]); assert_equal (paramhat, paramhat_out, 1e-4); ***** error loglfit (ones (2,5)); ***** error loglfit ([1, 2, 3, 4, 5], 1.2); ***** error loglfit ([1, 2, 3, 4, 5], 0); ***** error loglfit ([1, 2, 3, 4, 5], 'alpha'); ***** error ... loglfit ([1, 2, 3, 4, 5], 0.05, [1 1 0]); ***** error ... loglfit ([1, 2, 3, 4, 5], [], [1 1 0 1 1]'); ***** error ... loglfit ([1, 2, 3, 4, 5], 0.05, zeros (1,5), [1 1 0]); ***** error ... loglfit ([1, 2, 3, 4, 5], [], [], [1 1 0 1 1]'); ***** error ... loglfit ([1, 2, 3, 4, 5], 0.05, [], [], 2); 13 tests, 13 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/copulafit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/copulafit.m ***** demo ## Fit a Clayton copula to data and recover a confidence interval rng (42); randg ('state', 42); u = copularnd ("Clayton", 2, 500); [alpha, ci] = copulafit ("Clayton", u) ***** demo ## Fit a Gaussian copula and report the correlation matrix rng (42); randg ('state', 42); u = copularnd ("Gaussian", 0.6, 500); rho = copulafit ("Gaussian", u) ***** shared u u = [0.08,0.12; 0.17,0.25; 0.23,0.19; 0.31,0.42; 0.39,0.35; 0.46,0.51; ... 0.52,0.48; 0.58,0.63; 0.64,0.59; 0.71,0.68; 0.77,0.82; 0.83,0.79; ... 0.88,0.91; 0.93,0.87; 0.97,0.95]; ***** test rho = copulafit ("Gaussian", u); assert_equal (rho, [1, 0.979591430658725; 0.979591430658725, 1], 1e-12); ***** test [a, ci] = copulafit ("Clayton", u); assert_equal (a, 8.70842970823662, 1e-6); assert_equal (ci, [4.48832722027934, 12.9285321961939], 1e-5); ***** test [a, ci] = copulafit ("Frank", u); assert_equal (a, 29.7092786222299, 1e-5); assert_equal (ci, [7.05441865208815, 52.3641385923717], 1e-4); ***** test [a, ci] = copulafit ("Gumbel", u); assert_equal (a, 6.14597585483989, 1e-6); assert_equal (ci, [2.94928782240414, 9.34266388727563], 1e-5); ***** test [rho, nu] = copulafit ("t", u); assert_equal (rho, [1, 0.98084; 0.98084, 1], 2e-3); assert_equal (nu > 10, true); ***** test [~, ci95] = copulafit ("Clayton", u); [~, ci99] = copulafit ("Clayton", u, "alpha", 0.01); assert_equal (ci99(1) < ci95(1) && ci99(2) > ci95(2), true); ***** test rng (42); u = copularnd ("Clayton", 2, 2000); a = copulafit ("Clayton", u); assert_equal (a, 2, 0.3); ***** error ... copulafit (5, [0.2, 0.3]) ***** error ... copulafit ("Gaussian", "foo") ***** error ... copulafit ("Gaussian", [0.2, 0.3; 1.2, 0.5]) ***** error ... copulafit ("Gaussian", [0.2; 0.3; 0.4]) ***** error ... [a, b] = copulafit ("Gaussian", [0.2, 0.3; 0.4, 0.5]); ***** error ... copulafit ("t", [0.2, 0.3, 0.4; 0.5, 0.6, 0.7]) ***** error ... copulafit ("Clayton", [0.2, 0.3, 0.4; 0.5, 0.6, 0.7]) ***** error ... copulafit ("Clayton", [0.2, 0.3; 0.4, 0.5], "foo") ***** error ... copulafit ("Clayton", [0.2, 0.3; 0.4, 0.5], "alpha", 2) ***** error ... copulafit ("Foo", [0.2, 0.3; 0.4, 0.5]) 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/gumbelfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/gumbelfit.m ***** demo ## Sample 3 populations from different Gumbel distributions rng (42); r1 = gumbelrnd (2, 5, 400, 1); r2 = gumbelrnd (-5, 3, 400, 1); r3 = gumbelrnd (14, 8, 400, 1); r = [r1, r2, r3]; ## Plot them normalized and fix their colors hist (r, 25, 0.32); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); set (h(3), 'facecolor', 'r'); ylim ([0, 0.28]) xlim ([-11, 50]); hold on ## Estimate their MU and BETA parameters mu_betaA = gumbelfit (r(:,1)); mu_betaB = gumbelfit (r(:,2)); mu_betaC = gumbelfit (r(:,3)); ## Plot their estimated PDFs x = [min(r(:)):max(r(:))]; y = gumbelpdf (x, mu_betaA(1), mu_betaA(2)); plot (x, y, '-pr'); y = gumbelpdf (x, mu_betaB(1), mu_betaB(2)); plot (x, y, '-sg'); y = gumbelpdf (x, mu_betaC(1), mu_betaC(2)); plot (x, y, '-^c'); legend ({'Normalized HIST of sample 1 with μ=2 and β=5', ... 'Normalized HIST of sample 2 with μ=-5 and β=3', ... 'Normalized HIST of sample 3 with μ=14 and β=8', ... sprintf("PDF for sample 1 with estimated μ=%0.2f and β=%0.2f", ... mu_betaA(1), mu_betaA(2)), ... sprintf("PDF for sample 2 with estimated μ=%0.2f and β=%0.2f", ... mu_betaB(1), mu_betaB(2)), ... sprintf("PDF for sample 3 with estimated μ=%0.2f and β=%0.2f", ... mu_betaC(1), mu_betaC(2))}) title ('Three population samples from different Gumbel distributions') hold off ***** test x = 1:50; [paramhat, paramci] = gumbelfit (x); paramhat_out = [18.3188, 13.0509]; paramci_out = [14.4882, 10.5294; 22.1495, 16.1763]; assert_equal (paramhat, paramhat_out, 1e-4); assert_equal (paramci, paramci_out, 1e-4); ***** test x = 1:50; [paramhat, paramci] = gumbelfit (x, 0.01); paramci_out = [13.2845, 9.8426; 23.3532, 17.3051]; assert_equal (paramci, paramci_out, 1e-4); ***** error gumbelfit (ones (2,5)); ***** error ... gumbelfit (single (ones (1,5))); ***** error ... gumbelfit ([1, 2, 3, 4, NaN]); ***** error gumbelfit ([1, 2, 3, 4, 5], 1.2); ***** error ... gumbelfit ([1, 2, 3, 4, 5], 0.05, [1 1 0]); ***** error ... gumbelfit ([1, 2, 3, 4, 5], 0.05, [], [1 1 0]); ***** error gamfit ([1, 2, 3], 0.05, [], [1 5 -1]) ***** error ... gumbelfit ([1, 2, 3, 4, 5], 0.05, [], [], 2); 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/gamfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/gamfit.m ***** demo ## Sample 3 populations from different Gamma distributions randg ('state', 42); r1 = gamrnd (1, 2, 2000, 1); r2 = gamrnd (2, 2, 2000, 1); r3 = gamrnd (7.5, 1, 2000, 1); r = [r1, r2, r3]; ## Plot them normalized and fix their colors hist (r, 75, 4); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); set (h(3), 'facecolor', 'r'); ylim ([0, 0.62]); xlim ([0, 12]); hold on ## Estimate their α and β parameters a_bA = gamfit (r(:,1)); a_bB = gamfit (r(:,2)); a_bC = gamfit (r(:,3)); ## Plot their estimated PDFs x = [0.01,0.1:0.2:18]; y = gampdf (x, a_bA(1), a_bA(2)); plot (x, y, '-pr'); y = gampdf (x, a_bB(1), a_bB(2)); plot (x, y, '-sg'); y = gampdf (x, a_bC(1), a_bC(2)); plot (x, y, '-^c'); hold off legend ({'Normalized HIST of sample 1 with α=1 and β=2', ... 'Normalized HIST of sample 2 with α=2 and β=2', ... 'Normalized HIST of sample 3 with α=7.5 and β=1', ... sprintf("PDF for sample 1 with estimated α=%0.2f and β=%0.2f", ... a_bA(1), a_bA(2)), ... sprintf("PDF for sample 2 with estimated α=%0.2f and β=%0.2f", ... a_bB(1), a_bB(2)), ... sprintf("PDF for sample 3 with estimated α=%0.2f and β=%0.2f", ... a_bC(1), a_bC(2))}) title ('Three population samples from different Gamma distributions') hold off ***** shared x x = [1.2 1.6 1.7 1.8 1.9 2.0 2.2 2.6 3.0 3.5 4.0 4.8 5.6 6.6 7.6]; ***** test [paramhat, paramci] = gamfit (x); assert_equal (paramhat, [3.4248, 0.9752], 1e-4); assert_equal (paramci, [1.7287, 0.4670; 6.7852, 2.0366], 1e-4); ***** test [paramhat, paramci] = gamfit (x, 0.01); assert_equal (paramhat, [3.4248, 0.9752], 1e-4); assert_equal (paramci, [1.3945, 0.3705; 8.4113, 2.5668], 1e-4); ***** test freq = [1 1 1 1 2 1 1 1 1 2 1 1 1 1 2]; [paramhat, paramci] = gamfit (x, [], [], freq); assert_equal (paramhat, [3.3025, 1.0615], 1e-4); assert_equal (paramci, [1.7710, 0.5415; 6.1584, 2.0806], 1e-4); ***** test [paramhat, paramci] = gamfit (x, [], [], [1:15]); assert_equal (paramhat, [4.4484, 0.9689], 1e-4); assert_equal (paramci, [3.4848, 0.7482; 5.6785, 1.2546], 1e-4); ***** test [paramhat, paramci] = gamfit (x, 0.01, [], [1:15]); assert_equal (paramhat, [4.4484, 0.9689], 1e-4); assert_equal (paramci, [3.2275, 0.6899; 6.1312, 1.3608], 1e-4); ***** test cens = [0 0 0 0 1 0 0 0 0 0 0 0 0 0 0]; [paramhat, paramci] = gamfit (x, [], cens, [1:15]); assert_equal (paramhat, [4.7537, 0.9308], 1e-4); assert_equal (paramci, [3.7123, 0.7162; 6.0872, 1.2097], 1e-4); ***** test cens = [0 0 0 0 1 0 0 0 0 0 0 0 0 0 0]; freq = [1 1 1 1 2 1 1 1 1 2 1 1 1 1 2]; [paramhat, paramci] = gamfit (x, [], cens, freq); assert_equal (paramhat, [3.4736, 1.0847], 1e-4); assert_equal (paramci, [1.8286, 0.5359; 6.5982, 2.1956], 1e-4); ***** test [paramhat, paramci] = gamfit ([1 1 1 1 1 1]); assert_equal (paramhat, [Inf, 0]); assert_equal (paramci, [Inf, 0; Inf, 0]); ***** test [paramhat, paramci] = gamfit ([1 1 1 1 1 1], [], [1 1 1 1 1 1]); assert_equal (paramhat, [NaN, NaN]); assert_equal (paramci, [NaN, NaN; NaN, NaN]); ***** test [paramhat, paramci] = gamfit ([1 1 1 1 1 1], [], [], [1 1 1 1 1 1]); assert_equal (paramhat, [Inf, 0]); assert_equal (paramci, [Inf, 0; Inf, 0]); ***** assert_equal (class (gamfit (single (x))), "single") ***** error gamfit (ones (2)) ***** error gamfit (x, 1) ***** error gamfit (x, -1) ***** error gamfit (x, {0.05}) ***** error gamfit (x, 'a') ***** error gamfit (x, i) ***** error gamfit (x, [0.01 0.02]) ***** error gamfit ([1 2 3], 0.05, [], [1 5]) ***** error gamfit ([1 2 3], 0.05, [], [1 5 -1]) ***** error ... gamfit ([1:10], 0.05, [], [], 5) ***** error gamfit ([1 2 3 -4]) ***** error ... gamfit ([1 2 0], [], [1 0 0]) 23 tests, 23 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/poissfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/poissfit.m ***** demo ## Sample 3 populations from 3 different Poisson distributions rng (42); randp ('state', 42); r1 = poissrnd (1, 1000, 1); r2 = poissrnd (4, 1000, 1); r3 = poissrnd (10, 1000, 1); r = [r1, r2, r3]; ## Plot them normalized and fix their colors hist (r, [0:20], 1); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); set (h(3), 'facecolor', 'r'); hold on ## Estimate their lambda parameter lambdahat = poissfit (r); ## Plot their estimated PDFs x = [0:20]; y = poisspdf (x, lambdahat(1)); plot (x, y, '-pr'); y = poisspdf (x, lambdahat(2)); plot (x, y, '-sg'); y = poisspdf (x, lambdahat(3)); plot (x, y, '-^c'); xlim ([0, 20]) ylim ([0, 0.4]) legend ({'Normalized HIST of sample 1 with λ=1', ... 'Normalized HIST of sample 2 with λ=4', ... 'Normalized HIST of sample 3 with λ=10', ... sprintf("PDF for sample 1 with estimated λ=%0.2f", ... lambdahat(1)), ... sprintf("PDF for sample 2 with estimated λ=%0.2f", ... lambdahat(2)), ... sprintf("PDF for sample 3 with estimated λ=%0.2f", ... lambdahat(3))}) title ('Three population samples from different Poisson distributions') hold off ***** test x = [1 3 2 4 5 4 3 4]; [lhat, lci] = poissfit (x); assert_equal (lhat, 3.25) assert_equal (lci, [2.123007901949543; 4.762003010390628], 1e-14) ***** test x = [1 3 2 4 5 4 3 4]; [lhat, lci] = poissfit (x, 0.01); assert_equal (lhat, 3.25) assert_equal (lci, [1.842572740234582; 5.281369033298528], 1e-14) ***** test x = [1 2 3 4 5]; f = [1 1 2 3 1]; [lhat, lci] = poissfit (x, [], f); assert_equal (lhat, 3.25) assert_equal (lci, [2.123007901949543; 4.762003010390628], 1e-14) ***** test x = [1 2 3 4 5]; f = [1 1 2 3 1]; [lhat, lci] = poissfit (x, 0.01, f); assert_equal (lhat, 3.25) assert_equal (lci, [1.842572740234582; 5.281369033298528], 1e-14) ***** error poissfit ([1 2 -1 3]) ***** error poissfit ([1 2 3], 0) ***** error poissfit ([1 2 3], 1.2) ***** error poissfit ([1 2 3], [0.02 0.05]) ***** error poissfit ([1 2 3], [], [1 5]) ***** error poissfit ([1 2 3], [], [1 5 -1]) 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/logilike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/logilike.m ***** test nlogL = logilike ([25.5, 8.7725], [1:50]); assert_equal (nlogL, 206.6769, 1e-4); ***** test nlogL = logilike ([3, 0.8645], [1:5]); assert_equal (nlogL, 9.0699, 1e-4); ***** error logilike (3.25) ***** error logilike ([5, 0.2], ones (2)) ***** error ... logilike ([1, 0.2, 3], [1, 3, 5, 7]) ***** error ... logilike ([1.5, 0.2], [1:5], [0, 0, 0]) ***** error ... logilike ([1.5, 0.2], [1:5], [0, 0, 0, 0, 0], [1, 1, 1]) ***** error ... logilike ([1.5, 0.2], [1:5], [], [1, 1, 1]) 8 tests, 8 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/invgfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/invgfit.m ***** demo ## Sample 3 populations from different inverse Gaussian distributions rng (42); r1 = invgrnd (1, 0.2, 2000, 1); r2 = invgrnd (1, 3, 2000, 1); r3 = invgrnd (3, 1, 2000, 1); r = [r1, r2, r3]; ## Plot them normalized and fix their colors hist (r, [0.1:0.1:3.2], 9); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); set (h(3), 'facecolor', 'r'); ylim ([0, 3]); xlim ([0, 3]); hold on ## Estimate their MU and LAMBDA parameters mu_lambdaA = invgfit (r(:,1)); mu_lambdaB = invgfit (r(:,2)); mu_lambdaC = invgfit (r(:,3)); ## Plot their estimated PDFs x = [0:0.1:3]; y = invgpdf (x, mu_lambdaA(1), mu_lambdaA(2)); plot (x, y, '-pr'); y = invgpdf (x, mu_lambdaB(1), mu_lambdaB(2)); plot (x, y, '-sg'); y = invgpdf (x, mu_lambdaC(1), mu_lambdaC(2)); plot (x, y, '-^c'); hold off legend ({'Normalized HIST of sample 1 with μ=1 and λ=0.5', ... 'Normalized HIST of sample 2 with μ=2 and λ=0.3', ... 'Normalized HIST of sample 3 with μ=4 and λ=0.5', ... sprintf("PDF for sample 1 with estimated μ=%0.2f and λ=%0.2f", ... mu_lambdaA(1), mu_lambdaA(2)), ... sprintf("PDF for sample 2 with estimated μ=%0.2f and λ=%0.2f", ... mu_lambdaB(1), mu_lambdaB(2)), ... sprintf("PDF for sample 3 with estimated μ=%0.2f and λ=%0.2f", ... mu_lambdaC(1), mu_lambdaC(2))}) title ('Three population samples from different inverse Gaussian distributions') hold off ***** test paramhat = invgfit ([1:50]); paramhat_out = [25.5, 19.6973]; assert_equal (paramhat, paramhat_out, 1e-4); ***** test paramhat = invgfit ([1:5]); paramhat_out = [3, 8.1081]; assert_equal (paramhat, paramhat_out, 1e-4); ***** error invgfit (ones (2,5)); ***** error invgfit ([-1 2 3 4]); ***** error invgfit ([1, 2, 3, 4, 5], 1.2); ***** error invgfit ([1, 2, 3, 4, 5], 0); ***** error invgfit ([1, 2, 3, 4, 5], 'alpha'); ***** error ... invgfit ([1, 2, 3, 4, 5], 0.05, [1 1 0]); ***** error ... invgfit ([1, 2, 3, 4, 5], [], [1 1 0 1 1]'); ***** error ... invgfit ([1, 2, 3, 4, 5], 0.05, zeros (1,5), [1 1 0]); ***** error ... invgfit ([1, 2, 3, 4, 5], [], [], [1 1 0 1 1]'); ***** error ... invgfit ([1, 2, 3, 4, 5], 0.05, [], [], 2); 12 tests, 12 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/gevlike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/gevlike.m ***** test x = 1; k = 0.2; sigma = 0.3; mu = 0.5; [L, C] = gevlike ([k sigma mu], x); expected_L = 0.75942; expected_C = [-0.12547 1.77884 1.06731; 1.77884 16.40761 8.48877; 1.06731 8.48877 0.27979]; assert_equal (L, expected_L, 0.001); assert_equal (C, inv (expected_C), 0.001); ***** test x = 1; k = 0; sigma = 0.3; mu = 0.5; [L, C] = gevlike ([k sigma mu], x); expected_L = 0.65157; expected_C = [0.090036 3.41229 2.047337; 3.412229 24.760027 12.510190; 2.047337 12.510190 2.098618]; assert_equal (L, expected_L, 0.001); assert_equal (C, inv (expected_C), 0.001); ***** test ## ACOV is continuous at k = 0: the Gumbel-limit branch agrees with the ## general expressions evaluated just off zero. MATLAB's k = 0 branch does ## not, returning ACOV(1,1) = -0.3977 against the limit's -2.8133. [~, C0] = gevlike ([0, 0.3, 0.5], 1); [~, Ce] = gevlike ([1e-5, 0.3, 0.5], 1); assert_equal (C0, Ce, 1e-3); assert_equal (C0(1,1), -2.813275839387, 1e-9); ***** test x = -5:-1; k = -0.2; sigma = 0.3; mu = 0.5; [L, C] = gevlike ([k sigma mu], x); expected_L = 3786.4; expected_C = [1.6802e-07, 4.6110e-06, 8.7297e-05; ... 4.6110e-06, 7.5693e-06, 1.2034e-05; ... 8.7297e-05, 1.2034e-05, -0.0019125]; assert_equal (L, expected_L, -0.001); assert_equal (C, expected_C, -0.001); ***** test x = -5:0; k = -0.2; sigma = 0.3; mu = 0.5; [L, C] = gevlike ([k sigma mu], x, [1, 1, 1, 1, 1, 0]); expected_L = 3786.4; expected_C = [1.6802e-07, 4.6110e-06, 8.7297e-05; ... 4.6110e-06, 7.5693e-06, 1.2034e-05; ... 8.7297e-05, 1.2034e-05, -0.0019125]; assert_equal (L, expected_L, -0.001); assert_equal (C, expected_C, -0.001); ***** error gevlike (3.25) ***** error gevlike ([1, 2, 3], ones (2)) ***** error ... gevlike ([1, 2], [1, 3, 5, 7]) ***** error ... gevlike ([1, 2, 3, 4], [1, 3, 5, 7]) ***** error ... gevlike ([5, 0.2, 1], ones (10, 1), ones (8,1)) ***** error ... gevlike ([5, 0.2, 1], ones (1, 8), [1 1 1 1 1 1 1 -1]) ***** error ... gevlike ([5, 0.2, 1], ones (1, 8), [1 1 1 1 1 1 1 1.5]) 12 tests, 12 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/betalike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/betalike.m ***** test x = 0.01:0.02:0.99; [nlogL, avar] = betalike ([2.3, 1.2], x); avar_out = [0.03691678, 0.02803056; 0.02803056, 0.03965629]; assert_equal (nlogL, 17.873477715879040, 3e-14); assert_equal (avar, avar_out, 1e-7); ***** test x = 0.01:0.02:0.99; [nlogL, avar] = betalike ([1, 4], x); avar_out = [0.02793282, 0.02717274; 0.02717274, 0.03993361]; assert_equal (nlogL, 79.648061114839550, 1e-13); assert_equal (avar, avar_out, 1e-7); ***** test x = 0.00:0.02:1; [nlogL, avar] = betalike ([1, 4], x); avar_out = [0.00000801564765, 0.00000131397245; ... 0.00000131397245, 0.00070827639442]; assert_equal (nlogL, 573.2008434477486, 1e-10); assert_equal (avar, avar_out, 1e-14); ***** error ... betalike ([12, 15]); ***** error betalike ([12, 15, 3], [1:50]); ***** error ... betalike ([12, 15], ones (10, 1), ones (8,1)) ***** error ... betalike ([12, 15], ones (1, 8), [1 1 1 1 1 1 1 -1]) ***** error ... betalike ([12, 15], ones (1, 8), [1 1 1 1 1 1 1 1.5]) 8 tests, 8 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/bisalike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/bisalike.m ***** test nlogL = bisalike ([16.2649, 1.0156], [1:50]); assert_equal (nlogL, 215.5905, 1e-4); ***** test nlogL = bisalike ([2.5585, 0.5839], [1:5]); assert_equal (nlogL, 8.9950, 1e-4); ***** error bisalike (3.25) ***** error bisalike ([5, 0.2], ones (2)) ***** error bisalike ([5, 0.2], [-1, 3]) ***** error ... bisalike ([1, 0.2, 3], [1, 3, 5, 7]) ***** error ... bisalike ([1.5, 0.2], [1:5], [0, 0, 0]) ***** error ... bisalike ([1.5, 0.2], [1:5], [0, 0, 0, 0, 0], [1, 1, 1]) ***** error ... bisalike ([1.5, 0.2], [1:5], [], [1, 1, 1]) 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/stbllike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/stbllike.m ***** demo ## Negative log-likelihood of a stable fit to simulated data rng (42); x = stblrnd (1.5, 0.5, 1, 0, 150, 1); phat = stblfit (x); nlogL = stbllike (phat, x) ***** test # matches -sum (log (pdf)); stbllike uses a fast CF-inversion density # that differs from stblpdf by a few parts in 1e-5 x = [-2.3, -0.9, 0.1, 0.4, 1.2, 2.8, 5.1]; nlogL = stbllike ([1.5, 0.5, 1, 0], x); assert_equal (nlogL, - sum (log (stblpdf (x, 1.5, 0.5, 1, 0))), 1e-3); ***** test # frequency weights replicate observations x = [-1, 0.5, 2]; f = [2, 1, 3]; xr = [-1, -1, 0.5, 2, 2, 2]; assert_equal (stbllike ([1.2, 0, 1, 0], x, f), ... stbllike ([1.2, 0, 1, 0], xr), 1e-6); ***** test # acov is symmetric positive (co)variance at a sensible parameter rand ("seed", 1); x = stblrnd (1.6, 0, 1, 0, 150, 1); [~, acov] = stbllike ([1.6, 0, 1, 0], x); assert_equal (issymmetric (acov, 1e-10), true); assert_equal (all (diag (acov) > 0, 'all'), true); ***** error ... stbllike ([1.5, 0, 1, 0]) ***** error stbllike ([1.5, 0, 1, 0], ones (2, 2)) ***** error ... stbllike ([1.5, 0, 1], [1, 2, 3]) ***** error ... stbllike ([1.5, 0, 1, 0], [1, 2, 3], [1, 2]) ***** error ... stbllike ([1.5, 0, 1, 0], [1, 2, 3], [1, -1, 2]) ***** error ... stbllike ([1.5, 0, 1, 0], [1, 2, 3], [1, 1.5, 2]) 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/wblfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/wblfit.m ***** demo ## Sample 3 populations from 3 different Weibull distributions rande ('state', 42); r1 = wblrnd (2, 4, 2000, 1); r2 = wblrnd (5, 2, 2000, 1); r3 = wblrnd (1, 5, 2000, 1); r = [r1, r2, r3]; ## Plot them normalized and fix their colors hist (r, 30, [2.5 2.1 3.2]); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); set (h(3), 'facecolor', 'r'); ylim ([0, 2]); xlim ([0, 10]); hold on ## Estimate their lambda parameter lambda_kA = wblfit (r(:,1)); lambda_kB = wblfit (r(:,2)); lambda_kC = wblfit (r(:,3)); ## Plot their estimated PDFs x = [0:0.1:15]; y = wblpdf (x, lambda_kA(1), lambda_kA(2)); plot (x, y, '-pr'); y = wblpdf (x, lambda_kB(1), lambda_kB(2)); plot (x, y, '-sg'); y = wblpdf (x, lambda_kC(1), lambda_kC(2)); plot (x, y, '-^c'); hold off legend ({'Normalized HIST of sample 1 with λ=2 and k=4', ... 'Normalized HIST of sample 2 with λ=5 and k=2', ... 'Normalized HIST of sample 3 with λ=1 and k=5', ... sprintf("PDF for sample 1 with estimated λ=%0.2f and k=%0.2f", ... lambda_kA(1), lambda_kA(2)), ... sprintf("PDF for sample 2 with estimated λ=%0.2f and k=%0.2f", ... lambda_kB(1), lambda_kB(2)), ... sprintf("PDF for sample 3 with estimated λ=%0.2f and k=%0.2f", ... lambda_kC(1), lambda_kC(2))}) title ('Three population samples from different Weibull distributions') hold off ***** test x = 1:50; [paramhat, paramci] = wblfit (x); paramhat_out = [28.3636, 1.7130]; paramci_out = [23.9531, 1.3551; 33.5861, 2.1655]; assert_equal (paramhat, paramhat_out, 1e-4); assert_equal (paramci, paramci_out, 1e-4); ***** test x = 1:50; [paramhat, paramci] = wblfit (x, 0.01); paramci_out = [22.7143, 1.2589; 35.4179, 2.3310]; assert_equal (paramci, paramci_out, 1e-4); ***** error wblfit (ones (2,5)); ***** error wblfit ([-1 2 3 4]); ***** error wblfit ([1, 2, 3, 4, 5], 1.2); ***** error wblfit ([1, 2, 3, 4, 5], 0); ***** error wblfit ([1, 2, 3, 4, 5], 'alpha'); ***** error ... wblfit ([1, 2, 3, 4, 5], 0.05, [1 1 0]); ***** error ... wblfit ([1, 2, 3, 4, 5], [], [1 1 0 1 1]'); ***** error ... wblfit ([1, 2, 3, 4, 5], 0.05, zeros (1,5), [1 1 0]); ***** error ... wblfit ([1, 2, 3, 4, 5], [], [], [1 1 0 -1 1]); ***** error ... wblfit ([1, 2, 3, 4, 5], [], [], [1 1 0 1 1]'); ***** error ... wblfit ([1, 2, 3, 4, 5], 0.05, [], [], 2); 13 tests, 13 passed, 0 known failure, 0 skipped [inst/Distribution_Fitting/tlslike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Fitting/tlslike.m ***** test x = [-1.2352, -0.2741, 0.1726, 7.4356, 1.0392, 16.4165]; [nlogL, acov] = tlslike ([0.035893, 0.862711, 0.649261], x); acov_out = [0.2525, 0.0670, 0.0288; ... 0.0670, 0.5724, 0.1786; ... 0.0288, 0.1786, 0.1789]; assert_equal (nlogL, 17.9979636579, 1e-10); assert_equal (acov, acov_out, 1e-4); ***** error tlslike ([12, 15, 1]); ***** error tlslike ([12, 15], [1:50]); ***** error tlslike ([12, 3, 1], ones (10, 2)); ***** error tlslike ([12, 15, 1], [1:50], [1, 2, 3]); ***** error tlslike ([12, 15, 1], [1:50], [], [1, 2, 3]); ***** error tlslike ([12, 15, 1], [1:3], [], [1, 2, -3]); 7 tests, 7 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/mcnemar_test.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/mcnemar_test.m ***** test [h, p, st] = mcnemar_test ([101,121;59,33]); assert_equal (h, 1); assert_equal (p, 3.8151e-06, 1e-10); assert_equal (st.chi2stat, 21.356, 1e-3); ***** test [h, p, st] = mcnemar_test ([59,6;16,80]); assert_equal (h, 1); assert_equal (p, 0.034690, 1e-6); assert_equal (isfield (st, 'chi2stat'), false); ***** test [h, p] = mcnemar_test ([59,6;16,80], 'Alpha', 0.01); assert_equal (h, 0); assert_equal (p, 0.034690, 1e-6); ***** test [h, p] = mcnemar_test ([59,6;16,80], 'mid-p'); assert_equal (h, 1); assert_equal (p, 0.034690, 1e-6); ***** test [h, p, st] = mcnemar_test ([59,6;16,80], 'asymptotic'); assert_equal (h, 1); assert_equal (p, 0.033006, 1e-6); assert_equal (st.chi2stat, 4.5455, 1e-4); assert_equal (st.df, 1); ***** test [h, p, st] = mcnemar_test ([59,6;16,80], 'exact'); assert_equal (h, 0); assert_equal (p, 0.052479, 1e-6); assert_equal (isfield (st, 'chi2stat'), false); ***** test [h, p, st] = mcnemar_test ([59,6;16,80], 'corrected'); assert_equal (h, 0); assert_equal (p, 0.055009, 1e-6); assert_equal (st.chi2stat, 3.6818, 1e-4); ***** test [h, p] = mcnemar_test ([59,6;16,80], 'corrected', 'Alpha', 0.1); assert_equal (h, 1); assert_equal (p, 0.055009, 1e-6); ***** test ## Below the resolution of 1 - chi2cdf [~, p, st] = mcnemar_test ([100, 200; 0, 100]); assert_equal (p, erfc (sqrt (st.chi2stat / 2)), -1e-12); ***** test ## The exact tests are symmetric in the discordant counts, values from R [~, p] = mcnemar_test ([59,16;6,80], 'exact'); assert_equal (p, 0.052479, 1e-6); ***** test [~, p] = mcnemar_test ([59,16;6,80], 'mid-p'); assert_equal (p, 0.034690, 1e-6); ***** test [~, p] = mcnemar_test ([5,7;7,5], 'exact'); assert_equal (p, 1); ***** test [~, ~, st] = mcnemar_test ([59,6;16,80]); assert_equal (st.OddsRatio, 6 / 16); ***** test ## Clopper-Pearson interval of 6/22 from R's binom.test [~, ~, st] = mcnemar_test ([59,6;16,80]); assert_equal (st.OddsRatioCI, [0.12018366326892038, 1.0089244510694295], ... -1e-12); ***** test [~, ~, st] = mcnemar_test ([59,6;16,80]); assert_equal (st.CohensG, 6 / 22 - 0.5, -1e-14); ***** test [~, ~, st] = mcnemar_test ([59,6;16,80]); assert_equal (st.CohensGCI, ... [0.10728924837039702, 0.50222120126634895] - 0.5, -1e-12); ***** test [~, ~, st] = mcnemar_test ([101,121;59,33], 'Alpha', 0.01); assert_equal (st.OddsRatioCI, [1.3562696986628573, 3.1577641330443376], ... -1e-12); ***** test ## With no discordant pairs there is no effect to measure [~, ~, st] = mcnemar_test ([5,0;0,5]); assert_equal ([st.OddsRatio, st.CohensG], [NaN, NaN]); ***** test [~, ~, st] = mcnemar_test ([5,3;0,5]); assert_equal ([st.OddsRatio, st.OddsRatioCI(2)], [Inf, Inf]); ***** error mcnemar_test (59, 6, 16, 80) ***** error mcnemar_test (ones (3, 3)) ***** error ... mcnemar_test ([59,6;16,-80]) ***** error ... mcnemar_test ([59,6;16,4.5]) ***** error ... mcnemar_test ([59,6;16,80], {''}) ***** error ... mcnemar_test ([59,6;16,80], 0.05) ***** error ... mcnemar_test ([59,6;16,80], 'Alpha') ***** error ... mcnemar_test ([59,6;16,80], 'Alpha', -0.2) ***** error ... mcnemar_test ([59,6;16,80], 'Alpha', [0.05, 0.1]) ***** error ... mcnemar_test ([59,6;16,80], 'Alpha', 1) ***** error ... mcnemar_test ([59,6;16,80], '') 30 tests, 30 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/signtest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/signtest.m ***** test [pval, h, stats] = signtest ([-ones(1, 1000) 1], 0, 'tail', 'left'); assert_equal (pval, 1.091701889420221e-218, 1e-14); assert_equal (h, true); assert_equal (stats.zval, -31.5437631079266, 1e-14); ***** test [pval, h, stats] = signtest ([-2 -1 0 2 1 3 1], 0); assert_equal (pval, 0.6875000000000006, 1e-14); assert_equal (h, false); assert_equal (stats.zval, NaN); assert_equal (stats.sign, 4); ***** test [pval, h, stats] = signtest ([-2 -1 0 2 1 3 1], 0, 'method', 'approximate'); assert_equal (pval, 0.6830913983096086, 1e-14); assert_equal (h, false); assert_equal (stats.zval, 0.4082482904638631, 1e-14); assert_equal (stats.sign, 4); ***** test x = [1, 2, 3, 4, NaN, NaN, NaN]; [pval, h] = signtest (x); assert_equal (pval, 0.1250, 1e-4); assert_equal (h, false); ***** test x = [1, 2, 3, 4, 5]; y = [1, 1, NaN, 5, 4]; [pval, h] = signtest (x, y); assert_equal (pval, 1.0, 1e-4); assert_equal (h, false); ***** test x = [1, 2, 3, 4, 5, -1]; [p_val, ~] = signtest (x); [p, h, stats] = signtest (x, 0, 'alpha', p_val); assert_equal (h, true); ***** test ## the decision is logical, as it is in MATLAB and in signrank and ranksum [~, h] = signtest ([1.2 2.3 0.5 3.1 2.2 1.8 0.9 2.7 1.1 3.3], 2); assert_equal (class (h), 'logical'); assert_equal (h, false); ***** test [~, h] = signtest ([1.2 2.3 0.5 3.1 2.2 1.8 0.9 2.7 1.1 3.3], 100); assert_equal (class (h), 'logical'); assert_equal (h, true); ***** error signtest (ones (2)) ***** error ... signtest ([1, 2, 3, 4], ones (2)) ***** error ... signtest ([1, 2, 3, 4], [1, 2, 3]) ***** error ... signtest ([1, 2, 3, 4], [], 'tail') ***** error ... signtest ([1, 2, 3, 4], [], 'alpha', 1.2) ***** error ... signtest ([1, 2, 3, 4], [], 'alpha', 0) ***** error ... signtest ([1, 2, 3, 4], [], 'alpha', -0.05) ***** error ... signtest ([1, 2, 3, 4], [], 'alpha', 'a') ***** error ... signtest ([1, 2, 3, 4], [], 'alpha', [0.01, 0.05]) ***** error ... signtest ([1, 2, 3, 4], [], 'tail', 0.01) ***** error ... signtest ([1, 2, 3, 4], [], 'tail', {'both'}) ***** error ... signtest ([1, 2, 3, 4], [], 'tail', 'some') ***** error ... signtest ([1, 2, 3, 4], [], 'method', 'exact', 'tail', 'some') ***** error ... signtest ([1, 2, 3, 4], [], 'method', 0.01) ***** error ... signtest ([1, 2, 3, 4], [], 'method', {'exact'}) ***** error ... signtest ([1, 2, 3, 4], [], 'method', 'some') ***** error ... signtest ([1, 2, 3, 4], [], 'tail', 'both', 'method', 'some') 25 tests, 25 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/knntest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/knntest.m ***** shared XS, YS, XA, YA XS = [8, 4; 13, 1; 14, 2; 3, 3]; YS = [3, 19; 1, 7; 1, 17; 4, 10; 2, 17]; XA = [2, 2, 3; 3, 1, 1; 3, 1, 3; 3, 3, 1; 3, 3, 2; 1, 1, 1]; YA = [3, 2, 2; 1, 2, 2; 3, 2, 2; 2, 3, 3; 2, 1, 1; 3, 1, 1]; ***** test ## A tie goes to the lower pooled index [s, p, h] = knntest ([0; 20], [1; 2], 'NumNeighbors', 1, ... 'Distance', 'euclidean'); assert_equal (s, 0.25); assert_equal (p, 0.593168142116604, -1e-13); assert_equal (h, 0); ***** test [s, p] = knntest ([1; 2], [0; 20], 'NumNeighbors', 1, ... 'Distance', 'euclidean'); assert_equal (s, 0.5); assert_equal (p, 0.318675944116969, -1e-13); ***** test ## An observation is never its own neighbour, even beside a duplicate [s, p] = knntest ([0; 5], [0; 9], 'NumNeighbors', 1, ... 'Distance', 'euclidean'); assert_equal (s, 0); assert_equal (p, 0.827110706924420, -1e-13); ***** test ## seuclidean, the default, scales by the standard deviation over [X; Y] [s, p, h] = knntest (XS, YS, 'NumNeighbors', 1); assert_equal (s, 7 / 9, -1e-14); assert_equal (p, 0.076726923031103, -1e-13); assert_equal (h, 0); ***** assert_equal (knntest (XS, YS, 'NumNeighbors', 1, ... 'Distance', 'SEuclidean'), ... knntest (XS, YS, 'NumNeighbors', 1)) ***** assert_equal (knntest (XS, YS, 'NumNeighbors', 1, 'Distance', ... 'fastseuclidean'), knntest (XS, YS, 'NumNeighbors', 1)) ***** assert_equal (knntest (XS, YS, 'NumNeighbors', 1, ... 'Distance', 'fasteuclidean'), ... knntest (XS, YS, 'NumNeighbors', 1, 'Distance', 'euclidean')) ***** assert_equal (knntest ([XS; NaN, 2], YS, 'NumNeighbors', 1), 7 / 9, -1e-14) ***** test [~, ~, h] = knntest (XS, YS, 'NumNeighbors', 1, 'Alpha', 0.5); assert_equal (h, 1); ***** test ## Goodall 3 counts the query into the frequencies over [X; Y] [s, p] = knntest (XA, YA, 'NumNeighbors', 1, 'CategoricalVariables', ... 'all', 'Distance', 'goodall3'); assert_equal (s, 7 / 12, -1e-14); assert_equal (p, 0.264043416942331, -1e-13); ***** test ## hamming is the default where every variable holds levels [s, p] = knntest (XA, YA, 'NumNeighbors', 1, 'CategoricalVariables', 'all'); assert_equal (s, 7 / 12, -1e-14); assert_equal (p, 0.264043416942331, -1e-13); ***** test ## A level of Y that X lacks keeps its row [s, p] = knntest (XA, [YA; 4, 1, 1], 'NumNeighbors', 1, ... 'CategoricalVariables', 'all', 'Distance', 'goodall3'); assert_equal (s, 7 / 13, -1e-14); assert_equal (p, 0.346797481676874, -1e-13); ***** assert_equal (knntest (XA, [YA; 4, 1, 1], 'NumNeighbors', 1, ... 'CategoricalVariables', 'all'), 7 / 13, -1e-14) ***** test X = [4, 1, 4, 4, 4, 1; 2, 1, 2, 2, 2, 3; 1, 3, 1, 2, 2, 3; 2, 2, 1, 4, 4, 2; 2, 3, 3, 1, 3, 4; 2, 4, 1, 2, 2, 3; 3, 1, 2, 3, 4, 1]; Y = [1, 4, 4, 2, 4, 1; 1, 3, 1, 1, 4, 2; 1, 3, 3, 1, 3, 2; 1, 3, 2, 4, 2, 3; 2, 3, 4, 1, 2, 3; 1, 4, 2, 3, 4, 2; 2, 3, 2, 3, 2, 1]; [s, p] = knntest (X, Y, 'NumNeighbors', 1, 'CategoricalVariables', 'all', ... 'Distance', 'goodall3'); assert_equal (s, 5 / 14, -1e-14); assert_equal (p, 0.709666127521303, -1e-13); ***** test X = [1, 2, 1, 2, 1, 4; 3, 1, 4, 1, 4, 4; 4, 1, 3, 2, 2, 3; 3, 3, 4, 2, 4, 3; 4, 3, 2, 4, 3, 4; 2, 3, 4, 3, 1, 1; 3, 4, 1, 2, 3, 2]; Y = [4, 2, 4, 2, 1, 2; 4, 1, 1, 3, 4, 1; 4, 3, 1, 3, 4, 4; 4, 4, 2, 4, 2, 1; 2, 2, 2, 3, 3, 1; 1, 3, 4, 4, 4, 3; 2, 2, 4, 3, 3, 3]; s = knntest (X, Y, 'NumNeighbors', 1, 'CategoricalVariables', 'all', ... 'Distance', 'goodall3'); assert_equal (s, 5 / 14, -1e-14); ***** test X = [3, 1, 2, 2; 1, 1, 3, 2; 2, 1, 3, 1; 3, 3, 1, 3; 3, 2, 2, 1; 2, 3, 2, 1; 1, 1, 2, 2]; Y = [3, 2, 3, 3; 2, 3, 1, 3; 2, 3, 3, 3; 2, 2, 3, 2; 3, 1, 1, 3; 3, 2, 1, 3; 3, 1, 1, 2]; [s, p] = knntest (X, Y, 'NumNeighbors', 1, 'CategoricalVariables', 'all', ... 'Distance', 'goodall3'); assert_equal (s, 5 / 7, -1e-14); assert_equal (p, 0.090543972339391, -1e-13); ***** test load fisheriris [s, p, h] = knntest (meas(1:25,:), meas(26:50,:)); assert_equal (s, 0.438, -1e-14); assert_equal (p, 0.949281930319421, -1e-13); assert_equal (h, 0); ***** test ## Ties decided by rounding in MATLAB, which gives 0.909 load fisheriris [s, p, h] = knntest (meas(51:100,:), meas(101:150,:)); assert_equal (s, 0.908, -1e-14); assert_equal (p, 1.72915613588074e-76, -1e-10); assert_equal (h, 1); ***** test ## Ties decided by rounding in MATLAB, which gives 0.92 load fisheriris s = knntest (meas(51:100,:), meas(101:150,:), 'NumNeighbors', 5, ... 'Distance', 'cityblock'); assert_equal (s, 0.916, -1e-14); ***** test ## NumNeighbors above the observations but one is taken as that [s, p] = knntest ([0; 20], [1; 2]); assert_equal (s, 1 / 3, -1e-14); assert_equal (p, 0.5, -1e-14); ***** test ## Mixed data: ours; MATLAB's undocumented rule gives 0.583333 X = [3, 51; 3, 53; 2, 44; 2, 56; 1, 46; 3, 45]; Y = [1, 69; 3, 8; 2, 23; 2, 1; 1, 5; 1, 86]; [s, p] = knntest (X, Y, 'NumNeighbors', 1, 'CategoricalVariables', 1); assert_equal (s, 2 / 3, -1e-14); assert_equal (p, 0.14936110409448, -1e-12); ***** test X = [3, 51; 3, 53; 2, 44; 2, 56; 1, 46; 3, 45]; Y = [1, 69; 3, 8; 2, 23; 2, 1; 1, 5; 1, 86]; s = knntest (X, Y, 'NumNeighbors', 1, 'CategoricalVariables', [true, false]); assert_equal (s, knntest (X, Y, 'NumNeighbors', 1, ... 'CategoricalVariables', 1)); ***** test ## A table's categorical variable holds levels without being named X = [1, 89; 2, 58; 1, 99; 2, 52; 1, 84; 3, 49]; Y = [1, 72; 2, 58; 3, 100; 3, 97; 1, 68; 2, 70]; TX = table (categorical (X(:,1)), X(:,2)); TY = table (categorical (Y(:,1)), Y(:,2)); assert_equal (knntest (TX, TY, 'NumNeighbors', 1), ... knntest (X, Y, 'NumNeighbors', 1, 'CategoricalVariables', 1)); ***** test C = {'a', 'b', 'c'}; TX = table (C(XA(:,1))', XA(:,2) == 1, string (C(XA(:,3)))', ... 'VariableNames', {'A', 'B', 'C'}); TY = table (C(YA(:,1))', YA(:,2) == 1, string (C(YA(:,3)))', ... 'VariableNames', {'A', 'B', 'C'}); assert_equal (knntest (TX, TY, 'NumNeighbors', 1), ... knntest ([XA(:,1), XA(:,2) == 1, XA(:,3)], ... [YA(:,1), YA(:,2) == 1, YA(:,3)], ... 'NumNeighbors', 1, 'CategoricalVariables', 'all')); ***** test ## Tables are read over the variables they share TX = table (XS(:,1), XS(:,2), (1:4)', 'VariableNames', {'A', 'B', 'Z'}); TY = table (YS(:,2), YS(:,1), 'VariableNames', {'B', 'A'}); assert_equal (knntest (TX, TY, 'NumNeighbors', 1), 7 / 9, -1e-14); ***** test TX = table (XS(:,1), XS(:,2), 'VariableNames', {'A', 'B'}); TY = table (YS(:,1), YS(:,2), 'VariableNames', {'A', 'B'}); assert_equal (knntest (TX, TY, 'NumNeighbors', 1, 'VariableNames', 'A'), ... knntest (XS(:,1), YS(:,1), 'NumNeighbors', 1)); ***** error knntest (1) ***** error knntest (XS, YS, 'Tail', 1) ***** error ... knntest (XS, YS, 'Alpha', 1) ***** error ... knntest (XS, YS, 'NumNeighbors', 1.5) ***** error ... knntest (table (XS), YS) ***** error ... knntest (XS, YS, 'VariableNames', 'A') ***** error ... knntest ({1}, YS) ***** error ... knntest (XS, YS(:,1)) ***** error ... knntest (table ([1; 2], 'VariableNames', {'A'}), ... table ([1; 2], 'VariableNames', {'B'})) ***** error ... knntest (table ([1; 2], 'VariableNames', {'A'}), ... table ([1; 2], 'VariableNames', {'A'}), 'VariableNames', 'B') ***** error ... knntest (table ([1, 2; 3, 4], 'VariableNames', {'A'}), ... table ([1, 2; 3, 4], 'VariableNames', {'A'})) ***** error ... knntest (table ({1; 2}, 'VariableNames', {'A'}), ... table ({1; 2}, 'VariableNames', {'A'})) ***** error ... knntest (table ([1; 2], 'VariableNames', {'A'}), ... table ({'a'; 'b'}, 'VariableNames', {'A'})) ***** error ... knntest (XS, YS, 'CategoricalVariables', 'A') ***** error ... knntest (table ([1; 2], 'VariableNames', {'A'}), ... table ([1; 2], 'VariableNames', {'A'}), 'CategoricalVariables', 'B') ***** error ... knntest (XS, YS, 'CategoricalVariables', true) ***** error ... knntest (XS, YS, 'CategoricalVariables', 3) ***** error ... knntest ([NaN, 1], YS) ***** error ... knntest (XS, YS, 'Distance', 'minkowski') 45 tests, 45 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/ansaribradley.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/ansaribradley.m ***** demo ## Test whether two samples have the same dispersion. The second sample is ## drawn with twice the standard deviation, so the null hypothesis of equal ## dispersions should be rejected. x = [42, 44, 38, 52, 48, 46, 40, 50]; y = [30, 62, 25, 70, 33, 58, 20, 65]; [h, p, stats] = ansaribradley (x, y) ***** error ansaribradley (1); ***** error ... ansaribradley (ones (3, 2), ones (3, 1)); ***** error ... ansaribradley (ones (3, 1), ones (2, 2)); ***** error ansaribradley ([NaN, NaN], [1, 2]); ***** error ansaribradley ([1, 2], [NaN, NaN]); ***** error ... ansaribradley ([1, 2, 3], [4, 5, 6], 'alpha'); ***** error ... ansaribradley ([1, 2, 3], [4, 5, 6], 'alpha', 0); ***** error ... ansaribradley ([1, 2, 3], [4, 5, 6], 'alpha', 1); ***** error ... ansaribradley ([1, 2, 3], [4, 5, 6], 'alpha', -0.2); ***** error ... ansaribradley ([1, 2, 3], [4, 5, 6], 'alpha', [0.01, 0.05]); ***** error ... ansaribradley ([1, 2, 3], [4, 5, 6], 'alpha', 'x'); ***** error ... ansaribradley ([1, 2, 3], [4, 5, 6], 'tail', 'other'); ***** error ... ansaribradley ([1, 2, 3], [4, 5, 6], 'tail', 5); ***** error ... ansaribradley ([1, 2, 3], [4, 5, 6], 'method', 'other'); ***** error ... ansaribradley ([1, 2, 3], [4, 5, 6], 'method', 5); ***** error ... ansaribradley ([1, 2, 3], [4, 5, 6], 'name', 'value'); ***** test ## A concentrated sample versus a dispersed one (default exact, N = 16). x = [42, 44, 38, 52, 48, 46, 40, 50]; y = [30, 62, 25, 70, 33, 58, 20, 65]; [h, p, stats] = ansaribradley (x, y); assert_equal (h, 1); assert_equal (p, 0.000155400155400155, 1e-15); assert_equal (stats.W, 52); assert_equal (stats.Wstar, 3.38061701891407, 1e-13); ***** test ## Same data, left-tailed exact test (dispersion of X less than Y). x = [42, 44, 38, 52, 48, 46, 40, 50]; y = [30, 62, 25, 70, 33, 58, 20, 65]; [h, p] = ansaribradley (x, y, 'tail', 'left'); assert_equal (h, 1); assert_equal (p, 7.77000777000777e-05, 1e-16); ***** test ## Same data, normal approximation. x = [42, 44, 38, 52, 48, 46, 40, 50]; y = [30, 62, 25, 70, 33, 58, 20, 65]; [h, p, stats] = ansaribradley (x, y, 'method', 'approximate'); assert_equal (h, 1); assert_equal (p, 0.000723232716430194, 1e-15); assert_equal (stats.Wstar, 3.38061701891407, 1e-13); ***** test ## Total sample size 30 (> 25) defaults to the approximate method. u = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; v = [3, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 11, 12, 12, 13]; [h, p, stats] = ansaribradley (u, v); assert_equal (h, 0); assert_equal (p, 0.184251738662491, 1e-13); assert_equal (stats.Wstar, -1.32777714715389, 1e-13); ***** test ## Tied observations receive mid-rank scores (exact method). x = [1, 1, 2, 3, 3]; y = [0, 2, 2, 2, 4, 4]; [h, p, stats] = ansaribradley (x, y); assert_equal (h, 0); assert_equal (p, 0.904761904761905, 1e-14); assert_equal (stats.W, 17); assert_equal (stats.Wstar, 0.245274554572897, 1e-14); ***** test ## NaNs are ignored as missing values. x = [1, 2, 3, NaN, 5]; y = [2, NaN, 4, 6]; [h, p, stats] = ansaribradley (x, y); assert_equal (h, 0); assert_equal (p, 0.971428571428571, 1e-14); assert_equal (stats.W, 9.5); assert_equal (stats.Wstar, 0.253836541283405, 1e-14); 22 tests, 22 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/meanEffectSize.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/meanEffectSize.m ***** shared x, y, yp x = [2.1; 3.4; 1.9; 5.6; 4.4; 3.8; 2.7; 6.1; 3.3; 4.9]; y = [1.2; 2.8; 0.9; 2.2; 3.1; 1.7; 2.5; 0.4; 1.9; 3.6; 2.0; 1.1]; yp = [1.8; 2.9; 2.2; 4.1; 4.9; 2.6; 3.0; 4.8; 2.1; 4.0]; ***** test T = meanEffectSize (x, y); assert_equal (T.Properties.VariableNames, {'Effect', 'ConfidenceIntervals'}); assert_equal (T.Properties.RowNames, {'MeanDifference'}); assert_equal (T.Effect, 1.87, -1e-14); assert_equal (T.ConfidenceIntervals, ... [0.8093229690413275, 2.9306770309586709], -1e-13); ***** test T = meanEffectSize (x, 'Mean', 3); assert_equal (T{:,:}, [0.8199999999999994, -0.19771934142469916, ... 1.8377193414246979], -1e-13); ***** test T = meanEffectSize (x, 'Effect', 'cohen'); assert_equal (T{:,:}, [2.4538321615715333, 1.1921466698808931, ... 3.6909287967065962], -1e-13); ***** test T = meanEffectSize (x, y, 'VarianceType', 'unequal'); assert_equal (T{:,:}, [1.87, 0.74758396809829564, 2.992416031901703], ... -1e-13); ***** test T = meanEffectSize (x, y, 'Effect', 'cohen'); assert_equal (T.Properties.RowNames, {'CohensD'}); assert_equal (T{:,:}, [1.51473229411906, 0.5682402309164547, ... 2.4328200098432089], -1e-13); ***** test T = meanEffectSize (x, y, 'Effect', 'cohen', 'VarianceType', 'unequal'); assert_equal (T{:,:}, [1.4716714731499507, 0.49927861679878149, ... 2.411323051341753], -1e-13); ***** test T = meanEffectSize (x, y, 'Effect', 'glass'); assert_equal (T.Properties.RowNames, {'GlasssDelta'}); assert_equal (T{:,:}, [1.2012215031776874, 0.32205950867366817, ... 2.0417713231164596], -1e-13); ***** test T = meanEffectSize (x, y, 'Effect', 'glass', 'VarianceType', 'unequal'); assert_equal (T{:,:}, [1.2012215031776874, 0.32205950867366817, ... 2.0417713231164596], -1e-13); ***** test T = meanEffectSize (x, y, 'Effect', 'cliff'); assert_equal (T.Properties.RowNames, {'CliffsDelta'}); assert_equal (T{:,:}, [0.725, 0.27352437233891558, ... 0.91469527893564417], -1e-13); ***** test T = meanEffectSize ([1; 2; 2; 3; 3; 3; 4; 5], [2; 2; 3; 3; 4; 6], ... 'Effect', 'cliff'); assert_equal (T{:,:}, [-0.14583333333333334, -0.64640108601125412, ... 0.44249639444771338], -1e-13); ***** test T = meanEffectSize ([5; 6; 7], [1; 2; 3], 'Effect', 'cliff'); assert_equal (T{:,:}, [1, 1, 1]); ***** test T = meanEffectSize (1, [3; 4; 5], 'Effect', 'cliff'); assert_equal (T{:,:}, [-1, -1, -1]); ***** test T = meanEffectSize (x, y, 'Effect', 'cliff', 'Alpha', 0.1); assert_equal (T.ConfidenceIntervals, ... [0.35705295319266317, 0.89817708994266032], -1e-13); ***** test T = meanEffectSize (x, y, 'Effect', {'cliff', 'meandiff', 'glass', ... 'cohen'}); assert_equal (T.Properties.RowNames, {'CliffsDelta'; 'MeanDifference'; ... 'GlasssDelta'; 'CohensD'}); assert_equal (T.Effect, [0.725; 1.87; 1.2012215031776874; ... 1.51473229411906], -1e-13); ***** test T = meanEffectSize (x, y, 'Effect', {'cohen', 'cohen'}); assert_equal (T.Properties.RowNames, {'CohensD'}); ***** test T = meanEffectSize (x, y, 'Effect', 'COH'); assert_equal (T.Properties.RowNames, {'CohensD'}); ***** test T = meanEffectSize (x, y, 'Effect', 'cohen', 'Mean', 3); assert_equal (T.Effect, 1.51473229411906, -1e-13); ***** test T = meanEffectSize (x', y', 'Effect', 'cohen'); assert_equal (T.Effect, 1.51473229411906, -1e-13); ***** test T = meanEffectSize (x, y, 'Effect', 'cohen', ... 'ConfidenceIntervalType', 'none'); assert_equal (T.Properties.VariableNames, {'Effect'}); assert_equal (T.Effect, 1.51473229411906, -1e-13); ***** test T = meanEffectSize ([x; NaN], [NaN; y], 'Effect', 'cohen'); assert_equal (T{:,:}, [1.51473229411906, 0.5682402309164547, ... 2.4328200098432089], -1e-13); ***** test T = meanEffectSize (single (x), y, 'Effect', 'cohen'); assert_equal (class (T.Effect), 'single'); assert_equal (class (T.ConfidenceIntervals), 'single'); ***** test T = meanEffectSize (x, yp, 'Paired', true); assert_equal (T{:,:}, [0.57999999999999874, 0.044888382079159239, ... 1.1151116179208382], -1e-13); ***** test T = meanEffectSize (x, yp, 'Paired', 'on', 'Effect', 'cohen'); assert_equal (T{:,:}, [0.41222519124990314, 0.016525506916817929, ... 0.94928510130451305], -1e-12); ***** test T = meanEffectSize (x, yp, 'Paired', true, 'Effect', 'cohen', ... 'Alpha', 0.01); assert_equal (T.ConfidenceIntervals, ... [-0.10395569010229536, 1.2369598804778004], -1e-12); ***** test T = meanEffectSize ((1:8)', [8.2; 6.9; 7.4; 5.1; 5.8; 3.6; 4.4; 2.3], ... 'Paired', true, 'Effect', 'cohen'); assert_equal (T{:,:}, [-0.38188801178758269, -2.124735313427935, ... 1.1823775856056995], -1e-12); ***** test T = meanEffectSize ([1; 2], [2; 4], 'Paired', true, 'Effect', 'cohen'); assert_equal (T{:,:}, [0, -5.6823875052232813, 5.6823875052232813], ... -1e-12); ***** test T = meanEffectSize ([x; NaN], [yp; 2], 'Paired', true, 'Effect', 'cohen'); assert_equal (T.Effect, 0.41222519124990314, -1e-13); ***** test T = meanEffectSize (x, yp, 'Paired', true, 'Effect', 'cliff'); assert_equal (T{:,:}, [0.22222222222222221, 0.11569417468908846, ... 0.32875026975535593], -1e-13); ***** test T = meanEffectSize ([1; 2; 3; 4], [3; 1; 2; 5], 'Paired', true, ... 'Effect', 'cliff'); assert_equal (T{:,:}, [-0.083333333333333329, -0.24666366537833756, ... 0.079996998711670889], -1e-13); ***** test T = meanEffectSize (x, y, 'Effect', 'mediandiff', ... 'ConfidenceIntervalType', 'none'); assert_equal (T.Properties.RowNames, {'MedianDifference'}); assert_equal (T.Effect, 1.65, -1e-14); ***** test T = meanEffectSize (x, yp, 'Paired', true, 'Effect', 'mediandiff', ... 'ConfidenceIntervalType', 'none'); assert_equal (T.Effect, 0.65, -1e-14); ***** test T = meanEffectSize (x, y, 'Effect', 'kstest', ... 'ConfidenceIntervalType', 'none'); assert_equal (T.Properties.RowNames, {'KolmogorovSmirnovStatistic'}); assert_equal (T.Effect, 0.6166666666666667, -1e-14); ***** test T = meanEffectSize (x, yp, 'Paired', true, 'Effect', 'kstest', ... 'ConfidenceIntervalType', 'none'); assert_equal (T.Effect, 0.3, -1e-14); ***** test T = meanEffectSize (x, y, 'Effect', 'robustcohen', ... 'ConfidenceIntervalType', 'none'); assert_equal (T.Properties.RowNames, {'RobustCohensD'}); assert_equal (T.Effect, 1.2360631043171186, -1e-13); ***** test T = meanEffectSize (x, y, 'Effect', 'robustcohen', ... 'VarianceType', 'unequal', ... 'ConfidenceIntervalType', 'none'); assert_equal (T.Effect, 1.1952733752449272, -1e-13); ***** test T = meanEffectSize (x, yp, 'Paired', true, 'Effect', 'robustcohen', ... 'ConfidenceIntervalType', 'none'); assert_equal (T.Effect, 0.31641941202232715, -1e-13); ***** test T = meanEffectSize (x, 'Effect', 'robustcohen', ... 'ConfidenceIntervalType', 'none'); assert_equal (T.Effect, 1.9756476082746626, -1e-13); ***** test T = meanEffectSize (x, y, 'Effect', 'akpcohen', ... 'ConfidenceIntervalType', 'none'); assert_equal (T.Properties.RowNames, {'AKPCohensD'}); assert_equal (T.Effect, 1.4340672042318023, -2e-9); ***** test T = meanEffectSize (x, y, 'Effect', 'akpcohen', 'VarianceType', ... 'unequal', 'ConfidenceIntervalType', 'none'); assert_equal (T.Effect, 1.2409782758085974, -2e-9); ***** test T = meanEffectSize ([1; 2; 3; 4; 5; 6; 7; 8; 20; 30], 2 * (1:10)', ... 'Effect', 'akpcohen', 'ConfidenceIntervalType', 'none'); assert_equal (T.Effect, -1.0275756121741466, -2e-9); ***** test T = meanEffectSize (x, 'Effect', 'akpcohen', 'Mean', 3, ... 'ConfidenceIntervalType', 'none'); assert_equal (T.Effect, 0.50999107225010853, -2e-9); ***** test T = meanEffectSize ([1; 2; 3; 4; 5; 6; 7; 8; 20; 30], ... 'Effect', 'akpcohen', 'ConfidenceIntervalType', 'none'); assert_equal (T.Effect, 1.6247397012560751, -2e-9); ***** test T = meanEffectSize (x, yp, 'Paired', true, 'Effect', 'akpcohen', ... 'ConfidenceIntervalType', 'none'); assert_equal (T.Effect, 0.60651611028436192, -2e-9); ***** test T = meanEffectSize (x, y, 'Effect', 'cohen', 'NumBootstraps', 10); assert_equal (T.ConfidenceIntervals, ... [0.5682402309164547, 2.4328200098432089], -1e-13); ***** test rand ('state', 1); T = meanEffectSize ([1; 2; 3], [10; 10; 10; 10], 'NumBootstraps', 5000, ... 'ConfidenceIntervalType', 'bootstrap'); assert_equal (T.ConfidenceIntervals, [-9, -7]); ***** test rand ('state', 1); T = meanEffectSize ([1; 2; 3], [10; 10; 10; 10], 'NumBootstraps', 5000, ... 'ConfidenceIntervalType', 'bootstrap', 'Alpha', 0.4); assert_equal (T.ConfidenceIntervals, [-8.5, -7.5]); ***** test rand ('state', 1); T = meanEffectSize ([1; 2; 3], [10; 10; 10; 10], 'NumBootstraps', 5000, ... 'ConfidenceIntervalType', 'bootstrap', 'Alpha', 0.4, ... 'Resampling', 'stratified'); assert_equal (T.ConfidenceIntervals, [-25, -23] / 3, -1e-14); ***** test rand ('state', 1); T = meanEffectSize ([10; 10; 10], [1; 2; 3; 4], 'NumBootstraps', 5000, ... 'ConfidenceIntervalType', 'bootstrap', 'Alpha', 0.4, ... 'BootstrapOptions', statset ('UseParallel', true)); assert_equal (T.ConfidenceIntervals, [7, 8]); ***** warning ... T = meanEffectSize (ones (5, 1), 2 * ones (6, 1), 'Effect', 'cohen'); assert_equal (T{:,:}, [-Inf, NaN, NaN]); ***** warning ... T = meanEffectSize (5, 'Effect', 'cohen'); assert_equal (T{:,:}, [NaN, NaN, NaN]); ***** warning ... T = meanEffectSize ((1:8)', (2:9)', 'Paired', true, 'Effect', 'cohen'); assert_equal (T.ConfidenceIntervals, [NaN, NaN]); ***** warning ... T = meanEffectSize ([1; 2; 3], [3; 1; 2], 'Paired', true, 'Effect', 'cliff'); assert_equal (T{:,:}, [-1 / 6, NaN, NaN], -1e-14); ***** error meanEffectSize () ***** error ... meanEffectSize ([1, 2; 3, 4]) ***** error ... meanEffectSize ([]) ***** error ... meanEffectSize (int32 ([1; 2; 3])) ***** error ... meanEffectSize ([1; 2; 3], true (3, 1)) ***** error ... meanEffectSize ([1; 2; 3], 'Foo', 1) ***** error ... meanEffectSize ([1; 2; 3], 'Effect', 'foo') ***** error ... meanEffectSize ([1; 2; 3], 'Effect', 'c') ***** error ... meanEffectSize ([1; 2; 3], 'Effect', {}) ***** error ... meanEffectSize ([1; 2; 3], 'Mean', [1, 2]) ***** error ... meanEffectSize ([1; 2; 3], [1; 2; 3], 'Paired', 2) ***** error ... meanEffectSize ([1; 2; 3], [1; 2; 3], 'VarianceType', 'foo') ***** error ... meanEffectSize ([1; 2; 3], 'Alpha', 1) ***** error ... meanEffectSize ([1; 2; 3], 'ConfidenceIntervalType', 'foo') ***** error ... meanEffectSize ([1; 2; 3], 'NumBootstraps', 2.5) ***** error ... meanEffectSize ([1; 2; 3], 'Resampling', 'foo') ***** error ... meanEffectSize ([1; 2; 3], 'BootstrapOptions', 1) ***** error ... meanEffectSize ([1; 2; 3], 'Paired', true) ***** error ... meanEffectSize ([1; 2; 3], 'Effect', 'glass') ***** error ... meanEffectSize ([1; 2; 3], [1; 2], 'Paired', true) ***** error ... meanEffectSize ([1; 2; 3], [3; 2; 1], 'Paired', true, ... 'VarianceType', 'unequal') ***** error ... meanEffectSize ([1; 2; 3], [3; 2; 1], 'Paired', true, 'Effect', 'glass') ***** error ... meanEffectSize ([1; 2; 3], [3; 2; 1], 'Effect', 'mediandiff', ... 'ConfidenceIntervalType', 'exact') 75 tests, 75 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/regression_ttest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/regression_ttest.m ***** test x = [1 2 3 4 5 6 7 8 9 10]'; y = 2 + 3 * x + [0.3 -0.2 0.5 -0.4 0.1 0.2 -0.3 0.4 -0.1 0.2]'; [h, pval, ci, stats] = regression_ttest (y, x); n = numel (x); b = [ones(n,1), x] \ y; resid = y - [ones(n,1), x] * b; se = sqrt (sum (resid .^ 2) / (n - 2) / sum ((x - mean (x)) .^ 2)); assert_equal (stats.beta1, b(2), 1e-12); assert_equal (stats.beta0, b(1), 1e-12); assert_equal (stats.df, n - 2); assert_equal (stats.tstat, b(2) / se, 1e-9); assert_equal (pval, 2 * (1 - tcdf (abs (b(2) / se), n - 2)), 1e-12); assert_equal (ci(:)', [b(2) - tinv(0.975, n-2) * se, ... b(2) + tinv(0.975, n-2) * se], 1e-9); assert_equal (h, 1); ***** test x = [1 2 3 4 5 6 7 8 9 10]'; y = 2 + 3 * x + [0.3 -0.2 0.5 -0.4 0.1 0.2 -0.3 0.4 -0.1 0.2]'; [~, ~, ~, stats] = regression_ttest (y, x); SSE = sum ((y - (stats.beta0 + stats.beta1 * x)) .^ 2); SST = sum ((y - mean (y)) .^ 2); assert_equal (stats.tstat, ... stats.beta1 / sqrt (SSE / stats.df / sum ((x - mean (x)) .^ 2)), ... 1e-9); assert_equal (SSE < SST / 100, true); ***** test x = (1:40)'; y = [0.5 -1.2 0.3 0.8 -0.4 1.1 -0.7 0.2 -0.9 0.6 ... 1.3 -0.1 0.4 -1.1 0.7 0.9 -0.5 0.1 -0.8 1.0 ... -0.3 0.2 1.2 -0.6 0.5 -1.0 0.8 0.3 -0.2 0.9 ... -1.3 0.6 0.1 -0.7 1.1 -0.4 0.7 0.2 -0.9 0.4]'; [h, pval] = regression_ttest (y, x); assert_equal (h, 0); assert_equal (pval > 0.05, true); ***** test x = [1 2 3 4 5 6 7 8 9 10]'; y = 2 + 3 * x + [0.3 -0.2 0.5 -0.4 0.1 0.2 -0.3 0.4 -0.1 0.2]'; [~, pb] = regression_ttest (y, x, 'tail', 'both'); [~, pr] = regression_ttest (y, x, 'tail', 'right'); [~, pl] = regression_ttest (y, x, 'tail', 'left'); assert_equal (pr, pb / 2, 1e-12); assert_equal (pl, 1 - pr, 1e-12); ***** test x = [1 2 3 4 5 6 7 8 9 10]'; y = 2 + 3 * x + [0.3 -0.2 0.5 -0.4 0.1 0.2 -0.3 0.4 -0.1 0.2]'; [~, ~, ~, sc] = regression_ttest (y, x); [~, ~, ~, sr] = regression_ttest (y', x'); assert_equal (sr.beta1, sc.beta1, 1e-12); assert_equal (sr.tstat, sc.tstat, 1e-9); ***** test ## Below the resolution of 1 - tcdf, the slope p-value of fitlm in ## MATLAB R2024a x = (1:30)'; [~, pval] = regression_ttest (2 * x + 0.01 * sin (x), x); assert_equal (pval, 2.48569558345347e-96, -1e-6); ***** test x = (1:30)'; [~, pval] = regression_ttest (2 * x + 0.01 * sin (x), x, 'tail', 'right'); assert_equal (pval, 2.48569558345347e-96 / 2, -1e-6); ***** error regression_ttest (); ***** error regression_ttest (1); ***** error ... regression_ttest ([1 2 NaN]', [2 3 4]'); ***** error ... regression_ttest ([1 2 Inf]', [2 3 4]'); ***** error ... regression_ttest ([1 2 3+i]', [2 3 4]'); ***** error ... regression_ttest ([1 2 3]', [2 3 NaN]'); ***** error ... regression_ttest ([1 2 3]', [2 3 Inf]'); ***** error ... regression_ttest ([1 2 3]', [3 4 3+i]'); ***** error ... regression_ttest ([1 2 3]', [3 4 4 5]'); ***** error ... regression_ttest ([1 2 3]', [2 3 4]', 'alpha', 0); ***** error ... regression_ttest ([1 2 3]', [2 3 4]', 'alpha', 1.2); ***** error ... regression_ttest ([1 2 3]', [2 3 4]', 'alpha', [.02 .1]); ***** error ... regression_ttest ([1 2 3]', [2 3 4]', 'alpha', 'a'); ***** error ... regression_ttest ([1 2 3]', [2 3 4]', 'some', 0.05); ***** error ... regression_ttest ([1 2 3]', [2 3 4]', 'tail', 'val'); ***** error ... regression_ttest ([1 2 3]', [2 3 4]', 'alpha', 0.01, 'tail', 'val'); 23 tests, 23 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/barttest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/barttest.m ***** test ## Below the resolution of 1 - chi2cdf, values from MATLAB R2024a u = (1:30)'; [~, p] = barttest ([u, u + sin(u), cos(u)]); assert_equal (p, [3.45658879157417e-53; 0.247541092553521], -1e-10); ***** error barttest () ***** error barttest ([2,NaN;3,4]) ***** error barttest (ones (30, 4), 'alpha') ***** error barttest (ones (30, 4), 0) ***** error barttest (ones (30, 4), 1.2) ***** error barttest (ones (30, 4), [0.2, 0.05]) ***** error barttest (ones (30, 1)) ***** error barttest (ones (30, 1), 0.05) ***** test x = [2, 3, 4, 5, 6, 7, 8, 9; 1, 2, 3, 4, 5, 6, 7, 8]'; [ndim, pval, chisq] = barttest (x); assert_equal (ndim, 2); assert_equal (pval < 1e-100, true); ## assert_equal (chisq, 512.0558, 1e-4); Result differs between octave 6 and 7 ? ***** test x = [0.53767, 0.62702, -0.10224, -0.25485, 1.4193, 1.5237 ; ... 1.8339, 1.6452, -0.24145, -0.23444, 0.29158, 0.1634 ; ... -2.2588, -2.1351, 0.31286, 0.39396, 0.19781, 0.20995 ; ... 0.86217, 1.0835, 0.31286, 0.46499, 1.5877, 1.495 ; ... 0.31877, 0.38454, -0.86488, -0.63839, -0.80447, -0.7536 ; ... -1.3077, -1.1487, -0.030051, -0.017629, 0.69662, 0.60497 ; ... -0.43359, -0.32672, -0.16488, -0.37364, 0.83509, 0.89586 ; ... 0.34262, 0.29639, 0.62771, 0.51672, -0.24372, -0.13698 ; ... 3.5784, 3.5841, 1.0933, 0.93258, 0.21567, 0.455 ; ... 2.7694, 2.6307, 1.1093, 1.4298, -1.1658, -1.1816 ; ... -1.3499, -1.2111, -0.86365, -0.94186, -1.148, -1.4381 ; ... 3.0349, 2.8428, 0.077359, 0.18211, 0.10487, -0.014613; ... 0.7254, 0.56737, -1.2141, -1.2291, 0.72225, 0.90612 ; ... -0.063055,-0.17662, -1.1135, -0.97701, 2.5855, 2.4084 ; ... 0.71474, 0.29225, -0.0068493, -0.11468, -0.66689, -0.52466 ; ... -0.20497, -7.8874e-06, 1.5326, 1.3195, 0.18733, 0.20296 ; ... -0.12414, -0.077029, -0.76967, -0.96262, -0.082494, 0.121 ; ... 1.4897, 1.3683, 0.37138, 0.43653, -1.933, -2.1903 ; ... 1.409, 1.5882, -0.22558, -0.24835, -0.43897, -0.46247 ; ... 1.4172, 1.1616, 1.1174, 1.0785, -1.7947, -1.9471 ]; [ndim, pval, chisq] = barttest (x); assert_equal (ndim, 3); assert_equal (pval, [0; 0; 0; 0.52063; 0.34314], 1e-5); chisq_out = [251.6802; 210.2670; 153.1773; 4.2026; 2.1392]; assert_equal (chisq, chisq_out, 1e-4); 11 tests, 11 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/chi2gof.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/chi2gof.m ***** demo rng (42); x = normrnd (50, 5, 100, 1); [h, p, stats] = chi2gof (x) [h, p, stats] = chi2gof (x, 'cdf', @(x)normcdf (x, mean (x), std (x))) [h, p, stats] = chi2gof (x, 'cdf', {@normcdf, mean(x), std(x)}) ***** demo rng (42); x = rand (100,1 ); n = length (x); binedges = linspace (0, 1, 11); expectedCounts = n * diff (binedges); [h, p, stats] = chi2gof (x, 'binedges', binedges, 'expected', expectedCounts) ***** demo bins = 0:5; obsCounts = [6 16 10 12 4 2]; n = sum (obsCounts); lambdaHat = sum (bins.*obsCounts) / n; expCounts = n * poisspdf (bins,lambdaHat); [h, p, stats] = chi2gof (bins, 'binctrs', bins, 'frequency', obsCounts, ... 'expected', expCounts, 'nparams',1) ***** test ## Below the resolution of 1 - chi2cdf, values from MATLAB R2024a [~, p] = chi2gof (1:5, 'Ctrs', 1:5, ... 'Frequency', [500, 300, 300, 300, 600], ... 'Expected', 400 * ones (1, 5), 'NParams', 0); assert_equal (p, 3.75727673578105e-42, -1e-10); ***** error chi2gof () ***** error chi2gof ([2,3;3,4]) ***** error chi2gof ([1,2,3,4], 'nbins', 3, 'ctrs', [2,3,4]) ***** error chi2gof ([1,2,3,4], 'frequency', [2,3,2]) ***** error chi2gof ([1,2,3,4], 'frequency', [2,3,2,-2]) ***** error chi2gof ([1,2,3,4], 'frequency', [2,3,2,2], 'nparams', i) ***** error chi2gof ([1,2,3,4], 'frequency', [2,3,2,2], 'alpha', 1.3) ***** error chi2gof ([1,2,3,4], 'expected', [-3,2,2]) ***** error chi2gof ([1,2,3,4], 'expected', [3,2,2], 'nbins', 5) ***** error chi2gof ([1,2,3,4], 'cdf', @normcdff) ***** test x = [1 2 1 3 2 4 3 2 4 3 2 2]; [h, p, stats] = chi2gof (x); assert_equal (h, 0); assert_equal (p, NaN); assert_equal (stats.chi2stat, 0.1205375022748029, 1e-14); assert_equal (stats.df, 0); assert_equal (stats.edges, [1, 2.5, 4], 1e-14); assert_equal (stats.O, [7, 5], 1e-14); assert_equal (stats.E, [6.399995519909668, 5.600004480090332], 1e-14); 12 tests, 12 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/mmdtest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/mmdtest.m ***** assert_equal (mmdtest ([0; 1], 0.5), 0.126338154442911, -1e-13) ***** assert_equal (mmdtest ([0; 1], 1.5), 0.799739712952452, -1e-13) ***** assert_equal (mmdtest ([0; 1], 3), 1.665500671892900, -1e-13) ***** assert_equal (mmdtest ([0; 1], 10), 1.683939720585721, -1e-13) ***** assert_equal (mmdtest ([0; 1], 1), 0.316060279414279, -1e-13) ***** assert_equal (mmdtest ([0; 2], 1), 0.126338154442911, -1e-13) ***** assert_equal (mmdtest ([0; 10], 5), 0.126338154442911, -1e-13) ***** assert_equal (mmdtest ([0; 1; 4], 2), 0.200029287193120, -1e-13) ***** assert_equal (mmdtest ([0; 1; 4], [2; 6]), 0.269711792340645, -1e-13) ***** assert_equal (mmdtest ([2; 6], [0; 1; 4]), 0.237458896831246, -1e-13) ***** assert_equal (mmdtest ([0; 1; NaN], 1.5), 0.799739712952452, -1e-13) ***** assert_equal (mmdtest ([0, 0; 1, 10], [1, 0]), 0.470878401160454, -1e-13) ***** assert_equal (mmdtest ([0, 0; 1, 10; 3, 2], [1, 0; 2, 5]), ... 0.102827836885193, -1e-13) ***** assert_equal (mmdtest ([0, 0; 1, 10; 3, 2], [1, 0; 2, 5; 4, 4; 0, 9]), ... 0.029108941526544, -1e-12) ***** assert_equal (mmdtest ([1; 2; 1], [2; 2], 'CategoricalVariables', 1), ... 0.561884941180940, -1e-13) ***** assert_equal (mmdtest ([1; 2; 1; 3], [2; 2; 3], ... 'CategoricalVariables', 1), 0.272163018384518, -1e-13) ***** assert_equal (mmdtest ([1, 1; 2, 1; 1, 2], [2, 2; 2, 1], ... 'CategoricalVariables', 'all'), ... 0.419413238496425, -1e-13) ***** assert_equal (mmdtest ([1, 0; 2, 1; 1, 4], [2, 2; 1, 6], ... 'CategoricalVariables', 1), 0.266631734445491, -1e-13) ***** test ## Six pairs in X: the median of the squared distances, not its square v = mmdtest ([1, 0; 2, 1; 1, 4; 2, 3], [2, 2; 1, 6; 3, 1], ... 'CategoricalVariables', 1); assert_equal (v, 0.149533632990419, -1e-13); ***** test ## A table's categorical variable holds levels without being named v = mmdtest (table (categorical ([1; 2; 1])), table (categorical ([2; 2]))); assert_equal (v, 0.561884941180940, -1e-13); ***** test ## A standard deviation of 0 is taken as 1, and so is a scale of 0 assert_equal (mmdtest ([1, 0; 1, 1; 1, 2], [2, 0; 3, 1]), ... 0.887991689349540, -1e-13); assert_equal (mmdtest ([1; 1; 1], [2; 3]), 1.297744640525545, -1e-13); ***** test load fisheriris assert_equal (mmdtest (meas(1:25,:), meas(26:50,:)), ... 0.028159364150432, -1e-12); assert_equal (mmdtest (meas(51:100,:), meas(101:150,:)), ... 0.540247447946648, -1e-12); assert_equal (mmdtest (meas(101:150,:), meas(51:100,:)), ... 0.604761188982786, -1e-12); ***** test ## Each permutation is standardised afresh; the exact p-value over all 70 ## dealings is 0.2286, and MATLAB gave 0.2303 and 0.2273 over 20000 rand ('seed', 1); [v, p] = mmdtest ([2.5; 4; 3; 2], [3; -8; 2.5; 0], 'NumPermutations', 4000); assert_equal (v, 0.249999985933103, -1e-13); assert_equal (abs (p - 0.2286) < 0.03, true); ***** test rand ('seed', 1); [~, p, h] = mmdtest ([0; 0.1; 0.2], [10; 10.1; 10.2], ... 'NumPermutations', 9, 'Alpha', 0.2); assert_equal (p * 9, round (p * 9)); assert_equal (h, double (p <= 0.2)); ***** assert_equal (mmdtest ([0; 1], 0.5, 'Options', ... statset ('UseParallel', false)), ... 0.126338154442911, -1e-13) ***** error mmdtest (1) ***** error mmdtest (1, 2, 'Tail', 1) ***** error ... mmdtest ([0; 1], 2, 'Alpha', 0) ***** error ... mmdtest ([0; 1], 2, 'NumPermutations', 0) ***** error ... mmdtest ([0; 1], 2, 'Options', 1) ***** error ... mmdtest ([0; 1], 2, 'Options', struct ('UseParallel', true)) ***** error ... mmdtest ([0; 1], 2, 'Options', struct ('Streams', 1)) ***** error ... mmdtest ([0, 1; 1, 2], 2) ***** error ... mmdtest (NaN, 2) 34 tests, 34 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/ztest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/ztest.m ***** error ztest (); ***** error ... ztest ([1, 2, 3, 4], 2, -0.5); ***** error ... ztest ([1, 2, 3, 4], 1, 2, 'alpha', 0); ***** error ... ztest ([1, 2, 3, 4], 1, 2, 'alpha', 1.2); ***** error ... ztest ([1, 2, 3, 4], 1, 2, 'alpha', 'val'); ***** error ... ztest ([1, 2, 3, 4], 1, 2, 'tail', 'val'); ***** error ... ztest ([1, 2, 3, 4], 1, 2, 'alpha', 0.01, 'tail', 'val'); ***** error ... ztest ([1, 2, 3, 4], 1, 2, 'dim', 3); ***** error ... ztest ([1, 2, 3, 4], 1, 2, 'alpha', 0.01, 'tail', 'both', 'dim', 3); ***** error ... ztest ([1, 2, 3, 4], 1, 2, 'alpha', 0.01, 'tail', 'both', 'badoption', 3); ***** test load carsmall [h, pval, ci] = ztest (MPG, mean (MPG, 'omitnan'), std (MPG, 'omitnan')); assert_equal (h, 0); assert_equal (pval, 1, 1e-14); assert_equal (ci, [22.094; 25.343], 1e-3); ***** test load carsmall [h, pval, ci] = ztest (MPG, 26, 8); assert_equal (h, 1); assert_equal (pval, 0.00568359158544743, 1e-14); assert_equal (ci, [22.101; 25.335], 1e-3); ***** test load carsmall [h, pval, ci] = ztest (MPG, 26, 4); assert_equal (h, 1); assert_equal (pval, 3.184168011941316e-08, 1e-14); assert_equal (ci, [22.909; 24.527], 1e-3); ***** test x = normrnd (10, 2, 100, 1); [h, pval, ci] = ztest (x, 10, 2, 'tail', 'right'); assert_equal (isnan (pval), false); assert_equal (pval >= 0 && pval <= 1, true); ***** test x = normrnd (10, 2, 100, 1); [h, pval, ci] = ztest (x, 10, 2, 'tail', 'left'); assert_equal (isnan (pval), false); assert_equal (pval >= 0 && pval <= 1, true); ***** test load fisheriris; x = meas(:,1); m = 5.8; sigma = 0.8; [h, pval, ci] = ztest (x, m, sigma, 'tail', 'right'); assert_equal (h, 0) assert_equal (pval, 0.2535, 1e-4) assert_equal (ci, [5.7359; Inf], 1e-5) ***** test load fisheriris; x = meas(:,1); m = 5.8; sigma = 0.8; [h, pval, ci] = ztest (x, m, sigma, 'tail', 'left'); assert_equal (h, 0) assert_equal (pval, 0.7465, 1e-4) assert_equal (ci, [-Inf; 5.9508], 1e-4) ***** test [h, pval, ci, zvalue] = ztest ([1, 2; 3, 4; 5, 6], 3, 1); assert_equal (h, [0, 0]); assert_equal (pval, [1, 0.0833], 1e-4); assert_equal (ci, [1.8684, 2.8684; 4.1316, 5.1316], 1e-4); assert_equal (zvalue, [0, 1.7321], 1e-4); ***** test [h, pval, ci, zvalue] = ztest ([1, 2; NaN, 4; 5, 6], 3, 1); assert_equal (h, [0, 0]); assert_equal (pval, [1, 0.0833], 1e-4); assert_equal (ci, [1.6141, 2.8684; 4.3859, 5.1316], 1e-4); assert_equal (zvalue, [0, 1.7321], 1e-4); ***** test h = ztest ([1, 2; NaN, 4; 5, 6], 3, 1, 'dim', 2); assert_equal (h, [1; 0; 1]); ***** test h = ztest (reshape (1:12, 2, 3, 2), 3, 1); assert_equal (h, reshape ([1, 0, 1, 1, 1, 1], 1, 3, 2)); ***** test [h, pval, ci, zvalue] = ztest (5, 0, 1); assert_equal (h, 1); assert_equal (pval, 5.7330e-07, 1e-11); assert_equal (ci, [3.0400; 6.9600], 1e-4); assert_equal (zvalue, 5); ***** test assert_equal (ztest (NaN, 0, 1), NaN); ***** test [h, pval, ci] = ztest ([], 0, 1); assert_equal (h, zeros (1, 0)); assert_equal (pval, zeros (1, 0)); assert_equal (ci, zeros (2, 0)); ***** test [h, pval, ci] = ztest (zeros (0, 3), 0, 1); assert_equal (h, NaN (1, 3)); assert_equal (pval, NaN (1, 3)); assert_equal (ci, NaN (2, 3)); ***** test [h, pval, ci] = ztest (zeros (3, 0), 0, 1); assert_equal (h, zeros (1, 0)); assert_equal (pval, zeros (1, 0)); assert_equal (ci, zeros (2, 0)); ***** test assert_equal (ztest (zeros (0, 0, 3), 0, 1), zeros (1, 0, 3)); ***** test [h, pval, ci] = ztest (zeros (1, 0), 0, 1); assert_equal (h, NaN); assert_equal (pval, NaN); assert_equal (ci, [NaN, NaN]); ***** test [h, pval, ci] = ztest ([NaN; NaN], 0, 1); assert_equal (h, NaN); assert_equal (pval, NaN); assert_equal (ci, [NaN; NaN]); 29 tests, 29 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/jbtest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/jbtest.m ***** demo ## Test whether a sample departs from normality x = [1 2 3 4 5 6 7 8 9 100]; # last value is an outlier [h, p, jbstat] = jbtest (x) ***** test warning ("off", "jbtest:pTooBig", "local"); x = [1 2 3 4 5 6 7 8 9 10]; [h, p, jbstat, cv] = jbtest (x); assert_equal (h, 0); assert_equal (jbstat, 0.624487, 1e-5); # skewness 0, kurtosis 1.7758 assert_equal (cv, 2.5276, 1e-4); # tabulated critical value, n=10, a=0.05 assert_equal (p, 0.5, 1e-12); # clamped to the tabulated maximum ***** warning ... jbtest (1:10); ***** test # a strongly non-normal sample is rejected warning ("off", "jbtest:pTooSmall", "local"); x = [zeros(1, 20), 100]; h = jbtest (x); assert_equal (h, 1); ***** test # NaNs are removed warning ("off", "jbtest:pTooBig", "local"); assert_equal (jbtest ([1 2 3 4 5 6 7 8 9 10, NaN]), jbtest (1:10)); ***** test # alpha controls the critical value x = randn (1, 50); [~, ~, ~, cv1] = jbtest (x, 0.05); [~, ~, ~, cv2] = jbtest (x, 0.01); assert_equal (cv2 > cv1, true); warning: jbtest: P is greater than the largest tabulated value; returning 0.5. warning: called from jbtest at line 167 column 9 __test__ at line 4 column 3 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 1446 column 2 warning: jbtest: P is greater than the largest tabulated value; returning 0.5. warning: called from jbtest at line 167 column 9 __test__ at line 5 column 3 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 1446 column 2 ***** test # Monte-Carlo p-value runs and lies in (0,1] warning ("off", "jbtest:pTooBig", "local"); x = [1 2 3 4 5 6 7 8 9 10]; [h, p] = jbtest (x, 0.05, 0.05); assert_equal (p > 0 && p <= 1, true); ***** test # the Monte-Carlo p-value is unsmoothed and reaches exactly zero x = [zeros(1, 20), 100]; [h, p] = jbtest (x, 0.05, 0.05); assert_equal (h, 1); assert_equal (p, 0); ***** test # a degenerate (zero-variance) sample yields NaN jbstat, p=0, h=1 [h, p, jbstat] = jbtest (ones (1, 10)); assert_equal (h, 1); assert_equal (p, 0); assert_equal (isnan (jbstat), true); ***** error jbtest () ***** error jbtest (ones (3, 3)) ***** error jbtest ({1, 2, 3}) ***** error jbtest ([1 2 3i]) ***** error jbtest (5) ***** error jbtest (1:10, 0) ***** error jbtest (1:10, 1) ***** error jbtest (1:10, [0.1 0.2]) ***** error jbtest (1:10, 0.05, -1) 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/binotest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/binotest.m ***** demo % flip a coin 1000 times, showing 475 heads % Hypothesis: coin is fair, i.e. p=1/2 [h,p_val,ci] = binotest (475,1000,0.5) % Result: h = 0 : null hypothesis not rejected, coin could be fair % P value 0.12, i.e. hypothesis not rejected for alpha up to 12% % 0.444 <= p <= 0.506 with 95% confidence ***** demo % flip a coin 100 times, showing 65 heads % Alternative: coin shows more heads than tails, i.e. p>1/2 [h,p_val,ci] = binotest (65,100,0.5,'tail','right','alpha',0.01) % Result: h = 1 : null hypothesis is rejected, i.e. coin shows more heads than tails % P value 0.0018, i.e. hypothesis not rejected for alpha up to 0.18% % 0.53 <= p <= 1 with 99% confidence ***** test #example from https://en.wikipedia.org/wiki/Binomial_test [h,p_val,ci] = binotest (51,235,1/6); assert_equal (p_val, 0.0437, 0.00005) [h,p_val,ci] = binotest (51,235,1/6,'tail','right'); assert_equal (p_val, 0.027, 0.0005) ***** test [~, p] = binotest (51, 235, 1/6, 'tail', 'right'); assert_equal (p, sum (binopdf (51:235, 235, 1/6)), -1e-12); ***** test [~, p] = binotest (51, 235, 1/6, 'tail', 'left'); assert_equal (p, sum (binopdf (0:51, 235, 1/6)), -1e-12); ***** test ## 95 of 100 is no evidence that p < 0.2 [h, p] = binotest (95, 100, 0.2, 'tail', 'left'); assert_equal ([h, p], [0, 1]); ***** test ## Below the resolution of 1 - binocdf [~, p] = binotest (95, 100, 0.2, 'tail', 'right'); assert_equal (p, sum (binopdf (95:100, 100, 0.2)), -1e-12); ***** test [~, ~, ci] = binotest (51, 235, 1/6, 'tail', 'right'); assert_equal (ci(2), 1); ***** test [~, ~, ci] = binotest (51, 235, 1/6, 'tail', 'left'); assert_equal (ci(1), 0); ***** test ## Outcomes as likely as the one observed are counted, ties to within ## rounding included; values from R's binom.test [~, p] = binotest (1, 10, 0.5); assert_equal (p, 0.021484375, -1e-12); ***** test [~, p] = binotest (4, 10, 0.5); assert_equal (p, 0.75390625, -1e-12); ***** test [~, p] = binotest (11, 50, 0.5); assert_equal (p, 9.021490107130641e-05, -1e-10); ***** test [~, ~, ~, st] = binotest (51, 235, 1/6); assert_equal (st.phat, 51 / 235); ***** test [~, ~, ~, st] = binotest (51, 235, 1/6); assert_equal (st.CohensH, ... 2 * asin (sqrt (51 / 235)) - 2 * asin (sqrt (1/6)), -1e-14); ***** test [~, ~, ci, st] = binotest (51, 235, 1/6); assert_equal (st.CohensHCI, 2 * asin (sqrt (ci)) - 2 * asin (sqrt (1/6)), ... -1e-14); ***** test ## A one-sided interval maps to a one-sided interval [~, ~, ~, st] = binotest (51, 235, 1/6, 'tail', 'right'); assert_equal (st.CohensHCI(2), pi - 2 * asin (sqrt (1/6)), -1e-14); ***** error binotest (5, 10, 0.5, 'size', 1) ***** error binotest (5, 10, 0.5, 'alpha', 0) ***** error binotest (5, 10, 0.5, 'alpha', 1) ***** error ... binotest (5, 10, 0.5, 'alpha', [0.05, 0.1]) ***** error binotest (5, 10, 0.5, 'tail', 1) ***** error 0.> binotest (0, 0, 0.5) ***** error binotest (5, 10, 1.5) ***** error binotest (11, 10, 0.5) ***** error ... binotest (5, 10, 0.5, 'tail', 'up') 23 tests, 23 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/manova1.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/manova1.m ***** demo load carbig [d,p] = manova1 ([MPG, Acceleration, Weight, Displacement], Origin) ***** test load carbig [d,p] = manova1 ([MPG, Acceleration, Weight, Displacement], Origin); assert_equal (d, 3); assert_equal (p, [0, 3.140583347827075e-07, 0.007510999577743149, ... 0.1934100745898493]', [1e-12, 1e-12, 1e-12, 1e-12]'); ***** test load carbig [d,p] = manova1 ([MPG, Acceleration, Weight], Origin); assert_equal (d, 2); assert_equal (p, [0, 0.00516082975137544, 0.1206528056514453]', ... [1e-12, 1e-12, 1e-12]'); ***** test ## Below the resolution of 1 - chi2cdf, values from MATLAB R2024a w = [1:10, 101:110, 201:210]'; g = kron ((1:3)', ones (10, 1)); [~, p] = manova1 ([w, sin(1:30)'], g); assert_equal (p(1), 2.48250847911811e-37, -1e-10); 3 tests, 3 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/+stats/+drift/DriftDiagnostics.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/+stats/+drift/DriftDiagnostics.m ***** shared ddE, ddD ddE = detectdrift ([1; 2; 2; 4], [3; 5], 'EstimatePValues', false); rand ('seed', 1); x = (1:60)' / 10; ddD = detectdrift (table (x, x, 'VariableNames', {'Same', 'Far'}), ... table (x([2:60, 1]), x + 10, ... 'VariableNames', {'Same', 'Far'})); ***** test e = ecdf (ddE); assert_equal (e.x{1}', [1, 1, 2, 2, 3, 4, 5]); assert_equal (e.F_Baseline{1}', [0, 0.25, 0.25, 0.75, 0.75, 1, 1]); assert_equal (e.F_Target{1}', [0, 0, 0, 0, 0.5, 0.5, 1]); ***** test h = histcounts (ddE); assert_equal (h.Bins{1}, 0.5:5.5); assert_equal (h.Counts_Baseline{1}, [25, 50, 0, 25, 0]); assert_equal (h.Counts_Target{1}, [0, 0, 50, 0, 50]); ***** test ## Levels: each count increased by 0.5 C = detectdrift (categorical ([1; 1; 2; 3]), categorical ([1; 2; 2; 2]), ... 'EstimatePValues', false); h = histcounts (C); assert_equal (cellstr (h.Bins{1}), {'1'; '2'; '3'}); assert_equal (h.Counts_Baseline{1}, [2.5, 1.5, 1.5] * 100 / 5.5, -1e-14); assert_equal (C.VariableNames, string ('x1')); assert_equal (C.CategoricalVariables, 1); ***** test T = table ([1; 2; 3], categorical ([1; 2; 1]), 'VariableNames', {'A', 'B'}); e = ecdf (detectdrift (T, T, 'EstimatePValues', false), 'Variable', 'B'); assert_equal (e.x{1}, NaN); assert_equal (e.Properties.RowNames, {'B'}); ***** test e = ecdf (ddD, 'Variable', 2); assert_equal (e.Properties.RowNames, {'Far'}); ***** test t = summary (ddE); assert_equal (t.Properties.VariableNames, {'MetricValue', 'Metric'}); assert_equal (t.MetricValue, 1.75, -1e-14); ***** test t = summary (ddD); assert_equal (t.Properties.RowNames, {'Same'; 'Far'; 'MultipleTest'}); assert_equal (t.DriftStatus, string ({'Stable'; 'Drift'; 'Drift'})); assert_equal (t.PValue, [1; 0.001; NaN]); assert_equal (size (t.ConfidenceInterval), [3, 2]); ***** assert_equal (ddD.NumVariables, 2) ***** assert_equal (ddD.WarningThreshold, 0.1) ***** test hf = figure ('visible', 'off'); unwind_protect h = plotDriftStatus (ddD); assert_equal (numel (h), 3); ## Alphabetical, so Far comes before Same assert_equal (get (gca (), 'yticklabel'), {'Far'; 'Same'}); assert_equal (get (h(3), 'xdata')(:)', [0.001, NaN]); assert_equal (get (get (gca (), 'title'), 'string'), ... 'Estimated P-Values and Confidence Intervals'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = plotEmpiricalCDF (ddE); assert_equal (numel (h), 2); assert_equal (get (get (gca (), 'title'), 'string'), 'ECDF for x1'); assert_equal (get (get (gca (), 'ylabel'), 'string'), ... 'Cumulative Probability'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = plotHistogram (ddE); assert_equal (get (h(1), 'xdata')(:)', 1:5); assert_equal (get (h(1), 'ydata')(:)', [25, 50, 0, 25, 0]); assert_equal (get (get (gca (), 'xlabel'), 'string'), 'x1 Bins'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## The variable with the smallest p-value by default hf = figure ('visible', 'off'); unwind_protect plotHistogram (ddD); assert_equal (get (get (gca (), 'title'), 'string'), 'Histogram for Far'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = plotPermutationResults (ddD, 'Variable', 'Same'); assert_equal (numel (h), 2); assert_equal (sum (get (h(2), 'ydata')(:)), 100, -1e-12); assert_equal (get (get (gca (), 'xlabel'), 'string'), ... 'Wasserstein Metric Values'); unwind_protect_cleanup close (hf); end_unwind_protect ***** error ... ecdf (ddE, 'Variable', 'nope') ***** error ... ecdf (ddE, 'Foo', 1) ***** error ... histcounts (ddE, 'Variable', 3) ***** error ... plotDriftStatus (ddE) ***** error ... plotPermutationResults (ddE) ***** error ... plotEmpiricalCDF (detectdrift (categorical ([1; 2]), categorical ([2; 2]), ... 'EstimatePValues', false)) ***** error ... plotHistogram (ddD, 'Variable', [1, 2]) 21 tests, 21 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/correlation_test.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/correlation_test.m ***** test x = [6 7 7 9 10 12 13 14 15 17]; y = [19 22 27 25 30 28 30 29 25 32]; [h, p, stats] = correlation_test (x, y); assert_equal (stats.CorrCoef, corr (x', y'), 1e-14); assert_equal (p, 0.0223, 1e-4); ***** test x = [6 7 7 9 10 12 13 14 15 17]'; y = [19 22 27 25 30 28 30 29 25 32]'; [h, p, stats] = correlation_test (x, y); assert_equal (stats.CorrCoef, corr (x, y), 1e-14); assert_equal (p, 0.0223, 1e-4); ***** test ## Below the resolution of 1 - tcdf, the p-value of corr in MATLAB R2024a x = (1:30)'; [~, p] = correlation_test (x, x + 0.01 * sin (x)); assert_equal (p, 6.68262089195668e-88, -1e-7); ***** test ## Values from R's cor.test without exact tests, on tied data x = [1 2 2 3 4 4 4 5 6 7 7 8]'; y = [2 1 3 3 5 4 6 6 8 7 9 9]'; [~, ~, stats] = correlation_test (x, y); assert_equal (stats.CorrCoefCI, ... [0.8116031451285135, 0.98487109489995917], -1e-12); ***** test x = [1 2 2 3 4 4 4 5 6 7 7 8]'; y = [2 1 3 3 5 4 6 6 8 7 9 9]'; [~, p, stats] = correlation_test (x, y, 'tail', 'right'); assert_equal ([p, stats.CorrCoefCI], ... [1.7690247076465537e-06, 0.84452474586233817, 1], -1e-12); ***** test ## Kendall's variance allows for ties x = [1 2 2 3 4 4 4 5 6 7 7 8]'; y = [2 1 3 3 5 4 6 6 8 7 9 9]'; [~, p, stats] = correlation_test (x, y, 'method', 'kendall'); assert_equal ([stats.zval, p], ... [3.7786519487436312, 0.00015767962747712322], -1e-12); ***** test x = [1 2 2 3 4 4 4 5 6 7 7 8]'; y = [2 1 3 3 5 4 6 6 8 7 9 9]'; [~, p] = correlation_test (x, y, 'method', 'spearman'); assert_equal (p, 1.2599089155461711e-06, -1e-12); ***** test ## Spearman's test is symmetric in the sign of the coefficient x = (1:12)'; y = [3 1 4 2 6 5 8 9 7 12 10 11]'; [~, p] = correlation_test (x, -y, 'method', 'spearman'); assert_equal (p, 2.8428045348547355e-05, -1e-12); ***** test x = (1:12)'; y = [3 1 4 2 6 5 8 9 7 12 10 11]'; [~, ~, stats] = correlation_test (x, y, 'method', 'spearman'); r = stats.CorrCoef; assert_equal (stats.CorrCoefCI, ... tanh (atanh (r) + [-1, 1] * norminv (0.975) ... * sqrt ((1 + r ^ 2 / 2) / 9)), -1e-14); ***** test x = (1:12)'; y = [3 1 4 2 6 5 8 9 7 12 10 11]'; [~, ~, stats] = correlation_test (x, y, 'method', 'kendall', 'alpha', 0.01); r = stats.CorrCoef; assert_equal (stats.CorrCoefCI, ... tanh (atanh (r) + [-1, 1] * norminv (0.995) ... * sqrt (0.437 / 8)), -1e-14); ***** test [~, ~, stats] = correlation_test ((1:12)', (12:-1:1)' + sin (1:12)', ... 'tail', 'left'); assert_equal (stats.CorrCoefCI(1), -1); ***** test [~, ~, stats] = correlation_test ((1:12)', sin (1:12)', 'method', 'kendall'); assert_equal ([isfield(stats, 'zval'), isfield(stats, 'tstat')], ... [true, false]); ***** error correlation_test (); ***** error correlation_test (1); ***** error ... correlation_test ([1 2 NaN]', [2 3 4]'); ***** error ... correlation_test ([1 2 Inf]', [2 3 4]'); ***** error ... correlation_test ([1 2 3+i]', [2 3 4]'); ***** error ... correlation_test ([1 2 3]', [2 3 NaN]'); ***** error ... correlation_test ([1 2 3]', [2 3 Inf]'); ***** error ... correlation_test ([1 2 3]', [3 4 3+i]'); ***** error ... correlation_test ([1 2 3]', [3 4 4 5]'); ***** error ... correlation_test ([1 2 3]', [2 3 4]', 'alpha', 0); ***** error ... correlation_test ([1 2 3]', [2 3 4]', 'alpha', 1.2); ***** error ... correlation_test ([1 2 3]', [2 3 4]', 'alpha', [.02 .1]); ***** error ... correlation_test ([1 2 3]', [2 3 4]', 'alpha', 'a'); ***** error ... correlation_test ([1 2 3]', [2 3 4]', 'some', 0.05); ***** error ... correlation_test ([1 2 3]', [2 3 4]', 'tail', 'val'); ***** error ... correlation_test ([1 2 3]', [2 3 4]', 'alpha', 0.01, 'tail', 'val'); ***** error ... correlation_test ([1 2 3]', [2 3 4]', 'method', 0.01); ***** error ... correlation_test ([1 2 3]', [2 3 4]', 'method', 'some'); 30 tests, 30 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/anova2.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/anova2.m ***** demo # Factorial (Crossed) Two-way ANOVA with Interaction popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; [p, atab, stats] = anova2 (popcorn, 3, 'on'); ***** demo # One-way Repeated Measures ANOVA (Rows are a crossed random factor) data = [54, 43, 78, 111; 23, 34, 37, 41; 45, 65, 99, 78; 31, 33, 36, 35; 15, 25, 30, 26]; [p, atab, stats] = anova2 (data, 1, 'on', 'linear'); ***** demo # Balanced Nested One-way ANOVA (Rows are a nested random factor) data = [4.5924 7.3809 21.322; -0.5488 9.2085 25.0426; ... 6.1605 13.1147 22.66; 2.3374 15.2654 24.1283; ... 5.1873 12.4188 16.5927; 3.3579 14.3951 10.2129; ... 6.3092 8.5986 9.8934; 3.2831 3.4945 10.0203]; [p, atab, stats] = anova2 (data, 4, 'on', 'nested'); ***** test ## Test for anova2 ("interaction") ## comparison with results from Matlab for column effect popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; [p, atab, stats] = anova2 (popcorn, 3, 'off'); assert_equal (p(1), 7.678957383294716e-07, 1e-14); assert_equal (p(2), 0.0001003738963050171, 1e-14); assert_equal (p(3), 0.7462153966366274, 1e-14); assert_equal (atab{2,5}, 56.700, 1e-14); assert_equal (atab{2,3}, 2, 0); assert_equal (atab{4,2}, 0.08333333333333348, 1e-14); assert_equal (atab{5,4}, 0.1388888888888889, 1e-14); assert_equal (atab{5,2}, 1.666666666666667, 1e-14); assert_equal (atab{6,2}, 22); assert_equal (stats.source, "anova2"); assert_equal (stats.colmeans, [6.25, 4.75, 4]); assert_equal (stats.inter, true); assert_equal (stats.pval, 0.7462153966366274, 1e-14); assert_equal (stats.df, 12); ***** test ## Test for anova2 ("linear") - comparison with results from GraphPad Prism 8 data = [54, 43, 78, 111; 23, 34, 37, 41; 45, 65, 99, 78; 31, 33, 36, 35; 15, 25, 30, 26]; [p, atab, stats] = anova2 (data, 1, 'off', 'linear'); assert_equal (atab{2,2}, 2174.95, 1e-10); assert_equal (atab{3,2}, 8371.7, 1e-10); assert_equal (atab{4,2}, 2404.3, 1e-10); assert_equal (atab{5,2}, 12950.95, 1e-10); assert_equal (atab{2,4}, 724.983333333333, 1e-10); assert_equal (atab{3,4}, 2092.925, 1e-10); assert_equal (atab{4,4}, 200.358333333333, 1e-10); assert_equal (atab{2,5}, 3.61843363972882, 1e-10); assert_equal (atab{3,5}, 10.445909412303, 1e-10); assert_equal (atab{2,6}, 0.087266112738617, 1e-10); assert_equal (atab{3,6}, 0.000698397753556, 1e-10); ***** test ## Test for anova2 ("nested") - comparison with results from GraphPad Prism 8 data = [4.5924 7.3809 21.322; -0.5488 9.2085 25.0426; ... 6.1605 13.1147 22.66; 2.3374 15.2654 24.1283; ... 5.1873 12.4188 16.5927; 3.3579 14.3951 10.2129; ... 6.3092 8.5986 9.8934; 3.2831 3.4945 10.0203]; [p, atab, stats] = anova2 (data, 4, 'off', 'nested'); assert_equal (atab{2,2}, 745.360306290833, 1e-10); assert_equal (atab{3,2}, 278.01854140125, 1e-10); assert_equal (atab{4,2}, 180.180377467501, 1e-10); assert_equal (atab{5,2}, 1203.55922515958, 1e-10); assert_equal (atab{2,4}, 372.680153145417, 1e-10); assert_equal (atab{3,4}, 92.67284713375, 1e-10); assert_equal (atab{4,4}, 10.0100209704167, 1e-10); assert_equal (atab{2,5}, 4.02146005730833, 1e-10); assert_equal (atab{3,5}, 9.25800729165627, 1e-10); assert_equal (atab{2,6}, 0.141597630656771, 1e-10); assert_equal (atab{3,6}, 0.000636643812875719, 1e-10); ***** test ## Below the resolution of 1 - fcdf, values from MATLAB R2024a q = (1:6)'; p = anova2 ([q, q + 100, q + 200] + 0.1 * sin (reshape (1:18, 6, 3)), 1, ... 'off'); assert_equal (p, [6.92646657901359e-38, 7.28337250041466e-20], -1e-6); ***** error anova2 ([], 1, 'off') ***** error anova2 (zeros (0, 3), 2, 'off') ***** error anova2 (zeros (3, 0), 1, 'off') 7 tests, 7 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/vartestn.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/vartestn.m ***** demo ## Test the null hypothesis that the variances are equal across the five ## columns of data in the students’ exam grades matrix, grades. load examgrades vartestn (grades) ***** demo ## Test the null hypothesis that the variances in miles per gallon (MPG) are ## equal across different model years. load carsmall vartestn (MPG, Model_Year) ***** demo ## Use Levene’s test to test the null hypothesis that the variances in miles ## per gallon (MPG) are equal across different model years. load carsmall p = vartestn (MPG, Model_Year, 'TestType', 'LeveneAbsolute') ***** demo ## Test the null hypothesis that the variances are equal across the five ## columns of data in the students’ exam grades matrix, grades, using the ## Brown-Forsythe test. Suppress the display of the summary table of ## statistics and the box plot. load examgrades [p, stats] = vartestn (grades, 'TestType', 'BrownForsythe', 'Display', 'off') ***** test ## Below the resolution of 1 - chi2cdf, values from MATLAB R2024a s = sin (1:50)'; p = vartestn ([0.01 * s; 100 * s], [ones(50, 1); 2 * ones(50, 1)], ... 'Display', 'off'); assert_equal (p, 1.05713927539863e-181, -1e-10); ***** test ## Group labels as text labels in a cell array v = [sin(1:12)'; 3 * cos(1:17)'; 0.5 * sin(2 * (1:9))']; g = [ones(12, 1); 2 * ones(17, 1); 3 * ones(9, 1)]; gc = cellstr (char ('a' + g - 1)); [~, s0] = vartestn (v, g, 'Display', 'off'); [~, s] = vartestn (v, gc, 'Display', 'off'); assert_equal (s.chisqstat, s0.chisqstat); ***** test ## Group labels as a character matrix v = [sin(1:12)'; 3 * cos(1:17)'; 0.5 * sin(2 * (1:9))']; g = [ones(12, 1); 2 * ones(17, 1); 3 * ones(9, 1)]; gc = cellstr (char ('a' + g - 1)); [~, s0] = vartestn (v, g, 'Display', 'off'); [~, s] = vartestn (v, char (gc), 'Display', 'off'); assert_equal (s.chisqstat, s0.chisqstat); ***** test ## Group labels as categorical labels v = [sin(1:12)'; 3 * cos(1:17)'; 0.5 * sin(2 * (1:9))']; g = [ones(12, 1); 2 * ones(17, 1); 3 * ones(9, 1)]; gc = cellstr (char ('a' + g - 1)); [~, s0] = vartestn (v, g, 'Display', 'off'); [~, s] = vartestn (v, categorical (gc), 'Display', 'off'); assert_equal (s.chisqstat, s0.chisqstat); ***** test ## Group labels as string labels v = [sin(1:12)'; 3 * cos(1:17)'; 0.5 * sin(2 * (1:9))']; g = [ones(12, 1); 2 * ones(17, 1); 3 * ones(9, 1)]; gc = cellstr (char ('a' + g - 1)); [~, s0] = vartestn (v, g, 'Display', 'off'); [~, s] = vartestn (v, string (gc), 'Display', 'off'); assert_equal (s.chisqstat, s0.chisqstat); ***** error vartestn (); ***** error vartestn (1); ***** error vartestn ([]); ***** error vartestn (zeros (0, 3)); ***** error ... vartestn ([1, 2, 3, 4, 5, 6, 7], [1, 1, 1, 2, 2, 2, 2], 'Display', 'some'); ***** error ... vartestn (ones (50,3), 'Display', 'some'); ***** error ... vartestn (ones (50,3), 'Display', 'off', 'testtype', 'some'); ***** error ... vartestn (ones (50,3), [], 'som'); ***** error ... vartestn (ones (50,3), [], 'some', 'some'); ***** error ... vartestn (ones (50,3), [1, 2], 'Display', 'off'); ***** test load examgrades [p, stat] = vartestn (grades, 'Display', 'off'); assert_equal (p, 7.908647337018238e-08, 1e-14); assert_equal (stat.chisqstat, 38.7332, 1e-4); assert_equal (stat.df, 4); ***** test load examgrades [p, stat] = vartestn (grades, 'Display', 'off', 'TestType', 'LeveneAbsolute'); assert_equal (p, 9.523239714592791e-07, 1e-14); assert_equal (stat.fstat, 8.5953, 1e-4); assert_equal (stat.df, [4, 595]); ***** test load examgrades [p, stat] = vartestn (grades, 'Display', 'off', 'TestType', 'LeveneQuadratic'); assert_equal (p, 7.219514351897161e-07, 1e-14); assert_equal (stat.fstat, 8.7503, 1e-4); assert_equal (stat.df, [4, 595]); ***** test load examgrades [p, stat] = vartestn (grades, 'Display', 'off', 'TestType', 'BrownForsythe'); assert_equal (p, 1.312093241723211e-06, 1e-14); assert_equal (stat.fstat, 8.4160, 1e-4); assert_equal (stat.df, [4, 595]); ***** test load examgrades [p, stat] = vartestn (grades, 'Display', 'off', 'TestType', 'OBrien'); assert_equal (p, 8.235660885480556e-07, 1e-14); assert_equal (stat.fstat, 8.6766, 1e-4); assert_equal (stat.df, [4, 595]); ***** test [p, stats] = vartestn ((1:5)', [], 'Display', 'off'); assert_equal (p, NaN); assert_equal (stats.df, 0); ***** test p = vartestn (1:5, [], 'Display', 'off'); assert_equal (p, NaN); 22 tests, 22 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/anovan.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/anovan.m ***** demo # Two-sample unpaired test on independent samples (equivalent to Student's # t-test). Note that the absolute value of t-statistic can be obtained by # taking the square root of the reported F statistic. In this example, # t = sqrt (1.44) = 1.20. score = [54 23 45 54 45 43 34 65 77 46 65]'; gender = {'male' 'male' 'male' 'male' 'male' 'female' 'female' 'female' ... 'female' 'female' 'female'}'; [P, ATAB, STATS] = anovan (score, gender, 'display', 'on', 'varnames', 'gender'); ***** demo # Two-sample paired test on dependent or matched samples equivalent to a # paired t-test. As for the first example, the t-statistic can be obtained by # taking the square root of the reported F statistic. Naming subject as a # random factor (') keeps the treatment x subject interaction in the model # and makes its mean square the denominator of the test on treatment. score = [4.5 5.6; 3.7 6.4; 5.3 6.4; 5.4 6.0; 3.9 5.7]'; treatment = {'before' 'after'; 'before' 'after'; 'before' 'after'; 'before' 'after'; 'before' 'after'}'; subject = {'GS' 'GS'; 'JM' 'JM'; 'HM' 'HM'; 'JW' 'JW'; 'PS' 'PS'}'; [P, ATAB, STATS] = anovan (score(:), {treatment(:), subject(:)}, ... 'model', 'full', 'random', 2, 'sstype', 2, ... 'varnames', {'treatment', 'subject'}, ... 'display', 'on'); ***** demo # One-way ANOVA on the data from a study on the strength of structural beams, # in Hogg and Ledolter (1987) Engineering Statistics. New York: MacMillan strength = [82 86 79 83 84 85 86 87 74 82 ... 78 75 76 77 79 79 77 78 82 79]'; alloy = {'st','st','st','st','st','st','st','st', ... 'al1','al1','al1','al1','al1','al1', ... 'al2','al2','al2','al2','al2','al2'}'; [P, ATAB, STATS] = anovan (strength, alloy, 'display', 'on', ... 'varnames', 'alloy'); ***** demo # One-way repeated measures ANOVA on the data from a study on the number of # words recalled by 10 subjects for three time conditions, in Loftus & Masson # (1994) Psychon Bull Rev. 1(4):476-490, Table 2. Naming subject as a random # factor (') keeps the seconds x subject interaction in the model and makes # its mean square the denominator of the test on seconds. words = [10 13 13; 6 8 8; 11 14 14; 22 23 25; 16 18 20; ... 15 17 17; 1 1 4; 12 15 17; 9 12 12; 8 9 12]; seconds = [1 2 5; 1 2 5; 1 2 5; 1 2 5; 1 2 5; ... 1 2 5; 1 2 5; 1 2 5; 1 2 5; 1 2 5;]; subject = [ 1 1 1; 2 2 2; 3 3 3; 4 4 4; 5 5 5; ... 6 6 6; 7 7 7; 8 8 8; 9 9 9; 10 10 10]; [P, ATAB, STATS] = anovan (words(:), {seconds(:), subject(:)}, ... 'model', 'full', 'random', 2, 'sstype', 2, ... 'display', 'on', 'varnames', {'seconds', 'subject'}); ***** demo # Balanced two-way ANOVA with interaction on the data from a study of popcorn # brands and popper types, in Hogg and Ledolter (1987) Engineering Statistics. # New York: MacMillan popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; brands = {'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'}; popper = {'oil', 'oil', 'oil'; 'oil', 'oil', 'oil'; 'oil', 'oil', 'oil'; ... 'air', 'air', 'air'; 'air', 'air', 'air'; 'air', 'air', 'air'}; [P, ATAB, STATS] = anovan (popcorn(:), {brands(:), popper(:)}, ... 'display', 'on', 'model', 'full', ... 'varnames', {'brands', 'popper'}); ***** demo # Unbalanced two-way ANOVA (2x2) on the data from a study on the effects of # gender and having a college degree on salaries of company employees, # in Maxwell, Delaney and Kelly (2018): Chapter 7, Table 15 salary = [24 26 25 24 27 24 27 23 15 17 20 16, ... 25 29 27 19 18 21 20 21 22 19]'; gender = {'f' 'f' 'f' 'f' 'f' 'f' 'f' 'f' 'f' 'f' 'f' 'f'... 'm' 'm' 'm' 'm' 'm' 'm' 'm' 'm' 'm' 'm'}'; degree = [1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0 0 0]'; [P, ATAB, STATS] = anovan (salary, {gender, degree}, 'model', 'full', ... 'sstype', 3, 'display', 'on', 'varnames', ... {'gender', 'degree'}); ***** demo # Unbalanced two-way ANOVA (3x2) on the data from a study of the effect of # adding sugar and/or milk on the tendency of coffee to make people babble, # in from Navarro (2019): 16.10 sugar = {'real' 'fake' 'fake' 'real' 'real' 'real' 'none' 'none' 'none' ... 'fake' 'fake' 'fake' 'real' 'real' 'real' 'none' 'none' 'fake'}'; milk = {'yes' 'no' 'no' 'yes' 'yes' 'no' 'yes' 'yes' 'yes' ... 'no' 'no' 'yes' 'no' 'no' 'no' 'no' 'no' 'yes'}'; babble = [4.6 4.4 3.9 5.6 5.1 5.5 3.9 3.5 3.7... 5.6 4.7 5.9 6.0 5.4 6.6 5.8 5.3 5.7]'; [P, ATAB, STATS] = anovan (babble, {sugar, milk}, 'model', 'full', ... 'sstype', 3, 'display', 'on', ... 'varnames', {'sugar', 'milk'}); ***** demo # Unbalanced three-way ANOVA (3x2x2) on the data from a study of the effects # of three different drugs, biofeedback and diet on patient blood pressure, # adapted* from Maxwell, Delaney and Kelly (2018): Chapter 8, Table 12 # * Missing values introduced to make the sample sizes unequal to test the # calculation of different types of sums-of-squares drug = {'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' ... 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X'; 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' ... 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y'; 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' ... 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z'}; feedback = [1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0]; diet = [0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1; 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1; 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1]; BP = [170 175 165 180 160 158 161 173 157 152 181 190 ... 173 194 197 190 176 198 164 190 169 164 176 175; 186 194 201 215 219 209 164 166 159 182 187 174 ... 189 194 217 206 199 195 171 173 196 199 180 NaN; 180 187 199 170 204 194 162 184 183 156 180 173 ... 202 228 190 206 224 204 205 199 170 160 NaN NaN]; [P, ATAB, STATS] = anovan (BP(:), {drug(:), feedback(:), diet(:)}, ... 'model', 'full', 'sstype', 3, ... 'display', 'on', ... 'varnames', {'drug', 'feedback', 'diet'}); ***** demo # Balanced three-way ANOVA (2x2x2) with one of the factors being a blocking # factor. The data is from a randomized block design study on the effects # of antioxidant treatment on glutathione-S-transferase (GST) levels in # different mouse strains, from Festing (2014), ILAR Journal, 55(3):427-476. # Naming block as a random factor (') keeps every interaction with block in # the model; each F ratio then takes the denominator its expected mean # square calls for, which for block itself is a combination of three mean # squares carried on fractional degrees of freedom. measurement = [444 614 423 625 408 856 447 719 ... 764 831 586 782 609 1002 606 766]'; strain= {'NIH','NIH','BALB/C','BALB/C','A/J','A/J','129/Ola','129/Ola', ... 'NIH','NIH','BALB/C','BALB/C','A/J','A/J','129/Ola','129/Ola'}'; treatment={'C' 'T' 'C' 'T' 'C' 'T' 'C' 'T' 'C' 'T' 'C' 'T' 'C' 'T' 'C' 'T'}'; block = [1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2]'; [P, ATAB, STATS] = anovan (measurement/10, {strain, treatment, block}, ... 'sstype', 2, 'model', 'full', 'random', 3, ... 'display', 'on', ... 'varnames', {'strain', 'treatment', 'block'}); ***** demo # One-way ANCOVA on data from a study of the additive effects of species # and temperature on chirpy pulses of crickets, from Stitch, The Worst Stats # Text eveR pulse = [67.9 65.1 77.3 78.7 79.4 80.4 85.8 86.6 87.5 89.1 ... 98.6 100.8 99.3 101.7 44.3 47.2 47.6 49.6 50.3 51.8 ... 60 58.5 58.9 60.7 69.8 70.9 76.2 76.1 77 77.7 84.7]'; temp = [20.8 20.8 24 24 24 24 26.2 26.2 26.2 26.2 28.4 ... 29 30.4 30.4 17.2 18.3 18.3 18.3 18.9 18.9 20.4 ... 21 21 22.1 23.5 24.2 25.9 26.5 26.5 26.5 28.6]'; species = {'ex' 'ex' 'ex' 'ex' 'ex' 'ex' 'ex' 'ex' 'ex' 'ex' 'ex' ... 'ex' 'ex' 'ex' 'niv' 'niv' 'niv' 'niv' 'niv' 'niv' 'niv' ... 'niv' 'niv' 'niv' 'niv' 'niv' 'niv' 'niv' 'niv' 'niv' 'niv'}; [P, ATAB, STATS] = anovan (pulse, {species, temp}, 'model', 'linear', ... 'continuous', 2, 'sstype', 'h', 'display', 'on', ... 'varnames', {'species', 'temp'}); ***** demo # Factorial ANCOVA on data from a study of the effects of treatment and # exercise on stress reduction score after adjusting for age. Data from R # datarium package). score = [95.6 82.2 97.2 96.4 81.4 83.6 89.4 83.8 83.3 85.7 ... 97.2 78.2 78.9 91.8 86.9 84.1 88.6 89.8 87.3 85.4 ... 81.8 65.8 68.1 70.0 69.9 75.1 72.3 70.9 71.5 72.5 ... 84.9 96.1 94.6 82.5 90.7 87.0 86.8 93.3 87.6 92.4 ... 100. 80.5 92.9 84.0 88.4 91.1 85.7 91.3 92.3 87.9 ... 91.7 88.6 75.8 75.7 75.3 82.4 80.1 86.0 81.8 82.5]'; treatment = {'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' ... 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' ... 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' ... 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' ... 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' ... 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no'}'; exercise = {'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' ... 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' ... 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' ... 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' ... 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' ... 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi'}'; age = [59 65 70 66 61 65 57 61 58 55 62 61 60 59 55 57 60 63 62 57 ... 58 56 57 59 59 60 55 53 55 58 68 62 61 54 59 63 60 67 60 67 ... 75 54 57 62 65 60 58 61 65 57 56 58 58 58 52 53 60 62 61 61]'; [P, ATAB, STATS] = anovan (score, {treatment, exercise, age}, ... 'model', [1 0 0; 0 1 0; 0 0 1; 1 1 0], ... 'continuous', 3, 'sstype', 'h', 'display', 'on', ... 'varnames', {'treatment', 'exercise', 'age'}); ***** demo # Unbalanced one-way ANOVA with custom, orthogonal contrasts. The statistics # relating to the contrasts are shown in the table of model parameters, and # can be retrieved from the STATS.coeffs output. dv = [ 8.706 10.362 11.552 6.941 10.983 10.092 6.421 14.943 15.931 ... 22.968 18.590 16.567 15.944 21.637 14.492 17.965 18.851 22.891 ... 22.028 16.884 17.252 18.325 25.435 19.141 21.238 22.196 18.038 ... 22.628 31.163 26.053 24.419 32.145 28.966 30.207 29.142 33.212 ... 25.694 ]'; g = [1 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 ... 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5]'; C = [ 0.4001601 0.3333333 0.5 0.0 0.4001601 0.3333333 -0.5 0.0 0.4001601 -0.6666667 0.0 0.0 -0.6002401 0.0000000 0.0 0.5 -0.6002401 0.0000000 0.0 -0.5]; [P,ATAB, STATS] = anovan (dv, g, 'contrasts', C, 'varnames', 'score', ... 'alpha', 0.05, 'display', 'on'); ***** demo # One-way ANOVA with the linear model fit by weighted least squares to # account for heteroskedasticity. In this example, the variance appears # proportional to the outcome, so weights have been estimated by initially # fitting the model without weights and regressing the absolute residuals on # the fitted values. Although this data could have been analysed by Welch's # ANOVA test, the approach here can generalize to ANOVA models with more than # one factor. g = [1, 1, 1, 1, 1, 1, 1, 1, ... 2, 2, 2, 2, 2, 2, 2, 2, ... 3, 3, 3, 3, 3, 3, 3, 3]'; y = [13, 16, 16, 7, 11, 5, 1, 9, ... 10, 25, 66, 43, 47, 56, 6, 39, ... 11, 39, 26, 35, 25, 14, 24, 17]'; [P,ATAB,STATS] = anovan (y, g, 'display', 'off'); fitted = STATS.X * STATS.coeffs(:,1); # fitted values b = polyfit (fitted, abs (STATS.resid), 1); v = polyval (b, fitted); # Variance as a function of the fitted values figure ('Name', 'Regression of the absolute residuals on the fitted values'); plot (fitted, abs (STATS.resid),'ob');hold on; plot (fitted,v,'-r'); hold off; xlabel ('Fitted values'); ylabel ('Absolute residuals'); [P,ATAB,STATS] = anovan (y, g, 'weights', v.^-1); ***** test score = [54 23 45 54 45 43 34 65 77 46 65]'; gender = {'male' 'male' 'male' 'male' 'male' 'female' 'female' 'female' ... 'female' 'female' 'female'}'; [P, T, STATS] = anovan (score,gender,'display','off'); assert_equal (P(1), 0.2612876773271042, 1e-09); # compared to p calculated by MATLAB anovan assert_equal (sqrt (T{2,6}), abs (1.198608733288208), 1e-09); # compared to abs(t) calculated from sqrt(F) by MATLAB anovan assert_equal (P(1), 0.2612876773271047, 1e-09); # compared to p calculated by MATLAB ttest2 assert_equal (sqrt (T{2,6}), abs (-1.198608733288208), 1e-09); # compared to abs(t) calculated by MATLAB ttest2 ***** test score = [4.5 5.6; 3.7 6.4; 5.3 6.4; 5.4 6.0; 3.9 5.7]'; treatment = {'before' 'after'; 'before' 'after'; 'before' 'after'; 'before' 'after'; 'before' 'after'}'; subject = {'GS' 'GS'; 'JM' 'JM'; 'HM' 'HM'; 'JW' 'JW'; 'PS' 'PS'}'; [P, ATAB, STATS] = anovan (score(:),{treatment(:),subject(:)},'display','off','sstype',2); assert_equal (P(1), 0.016004356735364, 1e-09); # compared to p calculated by MATLAB anovan assert_equal (sqrt (ATAB{2,6}), abs (4.00941576558195), 1e-09); # compared to abs(t) calculated from sqrt(F) by MATLAB anovan assert_equal (P(1), 0.016004356735364, 1e-09); # compared to p calculated by MATLAB ttest2 assert_equal (sqrt (ATAB{2,6}), abs (-4.00941576558195), 1e-09); # compared to abs(t) calculated by MATLAB ttest2 ***** test strength = [82 86 79 83 84 85 86 87 74 82 ... 78 75 76 77 79 79 77 78 82 79]'; alloy = {'st','st','st','st','st','st','st','st', ... 'al1','al1','al1','al1','al1','al1', ... 'al2','al2','al2','al2','al2','al2'}'; [P, ATAB, STATS] = anovan (strength,{alloy},'display','off'); assert_equal (P(1), 0.000152643638830491, 1e-09); assert_equal (ATAB{2,6}, 15.4, 1e-09); ***** test words = [10 13 13; 6 8 8; 11 14 14; 22 23 25; 16 18 20; ... 15 17 17; 1 1 4; 12 15 17; 9 12 12; 8 9 12]; subject = [ 1 1 1; 2 2 2; 3 3 3; 4 4 4; 5 5 5; ... 6 6 6; 7 7 7; 8 8 8; 9 9 9; 10 10 10]; seconds = [1 2 5; 1 2 5; 1 2 5; 1 2 5; 1 2 5; ... 1 2 5; 1 2 5; 1 2 5; 1 2 5; 1 2 5;]; [P, ATAB, STATS] = anovan (words(:),{seconds(:),subject(:)},'model','full','random',2,'sstype',2,'display','off'); assert_equal (P(1), 1.51865926758752e-07, 1e-09); assert_equal (ATAB{2,2}, 52.2666666666667, 1e-09); assert_equal (ATAB{3,2}, 942.533333333333, 1e-09); assert_equal (ATAB{4,2}, 11.0666666666667, 1e-09); ***** test popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; brands = {'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'}; popper = {'oil', 'oil', 'oil'; 'oil', 'oil', 'oil'; 'oil', 'oil', 'oil'; ... 'air', 'air', 'air'; 'air', 'air', 'air'; 'air', 'air', 'air'}; [P, ATAB, STATS] = anovan (popcorn(:),{brands(:),popper(:)},'display','off','model','full'); assert_equal (P(1), 7.67895738278171e-07, 1e-09); assert_equal (P(2), 0.000100373896304998, 1e-09); assert_equal (P(3), 0.746215396636649, 1e-09); assert_equal (ATAB{2,6}, 56.7, 1e-09); assert_equal (ATAB{3,6}, 32.4, 1e-09); assert_equal (ATAB{4,6}, 0.29999999999997, 1e-09); ***** test salary = [24 26 25 24 27 24 27 23 15 17 20 16, ... 25 29 27 19 18 21 20 21 22 19]'; gender = {'f' 'f' 'f' 'f' 'f' 'f' 'f' 'f' 'f' 'f' 'f' 'f'... 'm' 'm' 'm' 'm' 'm' 'm' 'm' 'm' 'm' 'm'}'; degree = [1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0 0 0]'; [P, ATAB, STATS] = anovan (salary,{gender,degree},'model','full','sstype',1,'display','off'); assert_equal (P(1), 0.747462549227232, 1e-09); assert_equal (P(2), 1.03809316857694e-08, 1e-09); assert_equal (P(3), 0.523689833702691, 1e-09); assert_equal (ATAB{2,2}, 0.296969696969699, 1e-09); assert_equal (ATAB{3,2}, 272.391841491841, 1e-09); assert_equal (ATAB{4,2}, 1.17482517482512, 1e-09); assert_equal (ATAB{5,2}, 50.0000000000001, 1e-09); [P, ATAB, STATS] = anovan (salary,{degree,gender},'model','full','sstype',1,'display','off'); assert_equal (P(1), 2.53445097305047e-08, 1e-09); assert_equal (P(2), 0.00388133678528749, 1e-09); assert_equal (P(3), 0.523689833702671, 1e-09); assert_equal (ATAB{2,2}, 242.227272727273, 1e-09); assert_equal (ATAB{3,2}, 30.4615384615384, 1e-09); assert_equal (ATAB{4,2}, 1.17482517482523, 1e-09); assert_equal (ATAB{5,2}, 50.0000000000001, 1e-09); [P, ATAB, STATS] = anovan (salary,{gender,degree},'model','full','sstype',2,'display','off'); assert_equal (P(1), 0.00388133678528743, 1e-09); assert_equal (P(2), 1.03809316857694e-08, 1e-09); assert_equal (P(3), 0.523689833702691, 1e-09); assert_equal (ATAB{2,2}, 30.4615384615385, 1e-09); assert_equal (ATAB{3,2}, 272.391841491841, 1e-09); assert_equal (ATAB{4,2}, 1.17482517482512, 1e-09); assert_equal (ATAB{5,2}, 50.0000000000001, 1e-09); [P, ATAB, STATS] = anovan (salary,{gender,degree},'model','full','sstype',3,'display','off'); assert_equal (P(1), 0.00442898146583742, 1e-09); assert_equal (P(2), 1.30634252053587e-08, 1e-09); assert_equal (P(3), 0.523689833702691, 1e-09); assert_equal (ATAB{2,2}, 29.3706293706294, 1e-09); assert_equal (ATAB{3,2}, 264.335664335664, 1e-09); assert_equal (ATAB{4,2}, 1.17482517482512, 1e-09); assert_equal (ATAB{5,2}, 50.0000000000001, 1e-09); ***** test sugar = {'real' 'fake' 'fake' 'real' 'real' 'real' 'none' 'none' 'none' ... 'fake' 'fake' 'fake' 'real' 'real' 'real' 'none' 'none' 'fake'}'; milk = {'yes' 'no' 'no' 'yes' 'yes' 'no' 'yes' 'yes' 'yes' ... 'no' 'no' 'yes' 'no' 'no' 'no' 'no' 'no' 'yes'}'; babble = [4.6 4.4 3.9 5.6 5.1 5.5 3.9 3.5 3.7... 5.6 4.7 5.9 6.0 5.4 6.6 5.8 5.3 5.7]'; [P, ATAB, STATS] = anovan (babble,{sugar,milk},'model','full','sstype',1,'display','off'); assert_equal (P(1), 0.0108632139833963, 1e-09); assert_equal (P(2), 0.0810606976703546, 1e-09); assert_equal (P(3), 0.00175433329935627, 1e-09); assert_equal (ATAB{2,2}, 3.55752380952381, 1e-09); assert_equal (ATAB{3,2}, 0.956108477471702, 1e-09); assert_equal (ATAB{4,2}, 5.94386771300448, 1e-09); assert_equal (ATAB{5,2}, 3.1625, 1e-09); [P, ATAB, STATS] = anovan (babble,{milk,sugar},'model','full','sstype',1,'display','off'); assert_equal (P(1), 0.0373333189297505, 1e-09); assert_equal (P(2), 0.017075098787169, 1e-09); assert_equal (P(3), 0.00175433329935627, 1e-09); assert_equal (ATAB{2,2}, 1.444, 1e-09); assert_equal (ATAB{3,2}, 3.06963228699552, 1e-09); assert_equal (ATAB{4,2}, 5.94386771300448, 1e-09); assert_equal (ATAB{5,2}, 3.1625, 1e-09); [P, ATAB, STATS] = anovan (babble,{sugar,milk},'model','full','sstype',2,'display','off'); assert_equal (P(1), 0.017075098787169, 1e-09); assert_equal (P(2), 0.0810606976703546, 1e-09); assert_equal (P(3), 0.00175433329935627, 1e-09); assert_equal (ATAB{2,2}, 3.06963228699552, 1e-09); assert_equal (ATAB{3,2}, 0.956108477471702, 1e-09); assert_equal (ATAB{4,2}, 5.94386771300448, 1e-09); assert_equal (ATAB{5,2}, 3.1625, 1e-09); [P, ATAB, STATS] = anovan (babble,{sugar,milk},'model','full','sstype',3,'display','off'); assert_equal (P(1), 0.0454263063473954, 1e-09); assert_equal (P(2), 0.0746719907091438, 1e-09); assert_equal (P(3), 0.00175433329935627, 1e-09); assert_equal (ATAB{2,2}, 2.13184977578476, 1e-09); assert_equal (ATAB{3,2}, 1.00413461538462, 1e-09); assert_equal (ATAB{4,2}, 5.94386771300448, 1e-09); assert_equal (ATAB{5,2}, 3.1625, 1e-09); ***** test drug = {'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' ... 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X'; 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' ... 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y' 'Y'; 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' ... 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z' 'Z'}; feedback = [1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0]; diet = [0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1; 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1; 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1]; BP = [170 175 165 180 160 158 161 173 157 152 181 190 ... 173 194 197 190 176 198 164 190 169 164 176 175; 186 194 201 215 219 209 164 166 159 182 187 174 ... 189 194 217 206 199 195 171 173 196 199 180 NaN; 180 187 199 170 204 194 162 184 183 156 180 173 ... 202 228 190 206 224 204 205 199 170 160 NaN NaN]; [P, ATAB, STATS] = anovan (BP(:),{drug(:),feedback(:),diet(:)},'model','full','sstype', 1,'display','off'); assert_equal (P(1), 7.02561843825325e-05, 1e-09); assert_equal (P(2), 0.000425806013389362, 1e-09); assert_equal (P(3), 6.16780773446401e-07, 1e-09); assert_equal (P(4), 0.261347622678438, 1e-09); assert_equal (P(5), 0.0542278432357043, 1e-09); assert_equal (P(6), 0.590353225626655, 1e-09); assert_equal (P(7), 0.0861628249564267, 1e-09); assert_equal (ATAB{2,2}, 3614.70355731226, 1e-09); assert_equal (ATAB{3,2}, 2227.46639771024, 1e-09); assert_equal (ATAB{4,2}, 5008.25614451819, 1e-09); assert_equal (ATAB{5,2}, 437.066007908781, 1e-09); assert_equal (ATAB{6,2}, 976.180770397332, 1e-09); assert_equal (ATAB{7,2}, 46.616653365254, 1e-09); assert_equal (ATAB{8,2}, 814.345251396648, 1e-09); assert_equal (ATAB{9,2}, 9065.8, 1e-09); [P, ATAB, STATS] = anovan (BP(:),{drug(:),feedback(:),diet(:)},'model','full','sstype',2,'display','off'); assert_equal (P(1), 9.4879638470754e-05, 1e-09); assert_equal (P(2), 0.00124177666315809, 1e-09); assert_equal (P(3), 6.86162012732911e-07, 1e-09); assert_equal (P(4), 0.260856132341256, 1e-09); assert_equal (P(5), 0.0523758623892078, 1e-09); assert_equal (P(6), 0.590353225626655, 1e-09); assert_equal (P(7), 0.0861628249564267, 1e-09); assert_equal (ATAB{2,2}, 3481.72176560122, 1e-09); assert_equal (ATAB{3,2}, 1837.08812970469, 1e-09); assert_equal (ATAB{4,2}, 4957.20277938622, 1e-09); assert_equal (ATAB{5,2}, 437.693674777847, 1e-09); assert_equal (ATAB{6,2}, 988.431929811402, 1e-09); assert_equal (ATAB{7,2}, 46.616653365254, 1e-09); assert_equal (ATAB{8,2}, 814.345251396648, 1e-09); assert_equal (ATAB{9,2}, 9065.8, 1e-09); [P, ATAB, STATS] = anovan (BP(:),{drug(:),feedback(:),diet(:)},'model','full','sstype', 3,'display','off'); assert_equal (P(1), 0.000106518678028207, 1e-09); assert_equal (P(2), 0.00125371366571508, 1e-09); assert_equal (P(3), 5.30813260778464e-07, 1e-09); assert_equal (P(4), 0.308353667232981, 1e-09); assert_equal (P(5), 0.0562901327343161, 1e-09); assert_equal (P(6), 0.599091042141092, 1e-09); assert_equal (P(7), 0.0861628249564267, 1e-09); assert_equal (ATAB{2,2}, 3430.88156424581, 1e-09); assert_equal (ATAB{3,2}, 1833.68031496063, 1e-09); assert_equal (ATAB{4,2}, 5080.48346456693, 1e-09); assert_equal (ATAB{5,2}, 382.07709497207, 1e-09); assert_equal (ATAB{6,2}, 963.037988826813, 1e-09); assert_equal (ATAB{7,2}, 44.4519685039322, 1e-09); assert_equal (ATAB{8,2}, 814.345251396648, 1e-09); assert_equal (ATAB{9,2}, 9065.8, 1e-09); ***** test measurement = [444 614 423 625 408 856 447 719 ... 764 831 586 782 609 1002 606 766]'; strain= {'NIH','NIH','BALB/C','BALB/C','A/J','A/J','129/Ola','129/Ola', ... 'NIH','NIH','BALB/C','BALB/C','A/J','A/J','129/Ola','129/Ola'}'; treatment={'C' 'T' 'C' 'T' 'C' 'T' 'C' 'T' 'C' 'T' 'C' 'T' 'C' 'T' 'C' 'T'}'; block = [1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2]'; [P, ATAB, STATS] = anovan (measurement/10,{strain,treatment,block},'model','full','random',3,'display','off'); assert_equal (P(1:6), [0.288811428913179; 0.091455278902114; ... 0.042134889025806; 0.010944863181481; ... 0.061814763198376; 0.066584161056625], 1e-12); assert_equal (P(7), NaN); assert_equal (cell2mat (ATAB(2:8,2)), ... [286.132499999999; 2275.28999999999; 1242.5625; ... 495.905000000000; 141.472499999998; 47.6099999999987; ... 17.9249999999992], 1e-9); assert_equal (ATAB{9,2}, 0); assert_equal (ATAB{10,2}, 4506.8975, 1e-9); assert_equal (STATS.msdenom, ... [47.1575; 47.61; 88.7925; 5.975; 5.975; 5.975; 0], 1e-9); assert_equal (STATS.dfdenom, ... [3; 1; 2.610727841363640; 3; 3; 3; 0], 1e-12); assert_equal (STATS.varest, ... [144.22125; 20.59125; 10.40875; 5.975; 0], 1e-9); ***** test pulse = [67.9 65.1 77.3 78.7 79.4 80.4 85.8 86.6 87.5 89.1 ... 98.6 100.8 99.3 101.7 44.3 47.2 47.6 49.6 50.3 51.8 ... 60 58.5 58.9 60.7 69.8 70.9 76.2 76.1 77 77.7 84.7]'; temp = [20.8 20.8 24 24 24 24 26.2 26.2 26.2 26.2 28.4 ... 29 30.4 30.4 17.2 18.3 18.3 18.3 18.9 18.9 20.4 ... 21 21 22.1 23.5 24.2 25.9 26.5 26.5 26.5 28.6]'; species = {'ex' 'ex' 'ex' 'ex' 'ex' 'ex' 'ex' 'ex' 'ex' 'ex' 'ex' ... 'ex' 'ex' 'ex' 'niv' 'niv' 'niv' 'niv' 'niv' 'niv' 'niv' ... 'niv' 'niv' 'niv' 'niv' 'niv' 'niv' 'niv' 'niv' 'niv' 'niv'}; [P, ATAB, STATS] = anovan (pulse,{species,temp},'model','linear','continuous',2,'sstype','h','display','off'); assert_equal (P(1), 6.27153318786007e-14, 1e-09); assert_equal (P(2), 2.48773241196644e-25, 1e-09); assert_equal (ATAB{2,2}, 598.003953318404, 1e-09); assert_equal (ATAB{3,2}, 4376.08256843712, 1e-09); assert_equal (ATAB{4,2}, 89.3498685376726, 1e-09); assert_equal (ATAB{2,6}, 187.399388123951, 1e-09); assert_equal (ATAB{3,6}, 1371.35413763454, 1e-09); ***** test score = [95.6 82.2 97.2 96.4 81.4 83.6 89.4 83.8 83.3 85.7 ... 97.2 78.2 78.9 91.8 86.9 84.1 88.6 89.8 87.3 85.4 ... 81.8 65.8 68.1 70.0 69.9 75.1 72.3 70.9 71.5 72.5 ... 84.9 96.1 94.6 82.5 90.7 87.0 86.8 93.3 87.6 92.4 ... 100. 80.5 92.9 84.0 88.4 91.1 85.7 91.3 92.3 87.9 ... 91.7 88.6 75.8 75.7 75.3 82.4 80.1 86.0 81.8 82.5]'; treatment = {'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' ... 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' ... 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' ... 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' ... 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' ... 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no'}'; exercise = {'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' ... 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' ... 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' ... 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' ... 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' ... 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi'}'; age = [59 65 70 66 61 65 57 61 58 55 62 61 60 59 55 57 60 63 62 57 ... 58 56 57 59 59 60 55 53 55 58 68 62 61 54 59 63 60 67 60 67 ... 75 54 57 62 65 60 58 61 65 57 56 58 58 58 52 53 60 62 61 61]'; [P, ATAB, STATS] = anovan (score,{treatment,exercise,age},'model','full','continuous',3,'sstype','h','display','off'); assert_equal (P(5), 0.9245630968248468, 1e-09); assert_equal (P(6), 0.791115159521822, 1e-09); assert_equal (P(7), 0.9296668751457956, 1e-09); [P, ATAB, STATS] = anovan (score,{treatment,exercise,age},'model',[1 0 0; 0 1 0; 0 0 1; 1 1 0],'continuous',3,'sstype','h','display','off'); assert_equal (P(1), 0.00158132928938933, 1e-09); assert_equal (P(2), 2.12537505039986e-07, 1e-09); assert_equal (P(3), 0.00390292555160047, 1e-09); assert_equal (P(4), 0.0164086580775543, 1e-09); assert_equal (ATAB{2,6}, 11.0956027650549, 1e-09); assert_equal (ATAB{3,6}, 20.8195665467178, 1e-09); assert_equal (ATAB{4,6}, 9.10966630720186, 1e-09); assert_equal (ATAB{5,6}, 4.4457923698584, 1e-09); ***** test dv = [ 8.706 10.362 11.552 6.941 10.983 10.092 6.421 14.943 15.931 ... 22.968 18.590 16.567 15.944 21.637 14.492 17.965 18.851 22.891 ... 22.028 16.884 17.252 18.325 25.435 19.141 21.238 22.196 18.038 ... 22.628 31.163 26.053 24.419 32.145 28.966 30.207 29.142 33.212 ... 25.694 ]'; g = [1 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5]'; C = [ 0.4001601 0.3333333 0.5 0.0 0.4001601 0.3333333 -0.5 0.0 0.4001601 -0.6666667 0.0 0.0 -0.6002401 0.0000000 0.0 0.5 -0.6002401 0.0000000 0.0 -0.5]; [P,ATAB,STATS] = anovan (dv,g,'contrasts',{C},'display','off'); assert_equal (STATS.coeffs(1,1), 19.4001, 1e-04); assert_equal (STATS.coeffs(2,1), -9.3297, 1e-04); assert_equal (STATS.coeffs(3,1), -5.0000, 1e-04); assert_equal (STATS.coeffs(4,1), -8.0000, 1e-04); assert_equal (STATS.coeffs(5,1), -8.0000, 1e-04); assert_equal (STATS.coeffs(1,2), 0.4831, 1e-04); assert_equal (STATS.coeffs(2,2), 0.9694, 1e-04); assert_equal (STATS.coeffs(3,2), 1.3073, 1e-04); assert_equal (STATS.coeffs(4,2), 1.6411, 1e-04); assert_equal (STATS.coeffs(5,2), 1.4507, 1e-04); assert_equal (STATS.coeffs(1,5), 40.161, 1e-03); assert_equal (STATS.coeffs(2,5), -9.624, 1e-03); assert_equal (STATS.coeffs(3,5), -3.825, 1e-03); assert_equal (STATS.coeffs(4,5), -4.875, 1e-03); assert_equal (STATS.coeffs(5,5), -5.515, 1e-03); assert_equal (STATS.coeffs(2,6), 5.74e-11, 1e-12); assert_equal (STATS.coeffs(3,6), 0.000572, 1e-06); assert_equal (STATS.coeffs(4,6), 2.86e-05, 1e-07); assert_equal (STATS.coeffs(5,6), 4.44e-06, 1e-08); ***** test y = (1:12)'; g1 = repmat ([1; 2; 3], 4, 1); g2 = kron ([1; 2], ones (6, 1)); [~, ~, stats] = anovan (y, {g1, g2}, 'model', 'full', ... 'display', 'off'); assert_equal (stats.X(:,5), stats.X(:,2) .* stats.X(:,4)); assert_equal (stats.X(:,6), stats.X(:,3) .* stats.X(:,4)); ***** test n = 128; group = cell (1, 6); for k = 1:6 group{k} = mod (floor ((0:n-1)' / 2^(k-1)), 2) + 1; endfor [p, ~, stats, terms] = anovan ((1:n)', group, 'model', 'full', ... 'display', 'off'); assert_equal (rows (terms), 63); assert_equal (columns (stats.X), 64); assert_equal (numel (p), 63); ***** test group = ones (3, 1); [p, tbl, stats] = anovan ((1:3)', group, ... 'sstype', 2, 'display', 'off'); assert_equal (p, NaN); assert_equal (tbl{2, 2}, 0); assert_equal (tbl{2, 3}, 0); assert_equal (tbl{2, 6}, NaN); assert_equal (size (stats.X), [3, 1]); ***** test group = categorical ([3; 3; NaN; 1; 1], [3, 2, 1]); [p, tbl, stats] = anovan ((1:5)', group, 'sstype', 2, 'display', 'off'); [p_ref, tbl_ref] = anovan ([1; 2; 4; 5], [1; 1; 2; 2], ... 'sstype', 2, 'display', 'off'); assert_equal (p, p_ref, 1e-12); assert_equal (tbl, tbl_ref); assert_equal (stats.grpnames{1}, {'3'; '1'}); assert_equal (stats.Y, [1; 2; 4; 5]); ***** test A = [1; 1; 2; 2]; B = [1; 2; 1; 2]; y = 100 * A + B; [~, tbl, stats, terms] = anovan (y, {A, B}, 'model', [0, 1], ... 'display', 'off'); assert_equal (terms, [0, 1]); assert_equal (tbl{2, 1}, 'X2'); assert_equal (tbl{2, 2}, 1, 1e-12); assert_equal (full (stats.X(:, 2)), [-0.5; 0.5; -0.5; 0.5]); ***** test A = [1; 1; 2; 2]; B = [1; 2; 1; 2]; y = 100 * A + B; [~, tbl] = anovan (y, {A, B}, 'model', [0, 1; 1, 0], ... 'sstype', 1, 'display', 'off'); assert_equal (tbl(2:3, 1), {'X2'; 'X1'}); assert_equal (cell2mat (tbl(2:3, 2)), [1; 10000], 1e-10); ***** test x = (1:5)'; y = 2 + 3 * x + 4 * x .^ 2 + [0.3; -0.2; 0.1; 0.4; -0.6]; [p, tbl, ~, terms] = anovan (y, x, 'model', [1; 2], 'continuous', 1, ... 'sstype', 2, 'display', 'off'); assert_equal (terms, [1; 2]); assert_equal (tbl(2:3, 1), {'X1'; 'X1^2'}); assert_equal (cell2mat (tbl(2:3, 2)), ... [4.09767456073500; 216.071428571430], 1e-9); assert_equal (cell2mat (tbl(2:3, 3)), [1; 1]); assert_equal (cell2mat (tbl(4, 2:3)), [0.444571428570271, 2], 1e-9); assert_equal (p, [0.0501972848960940; 0.00102717552592300], 1e-12); ***** test x = (1:5)'; y = 2 + 3 * x + 4 * x .^ 2 + [0.3; -0.2; 0.1; 0.4; -0.6]; [p, tbl] = anovan (y, x, 'model', [1; 2], 'continuous', 1, ... 'sstype', 'h', 'display', 'off'); assert_equal (cell2mat (tbl(2:3, 2)), ... [7225.34400000000; 216.071428571430], 1e-8); assert_equal (p, [3.07633044150000e-05; 0.00102717552592300], 1e-12); ***** test x = (1:5)'; y = 2 + 3 * x + 4 * x .^ 2 + [0.3; -0.2; 0.1; 0.4; -0.6]; [p_lower, tbl_lower] = anovan (y, x, 'model', [1; 2], 'continuous', 1, ... 'sstype', 'h', 'display', 'off'); [p_upper, tbl_upper] = anovan (y, x, 'model', [1; 2], 'continuous', 1, ... 'sstype', 'H', 'display', 'off'); assert_equal (p_upper, p_lower); assert_equal (tbl_upper, tbl_lower); ***** test ## Below the resolution of 1 - tcdf [~, ~, stats] = anovan ([1:10, 101:110, 201:210]', ... kron ((1:3)', ones (10, 1)), 'display', 'off'); t = stats.coeffs(:,5); dfe = stats.dfe; assert_equal (stats.coeffs(:,6), ... betainc (dfe ./ (dfe + t .^ 2), dfe / 2, 1/2), -1e-12); ***** test ## Below the resolution of 1 - fcdf, values from MATLAB R2024a w = [1:10, 101:110, 201:210]'; g = kron ((1:3)', ones (10, 1)); p = anovan (w, {g}, 'display', 'off'); assert_equal (p, 5.52216470815463e-40, -1e-10); ***** error ... anovan ((1:4)', {[1; 1; 2; 2], [1; 2; 1; 2]}, ... 'model', [2, 0], 'display', 'off') ***** error ... anovan ((1:4)', {[1; 1; 2; 2], [1; 2; 1; 2]}, ... 'nested', [0, 1], 'display', 'off') ***** error ... anovan ((1:4)', {[1; 1; 2; 2], [1; 2; 1; 2]}, ... 'nested', [0, 2; 0, 0], 'display', 'off') ***** error ... anovan ((1:4)', {[1; 1; 2; 2], [1; 2; 1; 2]}, ... 'nested', eye (2), 'display', 'off') ***** error ... anovan ((1:4)', {[1; 1; 2; 2], [1; 2; 1; 2]}, ... 'nested', [0, 1; 1, 0], 'display', 'off') ***** error ... anovan ((1:4)', {[1; 1; 2; 2], [1; 2; 1; 2]}, ... 'nested', [0, 0; 1, 0], 'continuous', 1, 'display', 'off') ***** error ... anovan ((1:8)', [kron([1; 2], ones(4, 1)), ... repmat([1; 1; 2; 2], 2, 1)], 'nested', [0, 0; 1, 0], ... 'contrasts', {[]; [-0.5; 0.5]}, 'display', 'off') ***** test A = [1; 1; 1; 1; 2; 2]; B = [1; 1; 2; 2; 1; 1]; y = [3; 4; 7; 8; 5; 6]; [~, tbl] = anovan (y, {A, B}, 'model', 'full', 'sstype', 3, ... 'display', 'off'); assert_equal (tbl{end-1, 2}, 1.5, 1e-12); assert_equal (tbl{end-1, 3}, 3); assert_equal (tbl{end-1, 5}, 0.5, 1e-12); assert_equal (tbl{end, 2}, 17.5, 1e-12); ***** test A = [1; 1; 1; 1; 2; 2]; B = [1; 1; 2; 2; 1; 1]; y = [3; 4; 7; 8; 5; 6]; [~, t3] = anovan (y, {A, B}, 'model', 'full', 'sstype', 3, 'display', 'off'); assert_equal (cell2mat (t3(2:4, 3)), [0; 0; 0]); assert_equal (cell2mat (t3(2:4, 4)), [1; 1; 1]); [~, t2] = anovan (y, {A, B}, 'model', 'full', 'sstype', 2, 'display', 'off'); assert_equal (cell2mat (t2(2:4, 3)), [1; 1; 0]); assert_equal (cell2mat (t2(2:4, 4)), [0; 0; 1]); assert_equal (cell2mat (t2(2:4, 2)), [4; 16; 0], 1e-12); ***** test A = [1; 1; 2; 2; 3; 3]; B = [1; 1; 1; 1; 2; 2]; y = [3; 4; 7; 8; 5; 6]; [~, tbl] = anovan (y, {A, B}, 'model', 'linear', 'sstype', 3, ... 'display', 'off'); assert_equal (cell2mat (tbl(2:3, 3)), [1; 0]); assert_equal (cell2mat (tbl(2:3, 4)), [1; 1]); assert_equal (tbl{2, 2}, 16, 1e-12); ***** test A = [1; 1; 2; 2; 1; 1; 2; 2]; B = [1; 2; 1; 2; 1; 2; 1; 2]; y = [3; 4; 7; 8; 5; 6; 9; 11]; [~, tbl] = anovan (y, {A, B}, 'model', 'full', 'display', 'off'); assert_equal (cell2mat (tbl(2:4, 4)), [0; 0; 0]); assert_equal (cell2mat (tbl(2:4, 2)), [36.125; 3.125; 0.125], 1e-12); ***** test [~, tbl] = anovan ((1:3)', ones (3, 1), 'sstype', 2, 'display', 'off'); assert_equal (tbl{2, 3}, 0); assert_equal (tbl{2, 4}, 0); assert_equal (tbl{end-1, 2}, 2, 1e-12); ***** test A = [1; 1; 2; 2; 1; 1; 2; 2]; B = [1; 2; 1; 2; 1; 2; 1; 2]; y = [3; 4; 7; 8; 5; 6; 9; 11]; [~, tbl] = anovan (y, {A, B}, 'model', 'full', 'display', 'off'); assert_equal (tbl(1, :), {'Source', 'Sum Sq.', 'd.f.', 'Singular?', ... 'Mean Sq.', 'F', 'Prob>F', 'Eta Sq.', ... 'Part. Eta Sq.'}); ss = cell2mat (tbl(2:4, 2)); sse = tbl{end-1, 2}; sst = tbl{end, 2}; assert_equal (cell2mat (tbl(2:4, 8)), ss ./ sst, 1e-12); assert_equal (cell2mat (tbl(2:4, 9)), ss ./ (ss + sse), 1e-12); ***** test y = [444 614 423 625 408 856 447 719 ... 764 831 586 782 609 1002 606 766]' / 10; g1 = {'NIH','NIH','BALB/C','BALB/C','A/J','A/J','129/Ola','129/Ola', ... 'NIH','NIH','BALB/C','BALB/C','A/J','A/J','129/Ola','129/Ola'}'; g2 = {'C','T','C','T','C','T','C','T','C','T','C','T','C','T','C','T'}'; g3 = [1;1;1;1;1;1;1;1;2;2;2;2;2;2;2;2]; [~, tbl] = anovan (y, {g1, g2, g3}, 'model', 'full', 'random', 3, ... 'display', 'off'); assert_equal (size (tbl), [10, 17]); assert_equal (tbl(1, 1:15), {'Source', 'Sum Sq.', 'd.f.', 'Singular?', ... 'Mean Sq.', 'F', 'Prob>F', 'Type', 'Expected MS', ... 'MS denom', 'd.f. denom', 'Denom. defn.', 'Var. est.', ... 'Var. lower bnd', 'Var. upper bnd'}); assert_equal (tbl(2:9, 8), {'fixed'; 'fixed'; 'random'; 'fixed'; ... 'random'; 'random'; 'random'; 'random'}); assert_equal (cell2mat (tbl(2:8, 11)), ... [3; 1; 2.610727841363640; 3; 3; 3; 0], 1e-12); ***** test [~, tbl] = anovan ((1:12)', {repmat([1;2;3],4,1), kron([1;2],ones(6,1))}, ... 'model', 'full', 'display', 'off'); assert_equal (size (tbl), [6, 9]); assert_equal (tbl{1, 9}, 'Part. Eta Sq.'); ***** test y = [444 614 423 625 408 856 447 719 ... 764 831 586 782 609 1002 606 766]' / 10; g1 = {'NIH','NIH','BALB/C','BALB/C','A/J','A/J','129/Ola','129/Ola', ... 'NIH','NIH','BALB/C','BALB/C','A/J','A/J','129/Ola','129/Ola'}'; g2 = {'C','T','C','T','C','T','C','T','C','T','C','T','C','T','C','T'}'; g3 = [1;1;1;1;1;1;1;1;2;2;2;2;2;2;2;2]; [p, tbl, s, terms] = anovan (y, {g1, g2, g3}, 'model', 'full', ... 'random', 3, 'display', 'off'); assert_equal (rows (terms), 7); assert_equal (numel (p), 7); assert_equal (size (s.denom), [7, 5]); assert_equal (size (s.ems), [8, 8]); assert_equal (numel (s.txtems), 8); ***** test [~, tbl] = anovan ((1:12)', {repmat([1;2;3],4,1), kron([1;2],ones(6,1))}, ... 'model', 'full', 'display', 'off'); assert_equal (tbl(2:end, 1), ... {'X1'; 'X2'; 'X1:X2'; 'Error'; 'Total'}); ***** test g = cell (1, 3); for k = 1:3 g{k} = mod (floor ((0:15)' / 2^(k-1)), 2) + 1; endfor [~, tbl] = anovan ((1:16)', g, 'model', 'full', 'display', 'off'); assert_equal (tbl{8, 1}, 'X1:X2:X3'); ***** test y = [3; 4; 7; 8; 5; 6; 9; 11]; A = [1; 1; 2; 2; 1; 1; 2; 2]; B = [1; 2; 1; 2; 1; 2; 1; 2]; [~, tbl, s] = anovan (y, {A, B}, 'model', 'full', 'random', 2, ... 'display', 'off'); assert_equal (tbl(2:4, 1), {'X1'; 'X2'; 'X1:X2'}); assert_equal (s.varnames, {'X1', 'X2'}); assert_equal (any (cellfun (@(t) any (t == "'"), s.txtems)), false); assert_equal (any (cellfun (@(t) any (t == "'"), s.txtdenom)), false); ***** test y = [3; 4; 7; 8; 5; 6; 9; 11]; A = [1; 1; 2; 2; 1; 1; 2; 2]; B = [1; 2; 1; 2; 1; 2; 1; 2]; visible = get (0, 'defaultfigurevisible'); unwind_protect set (0, 'defaultfigurevisible', 'off'); txt = evalc (["anovan (y, {A, B}, 'model', 'full', 'random', 2, ", ... "'display', 'on');"]); unwind_protect_cleanup set (0, 'defaultfigurevisible', visible); close all; end_unwind_protect assert_equal (! isempty (strfind (txt, "X2'")), true); assert_equal (! isempty (strfind (txt, "X1:X2'")), true); 43 tests, 43 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/vartest2.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/vartest2.m ***** test ## Below the resolution of 1 - fcdf, values from MATLAB R2024a s = sin (1:50)'; [~, p] = vartest2 (100 * s, 0.01 * s); assert_equal (p, 6.38404544818042e-183, -1e-10); ***** error vartest2 (); ***** error vartest2 (ones (20,1)); ***** error ... vartest2 (rand (20,1), 5); ***** error ... vartest2 (rand (20,1), rand (25,1)*2, 'alpha', 0); ***** error ... vartest2 (rand (20,1), rand (25,1)*2, 'alpha', 1.2); ***** error ... vartest2 (rand (20,1), rand (25,1)*2, 'alpha', 'some'); ***** error ... vartest2 (rand (20,1), rand (25,1)*2, 'alpha', [0.05, 0.001]); ***** error ... vartest2 (rand (20,1), rand (25,1)*2, 'tail', [0.05, 0.001]); ***** error ... vartest2 (rand (20,1), rand (25,1)*2, 'tail', 'some'); ***** error ... vartest2 (rand (20,1), rand (25,1)*2, 'dim', 3); ***** error ... vartest2 (rand (20,1), rand (25,1)*2, 'alpha', 0.001, 'dim', 3); ***** error ... vartest2 (rand (20,1), rand (25,1)*2, 'some', 3); ***** error ... vartest2 (rand (20,1), rand (25,1)*2, 'some'); ***** test load carsmall [h, pval, ci, stat] = vartest2 (MPG(Model_Year==82), MPG(Model_Year==76)); assert_equal (h, 0); assert_equal (pval, 0.6288022362718455, 1e-13); assert_equal (ci, [0.4139; 1.7193], 1e-4); assert_equal (stat.fstat, 0.8384, 1e-4); assert_equal (stat.df1, 30); assert_equal (stat.df2, 33); ***** test load carsmall [h, pval, ci, stat] = vartest2 (MPG(Model_Year==82), MPG(Model_Year==76), ... 'tail', 'left'); assert_equal (h, 0); assert_equal (pval, 0.314401118135922, 1e-13); assert_equal (ci, [0; 1.5287], 1e-4); assert_equal (stat.fstat, 0.8384, 1e-4); assert_equal (stat.df1, 30); assert_equal (stat.df2, 33); ***** test load carsmall [h, pval, ci, stat] = vartest2 (MPG(Model_Year==82), MPG(Model_Year==76), ... 'tail', 'right'); assert_equal (h, 0); assert_equal (pval, 0.685598881864077, 1e-13); assert_equal (ci, [0.4643; Inf], 1e-4); assert_equal (stat.fstat, 0.8384, 1e-4); assert_equal (stat.df1, 30); assert_equal (stat.df2, 33); 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/kstest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/kstest.m ***** demo ## Use the stock return data set to test the null hypothesis that the data ## come from a standard normal distribution against the alternative ## hypothesis that the population CDF of the data is larger that the ## standard normal CDF. load stockreturns; x = stocks(:,2); [h, p, k, c] = kstest (x, 'Tail', 'larger') ## Compute the empirical CDF and plot against the standard normal CDF [f, x_values] = ecdf (x); h1 = plot (x_values, f); hold on; h2 = plot (x_values, normcdf (x_values), 'r--'); set (h1, 'LineWidth', 2); set (h2, 'LineWidth', 2); legend ([h1, h2], 'Empirical CDF', 'Standard Normal CDF', ... 'Location', 'southeast'); title ('Empirical CDF of stock return data against standard normal CDF') ***** error kstest () ***** error kstest (ones (2, 4)) ***** error kstest ([2, 3, 5, 3+3i]) ***** error kstest ([2, 3, 4, 5, 6], 'opt', 0.51) ***** error ... kstest ([2, 3, 4, 5, 6], 'tail') ***** error ... kstest ([2,3,4,5,6],'alpha', [0.05, 0.05]) ***** error ... kstest ([2, 3, 4, 5, 6], 'alpha', NaN) ***** error ... kstest ([2, 3, 4, 5, 6], 'tail', 0) ***** error ... kstest ([2,3,4,5,6], 'tail', 'whatever') ***** error ... kstest ([1, 2, 3, 4, 5], 'CDF', @(x) repmat (x, 2, 3)) ***** error ... kstest ([1, 2, 3, 4, 5], 'CDF', 'somedist') ***** error ... kstest ([1, 2, 3, 4, 5], 'CDF', cvpartition (5, 'resubstitution')) ***** error ... kstest ([2, 3, 4, 5, 6], 'alpha', 0.05, 'CDF', [2, 3, 4; 1, 3, 4; 1, 2, 1]) ***** error ... kstest ([2, 3, 4, 5, 6], 'alpha', 0.05, 'CDF', nan (5, 2)) ***** error ... kstest ([2, 3, 4, 5, 6], 'CDF', [2, 3; 1, 4; 3, 2]) ***** error ... kstest ([2, 3, 4, 5, 6], 'CDF', [2, 3; 2, 4; 3, 5]) ***** error ... kstest ([2, 3, 4, 5, 6], 'CDF', {1, 2, 3, 4, 5}) ***** test load examgrades [h, p] = kstest (grades(:,1)); assert_equal (h, true); assert_equal (p, 7.58603305206105e-107, 1e-14); ***** test load examgrades [h, p] = kstest (grades(:,1), 'CDF', @(x) normcdf (x, 75, 10)); assert_equal (h, false); assert_equal (p, 0.5612, 1e-4); ***** test load examgrades x = grades(:,1); test_cdf = makedist ('tlocationscale', 'mu', 75, 'sigma', 10, 'nu', 1); [h, p] = kstest (x, 'alpha', 0.01, 'CDF', test_cdf); assert_equal (h, true); assert_equal (p, 0.0021, 1e-4); ***** test load stockreturns x = stocks(:,3); [h,p,k,c] = kstest (x, 'Tail', 'larger'); assert_equal (h, true); assert_equal (p, 5.085438806199252e-05, 1e-14); assert_equal (k, 0.2197, 1e-4); assert_equal (c, 0.1207, 1e-4); 21 tests, 21 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/regression_ftest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/regression_ftest.m ***** shared X, y X = [1 1; 2 1; 3 2; 4 2; 5 3; 6 3; 7 4; 8 4; 9 5; 10 5; 11 6; 12 6]; y = 2 + 3 * X(:,1) - 1.5 * X(:,2) + ... [0.2 -0.3 0.1 0.4 -0.2 0.3 -0.1 0.2 -0.4 0.1 0.3 -0.2]'; ***** test ## Every column together, as R's anova (lm (y ~ 1), lm (y ~ x1 + x2)) [h, p, st] = regression_ftest (y, X); assert_equal ([h, st.df1, st.df2], [1, 2, 9]); assert_equal ([st.fstat, p], ... [4553.7218634686296, 2.9845354551931477e-14], -1e-10); ***** test ## Dropping one column, as R's anova (lm (y ~ x1), lm (y ~ x1 + x2)) [~, p, st] = regression_ftest (y, X, 1); assert_equal ([st.fstat, p], [27.05295073929755, 0.00056311880681268267], ... -1e-10); ***** test ## Without a constant, as R's anova (lm (y ~ 0 + x1), lm (y ~ 0 + x1 + x2)) [~, p, st] = regression_ftest (y, X, 1, 'Intercept', false); assert_equal ([st.fstat, p], ... [0.0076424950016706168, 0.93206240862541445], -1e-10); ***** test [~, ~, st] = regression_ftest (y, X, 1, 'Intercept', false); assert_equal ([st.df1, st.df2], [1, 10]); ***** test [~, pa] = regression_ftest (y, X, [true, false]); [~, pb] = regression_ftest (y, X, 1); assert_equal (pa, pb); ***** test [~, ~, st] = regression_ftest (y, X, 1); assert_equal (st.betafull, [ones(12, 1), X] \ y, -1e-12); ***** test [~, ~, st] = regression_ftest (y, X, 1); assert_equal (st.betareduced, [ones(12, 1), X(:,1)] \ y, -1e-12); ***** test [~, ~, st] = regression_ftest (y, X, 1); assert_equal (st.ssefull, sumsq (y - [ones(12, 1), X] * st.betafull), ... -1e-12); ***** test ## Cohen's f^2 with lambda = f^2 (df1 + df2 + 1); the bounds are R's pf ## with ncp inverted by uniroot [~, ~, st] = regression_ftest (y, X, 1); assert_equal (st.CohensF2, 1.8219258098493329, -1e-12); ***** test [~, ~, st] = regression_ftest (y, X, 1); assert_equal (st.CohensF2CI, [0.39131195887888376, 6.1366401225022624], ... -1e-8); ***** test ## A column that adds nothing has an interval from zero [h, ~, st] = regression_ftest (X(:,1) + sin (5 * (1:12)'), X, 1); assert_equal ([h, st.CohensF2CI(1)], [0, 0]); ***** test ## 'Alpha' moves the decision but never the p-value [h1, p1] = regression_ftest (y, X, 1, 'Alpha', 1e-4); [h2, p2] = regression_ftest (y, X, 1, 'Alpha', 0.01); assert_equal ([h1, h2, p1], [0, 1, p2]); ***** test [~, pr] = regression_ftest (y', X, 1); [~, pc] = regression_ftest (y, X, 1); assert_equal (pr, pc); ***** test ## Degrees of freedom follow the ranks of the designs [~, ~, st] = regression_ftest (y, [X, X(:,1)]); assert_equal (st.df1, 2); ***** error regression_ftest (); ***** error ... regression_ftest ([1 2 3]'); ***** error ... regression_ftest ([1 2 NaN]', [2 3 4; 3 4 5]'); ***** error ... regression_ftest ([1 2 Inf]', [2 3 4; 3 4 5]'); ***** error ... regression_ftest ([1 2 3+i]', [2 3 4; 3 4 5]'); ***** error ... regression_ftest ([1 2 3]', [2 3 NaN; 3 4 5]'); ***** error ... regression_ftest ([1 2 3]', [2 3 Inf; 3 4 5]'); ***** error ... regression_ftest ([1 2 3]', [2 3 4; 3 4 3+i]'); ***** error ... regression_ftest ([1 2 3]', [2 3; 3 4]'); ***** error ... regression_ftest ([1 2; 3 4]', [2 3; 3 4]'); ***** error ... regression_ftest ((1:5)', [1:5; 2 1 4 3 5]', 1, 'Alpha'); ***** error ... regression_ftest ((1:5)', [1:5; 2 1 4 3 5]', 1, 'Alpha', 0); ***** error ... regression_ftest ((1:5)', [1:5; 2 1 4 3 5]', 1, 'Alpha', 1.2); ***** error ... regression_ftest ((1:5)', [1:5; 2 1 4 3 5]', 1, 'Alpha', [0.02, 0.1]); ***** error ... regression_ftest ((1:5)', [1:5; 2 1 4 3 5]', 1, 'Alpha', 'a'); ***** error ... regression_ftest ((1:5)', [1:5; 2 1 4 3 5]', 1, 'Intercept', 'yes'); ***** error ... regression_ftest ((1:5)', [1:5; 2 1 4 3 5]', 1, 'some', 0.05); ***** error ... regression_ftest ((1:5)', [1:5; 2 1 4 3 5]', 1, 3, 0.05); ***** error ... regression_ftest ((1:5)', [1:5; 2 1 4 3 5]', 3); ***** error ... regression_ftest ((1:5)', [1:5; 2 1 4 3 5]', 1.5); ***** error ... regression_ftest ((1:6)', [1:6; 2 1 4 3 6 5; 1 1 2 2 3 4]', [1, 1]); ***** error ... regression_ftest ((1:5)', [1:5; 2 1 4 3 5]', true); ***** error ... regression_ftest ((1:5)', [1:5; 2 1 4 3 5]', [1, 2]); ***** error ... regression_ftest ([1 2 3]', [1 2 3; 2 1 3]'); ***** error ... regression_ftest ((1:6)', [1:6; 2 1 4 3 6 5; 1:6]', [1, 2]); 39 tests, 39 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/detectdrift.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/detectdrift.m ***** shared X, Y, C, T X = [0; 1; 2; 3; 7]; Y = [1; 2; 5; 6]; C = categorical ([1; 1; 2; 3; 3; 3]); T = categorical ([1; 2; 2; 2; 3]); ***** test D = detectdrift (X, Y, 'EstimatePValues', false); assert_equal (D.MetricValues, 1.3, -1e-14); assert_equal (D.Metrics, string ('Wasserstein')); assert_equal (D.VariableNames, string ('x1')); ***** assert_equal (detectdrift (X, Y, 'EstimatePValues', false, ... 'ContinuousMetric', 'ks').MetricValues, 0.3, -1e-14) ***** assert_equal (detectdrift (X, Y, 'EstimatePValues', false, ... 'ContinuousMetric', 'AD').MetricValues, ... 0.152357142857143, -1e-13) ***** assert_equal (detectdrift (X, Y, 'EstimatePValues', false, ... 'ContinuousMetric', 'energy').MetricValues, ... 0.768114574786861, -1e-13) ***** assert_equal (detectdrift (C, T, 'EstimatePValues', false).MetricValues, ... 0.257526267734947, -1e-13) ***** assert_equal (detectdrift (C, T, 'EstimatePValues', false, ... 'CategoricalMetric', 'tv').MetricValues, ... 0.338461538461538, -1e-13) ***** assert_equal (detectdrift (C, T, 'EstimatePValues', false, ... 'CategoricalMetric', 'psi').MetricValues, ... 0.539045501736854, -1e-13) ***** assert_equal (detectdrift (C, T, 'EstimatePValues', false, ... 'CategoricalMetric', 'chi2').MetricValues, ... 0.723584108199493, -1e-13) ***** assert_equal (detectdrift (C, T, 'EstimatePValues', false, ... 'CategoricalMetric', 'bhattacharyya').MetricValues, ... 0.068621274723466, -1e-12) ***** test ## A level the target lacks leaves every metric finite T2 = categorical ([1; 2; 2; 2]); D = detectdrift (C, T2, 'EstimatePValues', false, 'CategoricalMetric', 'psi'); assert_equal (D.MetricValues, 1.131879584405866, -1e-13); D = detectdrift (C, T2, 'EstimatePValues', false, 'CategoricalMetric', 'chi2'); assert_equal (D.MetricValues, 1.265643447461629, -1e-13); D = detectdrift (C, T2, 'EstimatePValues', false); assert_equal (D.MetricValues, 0.368461885678999, -1e-13); ***** test D = detectdrift ([0, 5; 1, 3; 2, 8; 3, 1; 7, 4], [1, 9; 2, 7; 5, 8; 6, 6], ... 'EstimatePValues', false); assert_equal (D.MetricValues, [1.3, 3.3], -1e-14); assert_equal (D.VariableNames, string ({'x1', 'x2'})); ***** test TB = table ([0; 1; 2; 3; 7; 4], categorical ([1; 1; 2; 3; 3; 3]), ... 'VariableNames', {'A', 'B'}); TT = table ([1; 2; 5; 6; 3], categorical ([1; 2; 2; 2; 3]), ... 'VariableNames', {'A', 'B'}); D = detectdrift (TB, TT, 'EstimatePValues', false); assert_equal (D.MetricValues, [0.9, 0.257526267734947], -1e-13); assert_equal (D.Metrics, string ({'Wasserstein', 'Hellinger'})); assert_equal (D.CategoricalVariables, 2); ***** test D = detectdrift (X, Y, 'EstimatePValues', false); assert_equal (ismissing (D.DriftStatus), true); assert_equal (ismissing (D.MultipleTestDriftStatus), true); assert_equal (D.PValues, NaN); assert_equal (D.ConfidenceIntervals, [NaN; NaN]); assert_equal (D.NumPermutations, 1); assert_equal (D.PermutationResults.PermutationResults, {1.3}); ***** test ## A shift no permutation reaches: the observed arrangement alone counts rand ('seed', 1); x = (1:60)' / 10; D = detectdrift ([x, x], [x + 10, x([2:60, 1])]); assert_equal (D.PValues, [0.001, 1]); assert_equal (D.ConfidenceIntervals, [2.53174874912919e-05, ... 0.996317916103134; 0.00555892427982512, 1], -1e-10); assert_equal (D.DriftStatus, string ({'Drift', 'Stable'})); assert_equal (D.NumPermutations, [1000, 1000]); assert_equal (D.PermutationResults.PermutationResults{1}(1), 10, -1e-14); ***** test ## MaxNumPermutations is never passed rand ('seed', 1); x = (1:60)' / 10; D = detectdrift (x, x + 10, 'MaxNumPermutations', 50); assert_equal (D.NumPermutations, 50); assert_equal (D.PValues, 0.02); assert_equal (D.DriftStatus, string ('Warning')); ***** test ## Bonferroni takes 4 * 0.001 and the false discovery rate 0.001 rand ('seed', 1); x = (1:60)' / 10; Z = repmat (x, 1, 4); B = detectdrift (Z, Z + 10, 'DriftThreshold', 0.002, 'WarningThreshold', 0.005); assert_equal (B.MultipleTestDriftStatus, string ('Warning')); assert_equal (B.MultipleTestCorrection, string ('Bonferroni')); F = detectdrift (Z, Z + 10, 'DriftThreshold', 0.002, ... 'WarningThreshold', 0.005, 'MultipleTestCorrection', 'fdr'); assert_equal (F.MultipleTestDriftStatus, string ('Drift')); assert_equal (F.MultipleTestCorrection, string ('FalseDiscoveryRate')); ***** error detectdrift (1) ***** error detectdrift (X, Y, 'Tail', 1) ***** error ... detectdrift (X, Y, 'ContinuousMetric', 'kl') ***** error ... detectdrift (X, Y, 'CategoricalMetric', 'kl') ***** error ... detectdrift (X, Y, 'MultipleTestCorrection', 'holm') ***** error ... detectdrift (X, Y, 'DriftThreshold', 1) ***** error ... detectdrift (X, Y, 'WarningThreshold', 0) ***** error ... detectdrift (X, Y, 'DriftThreshold', 0.1, 'WarningThreshold', 0.1) ***** error ... detectdrift (X, Y, 'MaxNumPermutations', 0) ***** error ... detectdrift (X, Y, 'EstimatePValues', 'no') ***** error ... detectdrift (X, Y, 'Options', 1) ***** error ... detectdrift (X, Y, 'Options', struct ('UseParallel', true)) ***** error ... detectdrift (X, Y, 'Options', struct ('Streams', 1)) ***** error ... detectdrift (C, X) ***** error ... detectdrift ([X, X], Y) ***** error ... detectdrift (NaN, Y) 32 tests, 32 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/friedman.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/friedman.m ***** demo load popcorn; friedman (popcorn, 3); ***** demo load popcorn; [p, atab] = friedman (popcorn, 3, 'off'); disp (p); ***** test popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; [p, atab] = friedman (popcorn, 3, 'off'); assert_equal (p, 0.001028853354594794, 1e-14); assert_equal (atab(1,:), {'Source', 'SS', 'df', 'MS', 'Chi-sq', 'Prob>Chi-sq'}); assert_equal (atab{2,1}, 'Columns'); assert_equal (atab{2,2}, 99.75, 1e-14); assert_equal (atab{2,3}, 2, 0); assert_equal (atab{2,4}, 49.875, 1e-14); assert_equal (atab{2,5}, 13.75862068965517, 1e-14); assert_equal (atab{2,6}, 0.001028853354594794, 1e-14); ***** test popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; [p, atab, stats] = friedman (popcorn, 3, 'off'); assert_equal (atab{end,1}, 'Total'); assert_equal (atab{end,2}, 116, 0); assert_equal (atab{end,3}, 17, 0); assert_equal (stats.source, 'friedman'); assert_equal (stats.n, 2); assert_equal (stats.meanranks, [8, 4.75, 2.25], 0); assert_equal (stats.sigma, 2.692582403567252, 1e-14); ***** test ## every row of the table, not only Columns and Total popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; [p, atab] = friedman (popcorn, 3, 'off'); assert_equal (atab{3,1}, 'Interaction'); assert_equal (atab{3,2}, 0.083333333333258, 1e-12); assert_equal (atab{3,3}, 2, 0); assert_equal (atab{3,4}, 0.041666666666629, 1e-12); assert_equal (atab{4,1}, 'Error'); assert_equal (atab{4,2}, 16.166666666666742, 1e-12); assert_equal (atab{4,3}, 12, 0); assert_equal (atab{4,4}, 1.347222222222229, 1e-12); ***** test ## the interaction carries (c-1)(r-1) degrees of freedom popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; [p, atab] = friedman (popcorn, 3, 'off'); c = 3; r = 2; assert_equal (atab{3,3}, (c - 1) * (r - 1), 0); assert_equal (atab{2,3} + atab{3,3} + atab{4,3} < atab{5,3}, true); ***** test ## without replicates the table has no interaction row popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; [p, atab] = friedman (popcorn, 1, 'off'); assert_equal (atab(:,1), {'Source'; 'Columns'; 'Error'; 'Total'}); assert_equal (atab{2,2}, 12, 1e-12); assert_equal (atab{3,2}, 0, 1e-12); assert_equal (atab{3,3}, 10, 0); assert_equal (atab{4,3}, 17, 0); ***** test popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; s = evalc ('[p, atab] = friedman (popcorn, 3, "off");'); assert_equal (isempty (strtrim (s)), true); ***** test popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; s = evalc ('[p, atab] = friedman (popcorn, 3, "on");'); assert_equal (! isempty (strtrim (s)), true); ***** test ## the table is displayed by default, as in MATLAB and in anova1 and anova2 popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; s = evalc ('[p, atab] = friedman (popcorn, 3);'); assert_equal (! isempty (strtrim (s)), true); ***** test popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; [p, atab] = friedman (popcorn, 3, 'off'); assert_equal (size (atab), [5, 6], 0); assert_equal (iscell (atab), true); assert_equal (isempty (atab{end,4}), true); ***** test x = [1, 2, 3; 2, 1, 3; 3, 2, 1]; [p, atab] = friedman (x, 1, 'off'); assert_equal (size (atab), [4, 6], 0); assert_equal (atab{3,1}, 'Error'); assert_equal (isempty (atab{2,5}), false); ***** test ## Below the resolution of 1 - chi2cdf, values from MATLAB R2024a q = (1:60)'; p = friedman ([q, q + 100, q + 200], 1, 'off'); assert_equal (p, 8.75651076269649e-27, -1e-10); ***** test x = [1, 2, 3, 4; 2, 2, 3, 1; 4, 3, 2, 1; 1, 3, 3, 4; 2, 1, 4, 3; 3, 3, 1, 2]; [~, ~, stats] = friedman (x, 1, 'off'); assert_equal (stats.KendallsW, 0.02046783625730994, -1e-13); ## Q falls below the upper 2.5% point of the central distribution, so the ## lower bound is the expected W of no effect, (c - 1) / (b (c - 1)) assert_equal (stats.KendallsWCI(1), 1 / 6, -1e-14); ***** test x = [1, 2, 3, 4; 1, 3, 2, 4; 2, 1, 3, 4; 1, 2, 4, 3; 1, 2, 3, 4]; [~, tbl, stats] = friedman (x, 1, 'off'); assert_equal (stats.KendallsW, 0.776, -1e-14); lambda = stats.KendallsWCI(1) * 15 - 3; assert_equal (ncx2cdf (tbl{2,5}, 3, lambda), 0.975, -1e-10); assert_equal (stats.KendallsWCI(2), 1); ***** test load popcorn; [~, tbl, stats] = friedman (popcorn, 3, 'off'); assert_equal (stats.KendallsW, tbl{2,5} / (2 * 9 * 8 / 10), -1e-14); ***** test rand ('state', 1); x = [1, 2, 3, 4; 1, 3, 2, 4; 2, 1, 3, 4; 1, 2, 4, 3; 1, 2, 3, 4; ... 2, 1, 3, 4; 1, 2, 3, 4; 1, 3, 2, 4]; [~, ~, stats] = friedman (x, 1, 'off', 'ConfidenceIntervalType', ... 'bootstrap', 'NumBootstraps', 200); ci = stats.KendallsWCI; assert_equal ([ci(1) <= ci(2), ci(1) >= 0, ci(2) <= 1], true (1, 3)); ***** error ... friedman ([5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; 6.5, 5.0, 4.0; ... 7.0, 5.5, 5.0; 7.0, 5.0, 4.5], 3, 'invalid_displayopt'); ***** error ... friedman ([1, 2; NaN, 4]); ***** error ... friedman ([1,2; 3,4; 5,6], 2); ***** error ... friedman ([1, 2; 3, 4; 5, 6], 1, 'off', 'Foo', 1) ***** error ... friedman ([1, 2; 3, 4; 5, 6], 1, 'off', 'Alpha', 0) ***** error ... friedman ([1, 2; 3, 4; 5, 6], 1, 'off', 'ConfidenceIntervalType', 'none') ***** error ... friedman ([1, 2; 3, 4; 5, 6], 1, 'off', 'NumBootstraps', -1) 22 tests, 22 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/ttest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/ttest.m ***** test x = 8:0.1:12; [h, pval, ci] = ttest (x, 10); assert_equal (h, 0) assert_equal (pval, 1, 10*eps) assert_equal (ci, [9.6219 10.3781], 1E-5) [h, pval, ci0] = ttest (x, 0); assert_equal (h, 1) assert_equal (pval, 7.99598458174846e-39, -1e-13) # MATLAB R2024a assert_equal (ci0, ci, 2e-15) [h, pval, ci] = ttest (x, 10, 'tail', 'right', 'dim', 2, 'alpha', 0.05); assert_equal (h, 0) assert_equal (pval, 0.5, 10*eps) assert_equal (ci, [9.68498 Inf], 1E-5) ***** test ## Below the resolution of 1 - tcdf, values from MATLAB R2024a [~, pval] = ttest (10 + sin (1:30)'); assert_equal (pval, 9.53562250074996e-35, -1e-13); ***** test [~, pval] = ttest (10 + sin (1:30)', 0, 'tail', 'right'); assert_equal (pval, 4.76781125037498e-35, -1e-13); ***** error ttest ([8:0.1:12], 10, 'tail', 'invalid'); ***** error ttest ([8:0.1:12], 10, 'tail', 25); ***** shared x, xm x = [10.2 9.7 11.1 10.5 9.9 10.8 10.1 9.6 10.4 10.7]; xm = [10.2 11.4; 9.7 10.9; 11.1 12.6; 10.5 11.1; 9.9 13.2]; ***** test [h, p, ci] = ttest (x, 10, 'Tail', 'left'); assert_equal (h, 0); assert_equal (p, 0.957607393606414, 1e-14); assert_equal (ci, [-Inf, 10.583984634395803], 1e-13); ***** test [h, p, ci] = ttest (x, 10, 'Tail', 'right'); assert_equal (h, 1); assert_equal (p, 0.042392606393586, 1e-14); assert_equal (ci, [10.016015365604199, Inf], 1e-13); ***** test ## a non-default alpha must actually widen the interval [~, p1, ci1] = ttest (x, 10); [~, p2, ci2] = ttest (x, 10, 'Alpha', 0.01); assert_equal (ci1, [9.949548119279150, 10.650451880720851], 1e-13); assert_equal (ci2, [9.796537642780031, 10.803462357219971], 1e-13); assert_equal (diff (ci2) > diff (ci1), true); assert_equal (p1, p2, 0); ***** test ## the fourth output was never exercised [~, ~, ~, stats] = ttest (x, 10); assert_equal (stats.tstat, 1.936491673103713, 1e-13); assert_equal (stats.df, 9); assert_equal (stats.sd, 0.489897948556636, 1e-14); ***** test [h, p] = ttest (xm, 10, 'Dim', 1); assert_equal (h, [0, 1]); assert_equal (p, [0.318172286240873, 0.015001169519765], 1e-13); ***** test [h, p] = ttest (xm, 10, 'Dim', 2); assert_equal (h(:)', [0, 0, 0, 0, 0]); assert_equal (p(:)', [0.409665529398267, 0.704832764699133, ... 0.245198884026780, 0.228400502439816, ... 0.519887895647178], 1e-13); ***** error ... ttest ([8:0.1:12], 10, 'Alpha', -0.05); ***** error ... ttest ([8:0.1:12], 10, 'Alpha', 0); ***** error ... ttest ([8:0.1:12], 10, 'Alpha', 1); ***** error ... ttest ([8:0.1:12], 10, 'Alpha', 1.5); ***** error ... ttest ([8:0.1:12], 10, 'Alpha', [0.01, 0.05]); ***** error ... ttest ([8:0.1:12], 10, 'Alpha', 'a'); ***** error ... ttest ([8:0.1:12], 10, 'Alpha', NaN); ***** error ... ttest ([8:0.1:12], 10, 'Alpha', 2 + 1i); 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/hotelling_t2test2.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/hotelling_t2test2.m ***** test ## Below the resolution of 1 - fcdf u = (1:30)'; [~, p, st] = hotelling_t2test2 ([u, sin(u)], [u + 100, sin(u)]); F = (30 + 30 - 2 - 1) * st.t2stat / (2 * (30 + 30 - 2)); d1 = st.df1; d2 = st.df2; assert_equal (p, betainc (d2 / (d2 + d1 * F), d2 / 2, d1 / 2), -1e-12); ***** test u = (1:30)'; [~, ~, st] = hotelling_t2test2 ([u / 30, sin(u)], ... [u / 30 + 0.2, sin(u) + 0.3]); assert_equal (st.MahalanobisD, 0.73996501021719263, -1e-12); ***** test ## The bounds are those of R's pf with ncp, inverted by uniroot u = (1:30)'; [~, ~, st] = hotelling_t2test2 ([u / 30, sin(u)], ... [u / 30 + 0.2, sin(u) + 0.3]); assert_equal (st.MahalanobisDCI, ... [0.22898023040240645, 1.3346946250293135], -1e-8); ***** error hotelling_t2test2 (); ***** error ... hotelling_t2test2 ([2, 3, 4, 5, 6]); ***** error ... hotelling_t2test2 (1, [2, 3, 4, 5, 6]); ***** error ... hotelling_t2test2 (ones (2,2,2), [2, 3, 4, 5, 6]); ***** error ... hotelling_t2test2 ([2, 3, 4, 5, 6], 2); ***** error ... hotelling_t2test2 ([2, 3, 4, 5, 6], ones (2,2,2)); ***** error ... hotelling_t2test2 (ones (20,2), ones (20,2), 'alpha', 1); ***** error ... hotelling_t2test2 (ones (20,2), ones (20,2), 'alpha', -0.2); ***** error ... hotelling_t2test2 (ones (20,2), ones (20,2), 'alpha', 'a'); ***** error ... hotelling_t2test2 (ones (20,2), ones (20,2), 'alpha', [0.01, 0.05]); ***** error ... hotelling_t2test2 (ones (20,2), ones (20,2), 'name', 0.01); ***** error ... hotelling_t2test2 (ones (20,1), ones (20,2)); ***** error ... hotelling_t2test2 (ones (20,2), ones (25,3)); ***** test randn ('seed', 1); x1 = randn (60000, 5); randn ('seed', 5); x2 = randn (30000, 5); [h, pval, stats] = hotelling_t2test2 (x1, x2); assert_equal (h, 0); assert_equal (stats.df1, 5); assert_equal (stats.df2, 89994); 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/runstest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/runstest.m ***** test ## NIST beam deflection data ## http://www.itl.nist.gov/div898/handbook/eda/section4/eda425.htm data = [-213, -564, -35, -15, 141, 115, -420, -360, 203, -338, -431, ... 194, -220, -513, 154, -125, -559, 92, -21, -579, -52, 99, -543, ... -175, 162, -457, -346, 204, -300, -474, 164, -107, -572, -8, 83, ... -541, -224, 180, -420, -374, 201, -236, -531, 83, 27, -564, -112, ... 131, -507, -254, 199, -311, -495, 143, -46, -579, -90, 136, ... -472, -338, 202, -287, -477, 169, -124, -568, 17, 48, -568, -135, ... 162, -430, -422, 172, -74, -577, -13, 92, -534, -243, 194, -355, ... -465, 156, -81, -578, -64, 139, -449, -384, 193, -198, -538, 110, ... -44, -577, -6, 66, -552, -164, 161, -460, -344, 205, -281, -504, ... 134, -28, -576, -118, 156, -437, -381, 200, -220, -540, 83, 11, ... -568, -160, 172, -414, -408, 188, -125, -572, -32, 139, -492, ... -321, 205, -262, -504, 142, -83, -574, 0, 48, -571, -106, 137, ... -501, -266, 190, -391, -406, 194, -186, -553, 83, -13, -577, -49, ... 103, -515, -280, 201, 300, -506, 131, -45, -578, -80, 138, -462, ... -361, 201, -211, -554, 32, 74, -533, -235, 187, -372, -442, 182, ... -147, -566, 25, 68, -535, -244, 194, -351, -463, 174, -125, -570, ... 15, 72, -550, -190, 172, -424, -385, 198, -218, -536, 96]; [h, p, stats] = runstest (data, median (data)); expected_h = 1; expected_p = 0.008562; expected_z = 2.6229; assert_equal (h, expected_h); assert_equal (p, expected_p, 1E-6); assert_equal (stats.z, expected_z, 1E-4); ***** shared x x = [45, -60, 1.225, 55.4, -9 27]; ***** test [h, p, stats] = runstest (x); assert_equal (h, 0); assert_equal (p, 0.6, 1e-14); assert_equal (stats.nruns, 5); assert_equal (stats.n1, 3); assert_equal (stats.n0, 3); assert_equal (stats.z, 0.456435464587638, 1e-14); ***** test ## Edge cases with empty arrays [h, p, s] = runstest ([]); assert_equal (h, 0); assert_equal (p, 1); assert_equal (isnan (s.nruns), true); assert_equal (s.n1, 0); assert_equal (s.n0, 0); assert_equal (isnan (s.z), true); ***** test [h, p, s] = runstest (zeros (0, 3)); assert_equal (h, 0); assert_equal (p, 1); assert_equal (isnan (s.nruns), true); assert_equal (s.n1, 0); assert_equal (s.n0, 0); assert_equal (isnan (s.z), true); ***** test [h, p, stats] = runstest (x, [], 'method', 'approximate'); assert_equal (h, 0); assert_equal (p, 0.6481, 1e-4); assert_equal (stats.z, 0.456435464587638, 1e-14); ***** test [h, p, stats] = runstest (x, [], 'tail', 'left'); assert_equal (h, 0); assert_equal (p, 0.9, 1e-14); assert_equal (stats.z, 1.369306393762915, 1e-14); ***** error runstest (ones (2,20)) ***** error runstest (['asdasda']) ***** error runstest ('') ***** error ... runstest ([2 3 4 3 2 3 4], 'updown') ***** error ... runstest ([2 3 4 3 2 3 4], [], 'alpha', 0) ***** error ... runstest ([2 3 4 3 2 3 4], [], 'alpha', [0.02 0.2]) ***** error ... runstest ([2 3 4 3 2 3 4], [], 'alpha', 1.2) ***** error ... runstest ([2 3 4 3 2 3 4], [], 'alpha', -0.05) ***** error ... runstest ([2 3 4 3 2 3 4], [], 'method', 'some') ***** error ... runstest ([2 3 4 3 2 3 4], [], 'tail', 'some') ***** error ... runstest ([2 3 4 3 2 3 4], [], 'option', 'some') 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/multcompare.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/multcompare.m ***** demo ## Demonstration using balanced one-way ANOVA from anova1 rng (42); randg ('state', 42); x = ones (50, 4) .* [-2, 0, 1, 5]; x = x + normrnd (0, 2, 50, 4); groups = {'A', 'B', 'C', 'D'}; [p, tbl, stats] = anova1 (x, groups, 'off'); multcompare (stats); ***** demo ## Demonstration using unbalanced one-way ANOVA example from anovan dv = [ 8.706 10.362 11.552 6.941 10.983 10.092 6.421 14.943 15.931 ... 22.968 18.590 16.567 15.944 21.637 14.492 17.965 18.851 22.891 ... 22.028 16.884 17.252 18.325 25.435 19.141 21.238 22.196 18.038 ... 22.628 31.163 26.053 24.419 32.145 28.966 30.207 29.142 33.212 ... 25.694 ]'; g = [1 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 ... 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5]'; [P,ATAB, STATS] = anovan (dv, g, 'varnames', 'score', 'display', 'off'); [C, M, H, GNAMES] = multcompare (STATS, 'dim', 1, 'ctype', 'holm', ... 'ControlGroup', 1, 'display', 'on') ***** demo ## Demonstration using factorial ANCOVA example from anovan score = [95.6 82.2 97.2 96.4 81.4 83.6 89.4 83.8 83.3 85.7 ... 97.2 78.2 78.9 91.8 86.9 84.1 88.6 89.8 87.3 85.4 ... 81.8 65.8 68.1 70.0 69.9 75.1 72.3 70.9 71.5 72.5 ... 84.9 96.1 94.6 82.5 90.7 87.0 86.8 93.3 87.6 92.4 ... 100. 80.5 92.9 84.0 88.4 91.1 85.7 91.3 92.3 87.9 ... 91.7 88.6 75.8 75.7 75.3 82.4 80.1 86.0 81.8 82.5]'; treatment = {'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' ... 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' ... 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' ... 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' ... 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' ... 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no' 'no'}'; exercise = {'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' ... 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' ... 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' ... 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' 'lo' ... 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' 'mid' ... 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi'}'; age = [59 65 70 66 61 65 57 61 58 55 62 61 60 59 55 57 60 63 62 57 ... 58 56 57 59 59 60 55 53 55 58 68 62 61 54 59 63 60 67 60 67 ... 75 54 57 62 65 60 58 61 65 57 56 58 58 58 52 53 60 62 61 61]'; [P, ATAB, STATS] = anovan (score, {treatment, exercise, age}, 'model', ... [1 0 0; 0 1 0; 0 0 1; 1 1 0], 'continuous', 3, ... 'sstype', 'h', 'display', 'off', 'contrasts', ... {'simple','poly',''}); [C, M, H, GNAMES] = multcompare (STATS, 'dim', [1 2], 'ctype', 'holm', ... 'display', 'on') ***** demo ## Demonstration using one-way ANOVA from anovan, with fit by weighted least ## squares to account for heteroskedasticity. g = [1, 1, 1, 1, 1, 1, 1, 1, ... 2, 2, 2, 2, 2, 2, 2, 2, ... 3, 3, 3, 3, 3, 3, 3, 3]'; y = [13, 16, 16, 7, 11, 5, 1, 9, ... 10, 25, 66, 43, 47, 56, 6, 39, ... 11, 39, 26, 35, 25, 14, 24, 17]'; [P,ATAB,STATS] = anovan (y, g, 'display', 'off'); fitted = STATS.X * STATS.coeffs(:,1); # fitted values b = polyfit (fitted, abs (STATS.resid), 1); v = polyval (b, fitted); # Variance as a function of the fitted values [P,ATAB,STATS] = anovan (y, g, 'weights', v.^-1, 'display', 'off'); [C, M] = multcompare (STATS, 'display', 'on', 'ctype', 'mvt') ***** demo ## Demonstration of p-value adjustments to control the false discovery rate ## Data from Westfall (1997) JASA. 92(437):299-306 p = [.005708; .023544; .024193; .044895; ... .048805; .221227; .395867; .693051; .775755]; padj = multcompare (p,'ctype','fdr') ***** test ## Tests using unbalanced one-way ANOVA example from anovan and anova1 ## Test for anovan - compare pairwise comparisons with matlab for CTYPE "lsd" dv = [ 8.706 10.362 11.552 6.941 10.983 10.092 6.421 14.943 15.931 ... 22.968 18.590 16.567 15.944 21.637 14.492 17.965 18.851 22.891 ... 22.028 16.884 17.252 18.325 25.435 19.141 21.238 22.196 18.038 ... 22.628 31.163 26.053 24.419 32.145 28.966 30.207 29.142 33.212 ... 25.694 ]'; g = [1 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 ... 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5]'; [P, ATAB, STATS] = anovan (dv, g, 'varnames', 'score', 'display', 'off'); [C, M, H, GNAMES] = multcompare (STATS, 'dim', 1, 'ctype', 'lsd', ... 'display', 'off'); assert_equal (C(1,6), 2.85812420217898e-05, 1e-09); assert_equal (C(2,6), 5.22936741204085e-07, 1e-09); assert_equal (C(3,6), 2.12794763209146e-08, 1e-09); assert_equal (C(4,6), 7.82091664406946e-15, 1e-09); assert_equal (C(5,6), 0.546591417210693, 1e-09); assert_equal (C(6,6), 0.0845897945254446, 1e-09); assert_equal (C(7,6), 9.47436557975328e-08, 1e-09); assert_equal (C(8,6), 0.188873478781067, 1e-09); assert_equal (C(9,6), 4.08974010364197e-08, 1e-09); assert_equal (C(10,6), 4.44427348175241e-06, 1e-09); assert_equal (M(1,1), 10, 1e-09); assert_equal (M(2,1), 18, 1e-09); assert_equal (M(3,1), 19, 1e-09); assert_equal (M(4,1), 21.0001428571429, 1e-09); assert_equal (M(5,1), 29.0001111111111, 1e-09); assert_equal (M(1,2), 1.0177537954095, 1e-09); assert_equal (M(2,2), 1.28736803631001, 1e-09); assert_equal (M(3,2), 1.0177537954095, 1e-09); assert_equal (M(4,2), 1.0880245732889, 1e-09); assert_equal (M(5,2), 0.959547480416536, 1e-09); ## Compare "fdr" adjusted p-values to those obtained using p.adjust in R [C, M, H, GNAMES] = multcompare (STATS, 'dim', 1, 'ctype', 'fdr', ... 'display', 'off'); assert_equal (C(1,6), 4.08303457454140e-05, 1e-09); assert_equal (C(2,6), 1.04587348240817e-06, 1e-09); assert_equal (C(3,6), 1.06397381604573e-07, 1e-09); assert_equal (C(4,6), 7.82091664406946e-14, 1e-09); assert_equal (C(5,6), 5.46591417210693e-01, 1e-09); assert_equal (C(6,6), 1.05737243156806e-01, 1e-09); assert_equal (C(7,6), 2.36859139493832e-07, 1e-09); assert_equal (C(8,6), 2.09859420867852e-01, 1e-09); assert_equal (C(9,6), 1.36324670121399e-07, 1e-09); assert_equal (C(10,6), 7.40712246958735e-06, 1e-09); ## Compare "hochberg" adjusted p-values to those obtained using p.adjust in R [C, M, H, GNAMES] = multcompare (STATS, 'dim', 1, 'ctype', 'hochberg', ... 'display', 'off'); assert_equal (C(1,6), 1.14324968087159e-04, 1e-09); assert_equal (C(2,6), 3.13762044722451e-06, 1e-09); assert_equal (C(3,6), 1.91515286888231e-07, 1e-09); assert_equal (C(4,6), 7.82091664406946e-14, 1e-09); assert_equal (C(5,6), 5.46591417210693e-01, 1e-09); assert_equal (C(6,6), 2.53769383576334e-01, 1e-09); assert_equal (C(7,6), 6.63205590582730e-07, 1e-09); assert_equal (C(8,6), 3.77746957562134e-01, 1e-09); assert_equal (C(9,6), 3.27179208291358e-07, 1e-09); assert_equal (C(10,6), 2.22213674087620e-05, 1e-09); ## Compare "holm" adjusted p-values to those obtained using p.adjust in R [C, M, H, GNAMES] = multcompare (STATS, 'dim', 1, 'ctype', 'holm', ... 'display', 'off'); assert_equal (C(1,6), 1.14324968087159e-04, 1e-09); assert_equal (C(2,6), 3.13762044722451e-06, 1e-09); assert_equal (C(3,6), 1.91515286888231e-07, 1e-09); assert_equal (C(4,6), 7.82091664406946e-14, 1e-09); assert_equal (C(5,6), 5.46591417210693e-01, 1e-09); assert_equal (C(6,6), 2.53769383576334e-01, 1e-09); assert_equal (C(7,6), 6.63205590582730e-07, 1e-09); assert_equal (C(8,6), 3.77746957562134e-01, 1e-09); assert_equal (C(9,6), 3.27179208291358e-07, 1e-09); assert_equal (C(10,6), 2.22213674087620e-05, 1e-09); ## Compare "scheffe" adjusted p-values to those obtained using 'scheffe' in Matlab [C, M, H, GNAMES] = multcompare (STATS, 'dim', 1, 'ctype', 'scheffe', ... 'display', 'off'); assert_equal (C(1,6), 0.00108105386141085, 1e-09); assert_equal (C(2,6), 2.7779386789517e-05, 1e-09); assert_equal (C(3,6), 1.3599854038198e-06, 1e-09); assert_equal (C(4,6), 7.58830197867751e-13, 1e-09); assert_equal (C(5,6), 0.984039948220281, 1e-09); assert_equal (C(6,6), 0.539077018557706, 1e-09); assert_equal (C(7,6), 5.59475764460574e-06, 1e-09); assert_equal (C(8,6), 0.771173490574105, 1e-09); assert_equal (C(9,6), 2.52838425729905e-06, 1e-09); assert_equal (C(10,6), 0.000200719143889168, 1e-09); ## Compare "bonferroni" adjusted p-values to those obtained using p.adjust in R [C, M, H, GNAMES] = multcompare (STATS, 'dim', 1, 'ctype', 'bonferroni', ... 'display', 'off'); assert_equal (C(1,6), 2.85812420217898e-04, 1e-09); assert_equal (C(2,6), 5.22936741204085e-06, 1e-09); assert_equal (C(3,6), 2.12794763209146e-07, 1e-09); assert_equal (C(4,6), 7.82091664406946e-14, 1e-09); assert_equal (C(5,6), 1.00000000000000e+00, 1e-09); assert_equal (C(6,6), 8.45897945254446e-01, 1e-09); assert_equal (C(7,6), 9.47436557975328e-07, 1e-09); assert_equal (C(8,6), 1.00000000000000e+00, 1e-09); assert_equal (C(9,6), 4.08974010364197e-07, 1e-09); assert_equal (C(10,6), 4.44427348175241e-05, 1e-09); ## Test for anova1 ("equal")- comparison of results from Matlab [P, ATAB, STATS] = anova1 (dv, g, 'off', 'equal'); [C, M, H, GNAMES] = multcompare (STATS, 'ctype', 'lsd', 'display', 'off'); assert_equal (C(1,6), 2.85812420217898e-05, 1e-09); assert_equal (C(2,6), 5.22936741204085e-07, 1e-09); assert_equal (C(3,6), 2.12794763209146e-08, 1e-09); assert_equal (C(4,6), 7.82091664406946e-15, 1e-09); assert_equal (C(5,6), 0.546591417210693, 1e-09); assert_equal (C(6,6), 0.0845897945254446, 1e-09); assert_equal (C(7,6), 9.47436557975328e-08, 1e-09); assert_equal (C(8,6), 0.188873478781067, 1e-09); assert_equal (C(9,6), 4.08974010364197e-08, 1e-09); assert_equal (C(10,6), 4.44427348175241e-06, 1e-09); assert_equal (M(1,1), 10, 1e-09); assert_equal (M(2,1), 18, 1e-09); assert_equal (M(3,1), 19, 1e-09); assert_equal (M(4,1), 21.0001428571429, 1e-09); assert_equal (M(5,1), 29.0001111111111, 1e-09); assert_equal (M(1,2), 1.0177537954095, 1e-09); assert_equal (M(2,2), 1.28736803631001, 1e-09); assert_equal (M(3,2), 1.0177537954095, 1e-09); assert_equal (M(4,2), 1.0880245732889, 1e-09); assert_equal (M(5,2), 0.959547480416536, 1e-09); ## Test for anova1 ("unequal") - comparison with results from GraphPad Prism 8 [P, ATAB, STATS] = anova1 (dv, g, 'off', 'unequal'); [C, M, H, GNAMES] = multcompare (STATS, 'ctype', 'lsd', 'display', 'off'); assert_equal (C(1,6), 0.001247025266382, 1e-09); assert_equal (C(2,6), 0.000018037115146, 1e-09); assert_equal (C(3,6), 0.000002974595187, 1e-09); assert_equal (C(4,6), 0.000000000786046, 1e-09); assert_equal (C(5,6), 0.5693192886650109, 1e-09); assert_equal (C(6,6), 0.110501699029776, 1e-09); assert_equal (C(7,6), 0.000131226488700, 1e-09); assert_equal (C(8,6), 0.1912101409715992, 1e-09); assert_equal (C(9,6), 0.000005385256394, 1e-09); assert_equal (C(10,6), 0.000074089106171, 1e-09); ***** test ## Test for anova2 ("interaction") - comparison with results from Matlab for column effect popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; [P, ATAB, STATS] = anova2 (popcorn, 3, 'off'); [C, M, H, GNAMES] = multcompare (STATS, 'estimate', 'column',... 'ctype', 'lsd', 'display', 'off'); assert_equal (C(1,6), 1.49311100811177e-05, 1e-09); assert_equal (C(2,6), 2.20506904243535e-07, 1e-09); assert_equal (C(3,6), 0.00449897860490058, 1e-09); assert_equal (M(1,1), 6.25, 1e-09); assert_equal (M(2,1), 4.75, 1e-09); assert_equal (M(3,1), 4, 1e-09); assert_equal (M(1,2), 0.152145154862547, 1e-09); assert_equal (M(2,2), 0.152145154862547, 1e-09); assert_equal (M(3,2), 0.152145154862547, 1e-09); ***** test ## Test for anova2 ("linear") - comparison with results from GraphPad Prism 8 words = [10 13 13; 6 8 8; 11 14 14; 22 23 25; 16 18 20; ... 15 17 17; 1 1 4; 12 15 17; 9 12 12; 8 9 12]; [P, ATAB, STATS] = anova2 (words, 1, 'off', 'linear'); [C, M, H, GNAMES] = multcompare (STATS, 'estimate', 'column',... 'ctype', 'lsd', 'display', 'off'); assert_equal (C(1,6), 0.000020799832702, 1e-09); assert_equal (C(2,6), 0.000000035812410, 1e-09); assert_equal (C(3,6), 0.003038942449215, 1e-09); ***** test ## Test for anova2 ("nested") - comparison with results from GraphPad Prism 8 data = [4.5924 7.3809 21.322; -0.5488 9.2085 25.0426; ... 6.1605 13.1147 22.66; 2.3374 15.2654 24.1283; ... 5.1873 12.4188 16.5927; 3.3579 14.3951 10.2129; ... 6.3092 8.5986 9.8934; 3.2831 3.4945 10.0203]; [P, ATAB, STATS] = anova2 (data, 4, 'off', 'nested'); [C, M, H, GNAMES] = multcompare (STATS, 'estimate', 'column',... 'ctype', 'lsd', 'display', 'off'); assert_equal (C(1,6), 0.261031111511073, 1e-09); assert_equal (C(2,6), 0.065879755907745, 1e-09); assert_equal (C(3,6), 0.241874613529270, 1e-09); ***** shared visibility_setting visibility_setting = get (0, 'DefaultFigureVisible'); ***** test set (0, 'DefaultFigureVisible', 'off'); ## Test for kruskalwallis - comparison with results from MATLAB data = [3,2,4; 5,4,4; 4,2,4; 4,2,4; 4,1,5; ... 4,2,3; 4,3,5; 4,2,4; 5,2,4; 5,3,3]; group = [1:3] .* ones (10,3); [P, ATAB, STATS] = kruskalwallis (data(:), group(:), 'off'); C = multcompare (STATS, 'ctype', 'lsd', 'display', 'off'); assert_equal (C(1,6), 0.000163089828959986, 1e-09); assert_equal (C(2,6), 0.630298044801257, 1e-09); assert_equal (C(3,6), 0.00100567660695682, 1e-09); C = multcompare (STATS, 'ctype', 'bonferroni', 'display', 'off'); assert_equal (C(1,6), 0.000489269486879958, 1e-09); assert_equal (C(2,6), 1, 1e-09); assert_equal (C(3,6), 0.00301702982087047, 1e-09); C = multcompare (STATS, 'ctype', 'scheffe', 'display', 'off'); assert_equal (C(1,6), 0.000819054880289573, 1e-09); assert_equal (C(2,6), 0.890628039849261, 1e-09); assert_equal (C(3,6), 0.00447816059021654, 1e-09); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); ## Test for friedman - comparison with results from MATLAB popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; [P, ATAB, STATS] = friedman (popcorn, 3, 'off'); C = multcompare (STATS, 'ctype', 'lsd', 'display', 'off'); assert_equal (C(1,6), 0.227424558028569, 1e-09); assert_equal (C(2,6), 0.0327204848315735, 1e-09); assert_equal (C(3,6), 0.353160353315988, 1e-09); C = multcompare (STATS, 'ctype', 'bonferroni', 'display', 'off'); assert_equal (C(1,6), 0.682273674085708, 1e-09); assert_equal (C(2,6), 0.0981614544947206, 1e-09); assert_equal (C(3,6), 1, 1e-09); C = multcompare (STATS, 'ctype', 'scheffe', 'display', 'off'); assert_equal (C(1,6), 0.482657360384373, 1e-09); assert_equal (C(2,6), 0.102266573027672, 1e-09); assert_equal (C(3,6), 0.649836502233148, 1e-09); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); ## Test for anovan with 'simple' contrasts - same comparisons as for first anovan example y = [ 8.706 10.362 11.552 6.941 10.983 10.092 6.421 14.943 15.931 ... 22.968 18.590 16.567 15.944 21.637 14.492 17.965 18.851 22.891 ... 22.028 16.884 17.252 18.325 25.435 19.141 21.238 22.196 18.038 ... 22.628 31.163 26.053 24.419 32.145 28.966 30.207 29.142 33.212 ... 25.694 ]'; X = [1 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5]'; [P, ATAB, STATS] = anovan (y, {X}, 'contrasts', 'simple', 'display', 'off'); [C, M] = multcompare (STATS, 'ctype', 'lsd', 'display', 'off'); assert_equal (C(1,6), 2.85812420217898e-05, 1e-09); assert_equal (C(2,6), 5.22936741204085e-07, 1e-09); assert_equal (C(3,6), 2.12794763209146e-08, 1e-09); assert_equal (C(4,6), 7.82091664406946e-15, 1e-09); assert_equal (C(5,6), 0.546591417210693, 1e-09); assert_equal (C(6,6), 0.0845897945254446, 1e-09); assert_equal (C(7,6), 9.47436557975328e-08, 1e-09); assert_equal (C(8,6), 0.188873478781067, 1e-09); assert_equal (C(9,6), 4.08974010364197e-08, 1e-09); assert_equal (C(10,6), 4.44427348175241e-06, 1e-09); assert_equal (M(1,1), 10, 1e-09); assert_equal (M(2,1), 18, 1e-09); assert_equal (M(3,1), 19, 1e-09); assert_equal (M(4,1), 21.0001428571429, 1e-09); assert_equal (M(5,1), 29.0001111111111, 1e-09); assert_equal (M(1,2), 1.0177537954095, 1e-09); assert_equal (M(2,2), 1.28736803631001, 1e-09); assert_equal (M(3,2), 1.0177537954095, 1e-09); assert_equal (M(4,2), 1.0880245732889, 1e-09); assert_equal (M(5,2), 0.959547480416536, 1e-09); set (0, 'DefaultFigureVisible', visibility_setting); ***** test ## Test p-value adjustments compared to R stats package function p.adjust ## Data from Westfall (1997) JASA. 92(437):299-306 p = [.005708; .023544; .024193; .044895; ... .048805; .221227; .395867; .693051; .775755]; padj = multcompare (p); assert_equal (padj(1), 0.051372, 1e-06); assert_equal (padj(2), 0.188352, 1e-06); assert_equal (padj(3), 0.188352, 1e-06); assert_equal (padj(4), 0.269370, 1e-06); assert_equal (padj(5), 0.269370, 1e-06); assert_equal (padj(6), 0.884908, 1e-06); assert_equal (padj(7), 1.000000, 1e-06); assert_equal (padj(8), 1.000000, 1e-06); assert_equal (padj(9), 1.000000, 1e-06); padj = multcompare (p,'ctype','holm'); assert_equal (padj(1), 0.051372, 1e-06); assert_equal (padj(2), 0.188352, 1e-06); assert_equal (padj(3), 0.188352, 1e-06); assert_equal (padj(4), 0.269370, 1e-06); assert_equal (padj(5), 0.269370, 1e-06); assert_equal (padj(6), 0.884908, 1e-06); assert_equal (padj(7), 1.000000, 1e-06); assert_equal (padj(8), 1.000000, 1e-06); assert_equal (padj(9), 1.000000, 1e-06); padj = multcompare (p,'ctype','hochberg'); assert_equal (padj(1), 0.051372, 1e-06); assert_equal (padj(2), 0.169351, 1e-06); assert_equal (padj(3), 0.169351, 1e-06); assert_equal (padj(4), 0.244025, 1e-06); assert_equal (padj(5), 0.244025, 1e-06); assert_equal (padj(6), 0.775755, 1e-06); assert_equal (padj(7), 0.775755, 1e-06); assert_equal (padj(8), 0.775755, 1e-06); assert_equal (padj(9), 0.775755, 1e-06); padj = multcompare (p,'ctype','fdr'); assert_equal (padj(1), 0.0513720, 1e-07); assert_equal (padj(2), 0.0725790, 1e-07); assert_equal (padj(3), 0.0725790, 1e-07); assert_equal (padj(4), 0.0878490, 1e-07); assert_equal (padj(5), 0.0878490, 1e-07); assert_equal (padj(6), 0.3318405, 1e-07); assert_equal (padj(7), 0.5089719, 1e-07); assert_equal (padj(8), 0.7757550, 1e-07); assert_equal (padj(9), 0.7757550, 1e-07); ***** test ## Below the resolution of 1 - tcdf, values from MATLAB R2024a [~, ~, stats] = anova1 ([1:10, 101:110, 201:210]', ... kron ((1:3)', ones (10, 1)), 'off'); C = multcompare (stats, 'CriticalValueType', 'lsd', 'Display', 'off'); assert_equal (C(:,6), [1.07511774090732e-32; 8.40615185462431e-41; ... 1.07511774090732e-32], -1e-13); ***** test ## Scheffe below the resolution of 1 - fcdf, values from MATLAB R2024a w = [1:10, 101:110, 201:210]'; g = kron ((1:3)', ones (10, 1)); [~, ~, st] = anova1 (w, g, 'off'); C = multcompare (st, 'CriticalValueType', 'scheffe', 'Display', 'off'); assert_equal (C(:,6), [7.05050215176788e-32; 5.522164708181e-40; ... 7.05050215176788e-32], -1e-10); 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/fishertest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/fishertest.m ***** demo ## A Fisher's exact test example x = [3, 1; 1, 3] [h, p, stats] = fishertest (x) ***** assert_equal (fishertest ([3, 4; 5, 7]), false); ***** assert_equal (isa (fishertest ([3, 4; 5, 7]), 'logical'), true); ***** test [h, pval, stats] = fishertest ([3, 4; 5, 7]); assert_equal (pval, 1, 1e-14); assert_equal (stats.OddsRatio, 1.05); CI = [0.159222057151289, 6.92429189601808]; assert_equal (stats.ConfidenceInterval, CI, 1e-14) ***** test [h, pval, stats] = fishertest ([3, 4; 5, 0]); assert_equal (pval, 0.08080808080808080, 1e-14); assert_equal (stats.OddsRatio, 0); assert_equal (stats.ConfidenceInterval, [-Inf, Inf]) ***** error fishertest (); ***** error fishertest (1, 2, 3, 4, 5, 6); ***** error ... fishertest (ones (2, 2, 2)); ***** error ... fishertest ([1, 2; -3, 4]); ***** error ... fishertest ([1, 2; 3, 4+i]); ***** error ... fishertest ([1, 2; 3, 4.2]); ***** error ... fishertest ([NaN, 2; 3, 4]); ***** error ... fishertest ([1, Inf; 3, 4]); ***** error ... fishertest (ones (2) * 1e8); ***** error ... fishertest ([1, 2; 3, 4], 'alpha', 0); ***** error ... fishertest ([1, 2; 3, 4], 'alpha', 1.2); ***** error ... fishertest ([1, 2; 3, 4], 'alpha', 'val'); ***** error ... fishertest ([1, 2; 3, 4], 'tail', 'val'); ***** error ... fishertest ([1, 2; 3, 4], 'alpha', 0.01, 'tail', 'val'); ***** error ... fishertest ([1, 2; 3, 4], 'alpha', 0.01, 'badoption', 3); 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/adtest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/adtest.m ***** error adtest (); ***** error adtest (ones (20,2)); ***** error adtest ([1+i,0-3i]); ***** error ... adtest (ones (20,1), 'Distribution', 'normal'); ***** error ... adtest (rand (20,1), 'Distribution', {'normal', 5, 3}); ***** error ... adtest (rand (20,1), 'Distribution', {'norm', 5}); ***** error ... adtest (rand (20,1), 'Distribution', {'exp', 5, 4}); ***** error ... adtest (rand (20,1), 'Distribution', {'ev', 5}); ***** error ... adtest (rand (20,1), 'Distribution', {'logn', 5, 3, 2}); ***** error ... adtest (rand (20,1), 'Distribution', {'Weibull', 5}); ***** error ... adtest (rand (20,1), 'Distribution', 35); ***** error ... adtest (rand (20,1), 'Name', 'norm'); ***** error ... adtest (rand (20,1), 'Name', {'norm', 75, 10}); ***** error ... adtest (rand (20,1), 'Distribution', 'norm', 'Asymptotic', true); ***** error ... adtest (rand (20,1), 'MCTol', 0.001, 'Asymptotic', true); ***** error ... adtest (rand (20,1), 'Distribution', {'norm', 5, 3}, 'MCTol', 0.001, ... 'Asymptotic', true); ***** error ... [h, pval, ADstat, CV] = adtest (ones (20,1), 'Distribution', {'norm',5,3},... 'Alpha', 0.000000001); ***** error ... [h, pval, ADstat, CV] = adtest (ones (20,1), 'Distribution', {'norm',5,3},... 'Alpha', 0.999999999); ***** error ... adtest (10); ***** warning ... randn ('seed', 34); adtest (ones (20,1), 'Alpha', 0.000001); ***** warning ... randn ('seed', 34); adtest (normrnd (0,1,100,1), 'Alpha', 0.99999); ***** warning ... randn ('seed', 34); adtest (normrnd (0,1,100,1), 'Alpha', 0.00001); ***** test load examgrades x = grades(:,1); [h, pval, adstat, cv] = adtest (x); assert_equal (h, false); assert_equal (pval, 0.1854, 1e-4); assert_equal (adstat, 0.5194, 1e-4); assert_equal (cv, 0.7470, 1e-4); ***** test load examgrades x = grades(:,1); [h, pval, adstat, cv] = adtest (x, 'Distribution', 'ev'); assert_equal (h, false); assert_equal (pval, 0.071363, 1e-6); ***** test load examgrades x = grades(:,1); [h, pval, adstat, cv] = adtest (x, 'Distribution', {'norm', 75, 10}); assert_equal (h, false); assert_equal (pval, 0.4687, 1e-4); 25 tests, 25 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/vartest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/vartest.m ***** error vartest (); ***** error vartest ([1, 2, 3, 4], -0.5); ***** error ... vartest ([1, 2, 3, 4], 1, 'alpha', 0); ***** error ... vartest ([1, 2, 3, 4], 1, 'alpha', 1.2); ***** error ... vartest ([1, 2, 3, 4], 1, 'alpha', 'val'); ***** error ... vartest ([1, 2, 3, 4], 1, 'tail', 'val'); ***** error ... vartest ([1, 2, 3, 4], 1, 'alpha', 0.01, 'tail', 'val'); ***** error ... vartest ([1, 2, 3, 4], 1, 'dim', 3); ***** error ... vartest ([1, 2, 3, 4], 1, 'alpha', 0.01, 'tail', 'both', 'dim', 3); ***** error ... vartest ([1, 2, 3, 4], 1, 'alpha', 0.01, 'tail', 'both', 'badoption', 3); ***** error ... vartest ([1, 2, 3, 4], 1, 'alpha', 0.01, 'tail'); ***** test load carsmall [h, pval, ci] = vartest (MPG, 7^2); assert_equal (h, 1); assert_equal (pval, 0.04335086742174443, 1e-14); assert_equal (ci, [49.397; 88.039], 1e-3); ***** test load carsmall [h, pval, ci] = vartest (MPG, 7^2, 'tail', 'left'); assert_equal (h, 0); assert_equal (pval, 0.978324566289128, 1e-14); assert_equal (ci, [0; 83.685], 1e-3); ***** test load carsmall [h, pval, ci] = vartest (MPG, 7^2, 'tail', 'right'); assert_equal (h, 1); assert_equal (pval, 0.021675433710872, 1e-14); assert_equal (ci, [51.543; Inf], 1e-3); 14 tests, 14 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/ranksum.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/ranksum.m ***** test mileage = [33.3, 34.5, 37.4; 33.4, 34.8, 36.8; ... 32.9, 33.8, 37.6; 32.6, 33.4, 36.6; ... 32.5, 33.7, 37.0; 33.0, 33.9, 36.7]; [p,h,stats] = ranksum (mileage(:,1),mileage(:,2)); assert_equal (p, 0.004329004329004329, 1e-14); assert_equal (h, true); assert_equal (stats.ranksum, 21.5); ***** test year1 = [51 52 62 62 52 52 51 53 59 63 59 56 63 74 68 86 82 70 69 75 73 ... 49 47 50 60 59 60 62 61 71]'; year2 = [54 53 64 66 57 53 54 54 62 66 59 59 67 76 75 86 82 67 74 80 75 ... 54 50 53 62 62 62 72 60 67]'; [p,h,stats] = ranksum (year1, year2, 'alpha', 0.01, 'tail', 'left'); assert_equal (p, 0.1270832752950605, 1e-14); assert_equal (h, false); assert_equal (stats.ranksum, 837.5); assert_equal (stats.zval, -1.140287483634606, 1e-14); [p,h,stats] = ranksum (year1, year2, 'alpha', 0.01, 'tail', 'left', ... 'method', 'exact'); assert_equal (p, 0.127343916432862, 1e-14); assert_equal (h, false); assert_equal (stats.ranksum, 837.5); ***** test # zval field always present, empty for the exact method x = 1:8; y = 9:16; [p, h, stats] = ranksum (x, y); assert_equal (fieldnames (stats), {'ranksum'; 'zval'; 'RankBiserial'; ... 'RankBiserialCI'}); assert_equal (isempty (stats.zval), true); ***** test # zval is second for the approximate method too x = 1:8; y = 9:16; [p, h, stats] = ranksum (x, y, 'method', 'approximate'); assert_equal (fieldnames (stats), {'ranksum'; 'zval'; 'RankBiserial'; ... 'RankBiserialCI'}); assert_equal (stats.zval, -3.3082, 1e-4); ***** test ## Effect size against the R package effectsize 1.0.3, rank_biserial m1 = [33.3, 33.4, 32.9, 32.6, 32.5, 33.0]; m2 = [34.5, 34.8, 33.8, 33.4, 33.7, 33.9]; [~, ~, stats] = ranksum (m1, m2); assert_equal (stats.RankBiserial, -0.97222222222222232, -1e-14); T = meanEffectSize (m1, m2, 'Effect', 'cliff'); assert_equal (stats.RankBiserialCI, T.ConfidenceIntervals); ***** test year1 = [51 52 62 62 52 52 51 53 59 63 59 56 63 74 68 86 82 70 69 75 73 ... 49 47 50 60 59 60 62 61 71]'; year2 = [54 53 64 66 57 53 54 54 62 66 59 59 67 76 75 86 82 67 74 80 75 ... 54 50 53 62 62 62 72 60 67]'; [~, ~, stats] = ranksum (year1, year2, 'alpha', 0.1); assert_equal (stats.RankBiserial, -0.17222222222222228, -1e-14); T = meanEffectSize (year1, year2, 'Effect', 'cliff', 'Alpha', 0.1); assert_equal (stats.RankBiserialCI, T.ConfidenceIntervals); ***** test rand ('state', 1); [~, ~, stats] = ranksum ([1, 3, 4, 7, 8], [2, 5, 6, 9, 10, 11], ... 'ConfidenceIntervalType', 'bootstrap', ... 'NumBootstraps', 200, 'Resampling', 'stratified'); ci = stats.RankBiserialCI; assert_equal ([ci(1) <= ci(2), ci(1) >= -1, ci(2) <= 1], true (1, 3)); ***** error ... ranksum ([1, 2, 3], [4, 5, 6], 'ConfidenceIntervalType', 'none') ***** error ... ranksum ([1, 2, 3], [4, 5, 6], 'NumBootstraps', 0) ***** error ... ranksum ([1, 2, 3], [4, 5, 6], 'Resampling', 'foo') ***** error ranksum ([1, 2; 3, 4], [1, 2, 3]) ***** error ... ranksum ([NaN, NaN], [1, 2, 3]) ***** error ... ranksum ([1, 2, 3], NaN) ***** error ... ranksum ([1, 2, 3], [4, 5, 6], 1.5) ***** error ... ranksum ([1, 2, 3], [4, 5, 6], 'tail') ***** error ... ranksum ([1, 2, 3], [4, 5, 6], 'Tial', 'left') ***** error ... ranksum ([1, 2, 3], [4, 5, 6], 'alpha', 0.1, 5, 'left') ***** error ... ranksum ([1, 2, 3], [4, 5, 6], 'alpha', 0) ***** error ... ranksum ([1, 2, 3], [4, 5, 6], 'alpha', [0.1, 0.2]) ***** error ... ranksum ([1, 2, 3], [4, 5, 6], 'method', 'foo') ***** error ... ranksum ([1, 2, 3], [4, 5, 6], 'tail', 'up') 21 tests, 21 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/dwtest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/dwtest.m ***** demo ## Test regression residuals for autocorrelation x = [ones(20, 1), (1:20)']; y = x * [1; 0.5] + sin ((1:20)' / 2); # add an autocorrelated component b = x \ y; r = y - x * b; [p, d] = dwtest (r, x) ***** test x = [ones(6, 1), (1:6)']; r = [1; -1; 1; -1; 1; -1]; # strong negative autocorrelation [p, d] = dwtest (r, x); assert_equal (d, sum (diff (r) .^ 2) / sum (r .^ 2), 1e-12); assert_equal (d, 20 / 6, 1e-12); assert_equal (p >= 0 && p <= 1, true); ***** test ## Edge cases with empty arrays [p, d] = dwtest ([], []); assert_equal (p, 0); assert_equal (isnan (d), true); ***** test [p, d] = dwtest (zeros (0, 3), zeros (0, 3)); assert_equal (p, 0); assert_equal (isnan (d), true); ***** test [p, d] = dwtest (zeros (0, 1), zeros (0, 2)); assert_equal (p, 0); assert_equal (isnan (d), true); ***** test # exact and approximate methods give similar p-values x = [ones(30, 1), (1:30)', ((1:30)') .^ 2]; r = sin ((1:30)' / 3); pe = dwtest (r, x, "Method", "exact"); pa = dwtest (r, x, "Method", "approximate"); assert_equal (pe, pa, 0.05); ***** test # tail selection is consistent x = [ones(15, 1), (1:15)']; r = (-1) .^ (1:15)'; # alternating -> D near 4 pr = dwtest (r, x, "Tail", "right"); pl = dwtest (r, x, "Tail", "left"); pb = dwtest (r, x, "Tail", "both"); assert_equal (pr + pl, 1, 1e-10); assert_equal (pb, 2 * min (pr, pl), 1e-10); ***** test # left tail rejects strong negative autocorrelation (D near 4) x = [ones(20, 1), (1:20)']; r = (-1) .^ (1:20)'; assert_equal (dwtest (r, x, "Tail", "left") < 0.05, true); ***** test # zero residual degrees of freedom (n == rank(x)) x = [1 0 0; 0 1 0; 0 0 1]; r = [0.5; -0.3; 0.8]; assert_equal (dwtest (r, x, "Tail", "right"), 0); assert_equal (dwtest (r, x, "Tail", "left"), 1); assert_equal (dwtest (r, x, "Tail", "both"), 0); ***** test # zero residual degrees of freedom, approximate method x = [1 0 0; 0 1 0; 0 0 1]; r = [0.5; -0.3; 0.8]; assert_equal (isnan (dwtest (r, x, "Method", "approximate")), true); ***** test # the statistic is returned with no residual degrees of freedom x = [1 0 0; 0 1 0; 0 0 1]; r = [0.5; -0.3; 0.8]; [p, d] = dwtest (r, x); assert_equal (d, 1.8878, 1e-4); ***** error dwtest (1) ***** error dwtest (ones (3, 3), ones (3, 2)) ***** error dwtest ('', []) ***** error ... dwtest ([1;2;3], ones (2, 2)) ***** error ... dwtest ([1;2;3], ones (3, 1), "Tail") ***** error ... dwtest ([1;2;3], ones (3, 1), "foo", "bar") ***** error ... dwtest ([1;2;3], ones (3, 1), "Method", "fast") ***** error ... dwtest ([1;2;3], ones (3, 1), "Tail", "up") 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/kruskalwallis.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/kruskalwallis.m ***** demo rng (42); x = meshgrid (1:6); x = x + normrnd (0, 1, 6, 6); kruskalwallis (x, [], 'off'); ***** demo rng (42); x = meshgrid (1:6); x = x + normrnd (0, 1, 6, 6); [p, atab] = kruskalwallis (x); ***** demo rng (42); x = ones (30, 4) .* [-2, 0, 1, 5]; x = x + normrnd (0, 2, 30, 4); group = {'A', 'B', 'C', 'D'}; kruskalwallis (x, group); ***** test data = [1.006, 0.996, 0.998, 1.000, 0.992, 0.993, 1.002, 0.999, 0.994, 1.000, ... 0.998, 1.006, 1.000, 1.002, 0.997, 0.998, 0.996, 1.000, 1.006, 0.988, ... 0.991, 0.987, 0.997, 0.999, 0.995, 0.994, 1.000, 0.999, 0.996, 0.996, ... 1.005, 1.002, 0.994, 1.000, 0.995, 0.994, 0.998, 0.996, 1.002, 0.996, ... 0.998, 0.998, 0.982, 0.990, 1.002, 0.984, 0.996, 0.993, 0.980, 0.996, ... 1.009, 1.013, 1.009, 0.997, 0.988, 1.002, 0.995, 0.998, 0.981, 0.996, ... 0.990, 1.004, 0.996, 1.001, 0.998, 1.000, 1.018, 1.010, 0.996, 1.002, ... 0.998, 1.000, 1.006, 1.000, 1.002, 0.996, 0.998, 0.996, 1.002, 1.006, ... 1.002, 0.998, 0.996, 0.995, 0.996, 1.004, 1.004, 0.998, 0.999, 0.991, ... 0.991, 0.995, 0.984, 0.994, 0.997, 0.997, 0.991, 0.998, 1.004, 0.997]; group = [1:10] .* ones (10,10); group = group(:); [p, tbl] = kruskalwallis (data, group, 'off'); assert_equal (p, 0.048229, 1e-6); assert_equal (tbl{2,5}, 17.03124, 1e-5); assert_equal (tbl{2,3}, 9, 0); assert_equal (tbl{4,2}, 82655.5, 1e-16); data = reshape (data, 10, 10); [p, tbl, stats] = kruskalwallis (data, [], 'off'); assert_equal (p, 0.048229, 1e-6); assert_equal (tbl{2,5}, 17.03124, 1e-5); assert_equal (tbl{2,3}, 9, 0); assert_equal (tbl{4,2}, 82655.5, 1e-16); means = [51.85, 60.45, 37.6, 51.1, 29.5, 54.25, 64.55, 66.7, 53.65, 35.35]; N = 10 * ones (1, 10); assert_equal (stats.meanranks, means, 1e-6); assert_equal (length (stats.gnames), 10, 0); assert_equal (stats.n, N, 0); ***** test [p, tbl] = kruskalwallis ((1:5)', [], 'off'); assert_equal (p, NaN); assert_equal (cell2mat (tbl(2:4,2:3)), [0, 0; 10, 4; 10, 4]); ***** test [p, tbl] = kruskalwallis (1:5, [], 'off'); assert_equal (p, NaN); assert_equal (cell2mat (tbl(2:4,2:3)), [0, 0; 10, 4; 10, 4]); ***** test [p, tbl] = kruskalwallis ([], [], 'off'); assert_equal (p, NaN); assert_equal (cell2mat (tbl(2:4,2:3)), zeros (3, 2)); ***** test ## Below the resolution of 1 - chi2cdf, values from MATLAB R2024a p = kruskalwallis ((1:200)', [ones(100, 1); 2 * ones(100, 1)], 'off'); assert_equal (p, 2.5239394239903e-34, -1e-10); ***** shared kw, kwg kw = [2.1, 3.4, 1.9, 5.6, 4.4, 3.8, 2.7, 6.1, 3.3, 4.9, 1.2, 2.8, 0.9, ... 2.2, 3.1, 1.7, 2.5, 0.4, 1.9, 3.6, 2.0, 1.1, 1.8, 2.9, 2.2, 4.1, ... 4.9, 2.6, 3.0, 4.8]'; kwg = [ones(10, 1); 2 * ones(12, 1); 3 * ones(8, 1)]; ***** test [~, tbl, stats] = kruskalwallis (kw, kwg, 'off'); assert_equal (stats.EtaSquared, 0.29653567934214958, -1e-13); ## The bounds put H at the upper and lower 2.5% points of the noncentral ## chi-square distribution lambda = stats.EtaSquaredCI * tbl{3,3}; assert_equal (ncx2cdf (tbl{2,5}, 2, lambda), [0.975, 0.025], -1e-10); ***** test [~, tbl, stats] = kruskalwallis (kw, kwg, 'off', 'Alpha', 0.1); lambda = stats.EtaSquaredCI * tbl{3,3}; assert_equal (ncx2cdf (tbl{2,5}, 2, lambda), [0.95, 0.05], -1e-10); ***** test x = [1, 2, 2, 3, 3, 3, 4, 5, 2, 2, 3, 3, 4, 6, 5, 6, 6, 7]'; g = [ones(8, 1); 2 * ones(6, 1); 3 * ones(4, 1)]; [~, ~, stats] = kruskalwallis (x, g, 'off'); assert_equal (stats.EtaSquared, 0.38833809693938293, -1e-13); assert_equal (stats.EtaSquaredCI(2), 1); ***** test [~, ~, stats] = kruskalwallis ([1, 5, 2, 8, 4, 3, 7, 6, 2, 9, 1, 3]', ... [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]', 'off'); assert_equal (stats.EtaSquared, 0); assert_equal (stats.EtaSquaredCI(1), 0); ***** test rand ('state', 1); [~, ~, stats] = kruskalwallis (kw, kwg, 'off', 'ConfidenceIntervalType', ... 'bootstrap', 'NumBootstraps', 200); ci = stats.EtaSquaredCI; assert_equal ([ci(1) <= ci(2), ci(1) >= 0, ci(2) <= 1], true (1, 3)); ***** error ... kruskalwallis ([1, 2, 3, 4], [1, 1, 2, 2], 'off', 'Foo', 1) ***** error ... kruskalwallis ([1, 2, 3, 4], [1, 1, 2, 2], 'off', 'Alpha', 1) ***** error ... kruskalwallis ([1, 2, 3, 4], [1, 1, 2, 2], 'off', ... 'ConfidenceIntervalType', 'none') ***** error ... kruskalwallis ([1, 2, 3, 4], [1, 1, 2, 2], 'off', 'NumBootstraps', 0) 14 tests, 14 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/lillietest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/lillietest.m ***** demo ## Test whether a sample is normally distributed x = [1 2 3 4 5 6 7 8 9 50]; # last value is an outlier [h, p, kstat] = lillietest (x) ***** test # statistic matches a direct Kolmogorov-Smirnov computation and MATLAB warning ("off", "lillietest:pTooBig", "local"); warning ("off", "lillietest:pTooSmall", "local"); x = [2.1 0.3 1.2 -0.7 0.9 1.5 2.8 0.1 0.4 1.1 3.2 0.6 2.0 0.9 1.7]'; [~, ~, ks] = lillietest (x); xs = sort (x); n = numel (x); cdf = normcdf ((xs - mean (x)) / std (x)); d = max (max ((1:n)'/n - cdf), max (cdf - (0:n-1)'/n)); assert_equal (ks, d, 1e-12); assert_equal (ks, 0.1026, 5e-4); # MATLAB lillietest reference ***** test # exponential and extreme value statistics match MATLAB references warning ("off", "lillietest:pTooBig", "local"); warning ("off", "lillietest:pTooSmall", "local"); xe = [0.5 1.2 0.3 2.1 0.8 1.5 0.2 3.0 0.7 1.1 0.4 2.5]'; [~, ~, kse] = lillietest (xe, "Distribution", "exponential"); assert_equal (kse, 0.1545, 5e-4); xn = [2.1 0.3 1.2 -0.7 0.9 1.5 2.8 0.1 0.4 1.1 3.2 0.6 2.0 0.9 1.7]'; [~, ~, ksv] = lillietest (xn, "Distribution", "extreme value"); assert_equal (ksv, 0.1512, 5e-4); ***** test # a clearly non-normal sample is rejected; h, p, critval consistent warning ("off", "lillietest:pTooSmall", "local"); x = [zeros(1, 15), 100]; [h, p, ks, cv] = lillietest (x); assert_equal (h, 1); assert_equal (h, double (ks > cv)); assert_equal (p, 0.001); # clamped to the tabulated minimum ***** test # distribution families run and return a decision warning ("off", "lillietest:pTooBig", "local"); warning ("off", "lillietest:pTooSmall", "local"); x = -log (rand (30, 1)); assert_equal (ismember (lillietest (x, "Distribution", "exponential"), [0 1]), true); assert_equal (ismember (lillietest (x, "Distribution", "extreme value"), [0 1]), true); ***** test # p-value stays in the tabulated range; critval grows as alpha falls warning ("off", "lillietest:pTooBig", "local"); warning ("off", "lillietest:pTooSmall", "local"); x = [3 1 4 1 5 9 2 6 5 3 5 8 9 7]'; [~, p, ~, cv05] = lillietest (x); [~, ~, ~, cv01] = lillietest (x, "Alpha", 0.01); assert_equal (p >= 0.001 && p <= 0.5, true); assert_equal (cv01 > cv05, true); ***** test # Monte-Carlo path runs and returns a valid p-value warning ("off", "lillietest:pTooBig", "local"); warning ("off", "lillietest:pTooSmall", "local"); x = [2.1 0.3 1.2 -0.7 0.9 1.5 2.8 0.1 0.4 1.1 3.2 0.6 2.0 0.9 1.7]'; [h, p] = lillietest (x, "MCTol", 0.05); assert_equal (ismember (h, [0 1]), true); assert_equal (p > 0 && p <= 1, true); ***** test # interpolation works for a sample size off the table grid (n = 17) warning ("off", "lillietest:pTooBig", "local"); warning ("off", "lillietest:pTooSmall", "local"); x = [1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16]'; [~, ~, ~, cv] = lillietest (x); assert_equal (isfinite (cv) && cv > 0, true); ***** test # extreme statistic with few reps gives an exact zero p-value x = [zeros(1, 15), 100]; [h, p, kstat] = lillietest (x, "MCTol", 0.05); assert_equal (p, 0); assert_equal (kstat, 0.5362, 5e-4); ***** warning ... lillietest (norminv ((1:20)' / 21)); ***** warning ... lillietest ([zeros(1, 15), 100]); ***** error lillietest () ***** error lillietest (ones (3, 3)) ***** error ... lillietest ([1 2 3]) ***** error ... lillietest (1:10, "Distribution", "poisson") ***** error ... lillietest (1:10, "Alpha", 0) ***** error ... lillietest (1:10, "Alpha", 0.75) ***** error ... lillietest (1:10, "MCTol", -1) 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/signrank.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/signrank.m ***** test ## the exact test has no z-statistic, so no ZVAL field is created at all x = [1.83 0.50 1.62 2.48 1.68 1.88 1.55 3.06 1.30]; y = [0.878 0.647 0.598 2.05 1.06 1.29 1.06 3.14 1.29]; [p, h, stats] = signrank (x, y, 'method', 'exact'); assert_equal (fieldnames (stats), {'signedrank'; 'zval'; 'RankBiserial'; ... 'RankBiserialCI'}); assert_equal (stats.signedrank, 40); assert_equal (isempty (stats.zval), true); assert_equal (p, 0.039062500000000, 1e-14); ***** test ## the default method for a small sample is the exact one x = [1.83 0.50 1.62 2.48 1.68 1.88 1.55 3.06 1.30]; [~, ~, stats] = signrank (x, 1); assert_equal (fieldnames (stats), {'signedrank'; 'zval'; 'RankBiserial'; ... 'RankBiserialCI'}); assert_equal (stats.signedrank, 43); assert_equal (isempty (stats.zval), true); ***** test ## identical inputs give a zero statistic and no z-value [p, h, stats] = signrank ([1 2 3], [1 2 3]); assert_equal (p, 1); assert_equal (fieldnames (stats), {'signedrank'; 'zval'; 'RankBiserial'; ... 'RankBiserialCI'}); assert_equal (stats.signedrank, 0); assert_equal (isempty (stats.zval), true); ***** test load gradespaired.mat [p, h, stats] = signrank (gradespaired(:,1), ... gradespaired(:,2), 'tail', 'left'); assert_equal (p, 0.0047, 1e-4); assert_equal (h, true); assert_equal (stats.zval, -2.5982, 1e-4); assert_equal (stats.signedrank, 2017.5); ***** test load ('gradespaired.mat'); [p, h, stats] = signrank (gradespaired(:,1), gradespaired(:,2), ... 'tail', 'left', 'method', 'exact'); assert_equal (p, 0.0045, 1e-4); assert_equal (h, true); assert_equal (isempty (stats.zval), true); assert_equal (stats.signedrank, 2017.5); ***** test load mileage [p, h, stats] = signrank (mileage(:,2), 33); assert_equal (p, 0.0312, 1e-4); assert_equal (h, true); assert_equal (isempty (stats.zval), true); assert_equal (stats.signedrank, 21); ***** test load mileage [p, h, stats] = signrank (mileage(:,2), 33, 'tail', 'right'); assert_equal (p, 0.0156, 1e-4); assert_equal (h, true); assert_equal (isempty (stats.zval), true); assert_equal (stats.signedrank, 21); ***** test load mileage [p, h, stats] = signrank (mileage(:,2), 33, 'tail', 'right', ... 'alpha', 0.01, 'method', 'approximate'); assert_equal (p, 0.0180, 1e-4); assert_equal (h, false); assert_equal (stats.zval, 2.0966, 1e-4); assert_equal (stats.signedrank, 21); ***** test x = [1, 2, 3, NaN, 4, 5]; p_clean = signrank ([1, 2, 3, 4, 5]); p_nan = signrank (x); assert_equal (p_nan, p_clean); ***** test ## Differences equal to within the precision of the values they came from ## rank as tied, as MATLAB ranks them. Two of these sit 2 ulps apart. big = [2.1 3.4 1.2 5.6 4.3 2.2 6.7 3.3 4.4 5.5 1.1 2.9 3.8 4.9 5.1 6.2 ... 7.3 2.4]; [p, h, stats] = signrank (big, 3, 'method', 'approximate'); assert_equal (stats.signedrank, 132); assert_equal (stats.zval, 2.025571814690999, 1e-12); ***** test ## A difference below that precision counts as no difference at all, and is ## dropped exactly as an exact zero is. Both forms measured against R2024a. x = [5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]; y = x + 1; y(16) = x(16) + eps (x(16)); [p, h, stats] = signrank (x, y, 'method', 'approximate'); assert_equal (stats.signedrank, 0); assert_equal (stats.zval, -3.872983346207417, 1e-12); y(16) = x(16); [p2, h2, stats2] = signrank (x, y, 'method', 'approximate'); assert_equal (p2, p, 1e-15); assert_equal (stats2.zval, stats.zval, 1e-15); ***** test x = [1.83 0.50 1.62 2.48 1.68 1.88 1.55 3.06 1.30]; y = [0.878 0.647 0.598 2.05 1.06 1.29 1.06 3.14 1.29]; [~, ~, stats] = signrank (x, y); assert_equal (stats.RankBiserial, 0.77777777777777768, -1e-14); assert_equal (stats.RankBiserialCI, ... [0.29536312933624187, 0.94415590192008148], -1e-13); ***** test x = [1.83 0.50 1.62 2.48 1.68 1.88 1.55 3.06 1.30]; y = [0.878 0.647 0.598 2.05 1.06 1.29 1.06 3.14 1.29]; [~, ~, stats] = signrank (x, y, 'alpha', 0.1, 'method', 'approximate'); assert_equal (stats.RankBiserial, 0.77777777777777768, -1e-14); assert_equal (stats.RankBiserialCI, ... [0.39915793850732861, 0.92978414736490256], -1e-13); ***** test x = [1.83 0.50 1.62 2.48 1.68 1.88 1.55 3.06 1.30]; [~, ~, stats] = signrank (x, 1); assert_equal (stats.RankBiserial, 0.9111111111111112, -1e-14); assert_equal (stats.RankBiserialCI, ... [0.66333041160415562, 0.9788499892207112], -1e-12); ***** test ## Three differences are zero, so the interval runs over six, where ## effectsize counts nine and gives [-0.4148, 0.7736] x = [1, 2, 2, 3, 5, 5, 4, 7, 6]; y = [1, 1, 3, 2, 4, 5, 6, 3, 6]; [~, ~, stats] = signrank (x, y); assert_equal (stats.RankBiserial, 0.28571428571428575, -1e-14); se = sqrt ((2 * 6 ^ 3 + 3 * 6 ^ 2 + 6) / 6) / 21; assert_equal (stats.RankBiserialCI, ... tanh (atanh (2 / 7) + [-1, 1] * norminv (0.975) * se), -1e-14); ***** test [~, ~, stats] = signrank ([1, 2, 3], [1, 2, 3]); assert_equal (stats.RankBiserial, NaN); assert_equal (stats.RankBiserialCI, [NaN, NaN]); ***** test rand ('state', 1); [~, ~, stats] = signrank ([1.2, 3.4, 2.2, 5.1, 0.3, 4.4, 2.8, 3.9], 2, ... 'ConfidenceIntervalType', 'bootstrap', ... 'NumBootstraps', 200); ci = stats.RankBiserialCI; assert_equal ([ci(1) <= ci(2), ci(1) >= -1, ci(2) <= 1], true (1, 3)); ***** error signrank (ones (2)) ***** error ... signrank ([1, 2, 3, 4], ones (2)) ***** error ... signrank ([1, 2, 3, 4], [1, 2, 3]) ***** error ... signrank ([1, 2, 3, 4], [], 'tail') ***** error ... signrank ([1, 2, 3, 4], [], 'alpha', 1.2) ***** error ... signrank ([1, 2, 3, 4], [], 'alpha', 0) ***** error ... signrank ([1, 2, 3, 4], [], 'alpha', -0.05) ***** error ... signrank ([1, 2, 3, 4], [], 'alpha', 'a') ***** error ... signrank ([1, 2, 3, 4], [], 'alpha', [0.01, 0.05]) ***** error ... signrank ([1, 2, 3, 4], [], 'tail', 0.01) ***** error ... signrank ([1, 2, 3, 4], [], 'tail', {'both'}) ***** error ... signrank ([1, 2, 3, 4], [], 'tail', 'some') ***** error ... signrank ([1, 2, 3, 4], [], 'method', 'exact', 'tail', 'some') ***** error ... signrank ([1, 2, 3, 4], [], 'method', 0.01) ***** error ... signrank ([1, 2, 3, 4], [], 'method', {'exact'}) ***** error ... signrank ([1, 2, 3, 4], [], 'method', 'some') ***** error ... signrank ([1, 2, 3, 4], [], 'tail', 'both', 'method', 'some') ***** error ... signrank ([1, 2, 3], 0, 'ConfidenceIntervalType', 'none') ***** error ... signrank ([1, 2, 3], 0, 'NumBootstraps', 2.5) 36 tests, 36 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/swtest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/swtest.m ***** demo ## Test whether a sample departs from normality x = [148 154 158 160 161 162 166 170 182 195 236]; [h, p, W] = swtest (x) ***** demo ## The Shapiro-Francia test on the same sample x = [148 154 158 160 161 162 166 170 182 195 236]; [h, p, W] = swtest (x, 'Method', 'shapiro-francia') ***** test # Shapiro and Wilk's example, n <= 11 x = [148 154 158 160 161 162 166 170 182 195 236]; [h, p, W, c] = swtest (x); assert_equal (h, 1); assert_equal (p, 0.00670381405650293, 1e-12); assert_equal (W, 0.788814694835387, 1e-12); assert_equal (c, 0.855278601529214, 1e-12); ***** test # n > 11 [h, p, W, c] = swtest (log (1:25)); assert_equal (h, 1); assert_equal (p, 0.00741545379169184, 1e-12); assert_equal (W, 0.881481586050452, 1e-12); assert_equal (c, 0.91953513814811, 1e-12); ***** test # n = 5, two approximated weights [h, p, W, c] = swtest ([2 3 5 8 13]); assert_equal (h, 0); assert_equal (p, 0.534654754257205, 1e-12); assert_equal (W, 0.920729192441235, 1e-12); assert_equal (c, 0.775099786396077, 1e-12); ***** test # n = 4 [h, p, W, c] = swtest ([1 2 4 8]); assert_equal (h, 0); assert_equal (p, 0.53808377727497, 1e-12); assert_equal (W, 0.92020267879194, 1e-12); assert_equal (c, 0.762289320516799, 1e-12); ***** test # n = 3, exact null distribution [h, p, W, c] = swtest ([1 2 4]); assert_equal (h, 0); assert_equal (W, 27 / 28, 1e-14); assert_equal (p, 6 / pi * (asin (sqrt (27 / 28)) - pi / 3), 1e-14); assert_equal (c, sin (pi / 3 + pi / 120) ^ 2, 1e-14); ***** test # three equally spaced values fit a normal sample exactly [h, p, W] = swtest ([1 2 3]); assert_equal (h, 0); assert_equal (p, 1); assert_equal (W, 1); ***** test # Shapiro-Francia, n <= 11 x = [148 154 158 160 161 162 166 170 182 195 236]; [h, p, W, c] = swtest (x, 'Method', 'shapiro-francia'); assert_equal (h, 1); assert_equal (p, 0.00734764001456067, 1e-12); assert_equal (W, 0.771381939646386, 1e-12); assert_equal (c, 0.855095971555222, 1e-12); ***** test # Shapiro-Francia, n > 11 [h, p, W, c] = swtest (log (1:25), 'Method', 'shapiro-francia'); assert_equal (h, 1); assert_equal (p, 0.00991400561293846, 1e-12); assert_equal (W, 0.882794840134263, 1e-12); assert_equal (c, 0.919670595475726, 1e-12); ***** test # Shapiro-Francia, n = 5 [h, p, W, c] = swtest ([2 3 5 8 13], 'Method', 'shapiro-francia'); assert_equal (h, 0); assert_equal (p, 0.592971063346381, 1e-12); assert_equal (W, 0.925681475433048, 1e-12); assert_equal (c, 0.782592834233546, 1e-12); ***** test # Shapiro-Francia, n = 200, measured with R's nortest sf.test [h, p, W] = swtest (sqrt (1:200), 'Method', 'shapiro-francia'); assert_equal (h, 1); assert_equal (p, 8.0650594412092e-06, -1e-10); assert_equal (W, 0.950552730992928, -1e-10); ***** test # Shapiro-Francia on a strong skew, measured with R's nortest sf.test [h, p, W] = swtest (exp ((1:20) / 5), 'Method', 'shapiro-francia'); assert_equal (h, 1); assert_equal (p, 0.00305794323924647, -1e-10); assert_equal (W, 0.824238460116288, -1e-10); ***** test # Shapiro-Francia on bounded data, measured with R's nortest sf.test [h, p, W] = swtest (sin (1:30), 'Method', 'shapiro-francia'); assert_equal (h, 1); assert_equal (p, 0.018296975230196, -1e-10); assert_equal (W, 0.911248253555032, -1e-10); ***** test # Alpha sets the critical value and leaves P unchanged [h, p, W, c] = swtest (log (1:25), 'Alpha', 0.01); assert_equal (h, 1); assert_equal (p, 0.00741545379169184, 1e-12); assert_equal (c, 0.887697842838192, 1e-12); ***** test # Alpha decides H assert_equal (swtest ([2 3 5 8 13], 'Alpha', 0.6), 1); ***** test # Method is case insensitive [~, p] = swtest (log (1:25), 'Method', 'Shapiro-Francia'); assert_equal (p, 0.00991400561293846, 1e-12); ***** test # Method as a string scalar [~, p] = swtest (log (1:25), 'Method', string ('shapiro-francia')); assert_equal (p, 0.00991400561293846, 1e-12); ***** test # NaNs are removed [h, p, W, c] = swtest ([NaN, log(1:25), NaN]); assert_equal ([h, p, W, c], ... [1, 0.00741545379169184, 0.881481586050452, ... 0.91953513814811], 1e-12); ***** test # a column vector gives the same result [h, p, W, c] = swtest (log (1:25)'); assert_equal ([h, p, W, c], ... [1, 0.00741545379169184, 0.881481586050452, ... 0.91953513814811], 1e-12); ***** test # unsorted data gives the same result [h, p, W, c] = swtest (fliplr (log (1:25))); assert_equal ([h, p, W, c], ... [1, 0.00741545379169184, 0.881481586050452, ... 0.91953513814811], 1e-12); ***** test # integer data is tested as double [~, p, W] = swtest (int16 ([148 154 158 160 161 162 166 170 182 195 236])); assert_equal (p, 0.00670381405650293, 1e-12); assert_equal (W, 0.788814694835387, 1e-12); ***** test # single data is tested as double [~, p, W] = swtest (single ([148 154 158 160 161 162 166 170 182 195 236])); assert_equal (p, 0.00670381405650293, 1e-12); assert_equal (W, 0.788814694835387, 1e-12); ***** test # a sample of 5000 values is accepted assert_equal (swtest (1:5000), 1); ***** error swtest () ***** error swtest (ones (3, 3)) ***** error swtest ({1, 2, 3}) ***** error swtest ([1 2 3i]) ***** error swtest ('abcde') ***** error ... swtest (1:10, 0.01) ***** error ... swtest (1:10, 'Tail', 'left') ***** error ... swtest (1:10, 'Alpha', 0) ***** error ... swtest (1:10, 'Alpha', 1) ***** error ... swtest (1:10, 'Alpha', [0.01 0.05]) ***** error ... swtest (1:10, 'Alpha', '0.05') ***** error ... swtest (1:10, 'Method', 'sf') ***** error ... swtest (1:10, 'Method', 5) ***** error swtest ([1 2 3 Inf]) ***** error ... swtest (1:4, 'Method', 'shapiro-francia') ***** error ... swtest ([1 2 NaN]) ***** error ... swtest (1:5001) ***** error swtest (ones (1, 10)) 40 tests, 40 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/anova.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/anova.m ***** demo ## Fit an ANOVA object and inspect component and summary statistics y = [1; 2; 3; 4; 5; 6; 10; 11; 12]; g = [1; 1; 1; 2; 2; 2; 3; 3; 3]; aov = anova (g, y, 'FactorNames', {'Treatment'}); component = stats (aov) summary_table = stats (aov, 'summary') ***** demo ## Estimate group means and perform post-hoc comparisons y = [1; 2; 3; 4; 5; 6; 10; 11; 12]; g = [1; 1; 1; 2; 2; 2; 3; 3; 3]; aov = anova (g, y, 'SumOfSquaresType', 'two'); means = groupmeans (aov) comparisons = multcompare (aov, 'display', 'off') ***** demo ## Plot multiple-comparison intervals y = [1; 2; 3; 4; 5; 6; 10; 11; 12]; g = [1; 1; 1; 2; 2; 2; 3; 3; 3]; aov = anova (g, y, 'SumOfSquaresType', 'two'); plotComparisons (aov); ***** test y = [1; 2; 3; 4; 5; 6]; g = [1; 1; 2; 2; 3; 3]; a = anova (g, y); assert_equal (class (a), 'anova'); assert_equal (a.Y, y); assert_equal (a.GROUP, g); ***** test y = magic (4); a = anova (y); assert_equal (class (a), "anova"); assert_equal (a.Y, y(:)); assert_equal (a.GROUP, []); ***** test y = (1:12)'; g1 = repmat ([1;2;3], 4, 1); g2 = repmat ([1;1;2;2], 3, 1); a = anova ({g1, g2}, y); assert_equal (class (a), 'anova'); assert_equal (a.NumFactors, 2); ***** test a = anova ([1;1;2;2], [1;2;3;4]); assert_equal (a.ModelSpecification, 'linear'); assert_equal (char (a.SumOfSquaresType), 'three'); assert_equal (a.ResponseName, 'Y'); assert_equal (cellstr (a.FactorNames), {'Factor1'}); assert_equal (a.RandomFactors, []); assert_equal (a.CategoricalFactors, 1); assert_equal (a.NumFactors, 1); assert_equal (a.NumObservations, 4); ***** test a = anova ([1;1;2;2], [1;2;3;4]); assert_equal (a.Coefficients, [2.5; -1; 1], 1e-12); assert_equal (cellstr (a.ExpandedFactorNames), ... {'(Intercept)'; '(Factor1==1)'; '(Factor1==2)'}); assert_equal (a.FittedValues, [1.5; 1.5; 3.5; 3.5], 1e-12); assert_equal (a.Residuals.Raw, [-0.5; 0.5; -0.5; 0.5], 1e-12); assert_equal (a.Residuals.Pearson, ... [-1; 1; -1; 1] / sqrt (2), 1e-12); assert_equal (a.DesignMatrix, []); ***** test y = (1:12)'; g1 = repmat ([1;2;3], 4, 1); g2 = repmat ([1;1;2;2], 3, 1); a = anova ({g1, g2}, y, 'SumOfSquaresType', 'two', ... 'ModelSpecification', 'full', 'FactorNames', {'A', 'B'}); assert_equal (char (a.SumOfSquaresType), 'two'); assert_equal (a.ModelSpecification, 'full'); assert_equal (cellstr (a.FactorNames), {'A', 'B'}); ***** test a = anova ([1;1;2;2], [1;2;3;4], 'SumOfSquaresType', 'one', 'displayopt', 'on'); assert_equal (char (a.SumOfSquaresType), 'one'); ***** test y = [1; 2; 3; 4]; g = [1; 1; 2; 2]; popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; figs = get (0, 'children'); cmd = strcat ("a1 = anova (g, y, 'Display', 'on');", ... "a2 = anova (popcorn, [], 'reps', 3, 'Display', 'on');", ... "a3 = anova (g, y, 'SumOfSquaresType', 'one',", ... " 'Display', 'on');"); str = evalc (cmd); assert_equal (isempty (str), true); assert_equal (isempty (setdiff (get (0, 'children'), figs)), true); ***** test a = anova ([1;1;2;2;3;3], [1;2;3;4;5;6]); assert_equal (isempty (strfind (evalc ('disp (a)'), '1-way anova')), false); ***** test a = anova (magic (4)); str = evalc ('disp (a)'); assert_equal (isempty (strfind (str, '1-way anova')), false); ***** test y = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; a = anova (y, [], 'reps', 3); assert_equal (isempty (strfind (evalc ('disp (a)'), '2-way anova')), false); ***** test y = (1:12)'; g1 = repmat ([1;2;3], 4, 1); g2 = repmat ([1;1;2;2], 3, 1); a = anova ({g1, g2}, y); str = evalc ('disp (a)'); assert_equal (isempty (strfind (str, '2-way anova')), false); ***** test y = (1:24)'; g1 = repmat ([1;2], 12, 1); g2 = repmat ([1;1;2;2], 6, 1); g3 = repmat ([1;1;1;1;2;2;2;2], 3, 1); a = anova ({g1, g2, g3}, y); str = evalc ('disp (a)'); assert_equal (isempty (strfind (str, '3-way anova')), false); ***** test a = anova ([1;1;2;2;3;3], [1;2;3;4;5;6], 'SumOfSquaresType', 'two'); assert_equal (isempty (strfind (evalc ('disp (a)'), 'Type II')), false); ***** test y = (1:12)'; g1 = repmat ([1;2;3], 4, 1); g2 = (1:12)'; ## continuous a = anova ({g1, g2}, y, 'CategoricalFactors', 1); assert_equal (a.CategoricalFactors, 1); ***** test y = [1; 2; 3; NaN; 5; 6; 7; 8]; g1 = [1; 2; 1; 2; 1; 2; 1; 2]; g2 = [1; 1; 2; 2; 1; 1; 2; 2]; a = anova ({g1, g2}, y); assert_equal (a.NumFactors, 2); assert_equal (a.NumObservations, 7); assert_equal (a.Stats.source, 'anovan'); ***** test a = anova ([1;1;2;2;3;3], [1;2;3;4;5;6], 'Weights', ones (6, 1)); assert_equal (a.Stats.source, 'anovan'); assert_equal (stats (a).Properties.RowNames, ... {'Factor1'; 'Error'; 'Total'}); ***** test y = [1; 2; 3; 4; 5; 6]; g = [1; 1; 2; 2; 3; 3]; a = anova (g, y); a.fit (); assert_equal (size (a.AnovaTable), [4, 6]); assert_equal (a.Stats.source, 'anova1'); assert_equal (a.DFE, 3); assert_equal (a.MSE, 0.5, 1e-12); ***** test popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; a = anova (popcorn, [], 'reps', 3); assert_equal (! isempty (strfind (evalc ('disp (a)'), '2-way anova')), true); a.fit (); assert_equal (size (a.AnovaTable), [5, 6]); assert_equal (a.MSE, 0.125, 1e-12); assert_equal (a.Stats.sigmasq, 0.125, 1e-12); ***** test y = (1:24)'; g1 = repmat ([1;2], 12, 1); g2 = repmat ([1;1;2;2], 6, 1); g3 = repmat ([1;1;1;1;2;2;2;2], 3, 1); a = anova ({g1, g2, g3}, y); assert_equal (a.NumFactors, 3); a.fit (); assert_equal (a.Stats.source, 'anovan'); assert_equal (size (a.AnovaTable), [6, 9]); assert_equal (size (a.Coefficients), [7, 1]); assert_equal (size (a.Residuals), [24, 2]); assert_equal (size (a.DesignMatrix), [24, 4]); ***** test y = [10; 12; 11; 14; 16; 15; 9; 8; 10]; g = [1;1;1;2;2;2;3;3;3]; a = anova (g, y, 'SumOfSquaresType', 'two'); a.fit (); assert_equal (numel (a.FittedValues), numel (y)); assert_equal (a.FittedValues + a.Residuals.Raw, y, 1e-9); ***** test a = anova ([1;1;1;2;2;2;3;3;3], (1:9)'); a.fit (); first_table = a.AnovaTable; a.fit (); assert_equal (a.AnovaTable, first_table); ***** test y = (1:12)'; g = repmat ([1;2;3], 4, 1); a = anova ({g}, y, 'SumOfSquaresType', 'two', 'Alpha', 0.10); a.fit (); assert_equal (char (a.SumOfSquaresType), 'two'); assert_equal (a.Stats.alpha, 0.10, 1e-12); ***** test y = [1; 2; 3; 4; 5; 6; 10; 11; 12]; g = [1; 1; 1; 2; 2; 2; 3; 3; 3]; a = anova (g, y, 'SumOfSquaresType', 'two'); a.fit (); T = a.AnovaTable; assert_equal (T{2, 2}, 126, 1e-12); assert_equal (T{3, 2}, 6, 1e-12); assert_equal (T{4, 2}, 132, 1e-12); assert_equal (T{2, 3}, 2); assert_equal (T{3, 3}, 6); assert_equal (T{2, 5}, 63, 1e-12); assert_equal (T{3, 5}, 1, 1e-12); assert_equal (T{2, 6}, 63, 1e-12); assert_equal (T{2, 7}, 9.3914e-05, 1e-9); assert_equal (a.MSE, 1, 1e-12); assert_equal (a.DFE, 6); ***** test y = [1; 2; 3; 4; 5; 6; 10; 11; 12]; g = [1; 1; 1; 2; 2; 2; 3; 3; 3]; a = anova (g, y, 'SumOfSquaresType', 'two'); assert_equal (predict (a), [2; 2; 2; 5; 5; 5; 11; 11; 11], 1e-12); assert_equal (a.Residuals.Raw, ... [-1; 0; 1; -1; 0; 1; -1; 0; 1], 1e-12); ***** test y = [1; 2; 3; 4; 5; 6; 10; 11; 12]; g = [1; 1; 1; 2; 2; 2; 3; 3; 3]; es = getEffectSizes (anova (g, y, 'SumOfSquaresType', 'two')); assert_equal (es.Source, {'Factor1'}); assert_equal (es.EtaSquared, 126 / 132, 1e-12); assert_equal (es.PartialEtaSquared, 126 / (126 + 6), 1e-12); assert_equal (es.OmegaSquared, 124 / 133, 1e-12); ***** test popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; a = anova (popcorn, [], 'reps', 3); a.fit (); T = a.AnovaTable; assert_equal (T{2, 2}, 15.75, 1e-12); assert_equal (T{3, 2}, 4.5, 1e-12); assert_equal (T{4, 2}, 1.75, 1e-12); assert_equal (T{5, 2}, 22, 1e-12); assert_equal (T{2, 5}, 63, 1e-12); assert_equal (T{3, 5}, 36, 1e-12); assert_equal (a.MSE, 0.125, 1e-12); ***** test y = [1; 2; 3; 4; 5; 6; 10; 11; 12]; g = [1; 1; 1; 2; 2; 2; 3; 3; 3]; a = anova (g, y, 'SumOfSquaresType', 'two'); C = multcompare (a, 'CriticalValueType', 'bonferroni'); assert_equal (istable (C), true); assert_equal (C.Group1, [1; 1; 2]); assert_equal (C.Group2, [2; 3; 3]); assert_equal (C.MeanDifference, [-3; -9; -6], 1e-12); assert_equal (all (C.pValue >= 0 & C.pValue <= 1), true); ***** test a = anova ([1;1;1;2;2;2;3;3;3], (1:9)', 'SumOfSquaresType', 'two'); str = evalc ('summary (a)'); assert_equal (! isempty (strfind (str, 'ANOVA TABLE')), true); assert_equal (! isempty (strfind (str, 'backend = anovan')), true); ***** test a = anova ([1;1;1;2;2;2;3;3;3], (1:9)', 'SumOfSquaresType', 'two', ... 'Alpha', 0.10); str = evalc ('summary (a)'); assert_equal (! isempty (strfind (str, 'Alpha: 0.1')), true); ***** test a = anova ([1;1;1;2;2;2;3;3;3], (1:9)', 'SumOfSquaresType', 'two'); str = evalc ('disp (a)'); assert_equal (! isempty (strfind (str, '1-way anova')), true); assert_equal (! isempty (strfind (str, 'Type II')), true); assert_equal (! isempty (strfind (str, 'Properties, Methods')), true); ***** test a1 = anova ([1;1;1;2;2;2;3;3;3], (1:9)', 'SumOfSquaresType', 'one'); a2 = anova ([1;1;1;2;2;2;3;3;3], (1:9)', 'SumOfSquaresType', 'two'); assert_equal (! isempty (strfind (evalc ('summary (a1)'), ... 'Type I sums')), true); assert_equal (! isempty (strfind (evalc ('summary (a2)'), ... 'Type II sums')), true); ***** test y = [1; 2; 3; 4; 5; 6; 10; 11; 12]; g = [1; 1; 1; 2; 2; 2; 3; 3; 3]; a = anova (g, y, 'SumOfSquaresType', 'two'); C = multcompare (a); assert_equal (size (C), [3, 6]); assert_equal (C.Properties.VariableNames, ... {'Group1', 'Group2', 'MeanDifference', ... 'MeanDifferenceLower', 'MeanDifferenceUpper', 'pValue'}); ***** test popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; a = anova (popcorn, [], 'reps', 3); C = multcompare (a, 'Factor1'); assert_equal (size (C), [3, 6]); ***** test a = anova ([1;1;2;2;3;3], (1:6)', 'SumOfSquaresType', 'two'); C = multcompare (a); assert_equal (size (C), [3, 6]); ***** test y = [1; 2; 3; 4; 5; 6; 10; 11; 12]; g = [1; 1; 1; 2; 2; 2; 3; 3; 3]; a = anova (g, y, "FactorNames", {"Brand"}, ... "ResponseName", "Yield", "SumOfSquaresType", "two"); assert_equal (char (a.Formula.Text), "Yield ~ 1 + Brand"); assert_equal (cellstr (a.Formula.PredictorNames), {"Brand"}); assert_equal (a.Formula.Terms, 1); assert_equal (istable (a.Factors), true); assert_equal (a.Factors.Brand, g); assert_equal (a.Response, y); assert_equal (isstring (a.FactorNames), true); assert_equal (cellstr (a.FactorNames), {"Brand"}); assert_equal (isstring (a.SumOfSquaresType), true); assert_equal (char (a.SumOfSquaresType), "two"); assert_equal (isstruct (a.Formula), true); assert_equal (! any (strcmp (methods ("anova"), "predict")), true); T = stats (a); M = groupmeans (a); V = varianceComponent (a); assert_equal (T.SumOfSquares(1), 126, 1e-12); assert_equal (M.Mean, [2; 5; 11], 1e-12); assert_equal (V.VarianceComponent, 1, 1e-12); ***** test a = anova ([1;1;1;2;2;2;3;3;3], (1:9)'); assert_equal (sort (properties (a)), sort ({'Y'; 'Factors'; 'Formula'; ... 'FactorNames'; 'ExpandedFactorNames'; 'SumOfSquaresType'; ... 'RandomFactors'; 'CategoricalFactors'; 'ResponseName'; ... 'NumObservations'; 'Coefficients'; 'Residuals'; 'Metrics'})); ***** test y = (1:12)'; g1 = repmat ([1;2;3], 4, 1); g2 = repmat ([1;1;2;2], 3, 1); a = anova ({g1, g2}, y, 'FactorNames', {'A', 'B'}); assert_equal (istable (a.Factors), true); assert_equal (a.Factors.A, g1); assert_equal (a.Factors.B, g2); ***** test y = [10; 12; 11; 14; 16; 15; 9; 8; 10]; g = [1;1;1;2;2;2;3;3;3]; a = anova (g, y, 'SumOfSquaresType', 'two'); a.fit (); assert_equal (istable (a.Residuals), true); assert_equal (a.Residuals.Properties.VariableNames, {'Raw', 'Pearson'}); assert_equal (a.Residuals.Pearson, a.Residuals.Raw ./ sqrt (a.MSE), 1e-12); ***** test y = [1; 2; 3; 4; 5; 6; 10; 11; 12]; g = [1; 1; 1; 2; 2; 2; 3; 3; 3]; a = anova (g, y, 'SumOfSquaresType', 'two'); a.fit (); M = a.Metrics; assert_equal (M.Properties.VariableNames, {'MSE', 'RMSE', 'SSE', 'SSR', ... 'SST', 'RSquared', 'AdjustedRSquared'}); assert_equal (M.SSE, 6, 1e-12); assert_equal (M.SST, 132, 1e-12); assert_equal (M.RSquared, 126 / 132, 1e-12); ***** test y = [1; 2; 3; 4; 5; 6; 10; 11; 12]; g = [1; 1; 1; 2; 2; 2; 3; 3; 3]; a = anova (g, y, 'SumOfSquaresType', 'two'); a.fit (); assert_equal (isstring (a.ExpandedFactorNames), true); assert_equal (cellstr (a.ExpandedFactorNames), ... {'(Intercept)'; '(Factor1==1)'; '(Factor1==2)'; ... '(Factor1==3)'}); ***** test y = [1; 2; 3; 4; 5; 6; 10; 11; 12]; g = [1; 1; 1; 2; 2; 2; 3; 3; 3]; M = groupmeans (anova (g, y, 'SumOfSquaresType', 'two')); assert_equal (all (M.MeanLower <= M.Mean, 'all'), true); assert_equal (all (M.Mean <= M.MeanUpper, 'all'), true); ***** test hf = figure ('visible', 'off'); unwind_protect y = [1; 2; 3; 4; 5; 6; 10; 11; 12]; g = [1; 1; 1; 2; 2; 2; 3; 3; 3]; h = boxchart (anova (g, y)); assert_equal (all (ishghandle (h)), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** test y = [1; 2; 3; 4; 5; 6; 10; 11; 12]; g = [1; 1; 1; 2; 2; 2; 3; 3; 3]; w = [1; 1; 1; 2; 2; 2; 3; 3; 3]; a = anova (g, y, 'Weights', w); a.fit (); assert_equal (a.FittedValues + a.Residuals.Raw, y, 1e-9); ***** test hfig = figure ("visible", "off"); unwind_protect ax = axes ("parent", hfig); a = anova ([1;1;1;2;2;2], [1;2;3;4;5;6], ... "SumOfSquaresType", "two"); h = boxchart (a, ax); assert_equal (all (ishghandle (h)), true); assert_equal (all (arrayfun (@(x) ancestor (x, "axes") == ax, h)), true); unwind_protect_cleanup close (hfig); end_unwind_protect ***** test hfig = figure ("visible", "off"); unwind_protect ax = axes ("parent", hfig); a = anova ([1;1;1;2;2;2;3;3;3], (1:9)', ... "SumOfSquaresType", "two"); h = plotComparisons (a, ax); assert_equal (h, hfig); assert_equal (numel (findall (ax, "type", "line")) >= 6, true); unwind_protect_cleanup close (hfig); end_unwind_protect ***** test hfig = figure ("visible", "off"); unwind_protect ax1 = subplot (1, 2, 1, "parent", hfig); ax2 = subplot (1, 2, 2, "parent", hfig); a = anova (kron ((1:4)', ones (3, 1)), (1:12)', ... "SumOfSquaresType", "two"); plotComparisons (a, ax1, "CriticalValueType", "lsd"); plotComparisons (a, ax2, "CriticalValueType", "dunn-sidak"); lsd = findobj (ax1, "type", "line", "linestyle", "-"); sidak = findobj (ax2, "type", "line", "linestyle", "-"); lsd_width = diff (get (lsd(1), "xdata")); sidak_width = diff (get (sidak(1), "xdata")); assert_equal (sidak_width > lsd_width, true); unwind_protect_cleanup close (hfig); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect y = [10; 12; 11; 14; 16; 15; 9; 8; 10]; g = [1;1;1;2;2;2;3;3;3]; a = anova (g, y, 'SumOfSquaresType', 'two'); h = plotDiagnostics (a, 'Visible', 'off'); assert_equal (all (ishghandle (h), 'all'), true); assert_equal (numel (findall (h, 'type', 'axes')), 4); unwind_protect_cleanup close (h); close (hf); end_unwind_protect ***** test y = [10; 12; 11; 14; 16; 15; 9; 8; 10]; g = [1;1;1;2;2;2;3;3;3]; a = anova (g, y, 'SumOfSquaresType', 'two'); assert_equal (predict (a), a.FittedValues, 1e-9); ***** test y = [10; 12; 11; 14; 16; 15; 9; 8; 10]; g = [1;1;1;2;2;2;3;3;3]; a = anova (g, y, 'SumOfSquaresType', 'two'); a.fit (); assert_equal (predict (a, full (a.DesignMatrix)), a.FittedValues, 1e-9); ***** test y = [10; 12; 11; 14; 16; 15; 9; 8; 10]; g = [1;1;1;2;2;2;3;3;3]; a = anova (g, y, 'SumOfSquaresType', 'two'); es = getEffectSizes (a); assert_equal (iscell (es.Source), true); assert_equal (numel (es.EtaSquared), numel (es.Source)); assert_equal (all (isfinite (es.PartialEtaSquared), 'all'), true); ***** error anova () ***** error anova ('abc') ***** error anova ([]) ***** error ... anova ([1;1;2;2], [1;2;3;4], 'SumOfSquaresType') ***** error ... anova ([1;1;2;2], [1;2;3;4], 'bogus', 1) ***** error ... anova ([1;1;2;2], [1;2;3;4], 'SumOfSquaresType', 5) ***** error ... anova ([1;1;2;2], [1;2;3;4], 'Alpha', 2) ***** error ... anova ([1;1;2;2], [1;2;3;4], 'Display', 'maybe') ***** error ... anova ([1;1;2;2], [1;2;3;4], 1, 2) ***** error ... anova (magic (4), [], 'reps', -2) ***** error ... anova (magic (4), [], 'reps', 1.5) ***** error ... anova ([1;1;2;2], [1;2;3;4], 'ModelSpecification', 'cubic') ***** error ... anova ([1;1;2;2], [1;2;3;4], 'Model', [1 0]) ***** error ... anova ([1;1;2], [1;2;3;4]) ***** error ... anova ({[1;1;2], [1;2;1;2]}, [1;2;3;4]) ***** error ... anova ([1;1;2;2], [1;2;3;4], 'Weights', [1;1;1]) ***** error ... anova ([1;1;2;2], [1;2;3;4], 'CategoricalFactors', 1.5) ***** error ... anova ([1;1;2;2], [1;2;3;4], 'CategoricalFactors', 2) ***** test a = anova (ones (5, 1), (1:5)'); [T, ems] = stats (a); assert_equal (T.DF(1), 0); assert_equal (T.pValue(1), NaN); assert_equal (cellstr (ems.ExpectedMeanSquares), ... {'V(Error)'; 'V(Error)'}); a = anova (ones (5, 1), (1:5)', 'SumOfSquaresType', 'two'); T = stats (a); assert_equal (T.DF(1), 0); assert_equal (T.pValue(1), NaN); ***** test a = anova (1, 7); T = stats (a); assert_equal (a.NumObservations, 1); assert_equal (T.pValue(1), NaN); ***** test a = anova ([1; 1; 2; 2], ones (4, 1)); T = stats (a); assert_equal (T.SumOfSquares(1), 0); assert_equal (T.DF, [1; 2; 3]); assert_equal (T.F(1), NaN); assert_equal (T.pValue(1), NaN); ***** test g = categorical ([3; 3; 1; 1], [3, 2, 1]); a = anova (g, (1:4)'); T = stats (a); assert_equal (isfinite (T.pValue(1)), true); assert_equal (a.Stats.n, [2, 2]); assert_equal (a.Stats.gnames, {'3'; '1'}); assert_equal (a.Stats.means, [1.5, 3.5]); a = anova (g, (1:4)', 'SumOfSquaresType', 'two'); T = stats (a); assert_equal (T.F(1), 8, 1e-12); assert_equal (a.Stats.grpnames{1}, {'3'; '1'}); ***** test # fitted values are the means of the groups a categorical holds g = categorical ([3; 3; 1; 1], [3, 2, 1]); a = anova (g, (1:4)'); assert_equal (a.FittedValues, [1.5; 1.5; 3.5; 3.5]); ***** test g = kron ((1:120)', ones (2, 1)); a = anova (g, (1:240)'); T = stats (a); assert_equal (T.DF(1), 119); assert_equal (T.DF(2), 120); ***** test n = 128; group = cell (1, 6); for k = 1:6 group{k} = mod (floor ((0:n-1)' / 2^(k-1)), 2) + 1; endfor a = anova (group, (1:n)', 'ModelSpecification', 'full'); stats (a); assert_equal (rows (a.Stats.terms), 63); assert_equal (columns (a.DesignMatrix), 64); ***** test y = [1; 2; 3; 4; 5; 6; 10; 11; 12]; g = [1; 1; 1; 2; 2; 2; 3; 3; 3]; a = anova (g, y, 'FactorNames', {'Treatment'}); [component, ems] = stats (a); assert_equal (istable (component), true); assert_equal (component.Properties.VariableNames, ... {'SumOfSquares', 'DF', 'MeanSquares', 'F', 'pValue'}); assert_equal (component.Properties.RowNames, ... {'Treatment'; 'Error'; 'Total'}); assert_equal (component.SumOfSquares, [126; 6; 132], 1e-12); assert_equal (istable (ems), true); assert_equal (ems.Properties.VariableNames, ... {'Type', 'ExpectedMeanSquares', 'MeanSquaresDenominator', ... 'DFDenominator', 'FDenominator'}); assert_equal (ems.Properties.RowNames, {'Treatment'; 'Error'}); assert_equal (cellstr (ems.Type), {'fixed'; 'random'}); assert_equal (cellstr (ems.ExpectedMeanSquares), ... {'3*Q(Treatment)+V(Error)'; 'V(Error)'}); assert_equal (ems.MeanSquaresDenominator, [1; NaN]); assert_equal (ems.DFDenominator, [6; NaN]); assert_equal (cellstr (ems.FDenominator), {'MS(Error)'; ''}); ***** test y = [1; 2; 3; 4; 5; 6; 10; 11; 12]; g = [1; 1; 1; 2; 2; 2; 3; 3; 3]; a = anova (g, y, 'FactorNames', {'Treatment'}, 'RandomFactors', 1); [~, ems] = stats (a); assert_equal (cellstr (ems.Type), {'random'; 'random'}); assert_equal (cellstr (ems.ExpectedMeanSquares), ... {'3*V(Treatment)+V(Error)'; 'V(Error)'}); ***** test y = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; a = anova (y, [], 'Reps', 3, 'ModelSpecification', 'interactions', ... 'FactorNames', {'Brand', 'PopperType'}); component = stats (a); assert_equal (component.Properties.RowNames, ... {'Brand'; 'PopperType'; 'Brand:PopperType'; 'Error'; 'Total'}); ***** function values = __anova_values__ (tbl) if (istable (tbl)) values = [tbl.SumOfSquares, tbl.DF, tbl.MeanSquares, tbl.F, tbl.pValue]; return; endif if (columns (tbl) == 6) columns_ = [2, 3, 4, 5, 6]; ## anova1 and anova2 layout else columns_ = [2, 3, 5, 6, 7]; ## anovan layout, Mean Sq. after Singular? endif values = NaN (rows (tbl) - 1, numel (columns_)); for i = 2:rows (tbl) for j = 1:numel (columns_) value = tbl{i, columns_(j)}; if (isnumeric (value) && isscalar (value)) values(i - 1, j) = value; endif endfor endfor ***** endfunction ***** test y = [24; 26; 25; 24; 15; 17; 20; 16; 25; 29; 27; 19; 18; 21; 20]; gender = [1; 1; 1; 1; 1; 1; 1; 1; 2; 2; 2; 2; 2; 2; 2]; degree = [1; 1; 1; 1; 0; 0; 0; 0; 1; 1; 1; 0; 0; 0; 0]; a = anova ({gender, degree}, y, 'ModelSpecification', 'full'); component = stats (a, 'component', 'one'); [~, expected] = anovan (y, {gender, degree}, 'model', 'full', ... 'sstype', 1, 'display', 'off'); assert_equal (component.Properties.RowNames, ... {'Factor1'; 'Factor2'; 'Factor1:Factor2'; 'Error'; 'Total'}); assert_equal (__anova_values__ (component), ... __anova_values__ (expected), 1e-10); assert_equal (char (a.SumOfSquaresType), 'three'); assert_equal (istable (stats (a)), true); ***** test y = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; a = anova (y, [], 'Reps', 3, 'ModelSpecification', 'interactions'); component = stats (a, 'Component', 'one'); assert_equal (__anova_values__ (component), ... __anova_values__ (stats (a)), 1e-10); summary_table = stats (a, 'summary'); assert_equal (summary_table.Properties.RowNames, ... {'Linear'; 'NonLinear'; 'Regression'; 'Error'; 'Total'}); assert_equal (summary_table.SumOfSquares(1:3), ... [20.25; 1 / 12; 61 / 3], 1e-10); assert_equal (summary_table.DF(1:3), [3; 2; 5]); assert_equal (summary_table.F(1:3), [48.6; 0.3; 29.28], 1e-10); ***** test x = kron ((0:3)', ones (2, 1)); y = [0; 0.2; 1; 1.2; 4; 4.2; 9; 9.2]; summary_table = stats (anova (x, y, 'CategoricalFactors', []), 'summary'); assert_equal (summary_table.Properties.RowNames, ... {'Linear'; 'Regression'; 'Error'; 'LackOfFit'; ... 'PureError'; 'Total'}); assert_equal (summary_table.SumOfSquares(3:5), [8.08; 8; 0.08], 1e-12); assert_equal (summary_table.DF(3:5), [6; 2; 4]); assert_equal (summary_table.F(4), 200, 1e-10); assert_equal (summary_table.pValue(4), 9.802960494567e-05, 1e-12); g = [ones(10, 1); 2 * ones(10, 1)]; y = [(0:9)'; (1000:1009)']; summary_table = stats (anova (g, y), 'summary'); assert_equal (summary_table.pValue(1) > 0, true); ***** test [demo_code, demo_idx] = test ('anovan', 'grabdemo'); assert_equal (numel (demo_idx) - 1, 13); for k = 1:numel (demo_idx) - 1 code = demo_code(demo_idx(k):demo_idx(k + 1) - 1); code = strrep (code, "'display', 'on'", "'display', 'off'"); code = strrep (code, "anovan (y, g, 'weights', v.^-1)", ... "anovan (y, g, 'weights', v.^-1, 'display', 'off')"); code = regexprep (code, '^ *(figure|plot|xlabel) [^\n]*$', '', 'lineanchors'); eval (code); switch (k) case 1 a = anova (gender, score, 'FactorNames', {'gender'}); case 2 a = anova ({treatment(:), subject(:)}, score(:), ... 'ModelSpecification', 'full', 'RandomFactors', 2, ... 'SumOfSquaresType', 'two', ... 'FactorNames', {'treatment', 'subject'}); case 3 a = anova (alloy, strength, 'FactorNames', {'alloy'}); case 4 a = anova ({seconds(:), subject(:)}, words(:), ... 'ModelSpecification', 'full', 'RandomFactors', 2, ... 'SumOfSquaresType', 'two', ... 'FactorNames', {'seconds', 'subject'}); case 5 a = anova ({brands(:), popper(:)}, popcorn(:), ... 'ModelSpecification', 'full', ... 'FactorNames', {'brands', 'popper'}); case 6 a = anova ({gender, degree}, salary, 'ModelSpecification', 'full', ... 'FactorNames', {'gender', 'degree'}); case 7 a = anova ({sugar, milk}, babble, 'ModelSpecification', 'full', ... 'FactorNames', {'sugar', 'milk'}); case 8 a = anova ({drug(:), feedback(:), diet(:)}, BP(:), ... 'ModelSpecification', 'full', ... 'FactorNames', {'drug', 'feedback', 'diet'}); case 9 a = anova ({strain, treatment, block}, measurement / 10, ... 'ModelSpecification', 'full', 'RandomFactors', 3, ... 'SumOfSquaresType', 'two', ... 'FactorNames', {'strain', 'treatment', 'block'}); case 10 a = anova ({species, temp}, pulse, 'CategoricalFactors', 1, ... 'SumOfSquaresType', 'hierarchical', ... 'FactorNames', {'species', 'temp'}); case 11 model = [1 0 0; 0 1 0; 0 0 1; 1 1 0]; a = anova ({treatment, exercise, age}, score, ... 'ModelSpecification', model, 'CategoricalFactors', [1, 2], ... 'SumOfSquaresType', 'hierarchical', ... 'FactorNames', {'treatment', 'exercise', 'age'}); case 12 a = anova (g, dv, 'FactorNames', {'score'}); case 13 a = anova (g, y, 'Weights', v .^ -1); endswitch switch (k) case 2 [~, ATAB, STATS] = anovan (score(:), ... {treatment(:), subject(:)}, 'model', 'full', 'sstype', 2, ... 'varnames', {'treatment', 'subject'}, 'display', 'off'); case 4 [~, ATAB, STATS] = anovan (words(:), ... {seconds(:), subject(:)}, 'model', 'full', 'sstype', 2, ... 'varnames', {'seconds', 'subject'}, 'display', 'off'); case 9 [~, ATAB, STATS] = anovan (measurement / 10, ... {strain, treatment, block}, 'model', 'full', 'sstype', 2, ... 'varnames', {'strain', 'treatment', 'block'}, ... 'display', 'off'); endswitch actual = stats (a); actual_sources = actual.Properties.RowNames; expected_sources = ATAB(2:end, 1); expected_sources = regexprep (expected_sources, "X([0-9]+)", "Factor$1"); if (strcmp (a.Stats.source, 'anova1')) actual_sources{1} = expected_sources{1}; endif assert_equal (actual_sources, expected_sources); actual_values = __anova_values__ (actual); expected_values = __anova_values__ (ATAB); if (any (k == [2, 4, 9])) assert_equal (actual_values(:, 1:3), expected_values(:, 1:3), 1e-8); else assert_equal (actual_values, expected_values, 1e-8); endif if (! any (k == [1, 3, 12])) if (k == 13) expected_residuals = STATS.Y - full (STATS.X) * STATS.coeffs(:, 1); else expected_residuals = STATS.resid; endif assert_equal (a.Residuals.Raw, expected_residuals, 1e-8); assert_equal (size (a.DesignMatrix), size (STATS.X)); endif endfor ***** test dose = [1; 1; 2; 2; 1; 2]; site = {'A'; 'B'; 'A'; 'B'; 'A'; 'B'}; yield = [1; 2; 4; 5; 2; 6]; tbl = table (dose, site, yield, ... 'VariableNames', {'Dose', 'Site', 'Yield'}); a = anova (tbl, 'Yield'); assert_equal (cellstr (a.FactorNames), {'Dose', 'Site'}); assert_equal (a.ResponseName, 'Yield'); assert_equal (istable (a.Factors), true); assert_equal (a.Factors.Properties.VariableNames, {'Dose', 'Site'}); assert_equal (a.Y, yield); T = stats (a); direct = stats (anova ({dose, site}, yield, ... 'FactorNames', {'Dose', 'Site'})); assert_equal (__anova_values__ (T), __anova_values__ (direct), 1e-12); ***** test dose = [1; 1; 2; 2; 1; 2]; site = {'A'; 'B'; 'A'; 'B'; 'A'; 'B'}; yield = [1; 2; 4; 5; 2; 6]; tbl = table (dose, site, yield, ... 'VariableNames', {'Dose', 'Site', 'Yield'}); a = anova (tbl, 'Yield ~ Dose + Site + Dose:Site'); T = stats (a); direct = stats (anova ({dose, site}, yield, ... 'FactorNames', {'Dose', 'Site'}, ... 'ModelSpecification', 'full')); assert_equal (char (a.Formula.Text), ... 'Yield ~ Dose + Site + Dose:Site'); assert_equal (a.ModelSpecification, char (a.Formula.Text)); assert_equal (__anova_values__ (T), __anova_values__ (direct), 1e-12); ***** test dose = [1; 1; 2; 2]; site = [1; 2; 1; 2]; y = [1; 2; 4; 5]; tbl = table (dose, site, 'VariableNames', {'Dose', 'Site'}); a = anova (tbl, y, 'FactorNames', {'Site'}); assert_equal (cellstr (a.FactorNames), {'Site'}); assert_equal (a.Factors.Site, site); assert_equal (stats (a).DF, [1; 2; 3]); ***** test g1 = [1; 1; 1; 1; 2; 2; 2; 2]; g2 = [1; 1; 2; 2; 1; 1; 2; 2]; y = (1:8)'; a = anova ({g1, g2}, y, 'FactorNames', {'A', 'B'}, ... 'CategoricalFactors', [true, false], 'RandomFactors', 'A'); assert_equal (a.CategoricalFactors, 1); assert_equal (a.RandomFactors, 1); b = anova ({g1, g2}, y, 'FactorNames', {'A', 'B'}, ... 'CategoricalFactors', {'A', 'B'}, 'RandomFactors', 'all'); assert_equal (b.CategoricalFactors, [1, 2]); assert_equal (b.RandomFactors, [1, 2]); ***** test y = [1; 2; 3; 4; 5; 6]; g = [1; 1; 1; 2; 2; 2]; a = anova (g, y, 'SumOfSquaresType', 'two'); stats (a); assert_equal (isvector (a.Coefficients), true); assert_equal (isstring (a.ExpandedFactorNames), true); assert_equal (istable (a.Residuals), true); assert_equal (a.Residuals.Properties.VariableNames, {'Raw', 'Pearson'}); assert_equal (a.Residuals.Pearson, ... a.Residuals.Raw / sqrt (a.Metrics.MSE), 1e-12); assert_equal (a.Metrics.Properties.VariableNames, ... {'MSE', 'RMSE', 'SSE', 'SSR', 'SST', ... 'RSquared', 'AdjustedRSquared'}); assert_equal (a.Metrics.SST, a.Metrics.SSE + a.Metrics.SSR, 1e-12); assert_equal (a.Coefficients, [3.5; -1.5; 1.5], 1e-12); assert_equal (cellstr (a.ExpandedFactorNames), ... {'(Intercept)'; '(Factor1==1)'; '(Factor1==2)'}); ***** test y = [1; 2; 3; 4; 5; 6; 10; 11; 12]; g = [1; 1; 1; 2; 2; 2; 3; 3; 3]; a = anova (g, y); m = multcompare (a); assert_equal (istable (m), true); assert_equal (m.Properties.VariableNames, ... {'Group1', 'Group2', 'MeanDifference', ... 'MeanDifferenceLower', 'MeanDifferenceUpper', 'pValue'}); assert_equal (m.MeanDifference, [-3; -9; -6], 1e-12); v = varianceComponent (a); assert_equal (v.Properties.VariableNames, ... {'VarianceComponent', 'VarianceComponentLower', ... 'VarianceComponentUpper'}); assert_equal (v.Properties.RowNames, {'Error'}); one_group = multcompare (anova (ones (4, 1), (1:4)')); assert_equal (istable (one_group), true); assert_equal (size (one_group), [0, 6]); ***** test g1 = [1; 1; 1; 1; 2; 2; 2; 2]; g2 = {'A'; 'A'; 'B'; 'B'; 'A'; 'A'; 'B'; 'B'}; y = [1; 2; 3; 4; 5; 6; 8; 9]; a = anova ({g1, g2}, y, 'FactorNames', {'Dose', 'Site'}, ... 'ModelSpecification', 'full'); m = multcompare (a, {'Dose', 'Site'}, ... 'CriticalValueType', 'bonferroni'); assert_equal (istable (m.Group1), true); assert_equal (istable (m.Group2), true); assert_equal (m.Group1.Properties.VariableNames, {'Dose', 'Site'}); assert_equal (rows (m), 6); ***** test g1 = {"x, y"; "x, y"; "x, y"; "x, y"; "z=1"; "z=1"; "z=1"; "z=1"}; g2 = {"a=1"; "a=1"; "b,2"; "b,2"; "a=1"; "a=1"; "b,2"; "b,2"}; y = (1:8)'; a = anova ({g1, g2}, y, "FactorNames", {"Dose", "Site"}, ... "ModelSpecification", "full"); m = multcompare (a, {"Dose", "Site"}); values = [m.Group1.Dose; m.Group2.Dose; m.Group1.Site; m.Group2.Site]; assert_equal (any (strcmp (values, "x, y")), true); assert_equal (any (strcmp (values, "z=1")), true); assert_equal (any (strcmp (values, "a=1")), true); assert_equal (any (strcmp (values, "b,2")), true); ***** test g1 = [1; 1; 1; 1; 2; 2; 2; 2]; g2 = [1; 1; 2; 2; 1; 1; 2; 2]; y = (1:8)'; a = anova ({g1, g2}, y, 'FactorNames', {'A', 'B'}, ... 'ResponseName', 'R', ... 'ModelSpecification', 'R ~ A + B + A:B'); assert_equal (char (a.Formula.Text), 'R ~ A + B + A:B'); assert_equal (stats (a).Properties.RowNames, ... {'A'; 'B'; 'A:B'; 'Error'; 'Total'}); b = anova ({g1, g2}, y, 'FactorNames', {'A', 'B'}, ... 'ModelSpecification', 3); assert_equal (b.ModelSpecification, 3); assert_equal (char (b.Formula.Text), 'Y ~ 1 + A + B + A:B'); assert_equal (__anova_values__ (stats (a)), ... __anova_values__ (stats (b)), 1e-12); ***** test tbl = table ([1; 1; 2; 2], [1; 2; 3; 4], ... 'VariableNames', {'Group', 'Yield'}); a = anova (tbl, 'Yield ~ Group', 'FactorNames', {'Yield'}, ... 'ResponseName', 'Ignored', 'ModelSpecification', 'full'); assert_equal (cellstr (a.FactorNames), {'Group'}); assert_equal (a.ResponseName, 'Yield'); assert_equal (a.ModelSpecification, 'Yield ~ Group'); ***** test a = anova ([1; 1; 2; 2], [1; NaN; 3; 4]); stats (a); assert_equal (a.NumObservations, 3); assert_equal (a.Y, [1; 3; 4]); assert_equal (height (a.Factors), 3); assert_equal (height (a.Residuals), 3); ***** test load carsmall a = anova ({Origin, Model_Year}, MPG, "RandomFactors", [1, 2], ... "FactorNames", {"Origin", "Year"}); v = varianceComponent (a); assert_equal (v.Properties.RowNames, {"Origin"; "Year"; "Error"}); assert_equal (v.VarianceComponent, [21.337; 44.031; 20.198], 5e-3); assert_equal (v.VarianceComponentLower, [6.1257; 11.176; 15.298], 5e-3); assert_equal (v.VarianceComponentUpper, [139.94; 1765.7; 27.909], 5e-1); ***** test A = kron ([1; 2], ones (12, 1)); B = repmat (kron ([1; 2; 3], ones (4, 1)), 2, 1); y = 10 + 2 * (A == 2) + ... [0;1;-1;0; 1;0;-1;0; -1;0;1;0; 0;1;0;-1; 2;1;0;1; -1;0;1;0]; a = anova ({A, B}, y, "FactorNames", {"A", "B"}, ... "ModelSpecification", "full", "RandomFactors", 2); [s, ems] = stats (a); assert_equal (s.Properties.RowNames, {"A"; "B"; "A:B"; "Error"; "Total"}); assert_equal (s.F(1:3), [49; 1; 1], 1e-12); assert_equal (cellstr (ems.Type), {"fixed"; "random"; "random"; "random"}); assert_equal (cellstr (ems.FDenominator), ... {"MS(A:B)"; "MS(A:B)"; "MS(Error)"; ""}); v = varianceComponent (a); assert_equal (v.Properties.RowNames, {"B"; "A:B"; "Error"}); ***** test A = kron ([1; 2], ones (12, 1)); B = repmat (kron ([1; 2; 3; 4], ones (3, 1)), 2, 1); y = [5;6;4; 12;13;11; 20;19;21; 8;7;9; ... 7;8;6; 15;14;16; 23;22;24; 10;11;9]; a = anova ({A, B}, y, 'FactorNames', {'A', 'B'}, ... 'ModelSpecification', 'full', 'RandomFactors', 2); v = varianceComponent (a); assert_equal (v.Properties.RowNames, {'B'; 'A:B'; 'Error'}); assert_equal (v.VarianceComponent, ... [45.4166666666666; -0.166666666666666; 1], 1e-9); assert_equal (v.VarianceComponentLower, ... [13.4429180926305; NaN; 0.554682109897800], 1e-9); assert_equal (v.VarianceComponentUpper, ... [632.517205323886; NaN; 2.31626772541430], 1e-8); ***** test A = kron ([1; 2], ones (12, 1)); B = repmat (kron ([1; 2; 3; 4], ones (3, 1)), 2, 1); y = [5;6;4; 12;13;11; 20;19;21; 8;7;9; ... 7;8;6; 15;14;16; 23;22;24; 10;11;9]; y(1:12) += [0;0;0; 1;1;1; -1;-1;-1; 0.4;0.4;0.4]; a = anova ({A, B}, y, 'FactorNames', {'A', 'B'}, ... 'ModelSpecification', 'full', 'RandomFactors', 2); v = varianceComponent (a); assert_equal (v.VarianceComponent(2), 0.253333333333400, 1e-9); assert_equal (v.VarianceComponentLower(2), 0); assert_equal (v.VarianceComponentUpper(2), 7.97098397237600, 1e-9); ***** test x = (-2:2)'; y = 2 + 3 * x + 4 * x .^ 2; a = anova (x, y, "CategoricalFactors", [], ... "ModelSpecification", "purequadratic", ... "FactorNames", {"x"}); s = stats (a); assert_equal (a.Stats.terms, [1; 2]); assert_equal (s.Properties.RowNames, {"x"; "x^2"; "Error"; "Total"}); assert_equal (a.FittedValues, y, 1e-12); ***** test x = [0; 1; 2; 4; 7; 8; 10; 15]; y = [1; 2; 3; 6; 12; 15; 21; 40]; a = anova (x, y, "CategoricalFactors", [], ... "ModelSpecification", [1; 2], ... "SumOfSquaresType", "hierarchical"); s = stats (a); assert_equal (char (a.SumOfSquaresType), "hierarchical"); assert_equal (a.SSType, "h"); assert_equal (s.SumOfSquares(1:2), ... [1149.540669856459; 60.32250042332054], 1e-10); ***** test a = anova ([1; 1; 2; 2], (1:4)', "SumOfSquaresType", "typeii"); assert_equal (char (a.SumOfSquaresType), "two"); ***** test [x1, x2] = ndgrid ((-2:2)', (-1:1)'); x1 = x1(:); x2 = x2(:); y = 1 + 2*x1 + 3*x2 + 4*x1.*x2 + 5*x1.^2 + 6*x2.^2; a = anova ({x1, x2}, y, "CategoricalFactors", [], ... "ModelSpecification", "quadratic"); stats (a); assert_equal (a.Stats.terms, [1 0; 0 1; 1 1; 2 0; 0 2]); assert_equal (a.FittedValues, y, 1e-10); ***** test [x1, x2] = ndgrid ([-1; 1], (-2:2)'); x1 = x1(:); x2 = x2(:); y = x1 + x2.^2 + x2.^3 + x1.*x2 + x1.*x2.^2; a = anova ({x1, x2}, y, "CategoricalFactors", [], ... "ModelSpecification", "poly13"); stats (a); assert_equal (a.Stats.terms, [1 0; 0 1; 0 2; 0 3; 1 1; 1 2]); ***** test x = (-2:2)'; tbl = table (x, 2 + 3*x + 4*x.^2, "VariableNames", {"x", "y"}); a = anova (tbl, "y ~ x^2", "CategoricalFactors", []); stats (a); assert_equal (a.Stats.terms, [1; 2]); assert_equal (a.FittedValues, tbl.y, 1e-12); ***** test A = kron ([1; 2], ones (6, 1)); B = repmat (kron ([1; 2], ones (3, 1)), 2, 1); y = 10*A + 2*B + repmat ([-1; 0; 1], 4, 1); tbl = table (A, B, y, "VariableNames", {"A", "B", "Y"}); a = anova (tbl, "Y ~ A + B(A)"); s = stats (a); assert_equal (a.Stats.terms, [1 0; 0 1]); assert_equal (a.Stats.vnested, logical ([0 0; 1 0])); assert_equal (s.Properties.RowNames, {"A"; "B(A)"; "Error"; "Total"}); assert_equal (s.DF, [1; 2; 8; 11]); ***** test [A, C, B, R] = ndgrid ([1; 2], [1; 2], [1; 2], [1; 2]); A = A(:); C = C(:); B = B(:); R = R(:); y = A + 2*C + 3*B + 0.1*R; tbl = table (A, B, C, y, "VariableNames", {"A", "B", "C", "Y"}); a = anova (tbl, "Y ~ A*C + B(A,C)"); s = stats (a); assert_equal (a.Stats.vnested, logical ([0 0 0; 1 0 1; 0 0 0])); assert_equal (s.Properties.RowNames, ... {"A"; "C"; "A:C"; "B(A,C)"; "Error"; "Total"}); assert_equal (s.DF(4), 4); ***** test x = [1, 5; 2, 6; 3, 7; NaN, 8]; warning ("off", "all", "local"); a = anova (x, [], "Reps", 2, "ModelSpecification", "interactions"); stats (a); assert_equal (a.Stats.source, "anovan"); assert_equal (a.NumObservations, 7); assert_equal (height (a.Residuals), 7); ***** test x = [1, 5; 2, 6; 3, 7; 4, 8]; a = anova (x, [], "Reps", 2, ... "ModelSpecification", [1 0; 0 1], ... "FactorNames", {"A", "B"}); s = stats (a); assert_equal (s.Properties.RowNames, {"A"; "B"; "Error"; "Total"}); ***** test g = [1; 1; 2; 2; 3; 3]; y = [1; 3; 4; 8; 9; 15]; a = anova (g, y, "Weights", [1; 2; 1; 3; 1; 4]); stats (a); assert_equal (a.Residuals.Raw, a.Y - a.FittedValues, 1e-12); ***** error ... anova ([1; 1; 2; 2], (1:4)', "ModelSpecification", "purequadratic") ***** error ... anova ([1;1;2;2], [1;2;3;4], "RandomFactors", 0) ***** error ... anova ([1;1;2;2], [1;2;3;4], "RandomFactors", 2) ***** error popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; plotDiagnostics (anova (popcorn, [], 'reps', 3)); ***** error y = [10; 12; 11; 14; 16; 15; 9; 8; 10]; g = [1;1;1;2;2;2;3;3;3]; plotDiagnostics (anova (g, y, 'SumOfSquaresType', 'two'), 'Visible'); ***** error y = [10; 12; 11; 14; 16; 15; 9; 8; 10]; g = [1;1;1;2;2;2;3;3;3]; plotDiagnostics (anova (g, y, 'SumOfSquaresType', 'two'), 'BadOption', true); ***** error y = [10; 12; 11; 14; 16; 15; 9; 8; 10]; g = [1;1;1;2;2;2;3;3;3]; predict (anova (g, y, 'SumOfSquaresType', 'two'), ones (2, 2)); ***** error a = anova ([1; 1; 2; 2], (1:4)'); stats (a, 'Component', 1); ***** error a = anova ([1; 1; 2; 2], (1:4)'); stats (a, 'Component', 'typei'); ***** error a = anova ([1; 1; 2; 2], (1:4)'); stats (a, 'details'); ***** error a = anova ([1; 1; 2; 2], (1:4)'); stats (a, 'summary', 'one'); ***** test y = [444 614 423 625 408 856 447 719 ... 764 831 586 782 609 1002 606 766]' / 10; X1 = {'NIH','NIH','BALB/C','BALB/C','A/J','A/J','129/Ola','129/Ola', ... 'NIH','NIH','BALB/C','BALB/C','A/J','A/J','129/Ola','129/Ola'}'; X2 = {'C','T','C','T','C','T','C','T','C','T','C','T','C','T','C','T'}'; X3 = [1;1;1;1;1;1;1;1;2;2;2;2;2;2;2;2]; a = anova ({X1, X2, X3}, y, 'ModelSpecification', 'full', ... 'RandomFactors', 3, 'FactorNames', {'X1', 'X2', 'X3'}); s = stats (a); assert_equal (s.DF', [3, 1, 1, 3, 3, 1, 3, 0, 15]); assert_equal (s.SumOfSquares(8), 0); assert_equal (s.pValue(1:6), ... [0.288811428913179; 0.091455278902114; 0.042134889025806; ... 0.010944863181481; 0.061814763198376; 0.066584161056625], ... 1e-12); assert_equal (s.pValue(7), NaN); ***** test y = [444 614 423 625 408 856 447 719 ... 764 831 586 782 609 1002 606 766]' / 10; X1 = {'NIH','NIH','BALB/C','BALB/C','A/J','A/J','129/Ola','129/Ola', ... 'NIH','NIH','BALB/C','BALB/C','A/J','A/J','129/Ola','129/Ola'}'; X2 = {'C','T','C','T','C','T','C','T','C','T','C','T','C','T','C','T'}'; X3 = [1;1;1;1;1;1;1;1;2;2;2;2;2;2;2;2]; a = anova ({X1, X2, X3}, y, 'ModelSpecification', 'full', ... 'RandomFactors', 3, 'FactorNames', {'X1', 'X2', 'X3'}); [~, ems] = stats (a); assert_equal (ems.MeanSquaresDenominator(1:7), ... [47.1575; 47.61; 88.7925; 5.975; 5.975; 5.975; 0], 1e-9); assert_equal (ems.DFDenominator(1:7), ... [3; 1; 2.610727841363640; 3; 3; 3; 0], 1e-12); ***** test y = [444 614 423 625 408 856 447 719 ... 764 831 586 782 609 1002 606 766]' / 10; X1 = {'NIH','NIH','BALB/C','BALB/C','A/J','A/J','129/Ola','129/Ola', ... 'NIH','NIH','BALB/C','BALB/C','A/J','A/J','129/Ola','129/Ola'}'; X2 = {'C','T','C','T','C','T','C','T','C','T','C','T','C','T','C','T'}'; X3 = [1;1;1;1;1;1;1;1;2;2;2;2;2;2;2;2]; a = anova ({X1, X2, X3}, y, 'ModelSpecification', 'full', ... 'RandomFactors', 3, 'FactorNames', {'X1', 'X2', 'X3'}); [~, ems] = stats (a); assert_equal (cellstr (ems.ExpectedMeanSquares), ... {'4*Q(X1)+2*Q(X1:X2)+2*V(X1:X3)+V(X1:X2:X3)+V(Error)'; ... '8*Q(X2)+2*Q(X1:X2)+4*V(X2:X3)+V(X1:X2:X3)+V(Error)'; ... '8*V(X3)+2*V(X1:X3)+4*V(X2:X3)+V(X1:X2:X3)+V(Error)'; ... '2*Q(X1:X2)+V(X1:X2:X3)+V(Error)'; ... '2*V(X1:X3)+V(X1:X2:X3)+V(Error)'; ... '4*V(X2:X3)+V(X1:X2:X3)+V(Error)'; ... 'V(X1:X2:X3)+V(Error)'; 'V(Error)'}); ***** test y = [3; 4; 7; 8]; [~, tbl] = anovan (y, {[1;1;2;2], [1;2;1;2]}, 'model', 'full', ... 'display', 'off'); assert_equal (tbl{end-1, 2}, 0); assert_equal (tbl{end-1, 3}, 0); assert_equal (tbl{end-1, 5}, 0); 124 tests, 124 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/chi2test.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/chi2test.m ***** function p = chi2p (varargin) [~, p] = chi2test (varargin{:}); ***** endfunction ***** test ## Below the resolution of 1 - chi2cdf [~, p, st] = chi2test ([300, 100; 100, 300]); assert_equal (p, erfc (sqrt (st.chi2stat / 2)), -1e-12); ***** test x = [11, 3, 8; 2, 9, 14; 12, 13, 28]; [~, p] = chi2test (x); assert_equal (p, 0.017787, 1e-6); ***** test x = [11, 3, 8; 2, 9, 14; 12, 13, 28]; [~, ~, st] = chi2test (x); assert_equal (st.chi2stat, 11.9421, 1e-4); ***** test x = [11, 3, 8; 2, 9, 14; 12, 13, 28]; [~, ~, st] = chi2test (x); assert_equal (st.df, 4); ***** test x = [11, 3, 8; 2, 9, 14; 12, 13, 28]; [~, ~, st] = chi2test (x); assert_equal (st.O, x); ***** assert_equal (chi2test ([11, 3, 8; 2, 9, 14; 12, 13, 28]), 1) ***** assert_equal (chi2test ([11, 3, 8; 2, 9, 14; 12, 13, 28], 'Alpha', 0.01), 0) ***** test ## Effect sizes corrected for bias; the intervals are R's inversion of ## pchisq with ncp by uniroot x = [11, 3, 8; 2, 9, 14; 12, 13, 28]; [~, ~, st] = chi2test (x); assert_equal (st.CohensW, sqrt ((st.chi2stat - 4) / 100), -1e-14); ***** test [~, ~, st] = chi2test ([11, 3, 8; 2, 9, 14; 12, 13, 28]); assert_equal (st.CohensWCI, [0.054364192439641336, 0.50550722873705722], ... -1e-10); ***** test [~, ~, st] = chi2test ([11, 3, 8; 2, 9, 14; 12, 13, 28]); assert_equal (st.CramersV, 0.19927484317340177, -1e-12); ***** test [~, ~, st] = chi2test ([11, 3, 8; 2, 9, 14; 12, 13, 28]); assert_equal (st.CramersVCI, ... [0.054364192439641336, 0.50550722873705722] / sqrt (2), ... -1e-10); ***** test ## A higher confidence level widens the interval on both sides x = [11, 3, 8; 2, 9, 14; 12, 13, 28]; [~, ~, s95] = chi2test (x); [~, ~, s99] = chi2test (x, 'Alpha', 0.01); assert_equal ([s99.CohensWCI(1) < s95.CohensWCI(1), ... s99.CohensWCI(2) > s95.CohensWCI(2)], [true, true]); ***** test ***** shared x x(:,:,1) = [59, 32; 9,16]; x(:,:,2) = [55, 24;12,33]; x(:,:,3) = [107,80;17,56]; ***** assert_equal (chi2p (x), 2.282063427117009e-11, 1e-14); ***** assert_equal (chi2p (x, 'mutual', []), 2.282063427117009e-11, 1e-14); ***** assert_equal (chi2p (x, 'joint', 1), 1.164834895206468e-11, 1e-14); ***** assert_equal (chi2p (x, 'joint', 2), 7.771350230001417e-11, 1e-14); ***** assert_equal (chi2p (x, 'joint', 3), 0.07151361728026107, 1e-14); ***** assert_equal (chi2p (x, 'marginal', 1), 0.12455768155123595, -1e-12); ***** assert_equal (chi2p (x, 'marginal', 2), 0.039793350279010681, -1e-12); ***** assert_equal (chi2p (x, 'marginal', 3), 9.0141038839122684e-13, -1e-12); ***** assert_equal (chi2p (x, 'conditional', 1), 0.2303114201312508, 1e-14); ***** assert_equal (chi2p (x, 'conditional', 2), 0.0958810684407079, 1e-14); ***** assert_equal (chi2p (x, 'conditional', 3), 2.648037344954446e-11, 1e-14); ***** assert_equal (chi2p (x, 'homogeneous', []), 0.57357539370887889, -1e-10); ***** assert_equal (chi2p (x, 'homogeneous'), chi2p (x, 'homogeneous', [])); ***** assert_equal (chi2p (x, 'mutual'), chi2p (x)); ***** assert_equal (chi2p (x, 'joint', 3, 'Alpha', 0.01), chi2p (x, 'joint', 3)); ***** test [~, ~, st] = chi2test (x); assert_equal (st.chi2stat, 64.0982, 1e-4); assert_equal (st.df, 7); assert_equal (st.E(:,:,1), [42.903, 39.921; 17.185, 15.991], 1e-3); ***** test [~, ~, st] = chi2test (x, 'joint', 2); assert_equal (st.chi2stat, 56.0943, 1e-4); assert_equal (st.df, 5); assert_equal (st.E(:,:,2), [40.922, 38.078; 23.310, 21.690], 1e-3); ***** test [~, ~, st] = chi2test (x, 'marginal', 3); assert_equal (st.chi2stat, 51.0479, 1e-4); assert_equal (st.df, 1); assert_equal (st.O, sum (x, 3)); assert_equal (st.E, [184.926, 172.074; 74.074, 68.926], 1e-3); ***** test [~, ~, st] = chi2test (x, 'conditional', 3); assert_equal (st.chi2stat, 52.2509, 1e-4); assert_equal (st.df, 3); assert_equal (st.E(:,:,1), [53.345, 37.655; 14.655, 10.345], 1e-3); ***** test [~, ~, st] = chi2test (x, 'homogeneous', []); assert_equal (st.chi2stat, 1.1117, 1e-4); assert_equal (st.df, 2); assert_equal (st.E(:,:,1), [60.469, 30.531; 7.531, 17.469], 1e-3); ***** test ## The homogeneous model reproduces every two-way margin [~, ~, st] = chi2test (x, 'homogeneous'); E = st.E; assert_equal ([sum(E, 1)(:); sum(E, 2)(:); sum(E, 3)(:)], ... [sum(x, 1)(:); sum(x, 2)(:); sum(x, 3)(:)], -1e-10); ***** test ## 'joint' measures V on the table flattened to its variable against the ## other two; bounds from R as above [h, ~, st] = chi2test (x, 'joint', 3, 'Alpha', 0.01); assert_equal (st.CohensWCI, [0, 0.24137302257386881], -1e-10); ***** test [~, ~, st] = chi2test (x, 'marginal', 3); assert_equal (st.CramersV, 0.31637908166758733, -1e-12); ***** test [~, ~, st] = chi2test (x, 'marginal', 3); assert_equal (st.CohensWCI, [0.23187195991809992, 0.40717646803341606], ... -1e-10); ***** test ## No two-way table, no Cramer's V [~, ~, st] = chi2test (x, 'conditional', 3); assert_equal (isfield (st, 'CramersV'), false); ***** test [~, ~, st] = chi2test (x); assert_equal (isfield (st, 'CramersV'), false); ***** test ## E keeps the layout of a table whose dimensions differ y = reshape ([12 7 3 9 15 4 6 8 11 5 14 2 9 10 3 7 6 13], [3, 2, 3]); [~, ~, st] = chi2test (y, 'joint', 2); assert_equal (sum (st.E, 2), sum (y, 2), -1e-12); ***** test y = reshape ([12 7 3 9 15 4 6 8 11 5 14 2 9 10 3 7 6 13], [3, 2, 3]); [~, ~, st] = chi2test (y, 'conditional', 2); assert_equal (size (st.E), [3, 2, 3]); ***** test ## Chi-squares of R's loglin on a 3-by-2-by-3 table y = reshape ([12 7 3 9 15 4 6 8 11 5 14 2 9 10 3 7 6 13], [3, 2, 3]); [~, ~, st] = chi2test (y, 'homogeneous'); assert_equal (st.chi2stat, 15.05772742, -1e-9); ***** test ## Marginal independence is tested in the collapsed table, as R's ## chisq.test does it y = reshape ([12 7 3 9 15 4 6 8 11 5 14 2 9 10 3 7 6 13], [3, 2, 3]); [~, ~, st] = chi2test (y, 'marginal', 2); assert_equal ([st.chi2stat, st.df], [7.584460, 4], -1e-6); ***** warning h = chi2test (ones (2)); ***** warning h = chi2test (ones (3, 2)); ***** warning h = chi2test (0.4 * ones (3)); ***** error chi2test (); ***** error chi2test ([1, 2, 3, 4, 5]); ***** error ... chi2test ([1, 2; 2, 1+3i]); ***** error ... chi2test ([NaN, 6; 34, 12]); ***** error ... chi2test (ones (3, 3), 'mutual', []); ***** error ... chi2test (ones (3, 3, 3, 4), 'mutual'); ***** error ... chi2test (ones (3, 3, 3), 'testtype', 2); ***** error ... chi2test (ones (3, 3), 'testtype', 2); ***** error ... chi2test (ones (3, 3, 3), 'joint'); ***** error ... chi2test (ones (3, 3), 'Alpha'); ***** error ... chi2test (ones (3, 3, 3), 'joint', 'a'); ***** error ... chi2test (ones (3, 3, 3), 'joint', [2, 3]); ***** error ... chi2test (ones (3, 3, 3), 'joint', 4); ***** error ... chi2test (ones (3, 3, 3), 'marginal', []); ***** error chi2test (ones (3, 3), 'Alpha', 0); ***** error chi2test (ones (3, 3), 'Alpha', 1.5); ***** error ... chi2test (ones (3, 3), 'Alpha', [0.1, 0.2]); 63 tests, 63 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/hotelling_t2test.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/hotelling_t2test.m ***** test ## Below the resolution of 1 - fcdf u = (1:30)'; [~, p, st] = hotelling_t2test ([u, sin(u)] + 100); F = (30 - 2) * st.t2stat / (2 * 29); d1 = st.df1; d2 = st.df2; assert_equal (p, betainc (d2 / (d2 + d1 * F), d2 / 2, d1 / 2), -1e-12); ***** test u = (1:30)'; [~, ~, st] = hotelling_t2test ([u / 30, sin(u)] + [0.3, 0.2]); assert_equal (st.fstat, (30 - 2) * st.t2stat / (2 * 29), -1e-14); ***** test ## The bounds are those of R's pf with ncp, inverted by uniroot u = (1:30)'; [~, ~, st] = hotelling_t2test ([u / 30, sin(u)] + [0.3, 0.2]); assert_equal (st.MahalanobisD, 2.6950446312948171, -1e-12); ***** test u = (1:30)'; [~, ~, st] = hotelling_t2test ([u / 30, sin(u)] + [0.3, 0.2]); assert_equal (st.MahalanobisDCI, ... [1.9814725140791032, 3.6141479420615656], -1e-8); ***** test u = (1:30)'; [~, ~, st] = hotelling_t2test ([u / 30, sin(u)] + [0.3, 0.2], [0, 0], ... 'alpha', 0.01); assert_equal (st.MahalanobisDCI, ... [1.7453752693724904, 3.8881257650035739], -1e-7); ***** test ## Beyond a noncentrality of 1e5 the interval is not computed u = (1:30)'; [~, ~, st] = hotelling_t2test ([u / 30, sin(u)] + 100); assert_equal (st.MahalanobisDCI, [NaN, NaN]); ***** error hotelling_t2test (); ***** error ... hotelling_t2test (1); ***** error ... hotelling_t2test (ones (2,2,2)); ***** error ... hotelling_t2test (ones (20,2), [0, 0], 'alpha', 1); ***** error ... hotelling_t2test (ones (20,2), [0, 0], 'alpha', -0.2); ***** error ... hotelling_t2test (ones (20,2), [0, 0], 'alpha', 'a'); ***** error ... hotelling_t2test (ones (20,2), [0, 0], 'alpha', [0.01, 0.05]); ***** error ... hotelling_t2test (ones (20,2), [0, 0], 'name', 0.01); ***** error ... hotelling_t2test (ones (20,1), [0, 0]); ***** error ... hotelling_t2test (ones (4,5), [0, 0, 0, 0, 0]); ***** error ... hotelling_t2test (ones (20,5), [0, 0, 0, 0]); ***** test randn ('seed', 1); x = randn (50000, 5); [h, pval, stats] = hotelling_t2test (x); assert_equal (h, 0); assert_equal (stats.df1, 5); assert_equal (stats.df2, 49995); ***** test randn ('seed', 1); x = randn (50000, 5); [h, pval, stats] = hotelling_t2test (x, ones (1, 5) * 10); assert_equal (h, 1); assert_equal (stats.df1, 5); assert_equal (stats.df2, 49995); 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/kstest2.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/kstest2.m ***** error kstest2 ([1,2,3,4,5,5]) ***** error kstest2 (ones (2,4), [1,2,3,4,5,5]) ***** error kstest2 ([2,3,5,7,3+3i], [1,2,3,4,5,5]) ***** error kstest2 ([2,3,4,5,6],[3;5;7;8;7;6;5],'tail') ***** error kstest2 ([2,3,4,5,6],[3;5;7;8;7;6;5],'tail', 'whatever') ***** error kstest2 ([2,3,4,5,6],[3;5;7;8;7;6;5],'badoption', 0.51) ***** error kstest2 ([2,3,4,5,6],[3;5;7;8;7;6;5],'tail', 0) ***** error kstest2 ([2,3,4,5,6],[3;5;7;8;7;6;5],'alpha', 0) ***** error kstest2 ([2,3,4,5,6],[3;5;7;8;7;6;5],'alpha', NaN) ***** error kstest2 ([NaN,NaN,NaN,NaN,NaN],[3;5;7;8;7;6;5],'tail', 'unequal') ***** test load examgrades [h, p] = kstest2 (grades(:,1), grades(:,2)); assert_equal (h, false); assert_equal (p, 0.1222791870137312, 1e-14); ***** test load examgrades [h, p] = kstest2 (grades(:,1), grades(:,2), 'tail', 'larger'); assert_equal (h, false); assert_equal (p, 0.1844421391011258, 1e-14); ***** test load examgrades [h, p] = kstest2 (grades(:,1), grades(:,2), 'tail', 'smaller'); assert_equal (h, false); assert_equal (p, 0.06115357930171663, 1e-14); ***** test load examgrades [h, p] = kstest2 (grades(:,1), grades(:,2), 'tail', 'smaller', 'alpha', 0.1); assert_equal (h, true); assert_equal (p, 0.06115357930171663, 1e-14); 14 tests, 14 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/ttest2.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/ttest2.m ***** test a = 1:5; b = 6:10; b(5) = NaN; [h,p,ci,stats] = ttest2 (a,b); assert_equal (h, 1); assert_equal (p, 0.002535996080258229, 1e-14); assert_equal (ci, [-6.822014919225481, -2.17798508077452], 1e-14); assert_equal (stats.tstat, -4.582575694955839, 1e-14); assert_equal (stats.df, 7); assert_equal (stats.sd, 1.4638501094228, 1e-13); ***** test ## Below the resolution of 1 - tcdf, values from MATLAB R2024a x = 10 + sin (1:30)'; [~, pval] = ttest2 (x, x - 20); assert_equal (pval, 4.62837535481253e-68, -1e-13); ***** test x = 10 + sin (1:30)'; [~, pval] = ttest2 (x, x - 20, 'tail', 'right'); assert_equal (pval, 2.31418767740626e-68, -1e-13); ***** error ttest2 ([8:0.1:12], [8:0.1:12], 'tail', 'invalid'); ***** error ttest2 ([8:0.1:12], [8:0.1:12], 'tail', 25); ***** shared x, y, xm x = [10.2 9.7 11.1 10.5 9.9 10.8 10.1 9.6 10.4 10.7]; y = [11.4 10.9 12.6 11.1 13.2 10.4 12.8 11.7]; xm = [10.2 11.4; 9.7 10.9; 11.1 12.6; 10.5 11.1; 9.9 13.2]; ***** test [h, p, ci, stats] = ttest2 (x, y, 'Vartype', 'equal'); assert_equal (h, 1); assert_equal (p, 8.895270853487265e-04, 1e-15); assert_equal (ci, [-2.224122032184765, -0.700877967815235], 1e-13); assert_equal (stats.tstat, -4.070735048482627, 1e-13); assert_equal (stats.df, 16); assert_equal (stats.sd, 0.757411298436985, 1e-14); ***** test ## Welch: a pooled denominator would give the 'equal' answer instead [h, p, ci, stats] = ttest2 (x, y, 'Vartype', 'unequal'); assert_equal (h, 1); assert_equal (p, 0.003801117252046, 1e-14); assert_equal (ci, [-2.327640087870322, -0.597359912129679], 1e-13); assert_equal (stats.tstat, -3.784559445642580, 1e-13); assert_equal (stats.df, 9.661941319801253, 1e-13); assert_equal (stats.sd(:)', [0.489897948556636, 1.001338390070295], 1e-14); ***** test ## the default is the equal-variance test [~, pd] = ttest2 (x, y); [~, pe] = ttest2 (x, y, 'Vartype', 'equal'); [~, pu] = ttest2 (x, y, 'Vartype', 'unequal'); assert_equal (pd, pe, 0); assert_equal (isequal (pd, pu), false); ***** test [h, p, ci] = ttest2 (x, y, 'Tail', 'left'); assert_equal (h, 1); assert_equal (p, 4.447635426743633e-04, 1e-15); assert_equal (ci, [-Inf, -0.835253361212791], 1e-13); ***** test [h, p, ci] = ttest2 (x, y, 'Tail', 'right'); assert_equal (h, 0); assert_equal (p, 0.999555236457326, 1e-14); assert_equal (ci, [-2.089746638787210, Inf], 1e-13); ***** test ## a non-default alpha must widen the interval and leave the p-value alone [~, p1, ci1] = ttest2 (x, y); [~, p2, ci2] = ttest2 (x, y, 'Alpha', 0.01); assert_equal (ci2, [-2.511854249766015, -0.413145750233985], 1e-13); assert_equal (diff (ci2) > diff (ci1), true); assert_equal (p1, p2, 0); ***** test [h, p] = ttest2 (xm, xm + 1, 'Dim', 1); assert_equal (h, [1, 0]); assert_equal (p, [0.020600636177229, 0.154833732538475], 1e-13); ***** error ... ttest2 ([8:0.1:12], [9:0.1:13], 'Alpha', -0.05); ***** error ... ttest2 ([8:0.1:12], [9:0.1:13], 'Alpha', 0); ***** error ... ttest2 ([8:0.1:12], [9:0.1:13], 'Alpha', 1); ***** error ... ttest2 ([8:0.1:12], [9:0.1:13], 'Alpha', 1.5); ***** error ... ttest2 ([8:0.1:12], [9:0.1:13], 'Alpha', [0.01, 0.05]); ***** error ... ttest2 ([8:0.1:12], [9:0.1:13], 'Alpha', 'a'); ***** error ... ttest2 ([8:0.1:12], [9:0.1:13], 'Alpha', NaN); ***** error ... ttest2 ([8:0.1:12], [9:0.1:13], 'Alpha', 2 + 1i); 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/ztest2.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/ztest2.m ***** test ## Values from R's prop.test without continuity correction [h, p] = ztest2 (30, 100, 18, 100); assert_equal ([h, p], [1, 0.046944726978481718], -1e-12); ***** test [~, ~, ~, st] = ztest2 (30, 100, 18, 100); assert_equal (st.zval ^ 2, 3.9473684210526314, -1e-12); ***** test ## Newcombe's interval, from the Wilson intervals of R's prop.test [~, ~, ci] = ztest2 (30, 100, 18, 100); assert_equal (ci, [0.0013340883914530755, 0.23469812426823411], -1e-12); ***** test [h, p] = ztest2 (45, 60, 20, 70, 'tail', 'right'); assert_equal ([h, p], [1, 6.5305496467962847e-08], -1e-12); ***** test [~, ~, ci] = ztest2 (45, 60, 20, 70, 'tail', 'right'); assert_equal (ci, [0.32502269598878675, 1], -1e-12); ***** test [~, ~, ci] = ztest2 (45, 60, 20, 70, 'tail', 'left'); assert_equal (ci(1), -1); ***** test [h, p] = ztest2 (30, 100, 18, 100, 'alpha', 0.01); assert_equal (h, 0); ***** test ## Below the resolution of 1 - normcdf [~, p] = ztest2 (900, 1000, 300, 1000); assert_equal (p, 4.01237554141706e-165, -1e-10); ***** test [~, ~, ~, st] = ztest2 (30, 100, 18, 100); assert_equal (st.CohensH, 2 * asin (sqrt (0.3)) - 2 * asin (sqrt (0.18)), ... -1e-14); ***** test [~, ~, ~, st] = ztest2 (30, 100, 18, 100); assert_equal (st.CohensHCI, ... st.CohensH + [-1, 1] * norminv (0.975) * sqrt (2 / 100), ... -1e-14); ***** test [~, ~, ~, st] = ztest2 (45, 60, 20, 70, 'tail', 'right'); assert_equal (st.CohensHCI(2), pi); ***** test ## One row of the interval per test [~, ~, ci, st] = ztest2 ([30; 45], [100; 60], [18; 20], [100; 70]); assert_equal (size (ci), [2, 2]); ***** test [~, ~, ci] = ztest2 ([30; 45], [100; 60], [18; 20], [100; 70]); [~, ~, c1] = ztest2 (45, 60, 20, 70); assert_equal (ci(2,:), c1); ***** error ztest2 (); ***** error ztest2 (1); ***** error ztest2 (1, 2); ***** error ztest2 (1, 2, 3); ***** error ztest2 (1, 2, 3, 2); ***** error ... ztest2 (1, 2, 3, 4, 'alpha') ***** error ... ztest2 (1, 2, 3, 4, 'alpha', 0); ***** error ... ztest2 (1, 2, 3, 4, 'alpha', 1.2); ***** error ... ztest2 (1, 2, 3, 4, 'alpha', 'val'); ***** error ... ztest2 (1, 2, 3, 4, 'tail', 'val'); ***** error ... ztest2 (1, 2, 3, 4, 'alpha', 0.01, 'tail', 'val'); ***** error ... ztest2 (1, 2, 3, 4, 'alpha', 0.01, 'tail', 'both', 'badoption', 3); 25 tests, 25 passed, 0 known failure, 0 skipped [inst/Hypothesis_Testing/anova1.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Hypothesis_Testing/anova1.m ***** demo rng (42); x = meshgrid (1:6); x = x + normrnd (0, 1, 6, 6); anova1 (x, [], 'off'); ***** demo rng (42); x = meshgrid (1:6); x = x + normrnd (0, 1, 6, 6); [p, atab] = anova1 (x); ***** demo rng (42); x = ones (50, 4) .* [-2, 0, 1, 5]; x = x + normrnd (0, 2, 50, 4); groups = {'A', 'B', 'C', 'D'}; anova1 (x, groups); ***** demo y = [54 87 45; 23 98 39; 45 64 51; 54 77 49; 45 89 50; 47 NaN 55]; g = [1 2 3 ; 1 2 3 ; 1 2 3 ; 1 2 3 ; 1 2 3 ; 1 2 3 ]; anova1 (y(:), g(:), 'on', 'unequal'); ***** test data = [1.006, 0.996, 0.998, 1.000, 0.992, 0.993, 1.002, 0.999, 0.994, 1.000, ... 0.998, 1.006, 1.000, 1.002, 0.997, 0.998, 0.996, 1.000, 1.006, 0.988, ... 0.991, 0.987, 0.997, 0.999, 0.995, 0.994, 1.000, 0.999, 0.996, 0.996, ... 1.005, 1.002, 0.994, 1.000, 0.995, 0.994, 0.998, 0.996, 1.002, 0.996, ... 0.998, 0.998, 0.982, 0.990, 1.002, 0.984, 0.996, 0.993, 0.980, 0.996, ... 1.009, 1.013, 1.009, 0.997, 0.988, 1.002, 0.995, 0.998, 0.981, 0.996, ... 0.990, 1.004, 0.996, 1.001, 0.998, 1.000, 1.018, 1.010, 0.996, 1.002, ... 0.998, 1.000, 1.006, 1.000, 1.002, 0.996, 0.998, 0.996, 1.002, 1.006, ... 1.002, 0.998, 0.996, 0.995, 0.996, 1.004, 1.004, 0.998, 0.999, 0.991, ... 0.991, 0.995, 0.984, 0.994, 0.997, 0.997, 0.991, 0.998, 1.004, 0.997]; group = [1:10] .* ones (10,10); group = group(:); [p, tbl] = anova1 (data, group, 'off'); assert_equal (p, 0.022661, 1e-6); assert_equal (tbl{2,5}, 2.2969, 1e-4); assert_equal (tbl{2,3}, 9, 0); assert_equal (tbl{4,2}, 0.003903, 1e-6); data = reshape (data, 10, 10); [p, tbl, stats] = anova1 (data, [], 'off'); assert_equal (p, 0.022661, 1e-6); assert_equal (tbl{2,5}, 2.2969, 1e-4); assert_equal (tbl{2,3}, 9, 0); assert_equal (tbl{4,2}, 0.003903, 1e-6); means = [0.998, 0.9991, 0.9954, 0.9982, 0.9919, 0.9988, 1.0015, 1.0004, 0.9983, 0.9948]; N = 10 * ones (1, 10); assert_equal (stats.means, means, 1e-6); assert_equal (length (stats.gnames), 10, 0); assert_equal (stats.n, N, 0); ***** test y = [54 87 45; 23 98 39; 45 64 51; 54 77 49; 45 89 50; 47 NaN 55]; g = [1 2 3 ; 1 2 3 ; 1 2 3 ; 1 2 3 ; 1 2 3 ; 1 2 3 ]; [p, tbl] = anova1 (y(:), g(:), 'off', 'equal'); assert_equal (p, 0.00004163, 1e-6); assert_equal (tbl(1,:), {'Source', 'SS', 'df', 'MS', 'F', 'Prob>F'}); assert_equal (tbl{2,5}, 22.573418, 1e-6); assert_equal (tbl{2,3}, 2, 0); assert_equal (tbl{3,3}, 14, 0); [p, tbl] = anova1 (y(:), g(:), 'off', 'unequal'); assert_equal (p, 0.00208877, 1e-8); assert_equal (size (tbl), [2, 5]); assert_equal (tbl(1,:), {'Source', 'F', 'df', 'dfe', 'Prob>F'}); assert_equal (tbl{2,2}, 15.523192, 1e-6); assert_equal (tbl{2,3}, 2, 0); assert_equal (tbl{2,4}, 7.5786897, 1e-6); ***** test y = [54, 87, 45; 23, 98, 39; 45, 64, 51; ... 54, 77, 49; 45, 89, 50; 47, NaN, 55]; g = categorical ([1, 2, 3; 1, 2, 3; 1, 2, 3; 1, 2, 3; 1, 2, 3; 1, 2, 3]); [p, tbl] = anova1 (y(:), g(:), 'off', 'equal'); assert_equal (p, 0.00004163, 1e-6); assert_equal (tbl(1,:), {'Source', 'SS', 'df', 'MS', 'F', 'Prob>F'}); assert_equal (tbl{2,5}, 22.573418, 1e-6); assert_equal (tbl{2,3}, 2, 0); assert_equal (tbl{3,3}, 14, 0); [p, tbl] = anova1 (y(:), g(:), 'off', 'unequal'); assert_equal (p, 0.00208877, 1e-8); assert_equal (size (tbl), [2, 5]); assert_equal (tbl(1,:), {'Source', 'F', 'df', 'dfe', 'Prob>F'}); assert_equal (tbl{2,2}, 15.523192, 1e-6); assert_equal (tbl{2,3}, 2, 0); assert_equal (tbl{2,4}, 7.5786897, 1e-6); ***** test y = [10; 20; 9999; NaN; 40; 50]; g = [1; 1; NaN; 1; 2; 2]; [p, tbl, stats] = anova1 (y, g, 'off'); assert_equal (p, 0.051317, 1e-6); assert_equal (tbl{2,5}, 18, 1e-6); assert_equal (tbl{2,3}, 1, 0); assert_equal (tbl{3,3}, 2, 0); assert_equal (tbl{4,3}, 3, 0); assert_equal (stats.n, [2, 2], 0); ***** test y = [1e12 + (1:10), -1e12 + (1:10)](:); g = [ones(10, 1); 2 * ones(10, 1)]; [~, ~, stats] = anova1 (y, g, 'off', 'unequal'); assert_equal (stats.vars, [55 / 6, 55 / 6], 1e-10); ***** test [p, tbl] = anova1 ((1:5)', ones (5, 1), 'off'); assert_equal (p, NaN); assert_equal (tbl{2, 3}, 0); assert_equal (tbl{3, 2}, 10); [p, tbl] = anova1 (7, 1, 'off'); assert_equal (p, NaN); assert_equal (tbl{3, 3}, 0); ***** test [p, tbl] = anova1 ([1; 2], [1; 2], 'off'); assert_equal (p, 0); assert_equal (tbl{2, 2}, 0.5); assert_equal (tbl{2, 3}, 1); assert_equal (tbl{3, 2}, 0); assert_equal (tbl{3, 3}, 0); ***** test [p, tbl] = anova1 (ones (6, 1), [1; 1; 1; 2; 2; 2], 'off'); assert_equal (p, NaN); assert_equal (tbl{2, 5}, NaN); assert_equal (tbl{2, 2}, 0); assert_equal (tbl{2, 3}, 1); assert_equal (tbl{3, 2}, 0); assert_equal (tbl{3, 3}, 4); ***** test y = (1:6)'; g = categorical ([1; 1; 3; 3; 3; 1], [1, 2, 3]); [p, tbl, stats] = anova1 (y, g, 'off'); [p_ref, tbl_ref] = anova1 (y, [1; 1; 2; 2; 2; 1], 'off'); assert_equal (p, p_ref, 1e-12); assert_equal (tbl, tbl_ref); assert_equal (stats.n, [3, 3]); assert_equal (stats.gnames, {'1'; '3'}); assert_equal (stats.means, [3, 4]); g = categorical ([3; 3; 1; 1], [3, 2, 1]); [~, ~, stats] = anova1 ((1:4)', g, 'off'); assert_equal (stats.gnames, {'3'; '1'}); assert_equal (stats.means, [1.5, 3.5]); ***** test g = kron ((1:120)', ones (2, 1)); [p, tbl, stats] = anova1 ((1:240)', g, 'off'); assert_equal (isfinite (p), true); assert_equal (tbl{2, 3}, 119); assert_equal (tbl{3, 3}, 120); assert_equal (stats.n, 2 * ones (1, 120)); ***** test y = [10; 20; 9999; NaN; 40; 50]; g = categorical ([1; 1; NaN; 1; 2; 2]); [p, tbl, stats] = anova1 (y, g, 'off'); assert_equal (p, 0.051317, 1e-6); assert_equal (tbl{2,5}, 18, 1e-6); assert_equal (tbl{2,3}, 1, 0); assert_equal (tbl{3,3}, 2, 0); assert_equal (tbl{4,3}, 3, 0); assert_equal (stats.n, [2, 2], 0); ***** test [p, tbl] = anova1 ((1:5)', [], 'off'); assert_equal (p, NaN); assert_equal (cell2mat (tbl(2:4,2:3)), [0, 0; 10, 4; 10, 4]); ***** test [p, tbl] = anova1 (1:5, [], 'off'); assert_equal (p, NaN); assert_equal (cell2mat (tbl(2:4,2:3)), [0, 0; 10, 4; 10, 4]); ***** test [p, tbl, stats] = anova1 ((1:5)', [], 'off'); assert_equal (stats.n, 5); assert_equal (stats.means, 3); assert_equal (stats.df, 4); ***** test [p, tbl] = anova1 ([], [], 'off'); assert_equal (p, NaN); assert_equal (cell2mat (tbl(2:4,2:3)), zeros (3, 2)); ***** test [p, tbl] = anova1 (zeros (0, 3), [], 'off'); assert_equal (p, NaN); assert_equal (cell2mat (tbl(2:4,2:3)), zeros (3, 2)); ***** test ## Below the resolution of 1 - fcdf, values from MATLAB R2024a p = anova1 ([1:10, 101:110, 201:210]', kron ((1:3)', ones (10, 1)), 'off'); assert_equal (p, 5.522164708181e-40, -1e-10); 17 tests, 17 passed, 0 known failure, 0 skipped [inst/loadmodel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/loadmodel.m ***** test load fisheriris Yb = strcmp (species, 'setosa'); m = fitcknn (meas, species, 'ScoreTransform', 'logit'); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (class (m2), class (m)); assert_equal (m2.W, m.W); assert_equal (m2.X, m.X); assert_equal (m2.Y, m.Y); assert_equal (m2.NumObservations, m.NumObservations); assert_equal (m2.RowsUsed, m.RowsUsed); assert_equal (m2.NumPredictors, m.NumPredictors); assert_equal (m2.PredictorNames, m.PredictorNames); assert_equal (m2.ResponseName, m.ResponseName); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (m2.Sigma, m.Sigma); assert_equal (m2.Mu, m.Mu); assert_equal (m2.BreakTies, m.BreakTies); assert_equal (m2.NumNeighbors, m.NumNeighbors); assert_equal (m2.Distance, m.Distance); assert_equal (m2.DistanceWeight, m.DistanceWeight); assert_equal (m2.DistParameter, m.DistParameter); assert_equal (m2.NSMethod, m.NSMethod); assert_equal (m2.IncludeTies, m.IncludeTies); assert_equal (m2.BucketSize, m.BucketSize); assert_equal (m2.CacheSize, m.CacheSize); assert_equal (m2.Cost, m.Cost); assert_equal (m2.Prior, m.Prior); assert_equal (m2.ScoreTransform, m.ScoreTransform); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test load fisheriris Yb = strcmp (species, 'setosa'); m = fitcdiscr (meas, species, 'ScoreTransform', 'logit'); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (class (m2), class (m)); assert_equal (m2.W, m.W); assert_equal (m2.X, m.X); assert_equal (m2.Y, m.Y); assert_equal (m2.NumObservations, m.NumObservations); assert_equal (m2.RowsUsed, m.RowsUsed); assert_equal (m2.NumPredictors, m.NumPredictors); assert_equal (m2.PredictorNames, m.PredictorNames); assert_equal (m2.ResponseName, m.ResponseName); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (m2.Sigma, m.Sigma); assert_equal (m2.Mu, m.Mu); assert_equal (m2.Coeffs, m.Coeffs); assert_equal (m2.Delta, m.Delta); assert_equal (m2.DiscrimType, m.DiscrimType); assert_equal (m2.Gamma, m.Gamma); assert_equal (m2.MinGamma, m.MinGamma); assert_equal (m2.LogDetSigma, m.LogDetSigma); assert_equal (m2.XCentered, m.XCentered); assert_equal (m2.Cost, m.Cost); assert_equal (m2.Prior, m.Prior); assert_equal (m2.ScoreTransform, m.ScoreTransform); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test load fisheriris Yb = strcmp (species, 'setosa'); m = fitcsvm (meas(1:100,:), Yb(1:100), 'ScoreTransform', 'logit'); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (class (m2), class (m)); assert_equal (m2.X, m.X); assert_equal (m2.Y, m.Y); assert_equal (m2.NumObservations, m.NumObservations); assert_equal (m2.RowsUsed, m.RowsUsed); assert_equal (m2.NumPredictors, m.NumPredictors); assert_equal (m2.PredictorNames, m.PredictorNames); assert_equal (m2.ResponseName, m.ResponseName); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (m2.Sigma, m.Sigma); assert_equal (m2.Mu, m.Mu); assert_equal (m2.ModelParameters, m.ModelParameters); assert_equal (m2.Model, m.Model); assert_equal (m2.Alpha, m.Alpha); assert_equal (m2.Beta, m.Beta); assert_equal (m2.Bias, m.Bias); assert_equal (m2.IsSupportVector, m.IsSupportVector); assert_equal (m2.SupportVectorLabels, m.SupportVectorLabels); assert_equal (m2.SupportVectors, m.SupportVectors); assert_equal (m2.Prior, m.Prior); assert_equal (m2.Cost, m.Cost); assert_equal (m2.W, m.W); assert_equal (m2.CategoricalPredictors, m.CategoricalPredictors); assert_equal (m2.ExpandedPredictorNames, m.ExpandedPredictorNames); assert_equal (m2.ScoreTransform, m.ScoreTransform); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test load fisheriris Yb = strcmp (species, 'setosa'); m = fitcgam (meas(1:100,:), Yb(1:100)); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (class (m2), class (m)); assert_equal (m2.X, m.X); assert_equal (m2.Y, m.Y); assert_equal (m2.NumObservations, m.NumObservations); assert_equal (m2.RowsUsed, m.RowsUsed); assert_equal (m2.NumPredictors, m.NumPredictors); assert_equal (m2.PredictorNames, m.PredictorNames); assert_equal (m2.ResponseName, m.ResponseName); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (m2.Prior, m.Prior); assert_equal (m2.Formula, m.Formula); assert_equal (m2.Interactions, m.Interactions); assert_equal (m2.Knots, m.Knots); assert_equal (m2.Order, m.Order); assert_equal (m2.DoF, m.DoF); assert_equal (m2.LearningRate, m.LearningRate); assert_equal (m2.NumIterations, m.NumIterations); assert_equal (m2.Intercept, m.Intercept); assert_equal (m2.W, m.W); assert_equal (m2.CategoricalPredictors, m.CategoricalPredictors); assert_equal (m2.ExpandedPredictorNames, m.ExpandedPredictorNames); assert_equal (m2.BaseModel, m.BaseModel); assert_equal (m2.ModelwInt, m.ModelwInt); assert_equal (m2.IntMatrix, m.IntMatrix); assert_equal (m2.Cost, m.Cost); assert_equal (m2.ScoreTransform, m.ScoreTransform); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test load fisheriris Yb = strcmp (species, 'setosa'); c = compact (fitcsvm (meas(1:100,:), Yb(1:100))); fn = tempname (); unwind_protect savemodel (c, fn); c2 = loadmodel (fn); assert_equal (class (c2), 'CompactClassificationSVM'); assert_equal (predict (c2, meas(1:10,:)), predict (c, meas(1:10,:))); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test load fisheriris Yb = strcmp (species, 'setosa'); m = fitcsvm (meas(1:100,:), Yb(1:100), 'ScoreTransform', 'logit'); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (strfind (evalc ('disp (m2)'), "'logit'") > 0, true); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test load fisheriris Yb = strcmp (species, 'setosa'); m = fitcgam (meas(1:100,:), Yb(1:100)); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.LearningRate, m.LearningRate); assert_equal (m2.NumIterations, m.NumIterations); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # ClassificationDiscriminant: categorical labels save and load load fisheriris m = fitcdiscr (meas, categorical (species)); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); assert_equal (m2.Y, m.Y); assert_equal (class (m2.Coeffs(1,2).Class1), 'categorical'); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # ClassificationDiscriminant: string labels save and load load fisheriris m = fitcdiscr (meas, string (species)); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); assert_equal (m2.Y, m.Y); assert_equal (class (m2.Coeffs(1,2).Class1), 'string'); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # CompactClassificationDiscriminant: categorical labels save and load load fisheriris m = compact (fitcdiscr (meas, categorical (species))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); assert_equal (class (m2.Coeffs(1,2).Class1), 'categorical'); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # CompactClassificationDiscriminant: string labels save and load load fisheriris m = compact (fitcdiscr (meas, string (species))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); assert_equal (class (m2.Coeffs(1,2).Class1), 'string'); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # ClassificationGAM: categorical labels save and load load fisheriris m = fitcgam (meas(51:150,:), categorical (species(51:150))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); assert_equal (m2.Y, m.Y); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # ClassificationGAM: string labels save and load load fisheriris m = fitcgam (meas(51:150,:), string (species(51:150))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); assert_equal (m2.Y, m.Y); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # CompactClassificationGAM: categorical labels save and load load fisheriris m = compact (fitcgam (meas(51:150,:), categorical (species(51:150)))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # CompactClassificationGAM: string labels save and load load fisheriris m = compact (fitcgam (meas(51:150,:), string (species(51:150)))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # ClassificationKernel: categorical labels save and load load fisheriris m = fitckernel (meas(51:150,:), categorical (species(51:150))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # ClassificationKernel: string labels save and load load fisheriris m = fitckernel (meas(51:150,:), string (species(51:150))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # ClassificationKNN: categorical labels save and load load fisheriris m = fitcknn (meas, categorical (species)); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); assert_equal (m2.Y, m.Y); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # ClassificationKNN: string labels save and load load fisheriris m = fitcknn (meas, string (species)); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); assert_equal (m2.Y, m.Y); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # ClassificationLinear: categorical labels save and load load fisheriris m = fitclinear (meas(51:150,:), categorical (species(51:150))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # ClassificationLinear: string labels save and load load fisheriris m = fitclinear (meas(51:150,:), string (species(51:150))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # ClassificationNaiveBayes: categorical labels save and load load fisheriris m = fitcnb (meas, categorical (species)); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); assert_equal (m2.Y, m.Y); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # ClassificationNaiveBayes: string labels save and load load fisheriris m = fitcnb (meas, string (species)); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); assert_equal (m2.Y, m.Y); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # CompactClassificationNaiveBayes: categorical labels save and load load fisheriris m = compact (fitcnb (meas, categorical (species))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # CompactClassificationNaiveBayes: string labels save and load load fisheriris m = compact (fitcnb (meas, string (species))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # ClassificationNeuralNetwork: categorical labels save and load load fisheriris m = fitcnet (meas, categorical (species)); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); assert_equal (m2.Y, m.Y); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # ClassificationNeuralNetwork: string labels save and load load fisheriris m = fitcnet (meas, string (species)); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); assert_equal (m2.Y, m.Y); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # CompactClassificationNeuralNetwork: categorical labels save and load load fisheriris m = compact (fitcnet (meas, categorical (species))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # CompactClassificationNeuralNetwork: string labels save and load load fisheriris m = compact (fitcnet (meas, string (species))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # ClassificationSVM: categorical labels save and load load fisheriris m = fitcsvm (meas(51:150,:), categorical (species(51:150))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); assert_equal (m2.Y, m.Y); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # ClassificationSVM: string labels save and load load fisheriris m = fitcsvm (meas(51:150,:), string (species(51:150))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); assert_equal (m2.Y, m.Y); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # CompactClassificationSVM: categorical labels save and load load fisheriris m = compact (fitcsvm (meas(51:150,:), categorical (species(51:150)))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # CompactClassificationSVM: string labels save and load load fisheriris m = compact (fitcsvm (meas(51:150,:), string (species(51:150)))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # ClassificationTree: categorical labels save and load load fisheriris m = fitctree (meas, categorical (species)); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); assert_equal (m2.Y, m.Y); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # ClassificationTree: string labels save and load load fisheriris m = fitctree (meas, string (species)); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); assert_equal (m2.Y, m.Y); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # CompactClassificationTree: categorical labels save and load load fisheriris m = compact (fitctree (meas, categorical (species))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # CompactClassificationTree: string labels save and load load fisheriris m = compact (fitctree (meas, string (species))); fn = tempname (); unwind_protect savemodel (m, fn); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (predict (m2, meas(51:55,:)), predict (m, meas(51:55,:))); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # a categorical model saved by version 1.9.2 loads load fisheriris m = fitcknn (meas, categorical (species)); fn = tempname (); unwind_protect savemodel (m, fn); d = load (fn); c = m.ClassNames; d.ClassNames = struct ('cats', {categories(c)}, ... 'code', uint16 (double (c)), ... 'isMissing', isundefined (c), ... 'isOrdinal', isordinal (c), ... 'isProtected', isprotected (c)); c = m.Y; d.Y = struct ('cats', {categories(c)}, 'code', uint16 (double (c)), ... 'isMissing', isundefined (c), 'isOrdinal', isordinal (c), ... 'isProtected', isprotected (c)); save ('-binary', fn, '-struct', 'd'); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (m2.Y, m.Y); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** test # a string model saved by version 1.9.2 loads load fisheriris m = fitcknn (meas, string (species)); fn = tempname (); unwind_protect savemodel (m, fn); d = load (fn); d.ClassNames = struct ('strs', {cellstr(m.ClassNames)}, ... 'isMissing', ismissing (m.ClassNames)); d.Y = struct ('strs', {cellstr(m.Y)}, 'isMissing', ismissing (m.Y)); save ('-binary', fn, '-struct', 'd'); m2 = loadmodel (fn); assert_equal (m2.ClassNames, m.ClassNames); assert_equal (m2.Y, m.Y); unwind_protect_cleanup if (exist (fn, 'file')) delete (fn); endif end_unwind_protect ***** error loadmodel () ***** error ... loadmodel ('fisheriris.mat') ***** error ... loadmodel ('fail_loadmodel.mdl') ***** error ... loadmodel ('fail_load_model.mdl') 43 tests, 43 passed, 0 known failure, 0 skipped [inst/Nearest_Neighbors/knnsearch.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Nearest_Neighbors/knnsearch.m ***** demo ## find 10 nearest neighbour of a point using different distance metrics ## and compare the results by plotting load fisheriris X = meas(:,3:4); Y = species; point = [5, 1.45]; ## calculate 10 nearest-neighbours by minkowski distance [id, d] = knnsearch (X, point, 'K', 10); ## calculate 10 nearest-neighbours by minkowski distance [idm, dm] = knnsearch (X, point, 'K', 10, 'distance', 'minkowski', 'p', 5); ## calculate 10 nearest-neighbours by chebychev distance [idc, dc] = knnsearch (X, point, 'K', 10, 'distance', 'chebychev'); ## plotting the results gscatter (X(:,1), X(:,2), species, [.75 .75 0; 0 .75 .75; .75 0 .75], '.', 20); title ('Fisher''s Iris Data - Nearest Neighbors with different types of distance metrics'); xlabel ('Petal length (cm)'); ylabel ('Petal width (cm)'); line (point(1), point(2), 'marker', 'X', 'color', 'k', ... 'linewidth', 2, 'displayname', 'query point') line (X(id,1), X(id,2), 'color', [0.5 0.5 0.5], 'marker', 'o', ... 'linestyle', 'none', 'markersize', 10, 'displayname', 'euclidean') line (X(idm,1), X(idm,2), 'color', [0.5 0.5 0.5], 'marker', 'd', ... 'linestyle', 'none', 'markersize', 10, 'displayname', 'Minkowski') line (X(idc,1), X(idc,2), 'color', [0.5 0.5 0.5], 'marker', 'p', ... 'linestyle', 'none', 'markersize', 10, 'displayname', 'chebychev') xlim ([4.5 5.5]); ylim ([1 2]); axis square; ***** demo ## knnsearch on iris dataset using kdtree method load fisheriris X = meas(:,3:4); gscatter (X(:,1), X(:,2), species, [.75 .75 0; 0 .75 .75; .75 0 .75], '.', 20); title ('Fisher''s iris dataset : Nearest Neighbors with kdtree search'); ## new point to be predicted point = [5 1.45]; line (point(1), point(2), 'marker', 'X', 'color', 'k', ... 'linewidth', 2, 'displayname', 'query point') ## knnsearch using kdtree method [idx, d] = knnsearch (X, point, 'K', 10, 'NSMethod', 'kdtree'); ## plotting predicted neighbours line (X(idx,1), X(idx,2), 'color', [0.5 0.5 0.5], 'marker', 'o', ... 'linestyle', 'none', 'markersize', 10, ... 'displayname', 'nearest neighbour') xlim ([4 6]) ylim ([1 3]) axis square ## details of predicted labels tabulate (species(idx)) ctr = point - d(end); diameter = 2 * d(end); ## Draw a circle around the 10 nearest neighbors. h = rectangle ('position', [ctr, diameter, diameter], 'curvature', [1 1]); ## here only 8 neighbours are plotted instead of 10 since the dataset ## contains duplicate values ***** shared X, Y X = [1, 2, 3, 4; 2, 3, 4, 5; 3, 4, 5, 6]; Y = [1, 2, 2, 3; 2, 3, 3, 4]; ***** test [idx, D] = knnsearch (X, Y, 'Distance', 'euclidean'); assert_equal (idx, [1; 1]); assert_equal (D, ones (2, 1) * sqrt (2)); ***** test eucldist = @(v,m) sqrt (sumsq (repmat (v,rows (m),1)-m,2)); [idx, D] = knnsearch (X, Y, 'Distance', eucldist); assert_equal (idx, [1; 1]); assert_equal (D, ones (2, 1) * sqrt (2)); ***** test [idx, D] = knnsearch (X, Y, 'Distance', 'euclidean', 'includeties', true); assert_equal (iscell (idx), true); assert_equal (iscell (D), true) assert_equal (idx {1}, [1]); assert_equal (idx {2}, [1, 2]); assert_equal (D{1}, ones (1, 1) * sqrt (2)); assert_equal (D{2}, ones (1, 2) * sqrt (2)); ***** test [idx, D] = knnsearch (X, Y, 'Distance', 'euclidean', 'k', 2); assert_equal (idx, [1, 2; 1, 2]); assert_equal (D, [sqrt(2), 3.162277660168380; sqrt(2), sqrt(2)], 1e-14); ***** test [idx, D] = knnsearch (X, Y, 'Distance', 'seuclidean'); assert_equal (idx, [1; 1]); assert_equal (D, ones (2, 1) * sqrt (2)); ***** test [idx, D] = knnsearch (X, Y, 'Distance', 'seuclidean', 'k', 2); assert_equal (idx, [1, 2; 1, 2]); assert_equal (D, [sqrt(2), 3.162277660168380; sqrt(2), sqrt(2)], 1e-14); ***** test xx = [1, 2; 1, 3; 2, 4; 3, 6]; yy = [2, 4; 2, 6]; [idx, D] = knnsearch (xx, yy, 'Distance', 'mahalanobis'); assert_equal (idx, [3; 2]); assert_equal (D, [0; 3.162277660168377], 1e-14); ***** test [idx, D] = knnsearch (X, Y, 'Distance', 'minkowski'); assert_equal (idx, [1; 1]); assert_equal (D, ones (2, 1) * sqrt (2)); ***** test [idx, D] = knnsearch (X, Y, 'Distance', 'minkowski', 'p', 3); assert_equal (idx, [1; 1]); assert_equal (D, ones (2, 1) * 1.259921049894873, 1e-14); ***** test [idx, D] = knnsearch (X, Y, 'Distance', 'cityblock'); assert_equal (idx, [1; 1]); assert_equal (D, [2; 2]); ***** test [idx, D] = knnsearch (X, Y, 'Distance', 'chebychev'); assert_equal (idx, [1; 1]); assert_equal (D, [1; 1]); ***** test [idx, D] = knnsearch (X, Y, 'Distance', 'cosine'); assert_equal (idx, [2; 3]); assert_equal (D, [0.005674536395645; 0.002911214328620], 1e-14); ***** test [idx, D] = knnsearch (X, Y, 'Distance', 'correlation'); assert_equal (idx, [1; 1]); assert_equal (D, ones (2, 1) * 0.051316701949486, 1e-14); ***** test [idx, D] = knnsearch (X, Y, 'Distance', 'spearman'); assert_equal (idx, [1; 1]); assert_equal (D, ones (2, 1) * 0.051316701949486, 1e-14); ***** test [idx, D] = knnsearch (X, Y, 'Distance', 'hamming'); assert_equal (idx, [1; 1]); assert_equal (D, [0.5; 0.5]); ***** test [idx, D] = knnsearch (X, Y, 'Distance', 'jaccard'); assert_equal (idx, [1; 1]); assert_equal (D, [0.5; 0.5]); ***** test [idx, D] = knnsearch (X, Y, 'Distance', 'jaccard', 'k', 2); assert_equal (idx, [1, 2; 1, 2]); assert_equal (D, [0.5, 1; 0.5, 0.5]); ***** test a = [1, 5; 1, 2; 2, 2; 1.5, 1.5; 5, 1; 2 -1.34; 1, -3; 4, -4; -3, 1; 8, 9]; b = [1, 1]; [idx, D] = knnsearch (a, b, 'K', 5, 'NSMethod', 'kdtree', 'includeties', true); assert_equal (iscell (idx), true); assert_equal (iscell (D), true) assert_equal (cell2mat (idx), [4, 2, 3, 6, 1, 5, 7, 9]); assert_equal (cell2mat (D), [0.7071, 1.0000, 1.4142, 2.5447, 4.0000, 4.0000, 4.0000, 4.0000], 1e-4); ***** test a = [1, 5; 1, 2; 2, 2; 1.5, 1.5; 5, 1; 2 -1.34; 1, -3; 4, -4; -3, 1; 8, 9]; b = [1, 1]; [idx, D] = knnsearch (a, b, 'K', 5, 'NSMethod', 'exhaustive', 'includeties', true); assert_equal (iscell (idx), true); assert_equal (iscell (D), true) assert_equal (cell2mat (idx), [4, 2, 3, 6, 1, 5, 7, 9]); assert_equal (cell2mat (D), [0.7071, 1.0000, 1.4142, 2.5447, 4.0000, 4.0000, 4.0000, 4.0000], 1e-4); ***** test a = [1, 5; 1, 2; 2, 2; 1.5, 1.5; 5, 1; 2 -1.34; 1, -3; 4, -4; -3, 1; 8, 9]; b = [1, 1]; [idx, D] = knnsearch (a, b, 'K', 5, 'NSMethod', 'kdtree', 'includeties', false); assert_equal (iscell (idx), false); assert_equal (iscell (D), false) assert_equal (idx, [4, 2, 3, 6, 1]); assert_equal (D, [0.7071, 1.0000, 1.4142, 2.5447, 4.0000], 1e-4); ***** test a = [1, 5; 1, 2; 2, 2; 1.5, 1.5; 5, 1; 2 -1.34; 1, -3; 4, -4; -3, 1; 8, 9]; b = [1, 1]; [idx, D] = knnsearch (a, b, 'K', 5, 'NSMethod', 'exhaustive', 'includeties', false); assert_equal (iscell (idx), false); assert_equal (iscell (D), false) assert_equal (idx, [4, 2, 3, 6, 1]); assert_equal (D, [0.7071, 1.0000, 1.4142, 2.5447, 4.0000], 1e-4); ***** test load fisheriris a = meas; b = min (meas); [idx, D] = knnsearch (a, b, 'K', 5, 'NSMethod', 'kdtree'); assert_equal (idx, [42, 9, 14, 39, 13]); assert_equal (D, [0.5099, 0.9950, 1.0050, 1.0536, 1.1874], 1e-4); ***** test load fisheriris a = meas; b = mean (meas); [idx, D] = knnsearch (a, b, 'K', 5, 'NSMethod', 'kdtree'); assert_equal (idx, [65, 83, 89, 72, 100]); assert_equal (D, [0.3451, 0.3869, 0.4354, 0.4481, 0.4625], 1e-4); ***** test load fisheriris a = meas; b = max (meas); [idx, D] = knnsearch (a, b, 'K', 5, 'NSMethod', 'kdtree'); assert_equal (idx, [118, 132, 110, 106, 136]); assert_equal (D, [0.7280, 0.9274, 1.3304, 1.5166, 1.6371], 1e-4); ***** test load fisheriris a = meas; b = max (meas); [idx, D] = knnsearch (a, b, 'K', 5, 'includeties', true); assert_equal (iscell (idx), true); assert_equal (iscell (D), true); assert_equal (cell2mat (idx), [118, 132, 110, 106, 136]); assert_equal (cell2mat (D), [0.7280, 0.9274, 1.3304, 1.5166, 1.6371], 1e-4); ***** test # IncludeTies gives a row per cell, whichever method is used a = [1, 5; 1, 2; 2, 2; 1.5, 1.5; 5, 1; 2 -1.34; 1, -3; 4, -4; -3, 1; 8, 9]; b = [1, 1]; [ik, dk] = knnsearch (a, b, 'K', 5, 'NSMethod', 'kdtree', 'includeties', true); [ie, de] = knnsearch (a, b, 'K', 5, 'NSMethod', 'exhaustive', 'includeties', true); assert_equal (size (ik{1}), [1, 8]); assert_equal (size (dk{1}), [1, 8]); assert_equal (ik{1}, ie{1}); assert_equal (dk{1}, de{1}, 1e-12); ***** test # the cell array itself is one column, as MATLAB returns a = [1, 5; 1, 2; 2, 2; 1.5, 1.5; 5, 1; 2 -1.34; 1, -3; 4, -4; -3, 1; 8, 9]; [idx, D] = knnsearch (a, [1, 1; 2, 2], 'K', 3, 'includeties', true); assert_equal (size (idx), [2, 1]); assert_equal (size (D), [2, 1]); assert_equal (rows (idx{1}), 1); assert_equal (rows (idx{2}), 1); ***** test [idx, D] = knnsearch ([1, 2; 3, 4; 5, 6], [1, 2], 'K', 5); assert_equal (idx, [1, 2, 3]); assert_equal (D, [0, 2*sqrt(2), 4*sqrt(2)], 1e-14); ***** test [idx, D] = knnsearch (zeros (0, 2), [1, 2; 3, 4], 'K', 3); assert_equal (size (idx), [2, 0]); assert_equal (size (D), [2, 0]); ***** test [idx, D] = knnsearch (zeros (0, 2), [1, 2], 'NSMethod', 'exhaustive'); assert_equal (size (idx), [1, 0]); assert_equal (size (D), [1, 0]); ***** test [idx, D] = knnsearch ([1, 2; 3, 4], zeros (0, 2), 'K', 3); assert_equal (size (idx), [0, 2]); assert_equal (size (D), [0, 2]); ***** test [idx, D] = knnsearch (zeros (0, 2), zeros (0, 2), 'K', 3); assert_equal (size (idx), [0, 0]); assert_equal (size (D), [0, 0]); ***** test [idx, D] = knnsearch (zeros (0, 2), [1, 2; 3, 4], 'K', 3, ... 'IncludeTies', true); assert_equal (size (idx), [2, 1]); assert_equal (idx{1}, zeros (1, 0)); assert_equal (D{2}, zeros (1, 0)); ***** test [idx, D] = knnsearch (single (zeros (0, 2)), [1, 2]); assert_equal (class (idx), 'double'); assert_equal (class (D), 'single'); ***** test load fisheriris X = meas(1:130,[1, 3]); [idx, D] = knnsearch (X, [6.3, 4.9], 'K', 5); assert_equal (idx, [73, 124, 127, 57, 128]); assert_equal (D(4), D(5)); assert_equal (knnsearch (X, [6.3, 4.9], 'K', 4), [73, 124, 127, 57]); idx = knnsearch (X, [6.3, 4.9], 'K', 4, 'NSMethod', 'exhaustive'); assert_equal (idx, [73, 124, 127, 57]); ***** error knnsearch (1) ***** error ... knnsearch (ones (4, 5), ones (4)) ***** error ... knnsearch (ones (4, 2), ones (3, 2), 'Distance', 'euclidean', 'some', 'some') ***** error ... knnsearch (ones (4, 5), ones (1, 5), 'scale', ones (1, 5), 'P', 3) ***** error ... knnsearch (ones (4, 5), ones (1, 5), 'K', 0) ***** error ... knnsearch (ones (4, 5), ones (1, 5), 'P', -2) ***** error ... knnsearch (ones (4, 5), ones (1, 5), 'scale', ones (4,5), 'distance', 'euclidean') ***** error ... knnsearch (ones (4, 5), ones (1, 5), 'cov', ['some' 'some']) ***** error ... knnsearch (ones (4, 5), ones (1, 5), 'cov', ones (4,5), 'distance', 'euclidean') ***** error ... knnsearch (ones (4, 5), ones (1, 5), 'bucketsize', -1) ***** error ... knnsearch (ones (4, 5), ones (1, 5), 'bucketsize', 2.5) ***** error ... knnsearch (ones (4, 5), ones (1, 5), 'NSmethod', 'kdtree', 'distance', 'cosine') ***** error ... knnsearch (ones (4, 5), ones (1, 5), 'NSmethod', 'kdtree', 'distance', 'mahalanobis') ***** error ... knnsearch (ones (4, 5), ones (1, 5), 'NSmethod', 'kdtree', 'distance', 'correlation') ***** error ... knnsearch (ones (4, 5), ones (1, 5), 'NSmethod', 'kdtree', 'distance', 'seuclidean') ***** error ... knnsearch (ones (4, 5), ones (1, 5), 'NSmethod', 'kdtree', 'distance', 'spearman') ***** error ... knnsearch (ones (4, 5), ones (1, 5), 'NSmethod', 'kdtree', 'distance', 'hamming') ***** error ... knnsearch (ones (4, 5), ones (1, 5), 'NSmethod', 'kdtree', 'distance', 'jaccard') ***** test X = [1, 2; 3, 4; 5, 6; 7, 8]; Y = [2, 3; 6, 7]; for m = {"kdtree", "exhaustive"} [idx, D] = knnsearch (single (X), single (Y), "K", 2, "NSMethod", m{1}); assert_equal (class (idx), 'double'); assert_equal (class (D), 'single'); [~, Dm] = knnsearch (single (X), Y, "K", 2, "NSMethod", m{1}); assert_equal (class (Dm), 'single'); assert_equal (Dm, D); [~, Dd] = knnsearch (X, Y, "K", 2, "NSMethod", m{1}); assert_equal (class (Dd), 'double'); endfor ***** test X = [0, 0; 0, 0; 1, 1; 1, 1; 2, 2; 2, 2]; idx = knnsearch (X, [0.5, 0.5], 'k', 1, 'NSMethod', 'exhaustive', ... 'IncludeTies', true); assert_equal (class (idx), 'cell'); assert_equal (sort (idx{1}), [1, 2, 3, 4]); ***** test X = [0, 0; 0, 0; 1, 1; 1, 1; 2, 2; 2, 2]; [i1, d1] = knnsearch (X, [0.5, 0.5], 'k', 1, 'NSMethod', 'exhaustive', ... 'IncludeTies', true); [i2, d2] = knnsearch (X, [0.5, 0.5], 'k', 1, 'NSMethod', 'kdtree', ... 'IncludeTies', true); assert_equal (sort (i1{1}), sort (i2{1})); assert_equal (sort (d1{1}), sort (d2{1}), 1e-12); 56 tests, 56 passed, 0 known failure, 0 skipped [inst/Nearest_Neighbors/mahal.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Nearest_Neighbors/mahal.m ***** error mahal () ***** error mahal (1, 2, 3) ***** error mahal ('A', 'B') ***** error mahal ([1, 2], ['A', 'B']) ***** error mahal (ones (2, 2, 2)) ***** error mahal (ones (2, 2), ones (2, 2, 2)) ***** error mahal (ones (2, 2), ones (2, 3)) ***** test X = [1 0; 0 1; 1 1; 0 0]; assert_equal (mahal (X, X), [1.5; 1.5; 1.5; 1.5], 10*eps) assert_equal (mahal (X, X+1), [7.5; 7.5; 1.5; 13.5], 10*eps) ***** assert_equal (mahal ([true; true], [false; true]), [0.5; 0.5], eps) 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Nearest_Neighbors/rangesearch.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Nearest_Neighbors/rangesearch.m ***** demo ## Generate 100 random 2D points from each of five distinct multivariate ## normal distributions that form five separate classes rng (42); N = 100; d = 10; X1 = mvnrnd (d * [0, 0], eye (2), N); X2 = mvnrnd (d * [1, 1], eye (2), N); X3 = mvnrnd (d * [-1, -1], eye (2), N); X4 = mvnrnd (d * [1, -1], eye (2), N); X5 = mvnrnd (d * [-1, 1], eye (2), N); X = [X1; X2; X3; X4; X5]; ## For each point in X, find the points in X that are within a radius d ## away from the points in X. Idx = rangesearch (X, X, d, 'NSMethod', 'exhaustive'); ## Select the first point in X (corresponding to the first class) and find ## its nearest neighbors within the radius d. Display these points in ## one color and the remaining points in a different color. x = X(1,:); nearestPoints = X(Idx{1},:); nonNearestIdx = true (size (X, 1), 1); nonNearestIdx(Idx{1}) = false; scatter (X(nonNearestIdx,1), X(nonNearestIdx,2)) hold on scatter (nearestPoints(:,1),nearestPoints(:,2)) scatter (x(1), x(2), 'black', 'filled') hold off ## Select the last point in X (corresponding to the fifth class) and find ## its nearest neighbors within the radius d. Display these points in ## one color and the remaining points in a different color. x = X(end,:); nearestPoints = X(Idx{end},:); nonNearestIdx = true (size (X, 1), 1); nonNearestIdx(Idx{end}) = false; figure scatter (X(nonNearestIdx,1), X(nonNearestIdx,2)) hold on scatter (nearestPoints(:,1),nearestPoints(:,2)) scatter (x(1), x(2), 'black', 'filled') hold off ***** shared x, y, X, Y x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = [2, 3, 4; 1, 4, 3]; X = [1, 2, 3, 4; 2, 3, 4, 5; 3, 4, 5, 6]; Y = [1, 2, 2, 3; 2, 3, 3, 4]; ***** test [idx, D] = rangesearch (x, y, 4); assert_equal (idx, {[1, 4, 2]; [1, 4]}); assert_equal (D, {[1.7321, 3.3166, 3.4641]; [2, 3.4641]}, 1e-4); ***** test [idx, D] = rangesearch (x, y, 4, 'NSMethod', 'exhaustive'); assert_equal (idx, {[1, 4, 2]; [1, 4]}); assert_equal (D, {[1.7321, 3.3166, 3.4641]; [2, 3.4641]}, 1e-4); ***** test [idx, D] = rangesearch (x, y, 4, 'NSMethod', 'kdtree'); assert_equal (idx, {[1, 4, 2]; [1, 4]}); assert_equal (D, {[1.7321, 3.3166, 3.4641]; [2, 3.4641]}, 1e-4); ***** test [idx, D] = rangesearch (x, y, 4, 'SortIndices', true); assert_equal (idx, {[1, 4, 2]; [1, 4]}); assert_equal (D, {[1.7321, 3.3166, 3.4641]; [2, 3.4641]}, 1e-4); ***** test [idx, D] = rangesearch (x, y, 4, 'SortIndices', false); assert_equal (idx, {[1, 2, 4]; [1, 4]}); assert_equal (D, {[1.7321, 3.4641, 3.3166]; [2, 3.4641]}, 1e-4); ***** test [idx, D] = rangesearch (x, y, 4, 'NSMethod', 'exhaustive', ... 'SortIndices', false); assert_equal (idx, {[1, 2, 4]; [1, 4]}); assert_equal (D, {[1.7321, 3.4641, 3.3166]; [2, 3.4641]}, 1e-4); ***** test eucldist = @(v,m) sqrt (sumsq (repmat (v,rows (m),1)-m,2)); [idx, D] = rangesearch (x, y, 4, 'Distance', eucldist); assert_equal (idx, {[1, 4, 2]; [1, 4]}); assert_equal (D, {[1.7321, 3.3166, 3.4641]; [2, 3.4641]}, 1e-4); ***** test eucldist = @(v,m) sqrt (sumsq (repmat (v,rows (m),1)-m,2)); [idx, D] = rangesearch (x, y, 4, 'Distance', eucldist, ... 'NSMethod', 'exhaustive'); assert_equal (idx, {[1, 4, 2]; [1, 4]}); assert_equal (D, {[1.7321, 3.3166, 3.4641]; [2, 3.4641]}, 1e-4); ***** test [idx, D] = rangesearch (x, y, 1.5, 'Distance', 'seuclidean', ... 'NSMethod', 'exhaustive'); assert_equal (idx, {[1, 4, 2]; [1, 4]}); assert_equal (D, {[0.6024, 1.0079, 1.2047]; [0.6963, 1.2047]}, 1e-4); ***** test [idx, D] = rangesearch (x, y, 1.5, 'Distance', 'seuclidean', ... 'NSMethod', 'exhaustive', 'SortIndices', false); assert_equal (idx, {[1, 2, 4]; [1, 4]}); assert_equal (D, {[0.6024, 1.2047, 1.0079]; [0.6963, 1.2047]}, 1e-4); ***** test [idx, D] = rangesearch (X, Y, 4); assert_equal (idx, {[1, 2]; [1, 2, 3]}); assert_equal (D, {[1.4142, 3.1623]; [1.4142, 1.4142, 3.1623]}, 1e-4); ***** test [idx, D] = rangesearch (X, Y, 2); assert_equal (idx, {[1]; [1, 2]}); assert_equal (D, {[1.4142]; [1.4142, 1.4142]}, 1e-4); ***** test eucldist = @(v,m) sqrt (sumsq (repmat (v,rows (m),1)-m,2)); [idx, D] = rangesearch (X, Y, 4, 'Distance', eucldist); assert_equal (idx, {[1, 2]; [1, 2, 3]}); assert_equal (D, {[1.4142, 3.1623]; [1.4142, 1.4142, 3.1623]}, 1e-4); ***** test [idx, D] = rangesearch (X, Y, 4, 'SortIndices', false); assert_equal (idx, {[1, 2]; [1, 2, 3]}); assert_equal (D, {[1.4142, 3.1623]; [1.4142, 1.4142, 3.1623]}, 1e-4); ***** test [idx, D] = rangesearch (X, Y, 4, 'Distance', 'seuclidean', ... 'NSMethod', 'exhaustive'); assert_equal (idx, {[1, 2]; [1, 2, 3]}); assert_equal (D, {[1.4142, 3.1623]; [1.4142, 1.4142, 3.1623]}, 1e-4); ***** test X = ones (10, 2); [idx, D] = rangesearch (X, X, 0.1, 'NSMethod', 'kdtree'); assert_equal (numel (idx), 10); ***** test X = ones (3, 2); [idx, D] = rangesearch (X, X, 0.1, 'NSMethod', 'kdtree', 'BucketSize', 1); assert_equal (numel (idx), 3); assert_equal (cellfun (@numel, idx) == 3, [true; true; true]); assert_equal (idx{1}, [1, 2, 3]); assert_equal (idx{2}, [1, 2, 3]); assert_equal (idx{3}, [1, 2, 3]); assert_equal (D{1}, [0, 0, 0]); assert_equal (D{2}, [0, 0, 0]); assert_equal (D{3}, [0, 0, 0]); ***** test [idx, D] = rangesearch (x, y, 4, 'NSMethod', 'kdtree', 'SortIndices', true); assert_equal (idx, {[1, 4, 2]; [1, 4]}); assert_equal (D, {[1.7321, 3.3166, 3.4641]; [2, 3.4641]}, 1e-4); ***** test [idx, D] = rangesearch (x, y, 4, 'NSMethod', 'kdtree', 'SortIndices', false); assert_equal (idx, {[1, 2, 4]; [1, 4]}); assert_equal (D, {[1.7321, 3.4641, 3.3166]; [2, 3.4641]}, 1e-4); ***** error rangesearch (1) ***** error rangesearch (ones (4, 5)) ***** error ... rangesearch (ones (4, 5), ones (4)) ***** error ... rangesearch (ones (4, 5), ones (4), 1) ***** error ... rangesearch (ones (4, 2), ones (3, 2), 1, 'Distance', 'euclidean', 'some', 'some') ***** error ... rangesearch (ones (4, 5), ones (1, 5), 1, 'scale', ones (1, 5), 'P', 3) ***** error ... rangesearch (ones (4, 5), ones (1, 5), 1, 'P', -2) ***** error ... rangesearch (ones (4, 5), ones (1, 5), 1, 'scale', ones (4,5), 'distance', 'euclidean') ***** error ... rangesearch (ones (4, 5), ones (1, 5), 1, 'cov', ['some' 'some']) ***** error ... rangesearch (ones (4, 5), ones (1, 5), 1, 'cov', ones (4,5), 'distance', 'euclidean') ***** error ... rangesearch (ones (4, 5), ones (1, 5), 1, 'bucketsize', -1) ***** error ... rangesearch (ones (4,2), ones (1,2), 1, 'BucketSize', 2.5) ***** error ... rangesearch (ones (4, 5), ones (1, 5), 1, 'NSmethod', 'kdtree', 'distance', 'cosine') ***** error ... rangesearch (ones (4, 5), ones (1, 5), 1, 'NSmethod', 'kdtree', 'distance', 'mahalanobis') ***** error ... rangesearch (ones (4, 5), ones (1, 5), 1, 'NSmethod', 'kdtree', 'distance', 'correlation') ***** error ... rangesearch (ones (4, 5), ones (1, 5), 1, 'NSmethod', 'kdtree', 'distance', 'seuclidean') ***** error ... rangesearch (ones (4, 5), ones (1, 5), 1, 'NSmethod', 'kdtree', 'distance', 'spearman') ***** error ... rangesearch (ones (4, 5), ones (1, 5), 1, 'NSmethod', 'kdtree', 'distance', 'hamming') ***** error ... rangesearch (ones (4, 5), ones (1, 5), 1, 'NSmethod', 'kdtree', 'distance', 'jaccard') ***** error ... rangesearch (ones (4,2), ones (1,2), 1, 'Distance', @(x,y) sqrt (sum ((x-y).^2)), 'NSMethod', 'kdtree') 39 tests, 39 passed, 0 known failure, 0 skipped [inst/Nearest_Neighbors/KDTreeSearcher.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Nearest_Neighbors/KDTreeSearcher.m ***** demo ## Demo to verify implementation using fisheriris dataset load fisheriris numSamples = size (meas, 1); queryIndices = [1, 23, 46, 63, 109]; dataIndices = ! ismember (1:numSamples, queryIndices); queryPoints = meas(queryIndices, :); dataPoints = meas(dataIndices, :); searchRadius = 0.3; kdTree = KDTreeSearcher (dataPoints, 'Distance', 'minkowski') nearestNeighbors = knnsearch (kdTree, queryPoints, 'K', 2) neighborsInRange = rangesearch (kdTree, queryPoints, searchRadius) ***** demo ## Create a KDTreeSearcher with Euclidean distance X = [1, 2; 3, 4; 5, 6]; obj = KDTreeSearcher (X); ## Find the nearest neighbor to [2, 3] Y = [2, 3]; [idx, D] = knnsearch (obj, Y, 'K', 1); disp ('Nearest neighbor index:'); disp (idx); disp ('Distance:'); disp (D); ## Find all points within radius 2 [idx, D] = rangesearch (obj, Y, 2); disp ('Indices within radius:'); disp (idx); disp ('Distances:'); disp (D); ***** demo ## Create a KDTreeSearcher with Minkowski distance (P=3) X = [0, 0; 1, 0; 2, 0]; obj = KDTreeSearcher (X, 'Distance', 'minkowski', 'P', 3); ## Find the nearest neighbor to [1, 0] Y = [1, 0]; [idx, D] = knnsearch (obj, Y, 'K', 1); disp ('Nearest neighbor index:'); disp (idx); disp ('Distance:'); disp (D); ***** demo rng (42); disp ('Demonstrating KDTreeSearcher'); n = 100; mu1 = [0.3, 0.3]; mu2 = [0.7, 0.7]; sigma = 0.1; X1 = mu1 + sigma * randn (n / 2, 2); X2 = mu2 + sigma * randn (n / 2, 2); X = [X1; X2]; obj = KDTreeSearcher (X); Y = [0.3, 0.3; 0.7, 0.7; 0.5, 0.5]; K = 5; [idx, D] = knnsearch (obj, Y, 'K', K); disp ('For the first query point:'); disp (['Query point: ', num2str(Y(1,:))]); disp ('Indices of nearest neighbors:'); disp (idx(1,:)); disp ('Distances:'); disp (D(1,:)); figure; scatter (X(:,1), X(:,2), 36, 'b', 'filled'); # Training points hold on; scatter (Y(:,1), Y(:,2), 36, 'r', 'filled'); # Query points for i = 1:size (Y, 1) query = Y(i,:); neighbors = X(idx(i,:), :); for j = 1:K plot ([query(1), neighbors(j,1)], [query(2), neighbors(j,2)], 'k-'); endfor endfor hold off; title ('K Nearest Neighbors with KDTreeSearcher'); xlabel ('X1'); ylabel ('X2'); r = 0.15; [idx, D] = rangesearch (obj, Y, r); disp ('For the first query point in rangesearch:'); disp (['Query point: ', num2str(Y(1,:))]); disp ('Indices of points within radius:'); disp (idx{1}); disp ('Distances:'); disp (D{1}); figure; scatter (X(:,1), X(:,2), 36, 'b', 'filled'); hold on; scatter (Y(:,1), Y(:,2), 36, 'r', 'filled'); theta = linspace (0, 2 * pi, 100); for i = 1:size (Y, 1) center = Y(i,:); x_circle = center(1) + r * cos (theta); y_circle = center(2) + r * sin (theta); plot (x_circle, y_circle, 'g-'); ## Highlight points within radius if (! isempty (idx{i})) in_radius = X(idx{i}, :); scatter (in_radius(:,1), in_radius(:,2), 36, 'g', 'filled'); endif endfor hold off title ('Points within Radius with KDTreeSearcher'); xlabel ('X1'); ylabel ('X2'); ***** test load fisheriris X = meas; obj = KDTreeSearcher (X); Y = X(1:5,:); [idx, D] = knnsearch (obj, Y, 'K', 3); assert_equal (idx, [[1, 18, 5]; [2, 35, 46]; [3, 48, 4]; [4, 48, 30]; [5, 38, 1]]) assert_equal (D, [[0, 0.1000, 0.1414]; [0, 0.1414, 0.1414]; [0, 0.1414, 0.2449]; [0, 0.1414, 0.1732]; [0, 0.1414, 0.1414]], 5e-5) ***** test load fisheriris X = meas; obj = KDTreeSearcher (X, 'Distance', 'minkowski', 'P', 3); Y = X(10:15,:); [idx, D] = knnsearch (obj, Y, 'K', 2); assert_equal (idx, [[10, 35]; [11, 49]; [12, 30]; [13, 2]; [14, 39]; [15, 34]]) assert_equal (D, [[0, 0.1000]; [0, 0.1000]; [0, 0.2080]; [0, 0.1260]; [0, 0.2154]; [0, 0.3503]], 5e-5) ***** test load fisheriris X = meas; obj = KDTreeSearcher (X, 'Distance', 'cityblock'); Y = X(20:25,:); [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (idx, [20; 21; 22; 23; 24; 25]) assert_equal (D, [0; 0; 0; 0; 0; 0]) ***** test load fisheriris X = meas; obj = KDTreeSearcher (X, 'Distance', 'chebychev'); Y = X(30:35,:); [idx, D] = knnsearch (obj, Y, 'K', 4); assert_equal (idx, [[30, 31, 4, 12]; [31, 30, 10, 35]; [32, 21, 37, 28]; [33, 20, 34, 47]; [34, 16, 15, 33]; [35, 10, 2, 26]]) assert_equal (D, [[0, 0.1000, 0.1000, 0.2000]; [0, 0.1000, 0.1000, 0.1000]; [0, 0.2000, 0.2000, 0.2000]; [0, 0.3000, 0.3000, 0.3000]; [0, 0.2000, 0.3000, 0.3000]; [0, 0.1000, 0.1000, 0.1000]], 5e-15) ***** test load fisheriris X = meas; obj = KDTreeSearcher (X, 'BucketSize', 20); Y = X(40:45,:); [idx, D] = knnsearch (obj, Y, 'K', 2); assert_equal (idx, [[40, 8]; [41, 18]; [42, 9]; [43, 39]; [44, 27]; [45, 47]]) assert_equal (D, [[0, 0.1000]; [0, 0.1414]; [0, 0.6245]; [0, 0.2000]; [0, 0.2236]; [0, 0.3606]], 4.7e-5) ***** test load fisheriris X = meas; obj = KDTreeSearcher (X); Y = X(50:55,:); [idx, D] = knnsearch (obj, Y, 'K', 3, 'IncludeTies', true); assert_equal (idx, {[50, 8, 40]; [51, 53, 87]; [52, 57, 76]; ... [53, 51, 87]; [54, 90, 81]; [55, 59, 76]}) assert_equal (D, {[0, 0.1414, 0.1732]; [0, 0.2646, 0.3317]; ... [0, 0.2646, 0.3162]; [0, 0.2646, 0.2828]; ... [0, 0.2000, 0.3000]; [0, 0.2449, 0.3162]}, 5e-5) ***** test load fisheriris X = meas; obj = KDTreeSearcher (X); Y = X(60:65,:); [idx, D] = rangesearch (obj, Y, 0.4); assert_equal (idx, {[60, 90]; [61, 94]; ... [62, 97, 79, 96, 100, 89, 98, 72]; [63]; ... [64, 92, 74, 79]; [65]}) assert_equal (D, {[0, 0.3873]; [0, 0.3606]; ... [0, 0.3000, 0.3317, 0.3606, 0.3606, 0.3742, 0.3873, ... 0.4000]; [0]; [0, 0.1414, 0.2236, 0.2449]; [0]}, 5e-5) ***** test load fisheriris X = meas; obj = KDTreeSearcher (X, 'Distance', 'cityblock'); Y = X(70:72,:); [idx, D] = rangesearch (obj, Y, 1.0); assert_equal (idx, {[70, 81, 90, 82, 83, 93, 54, 68, 95, 80, 91, 100, ... 60, 65, 89, 63]; ... [71, 139, 128, 150, 127, 57, 86, 64, 79, 92, 124]; ... [72, 100, 98, 83, 93, 97, 75, 68, 62, 89, 95, 74, ... 56, 90, 79, 92, 96, 64, 63, 65]}) assert_equal (D, {[0, 0.3000, 0.4000, 0.5000, 0.5000, 0.5000, 0.6000, ... 0.7000, 0.7000, 0.7000, 0.8000, 0.8000, 0.9000, ... 0.9000, 0.9000, 0.9000]; ... [0, 0.3000, 0.5000, 0.5000, 0.7000, 0.8000, 0.8000, ... 1.0000, 1.0000, 1.0000, 1]; ... [0, 0.5000, 0.5000, 0.6000, 0.6000, 0.7000, 0.7000, ... 0.8000, 0.8000, 0.8000, 0.8000, 0.8000, 0.9000, ... 0.9000, 0.9000, 0.9000, 0.9000, 0.9000, 1.0000, 1]}, 5e-5) ***** test load fisheriris X = meas; obj = KDTreeSearcher (X, 'Distance', 'minkowski', 'P', 3); Y = X(80:85,:); [idx, D] = rangesearch (obj, Y, 0.8); assert_equal (idx, {[80, 82, 81, 65, 70, 83, 93, 90, 54, 63, 68, 72, ... 100, 60, 89, 99, 95, 94, 97, 96]; [81, 82, 70, 54, ... 90, 93, 80, 83, 60, 68, 95, 100, 65, 63, 97, 61, 91, ... 94, 89, 96, 72, 58, 62, 56]; [82, 81, 70, 80, 54, ... 90, 93, 83, 68, 60, 65, 63, 100, 95, 94, 61, 58, 97, ... 89, 72, 96, 91, 99]; [83, 93, 100, 68, 70, 72, 95, ... 90, 97, 65, 89, 96, 81, 82, 80, 62, 54, 98, 63, 91, ... 56, 60, 79, 67, 75, 88, 85, 92, 69]; [84, 134, 102, ... 143, 150, 124, 128, 73, 127, 139, 147, 64, 112, 114, ... 120, 74, 135, 122, 71, 92, 104, 138, 148, 117, 79, ... 55, 56, 57, 67, 111, 129, 69, 78, 59, 52, 133, 85, ... 88, 87]; [85, 67, 56, 97, 95, 89, 96, 91, 100, 62, ... 71, 122, 79, 60, 107, 90, 139, 93, 68, 86, 83, 92, ... 64, 150, 102, 143, 74, 114, 70, 128, 84, 54, 72]}) assert_equal (D, {[0, 0.2884, 0.3530, 0.3826, 0.4062, 0.4198, 0.5117, ... 0.5440, 0.5718, 0.6000, 0.6018, 0.6073, 0.6308, ... 0.6333, 0.6753, 0.7000, 0.7192, 0.7230, 0.7350, ... 0.7459]; [0, 0.1260, 0.1442, 0.2571, 0.2571, 0.3530, ... 0.3530, 0.3826, 0.4344, 0.4344, 0.4642, 0.4747, ... 0.5217, 0.5217, 0.5896, 0.6009, 0.6082, 0.6316, ... 0.6316, 0.6611, 0.6664, 0.6993, 0.7417, 0.7507]; [0, ... 0.1260, 0.2224, 0.2884, 0.3803, 0.3803, 0.4121, ... 0.4121, 0.4905, 0.5013, 0.5360, 0.5429, 0.5463, ... 0.5646, 0.5749, 0.5819, 0.6542, 0.6581, 0.6753, ... 0.6938, 0.7094, 0.7107, 0.7423]; [0, 0.1260, 0.2224, ... 0.2520, 0.2571, 0.3107, 0.3302, 0.3332, 0.3332, ... 0.3530, 0.3530, 0.3803, 0.3826, 0.4121, 0.4198, ... 0.4344, 0.4531, 0.5155, 0.5217, 0.5348, 0.6028, ... 0.6073, 0.6374, 0.6527, 0.6611, 0.6804, 0.6938, ... 0.7399, 0.7560]; [0, 0.3072, 0.3271, 0.3271, 0.3302, ... 0.3503, 0.3530, 0.3530, 0.3530, 0.3958, 0.3979, ... 0.4327, 0.4626, 0.4642, 0.5027, 0.5066, 0.5130, ... 0.5155, 0.5440, 0.5440, 0.5518, 0.5848, 0.6009, ... 0.6073, 0.6082, 0.6316, 0.6471, 0.6746, 0.6753, ... 0.6797, 0.6804, 0.7047, 0.7192, 0.7218, 0.7405, ... 0.7405, 0.7719, 0.7725, 0.7786]; [0, 0.2000, 0.3503, ... 0.3979, 0.4121, 0.4309, 0.4327, 0.4531, 0.4747, ... 0.5337, 0.5718, 0.5896, 0.6009, 0.6316, 0.6366, ... 0.6374, 0.6463, 0.6542, 0.6542, 0.6550, 0.6938, ... 0.7014, 0.7067, 0.7166, 0.7186, 0.7186, 0.7281, ... 0.7380, 0.7447, 0.7571, 0.7719, 0.7813, 0.7851]}, 5e-5) ***** test load fisheriris X = meas; obj = KDTreeSearcher (X, 'Distance', 'chebychev'); Y = X(90,:); [idx, D] = rangesearch (obj, Y, 0.7); assert_equal (idx, {[90, 70, 54, 81, 95, 60, 83, 93, 100, 68, 82, 65, ... 97, 91, 56, 61, 62, 63, 67, 79, 80, 85, 89, 96, 72, ... 92, 107]}) assert_equal (D, {[0, 0.2000, 0.2000, 0.2000, 0.2000, 0.3000, 0.3000, ... 0.3000, 0.3000, 0.3000, 0.3000, 0.4000, 0.4000, ... 0.4000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.6000, ... 0.6000, 0.6000]}, 5e-5) ***** test ## Constructor with single-point dataset X = [0, 0]; obj = KDTreeSearcher (X); assert_equal (obj.X, X); assert_equal (obj.Distance, "euclidean"); assert_equal (isempty (obj.DistParameter), true); assert_equal (obj.BucketSize, 50); ***** test ## Constructor with duplicate points X = [0, 0; 0, 0; 1, 0]; obj = KDTreeSearcher (X, 'Distance', 'cityblock'); assert_equal (obj.X, X); assert_equal (obj.Distance, "cityblock"); ***** test ## Constructor with 3D data X = [0, 0, 0; 1, 0, 0; 0, 1, 0]; obj = KDTreeSearcher (X, 'Distance', 'minkowski', 'P', 3); assert_equal (obj.X, X); assert_equal (obj.DistParameter, 3); ***** test ## knnsearch with grid, K = 1 X = [0, 0; 0, 1; 1, 0; 1, 1]; obj = KDTreeSearcher (X, 'Distance', 'euclidean'); Y = [0.5, 0.5]; [idx, D] = knnsearch (obj, Y, 'K', 1); D_true = pdist2 (X, Y, 'euclidean'); assert_equal (D, min (D_true), 1e-10); assert_equal (any (idx == find (D_true == min (D_true))), true); ***** test ## knnsearch with IncludeTies, all points equidistant X = [0, 0; 0, 1; 1, 0; 1, 1]; obj = KDTreeSearcher (X); Y = [0.5, 0.5]; [idx, D] = knnsearch (obj, Y, 'K', 1, 'IncludeTies', true); D_true = pdist2 (X, Y, 'euclidean'); expected_idx = find (D_true == min (D_true)); assert_equal (sort (idx{1}(:)), sort (expected_idx)); assert_equal (D{1}(:)', repmat (min (D_true), 1, 4), 1e-10); ***** test ## rangesearch with line dataset X = [0, 0; 1, 0; 2, 0; 3, 0]; obj = KDTreeSearcher (X); Y = [1.5, 0]; r = 1; [idx, D] = rangesearch (obj, Y, r); D_true = pdist2 (X, Y, 'euclidean'); expected_idx = find (D_true <= r); assert_equal (sort (idx{1}(:)), sort (expected_idx)); assert_equal (D{1}, sort (D_true(expected_idx))', 1e-10); ***** test ## knnsearch with duplicates X = [0, 0; 0, 0; 1, 0]; obj = KDTreeSearcher (X, 'Distance', 'cityblock'); Y = [0, 0]; [idx, D] = knnsearch (obj, Y, 'K', 1, 'IncludeTies', true); assert_equal (sort (idx{1}(:))', [1, 2]); assert_equal (D{1}, [0, 0], 1e-10); ***** test ## rangesearch with 3D data X = [0, 0, 0; 1, 0, 0; 0, 1, 0]; obj = KDTreeSearcher (X, 'Distance', 'cityblock'); Y = [0, 0, 0]; r = 1; [idx, D] = rangesearch (obj, Y, r); assert_equal (sort (idx{1}(:))', [1, 2, 3]); assert_equal (D{1}, [0, 1, 1], 1e-10); ***** test ## knnsearch with P = 2 (Euclidean equivalent) X = [0, 0; 1, 1]; obj = KDTreeSearcher (X, 'Distance', 'minkowski', 'P', 2); Y = [0, 1]; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (idx, 1); assert_equal (D, 1, 1e-10); ***** test ## rangesearch with P = 3 X = [0, 0; 1, 0; 0, 1]; obj = KDTreeSearcher (X, 'Distance', 'minkowski', 'P', 3); Y = [0.5, 0.5]; r = 0.8; [idx, D] = rangesearch (obj, Y, r); D_true = pdist2 (X, Y, 'minkowski', 3); expected_idx = find (D_true <= r); assert_equal (sort (idx{1}(:)), sort (expected_idx)); assert_equal (D{1}, sort (D_true(expected_idx))', 1e-10); ***** test ## knnsearch with P = 4, random data X = rand (5, 2); obj = KDTreeSearcher (X, 'Distance', 'minkowski', 'P', 4); Y = rand (1, 2); [idx, D] = knnsearch (obj, Y, 'K', 3); D_true = pdist2 (X, Y, 'minkowski', 4); [sorted_D, sort_idx] = sort (D_true); assert_equal (idx', sort_idx(1:3)); assert_equal (D', sorted_D(1:3), 1e-10); ***** test ## knnsearch with all same points X = [1, 1; 1, 1; 1, 1]; obj = KDTreeSearcher (X, 'Distance', 'chebychev'); Y = [1, 1]; [idx, D] = knnsearch (obj, Y, 'K', 1, 'IncludeTies', true); assert_equal (sort (idx{1}(:))', [1, 2, 3]); assert_equal (D{1}, [0, 0, 0], 1e-10); ***** test ## rangesearch with grid X = [0, 0; 0, 1; 1, 0; 1, 1]; obj = KDTreeSearcher (X, 'Distance', 'chebychev'); Y = [0.5, 0.5]; r = 0.5; [idx, D] = rangesearch (obj, Y, r); D_true = pdist2 (X, Y, 'chebychev'); expected_idx = find (D_true <= r); assert_equal (sort (idx{1}(:)), sort (expected_idx)); assert_equal (D{1}, D_true(expected_idx)', 1e-10); ***** test ## Changing Distance and verifying search X = [0,0; 1,0]; obj = KDTreeSearcher (X, 'Distance', 'euclidean'); Y = [0,1]; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (D, 1, 1e-10); obj.Distance = 'chebychev'; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (D, 1, 1e-10); ***** test ## Changing DistParameter for minkowski X = [0,0; 1,0]; obj = KDTreeSearcher (X, 'Distance', 'minkowski', 'P', 1); Y = [0,1]; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (D, 1, 1e-10); obj.DistParameter = 3; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (D, 1, 1e-10); ***** test ## Different BucketSize values X = rand (20,2); obj1 = KDTreeSearcher (X, 'BucketSize', 5); obj2 = KDTreeSearcher (X, 'BucketSize', 15); Y = rand (1,2); [idx1, D1] = knnsearch (obj1, Y, 'K', 3); [idx2, D2] = knnsearch (obj2, Y, 'K', 3); assert_equal (idx1, idx2); assert_equal (D1, D2, 1e-10); ***** test ## Basic constructor with default Euclidean X = [1, 2; 3, 4; 5, 6]; obj = KDTreeSearcher (X); assert_equal (obj.X, X); assert_equal (obj.Distance, "euclidean"); assert_equal (isempty (obj.DistParameter), true); assert_equal (obj.BucketSize, 50); ***** test ## Minkowski distance with custom P X = [0, 0; 1, 1; 2, 2]; obj = KDTreeSearcher (X, 'Distance', 'minkowski', 'P', 3); assert_equal (obj.Distance, "minkowski"); assert_equal (obj.DistParameter, 3); ***** test ## Cityblock distance X = [0, 0; 1, 0; 0, 1]; obj = KDTreeSearcher (X, 'Distance', 'cityblock'); assert_equal (obj.Distance, "cityblock"); assert_equal (isempty (obj.DistParameter), true); ***** test ## Chebychev distance X = [1, 1; 2, 3; 4, 2]; obj = KDTreeSearcher (X, 'Distance', 'chebychev'); assert_equal (obj.Distance, "chebychev"); assert_equal (isempty (obj.DistParameter), true); ***** test ## knnsearch with Euclidean distance X = [1, 2; 3, 4; 5, 6]; obj = KDTreeSearcher (X); Y = [2, 3]; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (idx, 1); assert_equal (D, sqrt (2), 1e-10); ***** test ## knnsearch with Cityblock distance X = [0, 0; 1, 1; 2, 2]; obj = KDTreeSearcher (X, 'Distance', 'cityblock'); Y = [1, 0]; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (ismember (idx, [1, 2]), true); assert_equal (D, 1, 1e-10); ***** test ## knnsearch with Chebychev distance X = [1, 1; 2, 3; 4, 2]; obj = KDTreeSearcher (X, 'Distance', 'chebychev'); Y = [2, 2]; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (ismember (idx, [1, 2]), true); assert_equal (D, 1, 1e-10); ***** test ## knnsearch with Minkowski P=3 X = [0, 0; 1, 0; 2, 0]; obj = KDTreeSearcher (X, 'Distance', 'minkowski', 'P', 3); Y = [1, 0]; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (idx, 2); assert_equal (D, 0, 1e-10); ***** test ## knnsearch with IncludeTies X = [0, 0; 1, 0; 0, 1]; obj = KDTreeSearcher (X); Y = [0.5, 0]; [idx, D] = knnsearch (obj, Y, 'K', 1, 'IncludeTies', true); assert_equal (iscell (idx), true); assert_equal (sort (idx{1}(:))', [1, 2]); assert_equal (sort (D{1}(:)), [0.5; 0.5], 1e-10); ***** test ## rangesearch with Euclidean X = [1, 1; 2, 2; 3, 3]; obj = KDTreeSearcher (X); Y = [0, 0]; [idx, D] = rangesearch (obj, Y, 2); assert_equal (idx{1}, [1]); assert_equal (D{1}, [sqrt(2)], 1e-10); ***** test ## rangesearch with Cityblock X = [0, 0; 1, 1; 2, 2]; obj = KDTreeSearcher (X, 'Distance', 'cityblock'); Y = [0, 0]; [idx, D] = rangesearch (obj, Y, 1); assert_equal (idx{1}, [1]); assert_equal (D{1}, [0], 1e-10); ***** test ## rangesearch with Chebychev X = [1, 1; 2, 3; 4, 2]; obj = KDTreeSearcher (X, 'Distance', 'chebychev'); Y = [2, 2]; [idx, D] = rangesearch (obj, Y, 1); assert_equal (sort (idx{1}(:))', [1, 2]); assert_equal (sort (D{1}(:))', [1, 1], 1e-10); ***** test ## rangesearch with Minkowski P=3 X = [0, 0; 1, 0; 2, 0]; obj = KDTreeSearcher (X, 'Distance', 'minkowski', 'P', 3); Y = [1, 0]; [idx, D] = rangesearch (obj, Y, 1); assert_equal (sort (idx{1}(:))', [1, 2, 3]); assert_equal (sort (D{1}(:))', [0, 1, 1], 1e-10); ***** test ## Diverse dataset with Euclidean X = [0, 10; 5, 5; 10, 0]; obj = KDTreeSearcher (X); Y = [5, 5]; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (idx, 2); assert_equal (D, 0, 1e-10); ***** test ## High-dimensional data with Cityblock X = [1, 2, 3; 4, 5, 6; 7, 8, 9]; obj = KDTreeSearcher (X, 'Distance', 'cityblock'); Y = [4, 5, 6]; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (idx, 2); assert_equal (D, 0, 1e-10); ***** test ## Each cell holds one row per query point, as MATLAB returns and as ## ExhaustiveSearcher does; this searcher used to return columns, so a ## caller could not swap one searcher for the other. X = [1, 1; 2, 2; 3, 3; 4, 4; 5, 5; 1, 5; 5, 1]; Y = [2, 2; 4, 4]; [idx, D] = rangesearch (KDTreeSearcher (X), Y, 2); assert_equal (size (idx), [2, 1]); assert_equal (rows (idx{1}), 1); assert_equal (rows (D{1}), 1); [ie, de] = rangesearch (ExhaustiveSearcher (X), Y, 2); assert_equal (idx, ie); assert_equal (D, de, 1e-12); ***** test ## knnsearch with ties returns cells in the same orientation X = [1, 1; 2, 2; 3, 3; 4, 4; 5, 5; 1, 5; 5, 1]; Y = [2, 2; 4, 4]; [idx, D] = knnsearch (KDTreeSearcher (X), Y, 'K', 2, 'IncludeTies', true); assert_equal (rows (idx{1}), 1); assert_equal (rows (D{1}), 1); ***** test ## Distance and P may be overridden per call: the tree is built from the ## data alone, so only the pruning bound changes. The object is unchanged. X = [1, 1; 2, 2; 3, 3; 4, 4; 5, 5; 1, 5; 5, 1]; Y = [2, 2; 4, 4]; o = KDTreeSearcher (X); assert_equal (knnsearch (o, Y, 'K', 3, 'Distance', 'cityblock'), ... knnsearch (KDTreeSearcher (X, 'Distance', 'cityblock'), ... Y, 'K', 3)); assert_equal (rangesearch (o, Y, 3, 'Distance', 'cityblock'), ... rangesearch (KDTreeSearcher (X, 'Distance', 'cityblock'), ... Y, 3)); assert_equal (o.Distance, 'euclidean'); ***** error ... knnsearch (KDTreeSearcher ([1, 1; 2, 2]), [1, 1], 'K', 1, 'Cov', eye (2)) ***** error ... knnsearch (KDTreeSearcher ([1, 1; 2, 2]), [1, 1], 'K', 1, 'Scale', [1, 1]) ***** error ... KDTreeSearcher () ***** error ... KDTreeSearcher (ones (3,2), 'Distance') ***** error ... KDTreeSearcher ('abc') ***** error ... KDTreeSearcher ([1; Inf; 3]) ***** error ... KDTreeSearcher (ones (3,2), 'foo', 'bar') ***** error ... KDTreeSearcher (ones (3,2), 'Distance', 'invalid') ***** error ... KDTreeSearcher (ones (3,2), 'Distance', 1) ***** error ... KDTreeSearcher (ones (3,2), 'Distance', 'minkowski', 'P', -1) ***** error ... KDTreeSearcher (ones (3,2), 'BucketSize', 0) ***** error ... KDTreeSearcher (ones (3,2), 'BucketSize', -1) ***** error ... knnsearch (KDTreeSearcher (ones (3,2))) ***** error ... knnsearch (KDTreeSearcher (ones (3,2)), ones (3,2), 'K', 1, 'IncludeTies') ***** error ... knnsearch (KDTreeSearcher (ones (3,2)), 'abc', 'K', 1) ***** error ... knnsearch (KDTreeSearcher (ones (3,2)), ones (3,3), 'K', 1) ***** error ... knnsearch (KDTreeSearcher (ones (3,2)), ones (3,2), 'K', 0) ***** error ... obj = KDTreeSearcher (ones (3,2)); knnsearch (obj, ones (1,2), 'K', Inf) ***** error ... knnsearch (KDTreeSearcher (ones (3,2)), ones (3,2), 'K', 1, 'foo', 'bar') ***** error ... knnsearch (KDTreeSearcher (ones (3,2)), ones (3,2), 'K', 1, 'IncludeTies', 1) ***** error ... knnsearch (KDTreeSearcher (ones (3,2)), ones (3,2), 'K', 1, 'SortIndices', 1) ***** error ... rangesearch (KDTreeSearcher (ones (3,2))) ***** error ... rangesearch (KDTreeSearcher (ones (3,2)), ones (3,2), 1, 'SortIndices') ***** error ... rangesearch (KDTreeSearcher (ones (3,2)), 'abc', 1) ***** error ... rangesearch (KDTreeSearcher (ones (3,2)), ones (3,3), 1) ***** error ... rangesearch (KDTreeSearcher (ones (3,2)), ones (3,2), -1) ***** error ... obj = KDTreeSearcher (ones (3,2)); rangesearch (obj, ones (1,2), Inf) ***** error ... rangesearch (KDTreeSearcher (ones (3,2)), ones (3,2), 1, 'foo', 'bar') ***** error ... rangesearch (KDTreeSearcher (ones (3,2)), ones (3,2), 1, 'SortIndices', 1) ***** error ... obj = KDTreeSearcher (ones (3,2)); obj(1) ***** error ... obj = KDTreeSearcher (ones (3,2)); obj{1} ***** error ... obj = KDTreeSearcher (ones (3,2)); obj.invalid ***** error ... obj = KDTreeSearcher (ones (3,2)); obj(1) = 1 ***** error ... obj = KDTreeSearcher (ones (3,2)); obj{1} = 1 ***** error ... obj = KDTreeSearcher (ones (3,2)); obj.X.Y = 1 ***** error ... obj = KDTreeSearcher (ones (3,2)); obj.X = 1 ***** error ... obj = KDTreeSearcher (ones (3,2)); obj.KDTree = 1 ***** error ... obj = KDTreeSearcher (ones (3,2)); obj.Distance = 'invalid' ***** error ... obj = KDTreeSearcher (ones (3,2)); obj.Distance = 1 ***** error ... obj = KDTreeSearcher (ones (3,2), 'Distance', 'minkowski'); obj.DistParameter = -1 ***** error ... obj = KDTreeSearcher (ones (3,2)); obj.DistParameter = 1 ***** error ... obj = KDTreeSearcher (ones (3,2)); obj.BucketSize = 0 ***** error ... obj = KDTreeSearcher (ones (3,2)); obj.BucketSize = -1 ***** error ... obj = KDTreeSearcher (ones (3,2)); obj.BucketSize = 1.5 ***** error ... obj = KDTreeSearcher (ones (3,2)); obj.invalid = 1 ***** test randn ("seed", 4); X = randn (20, 2); Y = randn (5, 2); kd = KDTreeSearcher (X); for K = [20, 21, 100] [idx, D] = knnsearch (kd, Y, "K", K); assert_equal (size (idx), [5, 20]); assert_equal (size (D), [5, 20]); assert_equal (any (isnan (idx(:))), false); endfor ## and it agrees with the exhaustive answer [~, Dk] = knnsearch (kd, Y, "K", 100); [~, De] = knnsearch (ExhaustiveSearcher (X), Y, "K", 100); assert_equal (Dk, De, 1e-12); ***** test X = [1, 2; 3, 4; 5, 6; 7, 8]; Y = [2, 3; 6, 7]; obj = KDTreeSearcher (single (X)); assert_equal (class (obj.X), 'single'); [idx, D] = knnsearch (obj, single (Y), "K", 2); assert_equal (class (idx), 'double'); assert_equal (class (D), 'single'); ## a double query against single data is still computed in single [~, Dm] = knnsearch (obj, Y, "K", 2); assert_equal (class (Dm), 'single'); assert_equal (Dm, D); ## and so is a single query against double data [~, Ds] = knnsearch (KDTreeSearcher (X), single (Y), "K", 2); assert_equal (class (Ds), 'single'); ## double throughout stays double [~, Dd] = knnsearch (KDTreeSearcher (X), Y, "K", 2); assert_equal (class (Dd), 'double'); ***** test X = int32 ([10, 20; 33, 41; 55, 62]); Y = [21, 33]; obj = KDTreeSearcher (X); assert_equal (class (obj.X), 'double'); [~, D] = knnsearch (obj, Y, "K", 1); assert_equal (D, min (sqrt (sum ((double (X) - Y) .^ 2, 2))), 1e-12); ***** test X = [1, 2; 3, 4; 5, 6; 7, 8]; Y = [2, 3]; [idx, D] = rangesearch (KDTreeSearcher (single (X)), single (Y), 4); assert_equal (class (idx{1}), 'double'); assert_equal (class (D{1}), 'single'); 93 tests, 93 passed, 0 known failure, 0 skipped [inst/Nearest_Neighbors/pdist.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Nearest_Neighbors/pdist.m ***** shared xy, t, eucl, x xy = [0 1; 0 2; 7 6; 5 6]; t = 1e-3; eucl = @(v,m) sqrt (sumsq (repmat (v,rows (m),1)-m,2)); x = [1 2 3; 4 5 6; 7 8 9; 3 2 1]; ***** assert_equal (pdist (xy), [1.000 8.602 7.071 8.062 6.403 2.000], t); ***** assert_equal (pdist (xy, eucl), [1.000 8.602 7.071 8.062 6.403 2.000], t); ***** assert_equal (pdist (xy, 'euclidean'), [1.000 8.602 7.071 8.062 6.403 2.000], t); ***** assert_equal (pdist (xy, 'seuclidean'), [0.380 2.735 2.363 2.486 2.070 0.561], t); ***** assert_equal (pdist (xy, 'mahalanobis'), [1.384 1.967 2.446 2.384 1.535 2.045], t); ***** assert_equal (pdist (xy, 'cityblock'), [1.000 12.00 10.00 11.00 9.000 2.000], t); ***** assert_equal (pdist (xy, 'minkowski'), [1.000 8.602 7.071 8.062 6.403 2.000], t); ***** assert_equal (pdist (xy, 'minkowski', 3), [1.000 7.763 6.299 7.410 5.738 2.000], t); ***** assert_equal (pdist (xy, 'cosine'), [0.000 0.349 0.231 0.349 0.231 0.013], t); ***** assert_equal (pdist (xy, 'correlation'), [0.000 2.000 0.000 2.000 0.000 2.000], t); ***** assert_equal (pdist (xy, 'spearman'), [0.000 2.000 0.000 2.000 0.000 2.000], t); ***** assert_equal (pdist (xy, 'hamming'), [0.500 1.000 1.000 1.000 1.000 0.500], t); ***** assert_equal (pdist (xy, 'jaccard'), [1.000 1.000 1.000 1.000 1.000 0.500], t); ***** assert_equal (pdist (xy, 'chebychev'), [1.000 7.000 5.000 7.000 5.000 2.000], t); ***** assert_equal (pdist (x), [5.1962, 10.3923, 2.8284, 5.1962, 5.9161, 10.7703], 1e-4); ***** assert_equal (pdist (x, 'euclidean'), ... [5.1962, 10.3923, 2.8284, 5.1962, 5.9161, 10.7703], 1e-4); ***** assert_equal (pdist (x, eucl), ... [5.1962, 10.3923, 2.8284, 5.1962, 5.9161, 10.7703], 1e-4); ***** assert_equal (pdist (x, 'squaredeuclidean'), [27, 108, 8, 27, 35, 116]); ***** assert_equal (pdist (x, 'seuclidean'), ... [1.8071, 3.6142, 0.9831, 1.8071, 1.8143, 3.4854], 1e-4); ***** warning ... pdist (x, 'mahalanobis'); ***** assert_equal (pdist (x, 'cityblock'), [9, 18, 4, 9, 9, 18]); ***** assert_equal (pdist (x, 'minkowski'), ... [5.1962, 10.3923, 2.8284, 5.1962, 5.9161, 10.7703], 1e-4); ***** assert_equal (pdist (x, 'minkowski', 3), ... [4.3267, 8.6535, 2.5198, 4.3267, 5.3485, 9.2521], 1e-4); ***** assert_equal (pdist (x, 'cosine'), ... [0.0254, 0.0406, 0.2857, 0.0018, 0.1472, 0.1173], 1e-4); ***** assert_equal (pdist (x, 'correlation'), [0, 0, 2, 0, 2, 2], 1e-14); ***** assert_equal (pdist (x, 'spearman'), [0, 0, 2, 0, 2, 2], 1e-14); ***** assert_equal (pdist (x, 'hamming'), [1, 1, 2/3, 1, 1, 1]); ***** assert_equal (pdist (x, 'jaccard'), [1, 1, 2/3, 1, 1, 1]); ***** assert_equal (pdist (x, 'chebychev'), [3, 6, 2, 3, 5, 8]); ***** test ## A row is never at a negative distance from itself, the similarity of ## identical rows being able to round a step above one. X = [-3, -3; -3, -3]; assert_equal (pdist (X, "cosine") >= 0, true); ***** test ## Neither do the other two metrics built as one minus a similarity, on ## either the vectorised path or the blocked one taken for large N. Y = [1, 2, 4; 2, 4, 8; -1, -2, -4; 3, 6, 12]; for m = {"cosine", "correlation", "spearman"} assert_equal (any (pdist (Y, m{1}) < 0), false); assert_equal (any (pdist (repmat (Y, 300, 1), m{1}) < 0), false); endfor 31 tests, 31 passed, 0 known failure, 0 skipped [inst/Nearest_Neighbors/squareform.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Nearest_Neighbors/squareform.m ***** shared v, m v = 1:6; m = [0, 1, 2, 3; 1, 0, 4, 5; 2, 4, 0, 6; 3, 5, 6, 0]; ***** test ***** assert_equal (squareform (v), m) ***** assert_equal (squareform (squareform (v)), v) ***** assert_equal (squareform (m), v) ***** test ***** assert_equal (squareform (v'), m) ***** test ***** assert_equal (squareform (1), [0 1;1 0]) ***** assert_equal (squareform (1, 'tomatrix'), [0 1; 1 0]) ***** assert_equal (squareform (0, 'tovector'), zeros (1, 0)) ***** test for c = {@single, @double, @uint8, @uint16, @uint32, @uint64, @logical} f = c{1}; assert_equal (squareform (f(v)), f(m)) assert_equal (squareform (f(m)), f(v)) endfor ***** test v_log = [true, false, true]; m_log = [false, true, false; true, false, true; false, true, false]; assert_equal (squareform (v_log), m_log); assert_equal (squareform (m_log), v_log); ***** assert_equal (squareform (v, 'tom'), m); ***** assert_equal (squareform (m, 'tov'), v); ***** assert_equal (squareform (v, 'TOMATRIX'), m); ***** assert_equal (squareform (v, string ('tomatrix')), m); ***** assert_equal (squareform (m, string ('tovector')), v); ***** error ... squareform ('string') ***** error ... squareform ({1, 2, 3}) ***** error ... squareform ([1, 2, 3; 4, 5, 6], 'tovector') ***** error ... squareform (eye (3), 'tovector') ***** error ... squareform ([1, 2, 3; 4, 5, 6], string ({'tomatrix', 'tomatrix'})) ***** error ... squareform ([1, 2, 3; 4, 5, 6], true) ***** error ... squareform ([1, 2, 3, 4], 'tomatrix') ***** error squareform ([1, 2, 3], 'invalid') 25 tests, 25 passed, 0 known failure, 0 skipped [inst/Nearest_Neighbors/nomdist2.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Nearest_Neighbors/nomdist2.m ***** shared X X = [1, 1, 1; 1, 2, 1; 1, 1, 2; 2, 2, 2; 2, 1, 1; 3, 2, 2; 4, 1, 3]; ***** test D = squareform (nomdist (X)); D2 = nomdist2 (X, X); assert_equal (D2(! eye (7)), D(! eye (7))); ***** test D = squareform (nomdist (X, 'lin1', 'Weights', [0.7, 1, 0.4])); D2 = nomdist2 (X, X, 'lin1', 'Weights', [0.7, 1, 0.4]); assert_equal (D2(! eye (7)), D(! eye (7))); ***** test ## Identical rows need not be at 0: 1 - (3 - 24/42) / 3 D2 = nomdist2 (X, X); assert_equal (D2(1,1), 4 / 21, -1e-14); ***** assert_equal (size (nomdist2 (X, X(1:2,:))), [7, 2]) ***** assert_equal (nomdist2 (X, X(1:2,:), 'of'), nomdist2 (X, X, 'of')(:,1:2)) ***** assert_equal (nomdist2 ([1; 1; 2], [1; 2; 2]), [1/3, 1, 1; 1/3, 1, 1; ... 1, 0, 0], -1e-14) ***** assert_equal (nomdist2 ([1; 2; 2], [1; 1; 2]), [0, 0, 1; 1, 1, 1/3; ... 1, 1, 1/3], -1e-14) ***** test A = [1, 1; 2, 1; 2, 2]; B = [1, 2; 3, 1]; D = squareform (nomdist ([A; B], 'lin')); assert_equal (nomdist2 (A, B, 'lin', 'Reference', [A; B]), D(1:3,4:5), ... -1e-14); ***** assert_equal (nomdist2 (X, zeros (0, 3)), zeros (7, 0)) ***** test T = table ([1; 2; 2], {'a'; 'a'; 'b'}, 'VariableNames', {'A', 'B'}); U = table ({'b'; 'a'}, [2; 1], 'VariableNames', {'B', 'A'}); assert_equal (nomdist2 (T, U, 'sm'), [1, 0; 0.5, 0.5; 0, 1]); ***** test ## A new level of Y: OF scores its variable 0 s = 1 / (1 + log (3) * log (3 / 2)); D = nomdist2 ([1, 1; 2, 1; 2, 2], [3, 1; 3, 2], 'of'); assert_equal (D, [1, 2/s-1; 1, 2/s-1; 2/s-1, 1], -1e-14); ***** assert_equal (nomdist2 ({'a'; 'b'}, {'c'; 'a'}, 'burnaby'), [1, 0; 1, 0]) ***** assert_equal (nomdist2 ([1; 2], [3; 1], 'anderberg'), [1, 0; 1, 1]) ***** assert_equal (nomdist2 ([1; 2], [3; 1], 'lin'), [Inf, 0; Inf, Inf]) ***** assert_equal (nomdist2 ([1; 2], [3; 1], 'goodall4'), [1, 1; 1, 1]) ***** assert_equal (nomdist2 ([1, 1; 1, 1; 2, 1; 2, 1], [1, 3], 'iof', ... 'Weights', [1, 0]), [0; 0; 1; 1] * log (2) ^ 2, ... -1e-14) ***** assert_equal (nomdist2 ([1, 1; 1, 2], [2, 1], 'of', 'Weights', [0, 1]), ... [0; log(2) ^ 2], -1e-14) ***** assert_equal (nomdist2 ([1; 2], [3; 1], 'iof', 'Reference', ... [1; 1; 2; 2; 3; 3]), [1, 0; 1, 1] * log (2) ^ 2, ... -1e-14) ***** test A = [1; 1; 2; 2]; E = [nomdist2(A, 3, 'iof', 'Reference', [A; 3]), ... nomdist2(A, 1, 'iof', 'Reference', [A; 1])]; assert_equal (nomdist2 (A, [3; 1], 'iof', 'CountQuery', true), E); ***** test Y = X([2, 6],:); E = [nomdist2(X, Y(1,:), 'Reference', [X; Y(1,:)]), ... nomdist2(X, Y(2,:), 'Reference', [X; Y(2,:)])]; assert_equal (nomdist2 (X, Y, 'CountQuery', true), E); ***** test R = [X; 2, 2, 1]; Y = [1, 1, 3; 4, 2, 2]; E = [nomdist2(X, Y(1,:), 'lin', 'Reference', [R; Y(1,:)]), ... nomdist2(X, Y(2,:), 'lin', 'Reference', [R; Y(2,:)])]; assert_equal (nomdist2 (X, Y, 'lin', 'Reference', R, 'CountQuery', 1), E); ***** assert_equal (nomdist2 (X, X, 'of', 'CountQuery', false), ... nomdist2 (X, X, 'of')) ***** error nomdist2 ([1; 2]) ***** error ... nomdist2 ([1; 2], {1; 2}) ***** error ... nomdist2 ([1; 2], table ([1; 2])) ***** error ... nomdist2 (table ([1; 2]), [1; 2]) ***** error ... nomdist2 (table ([1; 2]), table ([1; 2], 'VariableNames', {'Z'})) ***** error ... nomdist2 (table ([1; 2], 'VariableNames', {'A'}), ... table ([1, 2], 'VariableNames', {'A'})) ***** error ... nomdist2 ([1; 2], [1, 2]) ***** error ... nomdist2 ([1; 2], {'a'}) ***** error ... nomdist2 ([1; 2], [1; NaN]) ***** error ... nomdist2 ([1; 2], [3; 1], 'iof') ***** error ... nomdist2 ([1; 1], 2, 'of') ***** error ... nomdist2 ([1; 1], 2, 'burnaby') ***** error ... nomdist2 ([1; 2], 1, 'CountQuery', 'yes') ***** error ... nomdist2 ([1; 2], 1, 'CountQuery', 2) 36 tests, 36 passed, 0 known failure, 0 skipped [inst/Nearest_Neighbors/createns.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Nearest_Neighbors/createns.m ***** test ## Default ExhaustiveSearcher X = [1, 2; 3, 4; 5, 6]; obj = createns (X); assert_equal (isa (obj, 'ExhaustiveSearcher'), true); assert_equal (obj.X, X); assert_equal (obj.Distance, "euclidean"); ***** test ## KDTreeSearcher with default parameters X = [1, 2; 3, 4; 5, 6]; obj = createns (X, 'NSMethod', 'kdtree'); assert_equal (isa (obj, 'KDTreeSearcher'), true); assert_equal (obj.X, X); assert_equal (obj.Distance, "euclidean"); ***** test ## hnswSearcher with custom parameters X = [1, 2; 3, 4; 5, 6]; obj = createns (X, 'NSMethod', 'hnsw', 'MaxNumLinksPerNode', 2, 'TrainSetSize', 3); assert_equal (isa (obj, 'hnswSearcher'), true); assert_equal (obj.X, X); assert_equal (obj.MaxNumLinksPerNode, 2); assert_equal (obj.TrainSetSize, 3); ***** test ## ExhaustiveSearcher with custom distance X = [1, 2; 3, 4]; obj = createns (X, 'NSMethod', 'exhaustive', 'Distance', 'cityblock'); assert_equal (isa (obj, 'ExhaustiveSearcher'), true); assert_equal (obj.Distance, "cityblock"); ***** error createns () ***** error X = [1, 2; 3, 4]; createns (X, 'NSMethod') ***** error createns ([1; Inf; 3]) ***** error X = [1, 2; 3, 4]; createns (X, 'NSMethod', 1) ***** error X = [1, 2; 3, 4]; createns (X, 'NSMethod', 'invalid') 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Nearest_Neighbors/ExhaustiveSearcher.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Nearest_Neighbors/ExhaustiveSearcher.m ***** demo ## Demo to verify implementation using fisheriris dataset load fisheriris numSamples = size (meas, 1); queryIndices = [20, 95, 123, 136, 138]; dataPoints = meas(! ismember (1:numSamples, queryIndices), :); queryPoints = meas(queryIndices, :); searchModel = ExhaustiveSearcher (dataPoints, 'Distance', 'mahalanobis') mahalanobisParam = searchModel.DistParameter searchRadius = 3; nearestNeighbors = knnsearch (searchModel, queryPoints, 'K', 2) neighborsInRange = rangesearch (searchModel, queryPoints, searchRadius) ***** demo ## Create an ExhaustiveSearcher with Euclidean distance X = [1, 2; 3, 4; 5, 6]; obj = ExhaustiveSearcher (X); ## Find the nearest neighbor to [2, 3] Y = [2, 3]; [idx, D] = knnsearch (obj, Y); disp ('Nearest neighbor index:'); disp (idx); disp ('Distance:'); disp (D); ## Find all points within radius 2 [idx, D] = rangesearch (obj, Y, 2); disp ('Indices within radius:'); disp (idx); disp ('Distances:'); disp (D); ***** demo ## Create an ExhaustiveSearcher with Minkowski distance (P=1) X = [0, 0; 1, 0; 0, 1]; obj = ExhaustiveSearcher (X, 'Distance', 'minkowski', 'P', 1); ## Find the 2 nearest neighbors to [0.5, 0.5] Y = [0.5, 0.5]; [idx, D] = knnsearch (obj, Y, 'K', 2); disp ('Nearest neighbor indices:'); disp (idx); disp ('Distances:'); disp (D); ***** demo rng (42); disp ('Demonstrating ExhaustiveSearcher'); n = 100; mu1 = [0.3, 0.3]; mu2 = [0.7, 0.7]; sigma = 0.1; X1 = mu1 + sigma * randn (n/2, 2); X2 = mu2 + sigma * randn (n/2, 2); X = [X1; X2]; obj = ExhaustiveSearcher (X); Y = [0.3, 0.3; 0.7, 0.7; 0.5, 0.5]; K = 5; [idx, D] = knnsearch (obj, Y, 'K', K); disp ('For the first query point:'); disp (['Query point: ', num2str(Y(1,:))]); disp ('Indices of nearest neighbors:'); disp (idx(1,:)); disp ('Distances:'); disp (D(1,:)); figure; scatter (X(:,1), X(:,2), 36, 'b', 'filled'); % Training points hold on; scatter (Y(:,1), Y(:,2), 36, 'r', 'filled'); % Query points for i = 1:size (Y,1) query = Y(i,:); neighbors = X(idx(i,:), :); for j = 1:K plot ([query(1), neighbors(j,1)], [query(2), neighbors(j,2)], 'k-'); endfor endfor hold off; title ('K Nearest Neighbors with ExhaustiveSearcher'); xlabel ('X1'); ylabel ('X2'); r = 0.15; [idx, D] = rangesearch (obj, Y, r); disp ('For the first query point in rangesearch:'); disp (['Query point: ', num2str(Y(1,:))]); disp ('Indices of points within radius:'); disp (idx{1}); disp ('Distances:'); disp (D{1}); figure; scatter (X(:,1), X(:,2), 36, 'b', 'filled'); hold on; scatter (Y(:,1), Y(:,2), 36, 'r', 'filled'); theta = linspace (0, 2*pi, 100); for i = 1:size (Y,1) center = Y(i,:); x_circle = center(1) + r * cos (theta); y_circle = center(2) + r * sin (theta); plot (x_circle, y_circle, 'g-'); % Highlight points within radius if ! isempty (idx{i}) in_radius = X(idx{i}, :); scatter (in_radius(:,1), in_radius(:,2), 36, 'g', 'filled'); endif endfor hold off; title ('Points within Radius with ExhaustiveSearcher'); xlabel ('X1'); ylabel ('X2'); ***** test ## Basic constructor with default Euclidean X = [1, 2; 3, 4; 5, 6]; obj = ExhaustiveSearcher (X); assert_equal (obj.X, X) assert_equal (obj.Distance, "euclidean") assert_equal (isempty (obj.DistParameter), true) ***** test ## Minkowski distance with custom P X = [1, 2; 3, 4]; obj = ExhaustiveSearcher (X, 'Distance', 'minkowski', 'P', 3); assert_equal (obj.Distance, "minkowski") assert_equal (obj.DistParameter, 3) ***** test ## Seuclidean distance with custom Scale X = [1, 2; 3, 4; 5, 6]; S = [1, 2]; obj = ExhaustiveSearcher (X, 'Distance', 'seuclidean', 'Scale', S); assert_equal (obj.Distance, "seuclidean") assert_equal (obj.DistParameter, S) ***** test ## Mahalanobis distance with custom Cov X = [1, 2; 3, 4; 5, 6]; C = [1, 0; 0, 1]; obj = ExhaustiveSearcher (X, 'Distance', 'mahalanobis', 'Cov', C); assert_equal (obj.Distance, "mahalanobis") assert_equal (obj.DistParameter, C) ***** test ## knnsearch with Euclidean distance X = [1, 2; 3, 4; 5, 6]; obj = ExhaustiveSearcher (X); Y = [2, 3]; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (idx, 1) assert_equal (D, sqrt (2), 1e-10) ***** test ## knnsearch with Cityblock distance X = [0, 0; 1, 1; 2, 2]; obj = ExhaustiveSearcher (X, 'Distance', 'cityblock'); Y = [1, 0]; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (idx, 1) assert_equal (D, 1, 1e-10) ***** test ## knnsearch with Chebychev distance X = [1, 1; 2, 3; 4, 2]; obj = ExhaustiveSearcher (X, 'Distance', 'chebychev'); Y = [2, 2]; [idx, D] = knnsearch (obj, Y); assert_equal (idx, 1) assert_equal (D, 1, 1e-10) ***** test ## knnsearch with Cosine distance X = [1, 0; 0, 1; 1, 1]; obj = ExhaustiveSearcher (X, 'Distance', 'cosine'); Y = [1, 0.5]; [idx, D] = knnsearch (obj, Y); assert_equal (idx, 3) assert_equal (D < 0.1, true) ***** test ## knnsearch with Minkowski P=1 (Manhattan) X = [0, 0; 1, 0; 0, 1]; obj = ExhaustiveSearcher (X, 'Distance', 'minkowski', 'P', 1); Y = [0.5, 0.5]; [idx, D] = knnsearch (obj, Y, 'K', 2, 'IncludeTies', true); assert_equal (iscell (idx), true) assert_equal (idx{1}, [1, 2, 3]) assert_equal (D{1}, [1, 1, 1], 1e-10) ***** test ## rangesearch with Seuclidean X = [1, 1; 2, 2; 3, 3]; S = [1, 1]; obj = ExhaustiveSearcher (X, 'Distance', 'seuclidean', 'Scale', S); Y = [0, 0]; [idx, D] = rangesearch (obj, Y, 2); assert_equal (idx{1}, [1]) assert_equal (D{1}, [sqrt(2)], 1e-10) ***** test ## rangesearch with Mahalanobis X = [1, 1; 2, 2; 3, 3]; C = [1, 0; 0, 1]; obj = ExhaustiveSearcher (X, 'Distance', 'mahalanobis', 'Cov', C); Y = [0, 0]; [idx, D] = rangesearch (obj, Y, 3, 'SortIndices', false); assert_equal (idx{1}, [1, 2]) assert_equal (D{1}, [sqrt(2), sqrt(8)], 1e-10) ***** test ## rangesearch with Hamming distance X = [0, 1; 1, 0; 1, 1]; obj = ExhaustiveSearcher (X, 'Distance', 'hamming'); Y = [0, 0]; [idx, D] = rangesearch (obj, Y, 0.5); assert_equal (idx{1}, [1, 2]) assert_equal (D{1}, [0.5, 0.5], 1e-10) ***** test ## Custom distance function X = [1, 2; 3, 4]; custom_dist = @(x, y) sum (abs (x - y)); obj = ExhaustiveSearcher (X, 'Distance', custom_dist); Y = [2, 3]; [idx, D] = knnsearch (obj, Y); assert_equal (idx, 1) assert_equal (D, 2, 1e-10) ***** test ## IncludeTies returns all tied neighbors X = [0; 1; 2]; obj = ExhaustiveSearcher (X); Y = 1; [idx, D] = knnsearch (obj, Y, 'K', 2, 'IncludeTies', true); assert_equal (idx{1}, [2, 1, 3]) assert_equal (D{1}, [0, 1, 1]) ***** test ## Custom distance function with vectorized output X = [1, 2; 3, 4]; f = @(x, y) sum (abs (x - y), 2); obj = ExhaustiveSearcher (X, 'Distance', f); Y = [2, 3]; [idx, D] = knnsearch (obj, Y); assert_equal (idx, 1) assert_equal (D, 2) ***** test ## Euclidean with high-dimensional data X = [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12]; obj = ExhaustiveSearcher (X); Y = [5, 6, 7]; [idx, D] = knnsearch (obj, Y); assert_equal (idx, 2) assert_equal (D, sqrt (3), 1e-10) ***** test ## Minkowski P=3 with scaled data X = [0, 1; 2, 3; 4, 5] * 10; obj = ExhaustiveSearcher (X, 'Distance', 'minkowski', 'P', 3); Y = [20, 30]; [idx, D] = knnsearch (obj, Y); assert_equal (idx, 2) assert_equal (D, 0, 1e-10) ***** test ## Seuclidean with custom scales on diverse data X = [1, 10; 2, 20; 3, 30]; S = [1, 5]; obj = ExhaustiveSearcher (X, 'Distance', 'seuclidean', 'Scale', S); Y = [1.5, 15]; [idx, D] = knnsearch (obj, Y); assert_equal (idx, 1) assert_equal (D, sqrt ((0.5/1)^2 + (5/5)^2), 1e-10) ***** test ## Mahalanobis with correlated data X = [1, 1; 2, 1.5; 3, 2]; C = [1, 0.5; 0.5, 1]; obj = ExhaustiveSearcher (X, 'Distance', 'mahalanobis', 'Cov', C); Y = [2, 1.5]; [idx, D] = knnsearch (obj, Y); assert_equal (idx, 2) assert_equal (D, 0, 1e-10) ***** test ## Cityblock with sparse data X = [0, 0, 1; 1, 0, 0; 0, 1, 0]; obj = ExhaustiveSearcher (X, 'Distance', 'cityblock'); Y = [0, 0, 0]; [idx, D] = rangesearch (obj, Y, 1); assert_equal (idx{1}, [1, 2, 3]) assert_equal (D{1}, [1, 1, 1], 1e-10) ***** test ## Chebychev with extreme values X = [0, 100; 50, 50; 100, 0]; obj = ExhaustiveSearcher (X, 'Distance', 'chebychev'); Y = [60, 60]; [idx, D] = knnsearch (obj, Y); assert_equal (idx, 2) assert_equal (D, 10, 1e-10) ***** test ## Cosine with normalized data X = [1, 0; 0, 1; 1/sqrt(2), 1/sqrt(2)]; obj = ExhaustiveSearcher (X, 'Distance', 'cosine'); Y = [1, 1]; [idx, D] = knnsearch (obj, Y); assert_equal (idx, 3) assert_equal (D < 0.1, true) ***** test ## Correlation with time-series-like data X = [1, 2, 3; 2, 4, 6; 1, 1, 1]; obj = ExhaustiveSearcher (X, 'Distance', 'correlation'); Y = [1.5, 3, 4.5]; [idx, D] = knnsearch (obj, Y); assert_equal (idx, 1) assert_equal (D < 0.1, true) ***** test ## Spearman with ranked data X = [1, 2, 3; 3, 2, 1; 2, 1, 3]; obj = ExhaustiveSearcher (X, 'Distance', 'spearman'); Y = [1, 2, 3]; [idx, D] = knnsearch (obj, Y); assert_equal (idx, 1) assert_equal (D, 0, 1e-10) ***** test ## Jaccard with binary sparse data X = [1, 0, 0; 0, 1, 0; 1, 1, 0]; obj = ExhaustiveSearcher (X, 'Distance', 'jaccard'); Y = [1, 0, 0]; [idx, D] = knnsearch (obj, Y); assert_equal (idx, 1) assert_equal (D, 0, 1e-10) ***** test obj = ExhaustiveSearcher (ones (3,2)); assert_equal (obj.X, ones (3,2)) assert_equal (obj.Distance, "euclidean") assert_equal (isempty (obj.DistParameter), true) ***** test obj = ExhaustiveSearcher (ones (3,2)); obj.Distance = 'minkowski'; assert_equal (obj.Distance, "minkowski") ***** test obj = ExhaustiveSearcher (ones (3,2), 'Distance', 'minkowski'); obj.DistParameter = 3; assert_equal (obj.DistParameter, 3) ***** test obj = ExhaustiveSearcher (ones (3,2), 'Distance', 'seuclidean'); obj.DistParameter = [1, 2]; assert_equal (obj.DistParameter, [1, 2]) ***** test obj = ExhaustiveSearcher (ones (3,2), 'Distance', 'mahalanobis'); obj.DistParameter = eye (2); assert_equal (obj.DistParameter, eye (2)) ***** test ## A metric given per call overrides the searcher's own for that call, ## matching a searcher built with it, and leaves the object unchanged. X = [1, 1; 2, 2; 3, 3; 4, 4; 5, 5; 1, 5; 5, 1]; Y = [2, 2; 4, 4]; o = ExhaustiveSearcher (X); assert_equal (knnsearch (o, Y, 'K', 3, 'Distance', 'cityblock'), ... knnsearch (ExhaustiveSearcher (X, 'Distance', 'cityblock'), ... Y, 'K', 3)); assert_equal (rangesearch (o, Y, 3, 'Distance', 'cityblock'), ... rangesearch (ExhaustiveSearcher (X, 'Distance', ... 'cityblock'), Y, 3)); assert_equal (knnsearch (o, Y, 'K', 2, 'Distance', 'minkowski', 'P', 3), ... knnsearch (ExhaustiveSearcher (X, 'Distance', 'minkowski', ... 'P', 3), Y, 'K', 2)); ## the searcher keeps its own metric assert_equal (o.Distance, 'euclidean'); assert_equal (isempty (o.DistParameter), true); ***** error ... knnsearch (ExhaustiveSearcher ([1, 1; 2, 2]), [1, 1], 'K', 1, ... 'Distance', 'cityblock', 'P', 3) ***** error ... knnsearch (ExhaustiveSearcher ([1, 1; 2, 2]), [1, 1], 'K', 1, ... 'Distance', 'bogus') ***** error ... ExhaustiveSearcher () ***** error ... ExhaustiveSearcher (ones (3,2), 'Distance') ***** error ... ExhaustiveSearcher ('abc') ***** error ... ExhaustiveSearcher ([1; Inf; 3]) ***** error ... ExhaustiveSearcher (ones (3,2), 'foo', 'bar') ***** error ... ExhaustiveSearcher (ones (3,2), 'Distance', 'invalid') ***** error ... ExhaustiveSearcher (ones (3,2), 'Distance', @(x) x) ***** error ... ExhaustiveSearcher (ones (3,2), 'Distance', 1) ***** error ... ExhaustiveSearcher (ones (3,2), 'Distance', 'minkowski', 'P', -1) ***** error ... ExhaustiveSearcher (ones (3,2), 'Distance', 'seuclidean', 'Scale', [-1, 1]) ***** error ... ExhaustiveSearcher (ones (3,2), 'Distance', 'mahalanobis', 'Cov', ones (3,3)) ***** error ... ExhaustiveSearcher (ones (3,2), 'Distance', 'mahalanobis', 'Cov', -eye (2)) ***** error ... knnsearch (ExhaustiveSearcher (ones (3,2))) ***** error ... knnsearch (ExhaustiveSearcher (ones (3,2)), ones (3,2), 'IncludeTies') ***** error ... knnsearch (ExhaustiveSearcher (ones (3,2)), 'abc') ***** error ... knnsearch (ExhaustiveSearcher (ones (3,2)), ones (3,3)) ***** error ... knnsearch (ExhaustiveSearcher (ones (3,2)), ones (3,2), 'K', 0) ***** error ... knnsearch (ExhaustiveSearcher (ones (3,2)), ones (3,2), 'foo', 'bar') ***** error ... knnsearch (ExhaustiveSearcher (ones (3,2)), ones (3,2), 'IncludeTies', 1) ***** error ... rangesearch (ExhaustiveSearcher (ones (3,2))) ***** error ... rangesearch (ExhaustiveSearcher (ones (3,2)), ones (3,2), 1, 'SortIndices') ***** error ... rangesearch (ExhaustiveSearcher (ones (3,2)), 'abc', 1) ***** error ... rangesearch (ExhaustiveSearcher (ones (3,2)), ones (3,3), 1) ***** error ... rangesearch (ExhaustiveSearcher (ones (3,2)), ones (3,2), -1) ***** error ... rangesearch (ExhaustiveSearcher (ones (3,2)), ones (3,2), 1, 'foo', 'bar') ***** error ... rangesearch (ExhaustiveSearcher (ones (3,2)), ones (3,2), 1, 'SortIndices', 1) ***** error ... obj = ExhaustiveSearcher (ones (3,2)); obj(1) ***** error ... obj = ExhaustiveSearcher (ones (3,2)); obj{1} ***** error ... obj = ExhaustiveSearcher (ones (3,2)); obj.(1) ***** error ... obj = ExhaustiveSearcher (ones (3,2)); obj.invalid ***** error ... obj = ExhaustiveSearcher (ones (3,2)); obj(1) = 1 ***** error ... obj = ExhaustiveSearcher (ones (3,2)); obj{1} = 1 ***** error ... obj = ExhaustiveSearcher (ones (3,2)); obj.X.Y = 1 ***** error ... obj = ExhaustiveSearcher (ones (3,2)); obj.(1) = 1 ***** error ... obj = ExhaustiveSearcher (ones (3,2)); obj.X = 1 ***** error ... obj = ExhaustiveSearcher (ones (3,2)); obj.Distance = 'invalid' ***** error ... obj = ExhaustiveSearcher (ones (3,2)); obj.Distance = @(x) x ***** error ... obj = ExhaustiveSearcher (ones (3,2)); obj.Distance = @(x, y) [1; 1] ***** error ... obj = ExhaustiveSearcher (ones (3,2)); obj.Distance = 1 ***** error ... obj = ExhaustiveSearcher (ones (3,2), 'Distance', 'minkowski'); obj.DistParameter = -1 ***** error ... obj = ExhaustiveSearcher (ones (3,2), 'Distance', 'seuclidean'); obj.DistParameter = [-1, 1] ***** error ... obj = ExhaustiveSearcher (ones (3,2), 'Distance', 'mahalanobis'); obj.DistParameter = ones (3,3) ***** error ... obj = ExhaustiveSearcher (ones (3,2), 'Distance', 'mahalanobis'); obj.DistParameter = -eye (2) ***** error ... obj = ExhaustiveSearcher (ones (3,2), 'Distance', 'euclidean'); obj.DistParameter = 1 ***** error ... obj = ExhaustiveSearcher (ones (3,2)); obj.invalid = 1 ***** test randn ("seed", 4); X = randn (20, 2); Y = randn (5, 2); ex = ExhaustiveSearcher (X); for K = [20, 21, 100] [idx, D] = knnsearch (ex, Y, "K", K); assert_equal (size (idx), [5, 20]); assert_equal (size (D), [5, 20]); assert_equal (any (isnan (idx(:))), false); assert_equal (all (diff (D, 1, 2)(:) >= -1e-12), true); endfor ***** test X = [1, 2; 3, 4; 5, 6; 7, 8]; Y = [2, 3; 6, 7]; obj = ExhaustiveSearcher (single (X)); assert_equal (class (obj.X), 'single'); [idx, D] = knnsearch (obj, single (Y), "K", 2); assert_equal (class (idx), 'double'); assert_equal (class (D), 'single'); ## a double query against single data is still computed in single [~, Dm] = knnsearch (obj, Y, "K", 2); assert_equal (class (Dm), 'single'); assert_equal (Dm, D); ## and so is a single query against double data [~, Ds] = knnsearch (ExhaustiveSearcher (X), single (Y), "K", 2); assert_equal (class (Ds), 'single'); ## double throughout stays double [~, Dd] = knnsearch (ExhaustiveSearcher (X), Y, "K", 2); assert_equal (class (Dd), 'double'); ***** test X = int32 ([10, 20; 33, 41; 55, 62]); Y = [21, 33]; obj = ExhaustiveSearcher (X); assert_equal (class (obj.X), 'double'); [~, D] = knnsearch (obj, Y, "K", 1); assert_equal (D, min (sqrt (sum ((double (X) - Y) .^ 2, 2))), 1e-12); ***** test X = [1, 2; 3, 4; 5, 6; 7, 8]; Y = [2, 3]; [idx, D] = rangesearch (ExhaustiveSearcher (single (X)), single (Y), 4); assert_equal (class (idx{1}), 'double'); assert_equal (class (D{1}), 'single'); 82 tests, 82 passed, 0 known failure, 0 skipped [inst/Nearest_Neighbors/nomdist.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Nearest_Neighbors/nomdist.m ***** shared X X = [1, 1, 1; 1, 2, 1; 1, 1, 2; 2, 2, 2; 2, 1, 1; 3, 2, 2; 4, 1, 3]; ***** test ## The default is Goodall 3; values from nomclust 2.8.1 D = [0.4285714285714286, 0.4761904761904762, 1, 0.4761904761904762, 1, ... 0.7619047619047619, 0.7142857142857143, 0.7142857142857143, ... 0.7142857142857143, 0.7142857142857143, 1, 0.7142857142857143, ... 0.7619047619047619, 0.7142857142857143, 0.7619047619047619, ... 0.6825396825396826, 0.4285714285714286, 1, 1, 0.7619047619047619, ... 1]; assert_equal (nomdist (X), D, -1e-14); ***** test D = [0.3333333333333334, 0.3333333333333334, 1, 0.3333333333333334, 1, ... 0.6666666666666667, 0.6666666666666667, 0.6666666666666667, ... 0.6666666666666667, 0.6666666666666667, 1, 0.6666666666666667, ... 0.6666666666666667, 0.6666666666666667, 0.6666666666666667, ... 0.6666666666666667, 0.3333333333333334, 1, 1, 0.6666666666666667, ... 1]; assert_equal (nomdist (X, 'SM'), D, -1e-14); ***** assert_equal (nomdist (X, "lin"), nomdist (X, 'lin')) ***** test ## Weighted Lin; values from nomclust 2.8.1 D = nomdist (X, 'lin', 'Weights', [0.7, 1, 0.4]); assert_equal (D(1:3), [0.7547596113257813, 0.2283122503928992, ... 4.98065967640019], -1e-14); ***** assert_equal (nomdist (X, 'Weights', [1, 1, 1]), nomdist (X)) ***** assert_equal (nomdist (X, 'Weights', []), nomdist (X)) ***** assert_equal (nomdist (X, 'lin', 'Weights', [1, 0, 1]), ... nomdist (X(:,[1, 3]), 'lin')) ***** assert_equal (nomdist (10 * X - 25), nomdist (X)) ***** assert_equal (nomdist (X == 1), nomdist (double (X == 1))) ***** assert_equal (nomdist (int8 (X)), nomdist (X)) ***** test C = {'a', 'b', 'c', 'd'}; assert_equal (nomdist (C(X)), nomdist (X)); ***** test C = {'a', 'b', 'c', 'd'}; assert_equal (nomdist (string (C(X))), nomdist (X)); ***** test C = {'a', 'b', 'c', 'd'}; assert_equal (nomdist (categorical (C(X))), nomdist (X)); ***** test C = {'a', 'b', 'c', 'd'}; T = table (categorical (C(X(:,1))'), X(:,2) == 1, C(X(:,3))', ... 'VariableNames', {'A', 'B', 'C'}); assert_equal (nomdist (T, 'of'), nomdist (X, 'of')); ***** assert_equal (nomdist ([1, 2, 3]), zeros (1, 0)) ***** assert_equal (nomdist ([1; 1; 2], 'goodall3'), [1/3, 1, 1], -1e-14) ***** assert_equal (nomdist ([1; 1; 2], 'goodall3', 'Reference', ... [1; 1; 1; 1; 2]), [0.6, 1, 1], -1e-14) ***** assert_equal (nomdist ([1; 1; 2], 'Reference', []), nomdist ([1; 1; 2])) ***** test T = table ([1; 1; 2], {'a'; 'b'; 'a'}, 'VariableNames', {'A', 'B'}); R = table ({'a'; 'b'; 'a'; 'a'}, [1; 1; 2; 1], 'VariableNames', {'B', 'A'}); assert_equal (nomdist (T, 'Reference', R), ... nomdist ([1, 1; 1, 2; 2, 1], 'Reference', ... [1, 1; 1, 2; 2, 1; 1, 1])); ***** error nomdist () ***** error ... nomdist ([1; 2], 'hamming') ***** error ... nomdist ([1; 2], 1) ***** error ... nomdist ([1; 2], 'Scale', 1) ***** error ... nomdist ([1; 2], 'CountQuery', true) ***** error ... nomdist (['ab'; 'cd']) ***** error ... nomdist (ones (2, 2, 2)) ***** error nomdist (zeros (0, 2)) ***** error ... nomdist (table ([1, 2; 3, 4])) ***** error nomdist ([1; NaN]) ***** error nomdist ({'a'; ''}) ***** error ... nomdist (table ([1; 2]), 'Reference', [1; 2]) ***** error ... nomdist (table ([1; 2]), 'Reference', table ([1; 2], 'VariableNames', {'Z'})) ***** error ... nomdist ([1; 2], 'Reference', table ([1; 2])) ***** error ... nomdist ([1; 2], 'Reference', ['a'; 'b']) ***** error ... nomdist ([1; 2], 'Reference', [1, 1; 2, 2]) ***** error ... nomdist ([1; 2], 'Reference', {'a'; 'b'}) ***** error ... nomdist ([1; 2], 'Reference', [1; 2; NaN]) ***** error ... nomdist ([1; 2], 'Reference', [1; 1]) ***** error ... nomdist ([1; 2], 'smirnov', 'Weights', 1) ***** error ... nomdist ([1, 1; 2, 1], 'Weights', 1) ***** error ... nomdist ([1, 1; 2, 1], 'Weights', [1, 2]) ***** error ... nomdist ([1, 1; 2, 1], 'Weights', [0, 0]) 42 tests, 42 passed, 0 known failure, 0 skipped [inst/Nearest_Neighbors/hnswSearcher.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Nearest_Neighbors/hnswSearcher.m ***** demo ## Create an hnswSearcher with Euclidean distance X = [1, 2; 3, 4; 5, 6]; obj = hnswSearcher (X); ## Find the nearest neighbor to [2, 3] Y = [2, 3]; [idx, D] = knnsearch (obj, Y, 'K', 1); disp ('Nearest neighbor index:'); disp (idx); disp ('Distance:'); disp (D); ***** demo ## Create an hnswSearcher with Minkowski distance (P=3) X = [0, 0; 1, 0; 2, 0]; obj = hnswSearcher (X, 'Distance', 'minkowski', 'P', 3); ## Find the nearest neighbor to [1, 0] Y = [1, 0]; [idx, D] = knnsearch (obj, Y, 'K', 1); disp ('Nearest neighbor index:'); disp (idx); disp ('Distance:'); disp (D); ***** test ## the graph is drawn from rand, so seed it: the search is approximate rand ("seed", 42); load fisheriris X = meas; obj = hnswSearcher (X, 'Distance', 'chebychev'); Y = X(30:35,:); [idx, D] = knnsearch (obj, Y, 'K', 4); ## Under chebychev these queries have several equidistant neighbours, so ## which of them is listed first is not defined. Assert the distances, ## which are, and that each returned index really sits at the distance ## reported for it. assert_equal (D, [[0 0.1000 0.1000 0.2000]; [0 0.1000 0.1000 0.1000]; [0 0.2000 ... 0.2000 0.2000]; [0 0.3000 0.3000 0.3000]; [0 0.2000 0.3000 ... 0.3000]; [0 0.1000 0.1000 0.1000]], 5e-15) for i = 1:rows (Y) assert_equal (numel (unique (idx(i,:))), 4); for j = 1:4 assert_equal (max (abs (X(idx(i,j),:) - Y(i,:))), D(i,j), 5e-15); endfor endfor ***** test ## the graph is drawn from rand, so seed it: the search is approximate rand ("seed", 42); load fisheriris X = meas; C = cov (X); obj = hnswSearcher (X, 'Distance', 'mahalanobis', 'Cov', C); Y = X(120:125,:); [idx, D] = knnsearch (obj, Y, 'K', 2); assert_equal (idx(1, :), [120 82]) assert_equal (idx(4, :), [123 106]) assert_equal (idx(5, :), [124 127]) assert_equal (idx(6, :), [125 57]) assert_equal (D(1, :), [0 0.7734], 1e-4) assert_equal (D(4, :), [0 0.8452], 1e-4) assert_equal (D(5, :), [0 0.4152], 1e-4) assert_equal (D(6, :), [0 0.7322], 1e-4) ***** test ## Basic constructor with default Euclidean X = [1, 2; 3, 4; 5, 6]; obj = hnswSearcher (X); assert_equal (obj.X, X); assert_equal (obj.Distance, "euclidean"); assert_equal (isempty (obj.DistParameter), true); ***** test ## Minkowski distance with custom P X = [0, 0; 1, 1; 2, 2]; obj = hnswSearcher (X, 'Distance', 'minkowski', 'P', 3); assert_equal (obj.Distance, "minkowski"); assert_equal (obj.DistParameter, 3); ***** test ## Seuclidean distance with custom Scale X = [1, 2; 3, 4; 5, 6]; S = [1, 2]; obj = hnswSearcher (X, 'Distance', 'seuclidean', 'Scale', S); assert_equal (obj.Distance, "seuclidean"); assert_equal (obj.DistParameter, S); ***** test ## Mahalanobis distance with custom Cov X = [1, 2; 3, 4; 5, 6]; C = [1, 0; 0, 1]; obj = hnswSearcher (X, 'Distance', 'mahalanobis', 'Cov', C); assert_equal (obj.Distance, "mahalanobis"); assert_equal (obj.DistParameter, C); ***** test ## knnsearch with Euclidean distance X = [1, 2; 3, 4; 5, 6]; obj = hnswSearcher (X); Y = [2, 3]; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (ismember (idx, [2]), true); assert_equal (abs (D - sqrt (2)) < 1e-2, true); ***** test ## knnsearch with Cityblock distance X = [0, 0; 1, 1; 2, 2]; obj = hnswSearcher (X, 'Distance', 'cityblock'); Y = [1, 0]; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (ismember (idx, [1, 2]), true); assert_equal (abs (D - 1) < 1e-2, true); ***** test ## knnsearch with Chebychev distance X = [1, 1; 2, 3; 4, 2]; obj = hnswSearcher (X, 'Distance', 'chebychev'); Y = [2, 2]; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (ismember (idx, [1, 2]), true); assert_equal (abs (D - 1) < 1e-2, true); ***** test ## knnsearch with Minkowski P=3 X = [0, 0; 1, 0; 2, 0]; obj = hnswSearcher (X, 'Distance', 'minkowski', 'P', 3); Y = [1, 0]; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (ismember (idx, [2]), true); assert_equal (abs (D - 0) < 1e-2, true); ***** test ## Diverse dataset with Euclidean X = [0, 10; 5, 5; 10, 0]; obj = hnswSearcher (X); Y = [5, 5]; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (ismember (idx, [2]), true); assert_equal (abs (D - 0) < 1e-2, true); ***** test ## High-dimensional data with Cityblock X = [1, 2, 3; 4, 5, 6; 7, 8, 9]; obj = hnswSearcher (X, 'Distance', 'cityblock'); Y = [4, 5, 6]; [idx, D] = knnsearch (obj, Y, 'K', 1); assert_equal (ismember (idx, [2]), true); assert_equal (abs (D - 0) < 1e-2, true); ***** test ## both the data and the graph are drawn, so seed both: the search is ## approximate and an unlucky graph misses a true neighbour rand ("seed", 42); randn ("seed", 4); X = [randn(20,2); randn(20,2) + 3; randn(20,2) + [0, 6]]; Y = randn (8, 2); hn = hnswSearcher (X); es = ExhaustiveSearcher (X); truth = knnsearch (es, Y, 'K', 3); for ess = [5, 16, 31, 32, 33, 60] assert_equal (knnsearch (hn, Y, 'K', 3, 'SearchSetSize', ess), truth); endfor ***** test ## the boundary that used to break was 2 * MaxNumLinksPerNode rand ("seed", 42); randn ("seed", 4); X = [randn(20,2); randn(20,2) + 3; randn(20,2) + [0, 6]]; Y = randn (8, 2); hn = hnswSearcher (X); assert_equal (knnsearch (hn, Y, 'K', 3, 'SearchSetSize', 31), ... knnsearch (hn, Y, 'K', 3, 'SearchSetSize', 32)); ***** test ## distinct queries must not collapse onto one index rand ("seed", 42); randn ("seed", 4); X = [randn(20,2); randn(20,2) + 3; randn(20,2) + [0, 6]]; Y = randn (8, 2); idx = knnsearch (hnswSearcher (X), Y, 'K', 3, 'SearchSetSize', 60); assert_equal (numel (unique (idx(:,1))) > 1, true); ***** error ... hnswSearcher () ***** error ... hnswSearcher (ones (3,2), 'Distance') ***** error ... hnswSearcher ([]) ***** error ... hnswSearcher ('abc') ***** error ... hnswSearcher ([1; Inf; 3]) ***** error ... hnswSearcher (ones (3,2), 'foo', 'bar') ***** error ... hnswSearcher (ones (3,2), 'Distance', 'invalid') ***** error ... hnswSearcher (ones (3,2), 'Distance', 1) ***** error ... hnswSearcher (ones (3,2), 'Distance', 'minkowski', 'P', -1) ***** error ... hnswSearcher (ones (3,2), 'Distance', 'seuclidean', 'Scale', [-1, 1]) ***** error ... hnswSearcher (ones (3,2), 'Distance', 'mahalanobis', 'Cov', ones (3,3)) ***** error ... hnswSearcher (ones (3,2), 'Distance', 'mahalanobis', 'Cov', [1, 2; 3, 4]) ***** error ... hnswSearcher (ones (3,2), 'Distance', 'mahalanobis', 'Cov', -eye (2)) ***** error ... hnswSearcher (ones (3,2), 'MaxNumLinksPerNode', 0) ***** error ... hnswSearcher (ones (3,2), 'TrainSetSize', -1) ***** error ... hnswSearcher (ones (3,2), 'TrainSetSize', 4) ***** error ... hnswSearcher (ones (3,2), 'MaxNumLinksPerNode', 200, 'TrainSetSize', 100) ***** error ... knnsearch (hnswSearcher (ones (3,2))) ***** error ... knnsearch (hnswSearcher (ones (3,2)), ones (3,2), 'K') ***** error ... knnsearch (hnswSearcher (ones (3,2)), {1, 2}) ***** error ... knnsearch (hnswSearcher (ones (3,2)), ones (3,2), 'K', 0) ***** error ... knnsearch (hnswSearcher (ones (3,2)), ones (3,2), 'foo', 'bar') ***** error ... obj = hnswSearcher (ones (3,2)); obj(1) ***** error ... obj = hnswSearcher (ones (3,2)); obj{1} ***** error ... obj = hnswSearcher (ones (3,2)); obj.invalid ***** error ... obj = hnswSearcher (ones (3,2)); obj(1) = 1 ***** error ... obj = hnswSearcher (ones (3,2)); obj{1} = 1 ***** error ... obj = hnswSearcher (ones (3,2)); obj.X = 1 ***** error ... obj = hnswSearcher (ones (3,2)); obj.HNSWGraph = 1 ***** error ... obj = hnswSearcher (ones (3,2)); obj.Distance = 'invalid' ***** error ... obj = hnswSearcher (ones (3,2)); obj.Distance = 1 ***** error ... obj = hnswSearcher (ones (3,2), 'Distance', 'minkowski'); obj.DistParameter = -1 ***** error ... obj = hnswSearcher (ones (3,2), 'Distance', 'seuclidean'); obj.DistParameter = [-1, 1] ***** error ... obj = hnswSearcher (ones (3,2), 'Distance', 'mahalanobis'); obj.DistParameter = ones (3,3) ***** error ... obj = hnswSearcher (ones (3,2), 'Distance', 'mahalanobis'); obj.DistParameter = -eye (2) ***** error ... obj = hnswSearcher (ones (3,2)); obj.DistParameter = 1 ***** error ... obj = hnswSearcher (ones (3,2)); obj.MaxNumLinksPerNode = 0 ***** error ... obj = hnswSearcher (ones (3,2)); obj.TrainSetSize = -1 ***** error ... obj = hnswSearcher (ones (3,2)); obj.efSearch = 1.5 ***** error ... obj = hnswSearcher (ones (3,2)); obj.invalid = 1 ***** shared Xs, Ys, hs ## the graph is built from rand, so seed it: the search is approximate and ## an unlucky graph misses a true neighbour rand ("seed", 42); randn ("seed", 4); Xs = [randn(20,2); randn(20,2) + 3; randn(20,2) + [0, 6]]; Ys = randn (8, 2); hs = hnswSearcher (Xs); ***** test # asking for every point returns every point, not a padding of NaN [idx, D] = knnsearch (hs, Ys, "K", 60); assert_equal (size (idx), [8, 60]); assert_equal (any (isnan (idx(:))), false); for r = 1:8 assert_equal (sort (idx(r,:)), 1:60); endfor ***** test # and the neighbours are the right ones, not merely present for K = [1, 5, 30, 60] [~, Dh] = knnsearch (hs, Ys, "K", K); [~, De] = knnsearch (ExhaustiveSearcher (Xs), Ys, "K", K); assert_equal (Dh, De, 1e-12); endfor ***** test # more neighbours than points gives all of them, not a wider matrix for K = [61, 100, 1000] [idx, D] = knnsearch (hs, Ys, "K", K); assert_equal (size (idx), [8, 60]); assert_equal (size (D), [8, 60]); assert_equal (any (isnan (idx(:))), false); endfor ***** test # an empty query is answered with an empty result [idx, D] = knnsearch (hs, zeros (0, 2), "K", 3); assert_equal (size (idx), [0, 3]); assert_equal (size (D), [0, 3]); ***** test # a query that is not finite is answered, its distances saying so [idx, D] = knnsearch (hs, [Inf, 0], "K", 3); assert_equal (size (idx), [1, 3]); assert_equal (all (isinf (D)), true); [idx, D] = knnsearch (hs, [NaN, NaN], "K", 3); assert_equal (size (idx), [1, 3]); assert_equal (all (isnan (D)), true); ***** test rand ("seed", 42); X = [1, 2; 3, 4; 5, 6; 7, 8]; Y = [2, 3; 6, 7]; obj = hnswSearcher (single (X)); assert_equal (class (obj.X), 'single'); [idx, D] = knnsearch (obj, single (Y), "K", 2); assert_equal (class (idx), 'double'); assert_equal (class (D), 'single'); ## a double query against single data is still computed in single [~, Dm] = knnsearch (obj, Y, "K", 2); assert_equal (class (Dm), 'single'); assert_equal (Dm, D); ## and so is a single query against double data [~, Ds] = knnsearch (hnswSearcher (X), single (Y), "K", 2); assert_equal (class (Ds), 'single'); ## double throughout stays double [~, Dd] = knnsearch (hnswSearcher (X), Y, "K", 2); assert_equal (class (Dd), 'double'); ***** test rand ("seed", 42); X = int32 ([10, 20; 33, 41; 55, 62]); Y = [21, 33]; obj = hnswSearcher (X); assert_equal (class (obj.X), 'double'); [~, D] = knnsearch (obj, Y, "K", 1); assert_equal (D, min (sqrt (sum ((double (X) - Y) .^ 2, 2))), 1e-12); 62 tests, 62 passed, 0 known failure, 0 skipped [inst/Nearest_Neighbors/pdist2.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Nearest_Neighbors/pdist2.m ***** shared x, y, xx x = [1, 1, 1; 2, 2, 2; 3, 3, 3]; y = [0, 0, 0; 1, 2, 3; 0, 2, 4; 4, 7, 1]; xx = [1 2 3; 4 5 6; 7 8 9; 3 2 1]; ***** test d = sqrt ([3, 5, 11, 45; 12, 2, 8, 30; 27, 5, 11, 21]); assert_equal (pdist2 (x, y), d); ***** test d = [5.1962, 2.2361, 3.3166, 6.7082; ... 3.4641, 2.2361, 3.3166, 5.4772]; i = [3, 1, 1, 1; 2, 3, 3, 2]; [D, I] = pdist2 (x, y, 'euclidean', 'largest', 2); assert_equal ({D, I}, {d, i}, 1e-4); ***** test d = [1.7321, 1.4142, 2.8284, 4.5826; ... 3.4641, 2.2361, 3.3166, 5.4772]; i = [1, 2, 2, 3;2, 1, 1, 2]; [D, I] = pdist2 (x, y, 'euclidean', 'smallest', 2); assert_equal ({D, I}, {d, i}, 1e-4); ***** test yy = [1 2 3;5 6 7;9 5 1]; d = [0, 6.1644, 5.3852; 1.4142, 6.9282, 8.7750; ... 3.7417, 7.0711, 9.9499; 6.1644, 10.4881, 10.3441]; i = [2, 4, 4; 3, 2, 2; 1, 3, 3; 4, 1, 1]; [D, I] = pdist2 (y, yy, 'euclidean', 'smallest', 4); assert_equal ({D, I}, {d, i}, 1e-4); ***** test yy = [1 2 3;5 6 7;9 5 1]; d = [0, 38, 29; 2, 48, 77; 14, 50, 99; 38, 110, 107]; i = [2, 4, 4; 3, 2, 2; 1, 3, 3; 4, 1, 1]; [D, I] = pdist2 (y, yy, 'squaredeuclidean', 'smallest', 4); assert_equal ({D, I}, {d, i}, 1e-4); ***** test yy = [1 2 3;5 6 7;9 5 1]; d = [0, 3.3256, 2.7249; 0.7610, 3.3453, 4.4799; ... 1.8514, 3.3869, 5.0703; 2.5525, 5.0709, 5.1297]; i = [2, 2, 4; 3, 4, 2; 1, 3, 1; 4, 1, 3]; [D, I] = pdist2 (y, yy, 'seuclidean', 'smallest', 4); assert_equal ({D, I}, {d, i}, 1e-4); ***** test d = [2.1213, 4.2426, 6.3640; 1.2247, 2.4495, 4.4159; ... 3.2404, 4.8990, 6.8191; 2.7386, 4.2426, 6.1237]; assert_equal (pdist2 (y, x, 'mahalanobis'), d, 1e-4); ***** test xx = [1, 3, 4; 3, 5, 4; 8, 7, 6]; d = [1.3053, 1.8257, 15.0499; 1.3053, 3.3665, 16.5680]; i = [2, 2, 2; 3, 4, 4]; [D, I] = pdist2 (y, xx, 'mahalanobis', 'smallest', 2); assert_equal ({D, I}, {d, i}, 1e-4); ***** test d = [2.5240, 4.1633, 17.3638; 2.0905, 3.9158, 17.0147]; i = [1, 1, 3; 4, 3, 1]; [D, I] = pdist2 (y, xx, 'mahalanobis', 'largest', 2); assert_equal ({D, I}, {d, i}, 1e-4); ***** test d = [3, 3, 5, 9; 6, 2, 4, 8; 9, 3, 5, 7]; assert_equal (pdist2 (x, y, 'cityblock'), d); ***** test d = [1, 2, 3, 6; 2, 1, 2, 5; 3, 2, 3, 4]; assert_equal (pdist2 (x, y, 'chebychev'), d); ***** test d = repmat ([NaN, 0.0742, 0.2254, 0.1472], [3, 1]); assert_equal (pdist2 (x, y, 'cosine'), d, 1e-4); ***** test yy = [1 2 3;5 6 7;9 5 1]; d = [0, 0, 0.5; 0, 0, 2; 1.5, 1.5, 2; NaN, NaN, NaN]; i = [2, 2, 4; 3, 3, 2; 4, 4, 3; 1, 1, 1]; [D, I] = pdist2 (y, yy, 'correlation', 'smallest', 4); assert_equal ({D, I}, {d, i}, eps); [D, I] = pdist2 (y, yy, 'spearman', 'smallest', 4); assert_equal ({D, I}, {d, i}, eps); ***** test d = [1, 2/3, 1, 1; 1, 2/3, 1, 1; 1, 2/3, 2/3, 2/3]; i = [1, 1, 1, 2; 2, 2, 3, 3; 3, 3, 2, 1]; [D, I] = pdist2 (x, y, 'hamming', 'largest', 4); assert_equal ({D, I}, {d, i}, eps); [D, I] = pdist2 (x, y, 'jaccard', 'largest', 4); assert_equal ({D, I}, {d, i}, eps); ***** test xx = [1, 2, 3, 4; 2, 3, 4, 5; 3, 4, 5, 6]; yy = [1, 2, 2, 3; 2, 3, 3, 4]; [D, I] = pdist2 (x, y, 'euclidean', 'Smallest', 4); eucldist = @(v,m) sqrt (sumsq (repmat (v,rows (m),1)-m,2)); [d, i] = pdist2 (x, y, eucldist, 'Smallest', 4); assert_equal ({D, I}, {d, i}); ***** warning ... pdist2 (xx, xx, 'mahalanobis'); ***** test ## A row is never at a negative distance from itself. For identical rows ## the similarity can round a step above one, and one minus it is then ## below zero, which no distance may be. A distance a rounding step above ## zero is kept, MATLAB returning one there too. X = [-3, -3; -3, -3]; assert_equal (pdist2 (X, X, "cosine"), zeros (2)); ***** test ## Neither do the other two metrics built as one minus a similarity. Y = [1, 2, 4; 2, 4, 8; -1, -2, -4]; for m = {"cosine", "correlation", "spearman"} D = pdist2 (Y, Y, m{1}); assert_equal (any (D(:) < 0), false); endfor ***** test ## The clamp corrects the sign and leaves a NaN alone: a zero row has no ## direction, so its cosine distance is undefined rather than zero, and ## stays undefined. Z = [0, 0; 1, 1]; D = pdist2 (Z, Z, "cosine"); assert_equal (isnan (D), [true, true; true, false]); assert_equal (D(2,2) >= 0, true); ***** error pdist2 (1) ***** error ... pdist2 (ones (4, 5), ones (4)) ***** error ... pdist2 (ones (4, 2, 3), ones (3, 2)) ***** error ... pdist2 (ones (3), ones (3), 'euclidean', 'Largest') ***** error ... pdist2 (ones (3), ones (3), 'minkowski', 3, 'Largest') ***** error ... pdist2 (ones (3), ones (3), 'minkowski', 3, 'large', 4) ***** error ... pdist2 (ones (3), ones (3), 'minkowski', 3, 'largest', 4.5) ***** error ... pdist2 (ones (3), ones (3), 'minkowski', 3, 'Largest', 4, 'smallest', 5) ***** error ... [d, i] = pdist2 (ones (3), ones (3), 'minkowski', 3) ***** error ... pdist2 (ones (3), ones (3), 'seuclidean', 3) ***** error ... pdist2 (ones (3), ones (3), 'seuclidean', [1, -1, 3]) ***** error ... pdist2 (ones (3), eye (3), 'mahalanobis', eye (2)) ***** error ... pdist2 (ones (3), eye (3), 'mahalanobis', ones (3)) ***** error ... pdist2 (ones (3), eye (3), 'minkowski', 0) ***** error ... pdist2 (ones (3), eye (3), 'minkowski', -5) ***** error ... pdist2 (ones (3), eye (3), 'minkowski', [1, 2]) ***** error ... pdist2 (ones (3), ones (3), @(v,m) sqrt (repmat (v,rows (m),1)-m,2)) ***** error ... pdist2 (ones (3), ones (3), @(v,m) sqrt (sum (sumsq (repmat (v,rows (m),1)-m,2)))) 37 tests, 37 passed, 0 known failure, 0 skipped [inst/Anomaly_Detection/IsolationForest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Anomaly_Detection/IsolationForest.m ***** test rand ("state", 5); X = [randn(40,2)*0.3; 10 10; -9 8]; Mdl = IsolationForest (X, "NumLearners", 50); assert_equal (isa (Mdl, "IsolationForest"), true); assert_equal (Mdl.NumLearners, 50); assert_equal (Mdl.NumObservationsPerLearner, 42); [tf, scores] = isanomaly (Mdl, [0 0; 12 12]); assert_equal (all (scores >= 0 & scores <= 1, 'all'), true); assert_equal (scores(2) > scores(1), true); # far point is more anomalous assert_equal (islogical (tf), true); 1 test, 1 passed, 0 known failure, 0 skipped [inst/Anomaly_Detection/iforest.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Anomaly_Detection/iforest.m ***** demo ## Flag a handful of outliers around a Gaussian cluster. rng (42); X = [randn(200,2); 6 + randn(10,2)]; [Mdl, tf, scores] = iforest (X, "ContaminationFraction", 0.05); gscatter (X(:,1), X(:,2), tf); title ("iforest: inliers vs. flagged anomalies"); ***** test rand ("state", 42); X = [randn(60,2)*0.3; 12 12; -11 10; 10 -12]; [Mdl, tf, scores] = iforest (X, "ContaminationFraction", 3/63); assert_equal (Mdl.NumLearners, 100); assert_equal (Mdl.NumObservationsPerLearner, 63); assert_equal (all (scores >= 0 & scores <= 1, 'all'), true); # outliers rank highest assert_equal (all (scores(61:63) > max (scores(1:60)), 'all'), true); assert_equal (tf, logical ([false(60,1); true(3,1)])); ***** test rand ("state", 7); X = [randn(50,2)*0.3; 9 9; -8 7]; [Mdl, tf, scores] = iforest (X); assert_equal (Mdl.ContaminationFraction, 0); assert_equal (Mdl.ScoreThreshold, max (scores), 1e-12); assert_equal (tf, false (52, 1)); [Mdl2, tf2, s2] = iforest (X, "ContaminationFraction", 0.1); assert_equal (Mdl2.ScoreThreshold, quantile (s2, 0.9), 1e-12); assert_equal (tf2, s2 > Mdl2.ScoreThreshold); ***** test rand ("state", 1); X = randn (400, 2); Mdl = iforest (X); assert_equal (Mdl.NumObservationsPerLearner, 256); ***** test rand ("state", 3); X = [randn(60,2)*0.3; 12 12; -11 10; 10 -12]; Mdl = iforest (X, "ContaminationFraction", 3/63); [tf, scores] = isanomaly (Mdl, [0 0; 15 15]); assert_equal (all (scores >= 0 & scores <= 1, 'all'), true); assert_equal (scores(2) > scores(1), true); # far point scores higher assert_equal (tf, logical ([false; true])); ***** error iforest () ***** error iforest ([]) ***** error iforest ("a") ***** error iforest (1) ***** error iforest (randn (2, 3)) ***** error ... iforest (randn (10,2), "NumLearners") ***** error ... iforest (randn (10,2), "foo", "bar") ***** error ... iforest (randn (10,2), "NumLearners", 0) ***** error ... iforest (randn (10,2), "NumObservationsPerLearner", 2) ***** error ... iforest (randn (10,2), "NumObservationsPerLearner", 20) ***** error ... iforest (randn (10,2), "ContaminationFraction", 2) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Anomaly_Detection/robustcov.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Anomaly_Detection/robustcov.m ***** demo ## Robust covariance is unaffected by a cluster of outliers. rng (42); X = [randn(80,2); 8 + randn(10,2)]; [sig, mu, mah, outliers] = robustcov (X); gscatter (X(:,1), X(:,2), outliers); title ("robustcov: inliers vs. flagged outliers"); ***** test X = [0.1 0.2; -0.3 0.5; 0.4 -0.1; 0.2 0.3; -0.2 -0.4; 0.5 0.1; -0.1 0.2; ... 0.3 -0.3; -0.4 0.1; 0.2 -0.2; 0.1 0.4; -0.3 -0.2; 5 5; -6 4]; [sig, mu, mah, ol] = robustcov (X, "BiasCorrection", 0); assert_equal (mu, [0.041666666666667 0.05], 1e-12); assert_equal (sig, [0.130395818314974 -0.012781705320642; ... -0.012781705320642 0.122435282545100], 1e-9); assert_equal (ol, logical ([0;0;0;0;0;0;0;0;0;0;0;0;1;1])); ***** test X = [0.1 0.2; -0.3 0.5; 0.4 -0.1; 0.2 0.3; -0.2 -0.4; 0.5 0.1; -0.1 0.2; ... 0.3 -0.3; -0.4 0.1; 0.2 -0.2; 0.1 0.4; -0.3 -0.2; 5 5; -6 4]; [sig, mu, mah, ol] = robustcov (X, "Method", "ogk"); assert_equal (mu, [0.041666666666667 0.05], 1e-12); assert_equal (sig, [0.080763888888889 -0.007916666666667; ... -0.007916666666667 0.075833333333333], 1e-9); assert_equal (ol, logical ([0;0;0;0;0;0;0;0;0;0;0;0;1;1])); ***** test X = [0.1 0.2; -0.3 0.5; 0.4 -0.1; 0.2 0.3; -0.2 -0.4; 0.5 0.1; -0.1 0.2; ... 0.3 -0.3; -0.4 0.1; 0.2 -0.2; 0.1 0.4; -0.3 -0.2; 5 5; -6 4]; sig0 = robustcov (X, "BiasCorrection", 0); sig1 = robustcov (X); r = sig1 ./ sig0; # scalar inflation factor assert_equal (all (abs (r - r(1)) < 1e-12, 'all'), true); assert_equal (r(1) > 1, true); ***** test X = [0.1 0.2; -0.3 0.5; 0.4 -0.1; 0.2 0.3; -0.2 -0.4; 0.5 0.1; -0.1 0.2; ... 0.3 -0.3; -0.4 0.1; 0.2 -0.2; 0.1 0.4; -0.3 -0.2; 5 5; -6 4]; [sig, mu, mah, ol] = robustcov (X); d2 = sum (((X - mu) / chol (sig)) .^ 2, 2); assert_equal (mah, sqrt (d2), 1e-12); assert_equal (ol, mah > sqrt (chi2inv (0.975, 2))); ***** test X = [randn(40,2); 10 10; -10 8]; [sig, mu, mah, ol, s] = robustcov (X); assert_equal (isfield (s, "Method") && strcmp (s.Method, "fmcd"), true); assert_equal (isfield (s, "Sigma") && isfield (s, "Mu"), true); assert_equal (isfield (s, "Distances") && isfield (s, "Outliers"), true); [~, ~, ~, ~, s2] = robustcov (X, "Method", "ogk"); assert_equal (strcmp (s2.Method, "ogk"), true); assert_equal (isfield (s2, "NumOGKIterations"), true); ***** test X = [1 1 1; 1 1 -1; 1 -1 1; 1 -1 -1; -1 1 1; -1 1 -1; -1 -1 1; -1 -1 -1; ... 10 10 10; -10 8 -9]; [sig, mu, mah, ol] = robustcov (X, "Method", "ogk"); assert_equal (sig, eye (3), 1e-12); assert_equal (mu, [0 0 0], 1e-12); assert_equal (ol, logical ([0;0;0;0;0;0;0;0;1;1])); ***** shared A, B, C A = [0.34 0.6; 0.32 0.96; -0.49 0.23; -0.84 -0.8; 2.77 -0.6; -0.21 -1.31; ... -1.57 -2.15; -0.76 1.76; -0.57 0.68; -0.88 -0.18; -1.39 -0.6; ... 1.75 0.58; -0.54 0.15; -0.52 -0.7; -1.7 0.16; 1.26 -0.11; ... -1.05 0.84; -0.25 1.72; 1.09 -1.17; 2.23 2.41; 3.22 3.23; ... 1.76 4.47; 1.9 2.17; 1.23 1.13]; B = [1.39 -0.25 -0.72; -0.31 -0.24 1.55; -0.02 -0.07 -1.59; ... 1.5 -0.84 0.91; -0.04 0.02 -0.01; -1.04 -1.34 -0.22; ... -0.3 -0.25 0.62; -0.42 -2.01 -0.04; -0.81 -0.14 1.13; ... 0.91 0.5 1.91; -0.06 -2.11 -2; 0.08 -1.65 -0.98; -0.85 0.25 -0.14; ... -0.12 0.12 0.66; -0.84 -1.26 -0.92; 0.12 -0.3 0.54; ... -0.3 -0.19 0.87; -0.22 0.14 0.76; 0 -1.45 1.23; 2.96 0.65 3.32; ... 3.93 0.25 -0.76; 1.93 3.02 0.77; 3.35 1.08 2.56; 2.19 1.23 3]; C = [0.29 -0.61 -1.36; -0.17 -0.49 1.17; 0.69 0.11 -0.14; ... 0.42 0.66 -1.19; 0.58 -0.41 -0.62; -0.77 -1.08 1.15; ... -1.01 -0.89 -0.12; -0.17 0.4 -0.69; -1.13 2.84 0.86; ... 1.51 -0.72 -0.72; 0.64 2.95 -0.08; -0.12 -1.92 -0.55; ... 1.57 -1.36 -1.85; -0.02 0.51 -0.32; -1.18 -0.25 -1.38; ... -2.82 -0.44 -0.05; 0.82 -1.14 -0.01; -0.25 0.81 -1.19; ... 1.42 -0.67 -0.98; -0.14 2.88 1.61; 2.25 1.46 1.94; ... -0.18 3.07 1.89; 2.67 1.94 2.91; 2.39 -0.03 1.95]; ***** test [sig, mu, ~, ol] = robustcov (A, "Method", "ogk"); assert_equal (sig, [1.722767148760330 1.020670247933884; ... 1.020670247933884 1.646486776859504], 1e-12); assert_equal (mu, [0.116818181818182 0.436363636363636], 1e-12); assert_equal (find (ol)', [5, 22]); ***** test [sig, mu, ~, ol] = robustcov (A, "Method", "ogk", ... "UnivariateEstimator", "qn"); assert_equal (sig, [1.324408616780046 0.636798412698413; ... 0.636798412698413 1.335555555555556], 1e-12); assert_equal (mu, [-0.030952380952381 0.303333333333333], 1e-12); assert_equal (find (ol)', [5, 21, 22]); ***** test [sig, mu, ~, ol] = robustcov (B, "Method", "ogk"); assert_equal (sig, [0.4791385802469 0.0781234567901 0.0867438271605; ... 0.0781234567901 0.5096617283951 0.2086302469136; ... 0.0867438271605 0.2086302469136 0.8511209876543], ... 1e-12); assert_equal (mu, [-0.0705555555556 -0.4977777777778 0.3088888888889], ... 1e-12); assert_equal (find (ol)', 20:24); ***** test [sig, mu, ~, ol] = robustcov (B, "Method", "ogk", ... "UnivariateEstimator", "qn"); assert_equal (sig, [0.673841 0.264091 0.378851; ... 0.264091 0.737886 0.606261; ... 0.378851 0.606261 1.394296], 1e-12); assert_equal (mu, [0.043 -0.492 0.328], 1e-12); assert_equal (find (ol)', 20:23); ***** test [sig, mu, ~, ol] = robustcov (C, "Method", "ogk", "NumOGKIterations", 1); assert_equal (sig, [0.64969 -0.302265 -0.327265; ... -0.302265 2.27578475 0.799012; ... -0.327265 0.799012 1.068354], 1e-12); assert_equal (mu, [0.14 0.2345 -0.226], 1e-12); assert_equal (find (ol)', [16, 21, 23, 24]); ***** test [sig, mu, ~, ol] = robustcov (C, "Method", "ogk", "NumOGKIterations", 1, ... "UnivariateEstimator", "qn"); assert_equal (sig, [1.159454320988 -0.2871074074074 -0.3650679012346; ... -0.2871074074074 1.065891666667 0.1486175925926; ... -0.3650679012346 0.1486175925926 0.7041015432099], ... 1e-12); assert_equal (mu, [-0.0188888888889 -0.2583333333333 -0.4438888888889], ... 1e-12); assert_equal (find (ol)', [9, 11, 20:24]); ***** test X = [1.2 0.4 2.1; 0.8 1.1 1.9; 1.5 0.9 2.3; 0.9 0.7 1.8; 1.1 1.3 2.0; ... 1.4 0.6 2.2; 0.7 1.0 1.7; 1.3 0.8 2.4; 1.0 1.2 1.6; 0.7 0.9 2.0; ... 15 16 17; -9 12 -10]; [sig, mu, mah, ol] = robustcov (X); assert_equal (size (sig), [3 3]); assert_equal (sig, sig', 1e-12); assert_equal (all (eig (sig) > 0, 'all'), true); assert_equal (ol(11:12), logical ([1;1])); ***** test X = [randn(30,2); NaN 1; 2 NaN]; [sig, mu, mah] = robustcov (X); assert_equal (numel (mah), 30); ***** error robustcov () ***** error robustcov ([]) ***** error robustcov ("a") ***** error ... robustcov (ones (5,2), "Method") ***** error ... robustcov (ones (5,2), "foo", "bar") ***** error ... robustcov (ones (5,2), "Method", "olivehawkins") ***** error ... robustcov (ones (5,2), "Method", "bogus") ***** error ... robustcov (ones (5,2), "OutlierFraction", 0.8) ***** error ... robustcov (ones (5,2), "Method", "ogk", "UnivariateEstimator", "mad") ***** error robustcov (ones (2,5)) 24 tests, 24 passed, 0 known failure, 0 skipped [inst/Anomaly_Detection/ocsvm.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Anomaly_Detection/ocsvm.m ***** demo ## Flag a handful of outliers around a Gaussian cluster. rng (42); X = [randn(200,2); 5 + randn(10,2)]; [Mdl, tf, scores] = ocsvm (X, "KernelScale", 2, ... "ContaminationFraction", 0.05); gscatter (X(:,1), X(:,2), tf); title ("ocsvm: inliers vs. flagged anomalies"); ***** test rand ("state", 42); randn ("state", 42); X = [randn(60,2)*0.3; 10 10; -9 8; 8 -10]; [Mdl, tf, scores] = ocsvm (X, "KernelScale", 2, ... "NumExpansionDimensions", 128, ... "ContaminationFraction", 3/63); # outliers rank highest assert_equal (all (scores(61:63) > max (scores(1:60)), 'all'), true); assert_equal (tf, logical ([false(60,1); true(3,1)])); ***** test rand ("state", 7); randn ("state", 7); X = [randn(50,2)*0.3; 9 9; -8 7]; [Mdl, tf, scores] = ocsvm (X, "KernelScale", 2); assert_equal (Mdl.ContaminationFraction, 0); assert_equal (Mdl.ScoreThreshold, max (scores), 1e-12); assert_equal (tf, false (52, 1)); [Mdl2, tf2, s2] = ocsvm (X, "KernelScale", 2, "ContaminationFraction", 0.1); assert_equal (Mdl2.ScoreThreshold, quantile (s2, 0.9), 1e-12); assert_equal (tf2, s2 > Mdl2.ScoreThreshold); ***** test rand ("state", 1); randn ("state", 1); X = randn (64, 3); Mdl = ocsvm (X); assert_equal (Mdl.KernelScale, 1); assert_equal (Mdl.Lambda, 1/64, 1e-12); assert_equal (Mdl.NumExpansionDimensions, 64); # 2^ceil(log2(64)) ***** test rand ("state", 3); randn ("state", 3); X = [randn(60,2)*[3 0; 0 0.2] + [5 -2]; 20 5]; Mdl = ocsvm (X, "KernelScale", 2, "StandardizeData", true); assert_equal (numel (Mdl.Mu), 2); assert_equal (numel (Mdl.Sigma), 2); [tf, scores] = isanomaly (Mdl, [5 -2; 20 5]); assert_equal (scores(2) > scores(1), true); # the outlier scores higher ***** test rand ("state", 5); randn ("state", 5); X = [randn(60,2)*0.3; 10 10; -9 8]; Mdl = ocsvm (X, "KernelScale", 2, "ContaminationFraction", 2/62); [tf, scores] = isanomaly (Mdl, [0 0; 15 15]); assert_equal (scores(2) > scores(1), true); assert_equal (tf, logical ([false; true])); ***** error ocsvm () ***** error ocsvm ([]) ***** error ocsvm ("a") ***** error ... ocsvm (randn (10,2), "KernelScale") ***** error ... ocsvm (randn (10,2), "foo", "bar") ***** error ... ocsvm (randn (10,2), "KernelScale", -1) ***** error ... ocsvm (randn (10,2), "Lambda", -1) ***** error ... ocsvm (randn (10,2), "NumExpansionDimensions", 0) ***** error ... ocsvm (randn (10,2), "ContaminationFraction", 2) 14 tests, 14 passed, 0 known failure, 0 skipped [inst/Anomaly_Detection/lof.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Anomaly_Detection/lof.m ***** demo ## Flag a handful of outliers around a Gaussian cluster. rng (42); X = [randn(100,2); 4 + randn(6,2)]; [Mdl, tf, scores] = lof (X, "ContaminationFraction", 0.05); gscatter (X(:,1), X(:,2), tf); title ("lof: inliers vs. flagged anomalies"); ***** test X = [0 0; 0.1 0.1; 0.2 -0.1; -0.1 0.2; 0.1 -0.2; -0.2 0.1; 0.15 0.05; ... -0.05 -0.15; 0.05 0.12; -0.12 -0.05; 5 5; -4 3]; [Mdl, tf, scores] = lof (X, "NumNeighbors", 5); exp_scores = [1.066572826392391; 0.965333187918473; 1.035972400143920; ... 1.019798243339781; 1.055271577857807; 1.047371774849485; ... 0.941746286231341; 0.987111513710991; 0.948358372496933; ... 1.004238203765983; 29.441894930160952; 20.058918161335612]; assert_equal (scores, exp_scores, 1e-12); assert_equal (tf, false (12, 1)); # contamination 0 flags none assert_equal (Mdl.ScoreThreshold, 29.441894930160952, 1e-12); ***** test X = [0 0; 0.1 0.1; 0.2 -0.1; -0.1 0.2; 0.1 -0.2; -0.2 0.1; 0.15 0.05; ... -0.05 -0.15; 0.05 0.12; -0.12 -0.05; 5 5; -4 3]; [Mdl, tf, scores] = lof (X, "NumNeighbors", 5, "ContaminationFraction", 0.2); assert_equal (Mdl.ScoreThreshold, 2.965807359886740, 1e-12); assert_equal (tf, logical ([0;0;0;0;0;0;0;0;0;0;1;1])); ***** test X = [0 0; 0.1 0.1; 0.2 -0.1; -0.1 0.2; 0.1 -0.2; -0.2 0.1; 0.15 0.05; ... -0.05 -0.15; 0.05 0.12; -0.12 -0.05; 5 5; -4 3]; Mdl = lof (X); assert_equal (Mdl.NumNeighbors, 11); ***** test X = [0 0; 0.1 0.1; 0.2 -0.1; -0.1 0.2; 0.1 -0.2; -0.2 0.1; 0.15 0.05; ... -0.05 -0.15; 0.05 0.12; -0.12 -0.05; 5 5; -4 3]; Mdl = lof (X, "NumNeighbors", 5); [tf, scores] = isanomaly (Mdl, [0 0.05; 6 6; -0.1 -0.1]); assert_equal (scores, [0.954484172585537; 27.876003442184082; ... 1.001784195086020], 1e-12); assert_equal (tf, logical ([0; 0; 0])); # cutoff 29.44 from training [tf2, ~] = isanomaly (Mdl, [6 6], "ScoreThreshold", 5); assert_equal (tf2, true); ***** test X = [0 0; 0.1 0.1; 0.2 -0.1; -0.1 0.2; 0.1 -0.2; -0.2 0.1; 0.15 0.05; ... -0.05 -0.15; 0.05 0.12; -0.12 -0.05; 5 5; -4 3]; [~, ~, scores] = lof (X, "NumNeighbors", 5, "Distance", "cityblock"); assert_equal (scores(11), 34.198447151536712, 1e-10); assert_equal (scores(1) > 1 && scores(7) < 1, true); ***** error lof () ***** error lof ([]) ***** error lof ("a") ***** error lof (ones (5,2), "Distance") ***** error lof (ones (5,2), "foo", "bar") ***** error ... lof (ones (5,2), "Distance", "taxicab") ***** error ... lof (ones (5,2), "NumNeighbors", 0) ***** error ... lof (ones (5,2), "NumNeighbors", 5) ***** error ... lof (magic (5), "NumNeighbors", 2, "ContaminationFraction", 1.5) ***** error ... isanomaly (lof (magic (6)), ones (3,3)) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Anomaly_Detection/LocalOutlierFactor.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Anomaly_Detection/LocalOutlierFactor.m ***** test X = [0 0; 0.1 0.1; 0.2 -0.1; -0.1 0.2; 0.1 -0.2; -0.2 0.1; 0.15 0.05; 5 5]; Mdl = LocalOutlierFactor (X, "NumNeighbors", 3); assert_equal (isa (Mdl, "LocalOutlierFactor"), true); assert_equal (Mdl.NumNeighbors, 3); assert_equal (Mdl.Distance, "euclidean"); [tf, scores] = isanomaly (Mdl, [0 0; 6 6]); assert_equal (size (scores), [2, 1]); assert_equal (scores(2) > scores(1), true); # far point is more anomalous assert_equal (islogical (tf), true); 1 test, 1 passed, 0 known failure, 0 skipped [inst/Anomaly_Detection/OneClassSVM.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Anomaly_Detection/OneClassSVM.m ***** test rand ("state", 8); randn ("state", 8); X = [randn(60,2)*0.3; 9 9; -8 7]; Mdl = OneClassSVM (X, "KernelScale", 2, "NumExpansionDimensions", 64); assert_equal (isa (Mdl, "OneClassSVM"), true); assert_equal (Mdl.NumExpansionDimensions, 64); [tf, scores] = isanomaly (Mdl, [0 0; 12 12]); assert_equal (scores(2) > scores(1), true); # far point is more anomalous assert_equal (islogical (tf), true); 1 test, 1 passed, 0 known failure, 0 skipped [inst/cholcov.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/cholcov.m ***** demo C1 = [2, 1, 1, 2; 1, 2, 1, 2; 1, 1, 2, 2; 2, 2, 2, 3] T = cholcov (C1) C2 = T'*T ***** test C1 = [2, 1, 1, 2; 1, 2, 1, 2; 1, 1, 2, 2; 2, 2, 2, 3]; T = cholcov (C1); assert_equal (C1, T'*T, 1e-15 * ones (size (C1))); 1 test, 1 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/stdrstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/stdrstat.m ***** test [m, v] = stdrstat (2, Inf); assert_equal (m, 2 / sqrt (pi), -1e-13); assert_equal (v, 2 - 4 / pi, -1e-12); ***** assert_equal (stdrstat (3, Inf), 3 / sqrt (pi), -1e-13) ***** test df = 5; Et = 2 * sqrt (df) * exp (gammaln ((df + 1) / 2) - gammaln (df / 2)) ... / (sqrt (pi) * (df - 1)); [m, v] = stdrstat (2, df); assert_equal (m, sqrt (2) * Et, -1e-12); assert_equal (v, 2 * df / (df - 2) - 2 * Et ^ 2, -1e-11); ***** assert_equal (stdrstat (5, Inf), 2.325929, 1e-6) ***** test [m, v] = stdrstat (3, [1, 1.5, 2]); assert_equal (isnan (m), [true, false, false]); assert_equal (isnan (v), [true, true, true]); ***** test [m, v] = stdrstat ([1, 2.5, NaN], 10); assert_equal ([m, v], NaN (1, 6)); ***** error stdrstat () ***** error stdrstat (3) ***** error stdrstat ({}, 10) ***** error stdrstat (3, '') ***** error stdrstat (i, 10) ***** error stdrstat (3, i) ***** error ... stdrstat (ones (3), ones (2)) 13 tests, 13 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/nctstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/nctstat.m ***** error nctstat () ***** error nctstat (1) ***** error nctstat ({}, 2) ***** error nctstat (1, '') ***** error nctstat (i, 2) ***** error nctstat (1, i) ***** error ... nctstat (ones (3), ones (2)) ***** error ... nctstat (ones (2), ones (3)) ***** shared df, mu df = [2, 0, -1, 1, 4]; mu = [1, NaN, 3, -1, 2]; ***** assert_equal (nctstat (df, mu), [1.7725, NaN, NaN, NaN, 2.5066], 1e-4); ***** assert_equal (nctstat ([df(1:2), df(4:5)], 1), [1.7725, NaN, NaN, 1.2533], 1e-4); ***** assert_equal (nctstat ([df(1:2), df(4:5)], 3), [5.3174, NaN, NaN, 3.7599], 1e-4); ***** assert_equal (nctstat ([df(1:2), df(4:5)], 2), [3.5449, NaN, NaN, 2.5066], 1e-4); ***** assert_equal (nctstat (2, [mu(1), mu(3:5)]), [1.7725,5.3174,-1.7725,3.5449], 1e-4); ***** assert_equal (nctstat (0, [mu(1), mu(3:5)]), [NaN, NaN, NaN, NaN]); ***** assert_equal (nctstat (1, [mu(1), mu(3:5)]), [NaN, NaN, NaN, NaN]); ***** assert_equal (nctstat (4, [mu(1), mu(3:5)]), [1.2533,3.7599,-1.2533,2.5066], 1e-4); 16 tests, 16 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/hnstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/hnstat.m ***** error hnstat () ***** error hnstat (1) ***** error hnstat ({}, 2) ***** error hnstat (1, '') ***** error hnstat (i, 2) ***** error hnstat (1, i) ***** error ... hnstat (ones (3), ones (2)) ***** error ... hnstat (ones (2), ones (3)) ***** test [m, v] = hnstat (0, 1); assert_equal (m, 0.7979, 1e-4); assert_equal (v, 0.3634, 1e-4); ***** test [m, v] = hnstat (2, 1); assert_equal (m, 2.7979, 1e-4); assert_equal (v, 0.3634, 1e-4); ***** test [m, v] = hnstat (2, 2); assert_equal (m, 3.5958, 1e-4); assert_equal (v, 1.4535, 1e-4); ***** test [m, v] = hnstat (2, 2.5); assert_equal (m, 3.9947, 1e-4); assert_equal (v, 2.2711, 1e-4); ***** test [m, v] = hnstat (1.5, 0.5); assert_equal (m, 1.8989, 1e-4); assert_equal (v, 0.0908, 1e-4); ***** test [m, v] = hnstat (-1.5, 0.5); assert_equal (m, -1.1011, 1e-4); assert_equal (v, 0.0908, 1e-4); 14 tests, 14 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/copulaparam.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/copulaparam.m ***** demo ## Copula parameter of a Gaussian copula with Kendall's tau 0.3 rho = copulaparam ("Gaussian", 0.3) ***** demo ## copulaparam inverts copulastat alpha = copulaparam ("Clayton", 0.5) tau = copulastat ("Clayton", alpha) ***** test assert_equal (copulaparam ("Gaussian", 0.3), 0.453990499739547, 1e-14); assert_equal (copulaparam ("Gaussian", 0.3, "type", "Spearman"), ... 0.312868930080462, 1e-14); assert_equal (copulaparam ("t", 0.3), 0.453990499739547, 1e-14); assert_equal (copulaparam ("Clayton", 0.3), 0.857142857142857, 1e-14); assert_equal (copulaparam ("Frank", 0.3), 2.91743444592452, 1e-8); assert_equal (copulaparam ("Gumbel", 0.3), 1.42857142857143, 1e-13); ***** test for tau = [0.1, 0.25, 0.5, 0.7] for fam = {"Clayton", "Gumbel", "Frank"} a = copulaparam (fam{1}, tau); assert_equal (copulastat (fam{1}, a), tau, 1e-8); endfor endfor ***** test for rs = [0.1, 0.3, 0.6] for fam = {"Clayton", "Gumbel", "Frank"} a = copulaparam (fam{1}, rs, "type", "Spearman"); assert_equal (copulastat (fam{1}, a, "type", "Spearman"), rs, 1e-7); endfor endfor ***** test a = copulaparam ("Frank", -0.3); assert_equal (copulastat ("Frank", a), -0.3, 1e-8); a = copulaparam ("Clayton", -0.2); assert_equal (copulastat ("Clayton", a), -0.2, 1e-8); ***** test tau = [1, 0.3; 0.3, 1]; assert_equal (copulaparam ("Gaussian", tau), sin (pi .* tau ./ 2), 1e-14); ***** error ... copulaparam (5, 0.3) ***** error copulaparam ("Gaussian", 2i) ***** error ... copulaparam ("Gaussian", 0.3, "type", "Pearson") ***** error ... copulaparam ("Gaussian", 0.3, "foo") ***** error ... copulaparam ("Gaussian", 1.5) ***** error ... copulaparam ("Clayton", [0.1, 0.2]) ***** error ... copulaparam ("Clayton", 1) ***** error ... copulaparam ("Gumbel", -0.3) ***** error copulaparam ("Foo", 0.3) ***** test for ty = {'Kendall', 'Spearman'} for a = [-0.9, -0.5, -0.1, 0, 0.3, 0.7, 0.95] r = copulastat ('AMH', a, 'type', ty{1}); assert_equal (copulaparam ('AMH', r, 'type', ty{1}), a, 1e-9); endfor for a = [-1, -0.4, 0, 0.6, 1] r = copulastat ('FGM', a, 'type', ty{1}); assert_equal (copulaparam ('FGM', r, 'type', ty{1}), a, 1e-12); endfor endfor ***** test # the FGM inverse is linear assert_equal (copulaparam ('FGM', 0.1), 0.45, 1e-14); assert_equal (copulaparam ('FGM', 0.1, 'type', 'Spearman'), 0.3, 1e-14); ***** error ... copulaparam ('FGM', 0.5) ***** error ... copulaparam ('AMH', 0.5) 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/poisstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/poisstat.m ***** error poisstat () ***** error poisstat ({}) ***** error poisstat ('') ***** error poisstat (i) ***** test lambda = 1 ./ (1:6); [m, v] = poisstat (lambda); assert_equal (m, lambda); assert_equal (v, lambda); 5 tests, 5 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/tstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/tstat.m ***** error tstat () ***** error tstat ({}) ***** error tstat ('') ***** error tstat (i) ***** test df = 3:8; [m, v] = tstat (df); expected_m = [0, 0, 0, 0, 0, 0]; expected_v = [3.0000, 2.0000, 1.6667, 1.5000, 1.4000, 1.3333]; assert_equal (m, expected_m); assert_equal (v, expected_v, 0.001); 5 tests, 5 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/gevstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/gevstat.m ***** error gevstat () ***** error gevstat (1) ***** error gevstat (1, 2) ***** error gevstat ({}, 2, 3) ***** error gevstat (1, '', 3) ***** error gevstat (1, 2, '') ***** error gevstat (i, 2, 3) ***** error gevstat (1, i, 3) ***** error gevstat (1, 2, i) ***** error ... gevstat (ones (3), ones (2), 3) ***** error ... gevstat (ones (2), 2, ones (3)) ***** error ... gevstat (1, ones (2), ones (3)) ***** test k = [-1, -0.5, 0, 0.2, 0.4, 0.5, 1]; sigma = 2; mu = 1; [m, v] = gevstat (k, sigma, mu); expected_m = [1, 1.4551, 2.1544, 2.6423, 3.4460, 4.0898, Inf]; expected_v = [4, 3.4336, 6.5797, 13.3761, 59.3288, Inf, Inf]; assert_equal (m, expected_m, -0.001); assert_equal (v, expected_v, -0.001); 13 tests, 13 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/hygestat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/hygestat.m ***** error hygestat () ***** error hygestat (1) ***** error hygestat (1, 2) ***** error hygestat ({}, 2, 3) ***** error hygestat (1, '', 3) ***** error hygestat (1, 2, '') ***** error hygestat (i, 2, 3) ***** error hygestat (1, i, 3) ***** error hygestat (1, 2, i) ***** error ... hygestat (ones (3), ones (2), 3) ***** error ... hygestat (ones (2), 2, ones (3)) ***** error ... hygestat (1, ones (2), ones (3)) ***** test m = 4:9; k = 0:5; n = 1:6; [mn, v] = hygestat (m, k, n); expected_mn = [0.0000, 0.4000, 1.0000, 1.7143, 2.5000, 3.3333]; expected_v = [0.0000, 0.2400, 0.4000, 0.4898, 0.5357, 0.5556]; assert_equal (mn, expected_mn, 0.001); assert_equal (v, expected_v, 0.001); ***** test m = 4:9; k = 0:5; [mn, v] = hygestat (m, k, 2); expected_mn = [0.0000, 0.4000, 0.6667, 0.8571, 1.0000, 1.1111]; expected_v = [0.0000, 0.2400, 0.3556, 0.4082, 0.4286, 0.4321]; assert_equal (mn, expected_mn, 0.001); assert_equal (v, expected_v, 0.001); 14 tests, 14 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/expstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/expstat.m ***** error expstat () ***** error expstat ({}) ***** error expstat ('') ***** error expstat (i) ***** test mu = 1:6; [m, v] = expstat (mu); assert_equal (m, [1, 2, 3, 4, 5, 6], 0.001); assert_equal (v, [1, 4, 9, 16, 25, 36], 0.001); 5 tests, 5 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/evstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/evstat.m ***** error evstat () ***** error evstat (1) ***** error evstat ({}, 2) ***** error evstat (1, '') ***** error evstat (i, 2) ***** error evstat (1, i) ***** error ... evstat (ones (3), ones (2)) ***** error ... evstat (ones (2), ones (3)) ***** shared x, y0, y1 x = [-5, 0, 1, 2, 3]; y0 = [NaN, NaN, 0.4228, 0.8456, 1.2684]; y1 = [-5.5772, -3.4633, -3.0405, -2.6177, -2.1949]; ***** assert_equal (evstat (x, x), y0, 1e-4) ***** assert_equal (evstat (x, x+6), y1, 1e-4) ***** assert_equal (evstat (x, x-6), NaN (1,5)) 11 tests, 11 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/fstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/fstat.m ***** error fstat () ***** error fstat (1) ***** error fstat ({}, 2) ***** error fstat (1, '') ***** error fstat (i, 2) ***** error fstat (1, i) ***** error ... fstat (ones (3), ones (2)) ***** error ... fstat (ones (2), ones (3)) ***** test df1 = 1:6; df2 = 5:10; [m, v] = fstat (df1, df2); expected_mn = [1.6667, 1.5000, 1.4000, 1.3333, 1.2857, 1.2500]; expected_v = [22.2222, 6.7500, 3.4844, 2.2222, 1.5869, 1.2153]; assert_equal (m, expected_mn, 0.001); assert_equal (v, expected_v, 0.001); ***** test df1 = 1:6; [m, v] = fstat (df1, 5); expected_mn = [1.6667, 1.6667, 1.6667, 1.6667, 1.6667, 1.6667]; expected_v = [22.2222, 13.8889, 11.1111, 9.7222, 8.8889, 8.3333]; assert_equal (m, expected_mn, 0.001); assert_equal (v, expected_v, 0.001); 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/unidstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/unidstat.m ***** error unidstat () ***** error unidstat ({}) ***** error unidstat ('') ***** error unidstat (i) ***** test N = 1:6; [m, v] = unidstat (N); expected_m = [1.0000, 1.5000, 2.0000, 2.5000, 3.0000, 3.5000]; expected_v = [0.0000, 0.2500, 0.6667, 1.2500, 2.0000, 2.9167]; assert_equal (m, expected_m, 0.001); assert_equal (v, expected_v, 0.001); 5 tests, 5 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/binostat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/binostat.m ***** error binostat () ***** error binostat (1) ***** error binostat ({}, 2) ***** error binostat (1, '') ***** error binostat (i, 2) ***** error binostat (1, i) ***** error ... binostat (ones (3), ones (2)) ***** error ... binostat (ones (2), ones (3)) ***** test n = 1:6; ps = 0:0.2:1; [m, v] = binostat (n, ps); expected_m = [0.00, 0.40, 1.20, 2.40, 4.00, 6.00]; expected_v = [0.00, 0.32, 0.72, 0.96, 0.80, 0.00]; assert_equal (m, expected_m, 0.001); assert_equal (v, expected_v, 0.001); ***** test n = 1:6; [m, v] = binostat (n, 0.5); expected_m = [0.50, 1.00, 1.50, 2.00, 2.50, 3.00]; expected_v = [0.25, 0.50, 0.75, 1.00, 1.25, 1.50]; assert_equal (m, expected_m, 0.001); assert_equal (v, expected_v, 0.001); ***** test n = [-Inf -3 5 0.5 3 NaN 100, Inf]; [m, v] = binostat (n, 0.5); assert_equal (isnan (m), [true true false true false true false false]) assert_equal (isnan (v), [true true false true false true false false]) assert_equal (m(end), Inf); assert_equal (v(end), Inf); ***** assert_equal (nthargout (1:2, @binostat, 5, []), {[], []}) ***** assert_equal (nthargout (1:2, @binostat, [], 5), {[], []}) ***** assert_equal (size (binostat (randi (100, 10, 5, 4), rand (10, 5, 4))), [10 5 4]) ***** assert_equal (size (binostat (randi (100, 10, 5, 4), 7)), [10 5 4]) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/burrstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/burrstat.m ***** error burrstat () ***** error burrstat (1) ***** error burrstat (1, 2) ***** error burrstat ({}, 2, 3) ***** error burrstat (1, '', 3) ***** error burrstat (1, 2, '') ***** error burrstat (i, 2, 3) ***** error burrstat (1, i, 3) ***** error burrstat (1, 2, i) ***** error ... burrstat (ones (3), ones (2), 3) ***** error ... burrstat (ones (2), 2, ones (3)) ***** error ... burrstat (1, ones (2), ones (3)) ***** test [m, v] = burrstat (1, 2, 5); assert_equal (m, 0.4295, 1e-4); assert_equal (v, 0.0655, 1e-4); ***** test [m, v] = burrstat (1, 1, 1); assert_equal (m, Inf); assert_equal (v, Inf); ***** test [m, v] = burrstat (2, 4, 1); assert_equal (m, 2.2214, 1e-4); assert_equal (v, 1.3484, 1e-4); 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/lognstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/lognstat.m ***** error lognstat () ***** error lognstat (1) ***** error lognstat ({}, 2) ***** error lognstat (1, '') ***** error lognstat (i, 2) ***** error lognstat (1, i) ***** error ... lognstat (ones (3), ones (2)) ***** error ... lognstat (ones (2), ones (3)) ***** test mu = 0:0.2:1; sigma = 0.2:0.2:1.2; [m, v] = lognstat (mu, sigma); expected_m = [1.0202, 1.3231, 1.7860, 2.5093, 3.6693, 5.5845]; expected_v = [0.0425, 0.3038, 1.3823, 5.6447, 23.1345, 100.4437]; assert_equal (m, expected_m, 0.001); assert_equal (v, expected_v, 0.001); ***** test sigma = 0.2:0.2:1.2; [m, v] = lognstat (0, sigma); expected_m = [1.0202, 1.0833, 1.1972, 1.3771, 1.6487, 2.0544]; expected_v = [0.0425, 0.2036, 0.6211, 1.7002, 4.6708, 13.5936]; assert_equal (m, expected_m, 0.001); assert_equal (v, expected_v, 0.001); 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/logistat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/logistat.m ***** error logistat () ***** error logistat (1) ***** error logistat ({}, 2) ***** error logistat (1, '') ***** error logistat (i, 2) ***** error logistat (1, i) ***** error ... logistat (ones (3), ones (2)) ***** error ... logistat (ones (2), ones (3)) ***** test [m, v] = logistat (0, 1); assert_equal (m, 0); assert_equal (v, 3.2899, 0.001); ***** test [m, v] = logistat (0, 0.8); assert_equal (m, 0); assert_equal (v, 2.1055, 0.001); ***** test [m, v] = logistat (1, 0.6); assert_equal (m, 1); assert_equal (v, 1.1844, 0.001); ***** test [m, v] = logistat (0, 0.4); assert_equal (m, 0); assert_equal (v, 0.5264, 0.001); ***** test [m, v] = logistat (-1, 0.2); assert_equal (m, -1); assert_equal (v, 0.1316, 0.001); 13 tests, 13 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/loglstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/loglstat.m ***** error loglstat () ***** error loglstat (1) ***** error loglstat ({}, 2) ***** error loglstat (1, '') ***** error loglstat (i, 2) ***** error loglstat (1, i) ***** error ... loglstat (ones (3), ones (2)) ***** error ... loglstat (ones (2), ones (3)) ***** test [m, v] = loglstat (0, 1); assert_equal (m, Inf, 0.001); assert_equal (v, Inf, 0.001); ***** test [m, v] = loglstat (0, 0.8); assert_equal (m, 4.2758, 0.001); assert_equal (v, Inf, 0.001); ***** test [m, v] = loglstat (0, 0.6); assert_equal (m, 1.9820, 0.001); assert_equal (v, Inf, 0.001); ***** test [m, v] = loglstat (0, 0.4); assert_equal (m, 1.3213, 0.001); assert_equal (v, 2.5300, 0.001); ***** test [m, v] = loglstat (0, 0.2); assert_equal (m, 1.0690, 0.001); assert_equal (v, 0.1786, 0.001); 13 tests, 13 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/unifstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/unifstat.m ***** error unifstat () ***** error unifstat (1) ***** error unifstat ({}, 2) ***** error unifstat (1, '') ***** error unifstat (i, 2) ***** error unifstat (1, i) ***** error ... unifstat (ones (3), ones (2)) ***** error ... unifstat (ones (2), ones (3)) ***** test a = 1:6; b = 2:2:12; [m, v] = unifstat (a, b); expected_m = [1.5000, 3.0000, 4.5000, 6.0000, 7.5000, 9.0000]; expected_v = [0.0833, 0.3333, 0.7500, 1.3333, 2.0833, 3.0000]; assert_equal (m, expected_m, 0.001); assert_equal (v, expected_v, 0.001); ***** test a = 1:6; [m, v] = unifstat (a, 10); expected_m = [5.5000, 6.0000, 6.5000, 7.0000, 7.5000, 8.0000]; expected_v = [6.7500, 5.3333, 4.0833, 3.0000, 2.0833, 1.3333]; assert_equal (m, expected_m, 0.001); assert_equal (v, expected_v, 0.001); 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/normstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/normstat.m ***** error normstat () ***** error normstat (1) ***** error normstat ({}, 2) ***** error normstat (1, '') ***** error normstat (i, 2) ***** error normstat (1, i) ***** error ... normstat (ones (3), ones (2)) ***** error ... normstat (ones (2), ones (3)) ***** test mu = 1:6; sigma = 0.2:0.2:1.2; [m, v] = normstat (mu, sigma); expected_v = [0.0400, 0.1600, 0.3600, 0.6400, 1.0000, 1.4400]; assert_equal (m, mu); assert_equal (v, expected_v, 0.001); ***** test sigma = 0.2:0.2:1.2; [m, v] = normstat (0, sigma); expected_mn = [0, 0, 0, 0, 0, 0]; expected_v = [0.0400, 0.1600, 0.3600, 0.6400, 1.0000, 1.4400]; assert_equal (m, expected_mn, 0.001); assert_equal (v, expected_v, 0.001); 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/ncfstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/ncfstat.m ***** error ncfstat () ***** error ncfstat (1) ***** error ncfstat (1, 2) ***** error ncfstat ({}, 2, 3) ***** error ncfstat (1, '', 3) ***** error ncfstat (1, 2, '') ***** error ncfstat (i, 2, 3) ***** error ncfstat (1, i, 3) ***** error ncfstat (1, 2, i) ***** error ... ncfstat (ones (3), ones (2), 3) ***** error ... ncfstat (ones (2), 2, ones (3)) ***** error ... ncfstat (1, ones (2), ones (3)) ***** shared df1, df2, lambda df1 = [2, 0, -1, 1, 4, 5]; df2 = [2, 4, -1, 5, 6, 7]; lambda = [1, NaN, 3, 0, 2, -1]; ***** assert_equal (ncfstat (df1, df2, lambda), [NaN, NaN, NaN, 1.6667, 2.25, 1.12], 1e-4); ***** assert_equal (ncfstat (df1(4:6), df2(4:6), 1), [3.3333, 1.8750, 1.6800], 1e-4); ***** assert_equal (ncfstat (df1(4:6), df2(4:6), 2), [5.0000, 2.2500, 1.9600], 1e-4); ***** assert_equal (ncfstat (df1(4:6), df2(4:6), 3), [6.6667, 2.6250, 2.2400], 1e-4); ***** assert_equal (ncfstat (2, [df2(1), df2(4:6)], 5), [NaN,5.8333,5.2500,4.9000], 1e-4); ***** assert_equal (ncfstat (0, [df2(1), df2(4:6)], 5), [NaN, Inf, Inf, Inf]); ***** assert_equal (ncfstat (1, [df2(1), df2(4:6)], 5), [NaN, 10, 9, 8.4], 1e-14); ***** assert_equal (ncfstat (4, [df2(1), df2(4:6)], 5), [NaN, 3.75, 3.375, 3.15], 1e-14); 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/gumbelstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/gumbelstat.m ***** test [m, v] = gumbelstat (0, 1); assert_equal (m, 0.577215664901533, 1e-15); assert_equal (v, pi ^ 2 / 6, eps); ***** test [m, v] = gumbelstat ([-5, 0, 1, 2, 3], [0, 1, 2, -1, 3]); assert_equal (m, [NaN, 0.577215664901533, 2.154431329803066, NaN, ... 4.731646994704599], 1e-14); assert_equal (v, [NaN, pi^2/6, 2*pi^2/3, NaN, 3*pi^2/2], 1e-14); ***** test [m, v] = gumbelstat (2, 3); f = @(x) gumbelpdf (x, 2, 3); assert_equal (m, integral (@(x) x .* f(x), -Inf, Inf), 1e-8); assert_equal (v, integral (@(x) (x - m) .^ 2 .* f(x), -Inf, Inf), 1e-8); ***** test [m, v] = gumbelstat (1, 2); [me, ve] = evstat (-1, 2); assert_equal (m, -me, 1e-14); assert_equal (v, ve, 1e-14); ***** test [m, v] = gumbelstat (0, single (1)); assert_equal (class (m), 'single'); assert_equal (class (v), 'single'); ***** error gumbelstat () ***** error gumbelstat (1) ***** error ... gumbelstat (ones (3), ones (2)) ***** error ... gumbelstat (int32 (1), 2) ***** error ... gumbelstat (1, true) ***** error ... gumbelstat ('a', 2) ***** error gumbelstat (i, 2) ***** error gumbelstat (1, i) 13 tests, 13 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/ricestat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/ricestat.m ***** error ricestat () ***** error ricestat (1) ***** error ricestat ({}, 2) ***** error ricestat (1, '') ***** error ricestat (i, 2) ***** error ricestat (1, i) ***** error ... ricestat (ones (3), ones (2)) ***** error ... ricestat (ones (2), ones (3)) ***** shared s, sigma s = [2, 0, -1, 1, 4]; sigma = [1, NaN, 3, -1, 2]; ***** assert_equal (ricestat (s, sigma), [2.2724, NaN, NaN, NaN, 4.5448], 1e-4); ***** assert_equal (ricestat ([s(1:2), s(4:5)], 1), [2.2724, 1.2533, 1.5486, 4.1272], 1e-4); ***** assert_equal (ricestat ([s(1:2), s(4:5)], 3), [4.1665, 3.7599, 3.8637, 5.2695], 1e-4); ***** assert_equal (ricestat ([s(1:2), s(4:5)], 2), [3.0971, 2.5066, 2.6609, 4.5448], 1e-4); ***** assert_equal (ricestat (2, [sigma(1), sigma(3:5)]), [2.2724, 4.1665, NaN, 3.0971], 1e-4); ***** assert_equal (ricestat (0, [sigma(1), sigma(3:5)]), [1.2533, 3.7599, NaN, 2.5066], 1e-4); ***** assert_equal (ricestat (1, [sigma(1), sigma(3:5)]), [1.5486, 3.8637, NaN, 2.6609], 1e-4); ***** assert_equal (ricestat (4, [sigma(1), sigma(3:5)]), [4.1272, 5.2695, NaN, 4.5448], 1e-4); 16 tests, 16 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/nbinstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/nbinstat.m ***** error nbinstat () ***** error nbinstat (1) ***** error nbinstat ({}, 2) ***** error nbinstat (1, '') ***** error nbinstat (i, 2) ***** error nbinstat (1, i) ***** error ... nbinstat (ones (3), ones (2)) ***** error ... nbinstat (ones (2), ones (3)) ***** test r = 1:4; ps = 0.2:0.2:0.8; [m, v] = nbinstat (r, ps); expected_m = [ 4.0000, 3.0000, 2.0000, 1.0000]; expected_v = [20.0000, 7.5000, 3.3333, 1.2500]; assert_equal (m, expected_m, 0.001); assert_equal (v, expected_v, 0.001); ***** test r = 1:4; [m, v] = nbinstat (r, 0.5); expected_m = [1, 2, 3, 4]; expected_v = [2, 4, 6, 8]; assert_equal (m, expected_m, 0.001); assert_equal (v, expected_v, 0.001); 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/bisastat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/bisastat.m ***** error bisastat () ***** error bisastat (1) ***** error bisastat ({}, 2) ***** error bisastat (1, '') ***** error bisastat (i, 2) ***** error bisastat (1, i) ***** error ... bisastat (ones (3), ones (2)) ***** error ... bisastat (ones (2), ones (3)) ***** test beta = 1:6; gamma = 1:0.2:2; [m, v] = bisastat (beta, gamma); expected_m = [1.50, 3.44, 5.94, 9.12, 13.10, 18]; expected_v = [2.25, 16.128, 60.858, 172.032, 409.050, 864]; assert_equal (m, expected_m, 1e-2); assert_equal (v, expected_v, 1e-3); ***** test beta = 1:6; [m, v] = bisastat (beta, 1.5); expected_m = [2.125, 4.25, 6.375, 8.5, 10.625, 12.75]; expected_v = [8.5781, 34.3125, 77.2031, 137.2500, 214.4531, 308.8125]; assert_equal (m, expected_m, 1e-3); assert_equal (v, expected_v, 1e-4); 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/invgstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/invgstat.m ***** error invgstat () ***** error invgstat (1) ***** error invgstat ({}, 2) ***** error invgstat (1, '') ***** error invgstat (i, 2) ***** error invgstat (1, i) ***** error ... invgstat (ones (3), ones (2)) ***** error ... invgstat (ones (2), ones (3)) ***** test [m, v] = invgstat (1, 1); assert_equal (m, 1); assert_equal (v, 1); ***** test [m, v] = invgstat (2, 1); assert_equal (m, 2); assert_equal (v, 8); ***** test [m, v] = invgstat (2, 2); assert_equal (m, 2); assert_equal (v, 4); ***** test [m, v] = invgstat (2, 2.5); assert_equal (m, 2); assert_equal (v, 3.2); ***** test [m, v] = invgstat (1.5, 0.5); assert_equal (m, 1.5); assert_equal (v, 6.75); 13 tests, 13 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/gpstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/gpstat.m ***** error gpstat () ***** error gpstat (1) ***** error gpstat (1, 2) ***** error gpstat ({}, 2, 3) ***** error gpstat (1, '', 3) ***** error gpstat (1, 2, '') ***** error gpstat (i, 2, 3) ***** error gpstat (1, i, 3) ***** error gpstat (1, 2, i) ***** error ... gpstat (ones (3), ones (2), 3) ***** error ... gpstat (ones (2), 2, ones (3)) ***** error ... gpstat (1, ones (2), ones (3)) ***** shared x, y x = [-Inf, -1, 0, 1/2, 1, Inf]; y = [0, 0.5, 1, 2, Inf, Inf]; ***** assert_equal (gpstat (x, ones (1,6), zeros (1,6)), y, eps) ***** assert_equal (gpstat (single (x), 1, 0), single (y), eps ('single')) ***** assert_equal (gpstat (x, single (1), 0), single (y), eps ('single')) ***** assert_equal (gpstat (x, 1, single (0)), single (y), eps ('single')) ***** assert_equal (gpstat (single ([x, NaN]), 1, 0), single ([y, NaN]), eps ('single')) ***** assert_equal (gpstat ([x, NaN], single (1), 0), single ([y, NaN]), eps ('single')) ***** assert_equal (gpstat ([x, NaN], 1, single (0)), single ([y, NaN]), eps ('single')) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/betastat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/betastat.m ***** error betastat () ***** error betastat (1) ***** error betastat ({}, 2) ***** error betastat (1, '') ***** error betastat (i, 2) ***** error betastat (1, i) ***** error ... betastat (ones (3), ones (2)) ***** error ... betastat (ones (2), ones (3)) ***** test a = -2:6; b = 0.4:0.2:2; [m, v] = betastat (a, b); expected_m = [NaN NaN NaN 1/2 2/3.2 3/4.4 4/5.6 5/6.8 6/8]; expected_v = [NaN NaN NaN 0.0833, 0.0558, 0.0402, 0.0309, 0.0250, 0.0208]; assert_equal (m, expected_m, eps*100); assert_equal (v, expected_v, 0.001); ***** test a = -2:1:6; [m, v] = betastat (a, 1.5); expected_m = [NaN NaN NaN 1/2.5 2/3.5 3/4.5 4/5.5 5/6.5 6/7.5]; expected_v = [NaN NaN NaN 0.0686, 0.0544, 0.0404, 0.0305, 0.0237, 0.0188]; assert_equal (m, expected_m); assert_equal (v, expected_v, 0.001); ***** test a = [14 Inf 10 NaN 10]; b = [12 9 NaN Inf 12]; [m, v] = betastat (a, b); expected_m = [14/26 NaN NaN NaN 10/22]; expected_v = [168/18252 NaN NaN NaN 120/11132]; assert_equal (m, expected_m); assert_equal (v, expected_v); ***** assert_equal (nthargout (1:2, @betastat, 5, []), {[], []}) ***** assert_equal (nthargout (1:2, @betastat, [], 5), {[], []}) ***** assert_equal (size (betastat (rand (10, 5, 4), rand (10, 5, 4))), [10 5 4]) ***** assert_equal (size (betastat (rand (10, 5, 4), 7)), [10 5 4]) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/gamstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/gamstat.m ***** error gamstat () ***** error gamstat (1) ***** error gamstat ({}, 2) ***** error gamstat (1, '') ***** error gamstat (i, 2) ***** error gamstat (1, i) ***** error ... gamstat (ones (3), ones (2)) ***** error ... gamstat (ones (2), ones (3)) ***** test a = 1:6; b = 1:0.2:2; [m, v] = gamstat (a, b); expected_m = [1.00, 2.40, 4.20, 6.40, 9.00, 12.00]; expected_v = [1.00, 2.88, 5.88, 10.24, 16.20, 24.00]; assert_equal (m, expected_m, 0.001); assert_equal (v, expected_v, 0.001); ***** test a = 1:6; [m, v] = gamstat (a, 1.5); expected_m = [1.50, 3.00, 4.50, 6.00, 7.50, 9.00]; expected_v = [2.25, 4.50, 6.75, 9.00, 11.25, 13.50]; assert_equal (m, expected_m, 0.001); assert_equal (v, expected_v, 0.001); 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/plstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/plstat.m ***** shared x, Fx x = [0, 1, 3, 4, 7, 10]; Fx = [0, 0.2, 0.5, 0.6, 0.7, 1]; ***** assert_equal (plstat (x, Fx), 4.15) ***** test [m, v] = plstat (x, Fx); assert_equal (v, 10.3775, 1e-14) ***** error plstat () ***** error plstat (1) ***** error ... plstat ([0, 1, 2], [0, 1]) ***** error ... plstat ([0], [1]) ***** error ... plstat ([0, 1, 2], [0, 1, 1.5]) ***** error ... plstat ([0, 1, 2], [0, i, 1]) ***** error ... plstat ([0, i, 2], [0, 0.5, 1]) ***** error ... plstat ([0, i, 2], [0, 0.5i, 1]) 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/tlsstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/tlsstat.m ***** error tlsstat () ***** error tlsstat (1) ***** error tlsstat (1, 2) ***** error tlsstat ({}, 2, 3) ***** error tlsstat (1, '', 3) ***** error tlsstat (1, 2, ['d']) ***** error tlsstat (i, 2, 3) ***** error tlsstat (1, i, 3) ***** error tlsstat (1, 2, i) ***** error ... tlsstat (ones (3), ones (2), 1) ***** error ... tlsstat (ones (2), 1, ones (3)) ***** error ... tlsstat (1, ones (2), ones (3)) ***** test [m, v] = tlsstat (0, 1, 0); assert_equal (m, NaN); assert_equal (v, NaN); ***** test [m, v] = tlsstat (0, 1, 1); assert_equal (m, NaN); assert_equal (v, NaN); ***** test [m, v] = tlsstat (2, 1, 1); assert_equal (m, NaN); assert_equal (v, NaN); ***** test [m, v] = tlsstat (-2, 1, 1); assert_equal (m, NaN); assert_equal (v, NaN); ***** test [m, v] = tlsstat (0, 1, 2); assert_equal (m, 0); assert_equal (v, NaN); ***** test [m, v] = tlsstat (2, 1, 2); assert_equal (m, 2); assert_equal (v, NaN); ***** test [m, v] = tlsstat (-2, 1, 2); assert_equal (m, -2); assert_equal (v, NaN); ***** test [m, v] = tlsstat (0, 2, 2); assert_equal (m, 0); assert_equal (v, NaN); ***** test [m, v] = tlsstat (2, 2, 2); assert_equal (m, 2); assert_equal (v, NaN); ***** test [m, v] = tlsstat (-2, 2, 2); assert_equal (m, -2); assert_equal (v, NaN); ***** test [m, v] = tlsstat (0, 1, 3); assert_equal (m, 0); assert_equal (v, 3); ***** test [m, v] = tlsstat (0, 2, 3); assert_equal (m, 0); assert_equal (v, 6); ***** test [m, v] = tlsstat (2, 1, 3); assert_equal (m, 2); assert_equal (v, 3); ***** test [m, v] = tlsstat (2, 2, 3); assert_equal (m, 2); assert_equal (v, 6); ***** test [m, v] = tlsstat (-2, 1, 3); assert_equal (m, -2); assert_equal (v, 3); ***** test [m, v] = tlsstat (-2, 2, 3); assert_equal (m, -2); assert_equal (v, 6); 28 tests, 28 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/tristat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/tristat.m ***** error tristat () ***** error tristat (1) ***** error tristat (1, 2) ***** error tristat ('i', 2, 1) ***** error tristat (0, 'd', 1) ***** error tristat (0, 3, {}) ***** error tristat (i, 2, 1) ***** error tristat (0, i, 1) ***** error tristat (0, 3, i) ***** test a = 1:5; b = 3:7; c = 5:9; [m, v] = tristat (a, b, c); expected_m = [3, 4, 5, 6, 7]; assert_equal (m, expected_m); assert_equal (v, ones (1, 5) * (2/3)); 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/nakastat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/nakastat.m ***** error nakastat () ***** error nakastat (1) ***** error nakastat ({}, 2) ***** error nakastat (1, '') ***** error nakastat (i, 2) ***** error nakastat (1, i) ***** error ... nakastat (ones (3), ones (2)) ***** error ... nakastat (ones (2), ones (3)) ***** test [m, v] = nakastat (1, 1); assert_equal (m, 0.8862269254, 1e-10); assert_equal (v, 0.2146018366, 1e-10); ***** test [m, v] = nakastat (1, 2); assert_equal (m, 1.25331413731, 1e-10); assert_equal (v, 0.42920367321, 1e-10); ***** test [m, v] = nakastat (2, 1); assert_equal (m, 0.93998560299, 1e-10); assert_equal (v, 0.11642706618, 1e-10); 11 tests, 11 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/copulastat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/copulastat.m ***** demo ## Kendall's tau and Spearman's rho of a Gaussian copula with correlation 0.5 tau = copulastat ("Gaussian", 0.5) rho = copulastat ("Gaussian", 0.5, "type", "Spearman") ***** demo ## Kendall's tau of a Clayton copula as its parameter grows alpha = [0.5, 1, 2, 5]; tau = arrayfun (@(a) copulastat ("Clayton", a), alpha) ***** test assert_equal (copulastat ("Gaussian", 0.5), 1/3, 1e-14); assert_equal (copulastat ("Gaussian", 0.5, "type", "Spearman"), ... 0.482583739530997, 1e-14); assert_equal (copulastat ("t", 0.5), 1/3, 1e-14); assert_equal (copulastat ("Clayton", 2), 0.5, 1e-14); assert_equal (copulastat ("Frank", 3), 0.307246959430723, 1e-12); assert_equal (copulastat ("Gumbel", 2), 0.5, 1e-14); ***** test rho = [1, 0.5; 0.5, 1]; assert_equal (copulastat ("Gaussian", rho), 2/pi .* asin (rho), 1e-14); ***** test assert_equal (copulastat ("Clayton", 0), 0, 1e-14); assert_equal (copulastat ("Frank", 0), 0, 1e-14); assert_equal (copulastat ("Gumbel", 1), 0, 1e-14); assert_equal (copulastat ("Clayton", 0, "type", "Spearman"), 0, 1e-14); assert_equal (copulastat ("Gumbel", 1, "type", "Spearman"), 0, 1e-14); ***** error ... copulastat (5, 0.5) ***** error copulastat ("Gaussian", 2i) ***** error ... copulastat ("Gaussian", 0.5, "type", "Pearson") ***** error ... copulastat ("Gaussian", 0.5, "foo") ***** error ... copulastat ("Gaussian", 1.5) ***** error ... copulastat ("Clayton", [1, 2]) ***** error ... copulastat ("Gumbel", 0.5) ***** error copulastat ("Foo", 0.5) ***** test for a = [-0.9, -0.5, 0.5, 0.9] f = @(u, v) arrayfun (@(p, q) copulacdf ('AMH', [p, q], a), u, v); rho = 12 * integral2 (f, 0, 1, 0, 1, 'AbsTol', 1e-11) - 3; assert_equal (copulastat ('AMH', a, 'type', 'Spearman'), rho, 1e-8); endfor ***** test for a = [-0.9, -0.5, 0.5, 0.9] f = @(u, v) arrayfun (@(p, q) copulacdf ('AMH', [p, q], a) ... * copulapdf ('AMH', [p, q], a), u, v); tau = 4 * integral2 (f, 0, 1, 0, 1, 'AbsTol', 1e-11) - 1; assert_equal (copulastat ('AMH', a), tau, 1e-8); endfor ***** test # both measures are linear in the FGM parameter for a = [-1, -0.5, 0, 0.5, 1] assert_equal (copulastat ('FGM', a), 2 * a / 9, 1e-14); assert_equal (copulastat ('FGM', a, 'type', 'Spearman'), a / 3, 1e-14); endfor ***** test # the independence copula at a zero parameter assert_equal (copulastat ('AMH', 0), 0); assert_equal (copulastat ('AMH', 0, 'type', 'Spearman'), 0); assert_equal (copulastat ('FGM', 0), 0); ***** test # the extremes of the Ali-Mikhail-Haq range are the known ones assert_equal (copulastat ('AMH', -1), (5 - 8 * log (2)) / 3, 1e-12); assert_equal (copulastat ('AMH', 1 - eps), 1 / 3, 1e-9); ***** error ... copulastat ('AMH', 1) ***** error ... copulastat ('FGM', 1.5) 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/geostat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/geostat.m ***** error geostat () ***** error geostat ({}) ***** error geostat ('') ***** error geostat (i) ***** test ps = 1 ./ (1:6); [m, v] = geostat (ps); assert_equal (m, [0, 1, 2, 3, 4, 5], 0.001); assert_equal (v, [0, 2, 6, 12, 20, 30], 0.001); 5 tests, 5 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/wblstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/wblstat.m ***** error wblstat () ***** error wblstat (1) ***** error wblstat ({}, 2) ***** error wblstat (1, '') ***** error wblstat (i, 2) ***** error wblstat (1, i) ***** error ... wblstat (ones (3), ones (2)) ***** error ... wblstat (ones (2), ones (3)) ***** test lambda = 3:8; k = 1:6; [m, v] = wblstat (lambda, k); expected_m = [3.0000, 3.5449, 4.4649, 5.4384, 6.4272, 7.4218]; expected_v = [9.0000, 3.4336, 2.6333, 2.3278, 2.1673, 2.0682]; assert_equal (m, expected_m, 0.001); assert_equal (v, expected_v, 0.001); ***** test k = 1:6; [m, v] = wblstat (6, k); expected_m = [ 6.0000, 5.3174, 5.3579, 5.4384, 5.5090, 5.5663]; expected_v = [36.0000, 7.7257, 3.7920, 2.3278, 1.5923, 1.1634]; assert_equal (m, expected_m, 0.001); assert_equal (v, expected_v, 0.001); 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/raylstat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/raylstat.m ***** error raylstat () ***** error raylstat ({}) ***** error raylstat ('') ***** error raylstat (i) ***** test sigma = 1:6; [m, v] = raylstat (sigma); expected_m = [1.2533, 2.5066, 3.7599, 5.0133, 6.2666, 7.5199]; expected_v = [0.4292, 1.7168, 3.8628, 6.8673, 10.7301, 15.4513]; assert_equal (m, expected_m, 0.001); assert_equal (v, expected_v, 0.001); 5 tests, 5 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/chi2stat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/chi2stat.m ***** error chi2stat () ***** error chi2stat ({}) ***** error chi2stat ('') ***** error chi2stat (i) ***** test df = 1:6; [m, v] = chi2stat (df); assert_equal (m, df); assert_equal (v, [2, 4, 6, 8, 10, 12], 0.001); 5 tests, 5 passed, 0 known failure, 0 skipped [inst/Distribution_Statistics/ncx2stat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Statistics/ncx2stat.m ***** error ncx2stat () ***** error ncx2stat (1) ***** error ncx2stat ({}, 2) ***** error ncx2stat (1, '') ***** error ncx2stat (i, 2) ***** error ncx2stat (1, i) ***** error ... ncx2stat (ones (3), ones (2)) ***** error ... ncx2stat (ones (2), ones (3)) ***** shared df, d1 df = [2, 0, -1, 1, 4]; d1 = [1, NaN, 3, -1, 2]; ***** assert_equal (ncx2stat (df, d1), [3, NaN, NaN, NaN, 6]); ***** assert_equal (ncx2stat ([df(1:2), df(4:5)], 1), [3, NaN, 2, 5]); ***** assert_equal (ncx2stat ([df(1:2), df(4:5)], 3), [5, NaN, 4, 7]); ***** assert_equal (ncx2stat ([df(1:2), df(4:5)], 2), [4, NaN, 3, 6]); ***** assert_equal (ncx2stat (2, [d1(1), d1(3:5)]), [3, 5, NaN, 4]); ***** assert_equal (ncx2stat (0, [d1(1), d1(3:5)]), [NaN, NaN, NaN, NaN]); ***** assert_equal (ncx2stat (1, [d1(1), d1(3:5)]), [2, 4, NaN, 3]); ***** assert_equal (ncx2stat (4, [d1(1), d1(3:5)]), [5, 7, NaN, 6]); 16 tests, 16 passed, 0 known failure, 0 skipped [inst/Data_Manipulation/isoutlier.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Data_Manipulation/isoutlier.m ***** demo A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; TF = isoutlier (A, 'mean') ***** demo ## Use a moving detection method to detect local outliers in a sine wave x = -2*pi:0.1:2*pi; A = sin (x); A(47) = 0; time = datenum (2023,1,1,0,0,0) + (1/24)*[0:length(x)-1] - 730485; TF = isoutlier (A, 'movmedian', 5*(1/24), 'SamplePoints', time); plot (time, A) hold on plot (time(TF), A(TF), 'x') datetick ('x', 20, 'keepticks') legend ('Original Data', 'Outlier Data') ***** demo ## Locate an outlier in a vector of data and visualize the outlier x = 1:10; A = [60 59 49 49 58 100 61 57 48 58]; [TF, L, U, C] = isoutlier (A); plot (x, A); hold on plot (x(TF), A(TF), 'x'); xlim ([1,10]); line ([1,10], [L, L], 'Linestyle', ':'); text (1.1, L-2, 'Lower Threshold'); line ([1,10], [U, U], 'Linestyle', ':'); text (1.1, U-2, 'Upper Threshold'); line ([1,10], [C, C], 'Linestyle', ':'); text (1.1, C-3, 'Center Value'); legend ('Original Data', 'Outlier Data'); ***** test A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; assert_equal (isoutlier (A, 'mean'), logical ([zeros(1,8) 1 zeros(1,6)])) assert_equal (isoutlier (A, 'median'), ... logical ([zeros(1,3) 1 zeros(1,4) 1 zeros(1,6)])) ***** test A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; [TF, L, U, C] = isoutlier (A, 'mean'); assert_equal (L, -109.2459044922864, 1e-12) assert_equal (U, 264.9792378256198, 1e-12) assert_equal (C, 77.8666666666666, 1e-12) ***** test A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; [TF, L, U, C] = isoutlier (A, 'median'); assert_equal (L, 50.104386688966386, 1e-12) assert_equal (U, 67.895613311033610, 1e-12) assert_equal (C, 59) ***** test A = magic (5) + diag (200*ones (1,5)); T = logical (eye (5)); assert_equal (isoutlier (A, 2), T) ***** test A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; [TF, L, U, C] = isoutlier (A, 'movmedian', 5); l = [54.5522, 52.8283, 54.5522, 54.5522, 54.5522, 53.5522, 53.5522, ... 53.5522, 47.6566, 56.5522, 57.5522, 56.5522, 51.1044, 52.3283, 53.5522]; u = [63.4478, 66.1717, 63.4478, 63.4478, 63.4478, 62.4478, 62.4478, ... 62.4478, 74.3434, 65.4478, 66.4478, 65.4478, 68.8956, 65.6717, 62.4478]; c = [59, 59.5, 59, 59, 59, 58, 58, 58, 61, 61, 62, 61, 60, 59, 58]; assert_equal (L, l, 1e-4) assert_equal (U, u, 1e-4) assert_equal (C, c) ***** test A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; [TF, L, U, C] = isoutlier (A, 'movmedian', 5, 'SamplePoints', [1:15]); l = [54.5522, 52.8283, 54.5522, 54.5522, 54.5522, 53.5522, 53.5522, ... 53.5522, 47.6566, 56.5522, 57.5522, 56.5522, 51.1044, 52.3283, 53.5522]; u = [63.4478, 66.1717, 63.4478, 63.4478, 63.4478, 62.4478, 62.4478, ... 62.4478, 74.3434, 65.4478, 66.4478, 65.4478, 68.8956, 65.6717, 62.4478]; c = [59, 59.5, 59, 59, 59, 58, 58, 58, 61, 61, 62, 61, 60, 59, 58]; assert_equal (L, l, 1e-4) assert_equal (U, u, 1e-4) assert_equal (C, c) ***** test A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; [TF, L, U, C] = isoutlier (A, 'movmean', 5); l = [54.0841, 6.8872, 11.5608, 12.1518, 11.0210, 10.0112, -218.2840, ... -217.2375, -215.1239, -213.4890, -211.3264, 55.5800, 52.9589, ... 52.5979, 51.0627]; u = [63.2492, 131.1128, 122.4392, 122.2482, 122.5790, 122.7888, 431.0840, ... 430.8375, 430.3239, 429.8890, 429.3264, 65.6200, 66.6411, 65.9021, ... 66.9373]; c = [58.6667, 69, 67, 67.2, 66.8, 66.4, 106.4, 106.8, 107.6, 108.2, 109, ... 60.6, 59.8, 59.25, 59]; assert_equal (L, l, 1e-4) assert_equal (U, u, 1e-4) assert_equal (C, c, 1e-4) ***** test A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; [TF, L, U, C] = isoutlier (A, 'movmean', 5, 'SamplePoints', [1:15]); l = [54.0841, 6.8872, 11.5608, 12.1518, 11.0210, 10.0112, -218.2840, ... -217.2375, -215.1239, -213.4890, -211.3264, 55.5800, 52.9589, ... 52.5979, 51.0627]; u = [63.2492, 131.1128, 122.4392, 122.2482, 122.5790, 122.7888, 431.0840, ... 430.8375, 430.3239, 429.8890, 429.3264, 65.6200, 66.6411, 65.9021, ... 66.9373]; c = [58.6667, 69, 67, 67.2, 66.8, 66.4, 106.4, 106.8, 107.6, 108.2, 109, ... 60.6, 59.8, 59.25, 59]; assert_equal (L, l, 1e-4) assert_equal (U, u, 1e-4) assert_equal (C, c, 1e-4) ***** test A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; [TF, L, U, C] = isoutlier (A, 'gesd'); assert_equal (TF, logical ([0 0 0 1 0 0 0 0 1 0 0 0 0 0 0])) assert_equal (L, 34.235977035439944, 1e-12) assert_equal (U, 89.764022964560060, 1e-12) assert_equal (C, 62) ***** test A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; [TF, L, U, C] = isoutlier (A, 'gesd', 'ThresholdFactor', 0.01); assert_equal (TF, logical ([0 0 0 1 0 0 0 0 1 0 0 0 0 0 0])) assert_equal (L, 31.489256770616173, 1e-12) assert_equal (U, 92.510743229383820, 1e-12) assert_equal (C, 62) ***** test A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; [TF, L, U, C] = isoutlier (A, 'gesd', 'ThresholdFactor', 5e-10); assert_equal (TF, logical ([0 0 0 0 0 0 0 0 1 0 0 0 0 0 0])) assert_equal (L, 23.976664158788935, 1e-12) assert_equal (U, 100.02333584121110, 1e-12) assert_equal (C, 62) ***** test A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; [TF, L, U, C] = isoutlier (A, 'grubbs'); assert_equal (TF, logical ([0 0 0 1 0 0 0 0 1 0 0 0 0 0 0])) assert_equal (L, 54.642809574646606, 1e-12) assert_equal (U, 63.511036579199555, 1e-12) assert_equal (C, 59.076923076923080, 1e-12) ***** test A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; [TF, L, U, C] = isoutlier (A, 'grubbs', 'ThresholdFactor', 0.01); assert_equal (TF, logical ([0 0 0 1 0 0 0 0 1 0 0 0 0 0 0])) assert_equal (L, 54.216083184201850, 1e-12) assert_equal (U, 63.937762969644310, 1e-12) assert_equal (C, 59.076923076923080, 1e-12) ***** test A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; [TF, L, U, C] = isoutlier (A, 'percentiles', [10 90]); assert_equal (TF, logical ([0 0 0 0 0 0 0 0 1 0 0 0 0 0 0])) assert_equal (L, 57) assert_equal (U, 100) assert_equal (C, 78.5) ***** test A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; [TF, L, U, C] = isoutlier (A, 'percentiles', [20 80]); assert_equal (TF, logical ([1 0 0 1 0 0 1 0 1 0 0 0 0 0 1])) assert_equal (L, 57.5) assert_equal (U, 62) assert_equal (C, 59.75) ***** test A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; [TF, L, U, C] = isoutlier (A, 'quartiles'); assert_equal (TF, logical ([0 0 0 1 0 0 0 0 1 0 0 0 0 0 0])) assert_equal (L, 52.375, 1e-12) assert_equal (U, 67.375, 1e-12) assert_equal (C, 59.875, 1e-12) ***** test A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; [TF, L, U, C] = isoutlier (A, 'quartiles', 'ThresholdFactor', 1); assert_equal (TF, logical ([0 0 0 1 0 0 0 0 1 0 0 0 0 0 0])) assert_equal (L, 54.25, 1e-12) assert_equal (U, 65.5, 1e-12) assert_equal (C, 59.875, 1e-12) ***** test B = magic (5) + diag (200 * ones (1, 5)); [TF, L, U, C] = isoutlier (B, 'quartiles', 1); assert_equal (TF, logical (eye (5))) assert_equal (L, [-86, -77.625, -94.25, -89.125, -73.125], 1e-12) assert_equal (U, [166, 157.375, 171.75, 165.875, 153.875], 1e-12) assert_equal (C, [40, 39.875, 38.75, 38.375, 40.375], 1e-12) ***** test B = magic (5) + diag (200 * ones (1, 5)); [TF, L, U, C] = isoutlier (B, 'quartiles', 2); assert_equal (TF, logical (eye (5))) assert_equal (L, [-92.75; -72.125; -90.875; -83.625; -84.625], 1e-12) assert_equal (U, [171.25; 152.875; 166.125;161.375; 164.375], 1e-12) assert_equal (C, [39.25; 40.375; 37.625; 38.875; 39.875], 1e-12) ***** test A = [57 59 60 100 59 NaN 57 58 300 61 62 60 62 58 57]; [TF, L, U, C] = isoutlier (A, 'quartiles'); assert_equal (TF, logical ([0 0 0 1 0 0 0 0 1 0 0 0 0 0 0])) assert_equal (L, 52, 1e-12) assert_equal (U, 68, 1e-12) assert_equal (C, 60, 1e-12) ***** test A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; [TF, L, U, C] = isoutlier (A, 'percentiles', [25 75]); assert_equal (TF, logical ([1 0 0 1 0 0 1 0 1 0 1 0 1 0 1])) assert_equal (L, 58, 1e-12) assert_equal (U, 61.75, 1e-12) assert_equal (C, 59.875, 1e-12) ***** test B = magic (5) + diag (200 * ones (1, 5)); [TF, L, U, C] = isoutlier (B, 'percentiles', [25 75], 1); assert_equal (L, [8.5, 10.5, 5.5, 6.5, 12], 1e-12) assert_equal (U, [71.5, 69.25, 72, 70.25, 68.75], 1e-12) assert_equal (C, [40, 39.875, 38.75, 38.375, 40.375], 1e-12) ***** test B = magic (5) + diag (200 * ones (1, 5)); [TF, L, U, C] = isoutlier (B, 'percentiles', [25 75], 2); assert_equal (L, [6.25; 12.25; 5.5; 8.25; 8.75], 1e-12) assert_equal (U, [72.25; 68.5; 69.75; 69.5; 71], 1e-12) assert_equal (C, [39.25; 40.375; 37.625; 38.875; 39.875], 1e-12) ***** test B = magic (5) + diag (200 * ones (1, 5)); [TF, L, U, C] = isoutlier (B, 'percentiles', [10 90], 1); assert_equal (TF, false (5)) assert_equal (L, [4, 6, 1, 2, 3], 1e-12) assert_equal (U, [217, 205, 213, 221, 209], 1e-12) ***** test [TF, L, U, C] = isoutlier ([1 2; 3 NaN; 5 6; 100 8], ... 'percentiles', [25 75], 1); assert_equal (TF, logical ([1 1; 0 0; 0 0; 1 1])) assert_equal (L, [2, 3], 1e-12) assert_equal (U, [52.5, 7.5], 1e-12) ***** error ... isoutlier ([1 2 3 4 5], 'movmean') ***** error ... isoutlier ([1 2 3 4 5], 'movmedian') ***** error ... isoutlier ([1 2 3 4 5], 'percentiles') ***** error ... isoutlier ([1 2 3 4 5], 'SamplePoints') ***** error ... isoutlier ([1 2 3 4 5], 'ThresholdFactor') ***** error ... isoutlier ([1 2 3 4 5], 'MaxNumOutliers') ***** shared A A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57]; ***** error ... isoutlier (A, 'movmedian', 0); ***** error ... isoutlier (A, 'movmedian', []); ***** error ... isoutlier (A, 'movmedian', [2 3 4]); ***** error ... isoutlier (A, 'movmedian', 1.4); ***** error ... isoutlier (A, 'movmedian', [0 1]); ***** error ... isoutlier (A, 'movmedian', [2 -1]); ***** error ... isoutlier (A, 'movmedian', {2 3}); ***** error ... isoutlier (A, 'movmedian', 'char'); ***** error ... isoutlier (A, 'movmean', 0); ***** error ... isoutlier (A, 'movmean', []); ***** error ... isoutlier (A, 'movmean', [2 3 4]); ***** error ... isoutlier (A, 'movmean', 1.4); ***** error ... isoutlier (A, 'movmean', [0 1]); ***** error ... isoutlier (A, 'movmean', [2 -1]); ***** error ... isoutlier (A, 'movmean', {2 3}); ***** error ... isoutlier (A, 'movmean', 'char'); ***** error ... isoutlier (A, 'percentiles', [-1 90]); ***** error ... isoutlier (A, 'percentiles', [10 -90]); ***** error ... isoutlier (A, 'percentiles', [90]); ***** error ... isoutlier (A, 'percentiles', [90 20]); ***** error ... isoutlier (A, 'percentiles', [90 20]); ***** error ... isoutlier (A, 'percentiles', [10 20 90]); ***** error ... isoutlier (A, 'percentiles', {10 90}); ***** error ... isoutlier (A, 'percentiles', 'char'); ***** error ... isoutlier (A, 'movmean', 5, 'SamplePoints', ones (3,15)); ***** error ... isoutlier (A, 'movmean', 5, 'SamplePoints', 15); ***** error ... isoutlier (A, 'movmean', 5, 'SamplePoints', [1,1:14]); ***** error ... isoutlier (A, 'movmean', 5, 'SamplePoints', [2,1,3:15]); ***** error ... isoutlier (A, 'movmean', 5, 'SamplePoints', [1:14]); ***** error ... isoutlier (A, 'movmean', 5, 'ThresholdFactor', [1:14]); ***** error ... isoutlier (A, 'movmean', 5, 'ThresholdFactor', -1); ***** error ... isoutlier (A, 'gesd', 'ThresholdFactor', 3); ***** error ... isoutlier (A, 'grubbs', 'ThresholdFactor', 3); ***** error ... isoutlier (A, 'movmean', 5, 'MaxNumOutliers', [1:14]); ***** error ... isoutlier (A, 'movmean', 5, 'MaxNumOutliers', -1); ***** error ... isoutlier (A, 'movmean', 5, 'MaxNumOutliers', 0); ***** error ... isoutlier (A, 'movmean', 5, 'MaxNumOutliers', 1.5); ***** error ... isoutlier (A, {'movmean'}, 5, 'SamplePoints', [1:15]); ***** error isoutlier (A, {1}); ***** error isoutlier (A, true); ***** error isoutlier (A, false); ***** error isoutlier (A, 0); ***** error isoutlier (A, [1 2]); ***** error isoutlier (A, -2); 75 tests, 75 passed, 0 known failure, 0 skipped [inst/Data_Manipulation/normalise_distribution.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Data_Manipulation/normalise_distribution.m ***** test v = normalise_distribution ([1 2 3], [], 1); assert_equal (v, [0 0 0]) ***** test v = normalise_distribution ([1 2 3], [], 2); assert_equal (v, norminv ([1 3 5] / 6), 3 * eps) ***** test v = normalise_distribution ([1 2 3]', [], 2); assert_equal (v, [0 0 0]') ***** test v = normalise_distribution ([1 2 3]', [], 1); assert_equal (v, norminv ([1 3 5]' / 6), 3 * eps) ***** test v = normalise_distribution ([1 1 2 2 3 3], [], 2); assert_equal (v, norminv ([3 3 7 7 11 11] / 12), 3 * eps) ***** test v = normalise_distribution ([1 1 2 2 3 3]', [], 1); assert_equal (v, norminv ([3 3 7 7 11 11]' / 12), 3 * eps) ***** test A = randn ( 10 ); N = normalise_distribution (A, @normcdf); assert_equal (A, N, 10000 * eps) ***** test A = exprnd (1, 100); N = normalise_distribution (A, @(x)(expcdf (x, 1))); assert_equal (mean (vec (N)), 0, 0.1) assert_equal (std (vec (N)), 1, 0.1) ***** test A = rand (1000,1); N = normalise_distribution (A, {@(x)(unifcdf (x, 0, 1))}); assert_equal (mean (vec (N)), 0, 0.2) assert_equal (std (vec (N)), 1, 0.1) ***** test A = [rand(1000,1), randn(1000, 1)]; N = normalise_distribution (A, {@(x)(unifcdf (x, 0, 1)), @normcdf}); assert_equal (mean (N), [0, 0], 0.2) assert_equal (std (N), [1, 1], 0.1) ***** test A = [rand(1000,1), randn(1000, 1), exprnd(1, 1000, 1)]'; N = normalise_distribution (A, {@(x)(unifcdf (x, 0, 1)); @normcdf; @(x)(expcdf (x, 1))}, 2); assert_equal (mean (N, 2), [0, 0, 0]', 0.2); assert_equal (std (N, [], 2), [1, 1, 1]', 0.1); ***** xtest A = exprnd (1, 1000, 9); A(300:500, 4:6) = 17; N = normalise_distribution (A); assert_equal (mean (N), [0 0 0 0.38 0.38 0.38 0 0 0], 0.1); assert_equal (var (N), [1 1 1 2.59 2.59 2.59 1 1 1], 0.1); ***** test ***** error normalise_distribution (zeros (3, 4), ... {@(x)(unifcdf (x, 0, 1)); @normcdf; @(x)(expcdf (x,1))}); 14 tests, 14 passed, 0 known failure, 0 skipped [inst/Data_Manipulation/multiway.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Data_Manipulation/multiway.m ***** test numbers = [4, 5, 6, 7, 8]; num_parts = 2; [groupindex, partition, groupsizes] = multiway (numbers, num_parts, 'completeKK'); assert_equal (sort (cellfun (@sum, partition)), sort ([15, 15])); ***** test numbers = [1, 2, 3, 4, 5, 6]; num_parts = 3; [groupindex, partition, groupsizes] = multiway (numbers, num_parts, 'completeKK'); assert_equal (sort (cellfun (@sum, partition)), sort ([7, 7, 7])); ***** test numbers = [24, 21, 18, 17, 12, 11, 8, 2]; num_parts = 3; [groupindex, partition, groupsizes] = multiway (numbers, num_parts, 'completeKK'); assert_equal (sort (cellfun (@sum, partition)), sort ([38, 38, 37])); ***** test numbers = [10, 10, 10]; num_parts = 3; [~, partition] = multiway (numbers, num_parts, 'completeKK'); assert_equal (sort (cellfun (@sum, partition)), [10, 10, 10]); ***** test numbers = 1:10; num_parts = 2; [~, partition] = multiway (numbers, num_parts, 'completeKK'); assert_equal (sort (cellfun (@sum, partition)), [27, 28]); ***** test numbers = [4, 5, 6, 7, 8]; num_parts = 2; [groupindex, partition, groupsizes] = multiway (numbers, num_parts, 'greedy'); assert_equal (sort (cellfun (@sum, partition)), sort ([13, 17])); ***** test numbers = [1, 2, 3, 4, 5, 6]; num_parts = 3; [groupindex, partition, groupsizes] = multiway (numbers, num_parts, 'greedy'); assert_equal (sort (cellfun (@sum, partition)), sort ([7, 7, 7])); ***** test numbers = [10, 7, 5, 5, 6, 4, 10, 11, 12, 9, 10, 4, 3, 4, 5]; num_parts = 4; [groupindex, partition, groupsizes] = multiway (numbers, num_parts, 'greedy'); assert_equal (sort (cellfun (@sum, partition)), sort ([27, 27, 27, 24])); ***** test numbers = [24, 21, 18, 17, 12, 11, 8, 2]; num_parts = 3; [groupindex, partition, groupsizes] = multiway (numbers, num_parts, 'greedy'); assert_equal (sort (cellfun (@sum, partition)), sort ([35, 37, 41])); ***** test numbers = [10, 10, 10]; num_parts = 3; [~, partition] = multiway (numbers, num_parts, 'greedy'); assert_equal (sort (cellfun (@sum, partition)), [10, 10, 10]); ***** test numbers = 1:10; num_parts = 2; [~, partition] = multiway (numbers, num_parts, 'greedy'); assert_equal (sort (cellfun (@sum, partition)), [27, 28]); ***** test grpidx_ckk = multiway ([3 2 4 3 9 3 64], 3); grpidx_greedy = multiway ([3 2 4 3 9 3 64], 3, 'greedy'); assert_equal (isequal (grpidx_ckk, grpidx_greedy), false); ***** test numbers = [4; 5; 6; 7; 8]; num_parts = 2; [groupindex, partition, groupsizes] = multiway (numbers, num_parts, 'completeKK'); assert_equal (iscolumn (groupindex), true) assert_equal (iscolumn (groupsizes), true); assert_equal (sort (cellfun (@sum, partition)), sort ([15, 15])); numbers = [4; 5; 6; 7; 8]; num_parts = 2; [groupindex, partition, groupsizes] = multiway (numbers, num_parts, 'greedy'); assert_equal (iscolumn (groupindex), true) assert_equal (iscolumn (groupsizes), true); assert_equal (sort (cellfun (@sum, partition)), sort ([13, 17])); ***** test numbers = [4, 5, 6, 7, 8]; num_parts = 2; [groupindex, partition, groupsizes] = multiway (numbers, num_parts, 'completeKK'); assert_equal (isrow (groupindex), true) assert_equal (isrow (groupsizes), true); assert_equal (sort (cellfun (@sum, partition)), sort ([15, 15])); ***** test numbers = [4, 5, 6, 7, 8]; num_parts = 2; [groupindex, partition, groupsizes] = multiway (numbers, num_parts, 'greedy'); assert_equal (isrow (groupindex), true) assert_equal (isrow (groupsizes), true); assert_equal (sort (cellfun (@sum, partition)), sort ([13, 17])); ***** error multiway () ***** error multiway ([1, 2]) ***** error ... multiway ([1, 2, 3], 2, 1) ***** error multiway ([], 2) ***** error multiway (ones (2, 2), 2) ***** error ... multiway ({1, 2, 3}, 2) ***** error multiway ([1, -2, 3], 2) ***** error ... multiway ([1, 2, NaN], 2) ***** error multiway ([1,2,3], [1,2]) ***** error ... multiway ([1, 2, 3], '2') ***** error multiway ([1, 2, 3], 0) ***** error multiway ([1, 2, 3], 1.5) ***** error multiway ([1, 2, 3], -1) ***** error ... multiway ([1, 2], 3) ***** error ... multiway ([1,2,3], 2, 'greedyalgo') 30 tests, 30 passed, 0 known failure, 0 skipped [inst/Data_Manipulation/randsample.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Data_Manipulation/randsample.m ***** test n = 20; k = 5; x = randsample (n, k); assert_equal (size (x), [k 1]); x = randsample (n, k, true); assert_equal (size (x), [k 1]); x = randsample (n, k, false); assert_equal (size (x), [k 1]); x = randsample (n, k, true, ones (n, 1)); assert_equal (size (x), [k 1]); x = randsample (1:n, k); assert_equal (size (x), [1 k]); x = randsample (1:n, k, true); assert_equal (size (x), [1 k]); x = randsample (1:n, k, false); assert_equal (size (x), [1 k]); x = randsample (1:n, k, true, ones (n, 1)); assert_equal (size (x), [1 k]); x = randsample ((1:n)', k); assert_equal (size (x), [k 1]); x = randsample ((1:n)', k, true); assert_equal (size (x), [k 1]); x = randsample ((1:n)', k, false); assert_equal (size (x), [k 1]); x = randsample ((1:n)', k, true, ones (n, 1)); assert_equal (size (x), [k 1]); n = 10; k = 100; x = randsample (n, k, true, 1:n); assert_equal (size (x), [k 1]); x = randsample ((1:n)', k, true); assert_equal (size (x), [k 1]); x = randsample (k, k, false, 1:k); assert_equal (size (x), [k 1]); ***** test n = 20; k = 5; p = 1:n; x = randsample (p, k); assert_equal (isnumeric (x), true); assert_equal (size (x), [1 k]); x = randsample (p, k, true); assert_equal (isnumeric (x), true); assert_equal (size (x), [1 k]); x = randsample (p, k, false); assert_equal (isnumeric (x), true); assert_equal (size (x), [1 k]); k = 30; x = randsample (p, k, true); assert_equal (isnumeric (x), true); assert_equal (size (x), [1 k]); ***** test p = categorical ({'a', 'b', 'c', 'd', 'a'}); k = 3; x = randsample (p, k, true); assert_equal (iscategorical (x), true); assert_equal (size (x), [1 k]); x = randsample (p, k, false); assert_equal (iscategorical (x), true); assert_equal (size (x), [1 k]); k = 30; x = randsample (p, k, true, ones (length (p),1)); assert_equal (iscategorical (x), true); assert_equal (size (x), [1 k]); ***** test p = {'a', 'b', 'c', 'd', 'a'}; k = 2; x = randsample (p, k, true); assert_equal (iscell (x), true); assert_equal (size (x), [1 k]); x = randsample (p, k, false); assert_equal (iscell (x), true); assert_equal (size (x), [1 k]); k = 30; x = randsample (p, k, true, ones (length (p),1)); assert_equal (iscell (x), true); assert_equal (size (x), [1 k]); ***** test p = string ({'a', 'b', 'c', 'd', 'a'}); k = 2; x = randsample (p, k, true); assert_equal (isstring (x), true); assert_equal (size (x), [1 k]); x = randsample (p, k, false); assert_equal (isstring (x), true); assert_equal (size (x), [1 k]); k = 30; x = randsample (p, k, true, ones (length (p),1)); assert_equal (isstring (x), true); assert_equal (size (x), [1 k]); ***** test assert_equal (randsample ('A', 1), 'A'); assert_equal (randsample (true, 1), true); assert_equal (randsample (5.5, 1), 5.5); assert_equal (randsample (-5, 1), -5); assert_equal (randsample (-Inf, 1), -Inf); assert_equal (randsample (NaN, 1), NaN); ***** test x = randsample (10, -2); assert_equal (isempty (x), true); assert_equal (size (x), [0, 1]); ***** error ... randsample ([1 2 3; 1 2 3], 5) ***** error ... randsample (10, 100) ***** error ... randsample (10, 5, false, ones (5,1)) ***** error ... randsample (5, 2, true, [0, 0, 0, 0, 0]) ***** error ... randsample (5, 2, true, [1, 2, -1, 4, 5]) ***** error ... randsample (5, 2, true, [1, 2, NaN, 4, 5]) ***** error ... randsample (5, 4, false, [1, 1, 0, 0, 0]) ***** error ... randsample (10, 2.5) ***** error randsample (Inf, 1) ***** error randsample (5, Inf, true) ***** error randsample (5, NaN) 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Data_Manipulation/datasample.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Data_Manipulation/datasample.m ***** error datasample (); ***** error datasample (1); ***** error datasample ({1, 2, 3}, 1); ***** error ... datasample ([1 2], -1); ***** error ... datasample ([1 2], 1.5); ***** error ... datasample ([1 2], [1 1]); ***** error ... datasample ([1 2], 'g', [1 1]); ***** error datasample ([1 2], 1, -1); ***** error datasample ([1 2], 1, 1.5); ***** error datasample ([1 2], 1, [1 1]); ***** error datasample ([1 2], 1, 1, 'Replace', -2); ***** error ... datasample ([1 2], 1, 1, 'Weights', 'abc'); ***** error ... datasample ([1 2], 1, 1, 'Weights', [1 -2 3]); ***** error ... datasample ([1 2], 1, 1, 'Weights', ones (2)); ***** error ... datasample ([1 2 3 4 5], 2, 'Weights', [NaN 1 1 1 1]); ***** error ... datasample ([1 2 3 4 5], 2, 'Weights', [0 0 0 0 0]); ***** error ... datasample ([1 2 3 4 5], 1, 'Weights', [0 0 0 0 0], 'Replace', false); ***** error datasample ([1 2], 1, 1, 'Weights', [1 2 3]); ***** error ... data = 1:5; weights = [0.077846, 0.103765, 0.703748, 0.840937, 0.422901]; sampled = datasample (data, 8, 'Weights', weights, 'Replace', false); ***** error ... data = 1:5; weights = [1, 0, 1, 0, 0]; sampled = datasample (data, 3, 'Weights', weights, 'Replace', false); ***** test dat = randn (10, 4); assert_equal (size (datasample (dat, 3, 1)), [3 4]); ***** test dat = randn (10, 4); assert_equal (size (datasample (dat, 3, 2)), [10 3]); ***** test ## Edge cases with empty arrays and k=0 assert_equal (datasample ([], 0), zeros (0, 0)); assert_equal (datasample (zeros (0, 3), 0), zeros (0, 3)); ***** test ## k = 0 with weights, sampling with replacement assert_equal (datasample ([1 2 3], 0, 'Weights', [1 1 1]), zeros (1, 0)); ***** test ## k = 0 with weights, sampling without replacement assert_equal (datasample ([1 2 3], 0, 'Replace', false, ... 'Weights', [1 1 1]), zeros (1, 0)); ***** test ## Inf weight with replacement always selects the Inf-weighted element assert_equal (datasample ([1 2 3 4 5], 2, ... 'Weights', [Inf 1 1 1 1], ... 'Replace', true), [1 1]); ***** test ## Several Inf weights with replacement draw among them alone sampled = datasample (1:5, 20, 'Weights', [Inf 1 Inf 1 1]); assert_equal (all (sampled == 1 | sampled == 3), true); ***** test ## Inf weight without replacement selects the Inf-weighted element first sampled = datasample ([1 2 3 4 5], 2, ... 'Weights', [Inf 1 1 1 1], ... 'Replace', false); assert_equal (sampled(1), 1); ***** test ## Several Inf weights without replacement are all drawn first sampled = datasample (1:5, 3, 'Weights', [Inf 1 Inf 1 1], 'Replace', false); assert_equal (sort (sampled(1:2)), [1 3]); 29 tests, 29 passed, 0 known failure, 0 skipped [inst/Data_Manipulation/grp2idx.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Data_Manipulation/grp2idx.m ***** test g = grp2idx ([3 2 1 2 3 1]); assert_equal (g, [3; 2; 1; 2; 3; 1]); ***** test [g, gn] = grp2idx (['b'; 'a'; 'c'; 'a']); assert_equal (g, [1; 2; 3; 2]); assert_equal (gn, {'b'; 'a'; 'c'}); ***** test in = [true, false, false, true]; out = {[2; 1; 1; 2] {'0'; '1'} [false; true]}; assert_equal (nthargout (1:3, @grp2idx, in), out) assert_equal (nthargout (1:3, @grp2idx, in), nthargout (1:3, @grp2idx, in')) ***** test assert_equal (nthargout (1:3, @grp2idx, [false, true]), {[1; 2] {'0'; '1'} [false; true]}); assert_equal (nthargout (1:3, @grp2idx, [true, false]), {[2; 1] {'0'; '1'} [false; true]}); ***** assert_equal (nthargout (1:3, @grp2idx, ['oct'; 'sci'; 'oct'; 'oct'; 'sci']), {[1; 2; 1; 1; 2] {'oct'; 'sci'} ['oct'; 'sci']}) ***** assert_equal (nthargout (1:3, @grp2idx, {'oct'; 'sci'; 'oct'; 'oct'; 'sci'}), {[1; 2; 1; 1; 2] {'oct'; 'sci'} {'oct'; 'sci'}}) ***** assert_equal (nthargout (1:3, @grp2idx, [1, -3, -2, -3, -3, 2, 1, -1, 3, -3]), {[4; 1; 2; 1; 1; 5; 4; 3; 6; 1], {'-3'; '-2'; '-1'; '1'; '2'; '3'}, ... [-3; -2; -1; 1; 2; 3]}) ***** test s = [1e6, 2e6, 1e6, 3e6]; [g, gn, gl] = grp2idx (s); assert_equal (g, [1; 2; 1; 3]); assert_equal (gn, {'1000000'; '2000000'; '3000000'}); assert_equal (gl, [1000000; 2000000; 3000000]); ***** test s = [0.1, 0.2, 0.3, 0.1, 0.2]; [g, gn, gl] = grp2idx (s); assert_equal (g, [1; 2; 3; 1; 2]); assert_equal (gn, {'0.1'; '0.2'; '0.3'}); assert_equal (gl, [0.1; 0.2; 0.3]); ***** test s = [-5 -10 0 5 10 -5]; [g, gn, gl] = grp2idx (s); assert_equal (g, [2; 1; 3; 4; 5; 2]); assert_equal (gn, {'-10'; '-5'; '0'; '5'; '10'}); assert_equal (gl, [-10; -5; 0; 5; 10]); ***** assert_equal (nthargout (1:3, @grp2idx, [2, 2, 3, NaN, 2, 3]), ... {[1; 1; 2; NaN; 1; 2] {'2'; '3'} [2; 3]}) ***** assert_equal (nthargout (1:3, @grp2idx, {'et', 'sa', 'sa', '', 'et'}), ... {[1; 2; 2; NaN; 1] {'et'; 'sa'} {'et'; 'sa'}}) ***** assert_equal (nthargout (1:3, @grp2idx, [2, 2, 3, NaN, 2, 4]), ... {[1; 1; 2; NaN; 1; 3] {'2'; '3'; '4'} [2; 3; 4]}) ***** test s = [NaN, NaN, NaN]; [g, gn, gl] = grp2idx (s); assert_equal (g, [NaN; NaN; NaN]); assert_equal (gn, cell (0,1)); assert_equal (gl, zeros (0,1)); ***** test s = single ([NaN, NaN, NaN]); [g, gn, gl] = grp2idx (s); assert_equal (g, [NaN; NaN; NaN]); assert_equal (gn, cell (0,1)); assert_equal (gl, single (zeros (0,1))); ***** test s = {''; ''; ''; ''}; [g, gn, gl] = grp2idx (s); assert_equal (g, [NaN; NaN; NaN; NaN]); assert_equal (gn, cell (0,1)); assert_equal (gl, cell (0,1)); ***** test s = {'', '', '', ''}; [g, gn, gl] = grp2idx (s); assert_equal (g, [NaN; NaN; NaN; NaN]); assert_equal (gn, cell (0,1)); assert_equal (gl, cell (0,1)); ***** test s = {'a'; ''; 'b'; ''; 'c'}; [g, gn, gl] = grp2idx (s); assert_equal (g, [1; NaN; 2; NaN; 3]); assert_equal (gn, {'a'; 'b'; 'c'}); assert_equal (gl, {'a'; 'b'; 'c'}); ***** test s = categorical ({''; ''; ''; ''}); [g, gn, gl] = grp2idx (s); assert_equal (g, [NaN; NaN; NaN; NaN]); assert_equal (gn, cell (0,1)); assert_equal (isequaln (gl, categorical (zeros (0,1))), true); assert_equal (size (gl), [0, 1]); ***** test s = string ({missing, missing, missing}); [g, gn, gl] = grp2idx (s); assert_equal (g, [NaN; NaN; NaN]); assert_equal (gn, cell (0,1)); assert_equal (isequal (gl, string (cell (0,1))), true); ***** test s = [duration(NaN, 0, 0), duration(NaN, 0, 0), duration(NaN, 0, 0)]; [g, gn, gl] = grp2idx (s); assert_equal (g, [NaN; NaN; NaN]); assert_equal (gn, cell (0,1)); assert_equal (isequal (gl, duration (NaN (0,3))), true); ***** test [g, gn, gl] = grp2idx (duration (NaN (3, 1), 0, 0)); assert_equal (g, [NaN; NaN; NaN]); assert_equal (gn, cell (0,1)); assert_equal (isequal (gl, duration (NaN (0,3))), true); ***** test assert_equal (nthargout (1:3, @grp2idx, ['sci'; 'oct'; 'sci'; 'oct'; 'oct']), {[1; 2; 1; 2; 2] {'sci'; 'oct'} ['sci'; 'oct']}); ***** test assert_equal (nthargout (1:3, @grp2idx, {'sci'; 'oct'; 'sci'; 'oct'; 'oct'}), {[1; 2; 1; 2; 2] {'sci'; 'oct'} {'sci'; 'oct'}}); ***** test assert_equal (nthargout (1:3, @grp2idx, {'sa' 'et' 'et' '' 'sa'}), {[1; 2; 2; NaN; 1] {'sa'; 'et'} {'sa'; 'et'}}) ***** test [g, gn, gl] = grp2idx (categorical ({'low', 'med', 'high', 'low'})); assert_equal (g, [2; 3; 1; 2]); assert_equal (gn, {'high'; 'low'; 'med'}); assert_equal (isequal (gl, categorical ({'high'; 'low'; 'med'})), true); ***** test [g, gn, gl] = grp2idx (categorical ([10, 20, 10, 30, 20])); assert_equal (g, [1; 2; 1; 3; 2]); assert_equal (gn, {'10'; '20'; '30'}); assert_equal (isequal (gl, categorical ([10; 20; 30])), true); ***** test cats = categorical ({'high', '', 'low', ''}); [g, gn, gl] = grp2idx (cats); assert_equal (g, [2; 1; 3; 1]); assert_equal (gn, {''; 'high'; 'low'}); assert_equal (isequal (gl, categorical ({''; 'high'; 'low'})), true); ***** test s = categorical ({''; ''; ''; ''}, {'1', '2', '3'}, {'1', '2', '3'}); [g, gn, gl] = grp2idx (s); assert_equal (g, nan (4, 1)); assert_equal (gn, {'1'; '2'; '3'}); assert_equal (iscategorical (gl), true); assert_equal (cellstr (gl), gn); ***** test s = categorical ({''; '1'; ''; '2'}, {'1', '2', '3'}, {'1', '2', '3'}); [g, gn, gl] = grp2idx (s); assert_equal (g, [NaN; 1; NaN; 2]); assert_equal (gn, {'1'; '2'; '3'}); assert_equal (iscategorical (gl), true); assert_equal (cellstr (gl), gn); ***** test s = categorical ({''; '2'; ''; '1'}, {'1', '2', '3'}, {'1', '2', '3'}); [g, gn, gl] = grp2idx (s); assert_equal (g, [NaN; 2; NaN; 1]); assert_equal (gn, {'1'; '2'; '3'}); assert_equal (iscategorical (gl), true); assert_equal (cellstr (gl), gn); ***** test # MATLAB parity: an unused category keeps its code s = categorical ({'b'; 'c'; 'b'}, {'a', 'b', 'c'}); [g, gn, gl] = grp2idx (s); assert_equal (g, [2; 3; 2]); assert_equal (gn, {'a'; 'b'; 'c'}); assert_equal (cellstr (gl), gn); ***** test # MATLAB parity: an undefined element is NaN between defined codes s = categorical ({'b'; ''; 'c'}, {'a', 'b', 'c'}); assert_equal (grp2idx (s), [2; NaN; 3]); ***** test # MATLAB parity: the categories keep their own order and ordinality s = categorical ({'c'; 'b'}, {'c', 'b', 'a'}, 'Ordinal', true); [g, gn, gl] = grp2idx (s); assert_equal (g, [1; 2]); assert_equal (gn, {'c'; 'b'; 'a'}); assert_equal (categories (gl), {'c'; 'b'; 'a'}); assert_equal (isordinal (gl), true); ***** test g = gn = gl = []; [g, gn, gl] = grp2idx (seconds ([1.234, 1.234, 2.5, 3.000])); assert_equal (g, [1; 1; 2; 3]); assert_equal (gn, {'1.234 sec'; '2.5 sec'; '3 sec'}); assert_equal (isequal (gl, seconds ([1.234; 2.5; 3.000])), true); ***** test [g, gn, gl] = grp2idx ([hours(1); hours(2); hours(1); hours(3)]); assert_equal (g, [1; 2; 1; 3]); assert_equal (gn, {'1 hr'; '2 hr'; '3 hr'}); assert_equal (isequal (gl, [hours(1); hours(2); hours(3)]), true); ***** test in = [duration(1, 30, 0); duration(0, 45, 30); duration(1, 30, 0); duration(2, 15, 15)]; [g, gn, gl] = grp2idx (in); assert_equal (g, [2; 1; 2; 3]); assert_equal (gn, {'00:45:30'; '01:30:00'; '02:15:15'}); assert_equal (isequal (gl, [duration(0, 45, 30); duration(1, 30, 0); duration(2, 15, 15)]), true); ***** test in = [hours(1); NaN; minutes(30); hours(1); NaN; seconds(90)]; [g, gn, gl] = grp2idx (in); assert_equal (g, [3; NaN; 2; 3; NaN; 1]); assert_equal (gn, {'0.025 hr'; '0.5 hr'; '1 hr'}); assert_equal (isequal (gl, [seconds(90); minutes(30); hours(1)]), true); ***** test [g, gn, gl] = grp2idx (string ({'123', 'erw', missing, '', '234'})); assert_equal (g, [1; 2; NaN; NaN; 3]); assert_equal (gn, {'123'; 'erw'; '234'}); assert_equal (isequal (gl, string ({'123'; 'erw'; '234'})), true); ***** test [g, gn, gl] = grp2idx (string ({'medium', 'low', 'high', 'medium', 'medium'})); assert_equal (g, [1; 2; 3; 1; 1]); assert_equal (gn, {'medium'; 'low'; 'high'}); assert_equal (isequal (gl, string ({'medium'; 'low'; 'high'})), true); ***** test [g, gn, gl] = grp2idx (string ({'', 'high', 'low', ''})); assert_equal (g, [NaN; 1; 2; NaN]); assert_equal (gn, {'high'; 'low'}); assert_equal (isequal (gl, string ({'high'; 'low'})), true); ***** test [g, gn, gl] = grp2idx (string ({'a', 'a', 'b', 'c'})); assert_equal (g, [1; 1; 2; 3]); assert_equal (gn, {'a'; 'b'; 'c'}); assert_equal (isstring (gl), true); assert_equal (cellstr (gl), gn); ***** test [g, gn, gl] = grp2idx (zeros (0, 1)); assert_equal (size (g), [0, 1]); assert_equal (size (gn), [0, 1]); assert_equal (size (gl), [0, 1]); ***** test [g, gn, gl] = grp2idx (cell (0, 1)); assert_equal (g, zeros (0, 1)); assert_equal (gn, cell (0, 1)); assert_equal (gl, cell (0, 1)); ***** test [g, gn, gl] = grp2idx (string (cell (0, 1))); assert_equal (g, zeros (0, 1)); assert_equal (gn, cell (0, 1)); assert_equal (isstring (gl), true); assert_equal (size (gl), [0, 1]); ***** test [g, gn, gl] = grp2idx (categorical (zeros (0, 1))); assert_equal (g, zeros (0, 1)); assert_equal (gn, cell (0, 1)); assert_equal (iscategorical (gl), true); assert_equal (size (gl), [0, 1]); ***** test [g, gn, gl] = grp2idx (char (zeros (0, 3))); assert_equal (g, zeros (0, 1)); assert_equal (gn, cell (0, 1)); assert_equal (gl, char (zeros (0, 3))); ***** test [g, gn, gl] = grp2idx (''); assert_equal (g, zeros (0, 1)); assert_equal (gn, cell (0, 1)); assert_equal (gl, ''); ***** test [g, gn, gl] = grp2idx (char (zeros (3, 0))); assert_equal (g, [NaN; NaN; NaN]); assert_equal (gn, cell (0, 1)); assert_equal (gl, ''); ***** error grp2idx (ones (3, 3, 3)) ***** error ... grp2idx (categorical ([1, 2; 1, 3])) ***** error ... grp2idx (datetime ('now')) ***** error ... grp2idx (days ([1, 2; 1, 3])) ***** error ... grp2idx (string ({'a', 'a'; 'b', 'c'})) ***** error grp2idx ({1}) ***** error grp2idx ([10, 20; 10, 30]) ***** error grp2idx ([true, false; false, true]) ***** error grp2idx ({'a', 'b'; 'c', 'd'}) 58 tests, 58 passed, 0 known failure, 0 skipped [inst/Data_Manipulation/fillmissing.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Data_Manipulation/fillmissing.m ***** assert_equal (fillmissing ([1, 2, 3], 'constant', 99), [1, 2, 3]) ***** assert_equal (fillmissing ([1, 2, NaN], 'constant', 99), [1, 2, 99]) ***** assert_equal (fillmissing ([NaN, 2, NaN], 'constant', 99), [99, 2, 99]) ***** assert_equal (fillmissing ([1, 2, 3]', 'constant', 99), [1, 2, 3]') ***** assert_equal (fillmissing ([1, 2, NaN]', 'constant', 99), [1, 2, 99]') ***** assert_equal (fillmissing ([1, 2, 3; 4, 5, 6], 'constant', 99), [1, 2, 3; 4, 5, 6]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'constant', 99), [1, 2, 99; 4, 99, 6]) ***** assert_equal (fillmissing ([NaN, 2, NaN; 4, NaN, 6], 'constant', [97, 98, 99]), [97, 2, 99; 4, 98, 6]) ***** test x = cat (3, [1, 2, NaN; 4, NaN, 6], [NaN, 2, 3; 4, 5, NaN]); y = cat (3, [1, 2, 99; 4, 99, 6], [99, 2, 3; 4, 5, 99]); assert_equal (fillmissing (x, 'constant', 99), y); y = cat (3, [1, 2, 96; 4, 95, 6], [97, 2, 3; 4, 5, 99]); assert_equal (fillmissing (x, 'constant', [94:99]), y); assert_equal (fillmissing (x, 'constant', [94:99]'), y); assert_equal (fillmissing (x, 'constant', permute ([94:99], [1 3 2])), y); assert_equal (fillmissing (x, 'constant', [94, 96, 98; 95, 97, 99]), y); assert_equal (fillmissing (x, 'constant', [94:99], 1), y); y = cat (3, [1, 2, 96; 4, 97, 6], [98, 2, 3; 4, 5, 99]); assert_equal (fillmissing (x, 'constant', [96:99], 2), y); y = cat (3, [1, 2, 98; 4, 97, 6], [94, 2, 3; 4, 5, 99]); assert_equal (fillmissing (x, 'constant', [94:99], 3), y); y = cat (3, [1, 2, 92; 4, 91, 6], [94, 2, 3; 4, 5, 99]); assert_equal (fillmissing (x, 'constant', [88:99], 99), y); ***** test x = reshape ([1:24], 4, 3, 2); x([1, 6, 7, 9, 12, 14, 16, 19, 22, 23]) = NaN; y = x; y([1, 6, 7, 9, 12, 14, 16, 19, 22, 23]) = [94, 95, 95, 96, 96, 97, 97, 98, 99, 99]; assert_equal (fillmissing (x, 'constant', [94:99], 1), y); y([1, 6, 7, 9, 12, 14, 16, 19, 22, 23]) = [92, 93, 94, 92, 95, 97, 99, 98, 97, 98]; assert_equal (fillmissing (x, 'constant', [92:99], 2), y); y([1, 6, 7, 9, 12, 14, 16, 19, 22, 23]) = [88, 93, 94, 96, 99, 89, 91, 94, 97, 98]; assert_equal (fillmissing (x, 'constant', [88:99], 3), y); y([1, 6, 7, 9, 12, 14, 16, 19, 22, 23]) = [76, 81, 82, 84, 87, 89, 91, 94, 97, 98]; assert_equal (fillmissing (x, 'constant', [76:99], 99), y); ***** assert_equal (fillmissing ([1, 2, 3], 'constant', 99, 'endvalues', 88), [1, 2, 3]) ***** assert_equal (fillmissing ([1, NaN, 3], 'constant', 99, 'endvalues', 88), [1, 99, 3]) ***** assert_equal (fillmissing ([1, 2, NaN], 'constant', 99, 'endvalues', 88), [1, 2, 88]) ***** assert_equal (fillmissing ([NaN, 2, 3], 'constant', 99, 'endvalues', 88), [88, 2, 3]) ***** assert_equal (fillmissing ([NaN, NaN, 3], 'constant', 99, 'endvalues', 88), [88, 88, 3]) ***** assert_equal (fillmissing ([1, NaN, NaN], 'constant', 99, 'endvalues', 88), [1, 88, 88]) ***** assert_equal (fillmissing ([NaN, 2, NaN], 'constant', 99, 'endvalues', 88), [88, 2, 88]) ***** assert_equal (fillmissing ([NaN, 2, NaN]', 'constant', 99, 'endvalues', 88), [88, 2, 88]') ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'constant', 99, 'endvalues', 88), [1, 99, 3, 99, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'constant', 99, 'endvalues', 88), [1, 99, 99, 99, 5]) ***** assert_equal (fillmissing ([NaN, NaN, NaN, NaN, 5], 'constant', 99, 'endvalues', 88), [88, 88, 88, 88, 5]) ***** assert_equal (fillmissing ([1, NaN, 3, 4, NaN], 'constant', 99, 'endvalues', 88), [1, 99, 3, 4, 88]) ***** assert_equal (fillmissing ([1, NaN, 3, 4, NaN], 'constant', 99, 1, 'endvalues', 88), [1, 88, 3, 4, 88]) ***** assert_equal (fillmissing ([1, NaN, 3, 4, NaN], 'constant', 99, 1, 'endvalues', 'extrap'), [1, 99, 3, 4, 99]) ***** test x = reshape ([1:24], 3, 4, 2); y = x; x([1, 2, 5, 6, 8, 10, 13, 16, 18, 19, 20, 21, 22]) = NaN; y([1, 2, 5, 6, 10, 13, 16, 18, 19, 20, 21, 22]) = 88; y([8]) = 99; assert_equal (fillmissing (x, 'constant', 99, 'endvalues', 88), y); assert_equal (fillmissing (x, 'constant', 99, 1, 'endvalues', 88), y); y = x; y([1, 2, 5, 8, 10, 13, 16, 19, 22]) = 88; y([6, 18, 20, 21]) = 99; assert_equal (fillmissing (x, 'constant', 99, 2, 'endvalues', 88), y); y(y == 99) = 88; assert_equal (fillmissing (x, 'constant', 99, 3, 'endvalues', 88), y); assert_equal (fillmissing (x, 'constant', 99, 4, 'endvalues', 88), y); assert_equal (fillmissing (x, 'constant', 99, 99, 'endvalues', 88), y); y([8]) = 94; assert_equal (fillmissing (x, 'constant', [92:99], 1, 'endvalues', 88), y); y([6, 8, 18, 20, 21]) = [96, 88, 99, 98, 99]; assert_equal (fillmissing (x, 'constant', [94:99], 2, 'endvalues', 88), y); y = x; y(isnan (y)) = 88; assert_equal (fillmissing (x, 'constant', [88:99], 3, 'endvalues', 88), y); y = x; y(isnan (y)) = [82, 82, 83, 83, 94, 85, 86, 87, 87, 88, 88, 88, 89]; assert_equal (fillmissing (x, 'constant', [92:99], 1, 'endvalues', [82:89]), y); y = x; y(isnan (y)) = [84, 85, 85, 96, 85, 84, 87, 87, 99, 87, 98, 99, 87]; assert_equal (fillmissing (x, 'constant', [94:99], 2, 'endvalues', [84:89]), y); y = x; y(isnan (y)) = [68, 69, 72, 73, 75, 77, 68, 71, 73, 74, 75, 76, 77]; assert_equal (fillmissing (x, 'constant', [88:99], 3, 'endvalues', [68:79]), y); assert_equal (fillmissing (x, 'constant', [88:93; 94:99]', 3, 'endvalues', [68:73; 74:79]'), y) ***** test x = reshape ([1:24],4,3,2); x([1, 6, 7, 9, 12, 14, 16, 19, 22, 23]) = NaN; y = x; y([1, 6, 7, 9, 12, 14, 16, 19, 22, 23]) = [94, 95, 95, 96, 96, 97, 97, 98, 99, 99]; assert_equal (fillmissing (x, 'constant', [94:99], 1), y); y([1, 6, 7, 9, 12, 14, 16, 19, 22, 23]) = [92, 93, 94, 92, 95, 97, 99, 98, 97, 98]; assert_equal (fillmissing (x, 'constant', [92:99], 2), y); y([1, 6, 7, 9, 12, 14, 16, 19, 22, 23]) = [88, 93, 94, 96, 99, 89, 91, 94, 97, 98]; assert_equal (fillmissing (x, 'constant', [88:99], 3), y); y([1, 6, 7, 9, 12, 14, 16, 19, 22, 23]) = [76, 81, 82, 84, 87, 89, 91, 94, 97, 98]; assert_equal (fillmissing (x, 'constant', [76:99], 99), y); ***** assert_equal (fillmissing ([1, 2, 3], 'previous'), [1, 2, 3]) ***** assert_equal (fillmissing ([1, 2, 3], 'next'), [1, 2, 3]) ***** assert_equal (fillmissing ([1, 2, 3]', 'previous'), [1, 2, 3]') ***** assert_equal (fillmissing ([1, 2, 3]', 'next'), [1, 2, 3]') ***** assert_equal (fillmissing ([1, 2, NaN], 'previous'), [1, 2, 2]) ***** assert_equal (fillmissing ([1, 2, NaN], 'next'), [1, 2, NaN]) ***** assert_equal (fillmissing ([NaN, 2, NaN], 'previous'), [NaN, 2, 2]) ***** assert_equal (fillmissing ([NaN, 2, NaN], 'next'), [2, 2, NaN]) ***** assert_equal (fillmissing ([1, NaN, 3], 'previous'), [1, 1, 3]) ***** assert_equal (fillmissing ([1, NaN, 3], 'next'), [1, 3, 3]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'previous', 1), [1, 2, NaN; 4, 2, 6]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'previous', 2), [1, 2, 2; 4, 4, 6]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'previous', 3), [1, 2, NaN; 4, NaN, 6]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'next', 1), [1, 2, 6; 4, NaN, 6]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'next', 2), [1, 2, NaN; 4, 6, 6]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'next', 3), [1, 2, NaN; 4, NaN, 6]) ***** test x = reshape ([1:24], 4, 3, 2); x([1, 6, 7, 9, 12, 14, 16, 19, 22, 23]) = NaN; y = x; y([1, 6, 7, 9, 14, 19, 22, 23]) = [2, 8, 8, 10, 15, 20, 24, 24]; assert_equal (fillmissing (x, 'next', 1), y); y = x; y([1, 6, 7, 14, 16]) = [5, 10, 11, 18, 20]; assert_equal (fillmissing (x, 'next', 2), y); y = x; y([1, 6, 9, 12]) = [13, 18, 21, 24]; assert_equal (fillmissing (x, 'next', 3), y); assert_equal (fillmissing (x, 'next', 99), x); y = x; y([6, 7, 12, 14, 16, 19, 22, 23]) = [5, 5, 11, 13, 15, 18, 21, 21]; assert_equal (fillmissing (x, 'previous', 1), y); y = x; y([6, 7, 9, 12, 19, 22, 23]) = [2, 3, 5, 8, 15, 18, 15]; assert_equal (fillmissing (x, 'previous', 2), y); y = x; y([14, 16, 22, 23]) = [2, 4, 10, 11]; assert_equal (fillmissing (x, 'previous', 3), y); assert_equal (fillmissing (x, 'previous', 99), x); ***** assert_equal (fillmissing ([1, 2, 3], 'constant', 0, 'endvalues', 'previous'), [1, 2, 3]) ***** assert_equal (fillmissing ([1, 2, 3], 'constant', 0, 'endvalues', 'next'), [1, 2, 3]) ***** assert_equal (fillmissing ([1, NaN, 3], 'constant', 0, 'endvalues', 'previous'), [1, 0, 3]) ***** assert_equal (fillmissing ([1, NaN, 3], 'constant', 0, 'endvalues', 'next'), [1, 0, 3]) ***** assert_equal (fillmissing ([1, 2, NaN], 'constant', 0, 'endvalues', 'previous'), [1, 2, 2]) ***** assert_equal (fillmissing ([1, 2, NaN], 'constant', 0, 'endvalues', 'next'), [1, 2, NaN]) ***** assert_equal (fillmissing ([1, NaN, NaN], 'constant', 0, 'endvalues', 'previous'), [1, 1, 1]) ***** assert_equal (fillmissing ([1, NaN, NaN], 'constant', 0, 'endvalues', 'next'), [1, NaN, NaN]) ***** assert_equal (fillmissing ([NaN, 2, 3], 'constant', 0, 'endvalues', 'previous'), [NaN, 2, 3]) ***** assert_equal (fillmissing ([NaN, 2, 3], 'constant', 0, 'endvalues', 'next'), [2, 2, 3]) ***** assert_equal (fillmissing ([NaN, NaN, 3], 'constant', 0, 'endvalues', 'previous'), [NaN, NaN, 3]) ***** assert_equal (fillmissing ([NaN, NaN, 3], 'constant', 0, 'endvalues', 'next'), [3, 3, 3]) ***** assert_equal (fillmissing ([NaN, NaN, NaN], 'constant', 0, 'endvalues', 'previous'), [NaN, NaN, NaN]) ***** assert_equal (fillmissing ([NaN, NaN, NaN], 'constant', 0, 'endvalues', 'next'), [NaN, NaN, NaN]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'constant', 0, 'endvalues', 'previous'), [NaN, 2, 0, 4, 4]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'constant', 0, 'endvalues', 'next'), [2, 2, 0, 4, NaN]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'constant', 0, 1, 'endvalues', 'previous'), [NaN, 2, NaN, 4, NaN]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'constant', 0, 1, 'endvalues', 'next'), [NaN, 2, NaN, 4, NaN]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'constant', 0, 2, 'endvalues', 'previous'), [NaN, 2, 0, 4, 4]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'constant', 0, 2, 'endvalues', 'next'), [2, 2, 0, 4, NaN]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'constant', 0, 3, 'endvalues', 'previous'), [NaN, 2, NaN, 4, NaN]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'constant', 0, 3, 'endvalues', 'next'), [NaN, 2, NaN, 4, NaN]) ***** test x = reshape ([1:24], 3, 4, 2); x([1, 2, 5, 6, 8, 10, 13, 16, 18, 19, 20, 21, 22]) = NaN; y = x; y([5, 6, 8, 18]) = [4, 4, 0, 17]; assert_equal (fillmissing (x, 'constant', 0, 'endvalues', 'previous'), y); assert_equal (fillmissing (x, 'constant', 0, 1, 'endvalues', 'previous'), y); y = x; y([6, 10, 18, 20, 21]) = [0, 7, 0, 0, 0]; assert_equal (fillmissing (x, 'constant', 0, 2, 'endvalues', 'previous'), y); y = x; y([16, 19, 21]) = [4, 7, 9]; assert_equal (fillmissing (x, 'constant', 0, 3, 'endvalues', 'previous'), y); assert_equal (fillmissing (x, 'constant', 0, 4, 'endvalues', 'previous'), x); assert_equal (fillmissing (x, 'constant', 0, 99, 'endvalues', 'previous'), x); y = x; y([1, 2, 8, 10, 13, 16, 22]) = [3, 3, 0, 11, 14, 17, 23]; assert_equal (fillmissing (x, 'constant', 0, 'endvalues', 'next'), y); assert_equal (fillmissing (x, 'constant', 0, 1, 'endvalues', 'next'), y); y = x; y([1, 2, 5, 6, 8, 18, 20, 21]) = [4, 11, 11, 0, 11, 0, 0, 0]; assert_equal (fillmissing (x, 'constant', 0, 2, 'endvalues', 'next'), y); y = x; y([2, 5]) = [14, 17]; assert_equal (fillmissing (x, 'constant', 0, 3, 'endvalues', 'next'), y); assert_equal (fillmissing (x, 'constant', 0, 4, 'endvalues', 'next'), x); assert_equal (fillmissing (x, 'constant', 0, 99, 'endvalues', 'next'), x); ***** assert_equal (fillmissing ([1, 2, 3], 'nearest'), [1, 2, 3]) ***** assert_equal (fillmissing ([1, 2, 3]', 'nearest'), [1, 2, 3]') ***** assert_equal (fillmissing ([1, 2, NaN], 'nearest'), [1, 2, 2]) ***** assert_equal (fillmissing ([NaN, 2, NaN], 'nearest'), [2, 2, 2]) ***** assert_equal (fillmissing ([1, NaN, 3], 'nearest'), [1, 3, 3]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'nearest', 1), [1, 2, 6; 4, 2, 6]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'nearest', 2), [1, 2, 2; 4, 6, 6]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'nearest', 3), [1, 2, NaN; 4, NaN, 6]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'nearest'), [1, 3, 3, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'nearest', 'samplepoints', [0, 1, 2, 3, 4]), [1, 3, 3, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'nearest', 'samplepoints', [0.5, 1, 2, 3, 5]), [1, 1, 3, 3, 5]) ***** test x = reshape ([1:24], 4, 3, 2); x([1, 6, 7, 9, 12, 14, 16, 19, 22, 23]) = NaN; y = x; y([1, 6, 7, 9, 12, 14, 16, 19, 22, 23]) = [2, 5, 8, 10, 11, 15, 15, 20, 21, 24]; assert_equal (fillmissing (x, 'nearest', 1), y); y = x; y([1, 6, 7, 9, 12, 14, 16, 19, 22, 23]) = [5, 10, 11, 5, 8, 18, 20, 15, 18, 15]; assert_equal (fillmissing (x, 'nearest', 2), y); y = x; y([1, 6, 9, 12, 14, 16, 22, 23]) = [13, 18, 21, 24, 2, 4, 10, 11]; assert_equal (fillmissing (x, 'nearest', 3), y); assert_equal (fillmissing (x, 'nearest', 99), x); ***** assert_equal (fillmissing ([1, 2, 3], 'constant', 0, 'endvalues', 'nearest'), [1, 2, 3]) ***** assert_equal (fillmissing ([1, NaN, 3], 'constant', 0, 'endvalues', 'nearest'), [1 0 3]) ***** assert_equal (fillmissing ([1, 2, NaN], 'constant', 0, 'endvalues', 'nearest'), [1, 2, 2]) ***** assert_equal (fillmissing ([1, NaN, NaN], 'constant', 0, 'endvalues', 'nearest'), [1, 1, 1]) ***** assert_equal (fillmissing ([NaN, 2, 3], 'constant', 0, 'endvalues', 'nearest'), [2, 2, 3]) ***** assert_equal (fillmissing ([NaN, NaN, 3], 'constant', 0, 'endvalues', 'nearest'), [3, 3, 3]) ***** assert_equal (fillmissing ([NaN, NaN, NaN], 'constant', 0, 'endvalues', 'nearest'), [NaN, NaN, NaN]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'constant', 0, 'endvalues', 'nearest'), [2, 2, 0, 4, 4]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'constant', 0, 1, 'endvalues', 'nearest'), [NaN, 2, NaN, 4, NaN]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'constant', 0, 2, 'endvalues', 'nearest'), [2, 2, 0, 4, 4]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'constant', 0, 3, 'endvalues', 'nearest'), [NaN, 2, NaN, 4, NaN]) ***** test x = reshape ([1:24], 3, 4, 2); x([1, 2, 5, 6, 8, 10, 13, 16, 18, 19, 20, 21, 22]) = NaN; y = x; y([1, 2, 5, 6, 8, 10, 13, 16, 18, 22]) = [3, 3, 4, 4, 0, 11, 14, 17, 17, 23]; assert_equal (fillmissing (x, 'constant', 0, 'endvalues', 'nearest'), y); assert_equal (fillmissing (x, 'constant', 0, 1, 'endvalues', 'nearest'), y); y = x; y([1, 2, 5, 6, 8, 10, 18, 20, 21]) = [4, 11, 11, 0, 11, 7, 0, 0, 0]; assert_equal (fillmissing (x, 'constant', 0, 2, 'endvalues', 'nearest'), y); y = x; y([2, 5, 16, 19, 21]) = [14, 17, 4, 7, 9]; assert_equal (fillmissing (x, 'constant', 0, 3, 'endvalues', 'nearest'), y); assert_equal (fillmissing (x, 'constant', 0, 99, 'endvalues', 'nearest'), x); ***** assert_equal (fillmissing ([1, 2, 3], 'linear'), [1, 2, 3]) ***** assert_equal (fillmissing ([1, 2, 3]', 'linear'), [1, 2, 3]') ***** assert_equal (fillmissing ([1, 2, NaN], 'linear'), [1, 2, 3]) ***** assert_equal (fillmissing ([NaN, 2, NaN], 'linear'), [NaN, 2, NaN]) ***** assert_equal (fillmissing ([1, NaN, 3], 'linear'), [1, 2, 3]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'linear', 1), [1, 2, NaN; 4, NaN, 6]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'linear', 2), [1, 2, 3; 4, 5, 6]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'linear', 3), [1, 2, NaN; 4, NaN, 6]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'linear'), [1, 2, 3, 4, 5]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'linear', 'samplepoints', [0, 1, 2, 3, 4]), [1, 2, 3, 4, 5]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'linear', 'samplepoints', [0, 1.5, 2, 5, 14]), [1, 2.5, 3, 3.5, 5], eps) ***** test x = reshape ([1:24], 4, 3, 2); x([1, 6, 7, 9, 12, 14, 16, 19, 22, 23]) = NaN; assert_equal (fillmissing (x, 'linear', 1), reshape ([1:24], 4, 3, 2)); y = reshape ([1:24], 4, 3, 2); y([1, 9, 14, 19, 22, 23]) = NaN; assert_equal (fillmissing (x, 'linear', 2), y); y = reshape ([1:24], 4, 3, 2); y([1, 6, 7, 9, 12, 14, 16, 19, 22, 23]) = NaN; assert_equal (fillmissing (x, 'linear', 3), y); assert_equal (fillmissing (x, 'linear', 99), x); ***** assert_equal (fillmissing ([1, 2, 3], 'linear', 'endvalues', 0), [1, 2, 3]) ***** assert_equal (fillmissing ([1, NaN, 3], 'linear', 'endvalues', 0), [1, 2, 3]) ***** assert_equal (fillmissing ([1, 2, NaN], 'linear', 'endvalues', 0), [1, 2, 0]) ***** assert_equal (fillmissing ([1, NaN, NaN], 'linear', 'endvalues', 0), [1, 0, 0]) ***** assert_equal (fillmissing ([NaN, 2, 3], 'linear', 'endvalues', 0), [0, 2, 3]) ***** assert_equal (fillmissing ([NaN, NaN, 3], 'linear', 'endvalues', 0), [0, 0, 3]) ***** assert_equal (fillmissing ([NaN, NaN, NaN], 'linear', 'endvalues', 0), [0, 0, 0]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'linear', 'endvalues', 0), [0, 2, 3, 4, 0]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'linear', 1, 'endvalues', 0), [0, 2, 0, 4, 0]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'linear', 2, 'endvalues', 0), [0, 2, 3, 4, 0]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'linear', 3, 'endvalues', 0), [0, 2, 0, 4, 0]) ***** test x = reshape ([1:24], 3, 4, 2); x([1, 2, 5, 6, 8, 10, 13, 16, 18, 19, 20, 21, 22]) = NaN; y = x; y([1, 2, 5, 6, 10, 13, 16, 18, 19, 20, 21, 22]) = 0; y(8) = 8; assert_equal (fillmissing (x, 'linear', 'endvalues', 0), y); assert_equal (fillmissing (x, 'linear', 1, 'endvalues', 0), y); y = x; y([1, 2, 5, 8, 10, 13, 16, 19, 22]) = 0; y([6, 18, 20, 21]) = [6, 18, 20, 21]; assert_equal (fillmissing (x, 'linear', 2, 'endvalues', 0), y); y = x; y(isnan (y)) = 0; assert_equal (fillmissing (x, 'linear', 3, 'endvalues', 0), y); assert_equal (fillmissing (x, 'linear', 99, 'endvalues', 0), y); ***** assert_equal (fillmissing ([1, 2, 3], 'constant', 99, 'endvalues', 'linear'), [1, 2, 3]) ***** assert_equal (fillmissing ([1, NaN, 3], 'constant', 99, 'endvalues', 'linear'), [1, 99, 3]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN], 'constant', 99, 'endvalues', 'linear'), [1, 99, 3, 4]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'constant', 99, 'endvalues', 'linear'), [1, 2, 99, 4, 5]) ***** assert_equal (fillmissing ([NaN, 2, NaN, NaN], 'constant', 99, 'endvalues', 'linear'), [NaN, 2, NaN, NaN]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'constant', 99, 'endvalues', 'linear', 'samplepoints', [1, 2, 3, 4, 5]), [1, 2, 99, 4, 5]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'constant', 99, 'endvalues', 'linear', 'samplepoints', [0, 2, 3, 4, 10]), [0, 2, 99, 4, 10]) ***** test x = reshape ([1:24], 3, 4, 2); x([1, 2, 5, 6, 8, 10, 13, 16, 18, 19, 20, 21, 22]) = NaN; y = x; y([1, 6, 10, 18, 20, 21]) = [2.5, 5, 8.5, 17.25, 21, 21.75]; assert_equal (fillmissing (x, 'linear', 2, 'samplepoints', [2 4 8 10]), y, eps); y([1, 6, 10, 18, 20, 21]) = [2.5, 4.5, 8.5, 17.25, 21.5, 21.75]; assert_equal (fillmissing (x, 'spline', 2, 'samplepoints', [2, 4, 8, 10]), y, eps); y([1, 6, 10, 18, 20, 21]) = [2.5, 4.559386973180077, 8.5, 17.25, 21.440613026819925, 21.75]; assert_equal (fillmissing (x, 'pchip', 2, 'samplepoints', [2, 4, 8, 10]), y, 10*eps); ***** test <60965> x = reshape ([1:24], 3, 4, 2); x([1, 2, 5, 6, 8, 10, 13, 16, 18, 19, 20, 21, 22]) = NaN; y = x; y([1, 6, 10, 18, 20, 21]) = [2.5, 4.609523809523809, 8.5, 17.25, 21.390476190476186, 21.75]; assert_equal (fillmissing (x, 'makima', 2, 'samplepoints', [2, 4, 8, 10]), y, 1e-14); ***** assert_equal (fillmissing ([1, 2, 3], 'constant', 99, 'endvalues', 'spline'), [1, 2, 3]) ***** assert_equal (fillmissing ([1, NaN, 3], 'constant', 99, 'endvalues', 'spline'), [1, 99, 3]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN], 'constant', 99, 'endvalues', 'spline'), [1, 99, 3, 4]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'constant', 99, 'endvalues', 'spline'), [1, 2, 99, 4, 5]) ***** assert_equal (fillmissing ([NaN, 2, NaN, NaN], 'constant', 99, 'endvalues', 'spline'), [NaN, 2, NaN, NaN]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'constant', 99, 'endvalues', 'spline', 'samplepoints', [1, 2, 3, 4, 5]), [1, 2, 99, 4, 5]) ***** assert_equal (fillmissing ([NaN, 2, NaN, 4, NaN], 'constant', 99, 'endvalues', 'spline', 'samplepoints', [0, 2, 3, 4, 10]), [0, 2, 99, 4, 10]) ***** assert_equal (fillmissing ([1, 2, 3], 'movmean', 1), [1, 2, 3]) ***** assert_equal (fillmissing ([1, 2, NaN], 'movmean', 1), [1, 2, NaN]) ***** assert_equal (fillmissing ([1, 2, 3], 'movmean', 2), [1, 2, 3]) ***** assert_equal (fillmissing ([1, 2, 3], 'movmean', [1, 0]), [1, 2, 3]) ***** assert_equal (fillmissing ([1, 2, 3]', 'movmean', 2), [1, 2, 3]') ***** assert_equal (fillmissing ([1, 2, NaN], 'movmean', 2), [1, 2, 2]) ***** assert_equal (fillmissing ([1, 2, NaN], 'movmean', [1, 0]), [1, 2, 2]) ***** assert_equal (fillmissing ([1, 2, NaN], 'movmean', [1, 0]'), [1, 2, 2]) ***** assert_equal (fillmissing ([NaN, 2, NaN], 'movmean', 2), [NaN, 2, 2]) ***** assert_equal (fillmissing ([NaN, 2, NaN], 'movmean', [1, 0]), [NaN, 2, 2]) ***** assert_equal (fillmissing ([NaN, 2, NaN], 'movmean', [0, 1]), [2, 2, NaN]) ***** assert_equal (fillmissing ([NaN, 2, NaN], 'movmean', [0, 1.1]), [2, 2, NaN]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'movmean', [3, 0]), [1, 1, 3, 2, 5]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'movmean', 3, 1), [1, 2, 6; 4, 2, 6]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'movmean', 3, 2), [1, 2, 2; 4, 5, 6]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'movmean', 3, 3), [1, 2, NaN; 4, NaN, 6]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'movmean', 99), [1, 3, 3, 3, 5]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'movmean', 99, 1), [1, NaN, 3, NaN, 5]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5]', 'movmean', 99, 1), [1, 3, 3, 3, 5]') ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'movmean', 99, 2), [1, 3, 3, 3, 5]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5]', 'movmean', 99, 2), [1, NaN, 3, NaN, 5]') ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmean', 3, 'samplepoints', [1, 2, 3, 4, 5]), [1, 1, NaN, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmean', [1, 1], 'samplepoints', [1, 2, 3, 4, 5]), [1, 1, NaN, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmean', [1.5, 1.5], 'samplepoints', [1, 2, 3, 4, 5]), [1, 1, NaN, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmean', 4, 'samplepoints', [1, 2, 3, 4, 5]), [1, 1, 1, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmean', [2, 2], 'samplepoints', [1, 2, 3, 4, 5]), [1, 1, 3, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmean', 4.0001, 'samplepoints', [1, 2, 3, 4, 5]), [1, 1, 3, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmean', 3, 'samplepoints', [1.5, 2, 3, 4, 5]), [1, 1, 1, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmean', 3, 'samplepoints', [1 2, 3, 4, 4.5]), [1, 1, NaN, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmean', 3, 'samplepoints', [1.5, 2, 3, 4, 4.5]), [1, 1, 1, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmean', [1.5, 1.5], 'samplepoints', [1.5, 2, 3, 4, 5]), [1, 1, 1, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmean', [1.5, 1.5], 'samplepoints', [1, 2, 3, 4, 4.5]), [1, 1, 5, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmean', [1.5, 1.5], 'samplepoints', [1.5, 2 3, 4, 4.5]), [1, 1, 3, 5, 5]) ***** test x = reshape ([1:24], 3, 4, 2); x([1, 2, 5, 6, 8, 10, 13, 16, 18, 19, 20, 21, 22]) = NaN; y = x; y([2, 5, 8, 10, 13, 16, 18, 22]) = [3, 4, 8, 11, 14, 17, 17, 23]; assert_equal (fillmissing (x, 'movmean', 3), y); assert_equal (fillmissing (x, 'movmean', [1, 1]), y); assert_equal (fillmissing (x, 'movmean', 3, 'endvalues', 'extrap'), y); assert_equal (fillmissing (x, 'movmean', 3, 'samplepoints', [1, 2, 3]), y); y = x; y([1, 6, 8, 10, 18, 20, 21]) = [4, 6, 11, 7, 15, 20, 24]; assert_equal (fillmissing (x, 'movmean', 3, 2), y); assert_equal (fillmissing (x, 'movmean', [1, 1], 2), y); assert_equal (fillmissing (x, 'movmean', 3, 2, 'endvalues', 'extrap'), y); assert_equal (fillmissing (x, 'movmean', 3, 2, 'samplepoints', [1, 2, 3, 4]), y); y([1, 18]) = NaN; y(6) = 9; assert_equal (fillmissing (x, 'movmean', 3, 2, 'samplepoints', [0, 2, 3, 4]), y); y = x; y([1, 2, 5, 6, 10, 13, 16, 18, 19, 20, 21, 22]) = 99; y(8) = 8; assert_equal (fillmissing (x, 'movmean', 3, 'endvalues', 99), y); y = x; y([1, 2, 5, 8, 10, 13, 16, 19, 22]) = 99; y([6, 18, 20, 21]) = [6, 15, 20, 24]; assert_equal (fillmissing (x, 'movmean', 3, 2, 'endvalues', 99), y); ***** assert_equal (fillmissing ([1, 2, 3], 'movmedian', 1), [1, 2, 3]) ***** assert_equal (fillmissing ([1, 2, NaN], 'movmedian', 1), [1, 2, NaN]) ***** assert_equal (fillmissing ([1, 2, 3], 'movmedian', 2), [1, 2, 3]) ***** assert_equal (fillmissing ([1, 2, 3], 'movmedian', [1, 0]), [1, 2, 3]) ***** assert_equal (fillmissing ([1, 2, 3]', 'movmedian', 2), [1, 2, 3]') ***** assert_equal (fillmissing ([1, 2, NaN], 'movmedian', 2), [1, 2, 2]) ***** assert_equal (fillmissing ([1, 2, NaN], 'movmedian', [1, 0]), [1, 2, 2]) ***** assert_equal (fillmissing ([1, 2, NaN], 'movmedian', [1, 0]'), [1, 2, 2]) ***** assert_equal (fillmissing ([NaN, 2, NaN], 'movmedian', 2), [NaN, 2, 2]) ***** assert_equal (fillmissing ([NaN, 2, NaN], 'movmedian', [1, 0]), [NaN, 2, 2]) ***** assert_equal (fillmissing ([NaN, 2, NaN], 'movmedian', [0, 1]), [2, 2, NaN]) ***** assert_equal (fillmissing ([NaN, 2, NaN], 'movmedian', [0, 1.1]), [2, 2, NaN]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'movmedian', [3, 0]), [1, 1, 3, 2, 5]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'movmedian', 3, 1), [1, 2, 6; 4, 2, 6]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'movmedian', 3, 2), [1, 2, 2; 4, 5, 6]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], 'movmedian', 3, 3), [1, 2, NaN; 4, NaN, 6]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'movmedian', 99), [1, 3, 3, 3, 5]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'movmedian', 99, 1), [1, NaN, 3, NaN, 5]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5]', 'movmedian', 99, 1), [1, 3, 3, 3, 5]') ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'movmedian', 99, 2), [1, 3, 3, 3, 5]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5]', 'movmedian', 99, 2), [1, NaN, 3, NaN, 5]') ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmedian', 3, 'samplepoints', [1, 2, 3, 4, 5]), [1, 1, NaN, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmedian', [1, 1], 'samplepoints', [1, 2, 3, 4, 5]), [1, 1, NaN, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmedian', [1.5, 1.5], 'samplepoints', [1, 2, 3, 4, 5]), [1, 1, NaN, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmedian', 4, 'samplepoints', [1, 2, 3, 4, 5]), [1, 1, 1, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmedian', [2, 2], 'samplepoints', [1, 2, 3, 4, 5]), [1, 1, 3, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmedian', 4.0001, 'samplepoints', [1, 2, 3, 4, 5]), [1, 1, 3, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmedian', 3, 'samplepoints', [1.5 2 3 4 5]), [1, 1, 1, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmedian', 3, 'samplepoints', [1 2 3 4 4.5]), [1, 1, NaN, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmedian', 3, 'samplepoints', [1.5 2 3 4 4.5]), [1, 1, 1, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmedian', [1.5, 1.5], 'samplepoints', [1.5 2 3 4 5]), [1, 1, 1, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmedian', [1.5, 1.5], 'samplepoints', [1 2 3 4 4.5]), [1, 1, 5, 5, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], 'movmedian', [1.5, 1.5], 'samplepoints', [1.5 2 3 4 4.5]), [1, 1, 3, 5, 5]) ***** test x = reshape ([1:24], 3, 4, 2); x([1, 2, 5, 6, 8, 10, 13, 16, 18, 19, 20, 21, 22]) = NaN; y = x; y([2, 5, 8, 10, 13, 16, 18, 22]) = [3, 4, 8, 11, 14, 17, 17, 23]; assert_equal (fillmissing (x, 'movmedian', 3), y); assert_equal (fillmissing (x, 'movmedian', [1, 1]), y); assert_equal (fillmissing (x, 'movmedian', 3, 'endvalues', 'extrap'), y); assert_equal (fillmissing (x, 'movmedian', 3, 'samplepoints', [1, 2, 3]), y); y = x; y([1, 6, 8, 10, 18, 20, 21]) = [4, 6, 11, 7, 15, 20, 24]; assert_equal (fillmissing (x, 'movmedian', 3, 2), y); assert_equal (fillmissing (x, 'movmedian', [1, 1], 2), y); assert_equal (fillmissing (x, 'movmedian', 3, 2, 'endvalues', 'extrap'), y); assert_equal (fillmissing (x, 'movmedian', 3, 2, 'samplepoints', [1, 2, 3, 4]), y); y([1,18]) = NaN; y(6) = 9; assert_equal (fillmissing (x, 'movmedian', 3, 2, 'samplepoints', [0, 2, 3, 4]), y); y = x; y([1, 2, 5, 6, 10, 13, 16, 18, 19, 20, 21, 22]) = 99; y(8) = 8; assert_equal (fillmissing (x, 'movmedian', 3, 'endvalues', 99), y); y = x; y([1, 2, 5, 8, 10, 13, 16, 19, 22]) = 99; y([6, 18, 20, 21]) = [6, 15, 20, 24]; assert_equal (fillmissing (x, 'movmedian', 3, 2, 'endvalues', 99), y); ***** assert_equal (fillmissing ([1, 2, 3], @(x,y,z) x+y+z, 2), [1, 2, 3]) ***** error ... fillmissing ([1, 2, NaN], @(x,y,z) x+y+z, 1) ***** assert_equal (fillmissing ([1, 2, 3], @(x,y,z) x+y+z, 2), [1, 2, 3]) ***** assert_equal (fillmissing ([1, 2, 3], @(x,y,z) x+y+z, [1, 0]), [1, 2, 3]) ***** assert_equal (fillmissing ([1, 2, 3]', @(x,y,z) x+y+z, 2), [1, 2, 3]') ***** assert_equal (fillmissing ([1, 2, NaN], @(x,y,z) x+y+z, 2), [1, 2, 7]) ***** assert_equal (fillmissing ([1, 2, NaN], @(x,y,z) x+y+z, [1, 0]), [1, 2, 7]) ***** assert_equal (fillmissing ([1, 2, NaN], @(x,y,z) x+y+z, [1, 0]'), [1, 2, 7]) ***** assert_equal (fillmissing ([NaN, 2, NaN], @(x,y,z) x+y+z, 2), [5, 2, 7]) ***** error ... fillmissing ([NaN, 2, NaN], @(x,y,z) x+y+z, [1, 0]) ***** error ... fillmissing ([NaN, 2, NaN], @(x,y,z) x+y+z, [0, 1]) ***** error ... fillmissing ([NaN, 2, NaN], @(x,y,z) x+y+z, [0, 1.1]) ***** assert_equal (fillmissing ([1, 2, NaN, NaN, 3, 4], @(x,y,z) x+y+z, 2), [1, 2, 7, 12, 3, 4]) ***** error ... fillmissing ([1, 2, NaN, NaN, 3, 4], @(x,y,z) x+y+z, 0.5) ***** function A = testfcn (x, y, z) if (isempty (y)) A = z; elseif (numel (y) == 1) A = repelem (x(1), numel (z)); else A = interp1 (y, x, z, 'linear', 'extrap'); endif ***** endfunction ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], @testfcn, [3, 0]), [1, 1, 3, NaN, 5]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], @testfcn, 3, 1), [1, 2, 6; 4, 2, 6]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], @testfcn, 3, 2), [1, 2, 2; 4, 5, 6]) ***** assert_equal (fillmissing ([1, 2, NaN; 4, NaN, 6], @testfcn, 3, 3), [1, 2, NaN; 4, NaN, 6]) ##known not-compatible. matlab bug ML2022a: [1, 2, 1; 4, 1, 6] ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], @testfcn, 99), [1, 2, 3, 4, 5]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], @testfcn, 99, 1), [1, NaN, 3, NaN, 5]) ##known not-compatible. matlab bug ML2022a: [1, 1, 3, 1, 5] ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5]', @testfcn, 99, 1), [1, 2, 3, 4, 5]') ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], @testfcn, 99, 2), [1, 2, 3, 4, 5]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5]', @testfcn, 99, 2), [1, NaN, 3, NaN, 5]') ##known not-compatible. matlab bug ML2022a: [1, 1, 3, 1, 5]' ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], @testfcn, 99, 3), [1, NaN, 3, NaN, 5]) ##known not-compatible. matlab bug ML2022a: [1, 1, 3, 1, 5] ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5]', @testfcn, 99, 3), [1, NaN, 3, NaN, 5]') ##known not-compatible. matlab bug ML2022a: [1, 1, 3, 1, 5]' ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], @testfcn, 3, 'samplepoints', [1, 2, 3, 4, 5]), [1, 2, 3, 4, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], @testfcn, [1, 1], 'samplepoints', [1, 2, 3, 4, 5]), [1, 2, 3, 4, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], @testfcn, [1.5, 1.5], 'samplepoints', [1, 2, 3, 4, 5]), [1, 2, 3, 4, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], @testfcn, 4, 'samplepoints', [1, 2, 3, 4, 5]), [1, 2, 3, 4, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], @testfcn, [2, 2], 'samplepoints', [1, 2, 3, 4, 5]), [1, 2, 3, 4, 5]) ***** assert_equal (fillmissing ([1, NaN, NaN, NaN, 5], @testfcn, 3, 'samplepoints', [1, 2, 2.5, 3, 3.5]), [1, 2.6, 3.4, 4.2, 5], 10*eps) ***** assert_equal (fillmissing ([NaN, NaN, 3, NaN, 5], @testfcn, 99, 1), [NaN, NaN, 3, NaN, 5]) ##known not-compatible. matlab bug ML2022a: [1, 1, 3, 1, 5] ***** test ***** function A = testfcn (x, y, z) if (isempty (y)) A = z; elseif (numel (y) == 1) A = repelem (x(1), numel (z)); else A = interp1 (y, x, z, 'linear', 'extrap'); endif ***** endfunction x = reshape ([1:24], 3, 4, 2); x([1, 2, 5, 6, 8, 10, 13, 16, 18, 19, 20, 21, 22]) = NaN; y = x; y([1, 2, 5, 6, 8, 10, 13, 16, 18, 22]) = [3, 3, 4, 4, 8, 11, 14, 17, 17, 23]; assert_equal (fillmissing (x, @testfcn, 3), y); assert_equal (fillmissing (x, @testfcn, [1, 1]), y); assert_equal (fillmissing (x, @testfcn, 3, 'endvalues', 'extrap'), y); assert_equal (fillmissing (x, @testfcn, 3, 'samplepoints', [1, 2, 3]), y); y= x; y(isnan (x)) = 99; y(8) = 8; assert_equal (fillmissing (x, @testfcn, 3, 'endvalues', 99), y) y = x; y([1, 2, 5, 6, 8, 10, 18, 20, 21]) = [4, 11, 11, 6, 11, 7, 18, 20, 21]; assert_equal (fillmissing (x, @testfcn, 3, 2), y); assert_equal (fillmissing (x, @testfcn, [1, 1], 2), y); assert_equal (fillmissing (x, @testfcn, 3, 2, 'endvalues', 'extrap'), y); assert_equal (fillmissing (x, @testfcn, 3, 2, 'samplepoints', [1, 2, 3, 4]), y); y(1) = NaN; y([6, 18, 21]) = [9, 24, 24]; assert_equal (fillmissing (x, @testfcn, 3, 2, 'samplepoints', [0, 2, 3, 4]), y); y = x; y([1, 2, 5, 6, 10, 13, 16, 18, 19, 20, 21, 22]) = 99; y(8) = 8; assert_equal (fillmissing (x, @testfcn, 3, 'endvalues', 99), y); y([6, 18, 20, 21]) = [6, 18, 20, 21]; y(8) = 99; assert_equal (fillmissing (x, @testfcn, 3, 2, 'endvalues', 99), y); y([6, 18, 20, 21]) = 99; assert_equal (fillmissing (x, @testfcn, 3, 3, 'endvalues', 99), y); ***** assert_equal (fillmissing ([1, 2, 3], 'constant', 0, 'maxgap', 1), [1, 2, 3]) ***** assert_equal (fillmissing ([1, 2, 3], 'constant', 0, 'maxgap', 99), [1, 2, 3]) ***** assert_equal (fillmissing ([1, NaN, 3], 'constant', 0, 'maxgap', 1), [1, NaN, 3]) ***** assert_equal (fillmissing ([1, NaN, 3], 'constant', 0, 'maxgap', 1.999), [1, NaN, 3]) ***** assert_equal (fillmissing ([1, NaN, 3], 'constant', 0, 'maxgap', 2), [1, 0, 3]) ***** assert_equal (fillmissing ([1, NaN, NaN, 4], 'constant', 0, 'maxgap', 2), [1, NaN, NaN, 4]) ***** assert_equal (fillmissing ([1, NaN, NaN, 4], 'constant', 0, 'maxgap', 3), [1, 0, 0, 4]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'constant', 0, 'maxgap', 2), [1, 0, 3, 0, 5]) ***** assert_equal (fillmissing ([NaN, 2, NaN], 'constant', 0, 'maxgap', 0.999), [NaN, 2, NaN]) ***** assert_equal (fillmissing ([NaN, 2, NaN], 'constant', 0, 'maxgap', 1), [0, 2, 0]) ***** assert_equal (fillmissing ([NaN, 2, NaN, NaN], 'constant', 0, 'maxgap', 1), [0, 2, NaN, NaN]) ***** assert_equal (fillmissing ([NaN, 2, NaN, NaN], 'constant', 0, 'maxgap', 2), [0, 2, 0, 0]) ***** assert_equal (fillmissing ([NaN, NaN, NaN], 'constant', 0, 'maxgap', 1), [NaN, NaN, NaN]) ***** assert_equal (fillmissing ([NaN, NaN, NaN], 'constant', 0, 'maxgap', 3), [NaN, NaN, NaN]) ***** assert_equal (fillmissing ([NaN, NaN, NaN], 'constant', 0, 'maxgap', 999), [NaN, NaN, NaN]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'constant', 0, 'maxgap', 2, 'samplepoints', [0, 1, 2, 3, 5]), [1, 0, 3, NaN, 5]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5]', 'constant', 0, 'maxgap', 2, 'samplepoints', [0, 1, 2, 3, 5]), [1, 0, 3, NaN, 5]') ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'constant', 0, 'maxgap', 2, 'samplepoints', [0, 2, 3, 4, 5]), [1, NaN, 3, 0, 5]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5; 1, NaN, 3, NaN, 5], 'constant', 0, 2, 'maxgap', 2, 'samplepoints', [0, 2, 3, 4, 5]), [1, NaN, 3, 0, 5; 1, NaN, 3, 0, 5]) ***** test x = cat (3, [1, 2, NaN; 4, NaN, NaN], [NaN, 2, 3; 4, 5, NaN]); assert_equal (fillmissing (x, 'constant', 0, 'maxgap', 0.1), x); y = x; y([4, 7, 12]) = 0; assert_equal (fillmissing (x, 'constant', 0, 'maxgap', 1), y); assert_equal (fillmissing (x, 'constant', 0, 1, 'maxgap', 1), y); y = x; y([5, 7, 12]) = 0; assert_equal (fillmissing (x, 'constant', 0, 2, 'maxgap', 1), y); y = x; y([4, 5, 7]) = 0; assert_equal (fillmissing (x, 'constant', 0, 3, 'maxgap', 1), y); ***** test x = cat (3, [1, 2, NaN; 4, NaN, NaN], [NaN, 2, 3; 4, 5, NaN]); [~, idx] = fillmissing (x, 'constant', 0, 'maxgap', 1); assert_equal (idx, logical (cat (3, [0, 0, 0; 0, 1, 0], [1, 0, 0; 0, 0, 1]))); [~, idx] = fillmissing (x, 'constant', 0, 1, 'maxgap', 1); assert_equal (idx, logical (cat (3, [0, 0, 0; 0, 1, 0], [1, 0, 0; 0, 0, 1]))); [~, idx] = fillmissing (x, 'constant', 0, 2, 'maxgap', 1); assert_equal (idx, logical (cat (3, [0, 0, 1; 0, 0, 0], [1, 0, 0; 0, 0, 1]))); [~, idx] = fillmissing (x, 'constant', 0, 3, 'maxgap', 1); assert_equal (idx, logical (cat (3, [0, 0, 1; 0, 1, 0], [1, 0, 0; 0, 0, 0]))); ***** test x = [NaN, 2, 3]; [~, idx] = fillmissing (x, 'previous'); assert_equal (idx, logical ([0, 0, 0])); [~, idx] = fillmissing (x, 'movmean', 1); assert_equal (idx, logical ([0, 0, 0])); x = [1:3; 4:6; 7:9]; x([2, 4, 7, 9]) = NaN; [~, idx] = fillmissing (x, 'linear'); assert_equal (idx, logical ([0, 1, 0; 1, 0, 0; 0, 0, 0])); [~, idx] = fillmissing (x, 'movmean', 2); assert_equal (idx, logical ([0, 0, 0; 1, 0, 0; 0, 0, 1])); [A, idx] = fillmissing ([1, 2, 3, NaN, NaN], 'movmean',2); assert_equal (A, [1, 2, 3, 3, NaN]); assert_equal (idx, logical ([0, 0, 0, 1, 0])); [A, idx] = fillmissing ([1, 2, 3, NaN, NaN], 'movmean',3); assert_equal (A, [1, 2, 3, 3, NaN]); assert_equal (idx, logical ([0, 0, 0, 1, 0])); [A, idx] = fillmissing ([1, 2, NaN, NaN, NaN], 'movmedian', 2); assert_equal (A, [1, 2, 2, NaN, NaN]); assert_equal (idx, logical ([0, 0, 1, 0, 0])); [A, idx] = fillmissing ([1, 2, 3, NaN, NaN], 'movmedian', 3); assert_equal (A, [1, 2, 3, 3, NaN]); assert_equal (idx, logical ([0, 0, 0, 1, 0])); [A, idx] = fillmissing ([1, NaN, 1, NaN, 1], @(x,y,z) z, 3); assert_equal (A, [1, 2, 1, 4, 1]); assert_equal (idx, logical ([0, 1, 0, 1, 0])); [A, idx] = fillmissing ([1, NaN, 1, NaN, 1], @(x,y,z) NaN (size (z)), 3); assert_equal (A, [1, NaN, 1, NaN, 1]); assert_equal (idx, logical ([0, 0, 0, 0, 0])); ***** assert_equal (fillmissing ([1, 2, 3], 'constant', 99, 'missinglocations', logical ([0, 0, 0])), [1, 2, 3]) ***** assert_equal (fillmissing ([1, 2, 3], 'constant', 99, 'missinglocations', logical ([1, 1, 1])), [99, 99, 99]) ***** assert_equal (fillmissing ([1, NaN, 2, 3, NaN], 'constant', 99, 'missinglocations', logical ([1, 0, 1, 0, 1])), [99, NaN, 99, 3, 99]) ***** assert_equal (fillmissing ([1, NaN, 3, NaN, 5], 'constant', NaN, 'missinglocations', logical ([0, 1, 1, 1, 0])), [1, NaN, NaN, NaN, 5]) ***** assert_equal (fillmissing (['foo '; ' bar'], 'constant', 'X', 'missinglocations', logical ([0, 0, 0, 0; 0, 0, 0, 0])), ['foo '; ' bar']) ***** assert_equal (fillmissing (['foo '; ' bar'], 'constant', 'X', 'missinglocations', logical ([1, 0, 1, 0; 0, 1, 1, 0])), ['XoX '; ' XXr']) ***** assert_equal (fillmissing ({'foo', '', 'bar'}, 'constant', 'X', 'missinglocations', logical ([0, 0, 0])), {'foo', '', 'bar'}) ***** assert_equal (fillmissing ({'foo', '', 'bar'}, 'constant', 'X', 'missinglocations', logical ([1, 1, 0])), {'X', 'X', 'bar'}) ***** test [~, idx] = fillmissing ([1, NaN, 3, NaN, 5], 'constant', NaN); assert_equal (idx, logical ([0, 0, 0, 0, 0])); [~, idx] = fillmissing ([1 NaN 3 NaN 5], 'constant', NaN, 'missinglocations', logical ([0, 1, 1, 1, 0])); assert_equal (idx, logical ([0, 1, 1, 1, 0])); [A, idx] = fillmissing ([1, 2, NaN, 1, NaN], 'movmean', 3.1, 'missinglocations', logical ([0, 0, 1, 1, 0])); assert_equal (A, [1, 2, 2, NaN, NaN]); assert_equal (idx, logical ([0, 0, 1, 0, 0])); [A, idx] = fillmissing ([1, 2, NaN, NaN, NaN], 'movmean', 2, 'missinglocations', logical ([0, 0, 1, 1, 0])); assert_equal (A, [1, 2, 2, NaN, NaN]); assert_equal (idx, logical ([0, 0, 1, 0, 0])); [A, idx] = fillmissing ([1, 2, NaN, 1, NaN], 'movmean', 3, 'missinglocations', logical ([0, 0, 1, 1, 0])); assert_equal (A, [1, 2, 2, NaN, NaN]); assert_equal (idx, logical ([0, 0, 1, 0, 0])); [A, idx] = fillmissing ([1, 2, NaN, NaN, NaN], 'movmean', 3, 'missinglocations', logical ([0, 0, 1, 1, 0])); assert_equal (A, [1, 2, 2, NaN, NaN]); assert_equal (idx, logical ([0, 0, 1, 0, 0])); [A, idx] = fillmissing ([1, 2, NaN, NaN, NaN], 'movmedian', 2, 'missinglocations', logical ([0, 0, 1, 1, 0])); assert_equal (A, [1, 2, 2, NaN, NaN]); assert_equal (idx, logical ([0, 0, 1, 0, 0])); [A, idx] = fillmissing ([1, 2, NaN, NaN, NaN], 'movmedian', 3, 'missinglocations', logical ([0, 0, 1, 1, 0])); assert_equal (A, [1, 2, 2, NaN, NaN]); assert_equal (idx, logical ([0, 0, 1, 0, 0])); [A, idx] = fillmissing ([1, 2, NaN, NaN, NaN], 'movmedian', 3.1, 'missinglocations', logical ([0, 0, 1, 1, 0])); assert_equal (A, [1, 2, 2, NaN, NaN]); assert_equal (idx, logical ([0, 0, 1, 0, 0])); [A, idx] = fillmissing ([1, NaN, 1, NaN, 1], @(x,y,z) ones (size (z)), 3, 'missinglocations', logical ([0, 1, 0, 1, 1])); assert_equal (A, [1, 1, 1, 1, 1]); assert_equal (idx, logical ([0, 1, 0, 1, 1])); [A, idx] = fillmissing ([1, NaN, 1, NaN, 1], @(x,y,z) NaN (size (z)), 3, 'missinglocations', logical ([0, 1, 0, 1, 1])); assert_equal (A, [1, NaN, 1, NaN, NaN]); assert_equal (idx, logical ([0, 0, 0, 0, 0])); ***** test [A, idx] = fillmissing ([1, 2, 5], 'movmedian', 3, 'missinglocations', logical ([0, 1, 0])); assert_equal (A, [1, 3, 5]); assert_equal (idx, logical ([0, 1, 0])); ***** assert_equal (fillmissing (' foo bar ', 'constant', 'X', 'missinglocations', logical ([1, 0, 0, 0, 1, 0, 0, 0, 1])), 'XfooXbarX') ***** assert_equal (fillmissing ([' foo'; 'bar '], 'constant', 'X', 'missinglocations', logical ([1, 0, 0, 0; 0, 0, 0, 1])), ['Xfoo'; 'barX']) ***** assert_equal (fillmissing ([' foo'; 'bar '], 'next', 'missinglocations', logical ([1, 0, 0, 0; 0, 0, 0, 1])), ['bfoo'; 'bar ']) ***** assert_equal (fillmissing ([' foo'; 'bar '], 'next', 1, 'missinglocations', logical ([1, 0, 0, 0; 0, 0, 0, 1])), ['bfoo'; 'bar ']) ***** assert_equal (fillmissing ([' foo'; 'bar '], 'previous', 'missinglocations', logical ([1, 0, 0, 0; 0, 0, 0, 1])), [' foo'; 'baro']) ***** assert_equal (fillmissing ([' foo'; 'bar '], 'previous', 1, 'missinglocations', logical ([1, 0, 0, 0; 0, 0, 0, 1])), [' foo'; 'baro']) ***** assert_equal (fillmissing ([' foo'; 'bar '], 'nearest', 'missinglocations', logical ([1, 0, 0, 0; 0, 0, 0, 1])), ['bfoo'; 'baro']) ***** assert_equal (fillmissing ([' foo'; 'bar '], 'nearest', 1, 'missinglocations', logical ([1, 0, 0, 0; 0, 0, 0, 1])), ['bfoo'; 'baro']) ***** assert_equal (fillmissing ([' foo'; 'bar '], 'next', 2, 'missinglocations', logical ([1, 0, 0, 0; 0, 0, 0, 1])), ['ffoo'; 'bar ']) ***** assert_equal (fillmissing ([' foo'; 'bar '], 'previous', 2, 'missinglocations', logical ([1, 0, 0, 0; 0, 0, 0, 1])), [' foo'; 'barr']) ***** assert_equal (fillmissing ([' foo'; 'bar '], 'nearest', 2, 'missinglocations', logical ([1, 0, 0, 0; 0, 0, 0, 1])), ['ffoo'; 'barr']) ***** assert_equal (fillmissing ([' foo'; 'bar '], 'next', 3, 'missinglocations', logical ([1, 0, 0, 0; 0, 0, 0, 1])), [' foo'; 'bar ']) ***** assert_equal (fillmissing ([' foo'; 'bar '], 'previous', 3, 'missinglocations', logical ([1, 0, 0, 0; 0, 0, 0, 1])), [' foo'; 'bar ']) ***** assert_equal (fillmissing ([' foo'; 'bar '], 'nearest', 3, 'missinglocations', logical ([1, 0, 0, 0; 0, 0, 0, 1])), [' foo'; 'bar ']) ***** assert_equal (fillmissing ({'foo', 'bar'}, 'constant', 'a'), {'foo', 'bar'}) ***** assert_equal (fillmissing ({'foo', 'bar'}, 'constant', {'a'}), {'foo', 'bar'}) ***** assert_equal (fillmissing ({'foo', '', 'bar'}, 'constant', 'a'), {'foo', 'a', 'bar'}) ***** assert_equal (fillmissing ({'foo', '', 'bar'}, 'constant', {'a'}), {'foo', 'a', 'bar'}) ***** assert_equal (fillmissing ({'foo', '', 'bar'}, 'previous'), {'foo', 'foo', 'bar'}) ***** assert_equal (fillmissing ({'foo', '', 'bar'}, 'next'), {'foo', 'bar', 'bar'}) ***** assert_equal (fillmissing ({'foo', '', 'bar'}, 'nearest'), {'foo', 'bar', 'bar'}) ***** assert_equal (fillmissing ({'foo', '', 'bar'}, 'previous', 2), {'foo', 'foo', 'bar'}) ***** assert_equal (fillmissing ({'foo', '', 'bar'}, 'next', 2), {'foo', 'bar', 'bar'}) ***** assert_equal (fillmissing ({'foo', '', 'bar'}, 'nearest', 2), {'foo', 'bar', 'bar'}) ***** assert_equal (fillmissing ({'foo', '', 'bar'}, 'previous', 1), {'foo', '', 'bar'}) ***** assert_equal (fillmissing ({'foo', '', 'bar'}, 'previous', 1), {'foo', '', 'bar'}) ***** assert_equal (fillmissing ({'foo', '', 'bar'}, 'next', 1), {'foo', '', 'bar'}) ***** assert_equal (fillmissing ({'foo', '', 'bar'}, 'nearest', 1), {'foo', '', 'bar'}) ***** assert_equal (fillmissing ('abc ', @(x,y,z) x+y+z, 2, 'missinglocations', logical ([0, 0, 0, 1])), 'abcj') ***** assert_equal (fillmissing ({'foo', '', 'bar'}, @(x,y,z) x(1), 3), {'foo', 'foo', 'bar'}) ***** test [A, idx] = fillmissing (' a b c', 'constant', ' ', 'missinglocations', logical ([1, 0, 1, 0, 1, 0])); assert_equal (A, ' a b c'); assert_equal (idx, logical ([1, 0, 1, 0, 1, 0])); ***** test [A, idx] = fillmissing (' a b c', 'constant', ' '); assert_equal (A, ' a b c'); assert_equal (idx, logical ([0, 0, 0, 0, 0, 0])); ***** test [A, idx] = fillmissing ({'foo', '', 'bar', ''}, 'constant', ''); assert_equal (A, {'foo', '', 'bar', ''}); assert_equal (idx, logical ([0, 0, 0, 0])); ***** test [A, idx] = fillmissing ({'foo', '', 'bar', ''}, 'constant', {''}); assert_equal (A, {'foo', '', 'bar', ''}); assert_equal (idx, logical ([0, 0, 0, 0])); ***** test [A, idx] = fillmissing (' f o o ', @(x,y,z) repelem ('a', numel (z)), 3, 'missinglocations', logical ([1, 0, 1, 0, 1, 0, 1])); assert_equal (A, 'afaoaoa'); assert_equal (idx, logical ([1, 0, 1, 0, 1, 0, 1])); ***** test [A, idx] = fillmissing (' f o o ', @(x,y,z) repelem (' ', numel (z)), 3); assert_equal (A, ' f o o '); assert_equal (idx, logical ([0, 0, 0, 0, 0, 0, 0])); ***** test [A, idx] = fillmissing ({'', 'foo', ''}, @(x,y,z) repelem ({'a'}, numel (z)), 3); assert_equal (A, {'a', 'foo', 'a'}); assert_equal (idx, logical ([1, 0, 1])); ***** test [A, idx] = fillmissing ({'', 'foo', ''}, @(x,y,z) repelem ({''}, numel (z)), 3); assert_equal (A, {'', 'foo', ''}); assert_equal (idx, logical ([0, 0, 0])); ***** assert_equal (fillmissing (logical ([1, 0, 1, 0, 1]), 'constant', true), logical ([1, 0, 1, 0, 1])) ***** assert_equal (fillmissing (logical ([1, 0, 1, 0, 1]), 'constant', false, 'missinglocations', logical ([1, 0, 1, 0, 1])), logical ([0, 0, 0, 0, 0])) ***** assert_equal (fillmissing (logical ([1, 0, 1, 0, 1]), 'previous', 'missinglocations', logical ([1, 0, 1, 0, 1])), logical ([1, 0, 0, 0, 0])) ***** assert_equal (fillmissing (logical ([1, 0, 1, 0, 1]), 'next', 'missinglocations', logical ([1, 0, 1, 0, 1])), logical ([0, 0, 0, 0, 1])) ***** assert_equal (fillmissing (logical ([1, 0, 1, 0, 1]), 'nearest', 'missinglocations', logical ([1, 0, 1, 0, 1])), logical ([0, 0, 0, 0, 0])) ***** assert_equal (fillmissing (logical ([1, 0, 1, 0, 1]), @(x,y,z) false (size (z)), 3), logical ([1, 0, 1, 0, 1])) ***** assert_equal (fillmissing (logical ([1, 0, 1, 0, 1]), @(x,y,z) false (size (z)), 3, 'missinglocations', logical ([1, 0, 1, 0, 1])), logical ([0, 0, 0, 0, 0])) ***** assert_equal (fillmissing (logical ([1, 0, 1, 0, 1]), @(x,y,z) false (size (z)), [2, 0], 'missinglocations', logical ([1, 0, 1, 0, 1])), logical ([0, 0, 0, 0, 0])) ***** test x = logical ([1, 0, 1, 0, 1]); [~, idx] = fillmissing (x, 'constant', true); assert_equal (idx, logical ([0, 0, 0, 0, 0])); [~, idx] = fillmissing (x, 'constant', false, 'missinglocations', logical ([1, 0, 1, 0, 1])); assert_equal (idx, logical ([1, 0, 1, 0, 1])); [~, idx] = fillmissing (x, 'constant', true, 'missinglocations', logical ([1, 0, 1, 0, 1])); assert_equal (idx, logical ([1, 0, 1, 0, 1])); [~, idx] = fillmissing (x, 'previous', 'missinglocations', logical ([1, 0, 1, 0, 1])); assert_equal (idx, logical ([0, 0, 1, 0, 1])); [~, idx] = fillmissing (x, 'next', 'missinglocations', logical ([1, 0, 1, 0, 1])); assert_equal (idx, logical ([1, 0, 1, 0, 0])); [~, idx] = fillmissing (x, 'nearest', 'missinglocations', logical ([1, 0, 1, 0, 1])); assert_equal (idx, logical ([1, 0, 1, 0, 1])); [~, idx] = fillmissing (x, @(x,y,z) false (size (z)), 3); assert_equal (idx, logical ([0, 0, 0, 0, 0])) [~, idx] = fillmissing (x, @(x,y,z) false (size (z)), 3, 'missinglocations', logical ([1, 0, 1, 0, 1])); assert_equal (idx, logical ([1, 0, 1, 0, 1])) [~, idx] = fillmissing (x, @(x,y,z) false (size (z)), [2 0], 'missinglocations', logical ([1, 0, 1, 0, 1])); assert_equal (idx, logical ([1, 0, 1, 0, 1])) ***** assert_equal (fillmissing (int32 ([1, 2, 3, 4, 5]), 'constant', 0), int32 ([1, 2, 3, 4, 5])) ***** assert_equal (fillmissing (int32 ([1, 2, 3, 4, 5]), 'constant', 0, 'missinglocations', logical ([1, 0, 1, 0, 1])), int32 ([0, 2, 0, 4, 0])) ***** assert_equal (fillmissing (int32 ([1, 2, 3, 4, 5]), 'previous', 'missinglocations', logical ([1, 0, 1, 0, 1])), int32 ([1, 2, 2, 4, 4])) ***** assert_equal (fillmissing (int32 ([1, 2, 3, 4, 5]), 'next', 'missinglocations', logical ([1, 0, 1, 0, 1])), int32 ([2, 2, 4, 4, 5])) ***** assert_equal (fillmissing (int32 ([1, 2, 3, 4, 5]), 'nearest', 'missinglocations', logical ([1, 0, 1, 0, 1])), int32 ([2, 2, 4, 4, 4])) ***** assert_equal (fillmissing (int32 ([1, 2, 3, 4, 5]), @(x,y,z) z+10, 3), int32 ([1, 2, 3, 4, 5])) ***** assert_equal (fillmissing (int32 ([1, 2, 3, 4, 5]), @(x,y,z) z+10, 3, 'missinglocations', logical ([1, 0, 1, 0, 1])), int32 ([11, 2, 13, 4, 15])) ***** assert_equal (fillmissing (int32 ([1, 2, 3, 4, 5]), @(x,y,z) z+10, [2, 0], 'missinglocations', logical ([1, 0, 1, 0, 1])), int32 ([11, 2, 13, 4, 15])) ***** assert_equal (fillmissing (int32 ([1, 2, 3, 4, 5]), @(x,y,z) z+10, [0, 2], 'missinglocations', logical ([1, 0, 1, 0, 1])), int32 ([11, 2, 13, 4, 15])) ***** assert_equal (fillmissing ([1, 2, 3, 4, 5], @(x,y,z) numel (x), [2, 0], 'missinglocations', logical ([1, 0, 1, 0, 1])), [0, 2, 2, 4, 2]) ***** assert_equal (fillmissing ([1, 2, 3, 4, 5], @(x,y,z) numel (x), [0, 2], 'missinglocations', logical ([1, 0, 1, 0, 1])), [2, 2, 2, 4, 0]) ***** test x = int32 ([1, 2, 3, 4, 5]); [~, idx] = fillmissing (x, 'constant', 0); assert_equal (idx, logical ([0, 0, 0, 0, 0])); [~, idx] = fillmissing (x, 'constant', 0, 'missinglocations', logical ([1, 0, 1, 0, 1])); assert_equal (idx, logical ([1, 0, 1, 0, 1])); [~, idx] = fillmissing (x, 'constant', 3, 'missinglocations', logical ([0, 0, 1, 0, 0])); assert_equal (idx, logical ([0, 0, 1, 0, 0])); [~, idx] = fillmissing (x, 'previous', 'missinglocations', logical ([1, 0, 1, 0, 1])); assert_equal (idx, logical ([0, 0, 1, 0, 1])); [~, idx] = fillmissing (x, 'next', 'missinglocations', logical ([1, 0, 1, 0, 1])); assert_equal (idx, logical ([1, 0, 1, 0, 0])); [~, idx] = fillmissing (x, 'nearest', 'missinglocations', logical ([1, 0, 1, 0, 1])); assert_equal (idx, logical ([1, 0, 1, 0, 1])); [~, idx] = fillmissing (x, @(x,y,z) z+10, 3); assert_equal (idx, logical ([0, 0, 0, 0, 0])); [~, idx] = fillmissing (x, @(x,y,z) z+10, 3, 'missinglocations', logical ([1, 0, 1, 0, 1])); assert_equal (idx, logical ([1, 0, 1, 0, 1])); [~, idx] = fillmissing (x, @(x,y,z) z+10, [2 0], 'missinglocations', logical ([1, 0, 1, 0, 1])); assert_equal (idx, logical ([1, 0, 1, 0, 1])); ***** test [A, idx] = fillmissing ([struct, struct], 'constant', 1); assert_equal (A, [struct, struct]) assert_equal (idx, [false, false]) ***** error fillmissing () ***** error fillmissing (1) ***** error fillmissing (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13) ***** error fillmissing (1, 2) ***** error fillmissing (1, 'foo') ***** error fillmissing (1, @(x) x, 1) ***** error fillmissing (1, @(x,y) x+y, 1) ***** error fillmissing ('a b c', 'linear') ***** error fillmissing ({'a', 'b'}, 'linear') ***** error <'movmean' and 'movmedian' methods only valid for numeric> fillmissing ('a b c', 'movmean', 2) ***** error <'movmean' and 'movmedian' methods only valid for numeric> fillmissing ({'a', 'b'}, 'movmean', 2) ***** error <'constant' method must be followed by> fillmissing (1, 'constant') ***** error fillmissing (1, 'constant', []) ***** error fillmissing (1, 'constant', 'a') ***** error fillmissing ('a', 'constant', 1) ***** error fillmissing ('a', 'constant', {'foo'}) ***** error fillmissing ({'foo'}, 'constant', 1) ***** error fillmissing (1, 'movmean') ***** error fillmissing (1, 'movmedian') ***** error fillmissing (1, 'constant', 1, 0) ***** error fillmissing (1, 'constant', 1, -1) ***** error fillmissing (1, 'constant', 1, [1, 2]) ***** error fillmissing (1, 'constant', 1, 'samplepoints') ***** error fillmissing (1, 'constant', 1, 'foo') ***** error fillmissing (1, 'constant', 1, 1, 'foo') ***** error fillmissing (1, 'constant', 1, 2, {1}, 4) ***** error fillmissing ([1, 2, 3], 'constant', 1, 2, 'samplepoints', [1, 2]) ***** error fillmissing ([1, 2, 3], 'constant', 1, 2, 'samplepoints', [3, 1, 2]) ***** error fillmissing ([1, 2, 3], 'constant', 1, 2, 'samplepoints', [1, 1, 2]) ***** error fillmissing ([1, 2, 3], 'constant', 1, 2, 'samplepoints', 'abc') ***** error fillmissing ([1, 2, 3], 'constant', 1, 2, 'samplepoints', logical ([1, 1, 1])) ***** error fillmissing ([1, 2, 3], 'constant', 1, 1, 'samplepoints', [1, 2, 3]) ***** error fillmissing ('foo', 'next', 'endvalues', 1) ***** error fillmissing (1, 'constant', 1, 1, 'endvalues', 'foo') ***** error fillmissing ([1, 2, 3], 'constant', 1, 2, 'endvalues', [1, 2, 3]) ***** error fillmissing ([1, 2, 3], 'constant', 1, 1, 'endvalues', [1, 2]) ***** error fillmissing (randi (5,4,3,2), 'constant', 1, 3, 'endvalues', [1, 2]) ***** error fillmissing (1, 'constant', 1, 1, 'endvalues', {1}) ***** error fillmissing (1, 'constant', 1, 2, 'foo', 4) ***** error fillmissing (struct, 'constant', 1, 'missinglocations', false) ***** error fillmissing (1, 'constant', 1, 2, 'maxgap', 1, 'missinglocations', false) ***** error fillmissing (1, 'constant', 1, 2, 'missinglocations', false, 'maxgap', 1) ***** error fillmissing (1, 'constant', 1, 'replacevalues', true) ***** error fillmissing (1, 'constant', 1, 'datavariables', 'Varname') ***** error fillmissing (1, 'constant', 1, 2, 'missinglocations', 1) ***** error fillmissing (1, 'constant', 1, 2, 'missinglocations', 'a') ***** error fillmissing (1, 'constant', 1, 2, 'missinglocations', [true, false]) ***** error fillmissing (true, 'linear', 'missinglocations', true) ***** error fillmissing (int8 (1), 'linear', 'missinglocations', true) ***** error fillmissing (true, 'next', 'missinglocations', true, 'EndValues', 'linear') ***** error fillmissing (true, 'next', 'EndValues', 'linear', 'missinglocations', true) ***** error fillmissing (int8 (1), 'next', 'missinglocations', true, 'EndValues', 'linear') ***** error fillmissing (int8 (1), 'next', 'EndValues', 'linear', 'missinglocations', true) ***** error fillmissing (1, 'constant', 1, 2, 'maxgap', true) ***** error fillmissing (1, 'constant', 1, 2, 'maxgap', 'a') ***** error fillmissing (1, 'constant', 1, 2, 'maxgap', [1, 2]) ***** error fillmissing (1, 'constant', 1, 2, 'maxgap', 0) ***** error fillmissing (1, 'constant', 1, 2, 'maxgap', -1) ***** error fillmissing ([1, 2, 3], 'constant', [1, 2, 3]) ***** error fillmissing ([1, 2, 3]', 'constant', [1, 2, 3]) ***** error fillmissing ([1, 2, 3]', 'constant', [1, 2, 3], 1) ***** error fillmissing ([1, 2, 3], 'constant', [1, 2, 3], 2) ***** error fillmissing (randi (5, 4, 3, 2), 'constant', [1, 2], 1) ***** error fillmissing (randi (5, 4, 3, 2), 'constant', [1, 2], 2) ***** error fillmissing (randi (5, 4, 3, 2), 'constant', [1, 2], 3) ***** error fillmissing (1, @(x,y,z) x+y+z) ***** error fillmissing ([1, NaN, 2], @(x,y,z) [1, 2], 2) 390 tests, 390 passed, 0 known failure, 0 skipped [inst/Data_Manipulation/ismissing.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Data_Manipulation/ismissing.m ***** assert_equal (ismissing ([1, NaN, 3]), [false, true, false]) ***** assert_equal (ismissing ('abcd f'), [false, false, false, false, false, false]) ***** assert_equal (ismissing ({'xxx', '', 'xyz'}), [false, true, false]) ***** assert_equal (ismissing ({'x', '', 'y'}), [false, true, false]) ***** assert_equal (ismissing ({'x', '', 'y'; 'z', 'a', ''}), logical ([0, 1, 0; 0, 0, 1])) ***** assert_equal (ismissing ([1, 2; NaN, 2]), [false, false; true, false]) ***** assert_equal (ismissing ([1, 2; NaN, 2], 2), [false, true; false, true]) ***** assert_equal (ismissing ([1, 2; NaN, 2], [1, 2]), [true, true; false, true]) ***** assert_equal (ismissing ([1, 2; NaN, 2], NaN), [false, false; true, false]) ***** assert_equal (ismissing (cat (3, magic (2), magic (2))), logical (zeros (2, 2, 2))) ***** assert_equal (ismissing (cat (3, magic (2), [1, 2; 3, NaN])), ... logical (cat (3, [0, 0; 0, 0], [0, 0; 0, 1]))) ***** assert_equal (ismissing ([1, 2; 3, 4], [5, 1; 2, 0]), logical ([1, 1; 0, 0])) ***** assert_equal (ismissing (cat (3, 'f oo', 'ba r')), ... logical (cat (3, [0, 0, 0, 0], [0, 0, 0, 0]))) ***** assert_equal (ismissing (cat (3, {'foo'}, {''}, {'bar'})), logical (cat (3, 0, 1, 0))) ***** assert_equal (ismissing (double (NaN)), true) ***** assert_equal (ismissing (single (NaN)), true) ***** assert_equal (ismissing (' '), false) ***** assert_equal (ismissing ({''}), true) ***** assert_equal (ismissing ({' '}), false) ***** assert_equal (ismissing (double (eye (3)), single (1)), logical (eye (3))) ***** assert_equal (ismissing (double (eye (3)), int32 (1)), logical (eye (3))) ***** assert_equal (ismissing (single (eye (3)), double (1)), logical (eye (3))) ***** assert_equal (ismissing (single (eye (3)), int32 (1)), logical (eye (3))) ***** assert_equal (ismissing ({'123', '', 123}), [false, false, false]) ***** assert_equal (ismissing (logical ([1, 0, 1])), [false, false, false]) ***** assert_equal (ismissing (int32 ([1, 2, 3])), [false, false, false]) ***** assert_equal (ismissing (uint32 ([1, 2, 3])), [false, false, false]) ***** assert_equal (ismissing ({1, 2, 3}), [false, false, false]) ***** assert_equal (ismissing ([struct struct struct]), [false, false, false]) ***** assert_equal (ismissing (logical (eye (3)), true), logical (eye (3))) ***** assert_equal (ismissing (logical (eye (3)), double (1)), logical (eye (3))) ***** assert_equal (ismissing (logical (eye (3)), single (1)), logical (eye (3))) ***** assert_equal (ismissing (logical (eye (3)), int32 (1)), logical (eye (3))) ***** assert_equal (ismissing (int32 (eye (3)), int32 (1)), logical (eye (3))) ***** assert_equal (ismissing (int32 (eye (3)), double (1)), logical (eye (3))) ***** assert_equal (ismissing (int32 (eye (3)), single (1)), logical (eye (3))) ***** assert_equal (ismissing ([]), logical ([])) ***** assert_equal (ismissing (''), logical ([])) ***** assert_equal (ismissing (ones (0,1)), logical (ones (0,1))) ***** assert_equal (ismissing (ones (1,0)), logical (ones (1,0))) ***** assert_equal (ismissing (ones (1,2,0)), logical (ones (1,2,0))) ***** assert_equal (ismissing ([1, NaN, 0, 2]), [false, true, false, false]) ***** assert_equal (ismissing ([1, NaN, 0, 2], [0, 1]), [true, false, true, false]) ***** assert_equal (ismissing ([1, NaN, 0, 2], [0, NaN]), [false, true, true, false]) ***** assert_equal (ismissing ([true, false, true]), [false, false, false]) ***** assert_equal (ismissing ([true, false, true], 1), [true, false, true]) ***** assert_equal (ismissing ([true, false, true], 0), [false, true, false]) ***** assert_equal (ismissing ({'', 'a', 'f'}), [true, false, false]) ***** assert_equal (ismissing ({'', 'a', 'f'}, 'a'), [false, true, false]) ***** assert_equal (ismissing ({'', 'a', 'f'}, {'a', 'g'}), [false, true, false]) ***** assert_equal (ismissing ({'', 'a', 'f'}, {'a', 'f'}), [false, true, true]) ***** error ismissing () ***** error ismissing (1, 2, 3) ***** error ... ismissing ([1, 2; 3, 4], 'abc') ***** error ... ismissing ({'', '', ''}, 1) ***** error ... ismissing (1, struct) ***** error ... ismissing (struct, 1) ***** error ... ismissing ({1, 2, 3}, 2) 58 tests, 58 passed, 0 known failure, 0 skipped [inst/Data_Manipulation/dummyvar.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Data_Manipulation/dummyvar.m ***** assert_equal (dummyvar ([]), []) ***** assert_equal (dummyvar (ones (2, 0)), ones (2, 0)) ***** assert_equal (dummyvar (zeros (0, 3)), zeros (0, 0)) ***** assert_equal (dummyvar ({[], []}), []) ***** assert_equal (dummyvar ([1; NaN; 2]), [1, 0; NaN, NaN; 0, 1]) ***** test ## numeric grouping vector g = [1; 2; 1; 3; 2]; D = dummyvar (g); assert_equal (D, [1, 0, 0; 0, 1, 0; 1, 0, 0; 0, 0, 1; 0, 1, 0]); ***** test g = categorical ({'a'; 'b'; 'a'}, {'a', 'b', 'c'}); D = dummyvar (g); cats = categories (g); g_str = cellstr (g); for k = 1:numel (cats) mask = strcmp (g_str, cats{k}); assert_equal (all (D(mask, k) == 1), true); assert_equal (all (D(! mask, k) == 0), true); endfor ***** test g = categorical ({'a'; ''; 'b'}, {'a', 'b', 'c'}); D = dummyvar (g); assert_equal (D, [1, 0, 0; NaN, NaN, NaN; 0, 1, 0]); ***** test colors = categorical ({'Red'; 'Blue'; 'Green'; 'Red'; 'Green'; 'Blue'}); D = dummyvar (colors); assert_equal (D, [0, 0, 1; 1, 0, 0; 0, 1, 0; 0, 0, 1; 0, 1, 0; 1, 0, 0]); ***** test g1 = [1; 1; 1; 1; 2; 2; 2; 2]; g2 = [1; 2; 3; 1; 2; 3; 1; 2]; D = dummyvar ([g1, g2]); D1 = [1, 0, 1, 0, 0; 1, 0, 0, 1, 0; 1, 0, 0, 0, 1; 1, 0, 1, 0, 0; ... 0, 1, 0, 1, 0; 0, 1, 0, 0, 1; 0, 1, 1, 0, 0; 0, 1, 0, 1, 0]; assert_equal (D, D1); ***** test phone = {'mob'; 'land'; 'mob';'mob';'mob';'land';'land'}; codes = categorical ([202; 202; 103; 103; 202; 103; 202]); D = dummyvar ({phone, codes}); D1 = [1, 0, 0, 1; 0, 1, 0, 1; 1, 0, 1, 0; 1, 0, 1, 0; ... 1, 0, 0, 1; 0, 1, 1, 0; 0, 1, 0, 1]; assert_equal (D, D1); ***** test colors = {'red'; 'blue'; 'red'; 'green'; 'yellow'; 'blue'}; D = dummyvar (categorical (colors)); D1 = [0, 0, 1, 0; 1, 0, 0, 0; 0, 0, 1, 0; 0, 1, 0, 0; 0, 0, 0, 1; 1, 0, 0, 0]; assert_equal (D, D1); ***** test colors = {'red'; 'blue'; 'red'; 'green'; 'yellow'; 'blue'}; D = dummyvar (colors); D1 = [1, 0, 0, 0; 0, 1, 0, 0; 1, 0, 0, 0; 0, 0, 1, 0; 0, 0, 0, 1; 0, 1, 0, 0]; assert_equal (D, D1); D = dummyvar ({colors}); D1 = [1, 0, 0, 0; 0, 1, 0, 0; 1, 0, 0, 0; 0, 0, 1, 0; 0, 0, 0, 1; 0, 1, 0, 0]; assert_equal (D, D1); ***** test g = [1, 2, 1, 2, 1, 3, 2, 1]; D = dummyvar (g); D1 = [1, 0, 0; 0, 1, 0; 1, 0, 0; 0, 1, 0; 1, 0, 0; 0, 0, 1; 0, 1, 0; 1, 0, 0]; assert_equal (D, D1); ***** test g = [1; 2; NaN; 3; 2]; D = dummyvar (g); assert_equal (D, [1, 0, 0; 0, 1, 0; NaN, NaN, NaN; 0, 0, 1; 0, 1, 0]); ***** test g = [1, 1; 2, NaN; 1, 2; 2, 1]; D = dummyvar (g); assert_equal (D, [1, 0, 1, 0; 0, 1, NaN, NaN; 1, 0, 0, 1; 0, 1, 1, 0]); ***** test D = dummyvar ([1, NaN; 2, NaN]); assert_equal (D, [1, 0; 0, 1]); warning: dummyvar: the following columns of GROUP contain all NaNs and produce no dummy variables: 2. warning: called from dummyvar at line 131 column 7 __test__ at line 3 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 2246 column 2 ***** test D = dummyvar ([1, NaN, 2; 2, NaN, 1]); assert_equal (D, [1, 0, 0, 1; 0, 1, 1, 0]); warning: dummyvar: the following columns of GROUP contain all NaNs and produce no dummy variables: 2. warning: called from dummyvar at line 131 column 7 __test__ at line 3 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 2246 column 2 ***** test D = dummyvar ([NaN; NaN]); assert_equal (size (D), [2, 0]); warning: dummyvar: the following columns of GROUP contain all NaNs and produce no dummy variables: 1. warning: called from dummyvar at line 131 column 7 __test__ at line 3 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 2246 column 2 ***** warning ... dummyvar ([1, NaN; 2, NaN]); ***** warning ... dummyvar ([NaN, NaN, NaN; NaN, NaN, NaN]); ***** error dummyvar () ***** error dummyvar (1, 2) ***** error ... dummyvar (categorical ({'a', 'b'})) ***** error ... dummyvar (ones (3, 3, 3)) ***** error ... dummyvar ([2, 4, 0, 8, 1]) ***** error ... dummyvar ([1; 1.5; 2]) ***** error ... dummyvar ([1; Inf; 2]) ***** error ... dummyvar ([1; -Inf; 2]) ***** error ... dummyvar ({'a', 'b'}) ***** error ... dummyvar ({[2;3;4;5], [1;2;3]}) ***** error dummyvar ([true; false]) 32 tests, 32 passed, 0 known failure, 0 skipped [inst/Data_Manipulation/combnk.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Data_Manipulation/combnk.m ***** demo c = combnk (1:5, 2); disp ('All pairs of integers between 1 and 5:'); disp (c); ***** test c = combnk (1:3, 2); assert_equal (c, [1, 2; 1, 3; 2, 3]); ***** test c = combnk (1:3, 6); assert_equal (isempty (c), true); ***** test c = combnk ({1, 2, 3}, 2); assert_equal (c, {1, 2; 1, 3; 2, 3}); ***** test c = combnk ('hello', 2); assert_equal (c, ['lo'; 'lo'; 'll'; 'eo'; 'el'; 'el'; 'ho'; 'hl'; 'hl'; 'he']); ***** assert_equal (combnk (1:3, 0), zeros (1, 0)) ***** assert_equal (combnk ((1:3)', 0), zeros (1, 0)) ***** assert_equal (combnk ('abc', 0), char (zeros (1, 0))) ***** assert_equal (combnk (int8 (1:3), 0), zeros (1, 0, 'int8')) 8 tests, 8 passed, 0 known failure, 0 skipped [inst/Data_Manipulation/crosstab.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Data_Manipulation/crosstab.m ***** error crosstab () ***** error crosstab (1) ***** error crosstab (ones (2), [1 1]) ***** error crosstab ([1 1], ones (2)) ***** error crosstab ([1], [1 2]) ***** error crosstab ([1 2], [1]) ***** error crosstab ([1 2], {1, 2}) ***** test load carbig [t, chisq, p, labels] = crosstab (cyl4, when, org); assert_equal (t(2,3,1), 38); assert_equal (labels{3,3}, "Japan"); ***** test load carbig [t, chisq, p, labels] = crosstab (cyl4, when, org); assert_equal (t(2,3,2), 17); assert_equal (labels{1,3}, "USA"); ***** test x = [1, 1, 2, 3, 1]; y = [1, 2, 5, 3, 1]; t = crosstab (x, y); assert_equal (t, [2, 1, 0, 0; 0, 0, 0, 1; 0, 0, 1, 0]); ***** test x = [1, 1, 2, 3, 1]; y = [1, 2, 3, 5, 1]; t = crosstab (x, y); assert_equal (t, [2, 1, 0, 0; 0, 0, 1, 0; 0, 0, 0, 1]); ***** test x1 = [1, 3, 7, 7, 8]; x2 = [4, 2, 1, 1, 1]; x3 = [6, 2, 6, 2, NaN]; T1 = [0, 0, 0; 0, 1, 0; 1, 0, 0; 0, 0, 0]; T2 = [0, 0, 1; 0, 0, 0; 1, 0, 0; 0, 0, 0]; T = zeros (4, 3, 2); T(:,:,1) = T1; T(:,:,2) = T2; t = crosstab (x1, x2, x3); assert_equal (t, T); ***** test x = [1, 2, NaN, 1]; y = [1, 2, 3, NaN]; t = crosstab (x, y); assert_equal (t, [1, 0, 0; 0, 1, 0]); ***** test x = categorical ({'A', 'B', 'A', 'C', 'B'}); y = [1, 2, 1, 3, 2]; t = crosstab (x, y); assert_equal (size (t), [3, 3]); assert_equal (t(1, 1), 2); # A with 1 assert_equal (t(2, 2), 2); # B with 2 ***** test x = categorical ({'low', 'med', 'high', 'low', 'med'}); y = categorical ({'X', 'Y', 'X', 'Y', 'X'}); t = crosstab (x, y); assert_equal (size (t), [3, 2]); ***** test # MATLAB parity: an unused category keeps its zero row g = categorical ({'hi'; 'hi'; 'lo'; 'lo'; 'hi'; 'lo'}, {'mid', 'lo', 'hi'}); w = warning (); warning ('off'); [t, chisq, p, labels] = crosstab (g, [1; 2; 5; 6; 3; 7] > 3); warning (w); assert_equal (t, [0, 0; 0, 3; 3, 0]); assert_equal (labels(:,1)', {'mid', 'lo', 'hi'}); assert_equal (chisq, 6); assert_equal (p, 0.01430587844, 1e-10); ***** test # MATLAB parity: rows follow the category order, not the names x = categorical ({'hi'; 'hi'; 'lo'; 'lo'; 'hi'; 'lo'}, {'lo', 'hi'}); t = crosstab (x, [1; 2; 5; 6; 3; 7] > 3); assert_equal (t, [0, 3; 3, 0]); ***** test ## Test categorical with numeric x = categorical ([10, 20, 10, 30, 20]); y = [1, 2, 1, 3, 2]; t = crosstab (x, y); assert_equal (t, [2, 0, 0; 0, 2, 0; 0, 0, 1]); ***** test smoker = [1 1 0 0 1 0 1 1 0 0 1 0]'; gender = [1 0 1 0 1 1 0 0 1 0 0 1]'; w = warning (); warning ('off'); [t, chisq, p, labels] = crosstab (smoker, gender); warning (w); assert_equal (t, [2 4; 4 2]); assert_equal (chisq, 1.33333333, 1e-8); assert_equal (p, 0.24821308, 1e-8); assert_equal (labels{1,1}, '0'); assert_equal (labels{1,2}, '0'); assert_equal (labels{2,1}, '1'); assert_equal (labels{2,2}, '1'); ***** test ## Test for categorical smk_cat = categorical ([0 0 1 1 0 1 0 0 1 1 0 1]'); gen_cat = categorical ([0 1 0 1 0 0 1 1 0 1 1 0]'); w = warning (); warning ('off'); [t, chisq, p] = crosstab (smk_cat, gen_cat); warning (w); assert_equal (t, [2 4; 4 2]); assert_equal (chisq, 1.33333333, 1e-6); assert_equal (p, 0.24821308, 1e-6); ***** test x = [1 1 1 2 2 2 3 3 3]'; y = [1 1 1 2 2 2 3 3 3]'; w = warning (); warning ('off'); [t, chisq, p, labels] = crosstab (x, y); warning (w); assert_equal (t, diag ([3 3 3])); assert_equal (chisq, 18.00000000); assert_equal (p, 0.00123410, 1e-8); ***** test ## The two columns holding only rows with a missing x7 are empty, and the ## test runs over the other four; R2024a returns NaN for chisq and p. x7 = [1 2 3 4 NaN NaN]'; y7 = [10 20 30 40 50 60]'; w = warning (); warning ('off'); [t, chisq, p, labels] = crosstab (x7, y7); warning (w); assert_equal (t, [eye(4), zeros(4, 2)]); assert_equal (chisq, 12); assert_equal (p, 0.2133093051, 1e-10); assert_equal (labels{1,1}, '1'); assert_equal (labels{1,2}, '10'); assert_equal (labels{2,1}, '2'); assert_equal (labels{2,2}, '20'); assert_equal (labels{3,1}, '3'); assert_equal (labels{3,2}, '30'); assert_equal (labels{4,1}, '4'); assert_equal (labels{4,2}, '40'); assert_equal (isempty (labels{5,1}), true); assert_equal (labels{5,2}, '50'); assert_equal (isempty (labels{6,1}), true); assert_equal (labels{6,2}, '60'); ***** test a = ones (15,1); b = ones (15,1); w = warning (); warning ('off'); [t, chisq, p] = crosstab (a, b); warning (w); assert_equal (t, 15); assert_equal (isnan (chisq), true); assert_equal (isnan (p), true); ***** test ## all NaN → empty table + NaN stats na = NaN (6,1); nb = (1:6)'; w = warning (); warning ('off'); [t, chisq, p] = crosstab (na, nb); warning (w); assert_equal (all (t(:) == 0), true); assert_equal (isnan (chisq), true); assert_equal (isnan (p), true); ***** test ## single observation → 1×1 table, NaN statistic w = warning (); warning ('off'); [t, chisq, p, labels] = crosstab (5, 'Z'); warning (w); assert_equal (t, 1); assert_equal (isnan (chisq), true); assert_equal (isnan (p), true); assert_equal (labels{1,1}, '5'); assert_equal (labels{1,2}, 'Z'); ***** test xx = [1 1 1 1 2 2 2 2]'; yy = [10 10 10 10 20 20 20 20]'; w = warning (); warning ('off'); [t, chisq, p] = crosstab (xx, yy); warning (w); assert_equal (t, [4 0; 0 4]); assert_equal (chisq, 8.00000000); assert_equal (p, 0.00467773, 1e-8); ***** test set1 = repmat ((1:5)', 20, 1); set2 = repmat ([1; 2], 50, 1); w = warning (); warning ('off'); [t, chisq, p] = crosstab (set1, set2); warning (w); assert_equal (t, 10 * ones (5,2)); assert_equal (chisq, 0); assert_equal (p, 1); ***** test ## 3-way table with NaN a = [1 1 2 2 3 3 1]'; b = [1 2 1 2 1 2 1]'; c = [1 1 NaN 2 2 1 2]'; w = warning (); warning ('off'); [t, chisq, p] = crosstab (a, b, c); warning (w); expected(:,:,1) = [1 1; 0 0; 0 1]; expected(:,:,2) = [1 0; 0 1; 1 0]; assert_equal (t, expected); assert_equal (chisq, 6.00000000); assert_equal (p, 0.53974935, 1e-9); ***** test ## sparse cellstr g = [1 5 7 12 1 5 19]'; h = {'A', 'B', 'A', 'C', 'D', 'E', 'A'}'; w = warning (); warning ('off'); [t, chisq, p] = crosstab (g, h); warning (w); assert_equal (sum (t(:)), 7); assert_equal (chisq, 16.33333333, 1e-8); assert_equal (p, 0.42994852, 1e-8); ***** test ## string array str1 = ['low'; 'high'; 'med'; 'low'; 'high']; str2 = ['X'; 'Y'; 'X'; 'Y'; 'X']; w = warning (); warning ('off'); [t, chisq, p] = crosstab (str1, str2); warning (w); assert_equal (t, [1 1; 1 1; 1 0]); assert_equal (chisq, 0.83333333, 1e-8); assert_equal (p, 0.659240631, 1e-9); ***** test ## cellstr c1 = {'A','B','A','C','B','A'}'; c2 = {'1','2','1','3','2','1'}'; w = warning (); warning ('off'); [t, chisq, p] = crosstab (c1, c2); warning (w); assert_equal (t, [3 0 0; 0 2 0; 0 0 1]); assert_equal (chisq, 12.00000000, 1e-14); assert_equal (p, 0.01735127, 1e-8); 31 tests, 31 passed, 0 known failure, 0 skipped [inst/Data_Manipulation/standardizeMissing.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Data_Manipulation/standardizeMissing.m ***** assert_equal (standardizeMissing (1, 1), NaN) ***** assert_equal (standardizeMissing (1, 0), 1) ***** assert_equal (standardizeMissing (eye (2), 1), [NaN 0;0 NaN]) ***** assert_equal (standardizeMissing ([1:3;4:6], [2 3 4 5]), [1, NaN, NaN; NaN, NaN, 6]) ***** assert_equal (standardizeMissing (cat (3,1,2,3,4), 3), cat (3,1,2,NaN,4)) ***** assert_equal (standardizeMissing ('foo', 'a'), 'foo') ***** assert_equal (standardizeMissing ('foo', 'f'), 'foo') ***** assert_equal (standardizeMissing ('foo', 'o'), 'foo') ***** assert_equal (standardizeMissing ('foo', 'oo'), 'foo') ***** assert_equal (standardizeMissing ({'foo'}, 'f'), {'foo'}) ***** assert_equal (standardizeMissing ({'foo'}, {'f'}), {'foo'}) ***** assert_equal (standardizeMissing ({'foo'}, 'test'), {'foo'}) ***** assert_equal (standardizeMissing ({'foo'}, {'test'}), {'foo'}) ***** assert_equal (standardizeMissing ({'foo'}, 'foo'), {''}) ***** assert_equal (standardizeMissing ({'foo'}, {'foo'}), {''}) ***** assert_equal (standardizeMissing (['foo';'bar'], 'oar'), ['foo';'bar']) ***** assert_equal (standardizeMissing (['foo';'bar'], ['o';'a';'r']), ['foo';'bar']) ***** assert_equal (standardizeMissing (['foo';'bar'], ['o ';'ar']), ['foo';'bar']) ***** assert_equal (standardizeMissing ({'foo','bar'}, 'foo'), {'','bar'}) ***** assert_equal (standardizeMissing ({'foo','bar'}, 'f'), {'foo','bar'}) ***** assert_equal (standardizeMissing ({'foo','bar'}, {'foo', 'a'}), {'','bar'}) ***** assert_equal (standardizeMissing ({'foo'}, {'f', 'oo'}), {'foo'}) ***** assert_equal (standardizeMissing ({'foo','bar'}, {'foo'}), {'','bar'}) ***** assert_equal (standardizeMissing ({'foo','bar'}, {'foo', 'a'}), {'','bar'}) ***** assert_equal (standardizeMissing (double (1), single (1)), double (NaN)) ***** assert_equal (standardizeMissing (single (1), single (1)), single (NaN)) ***** assert_equal (standardizeMissing (single (1), double (1)), single (NaN)) ***** assert_equal (standardizeMissing (single (1), uint8 (1)), single (NaN)) ***** assert_equal (standardizeMissing (double (1), int32 (1)), double (NaN)) ***** assert_equal (standardizeMissing (true, true), true) ***** assert_equal (standardizeMissing (true, 1), true) ***** assert_equal (standardizeMissing (int32 (1), int32 (1)), int32 (1)) ***** assert_equal (standardizeMissing (int32 (1), 1), int32 (1)) ***** assert_equal (standardizeMissing (uint32 (1), uint32 (1)), uint32 (1)) ***** assert_equal (standardizeMissing (uint32 (1), 1), uint32 (1)) ***** assert_equal (standardizeMissing ({'abc', 1}, 1), {'abc', 1}) ***** assert_equal (standardizeMissing (struct ('a','b'), 1), struct ('a','b')) ***** test ## every instance goes, and the remaining codes shift down a = standardizeMissing (categorical ({'a','b','c','b','a'}), 'b'); assert_equal (double (a), [1, NaN, 2, NaN, 1]); assert_equal (categories (a), {'a'; 'c'}); ***** test ## a category that is declared but unused is left alone A = categorical ({'a','b','c'}, {'a','b','c','d'}); a = standardizeMissing (A, 'b'); assert_equal (double (a), [1, NaN, 2]); assert_equal (categories (a), {'a'; 'c'; 'd'}); ***** test ## standardizing a level that is not present changes nothing a = standardizeMissing (categorical ({'a','b','c'}), 'z'); assert_equal (double (a), [1, 2, 3]); assert_equal (categories (a), {'a'; 'b'; 'c'}); ***** test ## several at once a = standardizeMissing (categorical ({'a','b','c'}), {'a','b'}); assert_equal (double (a), [NaN, NaN, 1]); assert_equal (categories (a), {'c'}); ***** test ## empty indicator is accepted A = [1 2 3]; B = standardizeMissing (A, []); assert_equal (B, A); ***** test ## matrix indicator is accepted A = [1 2 3; 4 5 6]; indicator = [1 9; 8 5]; B = standardizeMissing (A, indicator); assert_equal (B, [NaN 2 3; 4 NaN 6]); ***** assert_equal (double (standardizeMissing (categorical (1), categorical (1))), NaN) ***** assert_equal (double (standardizeMissing (categorical (1), '1')), NaN) ***** assert_equal (class (standardizeMissing (categorical (1), categorical (1))), 'categorical') ***** assert_equal (double (standardizeMissing (categorical (1), categorical (2))), 1) ***** assert_equal (double (standardizeMissing (categorical (1), '2')), 1) ***** assert_equal (class (standardizeMissing (categorical (1), categorical (2))), 'categorical') ***** test A = categorical ({'a', 'b', 'c'}); indicator = 'b'; a = standardizeMissing (A , indicator); assert_equal (class (a), 'categorical'); assert_equal (double (a), [1, NaN, 2]); assert_equal (categories (a), {'a'; 'c'}); ***** assert_equal (isnat (standardizeMissing (datetime ('today'), datetime ('today'))), true) ***** assert_equal (isnat (standardizeMissing (datetime ('today'), datetime ('yesterday'))), false) ***** assert_equal (days (standardizeMissing (days (1), days (1))), NaN) ***** assert_equal (days (standardizeMissing (days (1), days (2))), 1) ***** assert_equal (cellstr (standardizeMissing (string (1), string (1))), {''}) ***** assert_equal (cellstr (standardizeMissing (string (1), string (2))), {'1'}) ***** error standardizeMissing (); ***** error standardizeMissing (1); ***** error standardizeMissing (1, 2, 3); ***** error ... standardizeMissing ([1, 2, 3], {1}); ***** error ... standardizeMissing ([1, 2, 3], 'a'); ***** error ... standardizeMissing ([1, 2, 3], struct ('a', 1)); ***** error ... standardizeMissing (categorical (1), 1); ***** error ... standardizeMissing ({'foo'}, string ('foo')); ***** error ... standardizeMissing ({'foo'}, ['a';'b']); 65 tests, 65 passed, 0 known failure, 0 skipped [inst/Data_Manipulation/rmmissing.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Data_Manipulation/rmmissing.m ***** assert_equal (rmmissing ([1, NaN, 3]), [1, 3]) ***** assert_equal (rmmissing ('abcd f'), 'abcd f') ***** assert_equal (rmmissing ({'xxx', '', 'xyz'}), {'xxx', 'xyz'}) ***** assert_equal (rmmissing ({'xxx', ''; 'xyz', 'yyy'}), {'xyz', 'yyy'}) ***** assert_equal (rmmissing ({'xxx', ''; 'xyz', 'yyy'}, 2), {'xxx'; 'xyz'}) ***** assert_equal (rmmissing ([1, 2; NaN, 2]), [1, 2]) ***** assert_equal (rmmissing ([1, 2; NaN, 2], 2), [2, 2]') ***** assert_equal (rmmissing ([1, 2; NaN, 4; NaN, NaN],'MinNumMissing', 2), [1, 2; NaN, 4]) ***** assert_equal (rmmissing ([1, NaN, 3], 'MinNumMissing', 0), zeros (1, 0)) ***** assert_equal (rmmissing ([1, NaN, 3], 'MinNumMissing', 2), [1, NaN, 3]) ***** assert_equal (rmmissing ([1, NaN; 3, 4], 'MinNumMissing', 0), zeros (0, 2)) ***** assert_equal (rmmissing ([1, NaN; 3, 4], 2, 'MinNumMissing', 0), zeros (2, 0)) ***** test x = [1:6]; x([2,4]) = NaN; [~, idx] = rmmissing (x); assert_equal (idx, logical ([0, 1, 0, 1, 0, 0])); assert_equal (class (idx), 'logical'); x = reshape (x, [2, 3]); [~, idx] = rmmissing (x); assert_equal (idx, logical ([0; 1])); assert_equal (class (idx), 'logical'); [~, idx] = rmmissing (x, 2); assert_equal (idx, logical ([1, 1, 0])); assert_equal (class (idx), 'logical'); [~, idx] = rmmissing (x, 1, 'MinNumMissing', 2); assert_equal (idx, logical ([0; 1])); assert_equal (class (idx), 'logical'); [~, idx] = rmmissing (x, 2, 'MinNumMissing', 2); assert_equal (idx, logical ([0, 0, 0])); assert_equal (class (idx), 'logical'); ***** assert_equal (rmmissing (single ([1, 2, NaN; 3, 4, 5])), single ([3, 4, 5])) ***** assert_equal (rmmissing (logical (ones (3))), logical (ones (3))) ***** assert_equal (rmmissing (int32 (ones (3))), int32 (ones (3))) ***** assert_equal (rmmissing (uint32 (ones (3))), uint32 (ones (3))) ***** assert_equal (rmmissing ({1, 2, 3}), {1, 2, 3}) ***** assert_equal (rmmissing ([struct, struct, struct]), [struct, struct, struct]) ***** assert_equal (rmmissing ([]), []) ***** assert_equal (rmmissing (ones (1, 0)), ones (1, 0)) ***** assert_equal (rmmissing (ones (1, 0), 1), ones (1, 0)) ***** assert_equal (rmmissing (ones (1, 0), 2), ones (1, 0)) ***** assert_equal (rmmissing (ones (0, 1)), ones (0, 1)) ***** assert_equal (rmmissing (ones (0, 1), 1), ones (0, 1)) ***** assert_equal (rmmissing (ones (0, 1), 2), ones (0, 1)) ***** error ... rmmissing (ones (0, 1, 2)) ***** error rmmissing () ***** error ... rmmissing (ones (2, 2, 2)) ***** error ... rmmissing ([1, 2; 3, 4], 2, 'MinNumMissing', -2) ***** error ... rmmissing ([1, 2; 3, 4], 'MinNumMissing', 3.8) ***** error ... rmmissing ([1, 2; 3, 4], 'MinNumMissing', [1, 2, 3]) ***** error ... rmmissing ([1, 2; 3, 4], 'MinNumMissing', 'xxx') ***** error ... rmmissing ([1, 2; 3, 4], 'MissingLocations', false ([1, 1, 1])) ***** error rmmissing ([1, 2; 3, 4], 5) ***** error rmmissing ([1, 2; 3, 4], 'XXX', 1) ***** error rmmissing ([], 'MinNumMissing', -2) ***** error rmmissing ([], 5) ***** error rmmissing ([], 'MissingLocations', true) ***** test [R, TF] = rmmissing ([]); assert_equal (R, []); assert_equal (TF, false (0, 1)); ***** test [R, TF] = rmmissing (zeros (0, 3)); assert_equal (R, zeros (0, 3)); assert_equal (TF, false (0, 1)); ***** test [R, TF] = rmmissing (zeros (0, 3), 2); assert_equal (R, zeros (0, 3)); assert_equal (TF, false (1, 3)); ***** test [R, TF] = rmmissing (zeros (3, 0)); assert_equal (R, zeros (3, 0)); assert_equal (TF, false (3, 1)); ***** test [R, TF] = rmmissing (zeros (1, 0)); assert_equal (R, zeros (1, 0)); assert_equal (TF, false (1, 0)); ***** test [R, TF] = rmmissing (cell (0, 2)); assert_equal (R, cell (0, 2)); assert_equal (TF, false (0, 1)); 45 tests, 45 passed, 0 known failure, 0 skipped [inst/Data_Manipulation/tiedrank.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Data_Manipulation/tiedrank.m ***** test [r,tieadj] = tiedrank ([10, 20, 30, 40, 20]); assert_equal (r, [1, 2.5, 4, 5, 2.5]); assert_equal (tieadj, 3); ***** test [r,tieadj] = tiedrank ([10; 20; 30; 40; 20]); assert_equal (r, [1; 2.5; 4; 5; 2.5]); assert_equal (tieadj, 3); ***** test [r,tieadj] = tiedrank ([10, 20, 30, 40, 20], 1); assert_equal (r, [1, 2.5, 4, 5, 2.5]); assert_equal (tieadj, [1; 0; 18]); ***** test [r,tieadj] = tiedrank ([10, 20, 30, 40, 20], 0, 1); assert_equal (r, [1, 2.5, 2, 1, 2.5]); assert_equal (tieadj, 3); ***** test [r,tieadj] = tiedrank ([10, 20, 30, 40, 20], 1, 1); assert_equal (r, [1, 2.5, 2, 1, 2.5]); assert_equal (tieadj, [1; 0; 18]); ***** test ## TOL ties a pair whose gap is within the SUM of their two tolerances, and ## separates it beyond. Boundaries measured against R2024a. tol = [eps(1), 1e-10, 3e-10, eps(3)]; assert_equal (tiedrank ([1.0, 1.9, 1.9+3.9e-10, 3.0], 0, 0, tol), ... [1, 2.5, 2.5, 4]); assert_equal (tiedrank ([1.0, 1.9, 1.9+4.1e-10, 3.0], 0, 0, tol), ... [1, 2, 3, 4]); ***** test ## A scalar TOL applies to every element, and the default 0 is exact assert_equal (tiedrank ([1, 1+1e-9, 2], 0, 0, 1e-9), [1.5, 1.5, 3]); assert_equal (tiedrank ([1, 1+1e-9, 2], 0, 0, 0), [1, 2, 3]); assert_equal (tiedrank ([1, 1+1e-9, 2]), [1, 2, 3]); ***** test ## Exact equality still ties whatever TOL says, infinities included assert_equal (tiedrank ([Inf, Inf, 1]), [2.5, 2.5, 1]); assert_equal (tiedrank ([Inf, Inf, 1], 0, 0, 0), [2.5, 2.5, 1]); ***** test ## A matrix is ranked column by column, as MATLAB does, and TIEADJ carries ## one entry per column. x = [3, 1; 1, 4; 4, 1; 1, 5; 5, 9]; [r, tieadj] = tiedrank (x); assert_equal (r, [3, 1.5; 1.5, 3; 4, 1.5; 1.5, 4; 5, 5]); assert_equal (tieadj, [3, 3]); [r1, t1] = tiedrank (x(:,1)); [r2, t2] = tiedrank (x(:,2)); assert_equal (r, [r1, r2]); assert_equal (tieadj, [t1, t2]); ***** test ## With the tie flag TIEADJ gains its three rows per column x = [3, 1; 1, 4; 4, 1; 1, 5; 5, 9]; [r, tieadj] = tiedrank (x, 1); assert_equal (size (tieadj), [3, 2]); [~, t1] = tiedrank (x(:,1), 1); assert_equal (tieadj(:,1), t1); ***** test ## An empty matrix is ranked, not refused [r, tieadj] = tiedrank (zeros (0, 2)); assert_equal (size (r), [0, 2]); assert_equal (size (tieadj), [1, 2]); ***** test ## An N-D array is ranked along its first dimension, as MATLAB does, and ## TIEADJ keeps the higher dimensions of X. Verified against R2024a. y = cat (3, [1, 2; 3, 4], [5, 6; 7, 8]); [r, tieadj] = tiedrank (y); assert_equal (r(:,:,1), [1, 1; 2, 2]); assert_equal (r(:,:,2), [1, 1; 2, 2]); assert_equal (size (tieadj), [1, 2, 2]); ***** error ... tiedrank ([1, 2, 3, 4, 5], [1, 1]) ***** error ... tiedrank ([1, 2, 3, 4, 5], 'A') ***** error ... tiedrank ([1, 2, 3, 4, 5], [true, true]) ***** error ... tiedrank ([1, 2, 3, 4, 5], 0, [1, 1]) ***** error ... tiedrank ([1, 2, 3, 4, 5], 0, 'A') ***** error ... tiedrank ([1, 2, 3, 4, 5], 0, [true, true]) ***** error ... tiedrank ([1, 2, 3, 4, 5], 0, 0, -1) ***** error ... tiedrank ([1, 2, 3, 4, 5], 0, 0, 'A') ***** error ... tiedrank ([1, 2, 3, 4, 5], 0, 0, [1, 2]) 21 tests, 21 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/ncfcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/ncfcdf.m ***** demo ## Plot various CDFs from the noncentral F distribution x = 0:0.01:5; p1 = ncfcdf (x, 2, 5, 1); p2 = ncfcdf (x, 2, 5, 2); p3 = ncfcdf (x, 5, 10, 1); p4 = ncfcdf (x, 10, 20, 10); plot (x, p1, '-r', x, p2, '-g', x, p3, '-k', x, p4, '-m') grid on xlim ([0, 5]) legend ({'df1 = 2, df2 = 5, λ = 1', 'df1 = 2, df2 = 5, λ = 2', ... 'df1 = 5, df2 = 10, λ = 1', 'df1 = 10, df2 = 20, λ = 10'}, ... 'location', 'southeast') title ('Noncentral F CDF') xlabel ('values in x') ylabel ('probability') ***** demo ## Compare the noncentral F CDF with LAMBDA = 10 to the F CDF with the ## same number of numerator and denominator degrees of freedom (5, 20) x = 0.01:0.1:10.01; p1 = ncfcdf (x, 5, 20, 10); p2 = fcdf (x, 5, 20); plot (x, p1, '-', x, p2, '-'); grid on xlim ([0, 10]) legend ({'Noncentral F(5,20,10)', 'F(5,20)'}, 'location', 'southeast') title ('Noncentral F vs F CDFs') xlabel ('values in x') ylabel ('probability') ***** test x = -2:0.1:2; p = ncfcdf (x, 10, 1, 3); assert_equal (p([1:21]), zeros (1, 21), 1e-76); assert_equal (p(22), 0.004530737275319753, 1e-14); assert_equal (p(30), 0.255842099135669, 1e-14); assert_equal (p(41), 0.4379890998457305, 1e-14); ***** test p = ncfcdf (12, 10, 3, 2); assert_equal (p, 0.9582287900447416, 1e-14); ***** test p = ncfcdf (2, 3, 2, 1); assert_equal (p, 0.5731985522994989, 1e-14); ***** test p = ncfcdf (2, 3, 2, 1, 'upper'); assert_equal (p, 0.4268014477004823, 1e-14); ***** test p = ncfcdf ([3, 6], 3, 2, 5, 'upper'); assert_equal (p, [0.530248523596927, 0.3350482341323044], 1e-14); ***** error ncfcdf () ***** error ncfcdf (1) ***** error ncfcdf (1, 2) ***** error ncfcdf (1, 2, 3) ***** error ncfcdf (1, 2, 3, 4, 'tail') ***** error ncfcdf (1, 2, 3, 4, 5) ***** error ... ncfcdf (ones (3), ones (2), ones (2), ones (2)) ***** error ... ncfcdf (ones (2), ones (3), ones (2), ones (2)) ***** error ... ncfcdf (ones (2), ones (2), ones (3), ones (2)) ***** error ... ncfcdf (ones (2), ones (2), ones (2), ones (3)) ***** error ncfcdf (int32 (2), 2, 2, 2) ***** error ncfcdf (true, 2, 2, 2) ***** error ncfcdf ('a', 2, 2, 2) ***** error ncfcdf (i, 2, 2, 2) ***** error ncfcdf (2, i, 2, 2) ***** error ncfcdf (2, 2, i, 2) ***** error ncfcdf (2, 2, 2, i) 22 tests, 22 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/mvnpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/mvnpdf.m ***** demo mu = [1, -1]; sigma = [0.9, 0.4; 0.4, 0.3]; [X1, X2] = meshgrid (linspace (-1, 3, 25)', linspace (-3, 1, 25)'); x = [X1(:), X2(:)]; p = mvnpdf (x, mu, sigma); surf (X1, X2, reshape (p, 25, 25)); ***** error mvnpdf (int32 ([0, 0]), [0, 0], eye (2)) ***** error mvnpdf ([true, true], [0, 0], eye (2)) ***** error mvnpdf ('ab', [0, 0], eye (2)) ***** error y = mvnpdf (); ***** error y = mvnpdf ([]); ***** error y = mvnpdf (ones (3,3,3)); ***** error ... y = mvnpdf (ones (10, 2), [4, 2, 3]); ***** error ... y = mvnpdf (ones (10, 2), [4, 2; 3, 2]); ***** error ... y = mvnpdf (ones (10, 2), ones (3, 3, 3)); ***** shared x, mu, sigma x = [1, 2, 5, 4, 6]; mu = [2, 0, -1, 1, 4]; sigma = [2, 2, 2, 2, 2]; ***** assert_equal (mvnpdf (x), 1.579343404440977e-20, 1e-30); ***** assert_equal (mvnpdf (x, mu), 1.899325144348102e-14, 1e-25); ***** assert_equal (mvnpdf (x, mu, sigma), 2.449062307156273e-09, 1e-20); 12 tests, 12 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/betainv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/betainv.m ***** demo ## Plot various iCDFs from the Beta distribution p = 0.001:0.001:0.999; x1 = betainv (p, 0.5, 0.5); x2 = betainv (p, 5, 1); x3 = betainv (p, 1, 3); x4 = betainv (p, 2, 2); x5 = betainv (p, 2, 5); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', p, x4, '-c', p, x5, '-m') grid on legend ({'α = β = 0.5', 'α = 5, β = 1', 'α = 1, β = 3', ... 'α = 2, β = 2', 'α = 2, β = 5'}, 'location', 'southeast') title ('Beta iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p p = [-1 0 0.75 1 2]; ***** assert_equal (betainv (p, ones (1,5), 2*ones (1,5)), [NaN 0 0.5 1 NaN], eps) ***** assert_equal (betainv (p, 1, 2*ones (1,5)), [NaN 0 0.5 1 NaN], eps) ***** assert_equal (betainv (p, ones (1,5), 2), [NaN 0 0.5 1 NaN], eps) ***** assert_equal (betainv (p, [1 0 NaN 1 1], 2), [NaN NaN NaN 1 NaN]) ***** assert_equal (betainv (p, 1, 2*[1 0 NaN 1 1]), [NaN NaN NaN 1 NaN]) ***** assert_equal (betainv ([p(1:2) NaN p(4:5)], 1, 2), [NaN 0 NaN 1 NaN]) ***** test pp = [1e-300, 1e-20, 0.025, 0.5, 1 - 1e-12]; assert_equal (betainv (pp, 1, 1000), -expm1 (log1p (-pp) / 1000), -1e-14); ***** assert_equal (betainv ([1e-300, 1e-20, 0.3], 30, 1), ... [1e-300, 1e-20, 0.3] .^ (1/30), -1e-14) ***** assert_equal (betainv (2e-10, 0.5, 0.5), sin (pi * 1e-10) ^ 2, -1e-14) ***** assert_equal (betainv (1e-10, 0.5, 50), 1.578669844608891e-22, -1e-12) ***** assert_equal (betainv (0.999, 0.5, 50), 0.103102263418713, -1e-13) ***** assert_equal (betainv (1 - 1e-9, 0.5, 1000), 0.018493954158234, -1e-13) ***** assert_equal (betainv (0.3, 2.5, 7.3), 0.170751332194546, -1e-14) ***** assert_equal (betainv (1e-6, 30, 200), 0.048760009765902, -5e-14) ***** assert_equal (betainv (1e-20, 2, 3), 4.082482904749744e-11, -1e-14) ***** assert_equal (betainv (0.975, 0.5, 0.5), 0.998458666866564, -1e-14) ***** assert_equal (size (betainv (0.3 * ones (2, 3), 2, 5)), [2, 3]) ***** assert_equal (betainv ([p, NaN], 1, 2), [NaN 0 0.5 1 NaN NaN], eps) ***** assert_equal (betainv (single ([p, NaN]), 1, 2), single ([NaN 0 0.5 1 NaN NaN])) ***** assert_equal (betainv ([p, NaN], single (1), 2), single ([NaN 0 0.5 1 NaN NaN]), eps ('single')) ***** assert_equal (betainv ([p, NaN], 1, single (2)), single ([NaN 0 0.5 1 NaN NaN]), eps ('single')) ***** error betainv () ***** error betainv (1) ***** error betainv (1,2) ***** error betainv (1,2,3,4) ***** error ... betainv (ones (3), ones (2), ones (2)) ***** error ... betainv (ones (2), ones (3), ones (2)) ***** error ... betainv (ones (2), ones (2), ones (3)) ***** error betainv (int32 (2), 2, 2) ***** error betainv (true, 2, 2) ***** error betainv ('a', 2, 2) ***** error betainv (i, 2, 2) ***** error betainv (2, i, 2) ***** error betainv (2, 2, i) 34 tests, 34 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/bisapdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/bisapdf.m ***** demo ## Plot various PDFs from the Birnbaum-Saunders distribution x = 0.01:0.01:4; y1 = bisapdf (x, 1, 0.5); y2 = bisapdf (x, 1, 1); y3 = bisapdf (x, 1, 2); y4 = bisapdf (x, 1, 5); y5 = bisapdf (x, 1, 10); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', x, y4, '-c', x, y5, '-m') grid on ylim ([0, 1.5]) legend ({'β = 1 ,γ = 0.5', 'β = 1, γ = 1', 'β = 1, γ = 2', ... 'β = 1, γ = 5', 'β = 1, γ = 10'}, 'location', 'northeast') title ('Birnbaum-Saunders PDF') xlabel ('values in x') ylabel ('density') ***** demo ## Plot various PDFs from the Birnbaum-Saunders distribution x = 0.01:0.01:6; y1 = bisapdf (x, 1, 0.3); y2 = bisapdf (x, 2, 0.3); y3 = bisapdf (x, 1, 0.5); y4 = bisapdf (x, 3, 0.5); y5 = bisapdf (x, 5, 0.5); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', x, y4, '-c', x, y5, '-m') grid on ylim ([0, 1.5]) legend ({'β = 1, γ = 0.3', 'β = 2, γ = 0.3', 'β = 1, γ = 0.5', ... 'β = 3, γ = 0.5', 'β = 5, γ = 0.5'}, 'location', 'northeast') title ('Birnbaum-Saunders CDF') xlabel ('values in x') ylabel ('density') ***** shared x, y x = [-1, 0, 1, 2, Inf]; y = [0, 0, 0.3989422804014327, 0.1647717335503959, 0]; ***** assert_equal (bisapdf (x, ones (1,5), ones (1,5)), y, eps) ***** assert_equal (bisapdf (x, 1, 1), y, eps) ***** assert_equal (bisapdf (x, 1, ones (1,5)), y, eps) ***** assert_equal (bisapdf (x, ones (1,5), 1), y, eps) ***** assert_equal (bisapdf (x, 1, [1, 1, NaN, 1, 1]), [y(1:2), NaN, y(4:5)], eps) ***** assert_equal (bisapdf (x, [1, 1, NaN, 1, 1], 1), [y(1:2), NaN, y(4:5)], eps) ***** assert_equal (bisapdf ([x, NaN], 1, 1), [y, NaN], eps) ***** assert_equal (bisapdf (single ([x, NaN]), 1, 1), single ([y, NaN]), eps ('single')) ***** assert_equal (bisapdf ([x, NaN], 1, single (1)), single ([y, NaN]), eps ('single')) ***** assert_equal (bisapdf ([x, NaN], single (1), 1), single ([y, NaN]), eps ('single')) ***** error bisapdf () ***** error bisapdf (1) ***** error bisapdf (1, 2) ***** error bisapdf (1, 2, 3, 4) ***** error ... bisapdf (ones (3), ones (2), ones (2)) ***** error ... bisapdf (ones (2), ones (3), ones (2)) ***** error ... bisapdf (ones (2), ones (2), ones (3)) ***** error bisapdf (int32 (2), 4, 3) ***** error bisapdf (true, 4, 3) ***** error bisapdf ('a', 4, 3) ***** error bisapdf (i, 4, 3) ***** error bisapdf (1, i, 3) ***** error bisapdf (1, 4, i) 23 tests, 23 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/nbininv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/nbininv.m ***** demo ## Plot various iCDFs from the negative binomial distribution p = 0.001:0.001:0.999; x1 = nbininv (p, 2, 0.15); x2 = nbininv (p, 5, 0.2); x3 = nbininv (p, 4, 0.4); x4 = nbininv (p, 10, 0.3); plot (p, x1, '-r', p, x2, '-g', p, x3, '-k', p, x4, '-m') grid on ylim ([0, 40]) legend ({'r = 2, ps = 0.15', 'r = 5, ps = 0.2', 'r = 4, p = 0.4', ... 'r = 10, ps = 0.3'}, 'location', 'northwest') title ('Negative binomial iCDF') xlabel ('probability') ylabel ('values in x (number of failures)') ***** shared p p = [-1 0 3/4 1 2]; ***** assert_equal (nbininv (p, ones (1,5), 0.5*ones (1,5)), [NaN 0 1 Inf NaN]) ***** assert_equal (nbininv (p, 1, 0.5*ones (1,5)), [NaN 0 1 Inf NaN]) ***** assert_equal (nbininv (p, ones (1,5), 0.5), [NaN 0 1 Inf NaN]) ***** assert_equal (nbininv (p, [1 0 NaN Inf 1], 0.5), [NaN NaN NaN NaN NaN]) ***** assert_equal (nbininv (p, [1 0 1.5 Inf 1], 0.5), [NaN NaN 2 NaN NaN]) ***** assert_equal (nbininv (p, 1, 0.5*[1 -Inf NaN Inf 1]), [NaN NaN NaN NaN NaN]) ***** assert_equal (nbininv ([p(1:2) NaN p(4:5)], 1, 0.5), [NaN 0 NaN Inf NaN]) ***** assert_equal (nbininv ([p, NaN], 1, 0.5), [NaN 0 1 Inf NaN NaN]) ***** assert_equal (nbininv (single ([p, NaN]), 1, 0.5), single ([NaN 0 1 Inf NaN NaN])) ***** assert_equal (nbininv ([p, NaN], single (1), 0.5), single ([NaN 0 1 Inf NaN NaN])) ***** assert_equal (nbininv ([p, NaN], 1, single (0.5)), single ([NaN 0 1 Inf NaN NaN])) ***** shared y, tol y = magic (3) + 1; tol = 1; ***** assert_equal (nbininv (nbincdf (1:10, 3, 0.1), 3, 0.1), 1:10, tol) ***** assert_equal (nbininv (nbincdf (1:10, 3./(1:10), 0.1), 3./(1:10), 0.1), 1:10, tol) ***** assert_equal (nbininv (nbincdf (y, 3./y, 1./y), 3./y, 1./y), y, tol) ***** assert_equal (nbininv (0.5, 26, 0.5), 25) ***** assert_equal (nbininv (0.5, 101, 0.5), 100) ***** assert_equal (nbininv (0.5, 251, 0.5), 250) ***** assert_equal (nbininv (0.5, 2001, 0.5), 2000) ***** assert_equal (nbininv ([0.5, 0.9], 101, 0.5), [100, 120]) ***** assert_equal (nbininv ([0.5; 0.9], 101, 0.5), [100; 120]) ***** assert_equal (nbininv ([0.5, 0.5], [101, 251], 0.5), [100, 250]) ***** assert_equal (nbininv ([NaN, 0.5], 101, 0.5), [NaN, 100]) ***** assert_equal (nbininv ([2, 0.5], [101, 101], [0.5, 0.5]), [NaN, 100]) ***** error nbininv () ***** error nbininv (1) ***** error nbininv (1, 2) ***** error ... nbininv (ones (3), ones (2), ones (2)) ***** error ... nbininv (ones (2), ones (3), ones (2)) ***** error ... nbininv (ones (2), ones (2), ones (3)) ***** error nbininv (int32 (2), 2, 2) ***** error nbininv (true, 2, 2) ***** error nbininv ('a', 2, 2) ***** error nbininv (i, 2, 2) ***** error nbininv (2, i, 2) ***** error nbininv (2, 2, i) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/gevinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/gevinv.m ***** demo ## Plot various iCDFs from the generalized extreme value distribution p = 0.001:0.001:0.999; x1 = gevinv (p, 1, 1, 1); x2 = gevinv (p, 0.5, 1, 1); x3 = gevinv (p, 1, 1, 5); x4 = gevinv (p, 1, 2, 5); x5 = gevinv (p, 1, 5, 5); x6 = gevinv (p, 1, 0.5, 5); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', ... p, x4, '-c', p, x5, '-m', p, x6, '-k') grid on ylim ([-1, 10]) legend ({'k = 1, σ = 1, μ = 1', 'k = 0.5, σ = 1, μ = 1', ... 'k = 1, σ = 1, μ = 5', 'k = 1, σ = 2, μ = 5', ... 'k = 1, σ = 5, μ = 5', 'k = 1, σ = 0.5, μ = 5'}, ... 'location', 'northwest') title ('Generalized extreme value iCDF') xlabel ('probability') ylabel ('values in x') ***** test p = 0.1:0.1:0.9; k = 0; sigma = 1; mu = 0; x = gevinv (p, k, sigma, mu); c = gevcdf (x, k, sigma, mu); assert_equal (c, p, 0.001); ***** test p = 0.1:0.1:0.9; k = 1; sigma = 1; mu = 0; x = gevinv (p, k, sigma, mu); c = gevcdf (x, k, sigma, mu); assert_equal (c, p, 0.001); ***** test p = 0.1:0.1:0.9; k = 0.3; sigma = 1; mu = 0; x = gevinv (p, k, sigma, mu); c = gevcdf (x, k, sigma, mu); assert_equal (c, p, 0.001); ***** error gevinv () ***** error gevinv (1) ***** error gevinv (1, 2) ***** error gevinv (1, 2, 3) ***** error ... gevinv (ones (3), ones (2), ones (2), ones (2)) ***** error ... gevinv (ones (2), ones (3), ones (2), ones (2)) ***** error ... gevinv (ones (2), ones (2), ones (3), ones (2)) ***** error ... gevinv (ones (2), ones (2), ones (2), ones (3)) ***** error gevinv (int32 (2), 2, 3, 4) ***** error gevinv (true, 2, 3, 4) ***** error gevinv ('a', 2, 3, 4) ***** error gevinv (i, 2, 3, 4) ***** error gevinv (1, i, 3, 4) ***** error gevinv (1, 2, i, 4) ***** error gevinv (1, 2, 3, i) 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/finv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/finv.m ***** demo ## Plot various iCDFs from the F distribution p = 0.001:0.001:0.999; x1 = finv (p, 1, 1); x2 = finv (p, 2, 1); x3 = finv (p, 5, 2); x4 = finv (p, 10, 1); x5 = finv (p, 100, 100); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', p, x4, '-c', p, x5, '-m') grid on ylim ([0, 4]) legend ({'df1 = 1, df2 = 2', 'df1 = 2, df2 = 1', ... 'df1 = 5, df2 = 2', 'df1 = 10, df2 = 1', ... 'df1 = 100, df2 = 100'}, 'location', 'northwest') title ('F iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p p = [-1 0 0.5 1 2]; ***** assert_equal (finv (p, 2*ones (1,5), 2*ones (1,5)), [NaN 0 1 Inf NaN]) ***** assert_equal (finv (p, 2, 2*ones (1,5)), [NaN 0 1 Inf NaN]) ***** assert_equal (finv (p, 2*ones (1,5), 2), [NaN 0 1 Inf NaN]) ***** assert_equal (finv (p, [2 -Inf NaN Inf 2], 2), [NaN NaN NaN Inf NaN]) ***** assert_equal (finv (p, 2, [2 -Inf NaN Inf 2]), [NaN NaN NaN Inf NaN]) ***** assert_equal (finv ([p(1:2) NaN p(4:5)], 2, 2), [NaN 0 NaN Inf NaN]) ***** assert_equal (finv (0.025, 10, 1e6), 0.3247, 1e-4) ***** assert_equal (finv (0.025, 10, 1e7), 0.3247, 1e-4) ***** assert_equal (finv (0.025, 10, 1e10), 0.3247, 1e-4) ***** assert_equal (finv (0.025, 10, 1e255), 0.3247, 1e-4) ***** assert_equal (finv (0.025, 10, Inf), 0.3247, 1e-4) ***** test x = finv (0.35, Inf, 4); assert_equal (x, 0.9014, 1e-4) ***** test x = finv (0, Inf, 4); assert_equal (x, 0) ***** test x = finv (1, Inf, 4); assert_equal (x, Inf) ***** test x = finv (0.35, 4, Inf); assert_equal (x, 0.6175, 1e-4) ***** test x = finv (0, 4, Inf); assert_equal (x, 0) ***** test x = finv (1, 4, Inf); assert_equal (x, Inf) ***** test x = finv ([0, 0.000001, 0.35, 1, 1.2], Inf, Inf); assert_equal (x, [0, 1, 1, 1, NaN]); ***** assert_equal (finv (1e-8, 2, 2), 1.00000001e-08, -1e-14) ***** assert_equal (finv (1e-12, 2, 2), 1.000000000001e-12, -1e-14) ***** assert_equal (finv (1e-10, 1, 1), 2.46740110027235e-20, -1e-14) ***** assert_equal (finv (1e-6, 10, 20), 0.0285838655483384, -1e-14) ***** assert_equal (finv (0.975, 1e6, 1e6), 1.00392762317843, -1e-10) ***** assert_equal (finv (0.975, 2e6, 2e6), 1.00277565345099, -1e-10) ***** assert_equal (finv (0.975, 1e7, 1e7), 1.00124035874565, -1e-10) ***** assert_equal (finv (0.975, 1e8, 1e8), 1.00039206963839, -1e-10) ***** assert_equal (finv (0.975, 1e8, 1e10), 1.00027858274271, -1e-9) ***** assert_equal (finv (0.35, Inf, 4), 0.901370019458443, -1e-14) ***** assert_equal (finv (0.35, 4, Inf), 0.617521846868827, -1e-14) ***** assert_equal (finv (0.025, 10, 1e12), 0.32469727802368437, -1e-10) ***** assert_equal (finv (0.975, 1e12, 4), 8.2573219821426864, -1e-10) ***** assert_equal (finv (1e-10, 10, 1e12), 0.0052331065631905406, -1e-10) ***** assert_equal (finv ([p, NaN], 2, 2), [NaN 0 1 Inf NaN NaN]) ***** assert_equal (finv (single ([p, NaN]), 2, 2), single ([NaN 0 1 Inf NaN NaN])) ***** assert_equal (finv ([p, NaN], single (2), 2), single ([NaN 0 1 Inf NaN NaN])) ***** assert_equal (finv ([p, NaN], 2, single (2)), single ([NaN 0 1 Inf NaN NaN])) ***** error finv () ***** error finv (1) ***** error finv (1,2) ***** error ... finv (ones (3), ones (2), ones (2)) ***** error ... finv (ones (2), ones (3), ones (2)) ***** error ... finv (ones (2), ones (2), ones (3)) ***** error finv (int32 (2), 2, 2) ***** error finv (true, 2, 2) ***** error finv ('a', 2, 2) ***** error finv (i, 2, 2) ***** error finv (2, i, 2) ***** error finv (2, 2, i) 48 tests, 48 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/lognpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/lognpdf.m ***** demo ## Plot various PDFs from the log-normal distribution x = 0:0.01:5; y1 = lognpdf (x, 0, 1); y2 = lognpdf (x, 0, 0.5); y3 = lognpdf (x, 0, 0.25); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r') grid on ylim ([0, 2]) legend ({'μ = 0, σ = 1', 'μ = 0, σ = 0.5', 'μ = 0, σ = 0.25'}, ... 'location', 'northeast') title ('Log-normal PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y x = [-1 0 e Inf]; y = [0, 0, 1/(e*sqrt(2*pi)) * exp(-1/2), 0]; ***** assert_equal (lognpdf (x, zeros (1,4), ones (1,4)), y, eps) ***** assert_equal (lognpdf (x, 0, ones (1,4)), y, eps) ***** assert_equal (lognpdf (x, zeros (1,4), 1), y, eps) ***** assert_equal (lognpdf (x, [0 1 NaN 0], 1), [0 0 NaN y(4)], eps) ***** assert_equal (lognpdf (x, 0, [0 NaN Inf 1]), [NaN NaN NaN y(4)], eps) ***** assert_equal (lognpdf ([x, NaN], 0, 1), [y, NaN], eps) ***** assert_equal (lognpdf (single ([x, NaN]), 0, 1), single ([y, NaN]), eps ('single')) ***** assert_equal (lognpdf ([x, NaN], single (0), 1), single ([y, NaN]), eps ('single')) ***** assert_equal (lognpdf ([x, NaN], 0, single (1)), single ([y, NaN]), eps ('single')) ***** error lognpdf (int32 (2), 0, 1) ***** error lognpdf (true, 0, 1) ***** error lognpdf ('a', 0, 1) ***** error lognpdf () ***** error lognpdf (1,2,3,4) ***** error lognpdf (ones (3), ones (2), ones (2)) ***** error lognpdf (ones (2), ones (3), ones (2)) ***** error lognpdf (ones (2), ones (2), ones (3)) ***** error lognpdf (i, 2, 2) ***** error lognpdf (2, i, 2) ***** error lognpdf (2, 2, i) 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/unifcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/unifcdf.m ***** demo ## Plot various CDFs from the continuous uniform distribution x = 0:0.1:10; p1 = unifcdf (x, 2, 5); p2 = unifcdf (x, 3, 9); plot (x, p1, '-b', x, p2, '-g') grid on xlim ([0, 10]) ylim ([0, 1]) legend ({'a = 2, b = 5', 'a = 3, b = 9'}, 'location', 'southeast') title ('Continuous uniform CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y x = [-1 0 0.5 1 2] + 1; y = [0 0 0.5 1 1]; ***** assert_equal (unifcdf (x, ones (1,5), 2*ones (1,5)), y) ***** assert_equal (unifcdf (x, ones (1,5), 2*ones (1,5), 'upper'), 1 - y) ***** assert_equal (unifcdf (x, 1, 2*ones (1,5)), y) ***** assert_equal (unifcdf (x, 1, 2*ones (1,5), 'upper'), 1 - y) ***** assert_equal (unifcdf (x, ones (1,5), 2), y) ***** assert_equal (unifcdf (x, ones (1,5), 2, 'upper'), 1 - y) ***** assert_equal (unifcdf (x, [2 1 NaN 1 1], 2), [NaN 0 NaN 1 1]) ***** assert_equal (unifcdf (x, [2 1 NaN 1 1], 2, 'upper'), 1 - [NaN 0 NaN 1 1]) ***** assert_equal (unifcdf (x, 1, 2*[0 1 NaN 1 1]), [NaN 0 NaN 1 1]) ***** assert_equal (unifcdf (x, 1, 2*[0 1 NaN 1 1], 'upper'), 1 - [NaN 0 NaN 1 1]) ***** assert_equal (unifcdf ([x(1:2) NaN x(4:5)], 1, 2), [y(1:2) NaN y(4:5)]) ***** assert_equal (unifcdf ([x(1:2) NaN x(4:5)], 1, 2, 'upper'), 1 - [y(1:2) NaN y(4:5)]) ***** assert_equal (unifcdf ([x, NaN], 1, 2), [y, NaN]) ***** assert_equal (unifcdf (single ([x, NaN]), 1, 2), single ([y, NaN])) ***** assert_equal (unifcdf ([x, NaN], single (1), 2), single ([y, NaN])) ***** assert_equal (unifcdf ([x, NaN], 1, single (2)), single ([y, NaN])) ***** error unifcdf () ***** error unifcdf (1) ***** error unifcdf (1, 2) ***** error unifcdf (1, 2, 3, 4) ***** error unifcdf (1, 2, 3, 'tail') ***** error ... unifcdf (ones (3), ones (2), ones (2)) ***** error ... unifcdf (ones (2), ones (3), ones (2)) ***** error ... unifcdf (ones (2), ones (2), ones (3)) ***** error unifcdf (int32 (2), 2, 2) ***** error unifcdf (true, 2, 2) ***** error unifcdf ('a', 2, 2) ***** error unifcdf (i, 2, 2) ***** error unifcdf (2, i, 2) ***** error unifcdf (2, 2, i) 30 tests, 30 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/frnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/frnd.m ***** assert_equal (size (frnd (1, 1)), [1 1]) ***** assert_equal (size (frnd (1, ones (2,1))), [2, 1]) ***** assert_equal (size (frnd (1, ones (2,2))), [2, 2]) ***** assert_equal (size (frnd (ones (2,1), 1)), [2, 1]) ***** assert_equal (size (frnd (ones (2,2), 1)), [2, 2]) ***** assert_equal (size (frnd (1, 1, 3)), [3, 3]) ***** assert_equal (size (frnd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (frnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (frnd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (frnd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (frnd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (frnd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (frnd (1, 1, [])), [0, 0]) ***** assert_equal (size (frnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (frnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (frnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (frnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (frnd (1, 1)), "double") ***** assert_equal (class (frnd (1, single (1))), "single") ***** assert_equal (class (frnd (1, single ([1, 1]))), "single") ***** assert_equal (class (frnd (single (1), 1)), "single") ***** assert_equal (class (frnd (single ([1, 1]), 1)), "single") ***** error frnd () ***** error frnd (1) ***** error ... frnd (ones (3), ones (2)) ***** error ... frnd (ones (2), ones (3)) ***** error frnd (i, 2, 3) ***** error frnd (1, i, 3) ***** error ... frnd (1, 2, 1.2) ***** error ... frnd (1, 2, ones (2)) ***** error ... frnd (1, 2, [2 0 2.5]) ***** error ... frnd (1, 2, 2, 1.5, 5) ***** error ... frnd (2, ones (2), 3) ***** error ... frnd (2, ones (2), [3, 2]) ***** error ... frnd (2, ones (2), 3, 2) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/tcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/tcdf.m ***** demo ## Plot various CDFs from the Student's T distribution x = -5:0.01:5; p1 = tcdf (x, 1); p2 = tcdf (x, 2); p3 = tcdf (x, 5); p4 = tcdf (x, Inf); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', x, p4, '-m') grid on xlim ([-5, 5]) ylim ([0, 1]) legend ({'df = 1', 'df = 2', ... 'df = 5', 'df = \infty'}, 'location', 'southeast') title ('Student''s T CDF') xlabel ('values in x') ylabel ('probability') ***** shared x,y x = [-Inf 0 1 Inf]; y = [0 1/2 3/4 1]; ***** assert_equal (tcdf (x, ones (1,4)), y, eps) ***** assert_equal (tcdf (x, 1), y, eps) ***** assert_equal (tcdf (x, [0 1 NaN 1]), [NaN 1/2 NaN 1], eps) ***** assert_equal (tcdf ([x(1:2) NaN x(4)], 1), [y(1:2) NaN y(4)], eps) ***** assert_equal (tcdf (2, 3, 'upper'), 0.0697, 1e-4) ***** assert_equal (tcdf (205, 5, 'upper'), 2.6206e-11, 1e-14) ***** assert_equal (tcdf ([x, NaN], 1), [y, NaN], eps) ***** assert_equal (tcdf (single ([x, NaN]), 1), single ([y, NaN]), eps ('single')) ***** assert_equal (tcdf ([x, NaN], single (1)), single ([y, NaN]), eps ('single')) ***** error tcdf () ***** error tcdf (1) ***** error tcdf (1, 2, 'uper') ***** error tcdf (1, 2, 3) ***** error ... tcdf (ones (3), ones (2)) ***** error ... tcdf (ones (3), ones (2)) ***** error ... tcdf (ones (3), ones (2), 'upper') ***** error tcdf (int32 (2), 2) ***** error tcdf (true, 2) ***** error tcdf ('a', 2) ***** error tcdf (i, 2) ***** error tcdf (2, i) ***** shared tol_rel tol_rel = 10 * eps; ***** assert_equal (tcdf (10^(-10), 2.5), 0.50000000003618087, -tol_rel) ***** assert_equal (tcdf (10^(-11), 2.5), 0.50000000000361809, -tol_rel) ***** assert_equal (tcdf (10^(-12), 2.5), 0.50000000000036181, -tol_rel) ***** assert_equal (tcdf (10^(-13), 2.5), 0.50000000000003618, -tol_rel) ***** assert_equal (tcdf (10^(-14), 2.5), 0.50000000000000362, -tol_rel) ***** assert_equal (tcdf (10^(-15), 2.5), 0.50000000000000036, -tol_rel) ***** assert_equal (tcdf (10^(-16), 2.5), 0.50000000000000004, -tol_rel) ***** assert_equal (tcdf (-10^1, 2.5), 2.2207478836537124e-03, -tol_rel) ***** assert_equal (tcdf (-10^2, 2.5), 7.1916492116661878e-06, -tol_rel) ***** assert_equal (tcdf (-10^3, 2.5), 2.2747463948307452e-08, -tol_rel) ***** assert_equal (tcdf (-10^4, 2.5), 7.1933970159922115e-11, -tol_rel) ***** assert_equal (tcdf (-10^5, 2.5), 2.2747519231756221e-13, -tol_rel) ***** assert_equal (tcdf (-17.138, 147), 3.59494847838787e-37, -1e-13) ***** assert_equal (tcdf (17.138, 147, 'upper'), 3.59494847838787e-37, -1e-13) ***** assert_equal (tcdf (-8, 147), 1.70674966444924e-13, -1e-13) ***** assert_equal (tcdf (-1e10, 1), 3.18309886183791e-11, -1e-14) ***** assert_equal (tcdf (-1e5, 2), 4.99999999925002e-11, -1e-14) ***** assert_equal (tcdf (-1000, 3), 1.1026538212883e-09, -1e-13) 39 tests, 39 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/nbinpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/nbinpdf.m ***** demo ## Plot various PDFs from the negative binomial distribution x = 0:40; y1 = nbinpdf (x, 2, 0.15); y2 = nbinpdf (x, 5, 0.2); y3 = nbinpdf (x, 4, 0.4); y4 = nbinpdf (x, 10, 0.3); plot (x, y1, '*r', x, y2, '*g', x, y3, '*k', x, y4, '*m') grid on xlim ([0, 40]) ylim ([0, 0.12]) legend ({'r = 2, ps = 0.15', 'r = 5, ps = 0.2', 'r = 4, p = 0.4', ... 'r = 10, ps = 0.3'}, 'location', 'northeast') title ('Negative binomial PDF') xlabel ('values in x (number of failures)') ylabel ('density') ***** shared x, y x = [-1 0 1 2 Inf]; y = [0 1/2 1/4 1/8 0]; ***** assert_equal (nbinpdf (x, ones (1,5), 0.5*ones (1,5)), y) ***** assert_equal (nbinpdf (x, 1, 0.5*ones (1,5)), y) ***** assert_equal (nbinpdf (x, ones (1,5), 0.5), y) ***** assert_equal (nbinpdf (x, [0 1 NaN 1.5 Inf], 0.5), [NaN 1/2 NaN 1.875*0.5^1.5/4 NaN], eps) ***** assert_equal (nbinpdf (Inf, 5, 0.4), 0) ***** assert_equal (nbinpdf (x, 1, 0.5*[-1 NaN 4 1 1]), [NaN NaN NaN y(4:5)]) ***** assert_equal (nbinpdf ([x, NaN], 1, 0.5), [y, NaN]) ***** assert_equal (nbinpdf (1000, 1001, 0.5), 0.0089195055729428853, -1e-10) ***** assert_equal (nbinpdf (2000, 1001, 0.5), 1.2637737073869266e-76, -1e-10) ***** assert (all (isfinite (nbinpdf (0:2500, 1001, 0.5)))) ***** assert_equal (nbinpdf (single ([x, NaN]), 1, 0.5), single ([y, NaN])) ***** assert_equal (nbinpdf ([x, NaN], single (1), 0.5), single ([y, NaN])) ***** assert_equal (nbinpdf ([x, NaN], 1, single (0.5)), single ([y, NaN])) ***** error nbinpdf () ***** error nbinpdf (1) ***** error nbinpdf (1, 2) ***** error ... nbinpdf (ones (3), ones (2), ones (2)) ***** error ... nbinpdf (ones (2), ones (3), ones (2)) ***** error ... nbinpdf (ones (2), ones (2), ones (3)) ***** error nbinpdf (true, 2, 2) ***** error nbinpdf ('a', 2, 2) ***** assert_equal (class (nbinpdf (int32 (2), 2, 2)), 'double') ***** error nbinpdf (i, 2, 2) ***** error nbinpdf (2, i, 2) ***** error nbinpdf (2, 2, i) 25 tests, 25 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/hninv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/hninv.m ***** demo ## Plot various iCDFs from the half-normal distribution p = 0.001:0.001:0.999; x1 = hninv (p, 0, 1); x2 = hninv (p, 0, 2); x3 = hninv (p, 0, 3); x4 = hninv (p, 0, 5); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', p, x4, '-c') grid on ylim ([0, 10]) legend ({'μ = 0, σ = 1', 'μ = 0, σ = 2', ... 'μ = 0, σ = 3', 'μ = 0, σ = 5'}, 'location', 'northwest') title ('Half-normal iCDF') xlabel ('probability') ylabel ('x') ***** shared p, x p = [0, 0.3829, 0.6827, 1]; x = [0, 1/2, 1, Inf]; ***** assert_equal (hninv (p, 0, 1), x, 1e-4); ***** assert_equal (hninv (p, 5, 1), x + 5, 1e-4); ***** assert_equal (hninv (p, 0, ones (1,4)), x, 1e-4); ***** assert_equal (hninv (p, 0, [-1, 0, 1, 1]), [NaN, NaN, x(3:4)], 1e-4) ***** assert_equal (class (hninv (single ([p, NaN]), 0, 1)), "single") ***** assert_equal (class (hninv ([p, NaN], single (0), 1)), "single") ***** assert_equal (class (hninv ([p, NaN], 0, single (1))), "single") ***** error hninv (1) ***** error hninv (1, 2) ***** error ... hninv (1, ones (2), ones (3)) ***** error ... hninv (ones (2), 1, ones (3)) ***** error ... hninv (ones (2), ones (3), 1) ***** error hninv (int32 (2), 2, 3) ***** error hninv (true, 2, 3) ***** error hninv ('a', 2, 3) ***** error hninv (i, 2, 3) ***** error hninv (1, i, 3) ***** error hninv (1, 2, i) 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/invgpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/invgpdf.m ***** demo ## Plot various PDFs from the inverse Gaussian distribution x = 0:0.001:3; y1 = invgpdf (x, 1, 0.2); y2 = invgpdf (x, 1, 1); y3 = invgpdf (x, 1, 3); y4 = invgpdf (x, 3, 0.2); y5 = invgpdf (x, 3, 1); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', x, y4, '-c', x, y5, '-y') grid on xlim ([0, 3]) ylim ([0, 3]) legend ({'μ = 1, σ = 0.2', 'μ = 1, σ = 1', 'μ = 1, σ = 3', ... 'μ = 3, σ = 0.2', 'μ = 3, σ = 1'}, 'location', 'northeast') title ('Inverse Gaussian PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y x = [-Inf, -1, 0, 1/2, 1, Inf]; y = [0, 0, 0, 0.8788, 0.3989, 0]; ***** assert_equal (invgpdf ([x, NaN], 1, 1), [y, NaN], 1e-4) ***** assert_equal (invgpdf (x, 1, [-2, -1, 0, 1, 1, 1]), [nan(1,3), y([4:6])], 1e-4) ***** assert_equal (class (hncdf (single ([x, NaN]), 1, 1)), "single") ***** assert_equal (class (hncdf ([x, NaN], 1, single (1))), "single") ***** assert_equal (class (hncdf ([x, NaN], single (1), 1)), "single") ***** error invgpdf () ***** error invgpdf (1) ***** error invgpdf (1, 2) ***** error ... invgpdf (1, ones (2), ones (3)) ***** error ... invgpdf (ones (2), 1, ones (3)) ***** error ... invgpdf (ones (2), ones (3), 1) ***** error invgpdf (int32 (2), 2, 3) ***** error invgpdf (true, 2, 3) ***** error invgpdf ('a', 2, 3) ***** error invgpdf (i, 2, 3) ***** error invgpdf (1, i, 3) ***** error invgpdf (1, 2, i) 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/raylrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/raylrnd.m ***** assert_equal (size (raylrnd (2)), [1, 1]) ***** assert_equal (size (raylrnd (ones (2, 1))), [2, 1]) ***** assert_equal (size (raylrnd (ones (2, 2))), [2, 2]) ***** assert_equal (size (raylrnd (1, 3)), [3, 3]) ***** assert_equal (size (raylrnd (1, [4, 1])), [4, 1]) ***** assert_equal (size (raylrnd (1, 4, 1)), [4, 1]) ***** assert_equal (size (raylrnd (1, 4, 1)), [4, 1]) ***** assert_equal (size (raylrnd (1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (raylrnd (1, 0, 1)), [0, 1]) ***** assert_equal (size (raylrnd (1, 1, 0)), [1, 0]) ***** assert_equal (size (raylrnd (1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (raylrnd (1, [])), [0, 0]) ***** assert_equal (size (raylrnd (1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (raylrnd (1, -1)), [0, 0]) ***** assert_equal (size (raylrnd (1, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (raylrnd (1, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (raylrnd (0, 1, 1), NaN) ***** assert_equal (raylrnd ([0, 0, 0], [1, 3]), [NaN, NaN, NaN]) ***** assert_equal (class (raylrnd (2)), "double") ***** assert_equal (class (raylrnd (single (2))), "single") ***** assert_equal (class (raylrnd (single ([2, 2]))), "single") ***** error raylrnd () ***** error raylrnd (i) ***** error ... raylrnd (1, 1.2) ***** error ... raylrnd (1, ones (2)) ***** error ... raylrnd (1, [2 0 2.5]) ***** error ... raylrnd (ones (2), ones (2)) ***** error ... raylrnd (1, 2, 1.5, 5) ***** error raylrnd (ones (2,2), 3) ***** error raylrnd (ones (2,2), [3, 2]) ***** error raylrnd (ones (2,2), 2, 3) 31 tests, 31 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/invgrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/invgrnd.m ***** assert_equal (size (invgrnd (1, 1, 1)), [1, 1]) ***** assert_equal (size (invgrnd (1, 1, 2)), [2, 2]) ***** assert_equal (size (invgrnd (1, 1, [2, 1])), [2, 1]) ***** assert_equal (size (invgrnd (1, zeros (2, 2))), [2, 2]) ***** assert_equal (size (invgrnd (1, ones (2, 1))), [2, 1]) ***** assert_equal (size (invgrnd (1, ones (2, 2))), [2, 2]) ***** assert_equal (size (invgrnd (ones (2, 1), 1)), [2, 1]) ***** assert_equal (size (invgrnd (ones (2, 2), 1)), [2, 2]) ***** assert_equal (size (invgrnd (1, 1, 3)), [3, 3]) ***** assert_equal (size (invgrnd (1, 1, [4 1])), [4, 1]) ***** assert_equal (size (invgrnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (invgrnd (1, 1, [])), [0, 0]) ***** assert_equal (size (invgrnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (invgrnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (invgrnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (invgrnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** test r = invgrnd (1, [1, 0, -1]); assert_equal (r([2:3]), [NaN, NaN]) ***** assert_equal (class (invgrnd (1, 0)), "double") ***** assert_equal (class (invgrnd (1, single (0))), "single") ***** assert_equal (class (invgrnd (1, single ([0, 0]))), "single") ***** assert_equal (class (invgrnd (1, single (1))), "single") ***** assert_equal (class (invgrnd (1, single ([1, 1]))), "single") ***** assert_equal (class (invgrnd (single (1), 1)), "single") ***** assert_equal (class (invgrnd (single ([1, 1]), 1)), "single") ***** error invgrnd () ***** error invgrnd (1) ***** error ... invgrnd (ones (3), ones (2)) ***** error ... invgrnd (ones (2), ones (3)) ***** error invgrnd (i, 2, 3) ***** error invgrnd (1, i, 3) ***** error ... invgrnd (1, 2, 1.2) ***** error ... invgrnd (1, 2, ones (2)) ***** error ... invgrnd (1, 2, [2 0 2.5]) ***** error ... invgrnd (1, 2, 2, 1.5, 5) ***** error ... invgrnd (2, ones (2), 3) ***** error ... invgrnd (2, ones (2), [3, 2]) ***** error ... invgrnd (2, ones (2), 3, 2) 37 tests, 37 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/nbincdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/nbincdf.m ***** demo ## Plot various CDFs from the negative binomial distribution x = 0:50; p1 = nbincdf (x, 2, 0.15); p2 = nbincdf (x, 5, 0.2); p3 = nbincdf (x, 4, 0.4); p4 = nbincdf (x, 10, 0.3); plot (x, p1, '*r', x, p2, '*g', x, p3, '*k', x, p4, '*m') grid on xlim ([0, 40]) legend ({'r = 2, ps = 0.15', 'r = 5, ps = 0.2', 'r = 4, p = 0.4', ... 'r = 10, ps = 0.3'}, 'location', 'southeast') title ('Negative binomial CDF') xlabel ('values in x (number of failures)') ylabel ('probability') ***** shared x, y x = [-1 0 1 2 Inf]; y = [0 1/2 3/4 7/8 1]; ***** assert_equal (nbincdf (x, ones (1,5), 0.5*ones (1,5)), y) ***** assert_equal (nbincdf (x, 1, 0.5*ones (1,5)), y) ***** assert_equal (nbincdf (x, ones (1,5), 0.5), y) ***** assert_equal (nbincdf (x, ones (1,5), 0.5, 'upper'), 1 - y, eps) ***** assert_equal (nbincdf ([x(1:3) 0 x(5)], [0 1 NaN 1.5 Inf], 0.5), ... [NaN 1/2 NaN nbinpdf(0,1.5,0.5) NaN], eps) ***** assert_equal (nbincdf (x, 1, 0.5*[-1 NaN 4 1 1]), [NaN NaN NaN y(4:5)]) ***** assert_equal (nbincdf ([x(1:2) NaN x(4:5)], 1, 0.5), [y(1:2) NaN y(4:5)]) ***** assert_equal (nbincdf (1000, 1001, 0.5), 0.5, 1e-11) ***** assert (all (isfinite (nbincdf (0:2500, 1001, 0.5)))) ***** assert (all (diff (nbincdf (0:2500, 1001, 0.5)) >= 0)) ***** assert_equal (nbincdf ([x, NaN], 1, 0.5), [y, NaN]) ***** assert_equal (nbincdf (single ([x, NaN]), 1, 0.5), single ([y, NaN])) ***** assert_equal (nbincdf ([x, NaN], single (1), 0.5), single ([y, NaN])) ***** assert_equal (nbincdf ([x, NaN], 1, single (0.5)), single ([y, NaN])) ***** error nbincdf () ***** error nbincdf (1) ***** error nbincdf (1, 2) ***** error nbincdf (1, 2, 3, 4) ***** error nbincdf (1, 2, 3, 'some') ***** error ... nbincdf (ones (3), ones (2), ones (2)) ***** error ... nbincdf (ones (2), ones (3), ones (2)) ***** error ... nbincdf (ones (2), ones (2), ones (3)) ***** error nbincdf (true, 2, 2) ***** error nbincdf ('a', 2, 2) ***** assert_equal (class (nbincdf (int32 (2), 2, 2)), 'double') ***** error nbincdf (i, 2, 2) ***** error nbincdf (2, i, 2) ***** error nbincdf (2, 2, i) 28 tests, 28 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/iwishrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/iwishrnd.m ***** assert_equal (size (iwishrnd (1,2,1)), [1, 1]); ***** assert_equal (size (iwishrnd ([],2,1)), [1, 1]); ***** assert_equal (size (iwishrnd ([3 1; 1 3], 2.00001, [], 1)), [2, 2]); ***** assert_equal (size (iwishrnd (eye (2), 2, [], 3)), [2, 2, 3]); ***** error iwishrnd () ***** error iwishrnd (1) ***** error iwishrnd ([-3 1; 1 3],1) ***** error iwishrnd ([1; 1],1) 8 tests, 8 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/nctpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/nctpdf.m ***** demo ## Plot various PDFs from the noncentral T distribution x = -5:0.01:10; y1 = nctpdf (x, 1, 0); y2 = nctpdf (x, 4, 0); y3 = nctpdf (x, 1, 2); y4 = nctpdf (x, 4, 2); plot (x, y1, '-r', x, y2, '-g', x, y3, '-k', x, y4, '-m') grid on xlim ([-5, 10]) ylim ([0, 0.4]) legend ({'df = 1, μ = 0', 'df = 4, μ = 0', ... 'df = 1, μ = 2', 'df = 4, μ = 2'}, 'location', 'northeast') title ('Noncentral T PDF') xlabel ('values in x') ylabel ('density') ***** demo ## Compare the noncentral T PDF with MU = 1 to the T PDF ## with the same number of degrees of freedom (10). x = -5:0.1:5; y1 = nctpdf (x, 10, 1); y2 = tpdf (x, 10); plot (x, y1, '-', x, y2, '-'); grid on xlim ([-5, 5]) ylim ([0, 0.4]) legend ({'Noncentral χ^2(4,2)', 'χ^2(4)'}, 'location', 'northwest') title ('Noncentral T vs T PDFs') xlabel ('values in x') ylabel ('density') ***** shared x1, df, mu x1 = [-Inf, 2, NaN, 4, Inf]; df = [2, 0, -1, 1, 4]; mu = [1, NaN, 3, -1, 2]; ***** assert_equal (nctpdf (x1, df, mu), [0, NaN, NaN, 0.00401787561306999, 0], 1e-14); ***** assert_equal (nctpdf (x1, df, 1), [0, NaN, NaN, 0.0482312135423008, 0], 1e-14); ***** assert_equal (nctpdf (x1, df, 3), [0, NaN, NaN, 0.1048493126401585, 0], 1e-14); ***** assert_equal (nctpdf (x1, df, 2), [0, NaN, NaN, 0.08137377919890307, 0], 1e-14); ***** assert_equal (nctpdf (x1, 3, mu), [0, NaN, NaN, 0.001185305171654381, 0], 1e-14); ***** assert_equal (nctpdf (2, df, mu), [0.1791097459405861, NaN, NaN, ... 0.0146500727180389, 0.3082302682110299], 1e-14); ***** assert_equal (nctpdf (4, df, mu), [0.04467929612254971, NaN, NaN, ... 0.00401787561306999, 0.0972086534042828], 1e-14); ***** error nctpdf () ***** error nctpdf (1) ***** error nctpdf (1, 2) ***** error ... nctpdf (ones (3), ones (2), ones (2)) ***** error ... nctpdf (ones (2), ones (3), ones (2)) ***** error ... nctpdf (ones (2), ones (2), ones (3)) ***** error nctpdf (int32 (2), 2, 2) ***** error nctpdf (true, 2, 2) ***** error nctpdf ('a', 2, 2) ***** error nctpdf (i, 2, 2) ***** error nctpdf (2, i, 2) ***** error nctpdf (2, 2, i) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/geoinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/geoinv.m ***** demo ## Plot various iCDFs from the geometric distribution p = 0.001:0.001:0.999; x1 = geoinv (p, 0.2); x2 = geoinv (p, 0.5); x3 = geoinv (p, 0.7); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r') grid on ylim ([0, 10]) legend ({'ps = 0.2', 'ps = 0.5', 'ps = 0.7'}, 'location', 'northwest') title ('Geometric iCDF') xlabel ('probability') ylabel ('values in x (number of failures)') ***** shared p p = [-1 0 0.75 1 2]; ***** assert_equal (geoinv (p, 0.5*ones (1,5)), [NaN 0 1 Inf NaN]) ***** assert_equal (geoinv (p, 0.5), [NaN 0 1 Inf NaN]) ***** assert_equal (geoinv (p, 0.5*[1 -1 NaN 4 1]), [NaN NaN NaN NaN NaN]) ***** assert_equal (geoinv ([p(1:2) NaN p(4:5)], 0.5), [NaN 0 NaN Inf NaN]) ***** assert_equal (geoinv ([p, NaN], 0.5), [NaN 0 1 Inf NaN NaN]) ***** assert_equal (geoinv (single ([p, NaN]), 0.5), single ([NaN 0 1 Inf NaN NaN])) ***** assert_equal (geoinv ([p, NaN], single (0.5)), single ([NaN 0 1 Inf NaN NaN])) ***** error geoinv () ***** error geoinv (1) ***** error ... geoinv (ones (3), ones (2)) ***** error ... geoinv (ones (2), ones (3)) ***** error ... geoinv (int32 (2), 2) ***** error ... geoinv (true, 2) ***** error ... geoinv ('a', 2) ***** error ... geoinv (i, 2) ***** error ... geoinv (2, i) 16 tests, 16 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/ncfpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/ncfpdf.m ***** demo ## Plot various PDFs from the noncentral F distribution x = 0:0.01:5; y1 = ncfpdf (x, 2, 5, 1); y2 = ncfpdf (x, 2, 5, 2); y3 = ncfpdf (x, 5, 10, 1); y4 = ncfpdf (x, 10, 20, 10); plot (x, y1, '-r', x, y2, '-g', x, y3, '-k', x, y4, '-m') grid on xlim ([0, 5]) ylim ([0, 0.8]) legend ({'df1 = 2, df2 = 5, λ = 1', 'df1 = 2, df2 = 5, λ = 2', ... 'df1 = 5, df2 = 10, λ = 1', 'df1 = 10, df2 = 20, λ = 10'}, ... 'location', 'northeast') title ('Noncentral F PDF') xlabel ('values in x') ylabel ('density') ***** demo ## Compare the noncentral F PDF with LAMBDA = 10 to the F PDF with the ## same number of numerator and denominator degrees of freedom (5, 20) x = 0.01:0.1:10.01; y1 = ncfpdf (x, 5, 20, 10); y2 = fpdf (x, 5, 20); plot (x, y1, '-', x, y2, '-'); grid on xlim ([0, 10]) ylim ([0, 0.8]) legend ({'Noncentral F(5,20,10)', 'F(5,20)'}, 'location', 'northeast') title ('Noncentral F vs F PDFs') xlabel ('values in x') ylabel ('density') ***** shared x1, df1, df2, lambda x1 = [-Inf, 2, NaN, 4, Inf]; df1 = [2, 0, -1, 1, 4]; df2 = [2, 4, 5, 6, 8]; lambda = [1, NaN, 3, -1, 2]; ***** assert_equal (ncfpdf (x1, df1, df2, lambda), [0, NaN, NaN, NaN, NaN]); ***** assert_equal (ncfpdf (x1, df1, df2, 1), [0, NaN, NaN, ... 0.05607937264237208, NaN], 1e-14); ***** assert_equal (ncfpdf (x1, df1, df2, 3), [0, NaN, NaN, ... 0.080125760971946518, NaN], 1e-14); ***** assert_equal (ncfpdf (x1, df1, df2, 2), [0, NaN, NaN, ... 0.0715902008258656, NaN], 1e-14); ***** assert_equal (ncfpdf (x1, 3, 5, lambda), [0, NaN, NaN, NaN, NaN]); ***** assert_equal (ncfpdf (2, df1, df2, lambda), [0.1254046999837947, NaN, NaN, ... NaN, 0.2152571783045893], 1e-14); ***** assert_equal (ncfpdf (4, df1, df2, lambda), [0.05067089541001374, NaN, NaN, ... NaN, 0.05560846335398539], 1e-14); ***** error ncfpdf () ***** error ncfpdf (1) ***** error ncfpdf (1, 2) ***** error ncfpdf (1, 2, 3) ***** error ... ncfpdf (ones (3), ones (2), ones (2), ones (2)) ***** error ... ncfpdf (ones (2), ones (3), ones (2), ones (2)) ***** error ... ncfpdf (ones (2), ones (2), ones (3), ones (2)) ***** error ... ncfpdf (ones (2), ones (2), ones (2), ones (3)) ***** error ncfpdf (int32 (2), 2, 2, 2) ***** error ncfpdf (true, 2, 2, 2) ***** error ncfpdf ('a', 2, 2, 2) ***** error ncfpdf (i, 2, 2, 2) ***** error ncfpdf (2, i, 2, 2) ***** error ncfpdf (2, 2, i, 2) ***** error ncfpdf (2, 2, 2, i) 22 tests, 22 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/poissinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/poissinv.m ***** demo ## Plot various iCDFs from the Poisson distribution p = 0.001:0.001:0.999; x1 = poissinv (p, 13); x2 = poissinv (p, 4); x3 = poissinv (p, 10); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r') grid on ylim ([0, 20]) legend ({'λ = 1', 'λ = 4', 'λ = 10'}, 'location', 'northwest') title ('Poisson iCDF') xlabel ('probability') ylabel ('values in x (number of occurrences)') ***** shared p p = [-1 0 0.5 1 2]; ***** assert_equal (poissinv (p, ones (1,5)), [NaN 0 1 Inf NaN]) ***** assert_equal (poissinv (p, 1), [NaN 0 1 Inf NaN]) ***** assert_equal (poissinv (p, [1 0 NaN 1 1]), [NaN NaN NaN Inf NaN]) ***** assert_equal (poissinv ([p(1:2) NaN p(4:5)], 1), [NaN 0 NaN Inf NaN]) ***** assert_equal (poissinv ([p, NaN], 1), [NaN 0 1 Inf NaN NaN]) ***** assert_equal (poissinv (single ([p, NaN]), 1), single ([NaN 0 1 Inf NaN NaN])) ***** assert_equal (poissinv ([p, NaN], single (1)), single ([NaN 0 1 Inf NaN NaN])) ***** error poissinv () ***** error poissinv (1) ***** error ... poissinv (ones (3), ones (2)) ***** error ... poissinv (ones (2), ones (3)) ***** error poissinv (int32 (2), 2) ***** error poissinv (true, 2) ***** error poissinv ('a', 2) ***** error poissinv (i, 2) ***** error poissinv (2, i) 16 tests, 16 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/cauchyinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/cauchyinv.m ***** demo ## Plot various iCDFs from the Cauchy distribution p = 0.001:0.001:0.999; x1 = cauchyinv (p, 0, 0.5); x2 = cauchyinv (p, 0, 1); x3 = cauchyinv (p, 0, 2); x4 = cauchyinv (p, -2, 1); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', p, x4, '-c') grid on ylim ([-5, 5]) legend ({'x0 = 0, γ = 0.5', 'x0 = 0, γ = 1', ... 'x0 = 0, γ = 2', 'x0 = -2, γ = 1'}, 'location', 'northwest') title ('Cauchy iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p p = [-1 0 0.5 1 2]; ***** assert_equal (cauchyinv (p, ones (1,5), 2 * ones (1,5)), [NaN -Inf 1 Inf NaN], eps) ***** assert_equal (cauchyinv (p, 1, 2 * ones (1,5)), [NaN -Inf 1 Inf NaN], eps) ***** assert_equal (cauchyinv (p, ones (1,5), 2), [NaN -Inf 1 Inf NaN], eps) ***** assert_equal (cauchyinv (p, [1 -Inf NaN Inf 1], 2), [NaN NaN NaN NaN NaN]) ***** assert_equal (cauchyinv (p, 1, 2 * [1 0 NaN Inf 1]), [NaN NaN NaN NaN NaN]) ***** assert_equal (cauchyinv ([p(1:2) NaN p(4:5)], 1, 2), [NaN -Inf NaN Inf NaN]) ***** assert_equal (cauchyinv ([p, NaN], 1, 2), [NaN -Inf 1 Inf NaN NaN], eps) ***** assert_equal (cauchyinv (single ([p, NaN]), 1, 2), ... single ([NaN -Inf 1 Inf NaN NaN]), eps ('single')) ***** assert_equal (cauchyinv ([p, NaN], single (1), 2), ... single ([NaN -Inf 1 Inf NaN NaN]), eps ('single')) ***** assert_equal (cauchyinv ([p, NaN], 1, single (2)), ... single ([NaN -Inf 1 Inf NaN NaN]), eps ('single')) ***** error cauchyinv () ***** error cauchyinv (1) ***** error ... cauchyinv (1, 2) ***** error cauchyinv (1, 2, 3, 4) ***** error ... cauchyinv (ones (3), ones (2), ones (2)) ***** error ... cauchyinv (ones (2), ones (3), ones (2)) ***** error ... cauchyinv (ones (2), ones (2), ones (3)) ***** error cauchyinv (int32 (2), 4, 3) ***** error cauchyinv (true, 4, 3) ***** error cauchyinv ('a', 4, 3) ***** error cauchyinv (i, 4, 3) ***** error cauchyinv (1, i, 3) ***** error cauchyinv (1, 4, i) 23 tests, 23 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/exppdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/exppdf.m ***** demo ## Plot various PDFs from the exponential distribution x = 0:0.01:5; y1 = exppdf (x, 2/3); y2 = exppdf (x, 1.0); y3 = exppdf (x, 2.0); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r') grid on ylim ([0, 1.5]) legend ({'μ = 2/3', 'μ = 1', 'μ = 2'}, 'location', 'northeast') title ('Exponential PDF') xlabel ('values in x') ylabel ('density') ***** shared x,y x = [-1 0 0.5 1 Inf]; y = gampdf (x, 1, 2); ***** assert_equal (exppdf (x, 2*ones (1,5)), y) ***** assert_equal (exppdf (x, 2*[1 0 NaN 1 1]), [y(1) NaN NaN y(4:5)]) ***** assert_equal (exppdf ([x, NaN], 2), [y, NaN]) ***** assert_equal (exppdf (single ([x, NaN]), 2), single ([y, NaN])) ***** assert_equal (exppdf ([x, NaN], single (2)), single ([y, NaN])) ***** error exppdf () ***** error exppdf (1,2,3) ***** error ... exppdf (ones (3), ones (2)) ***** error ... exppdf (ones (2), ones (3)) ***** error exppdf (int32 (2), 2) ***** error exppdf (true, 2) ***** error exppdf ('a', 2) ***** error exppdf (i, 2) ***** error exppdf (2, i) 14 tests, 14 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/gpcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/gpcdf.m ***** demo ## Plot various CDFs from the generalized Pareto distribution x = 0:0.001:5; p1 = gpcdf (x, 1, 1, 0); p2 = gpcdf (x, 5, 1, 0); p3 = gpcdf (x, 20, 1, 0); p4 = gpcdf (x, 1, 2, 0); p5 = gpcdf (x, 5, 2, 0); p6 = gpcdf (x, 20, 2, 0); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', ... x, p4, '-c', x, p5, '-m', x, p6, '-k') grid on xlim ([0, 5]) legend ({'k = 1, σ = 1, θ = 0', 'k = 5, σ = 1, θ = 0', ... 'k = 20, σ = 1, θ = 0', 'k = 1, σ = 2, θ = 0', ... 'k = 5, σ = 2, θ = 0', 'k = 20, σ = 2, θ = 0'}, ... 'location', 'northwest') title ('Generalized Pareto CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y1, y1u, y2, y2u, y3, y3u x = [-Inf, -1, 0, 1/2, 1, Inf]; y1 = [0, 0, 0, 0.3934693402873666, 0.6321205588285577, 1]; y1u = [1, 1, 1, 0.6065306597126334, 0.3678794411714423, 0]; y2 = [0, 0, 0, 1/3, 1/2, 1]; y2u = [1, 1, 1, 2/3, 1/2, 0]; y3 = [0, 0, 0, 1/2, 1, 1]; y3u = [1, 1, 1, 1/2, 0, 0]; ***** assert_equal (gpcdf (x, zeros (1,6), ones (1,6), zeros (1,6)), y1, eps) ***** assert_equal (gpcdf (x, 0, 1, zeros (1,6)), y1, eps) ***** assert_equal (gpcdf (x, 0, ones (1,6), 0), y1, eps) ***** assert_equal (gpcdf (x, zeros (1,6), 1, 0), y1, eps) ***** assert_equal (gpcdf (x, 0, 1, 0), y1, eps) ***** assert_equal (gpcdf (x, 0, 1, [0, 0, 0, NaN, 0, 0]), [y1(1:3), NaN, y1(5:6)], eps) ***** assert_equal (gpcdf (x, 0, [1, 1, 1, NaN, 1, 1], 0), [y1(1:3), NaN, y1(5:6)], eps) ***** assert_equal (gpcdf (x, [0, 0, 0, NaN, 0, 0], 1, 0), [y1(1:3), NaN, y1(5:6)], eps) ***** assert_equal (gpcdf ([x(1:3), NaN, x(5:6)], 0, 1, 0), [y1(1:3), NaN, y1(5:6)], eps) ***** assert_equal (gpcdf (x, zeros (1,6), ones (1,6), zeros (1,6), 'upper'), y1u, eps) ***** assert_equal (gpcdf (x, 0, 1, zeros (1,6), 'upper'), y1u, eps) ***** assert_equal (gpcdf (x, 0, ones (1,6), 0, 'upper'), y1u, eps) ***** assert_equal (gpcdf (x, zeros (1,6), 1, 0, 'upper'), y1u, eps) ***** assert_equal (gpcdf (x, 0, 1, 0, 'upper'), y1u, eps) ***** assert_equal (gpcdf (x, ones (1,6), ones (1,6), zeros (1,6)), y2, eps) ***** assert_equal (gpcdf (x, 1, 1, zeros (1,6)), y2, eps) ***** assert_equal (gpcdf (x, 1, ones (1,6), 0), y2, eps) ***** assert_equal (gpcdf (x, ones (1,6), 1, 0), y2, eps) ***** assert_equal (gpcdf (x, 1, 1, 0), y2, eps) ***** assert_equal (gpcdf (x, 1, 1, [0, 0, 0, NaN, 0, 0]), [y2(1:3), NaN, y2(5:6)], eps) ***** assert_equal (gpcdf (x, 1, [1, 1, 1, NaN, 1, 1], 0), [y2(1:3), NaN, y2(5:6)], eps) ***** assert_equal (gpcdf (x, [1, 1, 1, NaN, 1, 1], 1, 0), [y2(1:3), NaN, y2(5:6)], eps) ***** assert_equal (gpcdf ([x(1:3), NaN, x(5:6)], 1, 1, 0), [y2(1:3), NaN, y2(5:6)], eps) ***** assert_equal (gpcdf (x, ones (1,6), ones (1,6), zeros (1,6), 'upper'), y2u, eps) ***** assert_equal (gpcdf (x, 1, 1, zeros (1,6), 'upper'), y2u, eps) ***** assert_equal (gpcdf (x, 1, ones (1,6), 0, 'upper'), y2u, eps) ***** assert_equal (gpcdf (x, ones (1,6), 1, 0, 'upper'), y2u, eps) ***** assert_equal (gpcdf (x, 1, 1, 0, 'upper'), y2u, eps) ***** assert_equal (gpcdf (x, 1, 1, [0, 0, 0, NaN, 0, 0], 'upper'), ... [y2u(1:3), NaN, y2u(5:6)], eps) ***** assert_equal (gpcdf (x, 1, [1, 1, 1, NaN, 1, 1], 0, 'upper'), ... [y2u(1:3), NaN, y2u(5:6)], eps) ***** assert_equal (gpcdf (x, [1, 1, 1, NaN, 1, 1], 1, 0, 'upper'), ... [y2u(1:3), NaN, y2u(5:6)], eps) ***** assert_equal (gpcdf ([x(1:3), NaN, x(5:6)], 1, 1, 0, 'upper'), ... [y2u(1:3), NaN, y2u(5:6)], eps) ***** assert_equal (gpcdf (x, -ones (1,6), ones (1,6), zeros (1,6)), y3, eps) ***** assert_equal (gpcdf (x, -1, 1, zeros (1,6)), y3, eps) ***** assert_equal (gpcdf (x, -1, ones (1,6), 0), y3, eps) ***** assert_equal (gpcdf (x, -ones (1,6), 1, 0), y3, eps) ***** assert_equal (gpcdf (x, -1, 1, 0), y3, eps) ***** assert_equal (gpcdf (x, -1, 1, [0, 0, 0, NaN, 0, 0]), [y3(1:3), NaN, y3(5:6)], eps) ***** assert_equal (gpcdf (x, -1, [1, 1, 1, NaN, 1, 1], 0), [y3(1:3), NaN, y3(5:6)], eps) ***** assert_equal (gpcdf (x, [-1, -1, -1, NaN, -1, -1], 1, 0), [y3(1:3), NaN, y3(5:6)], eps) ***** assert_equal (gpcdf ([x(1:3), NaN, x(5:6)], -1, 1, 0), [y3(1:3), NaN, y3(5:6)], eps) ***** assert_equal (gpcdf (x, -ones (1,6), ones (1,6), zeros (1,6), 'upper'), y3u, eps) ***** assert_equal (gpcdf (x, -1, 1, zeros (1,6), 'upper'), y3u, eps) ***** assert_equal (gpcdf (x, -1, ones (1,6), 0, 'upper'), y3u, eps) ***** assert_equal (gpcdf (x, -ones (1,6), 1, 0, 'upper'), y3u, eps) ***** assert_equal (gpcdf (x, -1, 1, 0, 'upper'), y3u, eps) ***** assert_equal (gpcdf (x, -1, 1, [0, 0, 0, NaN, 0, 0], 'upper'), ... [y3u(1:3), NaN, y3u(5:6)], eps) ***** assert_equal (gpcdf (x, -1, [1, 1, 1, NaN, 1, 1], 0, 'upper'), ... [y3u(1:3), NaN, y3u(5:6)], eps) ***** assert_equal (gpcdf (x, [-1, -1, -1, NaN, -1, -1], 1, 0, 'upper'), ... [y3u(1:3), NaN, y3u(5:6)], eps) ***** assert_equal (gpcdf ([x(1:3), NaN, x(5:6)], -1, 1, 0, 'upper'), ... [y3u(1:3), NaN, y3u(5:6)], eps) ***** assert_equal (gpcdf (single ([x, NaN]), 0, 1, 0), single ([y1, NaN]), eps ('single')) ***** assert_equal (gpcdf ([x, NaN], 0, 1, single (0)), single ([y1, NaN]), eps ('single')) ***** assert_equal (gpcdf ([x, NaN], 0, single (1), 0), single ([y1, NaN]), eps ('single')) ***** assert_equal (gpcdf ([x, NaN], single (0), 1, 0), single ([y1, NaN]), eps ('single')) ***** assert_equal (gpcdf (single ([x, NaN]), 1, 1, 0), single ([y2, NaN]), eps ('single')) ***** assert_equal (gpcdf ([x, NaN], 1, 1, single (0)), single ([y2, NaN]), eps ('single')) ***** assert_equal (gpcdf ([x, NaN], 1, single (1), 0), single ([y2, NaN]), eps ('single')) ***** assert_equal (gpcdf ([x, NaN], single (1), 1, 0), single ([y2, NaN]), eps ('single')) ***** assert_equal (gpcdf (single ([x, NaN]), -1, 1, 0), single ([y3, NaN]), eps ('single')) ***** assert_equal (gpcdf ([x, NaN], -1, 1, single (0)), single ([y3, NaN]), eps ('single')) ***** assert_equal (gpcdf ([x, NaN], -1, single (1), 0), single ([y3, NaN]), eps ('single')) ***** assert_equal (gpcdf ([x, NaN], single (-1), 1, 0), single ([y3, NaN]), eps ('single')) ***** error gpcdf () ***** error gpcdf (1) ***** error gpcdf (1, 2) ***** error gpcdf (1, 2, 3) ***** error gpcdf (1, 2, 3, 4, 'tail') ***** error gpcdf (1, 2, 3, 4, 5) ***** error ... gpcdf (ones (3), ones (2), ones (2), ones (2)) ***** error ... gpcdf (ones (2), ones (3), ones (2), ones (2)) ***** error ... gpcdf (ones (2), ones (2), ones (3), ones (2)) ***** error ... gpcdf (ones (2), ones (2), ones (2), ones (3)) ***** error gpcdf (int32 (2), 2, 3, 4) ***** error gpcdf (true, 2, 3, 4) ***** error gpcdf ('a', 2, 3, 4) ***** error gpcdf (i, 2, 3, 4) ***** error gpcdf (1, i, 3, 4) ***** error gpcdf (1, 2, i, 4) ***** error gpcdf (1, 2, 3, i) 79 tests, 79 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/gaminv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/gaminv.m ***** demo ## Plot various iCDFs from the Gamma distribution p = 0.001:0.001:0.999; x1 = gaminv (p, 1, 2); x2 = gaminv (p, 2, 2); x3 = gaminv (p, 3, 2); x4 = gaminv (p, 5, 1); x5 = gaminv (p, 9, 0.5); x6 = gaminv (p, 7.5, 1); x7 = gaminv (p, 0.5, 1); plot (p, x1, '-r', p, x2, '-g', p, x3, '-y', p, x4, '-m', ... p, x5, '-k', p, x6, '-b', p, x7, '-c') ylim ([0, 20]) grid on legend ({'α = 1, β = 2', 'α = 2, β = 2', 'α = 3, β = 2', ... 'α = 5, β = 1', 'α = 9, β = 0.5', 'α = 7.5, β = 1', ... 'α = 0.5, β = 1'}, 'location', 'northwest') title ('Gamma iCDF') xlabel ('probability') ylabel ('x') ***** shared p p = [-1 0 0.63212055882855778 1 2]; ***** assert_equal (gaminv (p, ones (1,5), ones (1,5)), [NaN 0 1 Inf NaN], eps) ***** assert_equal (gaminv (p, 1, ones (1,5)), [NaN 0 1 Inf NaN], eps) ***** assert_equal (gaminv (p, ones (1,5), 1), [NaN 0 1 Inf NaN], eps) ***** assert_equal (gaminv (p, [1 -Inf NaN Inf 1], 1), [NaN NaN NaN NaN NaN]) ***** assert_equal (gaminv (p, 1, [1 -Inf NaN Inf 1]), [NaN NaN NaN NaN NaN]) ***** assert_equal (gaminv ([p(1:2) NaN p(4:5)], 1, 1), [NaN 0 NaN Inf NaN]) ***** assert_equal (gaminv ([p(1:2) NaN p(4:5)], 1, 1), [NaN 0 NaN Inf NaN]) ***** assert_equal (gaminv (1e-16, 1, 1), 1e-16, eps) ***** assert_equal (gaminv (1e-16, 1, 2), 2e-16, eps) ***** assert_equal (gaminv (1e-20, 3, 5), 1.957434012161815e-06, eps) ***** assert_equal (gaminv (1e-15, 1, 1), 1e-15, eps) ***** assert_equal (gaminv (1e-35, 1, 1), 1e-35, eps) ***** assert_equal (gaminv ([p, NaN], 1, 1), [NaN 0 1 Inf NaN NaN], eps) ***** assert_equal (gaminv (single ([p, NaN]), 1, 1), single ([NaN 0 1 Inf NaN NaN]), ... eps ('single')) ***** assert_equal (gaminv ([p, NaN], single (1), 1), single ([NaN 0 1 Inf NaN NaN]), ... eps ('single')) ***** assert_equal (gaminv ([p, NaN], 1, single (1)), single ([NaN 0 1 Inf NaN NaN]), ... eps ('single')) ***** error gaminv () ***** error gaminv (1) ***** error gaminv (1,2) ***** error ... gaminv (ones (3), ones (2), ones (2)) ***** error ... gaminv (ones (2), ones (3), ones (2)) ***** error ... gaminv (ones (2), ones (2), ones (3)) ***** error gaminv (int32 (2), 2, 2) ***** error gaminv (true, 2, 2) ***** error gaminv ('a', 2, 2) ***** error gaminv (i, 2, 2) ***** error gaminv (2, i, 2) ***** error gaminv (2, 2, i) 28 tests, 28 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/fcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/fcdf.m ***** demo ## Plot various CDFs from the F distribution x = 0.01:0.01:4; p1 = fcdf (x, 1, 2); p2 = fcdf (x, 2, 1); p3 = fcdf (x, 5, 2); p4 = fcdf (x, 10, 1); p5 = fcdf (x, 100, 100); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', x, p4, '-c', x, p5, '-m') grid on legend ({'df1 = 1, df2 = 2', 'df1 = 2, df2 = 1', ... 'df1 = 5, df2 = 2', 'df1 = 10, df2 = 1', ... 'df1 = 100, df2 = 100'}, 'location', 'southeast') title ('F CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y x = [-1, 0, 0.5, 1, 2, Inf]; y = [0, 0, 1/3, 1/2, 2/3, 1]; ***** assert_equal (fcdf (x, 2*ones (1,6), 2*ones (1,6)), y, eps) ***** assert_equal (fcdf (x, 2, 2*ones (1,6)), y, eps) ***** assert_equal (fcdf (x, 2*ones (1,6), 2), y, eps) ***** assert_equal (fcdf (x, [0 NaN Inf 2 2 2], 2), [NaN NaN 0.1353352832366127 y(4:6)], eps) ***** assert_equal (fcdf (x, 2, [0 NaN Inf 2 2 2]), [NaN NaN 0.3934693402873666 y(4:6)], eps) ***** assert_equal (fcdf ([x(1:2) NaN x(4:6)], 2, 2), [y(1:2) NaN y(4:6)], eps) ***** assert_equal (fcdf ([x, NaN], 2, 2), [y, NaN], eps) ***** assert_equal (fcdf (single ([x, NaN]), 2, 2), single ([y, NaN]), eps ('single')) ***** assert_equal (fcdf ([x, NaN], single (2), 2), single ([y, NaN]), eps ('single')) ***** assert_equal (fcdf ([x, NaN], 2, single (2)), single ([y, NaN]), eps ('single')) ***** error fcdf () ***** error fcdf (1) ***** error fcdf (1, 2) ***** error fcdf (1, 2, 3, 4) ***** error fcdf (1, 2, 3, 'tail') ***** error ... fcdf (ones (3), ones (2), ones (2)) ***** error ... fcdf (ones (2), ones (3), ones (2)) ***** error ... fcdf (ones (2), ones (2), ones (3)) ***** error fcdf (int32 (2), 2, 2) ***** error fcdf (true, 2, 2) ***** error fcdf ('a', 2, 2) ***** error fcdf (i, 2, 2) ***** error fcdf (2, i, 2) ***** error fcdf (2, 2, i) 24 tests, 24 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/bisacdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/bisacdf.m ***** demo ## Plot various CDFs from the Birnbaum-Saunders distribution x = 0.01:0.01:4; p1 = bisacdf (x, 1, 0.5); p2 = bisacdf (x, 1, 1); p3 = bisacdf (x, 1, 2); p4 = bisacdf (x, 1, 5); p5 = bisacdf (x, 1, 10); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', x, p4, '-c', x, p5, '-m') grid on legend ({'β = 1, γ = 0.5', 'β = 1, γ = 1', 'β = 1, γ = 2', ... 'β = 1, γ = 5', 'β = 1, γ = 10'}, 'location', 'southeast') title ('Birnbaum-Saunders CDF') xlabel ('values in x') ylabel ('probability') ***** demo ## Plot various CDFs from the Birnbaum-Saunders distribution x = 0.01:0.01:6; p1 = bisacdf (x, 1, 0.3); p2 = bisacdf (x, 2, 0.3); p3 = bisacdf (x, 1, 0.5); p4 = bisacdf (x, 3, 0.5); p5 = bisacdf (x, 5, 0.5); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', x, p4, '-c', x, p5, '-m') grid on legend ({'β = 1, γ = 0.3', 'β = 2, γ = 0.3', 'β = 1, γ = 0.5', ... 'β = 3, γ = 0.5', 'β = 5, γ = 0.5'}, 'location', 'southeast') title ('Birnbaum-Saunders CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y x = [-1, 0, 1, 2, Inf]; y = [0, 0, 1/2, 0.76024993890652337, 1]; ***** assert_equal (bisacdf (x, ones (1,5), ones (1,5)), y, eps) ***** assert_equal (bisacdf (x, 1, 1), y, eps) ***** assert_equal (bisacdf (x, 1, ones (1,5)), y, eps) ***** assert_equal (bisacdf (x, ones (1,5), 1), y, eps) ***** assert_equal (bisacdf (x, 1, 1), y, eps) ***** assert_equal (bisacdf (x, 1, [1, 1, NaN, 1, 1]), [y(1:2), NaN, y(4:5)], eps) ***** assert_equal (bisacdf (x, [1, 1, NaN, 1, 1], 1), [y(1:2), NaN, y(4:5)], eps) ***** assert_equal (bisacdf ([x, NaN], 1, 1), [y, NaN], eps) ***** assert_equal (bisacdf (single ([x, NaN]), 1, 1), single ([y, NaN]), eps ('single')) ***** assert_equal (bisacdf ([x, NaN], 1, single (1)), single ([y, NaN]), eps ('single')) ***** assert_equal (bisacdf ([x, NaN], single (1), 1), single ([y, NaN]), eps ('single')) ***** error bisacdf () ***** error bisacdf (1) ***** error bisacdf (1, 2) ***** error ... bisacdf (1, 2, 3, 4, 5) ***** error bisacdf (1, 2, 3, 'tail') ***** error bisacdf (1, 2, 3, 4) ***** error ... bisacdf (ones (3), ones (2), ones (2)) ***** error ... bisacdf (ones (2), ones (3), ones (2)) ***** error ... bisacdf (ones (2), ones (2), ones (3)) ***** error bisacdf (int32 (2), 4, 3) ***** error bisacdf (true, 4, 3) ***** error bisacdf ('a', 4, 3) ***** error bisacdf (i, 4, 3) ***** error bisacdf (1, i, 3) ***** error bisacdf (1, 4, i) 26 tests, 26 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/normrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/normrnd.m ***** assert_equal (size (normrnd (1, 1)), [1, 1]) ***** assert_equal (size (normrnd (1, ones (2, 1))), [2, 1]) ***** assert_equal (size (normrnd (1, ones (2, 2))), [2, 2]) ***** assert_equal (size (normrnd (ones (2, 1), 1)), [2, 1]) ***** assert_equal (size (normrnd (ones (2, 2), 1)), [2, 2]) ***** assert_equal (size (normrnd (1, 1, 3)), [3, 3]) ***** assert_equal (size (normrnd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (normrnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (normrnd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (normrnd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (normrnd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (normrnd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (normrnd (1, 1, [])), [0, 0]) ***** assert_equal (size (normrnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (normrnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (normrnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (normrnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (normrnd (1, 1)), "double") ***** assert_equal (class (normrnd (1, single (1))), "single") ***** assert_equal (class (normrnd (1, single ([1, 1]))), "single") ***** assert_equal (class (normrnd (single (1), 1)), "single") ***** assert_equal (class (normrnd (single ([1, 1]), 1)), "single") ***** error normrnd () ***** error normrnd (1) ***** error ... normrnd (ones (3), ones (2)) ***** error ... normrnd (ones (2), ones (3)) ***** error normrnd (i, 2, 3) ***** error normrnd (1, i, 3) ***** error ... normrnd (1, 2, 1.2) ***** error ... normrnd (1, 2, ones (2)) ***** error ... normrnd (1, 2, [2 0 2.5]) ***** error ... normrnd (1, 2, 2, 1.5, 5) ***** error ... normrnd (2, ones (2), 3) ***** error ... normrnd (2, ones (2), [3, 2]) ***** error ... normrnd (2, ones (2), 3, 2) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/cauchycdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/cauchycdf.m ***** demo ## Plot various CDFs from the Cauchy distribution x = -5:0.01:5; p1 = cauchycdf (x, 0, 0.5); p2 = cauchycdf (x, 0, 1); p3 = cauchycdf (x, 0, 2); p4 = cauchycdf (x, -2, 1); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', x, p4, '-c') grid on xlim ([-5, 5]) legend ({'x0 = 0, γ = 0.5', 'x0 = 0, γ = 1', ... 'x0 = 0, γ = 2', 'x0 = -2, γ = 1'}, 'location', 'southeast') title ('Cauchy CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y x = [-1 0 0.5 1 2]; y = 1/pi * atan ((x-1) / 2) + 1/2; ***** assert_equal (cauchycdf (x, ones (1,5), 2*ones (1,5)), y) ***** assert_equal (cauchycdf (x, 1, 2*ones (1,5)), y) ***** assert_equal (cauchycdf (x, ones (1,5), 2), y) ***** assert_equal (cauchycdf (x, [-Inf 1 NaN 1 Inf], 2), [NaN y(2) NaN y(4) NaN]) ***** assert_equal (cauchycdf (x, 1, 2*[0 1 NaN 1 Inf]), [NaN y(2) NaN y(4) NaN]) ***** assert_equal (cauchycdf ([x(1:2) NaN x(4:5)], 1, 2), [y(1:2) NaN y(4:5)]) ***** assert_equal (cauchycdf ([x, NaN], 1, 2), [y, NaN]) ***** assert_equal (cauchycdf (single ([x, NaN]), 1, 2), single ([y, NaN]), eps ('single')) ***** assert_equal (cauchycdf ([x, NaN], single (1), 2), single ([y, NaN]), eps ('single')) ***** assert_equal (cauchycdf ([x, NaN], 1, single (2)), single ([y, NaN]), eps ('single')) ***** error cauchycdf () ***** error cauchycdf (1) ***** error ... cauchycdf (1, 2) ***** error ... cauchycdf (1, 2, 3, 4, 5) ***** error cauchycdf (1, 2, 3, 'tail') ***** error cauchycdf (1, 2, 3, 4) ***** error ... cauchycdf (ones (3), ones (2), ones (2)) ***** error ... cauchycdf (ones (2), ones (3), ones (2)) ***** error ... cauchycdf (ones (2), ones (2), ones (3)) ***** error cauchycdf (int32 (2), 2, 2) ***** error cauchycdf (true, 2, 2) ***** error cauchycdf ('a', 2, 2) ***** error cauchycdf (i, 2, 2) ***** error cauchycdf (2, i, 2) ***** error cauchycdf (2, 2, i) 25 tests, 25 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/triinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/triinv.m ***** demo ## Plot various iCDFs from the triangular distribution p = 0.001:0.001:0.999; x1 = triinv (p, 3, 6, 4); x2 = triinv (p, 1, 5, 2); x3 = triinv (p, 2, 9, 3); x4 = triinv (p, 2, 9, 5); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', p, x4, '-c') grid on ylim ([0, 10]) legend ({'a = 3, b = 6, c = 4', 'a = 1, b = 5, c = 2', ... 'a = 2, b = 9, c = 3', 'a = 2, b = 9, c = 5'}, ... 'location', 'northwest') title ('Triangular CDF') xlabel ('probability') ylabel ('values in x') ***** shared p, y p = [-1, 0, 0.02, 0.5, 0.98, 1, 2]; y = [NaN, 0, 0.1, 0.5, 0.9, 1, NaN] + 1; ***** assert_equal (triinv (p, ones (1, 7), 1.5 * ones (1, 7), 2 * ones (1, 7)), y, eps) ***** assert_equal (triinv (p, 1 * ones (1, 7), 1.5, 2), y, eps) ***** assert_equal (triinv (p, 1, 1.5, 2 * ones (1, 7)), y, eps) ***** assert_equal (triinv (p, 1, 1.5*ones (1,7), 2), y, eps) ***** assert_equal (triinv (p, 1, 1.5, 2), y, eps) ***** assert_equal (triinv (p, [1, 1, NaN, 1, 1, 1, 1], 1.5, 2), [y(1:2), NaN, y(4:7)], eps) ***** assert_equal (triinv (p, 1, 1.5 * [1, 1, NaN, 1, 1, 1, 1], 2), [y(1:2), NaN, y(4:7)], eps) ***** assert_equal (triinv (p, 1, 1.5, 2 * [1, 1, NaN, 1, 1, 1, 1]), [y(1:2), NaN, y(4:7)], eps) ***** assert_equal (triinv ([p, NaN], 1, 1.5, 2), [y, NaN], eps) ***** assert_equal (triinv (single ([p, NaN]), 1, 1.5, 2), single ([y, NaN]), eps ('single')) ***** assert_equal (triinv ([p, NaN], single (1), 1.5, 2), single ([y, NaN]), eps ('single')) ***** assert_equal (triinv ([p, NaN], 1, single (1.5), 2), single ([y, NaN]), eps ('single')) ***** assert_equal (triinv ([p, NaN], 1, 1.5, single (2)), single ([y, NaN]), eps ('single')) ***** error triinv () ***** error triinv (1) ***** error triinv (1, 2) ***** error triinv (1, 2, 3) ***** error ... triinv (1, 2, 3, 4, 5) ***** error ... triinv (ones (3), ones (2), ones (2), ones (2)) ***** error ... triinv (ones (2), ones (3), ones (2), ones (2)) ***** error ... triinv (ones (2), ones (2), ones (3), ones (2)) ***** error ... triinv (ones (2), ones (2), ones (2), ones (3)) ***** error triinv (int32 (2), 2, 3, 4) ***** error triinv (true, 2, 3, 4) ***** error triinv ('a', 2, 3, 4) ***** error triinv (i, 2, 3, 4) ***** error triinv (1, i, 3, 4) ***** error triinv (1, 2, i, 4) ***** error triinv (1, 2, 3, i) 29 tests, 29 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/trnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/trnd.m ***** assert_equal (size (trnd (2)), [1, 1]) ***** assert_equal (size (trnd (ones (2, 1))), [2, 1]) ***** assert_equal (size (trnd (ones (2, 2))), [2, 2]) ***** assert_equal (size (trnd (1, 3)), [3, 3]) ***** assert_equal (size (trnd (1, [4, 1])), [4, 1]) ***** assert_equal (size (trnd (1, 4, 1)), [4, 1]) ***** assert_equal (size (trnd (1, 4, 1)), [4, 1]) ***** assert_equal (size (trnd (1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (trnd (1, 0, 1)), [0, 1]) ***** assert_equal (size (trnd (1, 1, 0)), [1, 0]) ***** assert_equal (size (trnd (1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (trnd (1, [])), [0, 0]) ***** assert_equal (size (trnd (1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (trnd (1, -1)), [0, 0]) ***** assert_equal (size (trnd (1, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (trnd (1, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (trnd (0, 1, 1), NaN) ***** assert_equal (trnd ([0, 0, 0], [1, 3]), [NaN, NaN, NaN]) ***** assert_equal (class (trnd (2)), "double") ***** assert_equal (class (trnd (single (2))), "single") ***** assert_equal (class (trnd (single ([2, 2]))), "single") ***** error trnd () ***** error trnd (i) ***** error ... trnd (1, 1.2) ***** error ... trnd (1, ones (2)) ***** error ... trnd (1, [2 0 2.5]) ***** error ... trnd (ones (2), ones (2)) ***** error ... trnd (1, 2, 1.5, 5) ***** error trnd (ones (2,2), 3) ***** error trnd (ones (2,2), [3, 2]) ***** error trnd (ones (2,2), 2, 3) 31 tests, 31 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/burrcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/burrcdf.m ***** demo ## Plot various CDFs from the Burr type XII distribution x = 0.001:0.001:5; p1 = burrcdf (x, 1, 1, 1); p2 = burrcdf (x, 1, 1, 2); p3 = burrcdf (x, 1, 1, 3); p4 = burrcdf (x, 1, 2, 1); p5 = burrcdf (x, 1, 3, 1); p6 = burrcdf (x, 1, 0.5, 2); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', ... x, p4, '-c', x, p5, '-m', x, p6, '-k') grid on legend ({'λ = 1, c = 1, k = 1', 'λ = 1, c = 1, k = 2', ... 'λ = 1, c = 1, k = 3', 'λ = 1, c = 2, k = 1', ... 'λ = 1, c = 3, k = 1', 'λ = 1, c = 0.5, k = 2'}, ... 'location', 'southeast') title ('Burr type XII CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y x = [-1, 0, 1, 2, Inf]; y = [0, 0, 1/2, 2/3, 1]; ***** assert_equal (burrcdf (x, ones (1,5), ones (1,5), ones (1,5)), y, eps) ***** assert_equal (burrcdf (x, 1, 1, 1), y, eps) ***** assert_equal (burrcdf (x, [1, 1, NaN, 1, 1], 1, 1), [y(1:2), NaN, y(4:5)], eps) ***** assert_equal (burrcdf (x, 1, [1, 1, NaN, 1, 1], 1), [y(1:2), NaN, y(4:5)], eps) ***** assert_equal (burrcdf (x, 1, 1, [1, 1, NaN, 1, 1]), [y(1:2), NaN, y(4:5)], eps) ***** assert_equal (burrcdf ([x, NaN], 1, 1, 1), [y, NaN], eps) ***** assert_equal (burrcdf (single ([x, NaN]), 1, 1, 1), single ([y, NaN]), eps ('single')) ***** assert_equal (burrcdf ([x, NaN], single (1), 1, 1), single ([y, NaN]), eps ('single')) ***** assert_equal (burrcdf ([x, NaN], 1, single (1), 1), single ([y, NaN]), eps ('single')) ***** assert_equal (burrcdf ([x, NaN], 1, 1, single (1)), single ([y, NaN]), eps ('single')) ***** error burrcdf () ***** error burrcdf (1) ***** error burrcdf (1, 2) ***** error burrcdf (1, 2, 3) ***** error ... burrcdf (1, 2, 3, 4, 5, 6) ***** error burrcdf (1, 2, 3, 4, 'tail') ***** error burrcdf (1, 2, 3, 4, 5) ***** error ... burrcdf (ones (3), ones (2), ones (2), ones (2)) ***** error ... burrcdf (ones (2), ones (3), ones (2), ones (2)) ***** error ... burrcdf (ones (2), ones (2), ones (3), ones (2)) ***** error ... burrcdf (ones (2), ones (2), ones (2), ones (3)) ***** error burrcdf (int32 (2), 2, 3, 4) ***** error burrcdf (true, 2, 3, 4) ***** error burrcdf ('a', 2, 3, 4) ***** error burrcdf (i, 2, 3, 4) ***** error burrcdf (1, i, 3, 4) ***** error burrcdf (1, 2, i, 4) ***** error burrcdf (1, 2, 3, i) 28 tests, 28 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/mvtrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/mvtrnd.m ***** test rho = [1, 0.5; 0.5, 1]; df = 3; n = 10; r = mvtrnd (rho, df, n); assert_equal (size (r), [10, 2]); ***** test rho = [1, 0.5; 0.5, 1]; df = [2; 3]; n = 2; r = mvtrnd (rho, df, 2); assert_equal (size (r), [2, 2]); 2 tests, 2 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/tinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/tinv.m ***** demo ## Plot various iCDFs from the Student's T distribution p = 0.001:0.001:0.999; x1 = tinv (p, 1); x2 = tinv (p, 2); x3 = tinv (p, 5); x4 = tinv (p, Inf); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', p, x4, '-m') grid on xlim ([0, 1]) ylim ([-5, 5]) legend ({'df = 1', 'df = 2', ... 'df = 5', 'df = \infty'}, 'location', 'northwest') title ('Student''s T iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p p = [-1 0 0.5 1 2]; ***** assert_equal (tinv (p, ones (1,5)), [NaN -Inf 0 Inf NaN]) ***** assert_equal (tinv (p, 1), [NaN -Inf 0 Inf NaN], eps) ***** assert_equal (tinv (p, [1 0 NaN 1 1]), [NaN NaN NaN Inf NaN], eps) ***** assert_equal (tinv ([p(1:2) NaN p(4:5)], 1), [NaN -Inf NaN Inf NaN]) ***** test ## Deep in the tail, -cot (pi p); MATLAB gives -3183097229.936, the value ## of tan (pi (p - 0.5)), whose p - 0.5 loses the digits that matter assert_equal (tinv (1e-10, 1), -cot (pi * 1e-10), -1e-14); ***** assert_equal (tinv (0.5 + 2^-30, 1), tan (pi * 2^-30), -1e-14) ***** assert_equal (tinv (0.5 - 2^-30, 2), ... -2^-29 / sqrt (2 * (0.5 - 2^-30) * (0.5 + 2^-30)), -1e-14) ***** assert_equal (tinv ([p, NaN], 1), [NaN -Inf 0 Inf NaN NaN], eps) ***** assert_equal (tinv (single ([p, NaN]), 1), single ([NaN -Inf 0 Inf NaN NaN]), eps ('single')) ***** assert_equal (tinv ([p, NaN], single (1)), single ([NaN -Inf 0 Inf NaN NaN]), eps ('single')) ***** error tinv () ***** error tinv (1) ***** error ... tinv (ones (3), ones (2)) ***** error ... tinv (ones (2), ones (3)) ***** error tinv (int32 (2), 2) ***** error tinv (true, 2) ***** error tinv ('a', 2) ***** error tinv (i, 2) ***** error tinv (2, i) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/normcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/normcdf.m ***** demo ## Plot various CDFs from the normal distribution x = -5:0.01:5; p1 = normcdf (x, 0, 0.5); p2 = normcdf (x, 0, 1); p3 = normcdf (x, 0, 2); p4 = normcdf (x, -2, 0.8); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', x, p4, '-c') grid on xlim ([-5, 5]) legend ({'μ = 0, σ = 0.5', 'μ = 0, σ = 1', ... 'μ = 0, σ = 2', 'μ = -2, σ = 0.8'}, 'location', 'southeast') title ('Normal CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y x = [-Inf 1 2 Inf]; y = [0, 0.5, 1/2*(1+erf(1/sqrt(2))), 1]; ***** assert_equal (normcdf (x, ones (1,4), ones (1,4)), y) ***** assert_equal (normcdf (x, 1, ones (1,4)), y) ***** assert_equal (normcdf (x, ones (1,4), 1), y) ***** assert_equal (normcdf (x, [0, -Inf, NaN, Inf], 1), [0, 1, NaN, NaN]) ***** assert_equal (normcdf (x, 1, [Inf, NaN, -1, 0]), [NaN, NaN, NaN, 1]) ***** assert_equal (normcdf ([x(1:2), NaN, x(4)], 1, 1), [y(1:2), NaN, y(4)]) ***** assert_equal (normcdf (x, 'upper'), [1, 0.1587, 0.0228, 0], 1e-4) ***** assert_equal (normcdf ([x, NaN], 1, 1), [y, NaN]) ***** assert_equal (normcdf (single ([x, NaN]), 1, 1), single ([y, NaN]), eps ('single')) ***** assert_equal (normcdf ([x, NaN], single (1), 1), single ([y, NaN]), eps ('single')) ***** assert_equal (normcdf ([x, NaN], 1, single (1)), single ([y, NaN]), eps ('single')) ***** error normcdf () ***** error normcdf (1,2,3,4,5,6,7) ***** error normcdf (1, 2, 3, 4, 'uper') ***** error ... normcdf (ones (3), ones (2), ones (2)) ***** error normcdf (2, 3, 4, [1, 2]) ***** error ... [p, plo, pup] = normcdf (1, 2, 3) ***** error [p, plo, pup] = ... normcdf (1, 2, 3, [1, 0; 0, 1], 0) ***** error [p, plo, pup] = ... normcdf (1, 2, 3, [1, 0; 0, 1], 1.22) ***** error [p, plo, pup] = ... normcdf (1, 2, 3, [1, 0; 0, 1], 'alpha', 'upper') ***** error normcdf (int32 (2), 2, 2) ***** error normcdf (true, 2, 2) ***** error normcdf ('a', 2, 2) ***** error normcdf (i, 2, 2) ***** error normcdf (2, i, 2) ***** error normcdf (2, 2, i) ***** error ... [p, plo, pup] =normcdf (1, 2, 3, [1, 0; 0, -inf], 0.04) 27 tests, 27 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/gevrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/gevrnd.m ***** assert_equal (size (gevrnd (1, 2, 1)), [1, 1]); ***** assert_equal (size (gevrnd (ones (2, 1), 2, 1)), [2, 1]); ***** assert_equal (size (gevrnd (ones (2, 2), 2, 1)), [2, 2]); ***** assert_equal (size (gevrnd (1, 2 * ones (2, 1), 1)), [2, 1]); ***** assert_equal (size (gevrnd (1, 2 * ones (2, 2), 1)), [2, 2]); ***** assert_equal (size (gevrnd (1, 2, 1, 3)), [3, 3]); ***** assert_equal (size (gevrnd (1, 2, 1, [4, 1])), [4, 1]); ***** assert_equal (size (gevrnd (1, 2, 1, 4, 1)), [4, 1]); ***** assert_equal (size (gevrnd (1, 2, 1, [])), [0, 0]) ***** assert_equal (size (gevrnd (1, 2, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (gevrnd (1, 2, 3, -1)), [0, 0]) ***** assert_equal (size (gevrnd (1, 2, 3, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (gevrnd (1, 2, 3, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (gevrnd (1,1,1)), "double") ***** assert_equal (class (gevrnd (single (1),1,1)), "single") ***** assert_equal (class (gevrnd (single ([1 1]),1,1)), "single") ***** assert_equal (class (gevrnd (1,single (1),1)), "single") ***** assert_equal (class (gevrnd (1,single ([1 1]),1)), "single") ***** assert_equal (class (gevrnd (1,1,single (1))), "single") ***** assert_equal (class (gevrnd (1,1,single ([1 1]))), "single") ***** error gevrnd () ***** error gevrnd (1) ***** error gevrnd (1, 2) ***** error ... gevrnd (ones (3), ones (2), ones (2)) ***** error ... gevrnd (ones (2), ones (3), ones (2)) ***** error ... gevrnd (ones (2), ones (2), ones (3)) ***** error gevrnd (i, 2, 3) ***** error gevrnd (1, i, 3) ***** error gevrnd (1, 2, i) ***** error ... gevrnd (1, 2, 3, 1.2) ***** error ... gevrnd (1, 2, 3, ones (2)) ***** error ... gevrnd (1, 2, 3, [2 0 2.5]) ***** error ... gevrnd (1, 2, 3, 2, 1.5, 5) ***** error ... gevrnd (2, ones (2), 2, 3) ***** error ... gevrnd (2, ones (2), 2, [3, 2]) ***** error ... gevrnd (2, ones (2), 2, 3, 2) 36 tests, 36 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/chi2cdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/chi2cdf.m ***** demo ## Plot various CDFs from the chi-squared distribution x = 0:0.01:8; p1 = chi2cdf (x, 1); p2 = chi2cdf (x, 2); p3 = chi2cdf (x, 3); p4 = chi2cdf (x, 4); p5 = chi2cdf (x, 6); p6 = chi2cdf (x, 9); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', ... x, p4, '-c', x, p5, '-m', x, p6, '-y') grid on xlim ([0, 8]) legend ({'df = 1', 'df = 2', 'df = 3', ... 'df = 4', 'df = 6', 'df = 9'}, 'location', 'southeast') title ('Chi-squared CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, p, u x = [-1, 0, 0.5, 1, 2]; p = [0, (1 - exp (-x(2:end) / 2))]; u = [1, 0, NaN, 0.606530659712633, 0.367879441171442]; ***** assert_equal (chi2cdf (x, 2 * ones (1,5)), p, eps) ***** assert_equal (chi2cdf (x, 2), p, eps) ***** assert_equal (chi2cdf (x, 2 * [1, 0, NaN, 1, 1]), [0, 1, NaN, p(4:5)], eps) ***** assert_equal (chi2cdf (x, 2 * [1, 0, NaN, 1, 1], 'upper'), u, 3 * eps) ***** assert_equal (chi2cdf ([x(1:2), NaN, x(4:5)], 2), [p(1:2), NaN, p(4:5)], eps) ***** assert_equal (chi2cdf ([x, NaN], 2), [p, NaN], eps) ***** assert_equal (chi2cdf (single ([x, NaN]), 2), single ([p, NaN]), eps ('single')) ***** assert_equal (chi2cdf ([x, NaN], single (2)), single ([p, NaN]), eps ('single')) ***** error chi2cdf () ***** error chi2cdf (1) ***** error chi2cdf (1, 2, 3, 4) ***** error chi2cdf (1, 2, 3) ***** error chi2cdf (1, 2, 'uper') ***** error ... chi2cdf (ones (3), ones (2)) ***** error ... chi2cdf (ones (2), ones (3)) ***** error chi2cdf (int32 (2), 2) ***** error chi2cdf (true, 2) ***** error chi2cdf ('a', 2) ***** error chi2cdf (i, 2) ***** error chi2cdf (2, i) 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/wienrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/wienrnd.m ***** error wienrnd (0) ***** error wienrnd (1, 3, -50) ***** error wienrnd (5, 0) ***** error wienrnd (0.4, 3, 5) ***** error wienrnd ([1 4], 3, 5) 5 tests, 5 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/tripdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/tripdf.m ***** demo ## Plot various CDFs from the triangular distribution x = 0.001:0.001:10; y1 = tripdf (x, 3, 4, 6); y2 = tripdf (x, 1, 2, 5); y3 = tripdf (x, 2, 3, 9); y4 = tripdf (x, 2, 5, 9); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', x, y4, '-c') grid on xlim ([0, 10]) legend ({'a = 3, b = 4, c = 6', 'a = 1, b = 2, c = 5', ... 'a = 2, b = 3, c = 9', 'a = 2, b = 5, c = 9'}, ... 'location', 'northeast') title ('Triangular CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y, deps x = [-1, 0, 0.1, 0.5, 0.9, 1, 2] + 1; y = [0, 0, 0.4, 2, 0.4, 0, 0]; deps = 2*eps; ***** assert_equal (tripdf (x, ones (1,7), 1.5*ones (1,7), 2*ones (1,7)), y, deps) ***** assert_equal (tripdf (x, 1*ones (1,7), 1.5, 2), y, deps) ***** assert_equal (tripdf (x, 1, 1.5, 2*ones (1,7)), y, deps) ***** assert_equal (tripdf (x, 1, 1.5*ones (1,7), 2), y, deps) ***** assert_equal (tripdf (x, 1, 1.5, 2), y, deps) ***** assert_equal (tripdf (x, [1, 1, NaN, 1, 1, 1, 1], 1.5, 2), [y(1:2), NaN, y(4:7)], deps) ***** assert_equal (tripdf (x, 1, 1.5, 2*[1, 1, NaN, 1, 1, 1, 1]), [y(1:2), NaN, y(4:7)], deps) ***** assert_equal (tripdf (x, 1, 1.5*[1, 1, NaN, 1, 1, 1, 1], 2), [y(1:2), NaN, y(4:7)], deps) ***** assert_equal (tripdf ([x, NaN], 1, 1.5, 2), [y, NaN], deps) ***** assert_equal (tripdf (single ([x, NaN]), 1, 1.5, 2), single ([y, NaN]), eps ('single')) ***** assert_equal (tripdf ([x, NaN], single (1), 1.5, 2), single ([y, NaN]), eps ('single')) ***** assert_equal (tripdf ([x, NaN], 1, 1.5, single (2)), single ([y, NaN]), eps ('single')) ***** assert_equal (tripdf ([x, NaN], 1, single (1.5), 2), single ([y, NaN]), eps ('single')) ***** error tripdf () ***** error tripdf (1) ***** error tripdf (1, 2) ***** error tripdf (1, 2, 3) ***** error ... tripdf (1, 2, 3, 4, 5) ***** error ... tripdf (ones (3), ones (2), ones (2), ones (2)) ***** error ... tripdf (ones (2), ones (3), ones (2), ones (2)) ***** error ... tripdf (ones (2), ones (2), ones (3), ones (2)) ***** error ... tripdf (ones (2), ones (2), ones (2), ones (3)) ***** error tripdf (int32 (2), 2, 3, 4) ***** error tripdf (true, 2, 3, 4) ***** error tripdf ('a', 2, 3, 4) ***** error tripdf (i, 2, 3, 4) ***** error tripdf (1, i, 3, 4) ***** error tripdf (1, 2, i, 4) ***** error tripdf (1, 2, 3, i) 29 tests, 29 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/loglpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/loglpdf.m ***** demo ## Plot various PDFs from the log-logistic distribution x = 0.001:0.001:2; y1 = loglpdf (x, log (1), 1/0.5); y2 = loglpdf (x, log (1), 1); y3 = loglpdf (x, log (1), 1/2); y4 = loglpdf (x, log (1), 1/4); y5 = loglpdf (x, log (1), 1/8); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', x, y4, '-c', x, y5, '-m') grid on ylim ([0,3]) legend ({'σ = 2 (β = 0.5)', 'σ = 1 (β = 1)', 'σ = 0.5 (β = 2)', ... 'σ = 0.25 (β = 4)', 'σ = 0.125 (β = 8)'}, 'location', 'northeast') title ('Log-logistic PDF') xlabel ('values in x') ylabel ('density') text (0.1, 2.8, 'μ = 0 (α = 1), values of σ (β) as shown in legend') ***** shared out1, out2 out1 = [0, 0, 1, 0.2500, 0.1111, 0.0625, 0.0400, 0.0278, 0]; out2 = [0, 0, 0.0811, 0.0416, 0.0278, 0.0207, 0.0165, 0]; ***** assert_equal (loglpdf ([-1,0,realmin,1:5,Inf], 0, 1), out1, 1e-4) ***** assert_equal (loglpdf ([-1,0,realmin,1:5,Inf], 0, 1), out1, 1e-4) ***** assert_equal (loglpdf ([-1:5,Inf], 1, 3), out2, 1e-4) ***** assert_equal (class (loglpdf (single (1), 2, 3)), "single") ***** assert_equal (class (loglpdf (1, single (2), 3)), "single") ***** assert_equal (class (loglpdf (1, 2, single (3))), "single") ***** error loglpdf (1) ***** error loglpdf (1, 2) ***** error ... loglpdf (1, ones (2), ones (3)) ***** error ... loglpdf (ones (2), 1, ones (3)) ***** error ... loglpdf (ones (2), ones (3), 1) ***** error loglpdf (int32 (2), 2, 3) ***** error loglpdf (true, 2, 3) ***** error loglpdf ('a', 2, 3) ***** error loglpdf (i, 2, 3) ***** error loglpdf (1, i, 3) ***** error loglpdf (1, 2, i) 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/burrinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/burrinv.m ***** demo ## Plot various iCDFs from the Burr type XII distribution p = 0.001:0.001:0.999; x1 = burrinv (p, 1, 1, 1); x2 = burrinv (p, 1, 1, 2); x3 = burrinv (p, 1, 1, 3); x4 = burrinv (p, 1, 2, 1); x5 = burrinv (p, 1, 3, 1); x6 = burrinv (p, 1, 0.5, 2); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', ... p, x4, '-c', p, x5, '-m', p, x6, '-k') grid on ylim ([0, 5]) legend ({'λ = 1, c = 1, k = 1', 'λ = 1, c = 1, k = 2', ... 'λ = 1, c = 1, k = 3', 'λ = 1, c = 2, k = 1', ... 'λ = 1, c = 3, k = 1', 'λ = 1, c = 0.5, k = 2'}, ... 'location', 'northwest') title ('Burr type XII iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p, y p = [-Inf, -1, 0, 1/2, 1, 2, Inf]; y = [NaN, NaN, 0, 1 , Inf, NaN, NaN]; ***** assert_equal (burrinv (p, ones (1,7), ones (1,7), ones (1,7)), y, eps) ***** assert_equal (burrinv (p, 1, 1, 1), y, eps) ***** assert_equal (burrinv (p, [1, 1, 1, NaN, 1, 1, 1], 1, 1), [y(1:3), NaN, y(5:7)], eps) ***** assert_equal (burrinv (p, 1, [1, 1, 1, NaN, 1, 1, 1], 1), [y(1:3), NaN, y(5:7)], eps) ***** assert_equal (burrinv (p, 1, 1, [1, 1, 1, NaN, 1, 1, 1]), [y(1:3), NaN, y(5:7)], eps) ***** assert_equal (burrinv ([p, NaN], 1, 1, 1), [y, NaN], eps) ***** assert_equal (burrinv (0.5, 2, 1, 1), 2, eps) ***** assert_equal (burrinv (0.5, 3, 0.5, 0.5), 27, eps) ***** assert_equal (burrinv (0.5, 1.5, 2, 0.5), 1.5 * sqrt (3), eps) ***** assert_equal (burrinv (0.5, 5, 2, 2), 5 * sqrt (sqrt (2) - 1), eps) ***** assert_equal (burrcdf (burrinv (0.25, 2, 0.9, 4.2), 2, 0.9, 4.2), 0.25, 1e-12) ***** assert_equal (burrcdf (burrinv (0.75, 3, 0.5, 0.5), 3, 0.5, 0.5), 0.75, 1e-12) ***** assert_equal (burrcdf (burrinv (0.5, 0.4, 3, 0.2), 0.4, 3, 0.2), 0.5, 1e-12) ***** test q = [0.05, 0.25, 0.5, 0.75, 0.95]; assert_equal (burrcdf (burrinv (q, 1.7, 1.3, 2.6), 1.7, 1.3, 2.6), q, 1e-12); ***** assert_equal (isreal (burrinv (0.9, 0.5, 2, 3)), true) ***** assert_equal (burrinv ([0.5, 0.5], [2, 4], 1, 1), [2, 4], eps) ***** assert_equal (burrinv (single ([p, NaN]), 1, 1, 1), single ([y, NaN]), eps ('single')) ***** assert_equal (burrinv ([p, NaN], single (1), 1, 1), single ([y, NaN]), eps ('single')) ***** assert_equal (burrinv ([p, NaN], 1, single (1), 1), single ([y, NaN]), eps ('single')) ***** assert_equal (burrinv ([p, NaN], 1, 1, single (1)), single ([y, NaN]), eps ('single')) ***** error burrinv () ***** error burrinv (1) ***** error burrinv (1, 2) ***** error burrinv (1, 2, 3) ***** error ... burrinv (1, 2, 3, 4, 5) ***** error ... burrinv (ones (3), ones (2), ones (2), ones (2)) ***** error ... burrinv (ones (2), ones (3), ones (2), ones (2)) ***** error ... burrinv (ones (2), ones (2), ones (3), ones (2)) ***** error ... burrinv (ones (2), ones (2), ones (2), ones (3)) ***** error burrinv (int32 (2), 2, 3, 4) ***** error burrinv (true, 2, 3, 4) ***** error burrinv ('a', 2, 3, 4) ***** error burrinv (i, 2, 3, 4) ***** error burrinv (1, i, 3, 4) ***** error burrinv (1, 2, i, 4) ***** error burrinv (1, 2, 3, i) 36 tests, 36 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/cauchyrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/cauchyrnd.m ***** assert_equal (size (cauchyrnd (1, 1)), [1 1]) ***** assert_equal (size (cauchyrnd (1, ones (2,1))), [2, 1]) ***** assert_equal (size (cauchyrnd (1, ones (2,2))), [2, 2]) ***** assert_equal (size (cauchyrnd (ones (2,1), 1)), [2, 1]) ***** assert_equal (size (cauchyrnd (ones (2,2), 1)), [2, 2]) ***** assert_equal (size (cauchyrnd (1, 1, 3)), [3, 3]) ***** assert_equal (size (cauchyrnd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (cauchyrnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (cauchyrnd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (cauchyrnd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (cauchyrnd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (cauchyrnd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (cauchyrnd (1, 1, [])), [0, 0]) ***** assert_equal (size (cauchyrnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (cauchyrnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (cauchyrnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (cauchyrnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (cauchyrnd (1, 1)), "double") ***** assert_equal (class (cauchyrnd (1, single (1))), "single") ***** assert_equal (class (cauchyrnd (1, single ([1, 1]))), "single") ***** assert_equal (class (cauchyrnd (single (1), 1)), "single") ***** assert_equal (class (cauchyrnd (single ([1, 1]), 1)), "single") ***** error cauchyrnd () ***** error cauchyrnd (1) ***** error ... cauchyrnd (ones (3), ones (2)) ***** error ... cauchyrnd (ones (2), ones (3)) ***** error cauchyrnd (i, 2, 3) ***** error cauchyrnd (1, i, 3) ***** error ... cauchyrnd (1, 2, 1.2) ***** error ... cauchyrnd (1, 2, ones (2)) ***** error ... cauchyrnd (1, 2, [2 0 2.5]) ***** error ... cauchyrnd (1, 2, 2, 1.5, 5) ***** error ... cauchyrnd (2, ones (2), 3) ***** error ... cauchyrnd (2, ones (2), [3, 2]) ***** error ... cauchyrnd (2, ones (2), 3, 2) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/binoinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/binoinv.m ***** demo ## Plot various iCDFs from the binomial distribution p = 0.001:0.001:0.999; x1 = binoinv (p, 20, 0.5); x2 = binoinv (p, 20, 0.7); x3 = binoinv (p, 40, 0.5); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r') grid on legend ({'n = 20, ps = 0.5', 'n = 20, ps = 0.7', ... 'n = 40, ps = 0.5'}, 'location', 'southeast') title ('Binomial iCDF') xlabel ('probability') ylabel ('values in x (number of successes)') ***** shared p p = [-1 0 0.5 1 2]; ***** assert_equal (binoinv (p, 2*ones (1,5), 0.5*ones (1,5)), [NaN 0 1 2 NaN]) ***** assert_equal (binoinv (p, 2, 0.5*ones (1,5)), [NaN 0 1 2 NaN]) ***** assert_equal (binoinv (p, 2*ones (1,5), 0.5), [NaN 0 1 2 NaN]) ***** assert_equal (binoinv (p, 2*[0 -1 NaN 1.1 1], 0.5), [NaN NaN NaN NaN NaN]) ***** assert_equal (binoinv (p, 2, 0.5*[0 -1 NaN 3 1]), [NaN NaN NaN NaN NaN]) ***** assert_equal (binoinv ([p(1:2) NaN p(4:5)], 2, 0.5), [NaN 0 NaN 2 NaN]) ***** assert_equal (binoinv ([p, NaN], 2, 0.5), [NaN 0 1 2 NaN NaN]) ***** assert_equal (binoinv (single ([p, NaN]), 2, 0.5), single ([NaN 0 1 2 NaN NaN])) ***** assert_equal (binoinv ([p, NaN], single (2), 0.5), single ([NaN 0 1 2 NaN NaN])) ***** assert_equal (binoinv ([p, NaN], 2, single (0.5)), single ([NaN 0 1 2 NaN NaN])) ***** shared x x = magic (3) + 1; ***** assert_equal (binoinv (binocdf (1:10, 11, 0.1), 11, 0.1), 1:10) ***** assert_equal (binoinv (binocdf (1:10, 2*(1:10), 0.1), 2*(1:10), 0.1), 1:10) ***** assert_equal (binoinv (binocdf (x, 2*x, 1./x), 2*x, 1./x), x) ***** assert_equal (binoinv (0.5, 5, 0.5), 2) ***** assert_equal (binoinv (0.5, 7, 0.5), 3) ***** assert_equal (binoinv (0.5, 501, 0.5), 250) ***** assert_equal (binoinv (0.5, 2001, 0.5), 1000) ***** assert_equal (binoinv (0.5, 100001, 0.5), 50000) ***** assert_equal (binoinv (1, 500, 0.25), 500) ***** assert_equal (binoinv (1, [50, 500], [0.5, 0.1]), [50, 500]) ***** assert_equal (binoinv ([0.5, 0.9], 2001, 0.5), [1000, 1029]) ***** assert_equal (binoinv ([0.5; 0.9], 2001, 0.5), [1000; 1029]) ***** assert_equal (binoinv ([NaN, 0.5], 2001, 0.5), [NaN, 1000]) ***** assert_equal (binoinv ([2, 0.5], [2001, 2001], [0.5, 0.5]), [NaN, 1000]) ***** error binoinv () ***** error binoinv (1) ***** error binoinv (1,2) ***** error binoinv (1,2,3,4) ***** error ... binoinv (ones (3), ones (2), ones (2)) ***** error ... binoinv (ones (2), ones (3), ones (2)) ***** error ... binoinv (ones (2), ones (2), ones (3)) ***** error binoinv (int32 (2), 2, 2) ***** error binoinv (true, 2, 2) ***** error binoinv ('a', 2, 2) ***** error binoinv (i, 2, 2) ***** error binoinv (2, i, 2) ***** error binoinv (2, 2, i) 37 tests, 37 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/mvnrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/mvnrnd.m ***** error mvnrnd () ***** error mvnrnd ([2, 3, 4]) ***** error mvnrnd (ones (2, 2, 2), ones (1, 2, 3, 4)) ***** error mvnrnd (ones (1, 3), ones (1, 2, 3, 4)) ***** assert_equal (size (mvnrnd ([2, 3, 4], [2, 2, 2])), [1, 3]) ***** assert_equal (size (mvnrnd ([2, 3, 4], [2, 2, 2], 10)), [10, 3]) 6 tests, 6 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/laplacernd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/laplacernd.m ***** assert_equal (size (laplacernd (1, 1)), [1, 1]) ***** assert_equal (size (laplacernd (1, ones (2, 1))), [2, 1]) ***** assert_equal (size (laplacernd (1, ones (2, 2))), [2, 2]) ***** assert_equal (size (laplacernd (ones (2, 1), 1)), [2, 1]) ***** assert_equal (size (laplacernd (ones (2, 2), 1)), [2, 2]) ***** assert_equal (size (laplacernd (1, 1, 3)), [3, 3]) ***** assert_equal (size (laplacernd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (laplacernd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (laplacernd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (laplacernd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (laplacernd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (laplacernd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (laplacernd (1, 1, [])), [0, 0]) ***** assert_equal (size (laplacernd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (laplacernd (1, 2, -1)), [0, 0]) ***** assert_equal (size (laplacernd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (laplacernd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (laplacernd (1, 1)), "double") ***** assert_equal (class (laplacernd (1, single (1))), "single") ***** assert_equal (class (laplacernd (1, single ([1, 1]))), "single") ***** assert_equal (class (laplacernd (single (1), 1)), "single") ***** assert_equal (class (laplacernd (single ([1, 1]), 1)), "single") ***** error laplacernd () ***** error laplacernd (1) ***** error ... laplacernd (ones (3), ones (2)) ***** error ... laplacernd (ones (2), ones (3)) ***** error laplacernd (i, 2, 3) ***** error laplacernd (1, i, 3) ***** error ... laplacernd (1, 2, 1.2) ***** error ... laplacernd (1, 2, ones (2)) ***** error ... laplacernd (1, 2, [2 0 2.5]) ***** error ... laplacernd (1, 2, 2, 1.5, 5) ***** error ... laplacernd (2, ones (2), 3) ***** error ... laplacernd (2, ones (2), [3, 2]) ***** error ... laplacernd (2, ones (2), 3, 2) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/binocdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/binocdf.m ***** demo ## Plot various CDFs from the binomial distribution x = 0:40; p1 = binocdf (x, 20, 0.5); p2 = binocdf (x, 20, 0.7); p3 = binocdf (x, 40, 0.5); plot (x, p1, '*b', x, p2, '*g', x, p3, '*r') grid on legend ({'n = 20, ps = 0.5', 'n = 20, ps = 0.7', ... 'n = 40, ps = 0.5'}, 'location', 'southeast') title ('Binomial CDF') xlabel ('values in x (number of successes)') ylabel ('probability') ***** shared x, p, p1 x = [-1 0 1 2 3]; p = [0 1/4 3/4 1 1]; p1 = 1 - p; ***** assert_equal (binocdf (x, 2 * ones (1, 5), 0.5 * ones (1, 5)), p, eps) ***** assert_equal (binocdf (x, 2, 0.5 * ones (1, 5)), p, eps) ***** assert_equal (binocdf (x, 2 * ones (1, 5), 0.5), p, eps) ***** assert_equal (binocdf (x, 2 * [0 -1 NaN 1.1 1], 0.5), [0 NaN NaN NaN 1]) ***** assert_equal (binocdf (x, 2, 0.5 * [0 -1 NaN 3 1]), [0 NaN NaN NaN 1]) ***** assert_equal (binocdf ([x(1:2) NaN x(4:5)], 2, 0.5), [p(1:2) NaN p(4:5)], eps) ***** assert_equal (binocdf (99, 100, 0.1, 'upper'), 1e-100, 1e-112); ***** assert_equal (binocdf (x, 2 * ones (1, 5), 0.5*ones (1,5), 'upper'), p1, eps) ***** assert_equal (binocdf (x, 2, 0.5 * ones (1, 5), 'upper'), p1, eps) ***** assert_equal (binocdf (x, 2 * ones (1, 5), 0.5, 'upper'), p1, eps) ***** assert_equal (binocdf (x, 2 * [0 -1 NaN 1.1 1], 0.5, 'upper'), [1 NaN NaN NaN 0]) ***** assert_equal (binocdf (x, 2, 0.5 * [0 -1 NaN 3 1], 'upper'), [1 NaN NaN NaN 0]) ***** assert_equal (binocdf ([x(1:2) NaN x(4:5)], 2, 0.5, 'upper'), [p1(1:2) NaN p1(4:5)]) ***** assert_equal (binocdf ([x, NaN], 2, 0.5), [p, NaN], eps) ***** assert_equal (binocdf (single ([x, NaN]), 2, 0.5), single ([p, NaN])) ***** assert_equal (binocdf ([x, NaN], single (2), 0.5), single ([p, NaN])) ***** assert_equal (binocdf ([x, NaN], 2, single (0.5)), single ([p, NaN])) ***** error binocdf () ***** error binocdf (1) ***** error binocdf (1, 2) ***** error binocdf (1, 2, 3, 4, 5) ***** error binocdf (1, 2, 3, 'tail') ***** error binocdf (1, 2, 3, 4) ***** error ... binocdf (ones (3), ones (2), ones (2)) ***** error ... binocdf (ones (2), ones (3), ones (2)) ***** error ... binocdf (ones (2), ones (2), ones (3)) ***** error binocdf (true, 2, 2) ***** error binocdf ('a', 2, 2) ***** assert_equal (class (binocdf (int32 (2), 2, 2)), 'double') ***** error binocdf (i, 2, 2) ***** error binocdf (2, i, 2) ***** error binocdf (2, 2, i) 32 tests, 32 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/ncfrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/ncfrnd.m ***** assert_equal (size (ncfrnd (1, 1, 1)), [1, 1]) ***** assert_equal (size (ncfrnd (1, ones (2, 1), 1)), [2, 1]) ***** assert_equal (size (ncfrnd (1, ones (2, 2), 1)), [2, 2]) ***** assert_equal (size (ncfrnd (ones (2, 1), 1, 1)), [2, 1]) ***** assert_equal (size (ncfrnd (ones (2, 2), 1, 1)), [2, 2]) ***** assert_equal (size (ncfrnd (1, 1, 1, 3)), [3, 3]) ***** assert_equal (size (ncfrnd (1, 1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (ncfrnd (1, 1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (ncfrnd (1, 1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (ncfrnd (1, 1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (ncfrnd (1, 1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (ncfrnd (1, 1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (ncfrnd (1, 1, 1, [])), [0, 0]) ***** assert_equal (size (ncfrnd (1, 1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (ncfrnd (1, 2, 3, -1)), [0, 0]) ***** assert_equal (size (ncfrnd (1, 2, 3, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (ncfrnd (1, 2, 3, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (ncfrnd (1, 1, 1)), "double") ***** assert_equal (class (ncfrnd (1, single (1), 1)), "single") ***** assert_equal (class (ncfrnd (1, 1, single (1))), "single") ***** assert_equal (class (ncfrnd (1, single ([1, 1]), 1)), "single") ***** assert_equal (class (ncfrnd (1, 1, single ([1, 1]))), "single") ***** assert_equal (class (ncfrnd (single (1), 1, 1)), "single") ***** assert_equal (class (ncfrnd (single ([1, 1]), 1, 1)), "single") ***** error ncfrnd () ***** error ncfrnd (1) ***** error ncfrnd (1, 2) ***** error ... ncfrnd (ones (3), ones (2), ones (2)) ***** error ... ncfrnd (ones (2), ones (3), ones (2)) ***** error ... ncfrnd (ones (2), ones (2), ones (3)) ***** error ncfrnd (i, 2, 3) ***** error ncfrnd (1, i, 3) ***** error ncfrnd (1, 2, i) ***** error ... ncfrnd (1, 2, 3, 1.2) ***** error ... ncfrnd (1, 2, 3, ones (2)) ***** error ... ncfrnd (1, 2, 3, [2 0 2.5]) ***** error ... ncfrnd (1, 2, 3, 2, 1.5, 5) ***** error ... ncfrnd (2, ones (2), 2, 3) ***** error ... ncfrnd (2, ones (2), 2, [3, 2]) ***** error ... ncfrnd (2, ones (2), 2, 3, 2) 40 tests, 40 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/chi2rnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/chi2rnd.m ***** assert_equal (size (chi2rnd (2)), [1, 1]) ***** assert_equal (size (chi2rnd (ones (2,1))), [2, 1]) ***** assert_equal (size (chi2rnd (ones (2,2))), [2, 2]) ***** assert_equal (size (chi2rnd (1, 3)), [3, 3]) ***** assert_equal (size (chi2rnd (1, [4, 1])), [4, 1]) ***** assert_equal (size (chi2rnd (1, 4, 1)), [4, 1]) ***** assert_equal (size (chi2rnd (1, 4, 1)), [4, 1]) ***** assert_equal (size (chi2rnd (1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (chi2rnd (1, 0, 1)), [0, 1]) ***** assert_equal (size (chi2rnd (1, 1, 0)), [1, 0]) ***** assert_equal (size (chi2rnd (1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (chi2rnd (1, [])), [0, 0]) ***** assert_equal (size (chi2rnd (1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (chi2rnd (1, -1)), [0, 0]) ***** assert_equal (size (chi2rnd (1, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (chi2rnd (1, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (chi2rnd (2)), "double") ***** assert_equal (class (chi2rnd (single (2))), "single") ***** assert_equal (class (chi2rnd (single ([2 2]))), "single") ***** error chi2rnd () ***** error chi2rnd (i) ***** error ... chi2rnd (1, 1.2) ***** error ... chi2rnd (1, ones (2)) ***** error ... chi2rnd (1, [2 0 2.5]) ***** error ... chi2rnd (ones (2), ones (2)) ***** error ... chi2rnd (1, 2, 1.5, 5) ***** error chi2rnd (ones (2,2), 3) ***** error chi2rnd (ones (2,2), [3, 2]) ***** error chi2rnd (ones (2,2), 2, 3) 29 tests, 29 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/tpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/tpdf.m ***** demo ## Plot various PDFs from the Student's T distribution x = -5:0.01:5; y1 = tpdf (x, 1); y2 = tpdf (x, 2); y3 = tpdf (x, 5); y4 = tpdf (x, Inf); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', x, y4, '-m') grid on xlim ([-5, 5]) ylim ([0, 0.41]) legend ({'df = 1', 'df = 2', ... 'df = 5', 'df = \infty'}, 'location', 'northeast') title ('Student''s T PDF') xlabel ('values in x') ylabel ('density') ***** test x = rand (10,1); y = 1./(pi * (1 + x.^2)); assert_equal (tpdf (x, 1), y, 5*eps); ***** shared x, y x = [-Inf 0 0.5 1 Inf]; y = 1./(pi * (1 + x.^2)); ***** assert_equal (tpdf (x, ones (1,5)), y, eps) ***** assert_equal (tpdf (x, 1), y, eps) ***** assert_equal (tpdf (x, [0 NaN 1 1 1]), [NaN NaN y(3:5)], eps) ***** assert_equal (tpdf (x, Inf), normpdf (x)) ***** assert_equal (tpdf ([x, NaN], 1), [y, NaN], eps) ***** assert_equal (tpdf (single ([x, NaN]), 1), single ([y, NaN]), eps ('single')) ***** assert_equal (tpdf ([x, NaN], single (1)), single ([y, NaN]), eps ('single')) ***** error tpdf () ***** error tpdf (1) ***** error ... tpdf (ones (3), ones (2)) ***** error ... tpdf (ones (2), ones (3)) ***** error tpdf (int32 (2), 2) ***** error tpdf (true, 2) ***** error tpdf ('a', 2) ***** error tpdf (i, 2) ***** error tpdf (2, i) 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/raylcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/raylcdf.m ***** demo ## Plot various CDFs from the Rayleigh distribution x = 0:0.01:10; p1 = raylcdf (x, 0.5); p2 = raylcdf (x, 1); p3 = raylcdf (x, 2); p4 = raylcdf (x, 3); p5 = raylcdf (x, 4); plot (x, p1, '-b', x, p2, 'g', x, p3, '-r', x, p4, '-m', x, p5, '-k') grid on ylim ([0, 1]) legend ({'σ = 0.5', 'σ = 1', 'σ = 2', ... 'σ = 3', 'σ = 4'}, 'location', 'southeast') title ('Rayleigh CDF') xlabel ('values in x') ylabel ('probability') ***** test x = 0:0.5:2.5; sigma = 1:6; p = raylcdf (x, sigma); expected_p = [0.0000, 0.0308, 0.0540, 0.0679, 0.0769, 0.0831]; assert_equal (p, expected_p, 0.001); ***** test x = 0:0.5:2.5; p = raylcdf (x, 0.5); expected_p = [0.0000, 0.3935, 0.8647, 0.9889, 0.9997, 1.0000]; assert_equal (p, expected_p, 0.001); ***** shared x, p x = [-1, 0, 1, 2, Inf]; p = [0, 0, 0.39346934028737, 0.86466471676338, 1]; ***** assert_equal (raylcdf (x, 1), p, 1e-14) ***** assert_equal (raylcdf (x, 1, 'upper'), 1 - p, 1e-14) ***** error raylcdf () ***** error raylcdf (1) ***** error raylcdf (1, 2, 'uper') ***** error raylcdf (1, 2, 3) ***** error ... raylcdf (ones (3), ones (2)) ***** error ... raylcdf (ones (2), ones (3)) ***** error raylcdf (int32 (2), 2) ***** error raylcdf (true, 2) ***** error raylcdf ('a', 2) ***** error raylcdf (i, 2) ***** error raylcdf (2, i) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/mvtpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/mvtpdf.m ***** demo ## Compute the pdf of a multivariate t distribution with correlation ## parameters rho = [1 .4; .4 1] and 2 degrees of freedom. rho = [1, 0.4; 0.4, 1]; df = 2; [X1, X2] = meshgrid (linspace (-2, 2, 25)', linspace (-2, 2, 25)'); X = [X1(:), X2(:)]; y = mvtpdf (X, rho, df); surf (X1, X2, reshape (y, 25, 25)); title ('Bivariate Student''s t probability density function'); ***** assert_equal (mvtpdf ([0 0], eye (2), 1), 0.1591549, 1E-7) ***** assert_equal (mvtpdf ([1 0], [1 0.5; 0.5 1], 2), 0.06615947, 1E-7) ***** assert_equal (mvtpdf ([1 0.4 0; 1.2 0.5 0.5; 1.4 0.6 1], ... [1 0.5 0.3; 0.5 1 0.6; 0.3 0.6 1], [5 6 7]), ... [0.04713313 0.03722421 0.02069011]', 1E-7) ***** error mvtpdf (int32 ([0, 0]), eye (2), 5) ***** error mvtpdf ([true, true], eye (2), 5) ***** error mvtpdf ('ab', eye (2), 5) 6 tests, 6 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/wishrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/wishrnd.m ***** assert_equal (size (wishrnd (1,2)), [1, 1]); ***** assert_equal (size (wishrnd (1,2,[])), [1, 1]); ***** assert_equal (size (wishrnd (1,2,1)), [1, 1]); ***** assert_equal (size (wishrnd ([],2,1)), [1, 1]); ***** assert_equal (size (wishrnd ([3 1; 1 3], 2.00001, [], 1)), [2, 2]); ***** assert_equal (size (wishrnd (eye (2), 2, [], 3)), [2, 2, 3]); ***** error wishrnd () ***** error wishrnd (1) ***** error wishrnd ([1; 1], 2) ***** test W = wishrnd (eye (3), 2.5); assert_equal (size (W), [3, 3]); ***** warning wishrnd (eye (3), 1.5); 11 tests, 11 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/logiinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/logiinv.m ***** demo ## Plot various iCDFs from the logistic distribution p = 0.001:0.001:0.999; x1 = logiinv (p, 5, 2); x2 = logiinv (p, 9, 3); x3 = logiinv (p, 9, 4); x4 = logiinv (p, 6, 2); x5 = logiinv (p, 2, 1); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', p, x4, '-c', p, x5, '-m') grid on legend ({'μ = 5, σ = 2', 'μ = 9, σ = 3', 'μ = 9, σ = 4', ... 'μ = 6, σ = 2', 'μ = 2, σ = 1'}, 'location', 'southeast') title ('Logistic iCDF') xlabel ('probability') ylabel ('x') ***** test p = [0.01:0.01:0.99]; assert_equal (logiinv (p, 0, 1), log (p ./ (1-p)), 25*eps); ***** shared p p = [-1 0 0.5 1 2]; ***** assert_equal (logiinv (p, 0, 1), [NaN -Inf 0 Inf NaN]) ***** assert_equal (logiinv (p, 0, [-1, 0, 1, 2, 3]), [NaN NaN 0 Inf NaN]) ***** assert_equal (logiinv ([p, NaN], 0, 1), [NaN -Inf 0 Inf NaN NaN]) ***** assert_equal (logiinv (single ([p, NaN]), 0, 1), single ([NaN -Inf 0 Inf NaN NaN])) ***** assert_equal (logiinv ([p, NaN], single (0), 1), single ([NaN -Inf 0 Inf NaN NaN])) ***** assert_equal (logiinv ([p, NaN], 0, single (1)), single ([NaN -Inf 0 Inf NaN NaN])) ***** error logiinv () ***** error logiinv (1) ***** error ... logiinv (1, 2) ***** error ... logiinv (1, ones (2), ones (3)) ***** error ... logiinv (ones (2), 1, ones (3)) ***** error ... logiinv (ones (2), ones (3), 1) ***** error logiinv (int32 (2), 2, 3) ***** error logiinv (true, 2, 3) ***** error logiinv ('a', 2, 3) ***** error logiinv (i, 2, 3) ***** error logiinv (1, i, 3) ***** error logiinv (1, 2, i) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/ncx2pdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/ncx2pdf.m ***** demo ## Plot various PDFs from the noncentral chi-squared distribution x = 0:0.1:10; y1 = ncx2pdf (x, 2, 1); y2 = ncx2pdf (x, 2, 2); y3 = ncx2pdf (x, 2, 3); y4 = ncx2pdf (x, 4, 1); y5 = ncx2pdf (x, 4, 2); y6 = ncx2pdf (x, 4, 3); plot (x, y1, '-r', x, y2, '-g', x, y3, '-k', ... x, y4, '-m', x, y5, '-c', x, y6, '-y') grid on xlim ([0, 10]) ylim ([0, 0.32]) legend ({'df = 2, λ = 1', 'df = 2, λ = 2', ... 'df = 2, λ = 3', 'df = 4, λ = 1', ... 'df = 4, λ = 2', 'df = 4, λ = 3'}, 'location', 'northeast') title ('Noncentral chi-squared PDF') xlabel ('values in x') ylabel ('density') ***** demo ## Compare the noncentral chi-squared PDF with LAMBDA = 2 to the ## chi-squared PDF with the same number of degrees of freedom (4). x = 0:0.1:10; y1 = ncx2pdf (x, 4, 2); y2 = chi2pdf (x, 4); plot (x, y1, '-', x, y2, '-'); grid on xlim ([0, 10]) ylim ([0, 0.32]) legend ({'Noncentral T(10,1)', 'T(10)'}, 'location', 'northwest') title ('Noncentral chi-squared vs chi-squared PDFs') xlabel ('values in x') ylabel ('density') ***** shared x1, df, d1 x1 = [-Inf, 2, NaN, 4, Inf]; df = [2, 0, -1, 1, 4]; d1 = [1, NaN, 3, -1, 2]; ***** assert_equal (ncx2pdf (x1, df, d1), [0, NaN, NaN, NaN, 0]); ***** assert_equal (ncx2pdf (x1, df, 1), [0, 0.07093996461786045, NaN, ... 0.06160064323277038, 0], 1e-14); ***** assert_equal (ncx2pdf (x1, df, 3), [0, 0.1208364909271113, NaN, ... 0.09631299762429098, 0], 1e-14); ***** assert_equal (ncx2pdf (x1, df, 2), [0, 0.1076346446244688, NaN, ... 0.08430464047296625, 0], 1e-14); ***** assert_equal (ncx2pdf (x1, 2, d1), [0, NaN, NaN, NaN, 0]); ***** assert_equal (ncx2pdf (2, df, d1), [0.1747201674611283, NaN, NaN, ... NaN, 0.1076346446244688], 1e-14); ***** assert_equal (ncx2pdf (4, df, d1), [0.09355987820265799, NaN, NaN, ... NaN, 0.1192317192431485], 1e-14); ***** error ncx2pdf () ***** error ncx2pdf (1) ***** error ncx2pdf (1, 2) ***** error ... ncx2pdf (ones (3), ones (2), ones (2)) ***** error ... ncx2pdf (ones (2), ones (3), ones (2)) ***** error ... ncx2pdf (ones (2), ones (2), ones (3)) ***** error ncx2pdf (int32 (2), 2, 2) ***** error ncx2pdf (true, 2, 2) ***** error ncx2pdf ('a', 2, 2) ***** error ncx2pdf (i, 2, 2) ***** error ncx2pdf (2, i, 2) ***** error ncx2pdf (2, 2, i) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/gpinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/gpinv.m ***** demo ## Plot various iCDFs from the generalized Pareto distribution p = 0.001:0.001:0.999; x1 = gpinv (p, 1, 1, 0); x2 = gpinv (p, 5, 1, 0); x3 = gpinv (p, 20, 1, 0); x4 = gpinv (p, 1, 2, 0); x5 = gpinv (p, 5, 2, 0); x6 = gpinv (p, 20, 2, 0); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', ... p, x4, '-c', p, x5, '-m', p, x6, '-k') grid on ylim ([0, 5]) legend ({'k = 1, σ = 1, θ = 0', 'k = 5, σ = 1, θ = 0', ... 'k = 20, σ = 1, θ = 0', 'k = 1, σ = 2, θ = 0', ... 'k = 5, σ = 2, θ = 0', 'k = 20, σ = 2, θ = 0'}, ... 'location', 'southeast') title ('Generalized Pareto iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p, y1, y2, y3 p = [-1, 0, 1/2, 1, 2]; y1 = [NaN, 0, 0.6931471805599453, Inf, NaN]; y2 = [NaN, 0, 1, Inf, NaN]; y3 = [NaN, 0, 1/2, 1, NaN]; ***** assert_equal (gpinv (p, zeros (1,5), ones (1,5), zeros (1,5)), y1) ***** assert_equal (gpinv (p, 0, 1, zeros (1,5)), y1) ***** assert_equal (gpinv (p, 0, ones (1,5), 0), y1) ***** assert_equal (gpinv (p, zeros (1,5), 1, 0), y1) ***** assert_equal (gpinv (p, 0, 1, 0), y1) ***** assert_equal (gpinv (p, 0, 1, [0, 0, NaN, 0, 0]), [y1(1:2), NaN, y1(4:5)]) ***** assert_equal (gpinv (p, 0, [1, 1, NaN, 1, 1], 0), [y1(1:2), NaN, y1(4:5)]) ***** assert_equal (gpinv (p, [0, 0, NaN, 0, 0], 1, 0), [y1(1:2), NaN, y1(4:5)]) ***** assert_equal (gpinv ([p(1:2), NaN, p(4:5)], 0, 1, 0), [y1(1:2), NaN, y1(4:5)]) ***** assert_equal (gpinv (p, ones (1,5), ones (1,5), zeros (1,5)), y2) ***** assert_equal (gpinv (p, 1, 1, zeros (1,5)), y2) ***** assert_equal (gpinv (p, 1, ones (1,5), 0), y2) ***** assert_equal (gpinv (p, ones (1,5), 1, 0), y2) ***** assert_equal (gpinv (p, 1, 1, 0), y2) ***** assert_equal (gpinv (p, 1, 1, [0, 0, NaN, 0, 0]), [y2(1:2), NaN, y2(4:5)]) ***** assert_equal (gpinv (p, 1, [1, 1, NaN, 1, 1], 0), [y2(1:2), NaN, y2(4:5)]) ***** assert_equal (gpinv (p, [1, 1, NaN, 1, 1], 1, 0), [y2(1:2), NaN, y2(4:5)]) ***** assert_equal (gpinv ([p(1:2), NaN, p(4:5)], 1, 1, 0), [y2(1:2), NaN, y2(4:5)]) ***** assert_equal (gpinv (p, -ones (1,5), ones (1,5), zeros (1,5)), y3) ***** assert_equal (gpinv (p, -1, 1, zeros (1,5)), y3) ***** assert_equal (gpinv (p, -1, ones (1,5), 0), y3) ***** assert_equal (gpinv (p, -ones (1,5), 1, 0), y3) ***** assert_equal (gpinv (p, -1, 1, 0), y3) ***** assert_equal (gpinv (p, -1, 1, [0, 0, NaN, 0, 0]), [y3(1:2), NaN, y3(4:5)]) ***** assert_equal (gpinv (p, -1, [1, 1, NaN, 1, 1], 0), [y3(1:2), NaN, y3(4:5)]) ***** assert_equal (gpinv (p, -[1, 1, NaN, 1, 1], 1, 0), [y3(1:2), NaN, y3(4:5)]) ***** assert_equal (gpinv ([p(1:2), NaN, p(4:5)], -1, 1, 0), [y3(1:2), NaN, y3(4:5)]) ***** assert_equal (gpinv (single ([p, NaN]), 0, 1, 0), single ([y1, NaN])) ***** assert_equal (gpinv ([p, NaN], 0, 1, single (0)), single ([y1, NaN])) ***** assert_equal (gpinv ([p, NaN], 0, single (1), 0), single ([y1, NaN])) ***** assert_equal (gpinv ([p, NaN], single (0), 1, 0), single ([y1, NaN])) ***** assert_equal (gpinv (single ([p, NaN]), 1, 1, 0), single ([y2, NaN])) ***** assert_equal (gpinv ([p, NaN], 1, 1, single (0)), single ([y2, NaN])) ***** assert_equal (gpinv ([p, NaN], 1, single (1), 0), single ([y2, NaN])) ***** assert_equal (gpinv ([p, NaN], single (1), 1, 0), single ([y2, NaN])) ***** assert_equal (gpinv (single ([p, NaN]), -1, 1, 0), single ([y3, NaN])) ***** assert_equal (gpinv ([p, NaN], -1, 1, single (0)), single ([y3, NaN])) ***** assert_equal (gpinv ([p, NaN], -1, single (1), 0), single ([y3, NaN])) ***** assert_equal (gpinv ([p, NaN], single (-1), 1, 0), single ([y3, NaN])) ***** error gpinv () ***** error gpinv (1) ***** error gpinv (1, 2) ***** error gpinv (1, 2, 3) ***** error ... gpinv (ones (3), ones (2), ones (2), ones (2)) ***** error ... gpinv (ones (2), ones (3), ones (2), ones (2)) ***** error ... gpinv (ones (2), ones (2), ones (3), ones (2)) ***** error ... gpinv (ones (2), ones (2), ones (2), ones (3)) ***** error gpinv (int32 (2), 2, 3, 4) ***** error gpinv (true, 2, 3, 4) ***** error gpinv ('a', 2, 3, 4) ***** error gpinv (i, 2, 3, 4) ***** error gpinv (1, i, 3, 4) ***** error gpinv (1, 2, i, 4) ***** error gpinv (1, 2, 3, i) 54 tests, 54 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/mvtcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/mvtcdf.m ***** demo ## Compute the cdf of a multivariate Student's t distribution with ## correlation parameters rho = [1, 0.4; 0.4, 1] and 2 degrees of freedom. rho = [1, 0.4; 0.4, 1]; df = 2; [X1, X2] = meshgrid (linspace (-2, 2, 25)', linspace (-2, 2, 25)'); X = [X1(:), X2(:)]; p = mvtcdf (X, rho, df); surf (X1, X2, reshape (p, 25, 25)); title ('Bivariate Student''s t cumulative distribution function'); ***** test x = [1, 2]; rho = [1, 0.5; 0.5, 1]; df = 4; a = [-1, 0]; assert_equal (mvtcdf (a, x, rho, df), 0.294196905339283, 1e-14); ***** test x = [1, 2;2, 4;1, 5]; rho = [1, 0.5; 0.5, 1]; df = 4; p =[0.790285178602166; 0.938703291727784; 0.81222737321336]; assert_equal (mvtcdf (x, rho, df), p, 1e-14); ***** test x = [1, 2, 2, 4, 1, 5]; rho = eye (6); rho(rho == 0) = 0.5; df = 4; assert_equal (mvtcdf (x, rho, df), 0.6874, 1e-4); !!!!! test failed ASSERT errors for: assert_equal (mvtcdf (x, rho, df),0.6874,1e-4) Location | Observed | Expected | Reason () 0.6873 0.6874 Abs err 0.00010377 exceeds tol 0.0001 by 4e-06 ***** test # MATLAB parity: an options field missing or empty takes its default rho = [1, 0.5; 0.5, 1]; p = 1 / 3; assert_equal (mvtcdf ([0, 0], rho, 5, statset ('TolFun', 1e-4)), p, 1e-8); assert_equal (mvtcdf ([0, 0], rho, 5, struct ('TolFun', 1e-4)), p, 1e-8); assert_equal (mvtcdf ([0, 0], rho, 5, struct ('Display', 'final')), p, 1e-8); ***** error mvtcdf (int32 ([0, 0]), eye (2), 5) ***** error mvtcdf ([true, true], eye (2), 5) ***** error mvtcdf ('ab', eye (2), 5) ***** error mvtcdf (1) ***** error mvtcdf (1, 2) ***** error ... mvtcdf ([0, 0], eye (2), 5, struct ('Display', 'bogus')) ***** error ... mvtcdf (1, [2, 3; 3, 2], 1) ***** error ... mvtcdf ([2, 3, 4], ones (2), 1) ***** error ... mvtcdf ([1, 2, 3], [2, 3], ones (2), 1) ***** error ... mvtcdf ([2, 3], ones (2), [1, 2, 3]) ***** error ... mvtcdf ([2, 3], [1, 0.5; 0.5, 1], [1, 2, 3]) 15 tests, 14 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/expinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/expinv.m ***** demo ## Plot various iCDFs from the exponential distribution p = 0.001:0.001:0.999; x1 = expinv (p, 2/3); x2 = expinv (p, 1.0); x3 = expinv (p, 2.0); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r') grid on ylim ([0, 5]) legend ({'μ = 2/3', 'μ = 1', 'μ = 2'}, 'location', 'northwest') title ('Exponential iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p p = [-1 0 0.3934693402873666 1 2]; ***** assert_equal (expinv (p, 2*ones (1,5)), [NaN 0 1 Inf NaN], eps) ***** assert_equal (expinv (p, 2), [NaN 0 1 Inf NaN], eps) ***** assert_equal (expinv (p, 2*[1 0 NaN 1 1]), [NaN NaN NaN Inf NaN], eps) ***** assert_equal (expinv ([p(1:2) NaN p(4:5)], 2), [NaN 0 NaN Inf NaN], eps) ***** assert_equal (expinv ([p, NaN], 2), [NaN 0 1 Inf NaN NaN], eps) ***** assert_equal (expinv (single ([p, NaN]), 2), single ([NaN 0 1 Inf NaN NaN]), eps) ***** assert_equal (expinv ([p, NaN], single (2)), single ([NaN 0 1 Inf NaN NaN]), eps) ***** error expinv () ***** error expinv (1, 2 ,3 ,4 ,5) ***** error ... expinv (ones (3), ones (2)) ***** error ... expinv (2, 3, [1, 2]) ***** error ... [x, xlo, xup] = expinv (1, 2) ***** error [x, xlo, xup] = ... expinv (1, 2, 3, 0) ***** error [x, xlo, xup] = ... expinv (1, 2, 3, 1.22) ***** error [x, xlo, xup] = ... expinv (1, 2, 3, [0.05, 0.1]) ***** error expinv (int32 (2), 2) ***** error expinv (true, 2) ***** error expinv ('a', 2) ***** error expinv (i, 2) ***** error expinv (2, i) ***** error ... [x, xlo, xup] = expinv (1, 2, -1, 0.04) 21 tests, 21 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/exprnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/exprnd.m ***** assert_equal (size (exprnd (2)), [1, 1]) ***** assert_equal (size (exprnd (ones (2,1))), [2, 1]) ***** assert_equal (size (exprnd (ones (2,2))), [2, 2]) ***** assert_equal (size (exprnd (1, 3)), [3, 3]) ***** assert_equal (size (exprnd (1, [4 1])), [4, 1]) ***** assert_equal (size (exprnd (1, 4, 1)), [4, 1]) ***** assert_equal (size (exprnd (1, 4, 1)), [4, 1]) ***** assert_equal (size (exprnd (1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (exprnd (1, 0, 1)), [0, 1]) ***** assert_equal (size (exprnd (1, 1, 0)), [1, 0]) ***** assert_equal (size (exprnd (1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (exprnd (1, [])), [0, 0]) ***** assert_equal (size (exprnd (1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (exprnd (1, -1)), [0, 0]) ***** assert_equal (size (exprnd (1, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (exprnd (1, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (exprnd (2)), "double") ***** assert_equal (class (exprnd (single (2))), "single") ***** assert_equal (class (exprnd (single ([2 2]))), "single") ***** error exprnd () ***** error exprnd (i) ***** error ... exprnd (1, 1.2) ***** error ... exprnd (1, ones (2)) ***** error ... exprnd (1, [2 0 2.5]) ***** error ... exprnd (ones (2), ones (2)) ***** error ... exprnd (1, 2, 1.5, 5) ***** error exprnd (ones (2,2), 3) ***** error exprnd (ones (2,2), [3, 2]) ***** error exprnd (ones (2,2), 2, 3) 29 tests, 29 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/plcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/plcdf.m ***** demo ## Plot various CDFs from the Piecewise linear distribution data = 0:0.01:10; x1 = [0, 1, 3, 4, 7, 10]; Fx1 = [0, 0.2, 0.5, 0.6, 0.7, 1]; x2 = [0, 2, 5, 6, 7, 8]; Fx2 = [0, 0.1, 0.3, 0.6, 0.9, 1]; p1 = plcdf (data, x1, Fx1); p2 = plcdf (data, x2, Fx2); plot (data, p1, '-b', data, p2, 'g') grid on ylim ([0, 1]) xlim ([0, 10]) legend ({'x1, Fx1', 'x2, Fx2'}, 'location', 'southeast') title ('Piecewise linear CDF') xlabel ('values in data') ylabel ('probability') ***** test data = 0:0.2:1; p = plcdf (data, [0, 1], [0, 1]); assert_equal (p, data); ***** test data = 0:0.2:1; p = plcdf (data, [0, 2], [0, 1]); assert_equal (p, 0.5 * data); ***** test data = 0:0.2:1; p = plcdf (data, [0, 1], [0, 0.5]); assert_equal (p, 0.5 * data); ***** test data = 0:0.2:1; p = plcdf (data, [0, 0.5], [0, 1]); assert_equal (p, [0, 0.4, 0.8, 1, 1, 1]); ***** test data = 0:0.2:1; p = plcdf (data, [0, 1], [0, 1], 'upper'); assert_equal (p, 1 - data); ***** error plcdf () ***** error plcdf (1) ***** error plcdf (1, 2) ***** error plcdf (1, 2, 3, 'uper') ***** error plcdf (1, 2, 3, 4) ***** error ... plcdf (1, [0, 1, 2], [0, 1]) ***** error ... plcdf (1, [0], [1]) ***** error ... plcdf (1, [0, 1, 2], [0, 1, 1.5]) ***** error ... plcdf (1, [0, 1, 2], [0, i, 1]) ***** error ... plcdf (int32 (2), [0, 1, 2], [0, 0.5, 1]) ***** error ... plcdf (true, [0, 1, 2], [0, 0.5, 1]) ***** error ... plcdf ('a', [0, 1, 2], [0, 0.5, 1]) ***** error ... plcdf (i, [0, 1, 2], [0, 0.5, 1]) ***** error ... plcdf (1, [0, i, 2], [0, 0.5, 1]) ***** error ... plcdf (1, [0, 1, 2], [0, 0.5i, 1]) 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/hygecdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/hygecdf.m ***** demo ## Plot various CDFs from the hypergeometric distribution x = 0:60; p1 = hygecdf (x, 500, 50, 100); p2 = hygecdf (x, 500, 60, 200); p3 = hygecdf (x, 500, 70, 300); plot (x, p1, '*b', x, p2, '*g', x, p3, '*r') grid on xlim ([0, 60]) legend ({'m = 500, k = 50, n = 100', 'm = 500, k = 60, n = 200', ... 'm = 500, k = 70, n = 300'}, 'location', 'southeast') title ('Hypergeometric CDF') xlabel ('values in x (number of successes)') ylabel ('probability') ***** shared x, y x = [-1 0 1 2 3]; y = [0 1/6 5/6 1 1]; ***** assert_equal (hygecdf (x, 4*ones (1,5), 2, 2), y, 5*eps) ***** assert_equal (hygecdf (x, 4, 2*ones (1,5), 2), y, 5*eps) ***** assert_equal (hygecdf (x, 4, 2, 2*ones (1,5)), y, 5*eps) ***** assert_equal (hygecdf (x, 4*[1 -1 NaN 1.1 1], 2, 2), [y(1) NaN NaN NaN y(5)], 5*eps) ***** assert_equal (hygecdf (x, 4*[1 -1 NaN 1.1 1], 2, 2, 'upper'), ... [y(5) NaN NaN NaN y(1)], 5*eps) ***** assert_equal (hygecdf (x, 4, 2*[1 -1 NaN 1.1 1], 2), [y(1) NaN NaN NaN y(5)], 5*eps) ***** assert_equal (hygecdf (x, 4, 2*[1 -1 NaN 1.1 1], 2, 'upper'), ... [y(5) NaN NaN NaN y(1)], 5*eps) ***** assert_equal (hygecdf (x, 4, 5, 2), [NaN NaN NaN NaN NaN]) ***** assert_equal (hygecdf (x, 4, 2, 2*[1 -1 NaN 1.1 1]), [y(1) NaN NaN NaN y(5)], 5*eps) ***** assert_equal (hygecdf (x, 4, 2, 2*[1 -1 NaN 1.1 1], 'upper'), ... [y(5) NaN NaN NaN y(1)], 5*eps) ***** assert_equal (hygecdf (x, 4, 2, 5), [NaN NaN NaN NaN NaN]) ***** assert_equal (hygecdf ([x(1:2) NaN x(4:5)], 4, 2, 2), [y(1:2) NaN y(4:5)], 5*eps) ***** test p = hygecdf (x, 10, [1 2 3 4 5], 2, 'upper'); assert_equal (p, [1, 34/90, 2/30, 0, 0], 10*eps); ***** test p = hygecdf (2*x, 10, [1 2 3 4 5], 2, 'upper'); assert_equal (p, [1, 34/90, 0, 0, 0], 10*eps); ***** assert_equal (hygecdf ([x, NaN], 4, 2, 2), [y, NaN], 5*eps) ***** assert_equal (hygecdf (single ([x, NaN]), 4, 2, 2), single ([y, NaN]), ... eps ('single')) ***** assert_equal (hygecdf ([x, NaN], single (4), 2, 2), single ([y, NaN]), ... eps ('single')) ***** assert_equal (hygecdf ([x, NaN], 4, single (2), 2), single ([y, NaN]), ... eps ('single')) ***** assert_equal (hygecdf ([x, NaN], 4, 2, single (2)), single ([y, NaN]), ... eps ('single')) ***** error hygecdf () ***** error hygecdf (1) ***** error hygecdf (1,2) ***** error hygecdf (1,2,3) ***** error hygecdf (1,2,3,4,5) ***** error hygecdf (1,2,3,4,'uper') ***** error ... hygecdf (ones (2), ones (3), 1, 1) ***** error ... hygecdf (1, ones (2), ones (3), 1) ***** error ... hygecdf (1, 1, ones (2), ones (3)) ***** error hygecdf (true, 2, 2, 2) ***** error hygecdf ('a', 2, 2, 2) ***** assert_equal (class (hygecdf (int32 (2), 2, 2, 2)), 'double') ***** error hygecdf (i, 2, 2, 2) ***** error hygecdf (2, i, 2, 2) ***** error hygecdf (2, 2, i, 2) ***** error hygecdf (2, 2, 2, i) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/evcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/evcdf.m ***** demo ## Plot various CDFs from the extreme value distribution x = -10:0.01:10; p1 = evcdf (x, 0.5, 2); p2 = evcdf (x, 1.0, 2); p3 = evcdf (x, 1.5, 3); p4 = evcdf (x, 3.0, 4); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', x, p4, '-c') grid on legend ({'μ = 0.5, σ = 2', 'μ = 1.0, σ = 2', ... 'μ = 1.5, σ = 3', 'μ = 3.0, σ = 4'}, 'location', 'southeast') title ('Extreme value CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y x = [-Inf, 1, 2, Inf]; y = [0, 0.6321, 0.9340, 1]; ***** assert_equal (evcdf (x, ones (1,4), ones (1,4)), y, 1e-4) ***** assert_equal (evcdf (x, 1, ones (1,4)), y, 1e-4) ***** assert_equal (evcdf (x, ones (1,4), 1), y, 1e-4) ***** assert_equal (evcdf (x, [0, -Inf, NaN, Inf], 1), [0, 1, NaN, NaN], 1e-4) ***** assert_equal (evcdf (x, 1, [Inf, NaN, -1, 0]), [NaN, NaN, NaN, NaN], 1e-4) ***** assert_equal (evcdf ([x(1:2), NaN, x(4)], 1, 1), [y(1:2), NaN, y(4)], 1e-4) ***** assert_equal (evcdf (x, 'upper'), [1, 0.0660, 0.0006, 0], 1e-4) ***** assert_equal (evcdf ([x, NaN], 1, 1), [y, NaN], 1e-4) ***** assert_equal (evcdf (single ([x, NaN]), 1, 1), single ([y, NaN]), 1e-4) ***** assert_equal (evcdf ([x, NaN], single (1), 1), single ([y, NaN]), 1e-4) ***** assert_equal (evcdf ([x, NaN], 1, single (1)), single ([y, NaN]), 1e-4) ***** error evcdf () ***** error evcdf (1,2,3,4,5,6,7) ***** error evcdf (1, 2, 3, 4, 'uper') ***** error ... evcdf (ones (3), ones (2), ones (2)) ***** error evcdf (2, 3, 4, [1, 2]) ***** error ... [p, plo, pup] = evcdf (1, 2, 3) ***** error [p, plo, pup] = ... evcdf (1, 2, 3, [1, 0; 0, 1], 0) ***** error [p, plo, pup] = ... evcdf (1, 2, 3, [1, 0; 0, 1], 1.22) ***** error [p, plo, pup] = ... evcdf (1, 2, 3, [1, 0; 0, 1], 'alpha', 'upper') ***** error evcdf (int32 (2), 2, 2) ***** error evcdf (true, 2, 2) ***** error evcdf ('a', 2, 2) ***** error evcdf (i, 2, 2) ***** error evcdf (2, i, 2) ***** error evcdf (2, 2, i) ***** error ... [p, plo, pup] = evcdf (1, 2, 3, [1, 0; 0, -inf], 0.04) 27 tests, 27 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/hygernd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/hygernd.m ***** assert_equal (size (hygernd (4, 2, 2)), [1, 1]) ***** assert_equal (size (hygernd (4 * ones (2, 1), 2,2)), [2, 1]) ***** assert_equal (size (hygernd (4 * ones (2, 2), 2,2)), [2, 2]) ***** assert_equal (size (hygernd (4, 2 * ones (2, 1), 2)), [2, 1]) ***** assert_equal (size (hygernd (4, 2 * ones (2, 2), 2)), [2, 2]) ***** assert_equal (size (hygernd (4, 2, 2 * ones (2, 1))), [2, 1]) ***** assert_equal (size (hygernd (4, 2, 2 * ones (2, 2))), [2, 2]) ***** assert_equal (size (hygernd (4, 2, 2, 3)), [3, 3]) ***** assert_equal (size (hygernd (4, 2, 2, [4, 1])), [4, 1]) ***** assert_equal (size (hygernd (4, 2, 2, 4, 1)), [4, 1]) ***** assert_equal (size (hygernd (4, 2, 2, [])), [0, 0]) ***** assert_equal (size (hygernd (4, 2, 2, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (hygernd (1, 2, 3, -1)), [0, 0]) ***** assert_equal (size (hygernd (1, 2, 3, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (hygernd (1, 2, 3, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (hygernd (4, 2, 2)), "double") ***** assert_equal (class (hygernd (single (4), 2, 2)), "single") ***** assert_equal (class (hygernd (single ([4, 4]), 2, 2)), "single") ***** assert_equal (class (hygernd (4, single (2), 2)), "single") ***** assert_equal (class (hygernd (4, single ([2, 2]),2)), "single") ***** assert_equal (class (hygernd (4, 2, single (2))), "single") ***** assert_equal (class (hygernd (4, 2, single ([2, 2]))), "single") ***** error hygernd () ***** error hygernd (1) ***** error hygernd (1, 2) ***** error ... hygernd (ones (3), ones (2), ones (2)) ***** error ... hygernd (ones (2), ones (3), ones (2)) ***** error ... hygernd (ones (2), ones (2), ones (3)) ***** error hygernd (i, 2, 3) ***** error hygernd (1, i, 3) ***** error hygernd (1, 2, i) ***** error ... hygernd (1, 2, 3, 1.2) ***** error ... hygernd (1, 2, 3, ones (2)) ***** error ... hygernd (1, 2, 3, [2 0 2.5]) ***** error ... hygernd (1, 2, 3, 2, 1.5, 5) ***** error ... hygernd (2, ones (2), 2, 3) ***** error ... hygernd (2, ones (2), 2, [3, 2]) ***** error ... hygernd (2, ones (2), 2, 3, 2) 38 tests, 38 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/gamrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/gamrnd.m ***** assert_equal (size (gamrnd (1, 1)), [1 1]) ***** assert_equal (size (gamrnd (1, ones (2,1))), [2, 1]) ***** assert_equal (size (gamrnd (1, ones (2,2))), [2, 2]) ***** assert_equal (size (gamrnd (ones (2,1), 1)), [2, 1]) ***** assert_equal (size (gamrnd (ones (2,2), 1)), [2, 2]) ***** assert_equal (size (gamrnd (1, 1, 3)), [3, 3]) ***** assert_equal (size (gamrnd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (gamrnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (gamrnd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (gamrnd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (gamrnd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (gamrnd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (gamrnd (1, 1, [])), [0, 0]) ***** assert_equal (size (gamrnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (gamrnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (gamrnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (gamrnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (gamrnd (1, 1)), "double") ***** assert_equal (class (gamrnd (1, single (1))), "single") ***** assert_equal (class (gamrnd (1, single ([1, 1]))), "single") ***** assert_equal (class (gamrnd (single (1), 1)), "single") ***** assert_equal (class (gamrnd (single ([1, 1]), 1)), "single") ***** error gamrnd () ***** error gamrnd (1) ***** error ... gamrnd (ones (3), ones (2)) ***** error ... gamrnd (ones (2), ones (3)) ***** error gamrnd (i, 2, 3) ***** error gamrnd (1, i, 3) ***** error ... gamrnd (1, 2, 1.2) ***** error ... gamrnd (1, 2, ones (2)) ***** error ... gamrnd (1, 2, [2 0 2.5]) ***** error ... gamrnd (1, 2, 2, 1.5, 5) ***** error ... gamrnd (2, ones (2), 3) ***** error ... gamrnd (2, ones (2), [3, 2]) ***** error ... gamrnd (2, ones (2), 3, 2) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/bisarnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/bisarnd.m ***** assert_equal (size (bisarnd (1, 1)), [1 1]) ***** assert_equal (size (bisarnd (1, ones (2,1))), [2, 1]) ***** assert_equal (size (bisarnd (1, ones (2,2))), [2, 2]) ***** assert_equal (size (bisarnd (ones (2,1), 1)), [2, 1]) ***** assert_equal (size (bisarnd (ones (2,2), 1)), [2, 2]) ***** assert_equal (size (bisarnd (1, 1, 3)), [3, 3]) ***** assert_equal (size (bisarnd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (bisarnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (bisarnd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (bisarnd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (bisarnd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (bisarnd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (bisarnd (1, 1, [])), [0, 0]) ***** assert_equal (size (bisarnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (bisarnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (bisarnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (bisarnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (bisarnd (1, 1)), "double") ***** assert_equal (class (bisarnd (1, single (1))), "single") ***** assert_equal (class (bisarnd (1, single ([1, 1]))), "single") ***** assert_equal (class (bisarnd (single (1), 1)), "single") ***** assert_equal (class (bisarnd (single ([1, 1]), 1)), "single") ***** error bisarnd () ***** error bisarnd (1) ***** error ... bisarnd (ones (3), ones (2)) ***** error ... bisarnd (ones (2), ones (3)) ***** error bisarnd (i, 2, 3) ***** error bisarnd (1, i, 3) ***** error ... bisarnd (1, 2, 1.2) ***** error ... bisarnd (1, 2, ones (2)) ***** error ... bisarnd (1, 2, [2 0 2.5]) ***** error ... bisarnd (1, 2, 2, 1.5, 5) ***** error ... bisarnd (2, ones (2), 3) ***** error ... bisarnd (2, ones (2), [3, 2]) ***** error ... bisarnd (2, ones (2), 3, 2) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/gprnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/gprnd.m ***** assert_equal (size (gprnd (0, 1, 0)), [1, 1]) ***** assert_equal (size (gprnd (0, 1, zeros (2,1))), [2, 1]) ***** assert_equal (size (gprnd (0, 1, zeros (2,2))), [2, 2]) ***** assert_equal (size (gprnd (0, ones (2,1), 0)), [2, 1]) ***** assert_equal (size (gprnd (0, ones (2,2), 0)), [2, 2]) ***** assert_equal (size (gprnd (zeros (2,1), 1, 0)), [2, 1]) ***** assert_equal (size (gprnd (zeros (2,2), 1, 0)), [2, 2]) ***** assert_equal (size (gprnd (0, 1, 0, 3)), [3, 3]) ***** assert_equal (size (gprnd (0, 1, 0, [4 1])), [4, 1]) ***** assert_equal (size (gprnd (0, 1, 0, 4, 1)), [4, 1]) ***** assert_equal (size (gprnd (1,1,0)), [1, 1]) ***** assert_equal (size (gprnd (1, 1, zeros (2,1))), [2, 1]) ***** assert_equal (size (gprnd (1, 1, zeros (2,2))), [2, 2]) ***** assert_equal (size (gprnd (1, ones (2,1), 0)), [2, 1]) ***** assert_equal (size (gprnd (1, ones (2,2), 0)), [2, 2]) ***** assert_equal (size (gprnd (ones (2,1), 1, 0)), [2, 1]) ***** assert_equal (size (gprnd (ones (2,2), 1, 0)), [2, 2]) ***** assert_equal (size (gprnd (1, 1, 0, 3)), [3, 3]) ***** assert_equal (size (gprnd (1, 1, 0, [4 1])), [4, 1]) ***** assert_equal (size (gprnd (1, 1, 0, 4, 1)), [4, 1]) ***** assert_equal (size (gprnd (-1, 1, 0)), [1, 1]) ***** assert_equal (size (gprnd (-1, 1, zeros (2,1))), [2, 1]) ***** assert_equal (size (gprnd (1, -1, zeros (2,2))), [2, 2]) ***** assert_equal (size (gprnd (-1, ones (2,1), 0)), [2, 1]) ***** assert_equal (size (gprnd (-1, ones (2,2), 0)), [2, 2]) ***** assert_equal (size (gprnd (-ones (2,1), 1, 0)), [2, 1]) ***** assert_equal (size (gprnd (-ones (2,2), 1, 0)), [2, 2]) ***** assert_equal (size (gprnd (-1, 1, 0, 3)), [3, 3]) ***** assert_equal (size (gprnd (-1, 1, 0, [4, 1])), [4, 1]) ***** assert_equal (size (gprnd (-1, 1, 0, 4, 1)), [4, 1]) ***** assert_equal (size (gprnd (-1, 1, 0, [])), [0, 0]) ***** assert_equal (size (gprnd (-1, 1, 0, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (gprnd (1, 2, 3, -1)), [0, 0]) ***** assert_equal (size (gprnd (1, 2, 3, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (gprnd (1, 2, 3, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (gprnd (0, 1, 0)), "double") ***** assert_equal (class (gprnd (0, 1, single (0))), "single") ***** assert_equal (class (gprnd (0, 1, single ([0, 0]))), "single") ***** assert_equal (class (gprnd (0, single (1),0)), "single") ***** assert_equal (class (gprnd (0, single ([1, 1]),0)), "single") ***** assert_equal (class (gprnd (single (0), 1, 0)), "single") ***** assert_equal (class (gprnd (single ([0, 0]), 1, 0)), "single") ***** error gprnd () ***** error gprnd (1) ***** error gprnd (1, 2) ***** error ... gprnd (ones (3), ones (2), ones (2)) ***** error ... gprnd (ones (2), ones (3), ones (2)) ***** error ... gprnd (ones (2), ones (2), ones (3)) ***** error gprnd (i, 2, 3) ***** error gprnd (1, i, 3) ***** error gprnd (1, 2, i) ***** error ... gprnd (1, 2, 3, 1.2) ***** error ... gprnd (1, 2, 3, ones (2)) ***** error ... gprnd (1, 2, 3, [2 0 2.5]) ***** error ... gprnd (1, 2, 3, 2, 1.5, 5) ***** error ... gprnd (2, ones (2), 2, 3) ***** error ... gprnd (2, ones (2), 2, [3, 2]) ***** error ... gprnd (2, ones (2), 2, 3, 2) 58 tests, 58 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/tlsrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/tlsrnd.m ***** assert_equal (size (tlsrnd (1, 2, 3)), [1, 1]) ***** assert_equal (size (tlsrnd (ones (2, 1), 2, 3)), [2, 1]) ***** assert_equal (size (tlsrnd (ones (2, 2), 2, 3)), [2, 2]) ***** assert_equal (size (tlsrnd (1, 2, 3, 3)), [3, 3]) ***** assert_equal (size (tlsrnd (1, 2, 3, [4, 1])), [4, 1]) ***** assert_equal (size (tlsrnd (1, 2, 3, 4, 1)), [4, 1]) ***** assert_equal (size (tlsrnd (1, 2, 3, 4, 1)), [4, 1]) ***** assert_equal (size (tlsrnd (1, 2, 3, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (tlsrnd (1, 2, 3, 0, 1)), [0, 1]) ***** assert_equal (size (tlsrnd (1, 2, 3, 1, 0)), [1, 0]) ***** assert_equal (size (tlsrnd (1, 2, 3, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (tlsrnd (1, 2, 3, [])), [0, 0]) ***** assert_equal (size (tlsrnd (1, 2, 3, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (tlsrnd (1, 2, 3, -1)), [0, 0]) ***** assert_equal (size (tlsrnd (1, 2, 3, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (tlsrnd (1, 2, 3, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (tlsrnd (1, 2, 0, 1, 1), NaN) ***** assert_equal (tlsrnd (1, 2, [0, 0, 0], [1, 3]), [NaN, NaN, NaN]) ***** assert_equal (class (tlsrnd (1, 2, 3)), "double") ***** assert_equal (class (tlsrnd (single (1), 2, 3)), "single") ***** assert_equal (class (tlsrnd (single ([1, 1]), 2, 3)), "single") ***** assert_equal (class (tlsrnd (1, single (2), 3)), "single") ***** assert_equal (class (tlsrnd (1, single ([2, 2]), 3)), "single") ***** assert_equal (class (tlsrnd (1, 2, single (3))), "single") ***** assert_equal (class (tlsrnd (1, 2, single ([3, 3]))), "single") ***** error tlsrnd () ***** error tlsrnd (1) ***** error tlsrnd (1, 2) ***** error ... tlsrnd (ones (3), ones (2), 1) ***** error ... tlsrnd (ones (2), 1, ones (3)) ***** error ... tlsrnd (1, ones (2), ones (3)) ***** error tlsrnd (i, 2, 3) ***** error tlsrnd (1, i, 3) ***** error tlsrnd (1, 2, i) ***** error ... tlsrnd (1, 2, 3, 1.2) ***** error ... tlsrnd (1, 2, 3, ones (2)) ***** error ... tlsrnd (1, 2, 3, [2 0 2.5]) ***** error ... tlsrnd (ones (2), 2, 3, ones (2)) ***** error ... tlsrnd (1, 2, 3, 2, 1.5, 5) ***** error ... tlsrnd (ones (2,2), 2, 3, 3) ***** error ... tlsrnd (1, ones (2,2), 3, 3) ***** error ... tlsrnd (1, 2, ones (2,2), 3) ***** error ... tlsrnd (1, 2, ones (2,2), [3, 3]) ***** error ... tlsrnd (1, 2, ones (2,2), 2, 3) 44 tests, 44 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/plrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/plrnd.m ***** shared x, Fx x = [0, 1, 3, 4, 7, 10]; Fx = [0, 0.2, 0.5, 0.6, 0.7, 1]; ***** assert_equal (size (plrnd (x, Fx)), [1, 1]) ***** assert_equal (size (plrnd (x, Fx, 3)), [3, 3]) ***** assert_equal (size (plrnd (x, Fx, [4, 1])), [4, 1]) ***** assert_equal (size (plrnd (x, Fx, 4, 1)), [4, 1]) ***** assert_equal (size (plrnd (x, Fx, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (plrnd (x, Fx, 0, 1)), [0, 1]) ***** assert_equal (size (plrnd (x, Fx, 1, 0)), [1, 0]) ***** assert_equal (size (plrnd (x, Fx, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (plrnd (x, Fx, [])), [0, 0]) ***** assert_equal (size (plrnd (x, Fx, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (plrnd (x, Fx, -1)), [0, 0]) ***** assert_equal (size (plrnd (x, Fx, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (plrnd (x, Fx, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (plrnd (x, Fx)), "double") ***** assert_equal (class (plrnd (x, single (Fx))), "single") ***** assert_equal (class (plrnd (single (x), Fx)), "single") ***** error plrnd () ***** error plrnd (1) ***** error ... plrnd ([0, 1, 2], [0, 1]) ***** error ... plrnd ([0], [1]) ***** error ... plrnd ([0, 1, 2], [0, 1, 1.5]) ***** error ... plrnd ([0, 1, 2], [0, i, 1]) ***** error ... plrnd ([0, i, 2], [0, 0.5, 1]) ***** error ... plrnd ([0, i, 2], [0, 0.5i, 1]) ***** error ... plrnd (x, Fx, 1.2) ***** error ... plrnd (x, Fx, ones (2)) ***** error ... plrnd (x, Fx, [2 0 2.5]) ***** error ... plrnd (x, Fx, 2, 1.5, 5) 28 tests, 28 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/evrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/evrnd.m ***** assert_equal (size (evrnd (1, 1)), [1 1]) ***** assert_equal (size (evrnd (1, ones (2,1))), [2, 1]) ***** assert_equal (size (evrnd (1, ones (2,2))), [2, 2]) ***** assert_equal (size (evrnd (ones (2,1), 1)), [2, 1]) ***** assert_equal (size (evrnd (ones (2,2), 1)), [2, 2]) ***** assert_equal (size (evrnd (1, 1, 3)), [3, 3]) ***** assert_equal (size (evrnd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (evrnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (evrnd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (evrnd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (evrnd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (evrnd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (evrnd (1, 1, [])), [0, 0]) ***** assert_equal (size (evrnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (evrnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (evrnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (evrnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (evrnd (1, 1)), "double") ***** assert_equal (class (evrnd (1, single (1))), "single") ***** assert_equal (class (evrnd (1, single ([1, 1]))), "single") ***** assert_equal (class (evrnd (single (1), 1)), "single") ***** assert_equal (class (evrnd (single ([1, 1]), 1)), "single") ***** error evrnd () ***** error evrnd (1) ***** error ... evrnd (ones (3), ones (2)) ***** error ... evrnd (ones (2), ones (3)) ***** error evrnd (i, 2, 3) ***** error evrnd (1, i, 3) ***** error ... evrnd (1, 2, 1.2) ***** error ... evrnd (1, 2, ones (2)) ***** error ... evrnd (1, 2, [2 0 2.5]) ***** error ... evrnd (1, 2, 2, 1.5, 5) ***** error ... evrnd (2, ones (2), 3) ***** error ... evrnd (2, ones (2), [3, 2]) ***** error ... evrnd (2, ones (2), 3, 2) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/tlscdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/tlscdf.m ***** demo ## Plot various CDFs from the location-scale Student's T distribution x = -8:0.01:8; p1 = tlscdf (x, 0, 1, 1); p2 = tlscdf (x, 0, 2, 2); p3 = tlscdf (x, 3, 2, 5); p4 = tlscdf (x, -1, 3, Inf); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', x, p4, '-m') grid on xlim ([-8, 8]) ylim ([0, 1]) legend ({'mu = 0, sigma = 1, nu = 1', 'mu = 0, sigma = 2, nu = 2', ... 'mu = 3, sigma = 2, nu = 5', 'mu = -1, sigma = 3, nu = \infty'}, ... 'location', 'northwest') title ('Location-scale Student''s T CDF') xlabel ('values in x') ylabel ('probability') ***** shared x,y x = [-Inf 0 1 Inf]; y = [0 1/2 3/4 1]; ***** assert_equal (tlscdf (x, 0, 1, ones (1,4)), y, eps) ***** assert_equal (tlscdf (x, 0, 1, 1), y, eps) ***** assert_equal (tlscdf (x, 0, 1, [0 1 NaN 1]), [NaN 1/2 NaN 1], eps) ***** assert_equal (tlscdf ([x(1:2) NaN x(4)], 0, 1, 1), [y(1:2) NaN y(4)], eps) ***** assert_equal (tlscdf (2, 0, 1, 3, 'upper'), 0.0697, 1e-4) ***** assert_equal (tlscdf (205, 0, 1, 5, 'upper'), 2.6206e-11, 1e-14) ***** assert_equal (tlscdf ([x, NaN], 0, 1, 1), [y, NaN], eps) ***** assert_equal (tlscdf (single ([x, NaN]), 0, 1, 1), single ([y, NaN]), eps ('single')) ***** assert_equal (tlscdf ([x, NaN], single (0), 1, 1), single ([y, NaN]), eps ('single')) ***** assert_equal (tlscdf ([x, NaN], 0, single (1), 1), single ([y, NaN]), eps ('single')) ***** assert_equal (tlscdf ([x, NaN], 0, 1, single (1)), single ([y, NaN]), eps ('single')) ***** error tlscdf () ***** error tlscdf (1) ***** error tlscdf (1, 2) ***** error tlscdf (1, 2, 3) ***** error tlscdf (1, 2, 3, 4, 'uper') ***** error tlscdf (1, 2, 3, 4, 5) ***** error ... tlscdf (ones (3), ones (2), 1, 1) ***** error ... tlscdf (ones (3), 1, ones (2), 1) ***** error ... tlscdf (ones (3), 1, 1, ones (2)) ***** error ... tlscdf (ones (3), ones (2), 1, 1, 'upper') ***** error ... tlscdf (ones (3), 1, ones (2), 1, 'upper') ***** error ... tlscdf (ones (3), 1, 1, ones (2), 'upper') ***** error tlscdf (int32 (2), 2, 1, 1) ***** error tlscdf (true, 2, 1, 1) ***** error tlscdf ('a', 2, 1, 1) ***** error tlscdf (i, 2, 1, 1) ***** error tlscdf (2, i, 1, 1) ***** error tlscdf (2, 1, i, 1) ***** error tlscdf (2, 1, 1, i) 30 tests, 30 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/laplaceinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/laplaceinv.m ***** demo ## Plot various iCDFs from the Laplace distribution p = 0.001:0.001:0.999; x1 = cauchyinv (p, 0, 1); x2 = cauchyinv (p, 0, 2); x3 = cauchyinv (p, 0, 4); x4 = cauchyinv (p, -5, 4); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', p, x4, '-c') grid on ylim ([-10, 10]) legend ({'μ = 0, β = 1', 'μ = 0, β = 2', ... 'μ = 0, β = 4', 'μ = -5, β = 4'}, 'location', 'northwest') title ('Laplace iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p, x p = [-1 0 0.5 1 2]; x = [NaN, -Inf, 0, Inf, NaN]; ***** assert_equal (laplaceinv (p, 0, 1), x) ***** assert_equal (laplaceinv (p, 0, [-2, -1, 0, 1, 2]), [nan(1, 3), Inf, NaN]) ***** assert_equal (laplaceinv ([p, NaN], 0, 1), [x, NaN]) ***** assert_equal (laplaceinv (single ([p, NaN]), 0, 1), single ([x, NaN])) ***** assert_equal (laplaceinv ([p, NaN], single (0), 1), single ([x, NaN])) ***** assert_equal (laplaceinv ([p, NaN], 0, single (1)), single ([x, NaN])) ***** error laplaceinv () ***** error laplaceinv (1) ***** error ... laplaceinv (1, 2) ***** error laplaceinv (1, 2, 3, 4) ***** error ... laplaceinv (1, ones (2), ones (3)) ***** error ... laplaceinv (ones (2), 1, ones (3)) ***** error ... laplaceinv (ones (2), ones (3), 1) ***** error laplaceinv (int32 (2), 2, 3) ***** error laplaceinv (true, 2, 3) ***** error laplaceinv ('a', 2, 3) ***** error laplaceinv (i, 2, 3) ***** error laplaceinv (1, i, 3) ***** error laplaceinv (1, 2, i) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/wishpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/wishpdf.m ***** assert_equal (wishpdf (4, 3, 3.1), 0.07702496, 1E-7); ***** assert_equal (wishpdf ([2 -0.3;-0.3 4], [1 0.3;0.3 1], 4), 0.004529741, 1E-7); ***** assert_equal (wishpdf ([6 2 5; 2 10 -5; 5 -5 25], [9 5 5; 5 10 -8; 5 -8 22], 5.1), 4.474865e-10, 1E-15); ***** error wishpdf (int32 (eye (2)), eye (2), 3) ***** error wishpdf (true (2), eye (2), 3) ***** error wishpdf (['ab'; 'cd'], eye (2), 3) ***** error wishpdf () ***** error wishpdf (1, 2) ***** error wishpdf (1, 2, 0) ***** error wishpdf (1, 2) 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/gppdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/gppdf.m ***** demo ## Plot various PDFs from the generalized Pareto distribution x = 0:0.001:5; y1 = gppdf (x, 1, 1, 0); y2 = gppdf (x, 5, 1, 0); y3 = gppdf (x, 20, 1, 0); y4 = gppdf (x, 1, 2, 0); y5 = gppdf (x, 5, 2, 0); y6 = gppdf (x, 20, 2, 0); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', ... x, y4, '-c', x, y5, '-m', x, y6, '-k') grid on xlim ([0, 5]) ylim ([0, 1]) legend ({'k = 1, σ = 1, θ = 0', 'k = 5, σ = 1, θ = 0', ... 'k = 20, σ = 1, θ = 0', 'k = 1, σ = 2, θ = 0', ... 'k = 5, σ = 2, θ = 0', 'k = 20, σ = 2, θ = 0'}, ... 'location', 'northeast') title ('Generalized Pareto PDF') xlabel ('values in x') ylabel ('density') ***** test ## at k = -1 the distribution is uniform, and the density is 1/sigma assert_equal (gppdf (1, -1, 1, 0), 1); assert_equal (gppdf (1, -1, 1, 0), unifpdf (1, 0, 1)); assert_equal (gppdf (2, -1, 2, 0), 0.5); assert_equal (gppdf (2, -1, 2, 0), unifpdf (2, 0, 2)); ***** test ## between -1 and 0 the density vanishes at the endpoint assert_equal (gppdf (2, -0.5, 1, 0), 0); ***** test ## below -1 it diverges there assert_equal (gppdf (0.5, -2, 1, 0), Inf); ***** test ## and the endpoint agrees with the values approaching it assert_equal (gppdf (1 - 1e-12, -1, 1, 0), 1); assert_equal (gppdf (1.5, -1, 1, 0), 0); ***** shared x, y1, y2, y3 x = [-Inf, -1, 0, 1/2, 1, Inf]; y1 = [0, 0, 1, 0.6065306597126334, 0.36787944117144233, 0]; y2 = [0, 0, 1, 4/9, 1/4, 0]; y3 = [0, 0, 1, 1, 1, 0]; ***** assert_equal (gppdf (x, zeros (1,6), ones (1,6), zeros (1,6)), y1, eps) ***** assert_equal (gppdf (x, 0, 1, zeros (1,6)), y1, eps) ***** assert_equal (gppdf (x, 0, ones (1,6), 0), y1, eps) ***** assert_equal (gppdf (x, zeros (1,6), 1, 0), y1, eps) ***** assert_equal (gppdf (x, 0, 1, 0), y1, eps) ***** assert_equal (gppdf (x, 0, 1, [0, 0, 0, NaN, 0, 0]), [y1(1:3), NaN, y1(5:6)]) ***** assert_equal (gppdf (x, 0, [1, 1, 1, NaN, 1, 1], 0), [y1(1:3), NaN, y1(5:6)]) ***** assert_equal (gppdf (x, [0, 0, 0, NaN, 0, 0], 1, 0), [y1(1:3), NaN, y1(5:6)]) ***** assert_equal (gppdf ([x(1:3), NaN, x(5:6)], 0, 1, 0), [y1(1:3), NaN, y1(5:6)]) ***** assert_equal (gppdf (x, ones (1,6), ones (1,6), zeros (1,6)), y2, eps) ***** assert_equal (gppdf (x, 1, 1, zeros (1,6)), y2, eps) ***** assert_equal (gppdf (x, 1, ones (1,6), 0), y2, eps) ***** assert_equal (gppdf (x, ones (1,6), 1, 0), y2, eps) ***** assert_equal (gppdf (x, 1, 1, 0), y2, eps) ***** assert_equal (gppdf (x, 1, 1, [0, 0, 0, NaN, 0, 0]), [y2(1:3), NaN, y2(5:6)]) ***** assert_equal (gppdf (x, 1, [1, 1, 1, NaN, 1, 1], 0), [y2(1:3), NaN, y2(5:6)]) ***** assert_equal (gppdf (x, [1, 1, 1, NaN, 1, 1], 1, 0), [y2(1:3), NaN, y2(5:6)]) ***** assert_equal (gppdf ([x(1:3), NaN, x(5:6)], 1, 1, 0), [y2(1:3), NaN, y2(5:6)]) ***** assert_equal (gppdf (x, -ones (1,6), ones (1,6), zeros (1,6)), y3, eps) ***** assert_equal (gppdf (x, -1, 1, zeros (1,6)), y3, eps) ***** assert_equal (gppdf (x, -1, ones (1,6), 0), y3, eps) ***** assert_equal (gppdf (x, -ones (1,6), 1, 0), y3, eps) ***** assert_equal (gppdf (x, -1, 1, 0), y3, eps) ***** assert_equal (gppdf (x, -1, 1, [0, 0, 0, NaN, 0, 0]), [y3(1:3), NaN, y3(5:6)]) ***** assert_equal (gppdf (x, -1, [1, 1, 1, NaN, 1, 1], 0), [y3(1:3), NaN, y3(5:6)]) ***** assert_equal (gppdf (x, [-1, -1, -1, NaN, -1, -1], 1, 0), [y3(1:3), NaN, y3(5:6)]) ***** assert_equal (gppdf ([x(1:3), NaN, x(5:6)], -1, 1, 0), [y3(1:3), NaN, y3(5:6)]) ***** assert_equal (gppdf (single ([x, NaN]), 0, 1, 0), single ([y1, NaN])) ***** assert_equal (gppdf ([x, NaN], 0, 1, single (0)), single ([y1, NaN])) ***** assert_equal (gppdf ([x, NaN], 0, single (1), 0), single ([y1, NaN])) ***** assert_equal (gppdf ([x, NaN], single (0), 1, 0), single ([y1, NaN])) ***** assert_equal (gppdf (single ([x, NaN]), 1, 1, 0), single ([y2, NaN])) ***** assert_equal (gppdf ([x, NaN], 1, 1, single (0)), single ([y2, NaN])) ***** assert_equal (gppdf ([x, NaN], 1, single (1), 0), single ([y2, NaN])) ***** assert_equal (gppdf ([x, NaN], single (1), 1, 0), single ([y2, NaN])) ***** assert_equal (gppdf (single ([x, NaN]), -1, 1, 0), single ([y3, NaN])) ***** assert_equal (gppdf ([x, NaN], -1, 1, single (0)), single ([y3, NaN])) ***** assert_equal (gppdf ([x, NaN], -1, single (1), 0), single ([y3, NaN])) ***** assert_equal (gppdf ([x, NaN], single (-1), 1, 0), single ([y3, NaN])) ***** error gppdf (int32 (2), 1, 1, 0) ***** error gppdf (true, 1, 1, 0) ***** error gppdf ('a', 1, 1, 0) ***** error gpcdf () ***** error gpcdf (1) ***** error gpcdf (1, 2) ***** error gpcdf (1, 2, 3) ***** error ... gpcdf (ones (3), ones (2), ones (2), ones (2)) ***** error ... gpcdf (ones (2), ones (3), ones (2), ones (2)) ***** error ... gpcdf (ones (2), ones (2), ones (3), ones (2)) ***** error ... gpcdf (ones (2), ones (2), ones (2), ones (3)) ***** error gpcdf (i, 2, 3, 4) ***** error gpcdf (1, i, 3, 4) ***** error gpcdf (1, 2, i, 4) ***** error gpcdf (1, 2, 3, i) 58 tests, 58 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/loglrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/loglrnd.m ***** assert_equal (size (loglrnd (1, 1)), [1, 1]) ***** assert_equal (size (loglrnd (1, ones (2, 1))), [2, 1]) ***** assert_equal (size (loglrnd (1, ones (2, 2))), [2, 2]) ***** assert_equal (size (loglrnd (ones (2, 1), 1)), [2, 1]) ***** assert_equal (size (loglrnd (ones (2, 2), 1)), [2, 2]) ***** assert_equal (size (loglrnd (1, 1, 3)), [3, 3]) ***** assert_equal (size (loglrnd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (loglrnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (loglrnd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (loglrnd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (loglrnd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (loglrnd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (loglrnd (1, 1, [])), [0, 0]) ***** assert_equal (size (loglrnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (loglrnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (loglrnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (loglrnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (loglrnd (1, 1)), "double") ***** assert_equal (class (loglrnd (1, single (1))), "single") ***** assert_equal (class (loglrnd (1, single ([1, 1]))), "single") ***** assert_equal (class (loglrnd (single (1), 1)), "single") ***** assert_equal (class (loglrnd (single ([1, 1]), 1)), "single") ***** error loglrnd () ***** error loglrnd (1) ***** error ... loglrnd (ones (3), ones (2)) ***** error ... loglrnd (ones (2), ones (3)) ***** error loglrnd (i, 2, 3) ***** error loglrnd (1, i, 3) ***** error ... loglrnd (1, 2, 1.2) ***** error ... loglrnd (1, 2, ones (2)) ***** error ... loglrnd (1, 2, [2 0 2.5]) ***** error ... loglrnd (1, 2, 2, 1.5, 5) ***** error ... loglrnd (2, ones (2), 3) ***** error ... loglrnd (2, ones (2), [3, 2]) ***** error ... loglrnd (2, ones (2), 3, 2) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/ricepdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/ricepdf.m ***** demo ## Plot various PDFs from the Rician distribution x = 0:0.01:8; y1 = ricepdf (x, 0, 1); y2 = ricepdf (x, 0.5, 1); y3 = ricepdf (x, 1, 1); y4 = ricepdf (x, 2, 1); y5 = ricepdf (x, 4, 1); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', x, y4, '-m', x, y5, '-k') grid on ylim ([0, 0.65]) xlim ([0, 8]) legend ({'s = 0, σ = 1', 's = 0.5, σ = 1', 's = 1, σ = 1', ... 's = 2, σ = 1', 's = 4, σ = 1'}, 'location', 'northeast') title ('Rician PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y x = [-1 0 0.5 1 2]; y = [0 0 0.1073 0.1978 0.2846]; ***** assert_equal (ricepdf (x, ones (1, 5), 2 * ones (1, 5)), y, 1e-4) ***** assert_equal (ricepdf (x, 1, 2 * ones (1, 5)), y, 1e-4) ***** assert_equal (ricepdf (x, ones (1, 5), 2), y, 1e-4) ***** assert_equal (ricepdf (x, [0 NaN 1 1 1], 2), [0 NaN y(3:5)], 1e-4) ***** assert_equal (ricepdf (x, 1, 2 * [0 NaN 1 1 1]), [0 NaN y(3:5)], 1e-4) ***** assert_equal (ricepdf ([x, NaN], 1, 2), [y, NaN], 1e-4) ***** assert_equal (ricepdf (single ([x, NaN]), 1, 2), single ([y, NaN]), 1e-4) ***** assert_equal (ricepdf ([x, NaN], single (1), 2), single ([y, NaN]), 1e-4) ***** assert_equal (ricepdf ([x, NaN], 1, single (2)), single ([y, NaN]), 1e-4) ***** error ricepdf () ***** error ricepdf (1) ***** error ricepdf (1,2) ***** error ricepdf (1,2,3,4) ***** error ... ricepdf (ones (3), ones (2), ones (2)) ***** error ... ricepdf (ones (2), ones (3), ones (2)) ***** error ... ricepdf (ones (2), ones (2), ones (3)) ***** error ricepdf (int32 (2), 2, 2) ***** error ricepdf (true, 2, 2) ***** error ricepdf ('a', 2, 2) ***** error ricepdf (i, 2, 2) ***** error ricepdf (2, i, 2) ***** error ricepdf (2, 2, i) 22 tests, 22 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/chi2pdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/chi2pdf.m ***** demo ## Plot various PDFs from the chi-squared distribution x = 0:0.01:8; y1 = chi2pdf (x, 1); y2 = chi2pdf (x, 2); y3 = chi2pdf (x, 3); y4 = chi2pdf (x, 4); y5 = chi2pdf (x, 6); y6 = chi2pdf (x, 9); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', ... x, y4, '-c', x, y5, '-m', x, y6, '-y') grid on xlim ([0, 8]) ylim ([0, 0.5]) legend ({'df = 1', 'df = 2', 'df = 3', ... 'df = 4', 'df = 6', 'df = 9'}, 'location', 'northeast') title ('Chi-squared PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y x = [-1 0 0.5 1 Inf]; y = [0, 1/2 * exp(-x(2:5)/2)]; ***** assert_equal (chi2pdf (x, 2*ones (1,5)), y) ***** assert_equal (chi2pdf (x, 2), y) ***** assert_equal (chi2pdf (x, 2*[1 0 NaN 1 1]), [y(1) NaN NaN y(4:5)]) ***** assert_equal (chi2pdf ([x, NaN], 2), [y, NaN]) ***** assert_equal (chi2pdf (2, Inf), 0) ***** assert_equal (chi2pdf (single ([x, NaN]), 2), single ([y, NaN])) ***** assert_equal (chi2pdf ([x, NaN], single (2)), single ([y, NaN])) ***** error chi2pdf () ***** error chi2pdf (1) ***** error chi2pdf (1,2,3) ***** error ... chi2pdf (ones (3), ones (2)) ***** error ... chi2pdf (ones (2), ones (3)) ***** error chi2pdf (int32 (2), 2) ***** error chi2pdf (true, 2) ***** error chi2pdf ('a', 2) ***** error chi2pdf (i, 2) ***** error chi2pdf (2, i) 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/invgcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/invgcdf.m ***** demo ## Plot various CDFs from the inverse Gaussian distribution x = 0:0.001:3; p1 = invgcdf (x, 1, 0.2); p2 = invgcdf (x, 1, 1); p3 = invgcdf (x, 1, 3); p4 = invgcdf (x, 3, 0.2); p5 = invgcdf (x, 3, 1); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', x, p4, '-c', x, p5, '-y') grid on xlim ([0, 3]) legend ({'μ = 1, σ = 0.2', 'μ = 1, σ = 1', 'μ = 1, σ = 3', ... 'μ = 3, σ = 0.2', 'μ = 3, σ = 1'}, 'location', 'southeast') title ('Inverse Gaussian CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, p1, p1u, y2, y2u, y3, y3u x = [-Inf, -1, 0, 1/2, 1, Inf]; p1 = [0, 0, 0, 0.3650, 0.6681, 1]; p1u = [1, 1, 1, 0.6350, 0.3319, 0]; ***** assert_equal (invgcdf (x, ones (1,6), ones (1,6)), p1, 1e-4) ***** assert_equal (invgcdf (x, 1, 1), p1, 1e-4) ***** assert_equal (invgcdf (x, 1, ones (1,6)), p1, 1e-4) ***** assert_equal (invgcdf (x, ones (1,6), 1), p1, 1e-4) ***** assert_equal (invgcdf (x, 1, [1, 1, 1, NaN, 1, 1]), [p1(1:3), NaN, p1(5:6)], 1e-4) ***** assert_equal (invgcdf (x, [1, 1, 1, NaN, 1, 1], 1), [p1(1:3), NaN, p1(5:6)], 1e-4) ***** assert_equal (invgcdf ([x(1:3), NaN, x(5:6)], 1, 1), [p1(1:3), NaN, p1(5:6)], 1e-4) ***** assert_equal (invgcdf (x, ones (1,6), ones (1,6), 'upper'), p1u, 1e-4) ***** assert_equal (invgcdf (x, 1, 1, 'upper'), p1u, 1e-4) ***** assert_equal (invgcdf (x, 1, ones (1,6), 'upper'), p1u, 1e-4) ***** assert_equal (invgcdf (x, ones (1,6), 1, 'upper'), p1u, 1e-4) ***** assert_equal (class (invgcdf (single ([x, NaN]), 1, 1)), "single") ***** assert_equal (class (invgcdf ([x, NaN], 1, single (1))), "single") ***** assert_equal (class (invgcdf ([x, NaN], single (1), 1)), "single") ***** error invgcdf () ***** error invgcdf (1) ***** error invgcdf (1, 2) ***** error invgcdf (1, 2, 3, 'tail') ***** error invgcdf (1, 2, 3, 5) ***** error ... invgcdf (ones (3), ones (2), ones (2)) ***** error ... invgcdf (ones (2), ones (3), ones (2)) ***** error ... invgcdf (ones (2), ones (2), ones (3)) ***** error invgcdf (int32 (2), 2, 3) ***** error invgcdf (true, 2, 3) ***** error invgcdf ('a', 2, 3) ***** error invgcdf (i, 2, 3) ***** error invgcdf (1, i, 3) ***** error invgcdf (1, 2, i) 28 tests, 28 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/logirnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/logirnd.m ***** assert_equal (size (logirnd (1, 1)), [1, 1]) ***** assert_equal (size (logirnd (1, ones (2, 1))), [2, 1]) ***** assert_equal (size (logirnd (1, ones (2, 2))), [2, 2]) ***** assert_equal (size (logirnd (ones (2, 1), 1)), [2, 1]) ***** assert_equal (size (logirnd (ones (2, 2), 1)), [2, 2]) ***** assert_equal (size (logirnd (1, 1, 3)), [3, 3]) ***** assert_equal (size (logirnd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (logirnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (logirnd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (logirnd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (logirnd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (logirnd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (logirnd (1, 1, [])), [0, 0]) ***** assert_equal (size (logirnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (logirnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (logirnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (logirnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (logirnd (1, 1)), "double") ***** assert_equal (class (logirnd (1, single (1))), "single") ***** assert_equal (class (logirnd (1, single ([1, 1]))), "single") ***** assert_equal (class (logirnd (single (1), 1)), "single") ***** assert_equal (class (logirnd (single ([1, 1]), 1)), "single") ***** error logirnd () ***** error logirnd (1) ***** error ... logirnd (ones (3), ones (2)) ***** error ... logirnd (ones (2), ones (3)) ***** error logirnd (i, 2, 3) ***** error logirnd (1, i, 3) ***** error ... logirnd (1, 2, 1.2) ***** error ... logirnd (1, 2, ones (2)) ***** error ... logirnd (1, 2, [2 0 2.5]) ***** error ... logirnd (1, 2, 2, 1.5, 5) ***** error ... logirnd (2, ones (2), 3) ***** error ... logirnd (2, ones (2), [3, 2]) ***** error ... logirnd (2, ones (2), 3, 2) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/gampdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/gampdf.m ***** demo ## Plot various PDFs from the Gamma distribution x = 0:0.01:20; y1 = gampdf (x, 1, 2); y2 = gampdf (x, 2, 2); y3 = gampdf (x, 3, 2); y4 = gampdf (x, 5, 1); y5 = gampdf (x, 9, 0.5); y6 = gampdf (x, 7.5, 1); y7 = gampdf (x, 0.5, 1); plot (x, y1, '-r', x, y2, '-g', x, y3, '-y', x, y4, '-m', ... x, y5, '-k', x, y6, '-b', x, y7, '-c') grid on ylim ([0,0.5]) legend ({'α = 1, β = 2', 'α = 2, β = 2', 'α = 3, β = 2', ... 'α = 5, β = 1', 'α = 9, β = 0.5', 'α = 7.5, β = 1', ... 'α = 0.5, β = 1'}, 'location', 'northeast') title ('Gamma PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y x = [-1 0 0.5 1 Inf]; y = [0 exp(-x(2:end))]; ***** assert_equal (gampdf (x, ones (1,5), ones (1,5)), y) ***** assert_equal (gampdf (x, 1, ones (1,5)), y) ***** assert_equal (gampdf (x, ones (1,5), 1), y) ***** assert_equal (gampdf (x, [0 -Inf NaN Inf 1], 1), [NaN NaN NaN 0 y(5)]) ***** assert_equal (gampdf (x, [0 Inf NaN Inf 1], 1), [NaN 0 NaN 0 y(5)]) ***** assert_equal (gampdf (x, 1, [0 -Inf NaN Inf 1]), [NaN NaN NaN 0 y(5)]) ***** assert_equal (gampdf ([x, NaN], 1, 1), [y, NaN]) ***** assert_equal (gampdf (2, Inf, 4), 0) ***** assert_equal (gampdf (2, 4, Inf), 0) ***** assert_equal (gampdf (2, Inf, Inf), 0) ***** assert_equal (gampdf (single ([x, NaN]), 1, 1), single ([y, NaN])) ***** assert_equal (gampdf ([x, NaN], single (1), 1), single ([y, NaN])) ***** assert_equal (gampdf ([x, NaN], 1, single (1)), single ([y, NaN])) ***** error gampdf () ***** error gampdf (1) ***** error gampdf (1,2) ***** error ... gampdf (ones (3), ones (2), ones (2)) ***** error ... gampdf (ones (2), ones (3), ones (2)) ***** error ... gampdf (ones (2), ones (2), ones (3)) ***** error gampdf (int32 (2), 2, 2) ***** error gampdf (true, 2, 2) ***** error gampdf ('a', 2, 2) ***** error gampdf (i, 2, 2) ***** error gampdf (2, i, 2) ***** error gampdf (2, 2, i) 25 tests, 25 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/stdrpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/stdrpdf.m ***** demo ## Plot various PDFs from the studentized range distribution x = 0:0.01:8; y1 = stdrpdf (x, 2, 5); y2 = stdrpdf (x, 3, 5); y3 = stdrpdf (x, 5, 5); y4 = stdrpdf (x, 5, Inf); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', x, y4, '-m') grid on legend ({'k = 2, df = 5', 'k = 3, df = 5', 'k = 5, df = 5', ... 'k = 5, df = \infty'}, 'location', 'northeast') title ('Studentized range PDF') xlabel ('values in x') ylabel ('density') ***** shared x x = [0.5, 2, 4, 8]; ***** assert_equal (stdrpdf (x, 2, 5), sqrt (2) * tpdf (x / sqrt (2), 5), -1e-13) ***** assert_equal (stdrpdf (x, 2, Inf), exp (-x .^ 2 / 4) / sqrt (pi), -1e-13) ***** assert_equal (stdrpdf (0, 2, 5), sqrt (2) * tpdf (0, 5), -1e-13) ***** assert_equal (stdrpdf (0, 3, 5), 0) ***** test h = 1e-4; d = (stdrcdf (3 + h, 5, 10) - stdrcdf (3 - h, 5, 10)) / (2 * h); assert_equal (stdrpdf (3, 5, 10), d, -1e-7); ***** assert_equal (stdrpdf ([-1, Inf, NaN], 3, 10), [0, 0, NaN]) ***** assert_equal (stdrpdf (2, [1, 2.5, NaN, Inf], 10), NaN (1, 4)) ***** assert_equal (stdrpdf (2, 3, [0, -1, NaN]), NaN (1, 3)) ***** assert_equal (class (stdrpdf (single (2), 3, 10)), 'single') ***** assert_equal (class (stdrpdf (2, 3, single (10))), 'single') ***** error stdrpdf () ***** error stdrpdf (1, 2) ***** error ... stdrpdf (ones (3), ones (2), 3) ***** error ... stdrpdf (int32 (2), 3, 10) ***** error ... stdrpdf (true, 3, 10) ***** error ... stdrpdf ('a', 3, 10) ***** error stdrpdf (i, 3, 10) ***** error stdrpdf (2, i, 10) ***** error stdrpdf (2, 3, i) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/gumbelrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/gumbelrnd.m ***** assert_equal (size (gumbelrnd (1, 1)), [1 1]) ***** assert_equal (size (gumbelrnd (1, ones (2,1))), [2, 1]) ***** assert_equal (size (gumbelrnd (1, ones (2,2))), [2, 2]) ***** assert_equal (size (gumbelrnd (ones (2,1), 1)), [2, 1]) ***** assert_equal (size (gumbelrnd (ones (2,2), 1)), [2, 2]) ***** assert_equal (size (gumbelrnd (1, 1, 3)), [3, 3]) ***** assert_equal (size (gumbelrnd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (gumbelrnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (gumbelrnd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (gumbelrnd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (gumbelrnd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (gumbelrnd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (gumbelrnd (1, 1, [])), [0, 0]) ***** assert_equal (size (gumbelrnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (gumbelrnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (gumbelrnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (gumbelrnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (gumbelrnd (1, 1)), "double") ***** assert_equal (class (gumbelrnd (1, single (1))), "single") ***** assert_equal (class (gumbelrnd (1, single ([1, 1]))), "single") ***** assert_equal (class (gumbelrnd (single (1), 1)), "single") ***** assert_equal (class (gumbelrnd (single ([1, 1]), 1)), "single") ***** error gumbelrnd () ***** error gumbelrnd (1) ***** error ... gumbelrnd (ones (3), ones (2)) ***** error ... gumbelrnd (ones (2), ones (3)) ***** error gumbelrnd (i, 2, 3) ***** error gumbelrnd (1, i, 3) ***** error ... gumbelrnd (1, 2, 1.2) ***** error ... gumbelrnd (1, 2, ones (2)) ***** error ... gumbelrnd (1, 2, [2 0 2.5]) ***** error ... gumbelrnd (1, 2, 2, 1.5, 5) ***** error ... gumbelrnd (2, ones (2), 3) ***** error ... gumbelrnd (2, ones (2), [3, 2]) ***** error ... gumbelrnd (2, ones (2), 3, 2) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/hncdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/hncdf.m ***** demo ## Plot various CDFs from the half-normal distribution x = 0:0.001:10; p1 = hncdf (x, 0, 1); p2 = hncdf (x, 0, 2); p3 = hncdf (x, 0, 3); p4 = hncdf (x, 0, 5); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', x, p4, '-c') grid on xlim ([0, 10]) legend ({'μ = 0, σ = 1', 'μ = 0, σ = 2', ... 'μ = 0, σ = 3', 'μ = 0, σ = 5'}, 'location', 'southeast') title ('Half-normal CDF') xlabel ('values in x') ylabel ('probability') ***** demo ## Plot half-normal against normal cumulative distribution function x = -5:0.001:5; p1 = hncdf (x, 0, 1); p2 = normcdf (x); plot (x, p1, '-b', x, p2, '-g') grid on xlim ([-5, 5]) legend ({'half-normal with μ = 0, σ = 1', ... 'standard normal (μ = 0, σ = 1)'}, 'location', 'southeast') title ('Half-normal against standard normal CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, p1, p1u, y2, y2u, y3, y3u x = [-Inf, -1, 0, 1/2, 1, Inf]; p1 = [0, 0, 0, 0.3829, 0.6827, 1]; p1u = [1, 1, 1, 0.6171, 0.3173, 0]; ***** assert_equal (hncdf (x, zeros (1,6), ones (1,6)), p1, 1e-4) ***** assert_equal (hncdf (x, 0, 1), p1, 1e-4) ***** assert_equal (hncdf (x, 0, ones (1,6)), p1, 1e-4) ***** assert_equal (hncdf (x, zeros (1,6), 1), p1, 1e-4) ***** assert_equal (hncdf (x, 0, [1, 1, 1, NaN, 1, 1]), [p1(1:3), NaN, p1(5:6)], 1e-4) ***** assert_equal (hncdf (x, [0, 0, 0, NaN, 0, 0], 1), [p1(1:3), NaN, p1(5:6)], 1e-4) ***** assert_equal (hncdf ([x(1:3), NaN, x(5:6)], 0, 1), [p1(1:3), NaN, p1(5:6)], 1e-4) ***** assert_equal (hncdf (x, zeros (1,6), ones (1,6), 'upper'), p1u, 1e-4) ***** assert_equal (hncdf (x, 0, 1, 'upper'), p1u, 1e-4) ***** assert_equal (hncdf (x, 0, ones (1,6), 'upper'), p1u, 1e-4) ***** assert_equal (hncdf (x, zeros (1,6), 1, 'upper'), p1u, 1e-4) ***** assert_equal (class (hncdf (single ([x, NaN]), 0, 1)), "single") ***** assert_equal (class (hncdf ([x, NaN], 0, single (1))), "single") ***** assert_equal (class (hncdf ([x, NaN], single (0), 1)), "single") ***** error hncdf () ***** error hncdf (1) ***** error hncdf (1, 2) ***** error hncdf (1, 2, 3, 'tail') ***** error hncdf (1, 2, 3, 5) ***** error ... hncdf (ones (3), ones (2), ones (2)) ***** error ... hncdf (ones (2), ones (3), ones (2)) ***** error ... hncdf (ones (2), ones (2), ones (3)) ***** error hncdf (int32 (2), 2, 3) ***** error hncdf (true, 2, 3) ***** error hncdf ('a', 2, 3) ***** error hncdf (i, 2, 3) ***** error hncdf (1, i, 3) ***** error hncdf (1, 2, i) 28 tests, 28 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/gevcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/gevcdf.m ***** demo ## Plot various CDFs from the generalized extreme value distribution x = -1:0.001:10; p1 = gevcdf (x, 1, 1, 1); p2 = gevcdf (x, 0.5, 1, 1); p3 = gevcdf (x, 1, 1, 5); p4 = gevcdf (x, 1, 2, 5); p5 = gevcdf (x, 1, 5, 5); p6 = gevcdf (x, 1, 0.5, 5); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', ... x, p4, '-c', x, p5, '-m', x, p6, '-k') grid on xlim ([-1, 10]) legend ({'k = 1, σ = 1, μ = 1', 'k = 0.5, σ = 1, μ = 1', ... 'k = 1, σ = 1, μ = 5', 'k = 1, σ = 2, μ = 5', ... 'k = 1, σ = 5, μ = 5', 'k = 1, σ = 0.5, μ = 5'}, ... 'location', 'southeast') title ('Generalized extreme value CDF') xlabel ('values in x') ylabel ('probability') ***** test x = 0:0.5:2.5; sigma = 1:6; k = 1; mu = 0; p = gevcdf (x, k, sigma, mu); expected_p = [0.36788, 0.44933, 0.47237, 0.48323, 0.48954, 0.49367]; assert_equal (p, expected_p, 0.001); ***** test x = -0.5:0.5:2.5; sigma = 0.5; k = 1; mu = 0; p = gevcdf (x, k, sigma, mu); expected_p = [0, 0.36788, 0.60653, 0.71653, 0.77880, 0.81873, 0.84648]; assert_equal (p, expected_p, 0.001); ***** test # check for continuity for k near 0 x = 1; sigma = 0.5; k = -0.03:0.01:0.03; mu = 0; p = gevcdf (x, k, sigma, mu); expected_p = [0.88062, 0.87820, 0.87580, 0.87342, 0.87107, 0.86874, 0.86643]; assert_equal (p, expected_p, 0.001); ***** error gevcdf () ***** error gevcdf (1) ***** error gevcdf (1, 2) ***** error gevcdf (1, 2, 3) ***** error ... gevcdf (1, 2, 3, 4, 5, 6) ***** error gevcdf (1, 2, 3, 4, 'tail') ***** error gevcdf (1, 2, 3, 4, 5) ***** error ... gevcdf (ones (3), ones (2), ones (2), ones (2)) ***** error ... gevcdf (ones (2), ones (3), ones (2), ones (2)) ***** error ... gevcdf (ones (2), ones (2), ones (3), ones (2)) ***** error ... gevcdf (ones (2), ones (2), ones (2), ones (3)) ***** error gevcdf (int32 (2), 2, 3, 4) ***** error gevcdf (true, 2, 3, 4) ***** error gevcdf ('a', 2, 3, 4) ***** error gevcdf (i, 2, 3, 4) ***** error gevcdf (1, i, 3, 4) ***** error gevcdf (1, 2, i, 4) ***** error gevcdf (1, 2, 3, i) 21 tests, 21 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/copulacdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/copulacdf.m ***** test x = [0.2:0.2:0.6; 0.2:0.2:0.6]; theta = [1; 2]; p = copulacdf ('Clayton', x, theta); expected_p = [0.1395; 0.1767]; assert_equal (p, expected_p, 0.001); ***** test x = [0.2:0.2:0.6; 0.2:0.2:0.6]; p = copulacdf ('Gumbel', x, 2); expected_p = [0.1464; 0.1464]; assert_equal (p, expected_p, 0.001); ***** test x = [0.2:0.2:0.6; 0.2:0.2:0.6]; theta = [1; 2]; p = copulacdf ('Frank', x, theta); expected_p = [0.0699; 0.0930]; assert_equal (p, expected_p, 0.001); ***** test x = [0.2:0.2:0.6; 0.2:0.2:0.6]; theta = [0.3; 0.7]; p = copulacdf ('AMH', x, theta); expected_p = [0.0629; 0.0959]; assert_equal (p, expected_p, 0.001); ***** test x = [0.2:0.2:0.6; 0.2:0.1:0.4]; theta = [0.2, 0.1, 0.1, 0.05]; p = copulacdf ('FGM', x, theta); expected_p = [0.0558; 0.0293]; assert_equal (p, expected_p, 0.001); ***** error copulacdf ('Clayton', int32 ([0, 0]), 2) ***** error copulacdf ('Clayton', [true, true], 2) ***** error copulacdf ('Clayton', 'ab', 2) 8 tests, 8 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/logninv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/logninv.m ***** demo ## Plot various iCDFs from the log-normal distribution p = 0.001:0.001:0.999; x1 = logninv (p, 0, 1); x2 = logninv (p, 0, 0.5); x3 = logninv (p, 0, 0.25); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r') grid on ylim ([0, 3]) legend ({'μ = 0, σ = 1', 'μ = 0, σ = 0.5', 'μ = 0, σ = 0.25'}, ... 'location', 'northwest') title ('Log-normal iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p p = [-1 0 0.5 1 2]; ***** assert_equal (logninv (p, ones (1,5), ones (1,5)), [NaN 0 e Inf NaN], 2*eps) ***** assert_equal (logninv (p, 1, ones (1,5)), [NaN 0 e Inf NaN], 2*eps) ***** assert_equal (logninv (p, ones (1,5), 1), [NaN 0 e Inf NaN], 2*eps) ***** assert_equal (logninv (p, [1 1 NaN 0 1], 1), [NaN 0 NaN Inf NaN]) ***** assert_equal (logninv (p, 1, [1 0 NaN Inf 1]), [NaN NaN NaN NaN NaN]) ***** assert_equal (logninv ([p(1:2) NaN p(4:5)], 1, 2), [NaN 0 NaN Inf NaN]) ***** assert_equal (logninv ([p, NaN], 1, 1), [NaN 0 e Inf NaN NaN], 2*eps) ***** assert_equal (logninv (single ([p, NaN]), 1, 1), single ([NaN 0 e Inf NaN NaN])) ***** assert_equal (logninv ([p, NaN], single (1), 1), single ([NaN 0 e Inf NaN NaN])) ***** assert_equal (logninv ([p, NaN], 1, single (1)), single ([NaN 0 e Inf NaN NaN])) ***** error logninv (int32 (2), 0, 1) ***** error logninv (true, 0, 1) ***** error logninv ('a', 0, 1) ***** error logninv () ***** error logninv (1,2,3,4) ***** error logninv (ones (3), ones (2), ones (2)) ***** error logninv (ones (2), ones (3), ones (2)) ***** error logninv (ones (2), ones (2), ones (3)) ***** error logninv (i, 2, 2) ***** error logninv (2, i, 2) ***** error logninv (2, 2, i) 21 tests, 21 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/ricernd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/ricernd.m ***** assert_equal (size (ricernd (2, 1/2)), [1, 1]) ***** assert_equal (size (ricernd (2 * ones (2, 1), 1/2)), [2, 1]) ***** assert_equal (size (ricernd (2 * ones (2, 2), 1/2)), [2, 2]) ***** assert_equal (size (ricernd (2, 1/2 * ones (2, 1))), [2, 1]) ***** assert_equal (size (ricernd (1, 1/2 * ones (2, 2))), [2, 2]) ***** assert_equal (size (ricernd (ones (2, 1), 1)), [2, 1]) ***** assert_equal (size (ricernd (ones (2, 2), 1)), [2, 2]) ***** assert_equal (size (ricernd (2, 1/2, 3)), [3, 3]) ***** assert_equal (size (ricernd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (ricernd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (ricernd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (ricernd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (ricernd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (ricernd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (ricernd (1, 1, [])), [0, 0]) ***** assert_equal (size (ricernd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (ricernd (1, 1/2, -1)), [0, 0]) ***** assert_equal (size (ricernd (1, 1/2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (ricernd (1, 1/2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (ricernd (1, 1)), "double") ***** assert_equal (class (ricernd (1, single (0))), "single") ***** assert_equal (class (ricernd (1, single ([0, 0]))), "single") ***** assert_equal (class (ricernd (1, single (1), 2)), "single") ***** assert_equal (class (ricernd (1, single ([1, 1]), 1, 2)), "single") ***** assert_equal (class (ricernd (single (1), 1, 2)), "single") ***** assert_equal (class (ricernd (single ([1, 1]), 1, 1, 2)), "single") ***** error ricernd () ***** error ricernd (1) ***** error ... ricernd (ones (3), ones (2)) ***** error ... ricernd (ones (2), ones (3)) ***** error ricernd (i, 2) ***** error ricernd (1, i) ***** error ... ricernd (1, 1/2, 1.2) ***** error ... ricernd (1, 1/2, ones (2)) ***** error ... ricernd (1, 1/2, [2 0 2.5]) ***** error ... ricernd (1, 1/2, 2, 1.5, 5) ***** error ... ricernd (2, 1/2 * ones (2), 3) ***** error ... ricernd (2, 1/2 * ones (2), [3, 2]) ***** error ... ricernd (2, 1/2 * ones (2), 3, 2) ***** error ... ricernd (2 * ones (2), 1/2, 3) ***** error ... ricernd (2 * ones (2), 1/2, [3, 2]) ***** error ... ricernd (2 * ones (2), 1/2, 3, 2) 42 tests, 42 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/vmcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/vmcdf.m ***** demo ## Plot various CDFs from the von Mises distribution x1 = [-pi:0.1:pi]; p1 = vmcdf (x1, 0, 0.5); p2 = vmcdf (x1, 0, 1); p3 = vmcdf (x1, 0, 2); p4 = vmcdf (x1, 0, 4); plot (x1, p1, '-r', x1, p2, '-g', x1, p3, '-b', x1, p4, '-c') grid on xlim ([-pi, pi]) legend ({'μ = 0, k = 0.5', 'μ = 0, k = 1', ... 'μ = 0, k = 2', 'μ = 0, k = 4'}, 'location', 'northwest') title ('Von Mises CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, p0, p1 x = [-pi:pi/2:pi]; p0 = [0, 0.10975, 0.5, 0.89025, 1]; p1 = [0, 0.03752, 0.5, 0.99622, 1]; ***** assert_equal (vmcdf (x, 0, 1), p0, 1e-5) ***** assert_equal (vmcdf (x, 0, 1, 'upper'), 1 - p0, 1e-5) ***** assert_equal (vmcdf (x, zeros (1,5), ones (1,5)), p0, 1e-5) ***** assert_equal (vmcdf (x, zeros (1,5), ones (1,5), 'upper'), 1 - p0, 1e-5) ***** assert_equal (vmcdf (x, 0, [1 2 3 4 5]), p1, 1e-5) ***** assert_equal (vmcdf (x, 0, [1 2 3 4 5], 'upper'), 1 - p1, 1e-5) ***** assert_equal (isa (vmcdf (single (pi), 0, 1), 'single'), true) ***** assert_equal (isa (vmcdf (pi, single (0), 1), 'single'), true) ***** assert_equal (isa (vmcdf (pi, 0, single (1)), 'single'), true) ***** error vmcdf () ***** error vmcdf (1) ***** error vmcdf (1, 2) ***** error vmcdf (1, 2, 3, 'tail') ***** error vmcdf (1, 2, 3, 4) ***** error ... vmcdf (ones (3), ones (2), ones (2)) ***** error ... vmcdf (ones (2), ones (3), ones (2)) ***** error ... vmcdf (ones (2), ones (2), ones (3)) ***** error vmcdf (int32 (2), 2, 2) ***** error vmcdf (true, 2, 2) ***** error vmcdf ('a', 2, 2) ***** error vmcdf (i, 2, 2) ***** error vmcdf (2, i, 2) ***** error vmcdf (2, 2, i) 23 tests, 23 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/nakarnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/nakarnd.m ***** assert_equal (size (nakarnd (1, 1)), [1, 1]) ***** assert_equal (size (nakarnd (1, ones (2, 1))), [2, 1]) ***** assert_equal (size (nakarnd (1, ones (2, 2))), [2, 2]) ***** assert_equal (size (nakarnd (ones (2, 1), 1)), [2, 1]) ***** assert_equal (size (nakarnd (ones (2, 2), 1)), [2, 2]) ***** assert_equal (size (nakarnd (1, 1, 3)), [3, 3]) ***** assert_equal (size (nakarnd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (nakarnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (nakarnd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (nakarnd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (nakarnd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (nakarnd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (nakarnd (1, 1, [])), [0, 0]) ***** assert_equal (size (nakarnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (nakarnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (nakarnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (nakarnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (nakarnd (1, 1)), "double") ***** assert_equal (class (nakarnd (1, single (1))), "single") ***** assert_equal (class (nakarnd (1, single ([1, 1]))), "single") ***** assert_equal (class (nakarnd (single (1), 1)), "single") ***** assert_equal (class (nakarnd (single ([1, 1]), 1)), "single") ***** error nakarnd () ***** error nakarnd (1) ***** error ... nakarnd (ones (3), ones (2)) ***** error ... nakarnd (ones (2), ones (3)) ***** error nakarnd (i, 2, 3) ***** error nakarnd (1, i, 3) ***** error ... nakarnd (1, 2, 1.2) ***** error ... nakarnd (1, 2, ones (2)) ***** error ... nakarnd (1, 2, [2 0 2.5]) ***** error ... nakarnd (1, 2, 2, 1.5, 5) ***** error ... nakarnd (2, ones (2), 3) ***** error ... nakarnd (2, ones (2), [3, 2]) ***** error ... nakarnd (2, ones (2), 3, 2) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/unidinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/unidinv.m ***** demo ## Plot various iCDFs from the discrete uniform distribution p = 0.001:0.001:0.999; x1 = unidinv (p, 5); x2 = unidinv (p, 9); plot (p, x1, '-b', p, x2, '-g') grid on xlim ([0, 1]) ylim ([0, 10]) legend ({'N = 5', 'N = 9'}, 'location', 'northwest') title ('Discrete uniform iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p p = [-1 0 0.5 1 2]; ***** assert_equal (unidinv (p, 10*ones (1,5)), [NaN NaN 5 10 NaN], eps) ***** assert_equal (unidinv (p, 10), [NaN NaN 5 10 NaN], eps) ***** assert_equal (unidinv (p, 10*[0 1 NaN 1 1]), [NaN NaN NaN 10 NaN], eps) ***** assert_equal (unidinv ([p(1:2) NaN p(4:5)], 10), [NaN NaN NaN 10 NaN], eps) ***** assert_equal (unidinv ([p, NaN], 10), [NaN NaN 5 10 NaN NaN], eps) ***** assert_equal (unidinv (single ([p, NaN]), 10), single ([NaN NaN 5 10 NaN NaN]), eps) ***** assert_equal (unidinv ([p, NaN], single (10)), single ([NaN NaN 5 10 NaN NaN]), eps) ***** error unidinv () ***** error unidinv (1) ***** error ... unidinv (ones (3), ones (2)) ***** error ... unidinv (ones (2), ones (3)) ***** error unidinv (int32 (2), 2) ***** error unidinv (true, 2) ***** error unidinv ('a', 2) ***** error unidinv (i, 2) ***** error unidinv (2, i) 16 tests, 16 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/jsucdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/jsucdf.m ***** assert_equal (jsucdf (0), normcdf (1), -1e-15) ***** assert_equal (jsucdf (1, 0.5, 2), ... normcdf (0.5 + 2 * log (1 + sqrt (2))), -1e-14) ***** assert_equal (jsucdf (sinh (-2), 0, 1), normcdf (-2), -1e-14) ***** assert_equal (jsucdf (-1e8, 0, 1), normcdf (-log (2e8)), -1e-12) ***** assert_equal (jsucdf ([-Inf, NaN, Inf]), [0, NaN, 1]) ***** assert_equal (jsucdf (single (0)), single (normcdf (1)), -eps ('single')) ***** assert_equal (jsucdf (1, 0, 0), NaN) ***** assert_equal (jsucdf ([1, 2], 1, -1), [NaN, NaN]) ***** assert_equal (jsucdf (1, 1, [1, 0]), [jsucdf(1), NaN]) ***** error jsucdf (int32 (2), 1, 1) ***** error jsucdf (true, 1, 1) ***** error jsucdf ('a', 1, 1) ***** error jsucdf () ***** error jsucdf (1, 2, 3, 4) ***** error ... jsucdf (1, ones (2), ones (3)) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/gevpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/gevpdf.m ***** demo ## Plot various PDFs from the generalized extreme value distribution x = -1:0.001:10; y1 = gevpdf (x, 1, 1, 1); y2 = gevpdf (x, 0.5, 1, 1); y3 = gevpdf (x, 1, 1, 5); y4 = gevpdf (x, 1, 2, 5); y5 = gevpdf (x, 1, 5, 5); y6 = gevpdf (x, 1, 0.5, 5); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', ... x, y4, '-c', x, y5, '-m', x, y6, '-k') grid on xlim ([-1, 10]) ylim ([0, 1.1]) legend ({'k = 1, σ = 1, μ = 1', 'k = 0.5, σ = 1, μ = 1', ... 'k = 1, σ = 1, μ = 5', 'k = 1, σ = 2, μ = 5', ... 'k = 1, σ = 5, μ = 5', 'k = 1, σ = 0.5, μ = 5'}, ... 'location', 'northeast') title ('Generalized extreme value PDF') xlabel ('values in x') ylabel ('density') ***** test x = 0:0.5:2.5; sigma = 1:6; k = 1; mu = 0; y = gevpdf (x, k, sigma, mu); expected_y = [0.367879 0.143785 0.088569 0.063898 0.049953 0.040997]; assert_equal (y, expected_y, 0.001); ***** test x = -0.5:0.5:2.5; sigma = 0.5; k = 1; mu = 0; y = gevpdf (x, k, sigma, mu); expected_y = [0 0.735759 0.303265 0.159229 0.097350 0.065498 0.047027]; assert_equal (y, expected_y, 0.001); ***** test # check for continuity for k near 0 x = 1; sigma = 0.5; k = -0.03:0.01:0.03; mu = 0; y = gevpdf (x, k, sigma, mu); expected_y = [0.23820 0.23764 0.23704 0.23641 0.23576 0.23508 0.23438]; assert_equal (y, expected_y, 0.001); ***** error gevpdf () ***** error gevpdf (1) ***** error gevpdf (1, 2) ***** error gevpdf (1, 2, 3) ***** error ... gevpdf (ones (3), ones (2), ones (2), ones (2)) ***** error ... gevpdf (ones (2), ones (3), ones (2), ones (2)) ***** error ... gevpdf (ones (2), ones (2), ones (3), ones (2)) ***** error ... gevpdf (ones (2), ones (2), ones (2), ones (3)) ***** error gevpdf (int32 (2), 2, 3, 4) ***** error gevpdf (true, 2, 3, 4) ***** error gevpdf ('a', 2, 3, 4) ***** error gevpdf (i, 2, 3, 4) ***** error gevpdf (1, i, 3, 4) ***** error gevpdf (1, 2, i, 4) ***** error gevpdf (1, 2, 3, i) 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/stdrinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/stdrinv.m ***** demo ## Plot various iCDFs from the studentized range distribution p = 0.01:0.01:0.99; x1 = stdrinv (p, 2, 5); x2 = stdrinv (p, 3, 5); x3 = stdrinv (p, 5, Inf); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r') grid on legend ({'k = 2, df = 5', 'k = 3, df = 5', 'k = 5, df = \infty'}, ... 'location', 'northwest') title ('Studentized range iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p p = [0.1, 0.5, 0.95, 0.999]; ***** assert_equal (stdrinv (p, 2, 5), sqrt (2) * tinv ((1 + p) / 2, 5), -1e-12) ***** assert_equal (stdrinv (p, 2, 1), sqrt (2) * tan (pi * p / 2), -1e-12) ***** assert_equal (stdrinv ([0.5, 0.9, 0.95, 0.99], 3, 10), ... [1.6446889006146324, 3.2703084031559371, ... 3.8767767491915595, 5.2701615370332799], -1e-6) ***** assert_equal (stdrinv (0.95, 20, Inf), 5.0116887946867648, -1e-6) ***** assert_equal (stdrinv (0.95, 5, 30), 4.1020790196264514, -1e-4) ***** assert_equal (stdrinv (0.95, 3, 10), 3.8767767552295549, -1e-4) ***** assert_equal (stdrcdf (stdrinv (0.975, 4, 7), 4, 7), 0.975, -1e-13) ***** assert_equal (stdrcdf (stdrinv (1e-8, 4, 7), 4, 7), 1e-8, -1e-10) ***** assert_equal (stdrcdf (stdrinv (1 - 1e-10, 3, 20), 3, 20, 'upper'), ... 1e-10, -1e-6) ***** assert_equal (stdrinv ([0, 1, -1, 2, NaN], 3, 10), [0, Inf, NaN, NaN, NaN]) ***** assert_equal (stdrinv (0.5, [1, 2.5, NaN, Inf], 10), NaN (1, 4)) ***** assert_equal (stdrinv (0.5, 3, [0, -1, NaN]), NaN (1, 3)) ***** assert_equal (class (stdrinv (single (0.5), 3, 10)), 'single') ***** assert_equal (class (stdrinv (0.5, 3, single (10))), 'single') ***** error stdrinv () ***** error stdrinv (1, 2) ***** error ... stdrinv (ones (3), ones (2), 3) ***** error ... stdrinv (int32 (1), 3, 10) ***** error ... stdrinv (true, 3, 10) ***** error ... stdrinv ('a', 3, 10) ***** error stdrinv (i, 3, 10) ***** error stdrinv (0.5, i, 10) ***** error stdrinv (0.5, 3, i) 23 tests, 23 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/unifpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/unifpdf.m ***** demo ## Plot various PDFs from the continuous uniform distribution x = 0:0.001:10; y1 = unifpdf (x, 2, 5); y2 = unifpdf (x, 3, 9); plot (x, y1, '-b', x, y2, '-g') grid on xlim ([0, 10]) ylim ([0, 0.4]) legend ({'a = 2, b = 5', 'a = 3, b = 9'}, 'location', 'northeast') title ('Continuous uniform PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y x = [-1 0 0.5 1 2] + 1; y = [0 1 1 1 0]; ***** assert_equal (unifpdf (x, ones (1,5), 2*ones (1,5)), y) ***** assert_equal (unifpdf (x, 1, 2*ones (1,5)), y) ***** assert_equal (unifpdf (x, ones (1,5), 2), y) ***** assert_equal (unifpdf (x, [2 NaN 1 1 1], 2), [NaN NaN y(3:5)]) ***** assert_equal (unifpdf (x, 1, 2*[0 NaN 1 1 1]), [NaN NaN y(3:5)]) ***** assert_equal (unifpdf ([x, NaN], 1, 2), [y, NaN]) ***** assert_equal (unifpdf (x, 0, 1), [1 1 0 0 0]) ***** assert_equal (unifpdf (single ([x, NaN]), 1, 2), single ([y, NaN])) ***** assert_equal (unifpdf (single ([x, NaN]), single (1), 2), single ([y, NaN])) ***** assert_equal (unifpdf ([x, NaN], 1, single (2)), single ([y, NaN])) ***** error unifpdf () ***** error unifpdf (1) ***** error unifpdf (1, 2) ***** error ... unifpdf (ones (3), ones (2), ones (2)) ***** error ... unifpdf (ones (2), ones (3), ones (2)) ***** error ... unifpdf (ones (2), ones (2), ones (3)) ***** error unifpdf (int32 (2), 2, 2) ***** error unifpdf (true, 2, 2) ***** error unifpdf ('a', 2, 2) ***** error unifpdf (i, 2, 2) ***** error unifpdf (2, i, 2) ***** error unifpdf (2, 2, i) 22 tests, 22 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/normpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/normpdf.m ***** demo ## Plot various PDFs from the normal distribution x = -5:0.01:5; y1 = normpdf (x, 0, 0.5); y2 = normpdf (x, 0, 1); y3 = normpdf (x, 0, 2); y4 = normpdf (x, -2, 0.8); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', x, y4, '-c') grid on xlim ([-5, 5]) ylim ([0, 0.9]) legend ({'μ = 0, σ = 0.5', 'μ = 0, σ = 1', ... 'μ = 0, σ = 2', 'μ = -2, σ = 0.8'}, 'location', 'northeast') title ('Normal PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y x = [-Inf, 1, 2, Inf]; y = 1 / sqrt (2 * pi) * exp (-(x - 1) .^ 2 / 2); ***** assert_equal (normpdf (x, ones (1,4), ones (1,4)), y, eps) ***** assert_equal (normpdf (x, 1, ones (1,4)), y, eps) ***** assert_equal (normpdf (x, ones (1,4), 1), y, eps) ***** assert_equal (normpdf (x, [0 -Inf NaN Inf], 1), [y(1) NaN NaN NaN], eps) ***** assert_equal (normpdf (x, 1, [Inf NaN -1 0]), [NaN NaN NaN NaN], eps) ***** assert_equal (normpdf ([x, NaN], 1, 1), [y, NaN], eps) ***** assert_equal (normpdf (single ([x, NaN]), 1, 1), single ([y, NaN]), eps ('single')) ***** assert_equal (normpdf ([x, NaN], single (1), 1), single ([y, NaN]), eps ('single')) ***** assert_equal (normpdf ([x, NaN], 1, single (1)), single ([y, NaN]), eps ('single')) ***** error normpdf () ***** error ... normpdf (ones (3), ones (2), ones (2)) ***** error ... normpdf (ones (2), ones (3), ones (2)) ***** error ... normpdf (ones (2), ones (2), ones (3)) ***** error normpdf (int32 (2), 2, 2) ***** error normpdf (true, 2, 2) ***** error normpdf ('a', 2, 2) ***** error normpdf (i, 2, 2) ***** error normpdf (2, i, 2) ***** error normpdf (2, 2, i) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/vminv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/vminv.m ***** demo ## Plot various iCDFs from the von Mises distribution p1 = [0,0.005,0.01:0.01:0.1,0.15,0.2:0.1:0.8,0.85,0.9:0.01:0.99,0.995,1]; x1 = vminv (p1, 0, 0.5); x2 = vminv (p1, 0, 1); x3 = vminv (p1, 0, 2); x4 = vminv (p1, 0, 4); plot (p1, x1, '-r', p1, x2, '-g', p1, x3, '-b', p1, x4, '-c') grid on ylim ([-pi, pi]) legend ({'μ = 0, k = 0.5', 'μ = 0, k = 1', ... 'μ = 0, k = 2', 'μ = 0, k = 4'}, 'location', 'northwest') title ('Von Mises iCDF') xlabel ('probability') ylabel ('values in x') ***** shared x, p0, p1 x = [-pi:pi/2:pi]; p0 = [0, 0.10975, 0.5, 0.89025, 1]; p1 = [0, 0.03752, 0.5, 0.99622, 1]; ***** assert_equal (vminv (p0, 0, 1), x, 5e-5) ***** assert_equal (vminv (p0, zeros (1,5), ones (1,5)), x, 5e-5) ***** assert_equal (vminv (p1, 0, [1 2 3 4 5]), x, [5e-5, 5e-4, 5e-5, 5e-4, 5e-5]) ***** error vminv () ***** error vminv (1) ***** error vminv (1, 2) ***** error ... vminv (ones (3), ones (2), ones (2)) ***** error ... vminv (ones (2), ones (3), ones (2)) ***** error ... vminv (ones (2), ones (2), ones (3)) ***** error vminv (int32 (2), 2, 2) ***** error vminv (true, 2, 2) ***** error vminv ('a', 2, 2) ***** error vminv (i, 2, 2) ***** error vminv (2, i, 2) ***** error vminv (2, 2, i) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/stblpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/stblpdf.m ***** demo ## Stable densities: Cauchy, a skewed stable, and the normal limit x = linspace (-6, 6, 200); plot (x, stblpdf (x, 1, 0, 1, 0), "-", ... x, stblpdf (x, 1.5, 0.5, 1, 0), "-", ... x, stblpdf (x, 2, 0, 1, 0), "-"); legend ("Cauchy", "alpha=1.5, beta=0.5", "normal"); ***** test x = -5:5; y = stblpdf (x, 1.5, 0.5, 1, 0); exp_y = [0.00330549826030791, 0.00673588721821526, 0.0190320671951022, ... 0.0729514702833168, 0.208194435543156, 0.284283800988578, ... 0.198573023913399, 0.0958317325744725, 0.0428461930184788, ... 0.0207819141087301, 0.0113306451818624]; assert_equal (y, exp_y, 1e-9); ***** test x = -5:5; y = stblpdf (x, 0.8, 0.5, 1, 0); exp_y = [0.00634335874934447, 0.0093623044752761, 0.0155686941305108, ... 0.0326882516316453, 0.135673711418341, 0.298698147231422, ... 0.139071606104264, 0.0722555300098094, 0.0433943212392174, ... 0.0288186423689968, 0.020522989417733]; assert_equal (y, exp_y, 1e-9); ***** test x = -5:5; y = stblpdf (x, 1.2, -0.5, 1, 0); exp_y = [0.0166464288580291, 0.0264743439008481, 0.0459799636082411, ... 0.0881296016218348, 0.177627321920986, 0.288106176914537, ... 0.196803906514695, 0.0520585692918225, 0.0173156565634881, ... 0.00836895075945555, 0.00490202402183536]; assert_equal (y, exp_y, 1e-9); ***** test # scaled and shifted (gam = 2, delta = 3) x = -5:5; y = stblpdf (x, 1.5, 0.5, 2, 3); exp_y = [0.00336794360910763, 0.00537726811151198, 0.00951603359755111, ... 0.0184406959152125, 0.0364757351416584, 0.0666533040480966, ... 0.104097217771578, 0.134023248277231, 0.142141900494289, ... 0.127056343301115, 0.0992865119566997]; assert_equal (y, exp_y, 1e-9); ***** test # normal special case (alpha = 2) x = -5:5; assert_equal (stblpdf (x, 2, 0, 1, 0), normpdf (x, 0, sqrt (2)), 1e-12); ***** test # Cauchy special case (alpha = 1, beta = 0) x = -5:5; assert_equal (stblpdf (x, 1, 0, 1, 0), 1 ./ (pi .* (1 + x .^ 2)), 1e-12); ***** test # Levy (alpha = 0.5, beta = 1): S0 support boundary at x = -1 x = -5:5; y = stblpdf (x, 0.5, 1, 1, 0); assert_equal (y(x < 0), zeros (1, 5), 1e-6); assert_equal (y(x == 0), 0.241970724519143, 1e-9); ***** error stblpdf (int32 (2), 1.5, 0, 1, 0) ***** error stblpdf (true, 1.5, 0, 1, 0) ***** error stblpdf ('a', 1.5, 0, 1, 0) ***** error stblpdf (1, 1.5, 0.5, 1) ***** error ... stblpdf (1, 2.5, 0, 1, 0) ***** error ... stblpdf (1, 1.5, 2, 1, 0) ***** error stblpdf (1, 1.5, 0, 0, 0) ***** error stblpdf (1, 1.5, 0, 1, 1i) ***** error stblpdf (1i, 1.5, 0, 1, 0) 16 tests, 16 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/jsupdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/jsupdf.m ***** assert_equal (jsupdf (0), normpdf (1), -1e-15) ***** assert_equal (jsupdf (1, 0.5, 2), ... sqrt (2) * normpdf (0.5 + 2 * log (1 + sqrt (2))), -1e-14) ***** assert_equal (jsupdf ([-Inf, NaN, Inf]), [0, NaN, 0]) ***** assert_equal (integral (@(x) jsupdf (x, 0.5, 2), -Inf, 1), ... jsucdf (1, 0.5, 2), -1e-9) ***** assert_equal (jsupdf (single (0)), single (normpdf (1)), -eps ('single')) ***** assert_equal (jsupdf (1, 0, 0), NaN) ***** assert_equal (jsupdf ([1, 2], 1, -1), [NaN, NaN]) ***** assert_equal (jsupdf (1, 1, [1, 0]), [jsupdf(1), NaN]) ***** error jsupdf (int32 (2), 1, 1) ***** error jsupdf (true, 1, 1) ***** error jsupdf ('a', 1, 1) ***** error jsupdf () ***** error jsupdf (1, 2, 3, 4) ***** error ... jsupdf (1, ones (2), ones (3)) 14 tests, 14 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/nctcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/nctcdf.m ***** demo ## Plot various CDFs from the noncentral T distribution x = -5:0.01:5; p1 = nctcdf (x, 1, 0); p2 = nctcdf (x, 4, 0); p3 = nctcdf (x, 1, 2); p4 = nctcdf (x, 4, 2); plot (x, p1, '-r', x, p2, '-g', x, p3, '-k', x, p4, '-m') grid on xlim ([-5, 5]) legend ({'df = 1, μ = 0', 'df = 4, μ = 0', ... 'df = 1, μ = 2', 'df = 4, μ = 2'}, 'location', 'southeast') title ('Noncentral T CDF') xlabel ('values in x') ylabel ('probability') ***** demo ## Compare the noncentral T CDF with MU = 1 to the T CDF ## with the same number of degrees of freedom (10). x = -5:0.1:5; p1 = nctcdf (x, 10, 1); p2 = tcdf (x, 10); plot (x, p1, '-', x, p2, '-') grid on xlim ([-5, 5]) legend ({'Noncentral T(10,1)', 'T(10)'}, 'location', 'southeast') title ('Noncentral T vs T CDFs') xlabel ('values in x') ylabel ('probability') ***** test x = -2:0.1:2; p = nctcdf (x, 10, 1); assert_equal (p(1), 0.003302485766631558, 1e-14); assert_equal (p(2), 0.004084668193532631, 1e-14); assert_equal (p(3), 0.005052800319478737, 1e-14); assert_equal (p(41), 0.8076115625303751, 1e-14); ***** test p = nctcdf (12, 10, 3); assert_equal (p, 0.9997719343243797, 1e-14); ***** test p = nctcdf (2, 3, 2); assert_equal (p, 0.4430757822176028, 1e-14); ***** test p = nctcdf (2, 3, 2, 'upper'); assert_equal (p, 0.5569242177823971, 1e-14); ***** test p = nctcdf ([3, 6], 3, 2, 'upper'); assert_equal (p, [0.3199728259444777, 0.07064855592441913], 1e-14); ***** error nctcdf () ***** error nctcdf (1) ***** error nctcdf (1, 2) ***** error nctcdf (1, 2, 3, 'tail') ***** error nctcdf (1, 2, 3, 4) ***** error ... nctcdf (ones (3), ones (2), ones (2)) ***** error ... nctcdf (ones (2), ones (3), ones (2)) ***** error ... nctcdf (ones (2), ones (2), ones (3)) ***** error nctcdf (int32 (2), 2, 2) ***** error nctcdf (true, 2, 2) ***** error nctcdf ('a', 2, 2) ***** error nctcdf (i, 2, 2) ***** error nctcdf (2, i, 2) ***** error nctcdf (2, 2, i) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/stblinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/stblinv.m ***** demo ## Quantiles of a skewed stable distribution p = [0.1, 0.25, 0.5, 0.75, 0.9]; x = stblinv (p, 1.5, 0.5, 1, 0) ***** test p = [0.1, 0.25, 0.5, 0.75, 0.9]; x = stblinv (p, 1.5, 0.5, 1, 0); exp_x = [-1.63127009138493, -0.783313648587273, 0.133853042315326, ... 1.20341055131626, 2.58231785139714]; assert_equal (x, exp_x, 1e-6); ***** test p = [0.1, 0.25, 0.5, 0.75, 0.9]; x = stblinv (p, 0.8, 0.5, 1, 0); exp_x = [-1.62200033048034, -0.553853652413272, 0.250487323305453, ... 2.11601429745393, 8.03924696271835]; assert_equal (x, exp_x, 1e-5); ***** test # scaled and shifted (gam = 2, delta = 3) p = [0.1, 0.25, 0.5, 0.75, 0.9]; x = stblinv (p, 1.5, 0.5, 2, 3); exp_x = [-0.26254018276987, 1.43337270282545, 3.26770608463065, ... 5.40682110263252, 8.16463570279428]; assert_equal (x, exp_x, 1e-6); ***** test # symmetric case (beta = 0): quantiles antisymmetric about delta p = [0.1, 0.25, 0.5, 0.75, 0.9]; x = stblinv (p, 1.5, 0, 1, 0); exp_x = [-2.06146263813919, -0.968933181710917, 0, ... 0.968933181710917, 2.06146263813919]; assert_equal (x, exp_x, 1e-6); ***** test # normal and Cauchy special cases p = [0.1, 0.3, 0.5, 0.7, 0.9]; assert_equal (stblinv (p, 2, 0, 1, 0), norminv (p, 0, sqrt (2)), 1e-12); assert_equal (stblinv (p, 1, 0, 1, 0), tan (pi .* (p - 0.5)), 1e-12); ***** test # inverts stblcdf x0 = [-3, -0.5, 0.8, 4]; p = stblcdf (x0, 1.4, 0.3, 1.5, -1); assert_equal (stblinv (p, 1.4, 0.3, 1.5, -1), x0, 1e-6); ***** test # boundaries assert_equal (stblinv ([0, 1], 1.5, 0.5, 1, 0), [-Inf, Inf]); ***** error stblinv (int32 (2), 1.5, 0, 1, 0) ***** error stblinv (true, 1.5, 0, 1, 0) ***** error stblinv ('a', 1.5, 0, 1, 0) ***** error stblinv (0.5, 1.5, 0.5, 1) ***** error ... stblinv (0.5, 2.5, 0, 1, 0) ***** error ... stblinv (1.2, 1.5, 0, 1, 0) ***** error ... stblinv (0.5i, 1.5, 0, 1, 0) 14 tests, 14 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/wblinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/wblinv.m ***** demo ## Plot various iCDFs from the Weibull distribution p = 0.001:0.001:0.999; x1 = wblinv (p, 1, 0.5); x2 = wblinv (p, 1, 1); x3 = wblinv (p, 1, 1.5); x4 = wblinv (p, 1, 5); plot (p, x1, '-b', p, x2, '-r', p, x3, '-m', p, x4, '-g') ylim ([0, 2.5]) grid on legend ({'λ = 1, k = 0.5', 'λ = 1, k = 1', ... 'λ = 1, k = 1.5', 'λ = 1, k = 5'}, 'location', 'northwest') title ('Weibull iCDF') xlabel ('probability') ylabel ('x') ***** shared p p = [-1 0 0.63212055882855778 1 2]; ***** assert_equal (wblinv (p, ones (1,5), ones (1,5)), [NaN 0 1 Inf NaN], eps) ***** assert_equal (wblinv (p, 1, ones (1,5)), [NaN 0 1 Inf NaN], eps) ***** assert_equal (wblinv (p, ones (1,5), 1), [NaN 0 1 Inf NaN], eps) ***** assert_equal (wblinv (p, [1 -1 NaN Inf 1], 1), [NaN NaN NaN NaN NaN]) ***** assert_equal (wblinv (p, 1, [1 -1 NaN Inf 1]), [NaN NaN NaN NaN NaN]) ***** assert_equal (wblinv ([p(1:2) NaN p(4:5)], 1, 1), [NaN 0 NaN Inf NaN]) ***** assert_equal (wblinv ([p, NaN], 1, 1), [NaN 0 1 Inf NaN NaN], eps) ***** assert_equal (wblinv (single ([p, NaN]), 1, 1), single ([NaN 0 1 Inf NaN NaN]), eps ('single')) ***** assert_equal (wblinv ([p, NaN], single (1), 1), single ([NaN 0 1 Inf NaN NaN]), eps ('single')) ***** assert_equal (wblinv ([p, NaN], 1, single (1)), single ([NaN 0 1 Inf NaN NaN]), eps ('single')) ***** error wblinv () ***** error wblinv (1,2,3,4) ***** error ... wblinv (ones (3), ones (2), ones (2)) ***** error ... wblinv (ones (2), ones (3), ones (2)) ***** error ... wblinv (ones (2), ones (2), ones (3)) ***** error wblinv (int32 (2), 2, 2) ***** error wblinv (true, 2, 2) ***** error wblinv ('a', 2, 2) ***** error wblinv (i, 2, 2) ***** error wblinv (2, i, 2) ***** error wblinv (2, 2, i) 21 tests, 21 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/betapdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/betapdf.m ***** demo ## Plot various PDFs from the Beta distribution x = 0.001:0.001:0.999; y1 = betapdf (x, 0.5, 0.5); y2 = betapdf (x, 5, 1); y3 = betapdf (x, 1, 3); y4 = betapdf (x, 2, 2); y5 = betapdf (x, 2, 5); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', x, y4, '-c', x, y5, '-m') grid on ylim ([0, 2.5]) legend ({'α = β = 0.5', 'α = 5, β = 1', 'α = 1, β = 3', ... 'α = 2, β = 2', 'α = 2, β = 5'}, 'location', 'north') title ('Beta PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y x = [-1 0 0.5 1 2]; y = [0 2 1 0 0]; ***** assert_equal (betapdf (x, ones (1, 5), 2 * ones (1, 5)), y) ***** assert_equal (betapdf (x, 1, 2 * ones (1, 5)), y) ***** assert_equal (betapdf (x, ones (1, 5), 2), y) ***** assert_equal (betapdf (x, [0 NaN 1 1 1], 2), [NaN NaN y(3:5)]) ***** assert_equal (betapdf (x, 1, 2 * [0 NaN 1 1 1]), [NaN NaN y(3:5)]) ***** assert_equal (betapdf ([x, NaN], 1, 2), [y, NaN]) ***** assert_equal (betapdf (single ([x, NaN]), 1, 2), single ([y, NaN])) ***** assert_equal (betapdf ([x, NaN], single (1), 2), single ([y, NaN])) ***** assert_equal (betapdf ([x, NaN], 1, single (2)), single ([y, NaN])) ***** test x = rand (10,1); y = 1 ./ (pi * sqrt (x .* (1 - x))); assert_equal (betapdf (x, 1/2, 1/2), y, 1e-12); ***** assert_equal (betapdf (0.5, 1000, 1000), 35.678, 1e-3) ***** error betapdf () ***** error betapdf (1) ***** error betapdf (1,2) ***** error betapdf (1,2,3,4) ***** error ... betapdf (ones (3), ones (2), ones (2)) ***** error ... betapdf (ones (2), ones (3), ones (2)) ***** error ... betapdf (ones (2), ones (2), ones (3)) ***** error betapdf (int32 (2), 2, 2) ***** error betapdf (true, 2, 2) ***** error betapdf ('a', 2, 2) ***** error betapdf (i, 2, 2) ***** error betapdf (2, i, 2) ***** error betapdf (2, 2, i) 24 tests, 24 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/fpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/fpdf.m ***** demo ## Plot various PDFs from the F distribution x = 0.01:0.01:4; y1 = fpdf (x, 1, 1); y2 = fpdf (x, 2, 1); y3 = fpdf (x, 5, 2); y4 = fpdf (x, 10, 1); y5 = fpdf (x, 100, 100); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', x, y4, '-c', x, y5, '-m') grid on ylim ([0, 2.5]) legend ({'df1 = 1, df2 = 2', 'df1 = 2, df2 = 1', ... 'df1 = 5, df2 = 2', 'df1 = 10, df2 = 1', ... 'df1 = 100, df2 = 100'}, 'location', 'northeast') title ('F PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y x = [-1, 0, 0.5, 1, 2]; y = [0, 1, 4/9, 1/4, 1/9]; ***** assert_equal (fpdf (x, 2*ones (1,5), 2*ones (1,5)), y, eps) ***** assert_equal (fpdf (x, 2, 2*ones (1,5)), y, eps) ***** assert_equal (fpdf (x, 2*ones (1,5), 2), y, eps) ***** assert_equal (fpdf (x, [0, NaN, Inf, 2, 2], 2), [NaN, NaN, 0.5413, y(4:5)], 1e-4) ***** assert_equal (fpdf (x, 2, [0, NaN, Inf, 2, 2]), [NaN, NaN, 0.6065, y(4:5)], 1e-4) ***** assert_equal (fpdf ([x, NaN], 2, 2), [y, NaN], eps) ***** assert_equal (fpdf (0, 0.5, 2), Inf) ***** assert_equal (fpdf (0, 1, 1), Inf) ***** assert_equal (fpdf (0, 1, 7), Inf) ***** assert_equal (fpdf (0, 1.9, 3), Inf) ***** assert_equal (fpdf (0, 2, 1), 1) ***** assert_equal (fpdf (0, 2, 2), 1) ***** assert_equal (fpdf (0, 2, 5), 1) ***** assert_equal (fpdf (0, 2, 100), 1) ***** assert_equal (fpdf (0, 2, Inf), 1) ***** assert_equal (fpdf (0, 2.1, 3), 0) ***** assert_equal (fpdf (0, 3, 3), 0) ***** assert_equal (fpdf (0, 10, 10), 0) ***** assert_equal (fpdf (0, Inf, 4), 0) ***** assert_equal (fpdf (0, Inf, Inf), 0) ***** assert_equal (fpdf (0, [0.5, 1, 2, 3, Inf], 2), [Inf, Inf, 1, 0, 0]) ***** assert_equal (fpdf (0, 0, 2), NaN) ***** assert_equal (fpdf (0, 2, 0), NaN) ***** assert_equal (fpdf (0, NaN, 2), NaN) ***** assert_equal (fpdf (0, 2, NaN), NaN) ***** assert_equal (fpdf (single (0), 2, 2), single (1)) ***** test #F (x, 1, df1) == T distribution (sqrt (x), df1) / sqrt (x) rand ('seed', 1234); # for reproducibility xr = rand (10,1); xr = xr(x > 0.1 & x < 0.9); yr = tpdf (sqrt (xr), 2) ./ sqrt (xr); assert_equal (fpdf (xr, 1, 2), yr, 5*eps); ***** test yy = fpdf (2, 4, Inf); assert_equal (yy, 0.1465, 1e-4) ***** test yy = fpdf (2, 4, 1000000000000000); assert_equal (yy, 0.1465, 1e-4) ***** test yy = fpdf (2, Inf, 4); assert_equal (yy, 0.1839, 1e-4) ***** test yy = fpdf (2, 10000000000000000, 4); assert_equal (yy, 0.1839, 1e-4) ***** test yy = fpdf (2, Inf, Inf); assert_equal (yy, 0) ***** test yy = fpdf (NaN, Inf, Inf); assert_equal (yy, NaN) ***** assert_equal (fpdf (single ([x, NaN]), 2, 2), single ([y, NaN]), eps ('single')) ***** assert_equal (fpdf ([x, NaN], single (2), 2), single ([y, NaN]), eps ('single')) ***** assert_equal (fpdf ([x, NaN], 2, single (2)), single ([y, NaN]), eps ('single')) ***** error fpdf () ***** error fpdf (1) ***** error fpdf (1,2) ***** error ... fpdf (ones (3), ones (2), ones (2)) ***** error ... fpdf (ones (2), ones (3), ones (2)) ***** error ... fpdf (ones (2), ones (2), ones (3)) ***** error fpdf (int32 (2), 2, 2) ***** error fpdf (true, 2, 2) ***** error fpdf ('a', 2, 2) ***** error fpdf (i, 2, 2) ***** error fpdf (2, i, 2) ***** error fpdf (2, 2, i) 48 tests, 48 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/poisscdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/poisscdf.m ***** demo ## Plot various CDFs from the Poisson distribution x = 0:20; p1 = poisscdf (x, 1); p2 = poisscdf (x, 4); p3 = poisscdf (x, 10); plot (x, p1, '*b', x, p2, '*g', x, p3, '*r') grid on ylim ([0, 1]) legend ({'λ = 1', 'λ = 4', 'λ = 10'}, 'location', 'southeast') title ('Poisson CDF') xlabel ('values in x (number of occurrences)') ylabel ('probability') ***** shared x, y x = [-1 0 1 2 Inf]; y = [0, gammainc(1, (x(2:4) +1), 'upper'), 1]; ***** assert_equal (poisscdf (x, ones (1,5)), y) ***** assert_equal (poisscdf (x, 1), y) ***** assert_equal (poisscdf (x, [1 0 NaN 1 1]), [y(1) 1 NaN y(4:5)]) ***** assert_equal (poisscdf ([x(1:2) NaN Inf x(5)], 1), [y(1:2) NaN 1 y(5)]) ***** assert_equal (poisscdf ([x, NaN], 1), [y, NaN]) ***** assert_equal (poisscdf (single ([x, NaN]), 1), single ([y, NaN]), eps ('single')) ***** assert_equal (poisscdf ([x, NaN], single (1)), single ([y, NaN]), eps ('single')) ***** error poisscdf () ***** error poisscdf (1) ***** error poisscdf (1, 2, 3) ***** error poisscdf (1, 2, 'tail') ***** error ... poisscdf (ones (3), ones (2)) ***** error ... poisscdf (ones (2), ones (3)) ***** error poisscdf (true, 2) ***** error poisscdf ('a', 2) ***** assert_equal (class (poisscdf (int32 (2), 2)), 'double') ***** error poisscdf (i, 2) ***** error poisscdf (2, i) 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/unifinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/unifinv.m ***** demo ## Plot various iCDFs from the continuous uniform distribution p = 0.001:0.001:0.999; x1 = unifinv (p, 2, 5); x2 = unifinv (p, 3, 9); plot (p, x1, '-b', p, x2, '-g') grid on xlim ([0, 1]) ylim ([0, 10]) legend ({'a = 2, b = 5', 'a = 3, b = 9'}, 'location', 'northwest') title ('Continuous uniform iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p p = [-1 0 0.5 1 2]; ***** assert_equal (unifinv (p, ones (1,5), 2*ones (1,5)), [NaN 1 1.5 2 NaN]) ***** assert_equal (unifinv (p, 0, 1), [NaN 1 1.5 2 NaN] - 1) ***** assert_equal (unifinv (p, 1, 2*ones (1,5)), [NaN 1 1.5 2 NaN]) ***** assert_equal (unifinv (p, ones (1,5), 2), [NaN 1 1.5 2 NaN]) ***** assert_equal (unifinv (p, [1 2 NaN 1 1], 2), [NaN NaN NaN 2 NaN]) ***** assert_equal (unifinv (p, 1, 2*[1 0 NaN 1 1]), [NaN NaN NaN 2 NaN]) ***** assert_equal (unifinv ([p(1:2) NaN p(4:5)], 1, 2), [NaN 1 NaN 2 NaN]) ***** assert_equal (unifinv ([p, NaN], 1, 2), [NaN 1 1.5 2 NaN NaN]) ***** assert_equal (unifinv (single ([p, NaN]), 1, 2), single ([NaN 1 1.5 2 NaN NaN])) ***** assert_equal (unifinv ([p, NaN], single (1), 2), single ([NaN 1 1.5 2 NaN NaN])) ***** assert_equal (unifinv ([p, NaN], 1, single (2)), single ([NaN 1 1.5 2 NaN NaN])) ***** error unifinv () ***** error unifinv (1, 2) ***** error ... unifinv (ones (3), ones (2), ones (2)) ***** error ... unifinv (ones (2), ones (3), ones (2)) ***** error ... unifinv (ones (2), ones (2), ones (3)) ***** error unifinv (int32 (2), 2, 2) ***** error unifinv (true, 2, 2) ***** error unifinv ('a', 2, 2) ***** error unifinv (i, 2, 2) ***** error unifinv (2, i, 2) ***** error unifinv (2, 2, i) 22 tests, 22 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/betacdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/betacdf.m ***** demo ## Plot various CDFs from the Beta distribution x = 0:0.005:1; p1 = betacdf (x, 0.5, 0.5); p2 = betacdf (x, 5, 1); p3 = betacdf (x, 1, 3); p4 = betacdf (x, 2, 2); p5 = betacdf (x, 2, 5); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', x, p4, '-c', x, p5, '-m') grid on legend ({'α = β = 0.5', 'α = 5, β = 1', 'α = 1, β = 3', ... 'α = 2, β = 2', 'α = 2, β = 5'}, 'location', 'northwest') title ('Beta CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y, x1, x2 x = [-1 0 0.5 1 2]; y = [0 0 0.75 1 1]; ***** assert_equal (betacdf (x, ones (1, 5), 2 * ones (1, 5)), y) ***** assert_equal (betacdf (x, 1, 2 * ones (1, 5)), y) ***** assert_equal (betacdf (x, ones (1, 5), 2), y) ***** assert_equal (betacdf (x, [0 1 NaN 1 1], 2), [NaN 0 NaN 1 1]) ***** assert_equal (betacdf (x, 1, 2 * [0 1 NaN 1 1]), [NaN 0 NaN 1 1]) ***** assert_equal (betacdf ([x(1:2) NaN x(4:5)], 1, 2), [y(1:2) NaN y(4:5)]) x1 = [0.1:0.2:0.9]; ***** assert_equal (betacdf (x1, 2, 2), [0.028, 0.216, 0.5, 0.784, 0.972], 1e-14); ***** assert_equal (betacdf (x1, 2, 2, 'upper'), 1 - [0.028, 0.216, 0.5, 0.784, 0.972],... 1e-14); x2 = [1, 2, 3]; ***** assert_equal (betacdf (0.5, x2, x2), [0.5, 0.5, 0.5], 1e-14); ***** assert_equal (betacdf ([x, NaN], 1, 2), [y, NaN]) ***** assert_equal (betacdf (single ([x, NaN]), 1, 2), single ([y, NaN])) ***** assert_equal (betacdf ([x, NaN], single (1), 2), single ([y, NaN])) ***** assert_equal (betacdf ([x, NaN], 1, single (2)), single ([y, NaN])) ***** error betacdf () ***** error betacdf (1) ***** error betacdf (1, 2) ***** error betacdf (1, 2, 3, 4, 5) ***** error betacdf (1, 2, 3, 'tail') ***** error betacdf (1, 2, 3, 4) ***** error ... betacdf (ones (3), ones (2), ones (2)) ***** error ... betacdf (ones (2), ones (3), ones (2)) ***** error ... betacdf (ones (2), ones (2), ones (3)) ***** error betacdf (int32 (2), 2, 2) ***** error betacdf (true, 2, 2) ***** error betacdf ('a', 2, 2) ***** error betacdf (i, 2, 2) ***** error betacdf (2, i, 2) ***** error betacdf (2, 2, i) 28 tests, 28 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/ricecdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/ricecdf.m ***** demo ## Plot various CDFs from the Rician distribution x = 0:0.01:10; p1 = ricecdf (x, 0, 1); p2 = ricecdf (x, 0.5, 1); p3 = ricecdf (x, 1, 1); p4 = ricecdf (x, 2, 1); p5 = ricecdf (x, 4, 1); plot (x, p1, '-b', x, p2, 'g', x, p3, '-r', x, p4, '-m', x, p5, '-k') grid on ylim ([0, 1]) xlim ([0, 8]) legend ({'s = 0, σ = 1', 's = 0.5, σ = 1', 's = 1, σ = 1', ... 's = 2, σ = 1', 's = 4, σ = 1'}, 'location', 'southeast') title ('Rician CDF') xlabel ('values in x') ylabel ('probability') ***** demo ## Plot various CDFs from the Rician distribution x = 0:0.01:10; p1 = ricecdf (x, 0, 0.5); p2 = ricecdf (x, 0, 2); p3 = ricecdf (x, 0, 3); p4 = ricecdf (x, 2, 2); p5 = ricecdf (x, 4, 2); plot (x, p1, '-b', x, p2, 'g', x, p3, '-r', x, p4, '-m', x, p5, '-k') grid on ylim ([0, 1]) xlim ([0, 8]) legend ({'ν = 0, σ = 0.5', 'ν = 0, σ = 2', 'ν = 0, σ = 3', ... 'ν = 2, σ = 2', 'ν = 4, σ = 2'}, 'location', 'southeast') title ('Rician CDF') xlabel ('values in x') ylabel ('probability') ***** test x = 0:0.5:2.5; s = 1:6; p = ricecdf (x, s, 1); expected_p = [0.0000, 0.0179, 0.0108, 0.0034, 0.0008, 0.0001]; assert_equal (p, expected_p, 0.001); ***** test x = 0:0.5:2.5; sigma = 1:6; p = ricecdf (x, 1, sigma); expected_p = [0.0000, 0.0272, 0.0512, 0.0659, 0.0754, 0.0820]; assert_equal (p, expected_p, 0.001); ***** test x = 0:0.5:2.5; p = ricecdf (x, 0, 1); expected_p = [0.0000, 0.1175, 0.3935, 0.6753, 0.8647, 0.9561]; assert_equal (p, expected_p, 0.001); ***** test x = 0:0.5:2.5; p = ricecdf (x, 1, 1); expected_p = [0.0000, 0.0735, 0.2671, 0.5120, 0.7310, 0.8791]; assert_equal (p, expected_p, 0.001); ***** shared x, p x = [-1, 0, 1, 2, Inf]; p = [0, 0, 0.26712019620318, 0.73098793996409, 1]; ***** assert_equal (ricecdf (x, 1, 1), p, 1e-14) ***** assert_equal (ricecdf (x, 1, 1, 'upper'), 1 - p, 1e-14) ***** error ricecdf () ***** error ricecdf (1) ***** error ricecdf (1, 2) ***** error ricecdf (1, 2, 3, 'uper') ***** error ricecdf (1, 2, 3, 4) ***** error ... ricecdf (ones (3), ones (2), ones (2)) ***** error ... ricecdf (ones (2), ones (3), ones (2)) ***** error ... ricecdf (ones (2), ones (2), ones (3)) ***** error ricecdf (int32 (2), 2, 3) ***** error ricecdf (true, 2, 3) ***** error ricecdf ('a', 2, 3) ***** error ricecdf (i, 2, 3) ***** error ricecdf (2, i, 3) ***** error ricecdf (2, 2, i) 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/plpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/plpdf.m ***** demo ## Plot various PDFs from the Piecewise linear distribution data = 0:0.01:10; x1 = [0, 1, 3, 4, 7, 10]; Fx1 = [0, 0.2, 0.5, 0.6, 0.7, 1]; x2 = [0, 2, 5, 6, 7, 8]; Fx2 = [0, 0.1, 0.3, 0.6, 0.9, 1]; y1 = plpdf (data, x1, Fx1); y2 = plpdf (data, x2, Fx2); plot (data, y1, '-b', data, y2, 'g') grid on ylim ([0, 0.6]) xlim ([0, 10]) legend ({'x1, Fx1', 'x2, Fx2'}, 'location', 'northeast') title ('Piecewise linear CDF') xlabel ('values in data') ylabel ('density') ***** shared x, Fx x = [0, 1, 3, 4, 7, 10]; Fx = [0, 0.2, 0.5, 0.6, 0.7, 1]; ***** assert_equal (plpdf (0.5, x, Fx), 0.2, eps); ***** assert_equal (plpdf (1.5, x, Fx), 0.15, eps); ***** assert_equal (plpdf (3.5, x, Fx), 0.1, eps); ***** assert_equal (plpdf (5, x, Fx), 0.1/3, eps); ***** assert_equal (plpdf (8, x, Fx), 0.1, eps); ***** error plpdf () ***** error plpdf (1) ***** error plpdf (1, 2) ***** error ... plpdf (1, [0, 1, 2], [0, 1]) ***** error ... plpdf (1, [0], [1]) ***** error ... plpdf (1, [0, 1, 2], [0, 1, 1.5]) ***** error ... plpdf (1, [0, 1, 2], [0, i, 1]) ***** error ... plpdf (int32 (2), [0, 1, 2], [0, 0.5, 1]) ***** error ... plpdf (true, [0, 1, 2], [0, 0.5, 1]) ***** error ... plpdf ('a', [0, 1, 2], [0, 0.5, 1]) ***** error ... plpdf (i, [0, 1, 2], [0, 0.5, 1]) ***** error ... plpdf (1, [0, i, 2], [0, 0.5, 1]) ***** error ... plpdf (1, [0, 1, 2], [0, 0.5i, 1]) 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/nctinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/nctinv.m ***** demo ## Plot various iCDFs from the noncentral T distribution p = 0.001:0.001:0.999; x1 = nctinv (p, 1, 0); x2 = nctinv (p, 4, 0); x3 = nctinv (p, 1, 2); x4 = nctinv (p, 4, 2); plot (p, x1, '-r', p, x2, '-g', p, x3, '-k', p, x4, '-m') grid on ylim ([-5, 5]) legend ({'df = 1, μ = 0', 'df = 4, μ = 0', ... 'df = 1, μ = 2', 'df = 4, μ = 2'}, 'location', 'northwest') title ('Noncentral T iCDF') xlabel ('probability') ylabel ('values in x') ***** demo ## Compare the noncentral T iCDF with MU = 1 to the T iCDF ## with the same number of degrees of freedom (10). p = 0.001:0.001:0.999; x1 = nctinv (p, 10, 1); x2 = tinv (p, 10); plot (p, x1, '-', p, x2, '-'); grid on ylim ([-5, 5]) legend ({'Noncentral T(10,1)', 'T(10)'}, 'location', 'northwest') title ('Noncentral T vs T quantile functions') xlabel ('probability') ylabel ('values in x') ***** test x = [-Inf,-0.3347,0.1756,0.5209,0.8279,1.1424,1.5021,1.9633,2.6571,4.0845,Inf]; assert_equal (nctinv ([0:0.1:1], 2, 1), x, 1e-4); ***** test x = [-Inf,1.5756,2.0827,2.5343,3.0043,3.5406,4.2050,5.1128,6.5510,9.6442,Inf]; assert_equal (nctinv ([0:0.1:1], 2, 3), x, 1e-4); ***** test x = [-Inf,2.2167,2.9567,3.7276,4.6464,5.8455,7.5619,10.3327,15.7569,31.8159,Inf]; assert_equal (nctinv ([0:0.1:1], 1, 4), x, 1e-4); ***** test x = [1.7791 1.9368 2.0239 2.0801 2.1195 2.1489]; assert_equal (nctinv (0.05, [1, 2, 3, 4, 5, 6], 4), x, 1e-4); ***** test x = [-0.7755, 0.3670, 1.2554, 2.0239, 2.7348, 3.4154]; assert_equal (nctinv (0.05, 3, [1, 2, 3, 4, 5, 6]), x, 1e-4); ***** test x = [-0.7183, 0.3624, 1.2878, 2.1195, -3.5413, 3.6430]; assert_equal (nctinv (0.05, 5, [1, 2, 3, 4, -1, 6]), x, 1e-4); ***** test assert_equal (nctinv (0.996, 5, 8), 30.02610554063658, 2e-11); ***** error nctinv () ***** error nctinv (1) ***** error nctinv (1, 2) ***** error ... nctinv (ones (3), ones (2), ones (2)) ***** error ... nctinv (ones (2), ones (3), ones (2)) ***** error ... nctinv (ones (2), ones (2), ones (3)) ***** error nctinv (int32 (2), 2, 2) ***** error nctinv (true, 2, 2) ***** error nctinv ('a', 2, 2) ***** error nctinv (i, 2, 2) ***** error nctinv (2, i, 2) ***** error nctinv (2, 2, i) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/geornd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/geornd.m ***** assert_equal (size (geornd (0.5)), [1, 1]) ***** assert_equal (size (geornd (0.5*ones (2,1))), [2, 1]) ***** assert_equal (size (geornd (0.5*ones (2,2))), [2, 2]) ***** assert_equal (size (geornd (0.5, 3)), [3, 3]) ***** assert_equal (size (geornd (0.5, [4 1])), [4, 1]) ***** assert_equal (size (geornd (0.5, 4, 1)), [4, 1]) ***** assert_equal (size (geornd (0.5, [])), [0, 0]) ***** assert_equal (size (geornd (0.5, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (geornd (1, -1)), [0, 0]) ***** assert_equal (size (geornd (1, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (geornd (1, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (geornd (0.5)), "double") ***** assert_equal (class (geornd (single (0.5))), "single") ***** assert_equal (class (geornd (single ([0.5 0.5]))), "single") ***** assert_equal (class (geornd (single (0))), "single") ***** assert_equal (class (geornd (single (1))), "single") ***** error geornd () ***** error geornd (i) ***** error ... geornd (1, 1.2) ***** error ... geornd (1, ones (2)) ***** error ... geornd (1, [2 0 2.5]) ***** error ... geornd (ones (2), ones (2)) ***** error ... geornd (1, 2, 1.5, 5) ***** error geornd (ones (2,2), 3) ***** error geornd (ones (2,2), [3, 2]) ***** error geornd (ones (2,2), 2, 3) 26 tests, 26 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/poissrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/poissrnd.m ***** assert_equal (size (poissrnd (2)), [1, 1]) ***** assert_equal (size (poissrnd (ones (2, 1))), [2, 1]) ***** assert_equal (size (poissrnd (ones (2, 2))), [2, 2]) ***** assert_equal (size (poissrnd (1, 3)), [3, 3]) ***** assert_equal (size (poissrnd (1, [4, 1])), [4, 1]) ***** assert_equal (size (poissrnd (1, 4, 1)), [4, 1]) ***** assert_equal (size (poissrnd (1, 4, 1)), [4, 1]) ***** assert_equal (size (poissrnd (1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (poissrnd (1, 0, 1)), [0, 1]) ***** assert_equal (size (poissrnd (1, 1, 0)), [1, 0]) ***** assert_equal (size (poissrnd (1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (poissrnd (1, [])), [0, 0]) ***** assert_equal (size (poissrnd (1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (poissrnd (1, -1)), [0, 0]) ***** assert_equal (size (poissrnd (1, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (poissrnd (1, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (poissrnd (0, 1, 1), 0) ***** assert_equal (poissrnd ([0, 0, 0], [1, 3]), [0 0 0]) ***** assert_equal (class (poissrnd (2)), "double") ***** assert_equal (class (poissrnd (single (2))), "single") ***** assert_equal (class (poissrnd (single ([2 2]))), "single") ***** error poissrnd () ***** error poissrnd (i) ***** error ... poissrnd (1, 1.2) ***** error ... poissrnd (1, ones (2)) ***** error ... poissrnd (1, [2 0 2.5]) ***** error ... poissrnd (ones (2), ones (2)) ***** error ... poissrnd (1, 2, 1.5, 5) ***** error poissrnd (ones (2,2), 3) ***** error poissrnd (ones (2,2), [3, 2]) ***** error poissrnd (ones (2,2), 2, 3) 31 tests, 31 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/hnrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/hnrnd.m ***** assert_equal (size (hnrnd (1, 1, 1)), [1, 1]) ***** assert_equal (size (hnrnd (1, 1, 2)), [2, 2]) ***** assert_equal (size (hnrnd (1, 1, [2, 1])), [2, 1]) ***** assert_equal (size (hnrnd (1, zeros (2, 2))), [2, 2]) ***** assert_equal (size (hnrnd (1, ones (2, 1))), [2, 1]) ***** assert_equal (size (hnrnd (1, ones (2, 2))), [2, 2]) ***** assert_equal (size (hnrnd (ones (2, 1), 1)), [2, 1]) ***** assert_equal (size (hnrnd (ones (2, 2), 1)), [2, 2]) ***** assert_equal (size (hnrnd (1, 1, 3)), [3, 3]) ***** assert_equal (size (hnrnd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (hnrnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (hnrnd (1, 1, [])), [0, 0]) ***** assert_equal (size (hnrnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (hnrnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (hnrnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (hnrnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** test r = hnrnd (1, [1, 0, -1]); assert_equal (r([2:3]), [NaN, NaN]) ***** assert_equal (class (hnrnd (1, 0)), "double") ***** assert_equal (class (hnrnd (1, single (0))), "single") ***** assert_equal (class (hnrnd (1, single ([0, 0]))), "single") ***** assert_equal (class (hnrnd (1, single (1))), "single") ***** assert_equal (class (hnrnd (1, single ([1, 1]))), "single") ***** assert_equal (class (hnrnd (single (1), 1)), "single") ***** assert_equal (class (hnrnd (single ([1, 1]), 1)), "single") ***** error hnrnd () ***** error hnrnd (1) ***** error ... hnrnd (ones (3), ones (2)) ***** error ... hnrnd (ones (2), ones (3)) ***** error hnrnd (i, 2, 3) ***** error hnrnd (1, i, 3) ***** error ... hnrnd (1, 2, 1.2) ***** error ... hnrnd (1, 2, ones (2)) ***** error ... hnrnd (1, 2, [2 0 2.5]) ***** error ... hnrnd (1, 2, 2, 1.5, 5) ***** error ... hnrnd (2, ones (2), 3) ***** error ... hnrnd (2, ones (2), [3, 2]) ***** error ... hnrnd (2, ones (2), 3, 2) 37 tests, 37 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/chi2inv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/chi2inv.m ***** demo ## Plot various iCDFs from the chi-squared distribution p = 0.001:0.001:0.999; x1 = chi2inv (p, 1); x2 = chi2inv (p, 2); x3 = chi2inv (p, 3); x4 = chi2inv (p, 4); x5 = chi2inv (p, 6); x6 = chi2inv (p, 9); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', ... p, x4, '-c', p, x5, '-m', p, x6, '-y') grid on ylim ([0, 8]) legend ({'df = 1', 'df = 2', 'df = 3', ... 'df = 4', 'df = 6', 'df = 9'}, 'location', 'northwest') title ('Chi-squared iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p p = [-1 0 0.3934693402873666 1 2]; ***** assert_equal (chi2inv (p, 2*ones (1,5)), [NaN 0 1 Inf NaN], 5*eps) ***** assert_equal (chi2inv (p, 2), [NaN 0 1 Inf NaN], 5*eps) ***** assert_equal (chi2inv (p, 2*[0 1 NaN 1 1]), [NaN 0 NaN Inf NaN], 5*eps) ***** assert_equal (chi2inv ([p(1:2) NaN p(4:5)], 2), [NaN 0 NaN Inf NaN], 5*eps) ***** assert_equal (chi2inv ([p, NaN], 2), [NaN 0 1 Inf NaN NaN], 5*eps) ***** assert_equal (chi2inv (single ([p, NaN]), 2), single ([NaN 0 1 Inf NaN NaN]), 5*eps ('single')) ***** assert_equal (chi2inv ([p, NaN], single (2)), single ([NaN 0 1 Inf NaN NaN]), 5*eps ('single')) ***** error chi2inv () ***** error chi2inv (1) ***** error chi2inv (1,2,3) ***** error ... chi2inv (ones (3), ones (2)) ***** error ... chi2inv (ones (2), ones (3)) ***** error chi2inv (int32 (2), 2) ***** error chi2inv (true, 2) ***** error chi2inv ('a', 2) ***** error chi2inv (i, 2) ***** error chi2inv (2, i) 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/stblrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/stblrnd.m ***** demo ## Draw a large stable sample and overlay the theoretical density rng (42); r = stblrnd (1.5, 0.5, 1, 0, 1, 1e5); r = r(abs (r) < 15); hist (r, 100, 1); hold on; x = linspace (-15, 15, 400); plot (x, stblpdf (x, 1.5, 0.5, 1, 0), "r-", "linewidth", 2); hold off; ***** test rand ("state", 42); r = stblrnd (1.5, 0.5, 1, 0, 1, 200000); xs = [-2, -0.5, 0.5, 2]; ec = arrayfun (@(x) mean (r <= x), xs); assert_equal (ec, stblcdf (xs, 1.5, 0.5, 1, 0), 0.01); ***** test # heavy-tailed alpha < 1, scaled and shifted rand ("state", 7); r = stblrnd (0.8, -0.3, 2, 1, 1, 200000); xs = [-3, 0, 1, 4]; ec = arrayfun (@(x) mean (r <= x), xs); assert_equal (ec, stblcdf (xs, 0.8, -0.3, 2, 1), 0.01); ***** test # alpha = 1 with beta ~= 0 rand ("state", 99); r = stblrnd (1, 0.5, 1.5, -2, 1, 200000); xs = [-5, -2, 0, 3]; ec = arrayfun (@(x) mean (r <= x), xs); assert_equal (ec, stblcdf (xs, 1, 0.5, 1.5, -2), 0.01); ***** test # alpha = 2 is normal with variance 2*gam^2 rand ("state", 1); r = stblrnd (2, 0, 1, 0, 1, 200000); assert_equal (mean (r), 0, 0.02); assert_equal (var (r), 2, 0.05); ***** test assert_equal (size (stblrnd (1.5, 0.5, 1, 0, 3, 4)), [3, 4]); assert_equal (size (stblrnd (1.5, 0.5, 1, 0, [2, 5])), [2, 5]); assert_equal (isscalar (stblrnd (1.5, 0.5, 1, 0)), true); assert_equal (size (stblrnd (1.5, 0.5, 1, 0, -1)), [0, 0]); assert_equal (size (stblrnd (1.5, 0.5, 1, 0, 2, -1, 5)), [2, 0, 5]); ***** error stblrnd (1.5, 0.5, 1) ***** error ... stblrnd (2.5, 0, 1, 0) ***** error ... stblrnd (1.5, 2, 1, 0) ***** error stblrnd (1.5, 0, 0, 0) ***** error stblrnd (1.5, 0, 1, 1i) ***** error ... stblrnd (1.5, 0, 1, 0, 2.5) 11 tests, 11 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/plinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/plinv.m ***** demo ## Plot various iCDFs from the Piecewise linear distribution p = 0.001:0.001:0.999; x1 = [0, 1, 3, 4, 7, 10]; Fx1 = [0, 0.2, 0.5, 0.6, 0.7, 1]; x2 = [0, 2, 5, 6, 7, 8]; Fx2 = [0, 0.1, 0.3, 0.6, 0.9, 1]; data1 = plinv (p, x1, Fx1); data2 = plinv (p, x2, Fx2); plot (p, data1, '-b', p, data2, '-g') grid on legend ({'x1, Fx1', 'x2, Fx2'}, 'location', 'northwest') title ('Piecewise linear iCDF') xlabel ('probability') ylabel ('values in data') ***** test p = 0:0.2:1; data = plinv (p, [0, 1], [0, 1]); assert_equal (data, p); ***** test p = 0:0.2:1; data = plinv (p, [0, 2], [0, 1]); assert_equal (data, 2 * p); ***** test p = 0:0.2:1; data_out = 1:6; data = plinv (p, [0, 1], [0, 0.5]); assert_equal (data, [0, 0.4, 0.8, NA, NA, NA]); ***** test p = 0:0.2:1; data_out = 1:6; data = plinv (p, [0, 0.5], [0, 1]); assert_equal (data, [0:0.1:0.5]); ***** error plinv () ***** error plinv (1) ***** error plinv (1, 2) ***** error ... plinv (1, [0, 1, 2], [0, 1]) ***** error ... plinv (1, [0], [1]) ***** error ... plinv (1, [0, 1, 2], [0, 1, 1.5]) ***** error ... plinv (1, [0, 1, 2], [0, i, 1]) ***** error ... plinv (int32 (2), [0, 1, 2], [0, 0.5, 1]) ***** error ... plinv (true, [0, 1, 2], [0, 0.5, 1]) ***** error ... plinv ('a', [0, 1, 2], [0, 0.5, 1]) ***** error ... plinv (i, [0, 1, 2], [0, 0.5, 1]) ***** error ... plinv (1, [0, i, 2], [0, 0.5, 1]) ***** error ... plinv (1, [0, 1, 2], [0, 0.5i, 1]) 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/tlspdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/tlspdf.m ***** demo ## Plot various PDFs from the Student's T distribution x = -8:0.01:8; y1 = tlspdf (x, 0, 1, 1); y2 = tlspdf (x, 0, 2, 2); y3 = tlspdf (x, 3, 2, 5); y4 = tlspdf (x, -1, 3, Inf); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', x, y4, '-m') grid on xlim ([-8, 8]) ylim ([0, 0.41]) legend ({'mu = 0, sigma = 1, nu = 1', 'mu = 0, sigma = 2, nu = 2', ... 'mu = 3, sigma = 2, nu = 5', 'mu = -1, sigma = 3, nu = \infty'}, ... 'location', 'northwest') title ('Location-scale Student''s T PDF') xlabel ('values in x') ylabel ('density') ***** test x = rand (10,1); y = 1./(pi * (1 + x.^2)); assert_equal (tlspdf (x, 0, 1, 1), y, 5*eps); assert_equal (tlspdf (x+5, 5, 1, 1), y, 5*eps); assert_equal (tlspdf (x.*2, 0, 2, 1), y./2, 5*eps); ***** shared x, y x = [-Inf 0 0.5 1 Inf]; y = 1./(pi * (1 + x.^2)); ***** assert_equal (tlspdf (x, 0, 1, ones (1,5)), y, eps) ***** assert_equal (tlspdf (x, 0, 1, 1), y, eps) ***** assert_equal (tlspdf (x, 0, 1, [0 NaN 1 1 1]), [NaN NaN y(3:5)], eps) ***** assert_equal (tlspdf (x, 0, 1, Inf), normpdf (x)) ***** assert_equal (class (tlspdf ([x, NaN], 1, 1, 1)), "double") ***** assert_equal (class (tlspdf (single ([x, NaN]), 1, 1, 1)), "single") ***** assert_equal (class (tlspdf ([x, NaN], single (1), 1, 1)), "single") ***** assert_equal (class (tlspdf ([x, NaN], 1, single (1), 1)), "single") ***** assert_equal (class (tlspdf ([x, NaN], 1, 1, single (1))), "single") ***** error tlspdf () ***** error tlspdf (1) ***** error tlspdf (1, 2) ***** error tlspdf (1, 2, 3) ***** error ... tlspdf (ones (3), ones (2), 1, 1) ***** error ... tlspdf (ones (2), 1, ones (3), 1) ***** error ... tlspdf (ones (2), 1, 1, ones (3)) ***** error tlspdf (int32 (2), 2, 1, 1) ***** error tlspdf (true, 2, 1, 1) ***** error tlspdf ('a', 2, 1, 1) ***** error tlspdf (i, 2, 1, 1) ***** error tlspdf (2, i, 1, 1) ***** error tlspdf (2, 1, i, 1) ***** error tlspdf (2, 1, 1, i) 24 tests, 24 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/nbinrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/nbinrnd.m ***** assert_equal (size (nbinrnd (1, 0.5)), [1, 1]) ***** assert_equal (size (nbinrnd (1, 0.5 * ones (2, 1))), [2, 1]) ***** assert_equal (size (nbinrnd (1, 0.5 * ones (2, 2))), [2, 2]) ***** assert_equal (size (nbinrnd (ones (2, 1), 0.5)), [2, 1]) ***** assert_equal (size (nbinrnd (ones (2, 2), 0.5)), [2, 2]) ***** assert_equal (size (nbinrnd (1, 0.5, 3)), [3, 3]) ***** assert_equal (size (nbinrnd (1, 0.5, [4, 1])), [4, 1]) ***** assert_equal (size (nbinrnd (1, 0.5, 4, 1)), [4, 1]) ***** assert_equal (size (nbinrnd (1, 0.5, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (nbinrnd (1, 0.5, 0, 1)), [0, 1]) ***** assert_equal (size (nbinrnd (1, 0.5, 1, 0)), [1, 0]) ***** assert_equal (size (nbinrnd (1, 0.5, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (nbinrnd (1, 0.5, [])), [0, 0]) ***** assert_equal (size (nbinrnd (1, 0.5, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (nbinrnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (nbinrnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (nbinrnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (nbinrnd (1, 0.5)), "double") ***** assert_equal (class (nbinrnd (1, single (0.5))), "single") ***** assert_equal (class (nbinrnd (1, single ([0.5, 0.5]))), "single") ***** assert_equal (class (nbinrnd (single (1), 0.5)), "single") ***** assert_equal (class (nbinrnd (single ([1, 1]), 0.5)), "single") ***** error nbinrnd () ***** error nbinrnd (1) ***** error ... nbinrnd (ones (3), ones (2)) ***** error ... nbinrnd (ones (2), ones (3)) ***** error nbinrnd (i, 2, 3) ***** error nbinrnd (1, i, 3) ***** error ... nbinrnd (1, 2, 1.2) ***** error ... nbinrnd (1, 2, ones (2)) ***** error ... nbinrnd (1, 2, [2 0 2.5]) ***** error ... nbinrnd (1, 2, 2, 1.5, 5) ***** error ... nbinrnd (2, ones (2), 3) ***** error ... nbinrnd (2, ones (2), [3, 2]) ***** error ... nbinrnd (2, ones (2), 3, 2) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/betarnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/betarnd.m ***** assert_equal (size (betarnd (2, 1/2)), [1 1]) ***** assert_equal (size (betarnd (2 * ones (2, 1), 1/2)), [2, 1]) ***** assert_equal (size (betarnd (2 * ones (2, 2), 1/2)), [2, 2]) ***** assert_equal (size (betarnd (2, 1/2 * ones (2, 1))), [2, 1]) ***** assert_equal (size (betarnd (1, 1/2 * ones (2, 2))), [2, 2]) ***** assert_equal (size (betarnd (ones (2, 1), 1)), [2, 1]) ***** assert_equal (size (betarnd (ones (2, 2), 1)), [2, 2]) ***** assert_equal (size (betarnd (2, 1/2, 3)), [3, 3]) ***** assert_equal (size (betarnd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (betarnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (betarnd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (betarnd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (betarnd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (betarnd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (betarnd (1, 1, [])), [0, 0]) ***** assert_equal (size (betarnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (betarnd (1, 1/2, -1)), [0, 0]) ***** assert_equal (size (betarnd (1, 1/2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (betarnd (1, 1/2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (betarnd (1, 1)), "double") ***** assert_equal (class (betarnd (1, single (0))), "single") ***** assert_equal (class (betarnd (1, single ([0, 0]))), "single") ***** assert_equal (class (betarnd (1, single (1), 2)), "single") ***** assert_equal (class (betarnd (1, single ([1, 1]), 1, 2)), "single") ***** assert_equal (class (betarnd (single (1), 1, 2)), "single") ***** assert_equal (class (betarnd (single ([1, 1]), 1, 1, 2)), "single") ***** error betarnd () ***** error betarnd (1) ***** error ... betarnd (ones (3), ones (2)) ***** error ... betarnd (ones (2), ones (3)) ***** error betarnd (i, 2) ***** error betarnd (1, i) ***** error ... betarnd (1, 1/2, 1.2) ***** error ... betarnd (1, 1/2, ones (2)) ***** error ... betarnd (1, 1/2, [2 0 2.5]) ***** error ... betarnd (1, 1/2, 2, 1.5, 5) ***** error ... betarnd (2, 1/2 * ones (2), 3) ***** error ... betarnd (2, 1/2 * ones (2), [3, 2]) ***** error ... betarnd (2, 1/2 * ones (2), 3, 2) ***** error ... betarnd (2 * ones (2), 1/2, 3) ***** error ... betarnd (2 * ones (2), 1/2, [3, 2]) ***** error ... betarnd (2 * ones (2), 1/2, 3, 2) 42 tests, 42 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/evinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/evinv.m ***** demo ## Plot various iCDFs from the extreme value distribution p = 0.001:0.001:0.999; x1 = evinv (p, 0.5, 2); x2 = evinv (p, 1.0, 2); x3 = evinv (p, 1.5, 3); x4 = evinv (p, 3.0, 4); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', p, x4, '-c') grid on ylim ([-10, 10]) legend ({'μ = 0.5, σ = 2', 'μ = 1.0, σ = 2', ... 'μ = 1.5, σ = 3', 'μ = 3.0, σ = 4'}, 'location', 'northwest') title ('Extreme value iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p, x p = [0, 0.05, 0.5 0.95]; x = [-Inf, -2.9702, -0.3665, 1.0972]; ***** assert_equal (evinv (p), x, 1e-4) ***** assert_equal (evinv (p, zeros (1,4), ones (1,4)), x, 1e-4) ***** assert_equal (evinv (p, 0, ones (1,4)), x, 1e-4) ***** assert_equal (evinv (p, zeros (1,4), 1), x, 1e-4) ***** assert_equal (evinv (p, [0, -Inf, NaN, Inf], 1), [-Inf, -Inf, NaN, Inf], 1e-4) ***** assert_equal (evinv (p, 0, [Inf, NaN, -1, 0]), [-Inf, NaN, NaN, NaN], 1e-4) ***** assert_equal (evinv ([p(1:2), NaN, p(4)], 0, 1), [x(1:2), NaN, x(4)], 1e-4) ***** assert_equal (evinv ([p, NaN], 0, 1), [x, NaN], 1e-4) ***** assert_equal (evinv (single ([p, NaN]), 0, 1), single ([x, NaN]), 1e-4) ***** assert_equal (evinv ([p, NaN], single (0), 1), single ([x, NaN]), 1e-4) ***** assert_equal (evinv ([p, NaN], 0, single (1)), single ([x, NaN]), 1e-4) ***** error evinv () ***** error evinv (1,2,3,4,5,6) ***** error ... evinv (ones (3), ones (2), ones (2)) ***** error ... [p, plo, pup] = evinv (2, 3, 4, [1, 2]) ***** error ... [p, plo, pup] = evinv (1, 2, 3) ***** error [p, plo, pup] = ... evinv (1, 2, 3, [1, 0; 0, 1], 0) ***** error [p, plo, pup] = ... evinv (1, 2, 3, [1, 0; 0, 1], 1.22) ***** error evinv (int32 (2), 2, 2) ***** error evinv (true, 2, 2) ***** error evinv ('a', 2, 2) ***** error evinv (i, 2, 2) ***** error evinv (2, i, 2) ***** error evinv (2, 2, i) ***** error ... [p, plo, pup] = evinv (1, 2, 3, [-1, -10; -Inf, -Inf], 0.04) 25 tests, 25 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/burrpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/burrpdf.m ***** demo ## Plot various PDFs from the Burr type XII distribution x = 0.001:0.001:3; y1 = burrpdf (x, 1, 1, 1); y2 = burrpdf (x, 1, 1, 2); y3 = burrpdf (x, 1, 1, 3); y4 = burrpdf (x, 1, 2, 1); y5 = burrpdf (x, 1, 3, 1); y6 = burrpdf (x, 1, 0.5, 2); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', ... x, y4, '-c', x, y5, '-m', x, y6, '-k') grid on ylim ([0, 2]) legend ({'λ = 1, c = 1, k = 1', 'λ = 1, c = 1, k = 2', ... 'λ = 1, c = 1, k = 3', 'λ = 1, c = 2, k = 1', ... 'λ = 1, c = 3, k = 1', 'λ = 1, c = 0.5, k = 2'}, ... 'location', 'northeast') title ('Burr type XII PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y x = [-1, 0, 1, 2, Inf]; y = [0, 1, 1/4, 1/9, 0]; ***** assert_equal (burrpdf (x, ones (1,5), ones (1,5), ones (1,5)), y) ***** assert_equal (burrpdf (x, 1, 1, 1), y) ***** assert_equal (burrpdf (x, [1, 1, NaN, 1, 1], 1, 1), [y(1:2), NaN, y(4:5)]) ***** assert_equal (burrpdf (x, 1, [1, 1, NaN, 1, 1], 1), [y(1:2), NaN, y(4:5)]) ***** assert_equal (burrpdf (x, 1, 1, [1, 1, NaN, 1, 1]), [y(1:2), NaN, y(4:5)]) ***** assert_equal (burrpdf ([x, NaN], 1, 1, 1), [y, NaN]) ***** assert_equal (burrpdf (single ([x, NaN]), 1, 1, 1), single ([y, NaN])) ***** assert_equal (burrpdf ([x, NaN], single (1), 1, 1), single ([y, NaN])) ***** assert_equal (burrpdf ([x, NaN], 1, single (1), 1), single ([y, NaN])) ***** assert_equal (burrpdf ([x, NaN], 1, 1, single (1)), single ([y, NaN])) ***** error burrpdf () ***** error burrpdf (1) ***** error burrpdf (1, 2) ***** error burrpdf (1, 2, 3) ***** error ... burrpdf (1, 2, 3, 4, 5) ***** error ... burrpdf (ones (3), ones (2), ones (2), ones (2)) ***** error ... burrpdf (ones (2), ones (3), ones (2), ones (2)) ***** error ... burrpdf (ones (2), ones (2), ones (3), ones (2)) ***** error ... burrpdf (ones (2), ones (2), ones (2), ones (3)) ***** error burrpdf (int32 (2), 2, 3, 4) ***** error burrpdf (true, 2, 3, 4) ***** error burrpdf ('a', 2, 3, 4) ***** error burrpdf (i, 2, 3, 4) ***** error burrpdf (1, i, 3, 4) ***** error burrpdf (1, 2, i, 4) ***** error burrpdf (1, 2, 3, i) 26 tests, 26 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/bisainv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/bisainv.m ***** demo ## Plot various iCDFs from the Birnbaum-Saunders distribution p = 0.001:0.001:0.999; x1 = bisainv (p, 1, 0.5); x2 = bisainv (p, 1, 1); x3 = bisainv (p, 1, 2); x4 = bisainv (p, 1, 5); x5 = bisainv (p, 1, 10); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', p, x4, '-c', p, x5, '-m') grid on ylim ([0, 10]) legend ({'β = 1, γ = 0.5', 'β = 1, γ = 1', 'β = 1, γ = 2', ... 'β = 1, γ = 5', 'β = 1, γ = 10'}, 'location', 'northwest') title ('Birnbaum-Saunders iCDF') xlabel ('probability') ylabel ('values in x') ***** demo ## Plot various iCDFs from the Birnbaum-Saunders distribution p = 0.001:0.001:0.999; x1 = bisainv (p, 1, 0.3); x2 = bisainv (p, 2, 0.3); x3 = bisainv (p, 1, 0.5); x4 = bisainv (p, 3, 0.5); x5 = bisainv (p, 5, 0.5); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', p, x4, '-c', p, x5, '-m') grid on ylim ([0, 10]) legend ({'β = 1, γ = 0.3', 'β = 2, γ = 0.3', 'β = 1, γ = 0.5', ... 'β = 3, γ = 0.5', 'β = 5, γ = 0.5'}, 'location', 'northwest') title ('Birnbaum-Saunders iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p, y, f f = @(p,b,c) (b * (c * norminv (p) + sqrt (4 + (c * norminv (p))^2))^2) / 4; p = [-1, 0, 1/4, 1/2, 1, 2]; y = [NaN, 0, f(1/4, 1, 1), 1, Inf, NaN]; ***** assert_equal (bisainv (p, ones (1,6), ones (1,6)), y) ***** assert_equal (bisainv (p, 1, ones (1,6)), y) ***** assert_equal (bisainv (p, ones (1,6), 1), y) ***** assert_equal (bisainv (p, 1, 1), y) ***** assert_equal (bisainv (p, 1, [1, 1, 1, NaN, 1, 1]), [y(1:3), NaN, y(5:6)]) ***** assert_equal (bisainv (p, [1, 1, 1, NaN, 1, 1], 1), [y(1:3), NaN, y(5:6)]) ***** assert_equal (bisainv ([p, NaN], 1, 1), [y, NaN]) ***** assert_equal (bisainv (single ([p, NaN]), 1, 1), single ([y, NaN]), eps ('single')) ***** assert_equal (bisainv ([p, NaN], 1, single (1)), single ([y, NaN]), eps ('single')) ***** assert_equal (bisainv ([p, NaN], single (1), 1), single ([y, NaN]), eps ('single')) ***** error bisainv () ***** error bisainv (1) ***** error bisainv (1, 2) ***** error bisainv (1, 2, 3, 4) ***** error ... bisainv (ones (3), ones (2), ones (2)) ***** error ... bisainv (ones (2), ones (3), ones (2)) ***** error ... bisainv (ones (2), ones (2), ones (3)) ***** error bisainv (int32 (2), 4, 3) ***** error bisainv (true, 4, 3) ***** error bisainv ('a', 4, 3) ***** error bisainv (i, 4, 3) ***** error bisainv (1, i, 3) ***** error bisainv (1, 4, i) 23 tests, 23 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/hygepdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/hygepdf.m ***** demo ## Plot various PDFs from the hypergeometric distribution x = 0:60; y1 = hygepdf (x, 500, 50, 100); y2 = hygepdf (x, 500, 60, 200); y3 = hygepdf (x, 500, 70, 300); plot (x, y1, '*b', x, y2, '*g', x, y3, '*r') grid on xlim ([0, 60]) ylim ([0, 0.18]) legend ({'m = 500, k = 50, μ = 100', 'm = 500, k = 60, μ = 200', ... 'm = 500, k = 70, μ = 300'}, 'location', 'northeast') title ('Hypergeometric PDF') xlabel ('values in x (number of successes)') ylabel ('density') ***** shared x, y x = [-1 0 1 2 3]; y = [0 1/6 4/6 1/6 0]; ***** assert_equal (hygepdf (x, 4 * ones (1, 5), 2, 2), y, 3 * eps) ***** assert_equal (hygepdf (x, 4, 2 * ones (1, 5), 2), y, 3 * eps) ***** assert_equal (hygepdf (x, 4, 2, 2 * ones (1, 5)), y, 3 * eps) ***** assert_equal (hygepdf (x, 4 * [1, -1, NaN, 1.1, 1], 2, 2), [0, NaN, NaN, NaN, 0]) ***** assert_equal (hygepdf (x, 4, 2 * [1, -1, NaN, 1.1, 1], 2), [0, NaN, NaN, NaN, 0]) ***** assert_equal (hygepdf (x, 4, 5, 2), [NaN, NaN, NaN, NaN, NaN], 3 * eps) ***** assert_equal (hygepdf (x, 4, 2, 2 * [1, -1, NaN, 1.1, 1]), [0, NaN, NaN, NaN, 0]) ***** assert_equal (hygepdf (x, 4, 2, 5), [NaN, NaN, NaN, NaN, NaN], 3 * eps) ***** assert_equal (hygepdf ([x, NaN], 4, 2, 2), [y, NaN], 3 * eps) ***** assert_equal (hygepdf (single ([x, NaN]), 4, 2, 2), single ([y, NaN]), eps ('single')) ***** assert_equal (hygepdf ([x, NaN], single (4), 2, 2), single ([y, NaN]), eps ('single')) ***** assert_equal (hygepdf ([x, NaN], 4, single (2), 2), single ([y, NaN]), eps ('single')) ***** assert_equal (hygepdf ([x, NaN], 4, 2, single (2)), single ([y, NaN]), eps ('single')) ***** test z = zeros (3,5); z([4,5,6,8,9,12]) = [1, 0.5, 1/6, 0.5, 2/3, 1/6]; assert_equal (hygepdf (x, 4, [0, 1, 2], 2, 'vectorexpand'), z, 3 * eps); assert_equal (hygepdf (x, 4, [0, 1, 2]', 2, 'vectorexpand'), z, 3 * eps); assert_equal (hygepdf (x', 4, [0, 1, 2], 2, 'vectorexpand'), z, 3 * eps); assert_equal (hygepdf (2, 4, [0 ,1, 2], 2, 'vectorexpand'), z(:,4), 3 * eps); assert_equal (hygepdf (x, 4, 1, 2, 'vectorexpand'), z(2,:), 3 *eps); assert_equal (hygepdf ([NaN, x], 4, [0 1 2]', 2, 'vectorexpand'), [NaN(3, 1), z], 3 * eps); ***** error hygepdf () ***** error hygepdf (1) ***** error hygepdf (1,2) ***** error hygepdf (1,2,3) ***** error ... hygepdf (1, ones (3), ones (2), ones (2)) ***** error ... hygepdf (1, ones (2), ones (3), ones (2)) ***** error ... hygepdf (1, ones (2), ones (2), ones (3)) ***** error hygepdf (true, 2, 2, 2) ***** error hygepdf ('a', 2, 2, 2) ***** assert_equal (class (hygepdf (int32 (2), 2, 2, 2)), 'double') ***** error hygepdf (i, 2, 2, 2) ***** error hygepdf (2, i, 2, 2) ***** error hygepdf (2, 2, i, 2) ***** error hygepdf (2, 2, 2, i) 28 tests, 28 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/geocdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/geocdf.m ***** demo ## Plot various CDFs from the geometric distribution x = 0:10; p1 = geocdf (x, 0.2); p2 = geocdf (x, 0.5); p3 = geocdf (x, 0.7); plot (x, p1, '*b', x, p2, '*g', x, p3, '*r') grid on xlim ([0, 10]) legend ({'ps = 0.2', 'ps = 0.5', 'ps = 0.7'}, 'location', 'southeast') title ('Geometric CDF') xlabel ('values in x (number of failures)') ylabel ('probability') ***** test p = geocdf ([1, 2, 3, 4], 0.25); assert_equal (p(1), 0.4375000000, 1e-14); assert_equal (p(2), 0.5781250000, 1e-14); assert_equal (p(3), 0.6835937500, 1e-14); assert_equal (p(4), 0.7626953125, 1e-14); ***** test p = geocdf ([1, 2, 3, 4], 0.25, 'upper'); assert_equal (p(1), 0.5625000000, 1e-14); assert_equal (p(2), 0.4218750000, 1e-14); assert_equal (p(3), 0.3164062500, 1e-14); assert_equal (p(4), 0.2373046875, 1e-14); ***** shared x, p x = [-1 0 1 Inf]; p = [0 0.5 0.75 1]; ***** assert_equal (geocdf (x, 0.5*ones (1,4)), p) ***** assert_equal (geocdf (x, 0.5), p) ***** assert_equal (geocdf (x, 0.5*[-1 NaN 4 1]), [NaN NaN NaN p(4)]) ***** assert_equal (geocdf ([x(1:2) NaN x(4)], 0.5), [p(1:2) NaN p(4)]) ***** assert_equal (geocdf ([x, NaN], 0.5), [p, NaN]) ***** assert_equal (geocdf (single ([x, NaN]), 0.5), single ([p, NaN])) ***** assert_equal (geocdf ([x, NaN], single (0.5)), single ([p, NaN])) ***** error geocdf () ***** error geocdf (1) ***** error ... geocdf (ones (3), ones (2)) ***** error ... geocdf (ones (2), ones (3)) ***** error geocdf (true, 2) ***** error geocdf ('a', 2) ***** assert_equal (class (geocdf (int32 (2), 2)), 'double') ***** error geocdf (i, 2) ***** error geocdf (2, i) ***** error geocdf (2, 3, 'tail') ***** error geocdf (2, 3, 5) 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/norminv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/norminv.m ***** demo ## Plot various iCDFs from the normal distribution p = 0.001:0.001:0.999; x1 = norminv (p, 0, 0.5); x2 = norminv (p, 0, 1); x3 = norminv (p, 0, 2); x4 = norminv (p, -2, 0.8); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', p, x4, '-c') grid on ylim ([-5, 5]) legend ({'μ = 0, σ = 0.5', 'μ = 0, σ = 1', ... 'μ = 0, σ = 2', 'μ = -2, σ = 0.8'}, 'location', 'northwest') title ('Normal iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p p = [-1 0 0.5 1 2]; ***** assert_equal (norminv (p, ones (1,5), ones (1,5)), [NaN -Inf 1 Inf NaN]) ***** assert_equal (norminv (p, 1, ones (1,5)), [NaN -Inf 1 Inf NaN]) ***** assert_equal (norminv (p, ones (1,5), 1), [NaN -Inf 1 Inf NaN]) ***** assert_equal (norminv (p, [1 -Inf NaN Inf 1], 1), [NaN NaN NaN NaN NaN]) ***** assert_equal (norminv (p, 1, [1 0 NaN Inf 1]), [NaN NaN NaN NaN NaN]) ***** assert_equal (norminv ([p(1:2) NaN p(4:5)], 1, 1), [NaN -Inf NaN Inf NaN]) ***** assert_equal (norminv (p), probit (p)) ***** assert_equal (norminv (0.31254), probit (0.31254)) ***** assert_equal (norminv ([p, NaN], 1, 1), [NaN -Inf 1 Inf NaN NaN]) ***** assert_equal (norminv (single ([p, NaN]), 1, 1), single ([NaN -Inf 1 Inf NaN NaN])) ***** assert_equal (norminv ([p, NaN], single (1), 1), single ([NaN -Inf 1 Inf NaN NaN])) ***** assert_equal (norminv ([p, NaN], 1, single (1)), single ([NaN -Inf 1 Inf NaN NaN])) ***** error norminv () ***** error ... norminv (ones (3), ones (2), ones (2)) ***** error ... norminv (ones (2), ones (3), ones (2)) ***** error ... norminv (ones (2), ones (2), ones (3)) ***** error norminv (int32 (2), 2, 2) ***** error norminv (true, 2, 2) ***** error norminv ('a', 2, 2) ***** error norminv (i, 2, 2) ***** error norminv (2, i, 2) ***** error norminv (2, 2, i) 22 tests, 22 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/iwishpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/iwishpdf.m ***** assert_equal (iwishpdf (4, 3, 3.1), 0.04226595, 1E-7); ***** assert_equal (iwishpdf ([2 -0.3;-0.3 4], [1 0.3;0.3 1], 4), 1.60166e-05, 1E-10); ***** assert_equal (iwishpdf ([6 2 5; 2 10 -5; 5 -5 25], ... [9 5 5; 5 10 -8; 5 -8 22], 5.1), 4.946831e-12, 1E-17); ***** error iwishpdf (int32 (eye (2)), eye (2), 3) ***** error iwishpdf (true (2), eye (2), 3) ***** error iwishpdf (['ab'; 'cd'], eye (2), 3) ***** error iwishpdf () ***** error iwishpdf (1, 2) ***** error iwishpdf (1, 2, 0) 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/riceinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/riceinv.m ***** demo ## Plot various iCDFs from the Rician distribution p = 0.001:0.001:0.999; x1 = riceinv (p, 0, 1); x2 = riceinv (p, 0.5, 1); x3 = riceinv (p, 1, 1); x4 = riceinv (p, 2, 1); x5 = riceinv (p, 4, 1); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', p, x4, '-m', p, x5, '-k') grid on legend ({'s = 0, σ = 1', 's = 0.5, σ = 1', 's = 1, σ = 1', ... 's = 2, σ = 1', 's = 4, σ = 1'}, 'location', 'northwest') title ('Rician iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p p = [-1 0 0.75 1 2]; ***** assert_equal (riceinv (p, ones (1,5), 2*ones (1,5)), [NaN 0 3.5354 Inf NaN], 1e-4) ***** assert_equal (riceinv (p, 1, 2*ones (1,5)), [NaN 0 3.5354 Inf NaN], 1e-4) ***** assert_equal (riceinv (p, ones (1,5), 2), [NaN 0 3.5354 Inf NaN], 1e-4) ***** assert_equal (riceinv (p, [1 0 NaN 1 1], 2), [NaN 0 NaN Inf NaN]) ***** assert_equal (riceinv (p, 1, 2*[1 0 NaN 1 1]), [NaN NaN NaN Inf NaN]) ***** assert_equal (riceinv ([p(1:2) NaN p(4:5)], 1, 2), [NaN 0 NaN Inf NaN]) ***** assert_equal (riceinv ([p, NaN], 1, 2), [NaN 0 3.5354 Inf NaN NaN], 1e-4) ***** assert_equal (riceinv (single ([p, NaN]), 1, 2), ... single ([NaN 0 3.5354 Inf NaN NaN]), 1e-4) ***** assert_equal (riceinv ([p, NaN], single (1), 2), ... single ([NaN 0 3.5354 Inf NaN NaN]), 1e-4) ***** assert_equal (riceinv ([p, NaN], 1, single (2)), ... single ([NaN 0 3.5354 Inf NaN NaN]), 1e-4) ***** error riceinv () ***** error riceinv (1) ***** error riceinv (1,2) ***** error riceinv (1,2,3,4) ***** error ... riceinv (ones (3), ones (2), ones (2)) ***** error ... riceinv (ones (2), ones (3), ones (2)) ***** error ... riceinv (ones (2), ones (2), ones (3)) ***** error riceinv (int32 (2), 2, 2) ***** error riceinv (true, 2, 2) ***** error riceinv ('a', 2, 2) ***** error riceinv (i, 2, 2) ***** error riceinv (2, i, 2) ***** error riceinv (2, 2, i) 23 tests, 23 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/hnpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/hnpdf.m ***** demo ## Plot various PDFs from the half-normal distribution x = 0:0.001:10; y1 = hnpdf (x, 0, 1); y2 = hnpdf (x, 0, 2); y3 = hnpdf (x, 0, 3); y4 = hnpdf (x, 0, 5); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', x, y4, '-c') grid on xlim ([0, 10]) ylim ([0, 0.9]) legend ({'μ = 0, σ = 1', 'μ = 0, σ = 2', ... 'μ = 0, σ = 3', 'μ = 0, σ = 5'}, 'location', 'northeast') title ('Half-normal PDF') xlabel ('values in x') ylabel ('density') ***** demo ## Plot half-normal against normal probability density function x = -5:0.001:5; y1 = hnpdf (x, 0, 1); y2 = normpdf (x); plot (x, y1, '-b', x, y2, '-g') grid on xlim ([-5, 5]) ylim ([0, 0.9]) legend ({'half-normal with μ = 0, σ = 1', ... 'standard normal (μ = 0, σ = 1)'}, 'location', 'northeast') title ('Half-normal against standard normal PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y x = [-Inf, -1, 0, 1/2, 1, Inf]; y = [0, 0, 0.7979, 0.7041, 0.4839, 0]; ***** assert_equal (hnpdf ([x, NaN], 0, 1), [y, NaN], 1e-4) ***** assert_equal (hnpdf (x, 0, [-2, -1, 0, 1, 1, 1]), [nan(1,3), y([4:6])], 1e-4) ***** assert_equal (class (hncdf (single ([x, NaN]), 0, 1)), "single") ***** assert_equal (class (hncdf ([x, NaN], 0, single (1))), "single") ***** assert_equal (class (hncdf ([x, NaN], single (0), 1)), "single") ***** error hnpdf () ***** error hnpdf (1) ***** error hnpdf (1, 2) ***** error ... hnpdf (1, ones (2), ones (3)) ***** error ... hnpdf (ones (2), 1, ones (3)) ***** error ... hnpdf (ones (2), ones (3), 1) ***** error hnpdf (int32 (2), 2, 3) ***** error hnpdf (true, 2, 3) ***** error hnpdf ('a', 2, 3) ***** error hnpdf (i, 2, 3) ***** error hnpdf (1, i, 3) ***** error hnpdf (1, 2, i) 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/burrrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/burrrnd.m ***** assert_equal (size (burrrnd (1, 1, 1)), [1 1]) ***** assert_equal (size (burrrnd (ones (2,1), 1, 1)), [2, 1]) ***** assert_equal (size (burrrnd (ones (2,2), 1, 1)), [2, 2]) ***** assert_equal (size (burrrnd (1, ones (2,1), 1)), [2, 1]) ***** assert_equal (size (burrrnd (1, ones (2,2), 1)), [2, 2]) ***** assert_equal (size (burrrnd (1, 1, ones (2,1))), [2, 1]) ***** assert_equal (size (burrrnd (1, 1, ones (2,2))), [2, 2]) ***** assert_equal (size (burrrnd (1, 1, 1, 3)), [3, 3]) ***** assert_equal (size (burrrnd (1, 1, 1, [4 1])), [4, 1]) ***** assert_equal (size (burrrnd (1, 1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (burrrnd (1, 1, 1, [])), [0, 0]) ***** assert_equal (size (burrrnd (1, 1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (burrrnd (1, 2, 3, -1)), [0, 0]) ***** assert_equal (size (burrrnd (1, 2, 3, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (burrrnd (1, 2, 3, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (burrrnd (1,1,1)), "double") ***** assert_equal (class (burrrnd (single (1),1,1)), "single") ***** assert_equal (class (burrrnd (single ([1 1]),1,1)), "single") ***** assert_equal (class (burrrnd (1,single (1),1)), "single") ***** assert_equal (class (burrrnd (1,single ([1 1]),1)), "single") ***** assert_equal (class (burrrnd (1,1,single (1))), "single") ***** assert_equal (class (burrrnd (1,1,single ([1 1]))), "single") ***** error burrrnd () ***** error burrrnd (1) ***** error burrrnd (1, 2) ***** error ... burrrnd (ones (3), ones (2), ones (2)) ***** error ... burrrnd (ones (2), ones (3), ones (2)) ***** error ... burrrnd (ones (2), ones (2), ones (3)) ***** error burrrnd (i, 2, 3) ***** error burrrnd (1, i, 3) ***** error burrrnd (1, 2, i) ***** error ... burrrnd (1, 2, 3, 1.2) ***** error ... burrrnd (1, 2, 3, ones (2)) ***** error ... burrrnd (1, 2, 3, [2 0 2.5]) ***** error ... burrrnd (1, 2, 3, 2, 1.5, 5) ***** error ... burrrnd (2, ones (2), 2, 3) ***** error ... burrrnd (2, ones (2), 2, [3, 2]) ***** error ... burrrnd (2, ones (2), 2, 3, 2) 38 tests, 38 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/tlsinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/tlsinv.m ***** demo ## Plot various iCDFs from the location-scale Student's T distribution p = 0.001:0.001:0.999; x1 = tlsinv (p, 0, 1, 1); x2 = tlsinv (p, 0, 2, 2); x3 = tlsinv (p, 3, 2, 5); x4 = tlsinv (p, -1, 3, Inf); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', p, x4, '-m') grid on xlim ([0, 1]) ylim ([-8, 8]) legend ({'mu = 0, sigma = 1, nu = 1', 'mu = 0, sigma = 2, nu = 2', ... 'mu = 3, sigma = 2, nu = 5', 'mu = -1, sigma = 3, nu = \infty'}, ... 'location', 'southeast') title ('Location-scale Student''s T iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p p = [-1 0 0.5 1 2]; ***** assert_equal (tlsinv (p, 0, 1, ones (1,5)), [NaN -Inf 0 Inf NaN]) ***** assert_equal (tlsinv (p, 0, 1, 1), [NaN -Inf 0 Inf NaN], eps) ***** assert_equal (tlsinv (p, 0, 1, [1 0 NaN 1 1]), [NaN NaN NaN Inf NaN], eps) ***** assert_equal (tlsinv ([p(1:2) NaN p(4:5)], 0, 1, 1), [NaN -Inf NaN Inf NaN]) ***** assert_equal (class (tlsinv ([p, NaN], 0, 1, 1)), "double") ***** assert_equal (class (tlsinv (single ([p, NaN]), 0, 1, 1)), "single") ***** assert_equal (class (tlsinv ([p, NaN], single (0), 1, 1)), "single") ***** assert_equal (class (tlsinv ([p, NaN], 0, single (1), 1)), "single") ***** assert_equal (class (tlsinv ([p, NaN], 0, 1, single (1))), "single") ***** error tlsinv () ***** error tlsinv (1) ***** error tlsinv (1, 2) ***** error tlsinv (1, 2, 3) ***** error ... tlsinv (ones (3), ones (2), 1, 1) ***** error ... tlsinv (ones (2), 1, ones (3), 1) ***** error ... tlsinv (ones (2), 1, 1, ones (3)) ***** error tlsinv (int32 (2), 2, 3, 4) ***** error tlsinv (true, 2, 3, 4) ***** error tlsinv ('a', 2, 3, 4) ***** error tlsinv (i, 2, 3, 4) ***** error tlsinv (2, i, 3, 4) ***** error tlsinv (2, 2, i, 4) ***** error tlsinv (2, 2, 3, i) 23 tests, 23 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/stdrrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/stdrrnd.m ***** demo ## Compare random samples with the density they are drawn from rng (42); r = stdrrnd (4, 10, 1, 10000); x = 0:0.05:10; hist (r, x, 1 / 0.05) hold on plot (x, stdrpdf (x, 4, 10), '-r', 'linewidth', 2) hold off xlim ([0, 10]) legend ({'10000 samples', 'k = 4, df = 10'}, 'location', 'northeast') title ('Studentized range random samples') xlabel ('values in r') ylabel ('density') ***** assert_equal (size (stdrrnd (3, 10)), [1, 1]) ***** assert_equal (size (stdrrnd (3 * ones (2, 1), 10)), [2, 1]) ***** assert_equal (size (stdrrnd (3, 10 * ones (2, 2))), [2, 2]) ***** assert_equal (size (stdrrnd (3, 10, 3)), [3, 3]) ***** assert_equal (size (stdrrnd (3, 10, [4, 1])), [4, 1]) ***** assert_equal (size (stdrrnd (3, 10, 4, 1)), [4, 1]) ***** assert_equal (size (stdrrnd (3, 10, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (stdrrnd (3, 10, 0, 1)), [0, 1]) ***** assert_equal (size (stdrrnd (3, 10, [])), [0, 0]) ***** assert_equal (size (stdrrnd (3, 10, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (stdrrnd ([1, 2.5, NaN], 10), [NaN, NaN, NaN]) ***** assert_equal (stdrrnd (3, [0, -1, NaN]), [NaN, NaN, NaN]) ***** assert_equal (all (stdrrnd (3, Inf, 1, 100) > 0), true) ***** assert_equal (class (stdrrnd (3, 10)), 'double') ***** assert_equal (class (stdrrnd (single (3), 10)), 'single') ***** assert_equal (class (stdrrnd (3, single ([10, 10]))), 'single') ***** error stdrrnd () ***** error stdrrnd (3) ***** error ... stdrrnd (ones (3), ones (2)) ***** error stdrrnd (i, 10) ***** error stdrrnd (3, i) ***** error ... stdrrnd (3, 10, 1.2) ***** error ... stdrrnd (3, 10, ones (2)) ***** error stdrrnd (3, 10, 2, 1.5) ***** error ... stdrrnd (3 * ones (2), 10, 3) 25 tests, 25 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/lognrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/lognrnd.m ***** assert_equal (size (lognrnd (1, 1)), [1, 1]) ***** assert_equal (size (lognrnd (1, ones (2, 1))), [2, 1]) ***** assert_equal (size (lognrnd (1, ones (2, 2))), [2, 2]) ***** assert_equal (size (lognrnd (ones (2, 1), 1)), [2, 1]) ***** assert_equal (size (lognrnd (ones (2, 2), 1)), [2, 2]) ***** assert_equal (size (lognrnd (1, 1, 3)), [3, 3]) ***** assert_equal (size (lognrnd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (lognrnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (lognrnd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (lognrnd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (lognrnd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (lognrnd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (lognrnd (1, 1, [])), [0, 0]) ***** assert_equal (size (lognrnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (lognrnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (lognrnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (lognrnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (lognrnd (1, 1)), "double") ***** assert_equal (class (lognrnd (1, single (1))), "single") ***** assert_equal (class (lognrnd (1, single ([1, 1]))), "single") ***** assert_equal (class (lognrnd (single (1), 1)), "single") ***** assert_equal (class (lognrnd (single ([1, 1]), 1)), "single") ***** error lognrnd () ***** error lognrnd (1) ***** error ... lognrnd (ones (3), ones (2)) ***** error ... lognrnd (ones (2), ones (3)) ***** error lognrnd (i, 2, 3) ***** error lognrnd (1, i, 3) ***** error ... lognrnd (1, 2, 1.2) ***** error ... lognrnd (1, 2, ones (2)) ***** error ... lognrnd (1, 2, [2 0 2.5]) ***** error ... lognrnd (1, 2, 2, 1.5, 5) ***** error ... lognrnd (2, ones (2), 3) ***** error ... lognrnd (2, ones (2), [3, 2]) ***** error ... lognrnd (2, ones (2), 3, 2) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/nctrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/nctrnd.m ***** assert_equal (size (nctrnd (1, 1)), [1, 1]) ***** assert_equal (size (nctrnd (1, ones (2, 1))), [2, 1]) ***** assert_equal (size (nctrnd (1, ones (2, 2))), [2, 2]) ***** assert_equal (size (nctrnd (ones (2, 1), 1)), [2, 1]) ***** assert_equal (size (nctrnd (ones (2, 2), 1)), [2, 2]) ***** assert_equal (size (nctrnd (1, 1, 3)), [3, 3]) ***** assert_equal (size (nctrnd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (nctrnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (nctrnd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (nctrnd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (nctrnd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (nctrnd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (nctrnd (1, 1, [])), [0, 0]) ***** assert_equal (size (nctrnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (nctrnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (nctrnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (nctrnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (nctrnd (1, 1)), "double") ***** assert_equal (class (nctrnd (1, single (1))), "single") ***** assert_equal (class (nctrnd (1, single ([1, 1]))), "single") ***** assert_equal (class (nctrnd (single (1), 1)), "single") ***** assert_equal (class (nctrnd (single ([1, 1]), 1)), "single") ***** error nctrnd () ***** error nctrnd (1) ***** error ... nctrnd (ones (3), ones (2)) ***** error ... nctrnd (ones (2), ones (3)) ***** error nctrnd (i, 2) ***** error nctrnd (1, i) ***** error ... nctrnd (1, 2, 1.2) ***** error ... nctrnd (1, 2, ones (2)) ***** error ... nctrnd (1, 2, [2 0 2.5]) ***** error ... nctrnd (1, 2, 2, 1.5, 5) ***** error ... nctrnd (2, ones (2), 3) ***** error ... nctrnd (2, ones (2), [3, 2]) ***** error ... nctrnd (2, ones (2), 3, 2) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/stdrcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/stdrcdf.m ***** demo ## Plot various CDFs from the studentized range distribution x = 0:0.01:8; p1 = stdrcdf (x, 2, 5); p2 = stdrcdf (x, 3, 5); p3 = stdrcdf (x, 5, 5); p4 = stdrcdf (x, 5, Inf); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', x, p4, '-m') grid on ylim ([0, 1]) legend ({'k = 2, df = 5', 'k = 3, df = 5', 'k = 5, df = 5', ... 'k = 5, df = \infty'}, 'location', 'southeast') title ('Studentized range CDF') xlabel ('values in x') ylabel ('probability') ***** shared x x = [0.5, 2, 4, 8]; ***** assert_equal (stdrcdf (x, 2, 5), 1 - 2 * tcdf (-x / sqrt (2), 5), -1e-13) ***** assert_equal (stdrcdf (x, 2, 5, 'upper'), 2 * tcdf (-x / sqrt (2), 5), -1e-13) ***** assert_equal (stdrcdf (x, 2, Inf), erf (x / 2), -1e-13) ***** assert_equal (stdrcdf (x, 2, Inf, 'upper'), erfc (x / 2), -1e-13) ***** assert_equal (stdrcdf ([x, 900], 2, 1, 'upper'), ... 2 * tcdf (-[x, 900] / sqrt (2), 1), -1e-13) ***** assert_equal (stdrcdf (20, 2, 30, 'upper'), ... betainc (200 / 230, 1/2, 15, 'upper'), -1e-12) ***** assert_equal (stdrcdf ([2, 4, 8], 3, 10, 'upper'), ... [0.37054467503555799, 0.043349349760161804, ... 0.00055885879221251322], -1e-5) ***** assert_equal (stdrcdf ([2, 4, 8], 10, 30, 'upper'), ... [0.91315280898350459, 0.17214641499562477, ... 0.00013979917001072373], -1e-5) ***** assert_equal (stdrcdf ([2, 4, 8], 20, Inf, 'upper'), ... [0.9976642515512063, 0.3360234394147692, ... 2.8901613927656555e-06], -1e-5) ***** assert_equal (stdrcdf ([0.5, 1, 1.5], 3, 10, 'upper'), ... [0.93386416513356696, 0.76489080347916205, ... 0.55804816568706039], -1e-3) ***** assert_equal (stdrcdf ([0.5, 1.5, 3, 5], 5, 30, 'upper'), ... [0.99646380721257077, 0.82481287273578452, ... 0.23767360358955125, 0.010890009004856521], -1e-3) ***** assert_equal (stdrcdf ([-1, 0, Inf, NaN], 3, 10), [0, 0, 1, NaN]) ***** assert_equal (stdrcdf ([-1, 0, Inf, NaN], 3, 10, 'upper'), [1, 1, 0, NaN]) ***** assert_equal (stdrcdf (2, [1, 2.5, NaN, Inf], 10), NaN (1, 4)) ***** assert_equal (stdrcdf (2, 3, [0, -1, NaN]), NaN (1, 3)) ***** assert_equal (class (stdrcdf (single (2), 3, 10)), 'single') ***** assert_equal (class (stdrcdf (2, single (3), 10)), 'single') ***** assert_equal (class (stdrcdf (2, 3, single (10))), 'single') ***** error stdrcdf () ***** error stdrcdf (1, 2) ***** error stdrcdf (1, 2, 3, 'uper') ***** error stdrcdf (1, 2, 3, 4) ***** error ... stdrcdf (ones (3), ones (2), 3) ***** error ... stdrcdf (int32 (2), 3, 10) ***** error ... stdrcdf (true, 3, 10) ***** error ... stdrcdf ('a', 3, 10) ***** error stdrcdf (i, 3, 10) ***** error stdrcdf (2, i, 10) ***** error stdrcdf (2, 3, i) 29 tests, 29 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/logncdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/logncdf.m ***** demo ## Plot various CDFs from the log-normal distribution x = 0:0.01:3; p1 = logncdf (x, 0, 1); p2 = logncdf (x, 0, 0.5); p3 = logncdf (x, 0, 0.25); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r') grid on legend ({'μ = 0, σ = 1', 'μ = 0, σ = 0.5', 'μ = 0, σ = 0.25'}, ... 'location', 'southeast') title ('Log-normal CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y x = [-1, 0, 1, e, Inf]; y = [0, 0, 0.5, 1/2+1/2*erf(1/2), 1]; ***** assert_equal (logncdf (x, zeros (1,5), sqrt (2)*ones (1,5)), y, eps) ***** assert_equal (logncdf (x, zeros (1,5), sqrt (2)*ones (1,5), []), y, eps) ***** assert_equal (logncdf (x, 0, sqrt (2)*ones (1,5)), y, eps) ***** assert_equal (logncdf (x, zeros (1,5), sqrt (2)), y, eps) ***** assert_equal (logncdf (x, [0 1 NaN 0 1], sqrt (2)), [0 0 NaN y(4:5)], eps) ***** assert_equal (logncdf (x, 0, sqrt (2)*[0 NaN Inf 1 1]), [NaN NaN y(3:5)], eps) ***** assert_equal (logncdf ([x(1:3) NaN x(5)], 0, sqrt (2)), [y(1:3) NaN y(5)], eps) ***** assert_equal (logncdf ([x, NaN], 0, sqrt (2)), [y, NaN], eps) ***** assert_equal (logncdf (single ([x, NaN]), 0, sqrt (2)), single ([y, NaN]), eps ('single')) ***** assert_equal (logncdf ([x, NaN], single (0), sqrt (2)), single ([y, NaN]), eps ('single')) ***** assert_equal (logncdf ([x, NaN], 0, single (sqrt (2))), single ([y, NaN]), eps ('single')) ***** error logncdf () ***** error logncdf (1,2,3,4,5,6,7) ***** error logncdf (1, 2, 3, 4, 'uper') ***** error ... logncdf (ones (3), ones (2), ones (2)) ***** error logncdf (2, 3, 4, [1, 2]) ***** error ... [p, plo, pup] = logncdf (1, 2, 3) ***** error [p, plo, pup] = ... logncdf (1, 2, 3, [1, 0; 0, 1], 0) ***** error [p, plo, pup] = ... logncdf (1, 2, 3, [1, 0; 0, 1], 1.22) ***** error [p, plo, pup] = ... logncdf (1, 2, 3, [1, 0; 0, 1], 'alpha', 'upper') ***** error logncdf (int32 (2), 2, 2) ***** error logncdf (true, 2, 2) ***** error logncdf ('a', 2, 2) ***** error logncdf (i, 2, 2) ***** error logncdf (2, i, 2) ***** error logncdf (2, 2, i) ***** error ... [p, plo, pup] =logncdf (1, 2, 3, [1, 0; 0, -inf], 0.04) 27 tests, 27 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/gumbelcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/gumbelcdf.m ***** demo ## Plot various CDFs from the Gumbel distribution x = -5:0.01:20; p1 = gumbelcdf (x, 0.5, 2); p2 = gumbelcdf (x, 1.0, 2); p3 = gumbelcdf (x, 1.5, 3); p4 = gumbelcdf (x, 3.0, 4); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', x, p4, '-c') grid on legend ({'μ = 0.5, β = 2', 'μ = 1.0, β = 2', ... 'μ = 1.5, β = 3', 'μ = 3.0, β = 4'}, 'location', 'southeast') title ('Gumbel CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y x = [-Inf, 1, 2, Inf]; y = [0, 0.3679, 0.6922, 1]; ***** assert_equal (gumbelcdf (x, ones (1,4), ones (1,4)), y, 1e-4) ***** assert_equal (gumbelcdf (x, 1, ones (1,4)), y, 1e-4) ***** assert_equal (gumbelcdf (x, ones (1,4), 1), y, 1e-4) ***** assert_equal (gumbelcdf (x, [0, -Inf, NaN, Inf], 1), [0, 1, NaN, NaN], 1e-4) ***** assert_equal (gumbelcdf (x, 1, [Inf, NaN, -1, 0]), [NaN, NaN, NaN, NaN], 1e-4) ***** assert_equal (gumbelcdf ([x(1:2), NaN, x(4)], 1, 1), [y(1:2), NaN, y(4)], 1e-4) ***** assert_equal (gumbelcdf (x, 'upper'), [1, 0.3078, 0.1266, 0], 1e-4) ***** assert_equal (gumbelcdf ([x, NaN], 1, 1), [y, NaN], 1e-4) ***** assert_equal (gumbelcdf (single ([x, NaN]), 1, 1), single ([y, NaN]), 1e-4) ***** assert_equal (gumbelcdf ([x, NaN], single (1), 1), single ([y, NaN]), 1e-4) ***** assert_equal (gumbelcdf ([x, NaN], 1, single (1)), single ([y, NaN]), 1e-4) ***** error gumbelcdf () ***** error gumbelcdf (1,2,3,4,5,6,7) ***** error gumbelcdf (1, 2, 3, 4, 'uper') ***** error ... gumbelcdf (ones (3), ones (2), ones (2)) ***** error gumbelcdf (2, 3, 4, [1, 2]) ***** error ... [p, plo, pup] = gumbelcdf (1, 2, 3) ***** error [p, plo, pup] = ... gumbelcdf (1, 2, 3, [1, 0; 0, 1], 0) ***** error [p, plo, pup] = ... gumbelcdf (1, 2, 3, [1, 0; 0, 1], 1.22) ***** error [p, plo, pup] = ... gumbelcdf (1, 2, 3, [1, 0; 0, 1], 'alpha', 'upper') ***** error gumbelcdf (int32 (2), 2, 2) ***** error gumbelcdf (true, 2, 2) ***** error gumbelcdf ('a', 2, 2) ***** error gumbelcdf (i, 2, 2) ***** error gumbelcdf (2, i, 2) ***** error gumbelcdf (2, 2, i) ***** error ... [p, plo, pup] = gumbelcdf (1, 2, 3, [1, 0; 0, -inf], 0.04) 27 tests, 27 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/poisspdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/poisspdf.m ***** demo ## Plot various PDFs from the Poisson distribution x = 0:20; y1 = poisspdf (x, 1); y2 = poisspdf (x, 4); y3 = poisspdf (x, 10); plot (x, y1, '*b', x, y2, '*g', x, y3, '*r') grid on ylim ([0, 0.4]) legend ({'λ = 1', 'λ = 4', 'λ = 10'}, 'location', 'northeast') title ('Poisson PDF') xlabel ('values in x (number of occurrences)') ylabel ('density') ***** shared x, y x = [-1 0 1 2 Inf]; y = [0, exp(-1)*[1 1 0.5], 0]; ***** assert_equal (poisspdf (x, ones (1,5)), y, eps) ***** assert_equal (poisspdf (x, 1), y, eps) ***** assert_equal (poisspdf (x, [1 0 NaN 1 1]), [y(1) NaN NaN y(4:5)], eps) ***** assert_equal (poisspdf ([x, NaN], 1), [y, NaN], eps) ***** assert_equal (poisspdf (single ([x, NaN]), 1), single ([y, NaN]), eps ('single')) ***** assert_equal (poisspdf ([x, NaN], single (1)), single ([y, NaN]), eps ('single')) ***** error poisspdf () ***** error poisspdf (1) ***** error ... poisspdf (ones (3), ones (2)) ***** error ... poisspdf (ones (2), ones (3)) ***** error poisspdf (true, 2) ***** error poisspdf ('a', 2) ***** assert_equal (class (poisspdf (int32 (2), 2)), 'double') ***** error poisspdf (i, 2) ***** error poisspdf (2, i) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/tricdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/tricdf.m ***** demo ## Plot various CDFs from the triangular distribution x = 0.001:0.001:10; p1 = tricdf (x, 3, 4, 6); p2 = tricdf (x, 1, 2, 5); p3 = tricdf (x, 2, 3, 9); p4 = tricdf (x, 2, 5, 9); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', x, p4, '-c') grid on xlim ([0, 10]) legend ({'a = 3, b = 4, c = 6', 'a = 1, b = 2, c = 5', ... 'a = 2, b = 3, c = 9', 'a = 2, b = 5, c = 9'}, ... 'location', 'southeast') title ('Triangular CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y x = [-1, 0, 0.1, 0.5, 0.9, 1, 2] + 1; y = [0, 0, 0.02, 0.5, 0.98, 1 1]; ***** assert_equal (tricdf (x, ones (1,7), 1.5 * ones (1, 7), 2 * ones (1, 7)), y, eps) ***** assert_equal (tricdf (x, 1 * ones (1, 7), 1.5, 2), y, eps) ***** assert_equal (tricdf (x, 1 * ones (1, 7), 1.5, 2, 'upper'), 1 - y, eps) ***** assert_equal (tricdf (x, 1, 1.5, 2 * ones (1, 7)), y, eps) ***** assert_equal (tricdf (x, 1, 1.5 * ones (1, 7), 2), y, eps) ***** assert_equal (tricdf (x, 1, 1.5, 2), y, eps) ***** assert_equal (tricdf (x, [1, 1, NaN, 1, 1, 1, 1], 1.5, 2), ... [y(1:2), NaN, y(4:7)], eps) ***** assert_equal (tricdf (x, 1, 1.5, 2*[1, 1, NaN, 1, 1, 1, 1]), ... [y(1:2), NaN, y(4:7)], eps) ***** assert_equal (tricdf (x, 1, 1.5, 2*[1, 1, NaN, 1, 1, 1, 1]), ... [y(1:2), NaN, y(4:7)], eps) ***** assert_equal (tricdf ([x, NaN], 1, 1.5, 2), [y, NaN], eps) ***** assert_equal (tricdf (single ([x, NaN]), 1, 1.5, 2), ... single ([y, NaN]), eps ('single')) ***** assert_equal (tricdf ([x, NaN], single (1), 1.5, 2), ... single ([y, NaN]), eps ('single')) ***** assert_equal (tricdf ([x, NaN], 1, single (1.5), 2), ... single ([y, NaN]), eps ('single')) ***** assert_equal (tricdf ([x, NaN], 1, 1.5, single (2)), ... single ([y, NaN]), eps ('single')) ***** error tricdf () ***** error tricdf (1) ***** error tricdf (1, 2) ***** error tricdf (1, 2, 3) ***** error ... tricdf (1, 2, 3, 4, 5, 6) ***** error tricdf (1, 2, 3, 4, 'tail') ***** error tricdf (1, 2, 3, 4, 5) ***** error ... tricdf (ones (3), ones (2), ones (2), ones (2)) ***** error ... tricdf (ones (2), ones (3), ones (2), ones (2)) ***** error ... tricdf (ones (2), ones (2), ones (3), ones (2)) ***** error ... tricdf (ones (2), ones (2), ones (2), ones (3)) ***** error tricdf (int32 (2), 2, 3, 4) ***** error tricdf (true, 2, 3, 4) ***** error tricdf ('a', 2, 3, 4) ***** error tricdf (i, 2, 3, 4) ***** error tricdf (1, i, 3, 4) ***** error tricdf (1, 2, i, 4) ***** error tricdf (1, 2, 3, i) 32 tests, 32 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/ncfinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/ncfinv.m ***** demo ## Plot various iCDFs from the noncentral F distribution p = 0.001:0.001:0.999; x1 = ncfinv (p, 2, 5, 1); x2 = ncfinv (p, 2, 5, 2); x3 = ncfinv (p, 5, 10, 1); x4 = ncfinv (p, 10, 20, 10); plot (p, x1, '-r', p, x2, '-g', p, x3, '-k', p, x4, '-m') grid on ylim ([0, 5]) legend ({'df1 = 2, df2 = 5, λ = 1', 'df1 = 2, df2 = 5, λ = 2', ... 'df1 = 5, df2 = 10, λ = 1', 'df1 = 10, df2 = 20, λ = 10'}, ... 'location', 'northwest') title ('Noncentral F iCDF') xlabel ('probability') ylabel ('values in x') ***** demo ## Compare the noncentral F iCDF with LAMBDA = 10 to the F iCDF with the ## same number of numerator and denominator degrees of freedom (5, 20) p = 0.001:0.001:0.999; x1 = ncfinv (p, 5, 20, 10); x2 = finv (p, 5, 20); plot (p, x1, '-', p, x2, '-'); grid on ylim ([0, 10]) legend ({'Noncentral F(5,20,10)', 'F(5,20)'}, 'location', 'northwest') title ('Noncentral F vs F quantile functions') xlabel ('probability') ylabel ('values in x') ***** test x = [0,0.1775,0.3864,0.6395,0.9564,1.3712,1.9471,2.8215,4.3679,8.1865,Inf]; assert_equal (ncfinv ([0:0.1:1], 2, 3, 1), x, 1e-4); ***** test x = [0,0.7492,1.3539,2.0025,2.7658,3.7278,5.0324,6.9826,10.3955,18.7665,Inf]; assert_equal (ncfinv ([0:0.1:1], 2, 3, 5), x, 1e-4); ***** test x = [0,0.2890,0.8632,1.5653,2.4088,3.4594,4.8442,6.8286,10.0983,17.3736,Inf]; assert_equal (ncfinv ([0:0.1:1], 1, 4, 3), x, 1e-4); ***** test x = [0.078410, 0.212716, 0.288618, 0.335752, 0.367963, 0.391460]; assert_equal (ncfinv (0.05, [1, 2, 3, 4, 5, 6], 10, 3), x, 1e-6); ***** test x = [0.2574, 0.2966, 0.3188, 0.3331, 0.3432, 0.3507]; assert_equal (ncfinv (0.05, 5, [1, 2, 3, 4, 5, 6], 3), x, 1e-4); ***** test x = [1.6090, 1.8113, 1.9215, 1.9911, NaN, 2.0742]; assert_equal (ncfinv (0.05, 1, [1, 2, 3, 4, -1, 6], 10), x, 1e-4); ***** test assert_equal (ncfinv (0.996, 3, 5, 8), 58.0912074080671, 4e-12); ***** error ncfinv () ***** error ncfinv (1) ***** error ncfinv (1, 2) ***** error ncfinv (1, 2, 3) ***** error ... ncfinv (ones (3), ones (2), ones (2), ones (2)) ***** error ... ncfinv (ones (2), ones (3), ones (2), ones (2)) ***** error ... ncfinv (ones (2), ones (2), ones (3), ones (2)) ***** error ... ncfinv (ones (2), ones (2), ones (2), ones (3)) ***** error ncfinv (int32 (2), 2, 2, 2) ***** error ncfinv (true, 2, 2, 2) ***** error ncfinv ('a', 2, 2, 2) ***** error ncfinv (i, 2, 2, 2) ***** error ncfinv (2, i, 2, 2) ***** error ncfinv (2, 2, i, 2) ***** error ncfinv (2, 2, 2, i) 22 tests, 22 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/vmpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/vmpdf.m ***** demo ## Plot various PDFs from the von Mises distribution x1 = [-pi:0.1:pi]; y1 = vmpdf (x1, 0, 0.5); y2 = vmpdf (x1, 0, 1); y3 = vmpdf (x1, 0, 2); y4 = vmpdf (x1, 0, 4); plot (x1, y1, '-r', x1, y2, '-g', x1, y3, '-b', x1, y4, '-c') grid on xlim ([-pi, pi]) ylim ([0, 0.8]) legend ({'μ = 0, k = 0.5', 'μ = 0, k = 1', ... 'μ = 0, k = 2', 'μ = 0, k = 4'}, 'location', 'northwest') title ('Von Mises PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y0, y1 x = [-pi:pi/2:pi]; y0 = [0.046245, 0.125708, 0.341710, 0.125708, 0.046245]; y1 = [0.046245, 0.069817, 0.654958, 0.014082, 0.000039]; ***** assert_equal (vmpdf (x, 0, 1), y0, 1e-5) ***** assert_equal (vmpdf (x, zeros (1,5), ones (1,5)), y0, 1e-6) ***** assert_equal (vmpdf (x, 0, [1 2 3 4 5]), y1, 1e-6) ***** assert_equal (isa (vmpdf (single (pi), 0, 1), 'single'), true) ***** assert_equal (isa (vmpdf (pi, single (0), 1), 'single'), true) ***** assert_equal (isa (vmpdf (pi, 0, single (1)), 'single'), true) ***** error vmpdf () ***** error vmpdf (1) ***** error vmpdf (1, 2) ***** error ... vmpdf (ones (3), ones (2), ones (2)) ***** error ... vmpdf (ones (2), ones (3), ones (2)) ***** error ... vmpdf (ones (2), ones (2), ones (3)) ***** error vmpdf (int32 (2), 2, 2) ***** error vmpdf (true, 2, 2) ***** error vmpdf ('a', 2, 2) ***** error vmpdf (i, 2, 2) ***** error vmpdf (2, i, 2) ***** error vmpdf (2, 2, i) 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/stblcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/stblcdf.m ***** demo ## Stable cdf: Cauchy, a skewed stable, and the normal limit x = linspace (-6, 6, 200); plot (x, stblcdf (x, 1, 0, 1, 0), "-", ... x, stblcdf (x, 1.5, 0.5, 1, 0), "-", ... x, stblcdf (x, 2, 0, 1, 0), "-"); legend ("Cauchy", "alpha=1.5, beta=0.5", "normal", "location", "southeast"); ***** test x = -5:5; p = stblcdf (x, 1.5, 0.5, 1, 0); exp_p = [0.00961772128347771, 0.0143422747723476, 0.0257902242195547, ... 0.0657154294128386, 0.201576145758624, 0.462186560100778, ... 0.712063555515659, 0.855535196378772, 0.921201224725992, ... 0.951409668616683, 0.966845678836178]; assert_equal (p, exp_p, 1e-8); ***** test x = -5:5; p = stblcdf (x, 0.8, 0.5, 1, 0); exp_p = [0.0427283102762096, 0.0504255041089544, 0.0624716830177048, ... 0.0849086757683013, 0.150275591315296, 0.431333711402679, ... 0.641248581720908, 0.74188789948898, 0.797926083610673, ... 0.833292740693924, 0.857610462691116]; assert_equal (p, exp_p, 1e-8); ***** test # scaled and shifted (gam = 2, delta = 3) x = -5:5; p = stblcdf (x, 1.5, 0.5, 2, 3); exp_p = [0.0143422747723476, 0.0186030552365194, 0.0257902242195547, ... 0.0392075905274278, 0.0657154294128386, 0.116299801968237, ... 0.201576145758624, 0.321987153858349, 0.462186560100778, ... 0.598389078433622, 0.712063555515659]; assert_equal (p, exp_p, 1e-8); ***** test # normal special case x = -5:5; assert_equal (stblcdf (x, 2, 0, 1, 0), normcdf (x, 0, sqrt (2)), 1e-12); ***** test # Cauchy special case x = -5:5; assert_equal (stblcdf (x, 1, 0, 1, 0), 0.5 + atan (x) ./ pi, 1e-12); ***** test # cdf is the integral of the pdf assert_equal (stblcdf (0.7, 1.3, -0.4, 1, 0) - ... stblcdf (-1.2, 1.3, -0.4, 1, 0), ... quadgk (@(x) stblpdf (x, 1.3, -0.4, 1, 0), -1.2, 0.7), 1e-8); ***** error stblcdf (int32 (2), 1.5, 0, 1, 0) ***** error stblcdf (true, 1.5, 0, 1, 0) ***** error stblcdf ('a', 1.5, 0, 1, 0) ***** error stblcdf (1, 1.5, 0.5, 1) ***** error ... stblcdf (1, 2.5, 0, 1, 0) ***** error ... stblcdf (1, 1.5, 2, 1, 0) ***** error stblcdf (1, 1.5, 0, 0, 0) ***** error stblcdf (1, 1.5, 0, 1, 1i) ***** error stblcdf (1i, 1.5, 0, 1, 0) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/loglcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/loglcdf.m ***** demo ## Plot various CDFs from the log-logistic distribution x = 0:0.001:2; p1 = loglcdf (x, log (1), 1/0.5); p2 = loglcdf (x, log (1), 1); p3 = loglcdf (x, log (1), 1/2); p4 = loglcdf (x, log (1), 1/4); p5 = loglcdf (x, log (1), 1/8); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', x, p4, '-c', x, p5, '-m') legend ({'σ = 2 (β = 0.5)', 'σ = 1 (β = 1)', 'σ = 0.5 (β = 2)', ... 'σ = 0.25 (β = 4)', 'σ = 0.125 (β = 8)'}, 'location', 'northwest') grid on title ('Log-logistic CDF') xlabel ('values in x') ylabel ('probability') text (0.05, 0.64, 'μ = 0 (α = 1), values of σ (β) as shown in legend') ***** shared out1, out2 out1 = [0, 0.5, 0.66666667, 0.75, 0.8, 0.83333333]; out2 = [0, 0.4174, 0.4745, 0.5082, 0.5321, 0.5506]; ***** assert_equal (loglcdf ([0:5], 0, 1), out1, 1e-8) ***** assert_equal (loglcdf ([0:5], 0, 1, 'upper'), 1 - out1, 1e-8) ***** assert_equal (loglcdf ([0:5], 0, 1), out1, 1e-8) ***** assert_equal (loglcdf ([0:5], 0, 1, 'upper'), 1 - out1, 1e-8) ***** assert_equal (loglcdf ([0:5], 1, 3), out2, 1e-4) ***** assert_equal (loglcdf ([0:5], 1, 3, 'upper'), 1 - out2, 1e-4) ***** assert_equal (class (loglcdf (single (1), 2, 3)), "single") ***** assert_equal (class (loglcdf (1, single (2), 3)), "single") ***** assert_equal (class (loglcdf (1, 2, single (3))), "single") ***** error loglcdf (1) ***** error loglcdf (1, 2) ***** error ... loglcdf (1, 2, 3, 4) ***** error ... loglcdf (1, 2, 3, 'uper') ***** error ... loglcdf (1, ones (2), ones (3)) ***** error ... loglcdf (1, ones (2), ones (3), 'upper') ***** error ... loglcdf (ones (2), 1, ones (3)) ***** error ... loglcdf (ones (2), 1, ones (3), 'upper') ***** error ... loglcdf (ones (2), ones (3), 1) ***** error ... loglcdf (ones (2), ones (3), 1, 'upper') ***** error loglcdf (int32 (2), 2, 3) ***** error loglcdf (true, 2, 3) ***** error loglcdf ('a', 2, 3) ***** error loglcdf (i, 2, 3) ***** error loglcdf (i, 2, 3, 'upper') ***** error loglcdf (1, i, 3) ***** error loglcdf (1, i, 3, 'upper') ***** error loglcdf (1, 2, i) ***** error loglcdf (1, 2, i, 'upper') 28 tests, 28 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/wblrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/wblrnd.m ***** assert_equal (size (wblrnd (1, 1)), [1, 1]) ***** assert_equal (size (wblrnd (1, ones (2, 1))), [2, 1]) ***** assert_equal (size (wblrnd (1, ones (2, 2))), [2, 2]) ***** assert_equal (size (wblrnd (ones (2, 1), 1)), [2, 1]) ***** assert_equal (size (wblrnd (ones (2, 2), 1)), [2, 2]) ***** assert_equal (size (wblrnd (1, 1, 3)), [3, 3]) ***** assert_equal (size (wblrnd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (wblrnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (wblrnd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (wblrnd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (wblrnd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (wblrnd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (wblrnd (1, 1, [])), [0, 0]) ***** assert_equal (size (wblrnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (wblrnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (wblrnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (wblrnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (wblrnd (1, 1)), "double") ***** assert_equal (class (wblrnd (1, single (1))), "single") ***** assert_equal (class (wblrnd (1, single ([1, 1]))), "single") ***** assert_equal (class (wblrnd (single (1), 1)), "single") ***** assert_equal (class (wblrnd (single ([1, 1]), 1)), "single") ***** error wblrnd () ***** error wblrnd (1) ***** error ... wblrnd (ones (3), ones (2)) ***** error ... wblrnd (ones (2), ones (3)) ***** error wblrnd (i, 2, 3) ***** error wblrnd (1, i, 3) ***** error ... wblrnd (1, 2, 1.2) ***** error ... wblrnd (1, 2, ones (2)) ***** error ... wblrnd (1, 2, [2 0 2.5]) ***** error ... wblrnd (1, 2, 2, 1.5, 5) ***** error ... wblrnd (2, ones (2), 3) ***** error ... wblrnd (2, ones (2), [3, 2]) ***** error ... wblrnd (2, ones (2), 3, 2) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/unidrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/unidrnd.m ***** assert_equal (size (unidrnd (2)), [1, 1]) ***** assert_equal (size (unidrnd (ones (2, 1))), [2, 1]) ***** assert_equal (size (unidrnd (ones (2, 2))), [2, 2]) ***** assert_equal (size (unidrnd (1, 3)), [3, 3]) ***** assert_equal (size (unidrnd (1, [4, 1])), [4, 1]) ***** assert_equal (size (unidrnd (1, 4, 1)), [4, 1]) ***** assert_equal (size (unidrnd (1, 4, 1)), [4, 1]) ***** assert_equal (size (unidrnd (1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (unidrnd (1, 0, 1)), [0, 1]) ***** assert_equal (size (unidrnd (1, 1, 0)), [1, 0]) ***** assert_equal (size (unidrnd (1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (unidrnd (1, [])), [0, 0]) ***** assert_equal (size (unidrnd (1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (unidrnd (1, -1)), [0, 0]) ***** assert_equal (size (unidrnd (1, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (unidrnd (1, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (unidrnd (0, 1, 1), NaN) ***** assert_equal (unidrnd ([0, 0, 0], [1, 3]), [NaN, NaN, NaN]) ***** assert_equal (class (unidrnd (2)), "double") ***** assert_equal (class (unidrnd (single (2))), "single") ***** assert_equal (class (unidrnd (single ([2, 2]))), "single") ***** error unidrnd () ***** error unidrnd (i) ***** error ... unidrnd (1, 1.2) ***** error ... unidrnd (1, ones (2)) ***** error ... unidrnd (1, [2 0 2.5]) ***** error ... unidrnd (ones (2), ones (2)) ***** error ... unidrnd (1, 2, 1.5, 5) ***** error unidrnd (ones (2,2), 3) ***** error unidrnd (ones (2,2), [3, 2]) ***** error unidrnd (ones (2,2), 2, 3) 31 tests, 31 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/laplacecdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/laplacecdf.m ***** demo ## Plot various CDFs from the Laplace distribution x = -10:0.01:10; p1 = laplacecdf (x, 0, 1); p2 = laplacecdf (x, 0, 2); p3 = laplacecdf (x, 0, 4); p4 = laplacecdf (x, -5, 4); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', x, p4, '-c') grid on xlim ([-10, 10]) legend ({'μ = 0, β = 1', 'μ = 0, β = 2', ... 'μ = 0, β = 4', 'μ = -5, β = 4'}, 'location', 'southeast') title ('Laplace CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y x = [-Inf, -log(2), 0, log(2), Inf]; y = [0, 1/4, 1/2, 3/4, 1]; ***** assert_equal (laplacecdf ([x, NaN], 0, 1), [y, NaN]) ***** assert_equal (laplacecdf (x, 0, [-2, -1, 0, 1, 2]), [nan(1, 3), 0.75, 1]) ***** assert_equal (laplacecdf (single ([x, NaN]), 0, 1), single ([y, NaN]), eps ('single')) ***** assert_equal (laplacecdf ([x, NaN], single (0), 1), single ([y, NaN]), eps ('single')) ***** assert_equal (laplacecdf ([x, NaN], 0, single (1)), single ([y, NaN]), eps ('single')) ***** error laplacecdf () ***** error laplacecdf (1) ***** error ... laplacecdf (1, 2) ***** error ... laplacecdf (1, 2, 3, 4, 5) ***** error laplacecdf (1, 2, 3, 'tail') ***** error laplacecdf (1, 2, 3, 4) ***** error ... laplacecdf (ones (3), ones (2), ones (2)) ***** error ... laplacecdf (ones (2), ones (3), ones (2)) ***** error ... laplacecdf (ones (2), ones (2), ones (3)) ***** error laplacecdf (int32 (2), 2, 2) ***** error laplacecdf (true, 2, 2) ***** error laplacecdf ('a', 2, 2) ***** error laplacecdf (i, 2, 2) ***** error laplacecdf (2, i, 2) ***** error laplacecdf (2, 2, i) 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/wblcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/wblcdf.m ***** demo ## Plot various CDFs from the Weibull distribution x = 0:0.001:2.5; p1 = wblcdf (x, 1, 0.5); p2 = wblcdf (x, 1, 1); p3 = wblcdf (x, 1, 1.5); p4 = wblcdf (x, 1, 5); plot (x, p1, '-b', x, p2, '-r', x, p3, '-m', x, p4, '-g') grid on legend ({'λ = 1, k = 0.5', 'λ = 1, k = 1', ... 'λ = 1, k = 1.5', 'λ = 1, k = 5'}, 'location', 'southeast') title ('Weibull CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y x = [-1 0 0.5 1 Inf]; y = [0, 1-exp(-x(2:4)), 1]; ***** assert_equal (wblcdf (x, ones (1,5), ones (1,5)), y, 1e-16) ***** assert_equal (wblcdf (x, ones (1,5), ones (1,5), 'upper'), 1 - y) ***** assert_equal (wblcdf (x, 'upper'), 1 - y) ***** assert_equal (wblcdf (x, 1, ones (1,5)), y, 1e-16) ***** assert_equal (wblcdf (x, ones (1,5), 1), y, 1e-16) ***** assert_equal (wblcdf (x, [0 1 NaN Inf 1], 1), [NaN 0 NaN 0 1]) ***** assert_equal (wblcdf (x, [0 1 NaN Inf 1], 1, 'upper'), 1 - [NaN 0 NaN 0 1]) ***** assert_equal (wblcdf (x, 1, [0 1 NaN Inf 1]), [NaN 0 NaN y(4:5)]) ***** assert_equal (wblcdf (x, 1, [0 1 NaN Inf 1], 'upper'), 1 - [NaN 0 NaN y(4:5)]) ***** assert_equal (wblcdf ([x(1:2) NaN x(4:5)], 1, 1), [y(1:2) NaN y(4:5)]) ***** assert_equal (wblcdf ([x(1:2) NaN x(4:5)], 1, 1, 'upper'), 1 - [y(1:2) NaN y(4:5)]) ***** assert_equal (wblcdf ([x, NaN], 1, 1), [y, NaN], 1e-16) ***** assert_equal (wblcdf (single ([x, NaN]), 1, 1), single ([y, NaN])) ***** assert_equal (wblcdf ([x, NaN], single (1), 1), single ([y, NaN])) ***** assert_equal (wblcdf ([x, NaN], 1, single (1)), single ([y, NaN])) ***** error wblcdf () ***** error wblcdf (1,2,3,4,5,6,7) ***** error wblcdf (1, 2, 3, 4, 'uper') ***** error ... wblcdf (ones (3), ones (2), ones (2)) ***** error wblcdf (2, 3, 4, [1, 2]) ***** error ... [p, plo, pup] = wblcdf (1, 2, 3) ***** error [p, plo, pup] = ... wblcdf (1, 2, 3, [1, 0; 0, 1], 0) ***** error [p, plo, pup] = ... wblcdf (1, 2, 3, [1, 0; 0, 1], 1.22) ***** error [p, plo, pup] = ... wblcdf (1, 2, 3, [1, 0; 0, 1], 'alpha', 'upper') ***** error wblcdf (int32 (2), 2, 2) ***** error wblcdf (true, 2, 2) ***** error wblcdf ('a', 2, 2) ***** error wblcdf (i, 2, 2) ***** error wblcdf (2, i, 2) ***** error wblcdf (2, 2, i) ***** error ... [p, plo, pup] =wblcdf (1, 2, 3, [1, 0; 0, -inf], 0.04) 31 tests, 31 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/vmrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/vmrnd.m ***** assert_equal (size (vmrnd (1, 1)), [1, 1]) ***** assert_equal (size (vmrnd (1, ones (2, 1))), [2, 1]) ***** assert_equal (size (vmrnd (1, ones (2, 2))), [2, 2]) ***** assert_equal (size (vmrnd (ones (2, 1), 1)), [2, 1]) ***** assert_equal (size (vmrnd (ones (2, 2), 1)), [2, 2]) ***** assert_equal (size (vmrnd (1, 1, 3)), [3, 3]) ***** assert_equal (size (vmrnd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (vmrnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (vmrnd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (vmrnd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (vmrnd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (vmrnd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (vmrnd (1, 1, [])), [0, 0]) ***** assert_equal (size (vmrnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (vmrnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (vmrnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (vmrnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (vmrnd (1, 1)), "double") ***** assert_equal (class (vmrnd (1, single (1))), "single") ***** assert_equal (class (vmrnd (1, single ([1, 1]))), "single") ***** assert_equal (class (vmrnd (single (1), 1)), "single") ***** assert_equal (class (vmrnd (single ([1, 1]), 1)), "single") ***** error vmrnd () ***** error vmrnd (1) ***** error ... vmrnd (ones (3), ones (2)) ***** error ... vmrnd (ones (2), ones (3)) ***** error vmrnd (i, 2, 3) ***** error vmrnd (1, i, 3) ***** error ... vmrnd (1, 2, 1.2) ***** error ... vmrnd (1, 2, ones (2)) ***** error ... vmrnd (1, 2, [2 0 2.5]) ***** error ... vmrnd (1, 2, 2, 1.5, 5) ***** error ... vmrnd (2, ones (2), 3) ***** error ... vmrnd (2, ones (2), [3, 2]) ***** error ... vmrnd (2, ones (2), 3, 2) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/mnpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/mnpdf.m ***** test x = [1, 4, 2]; pk = [0.2, 0.5, 0.3]; y = mnpdf (x, pk); assert_equal (y, 0.11812, 0.001); ***** test x = [1, 4, 2; 1, 0, 9]; pk = [0.2, 0.5, 0.3; 0.1, 0.1, 0.8]; y = mnpdf (x, pk); assert_equal (y, [0.11812; 0.13422], 0.001); ***** error mnpdf ([true, true], [0.3, 0.7]) ***** error mnpdf ('ab', [0.3, 0.7]) ***** assert_equal (class (mnpdf (int32 ([1, 2]), [0.3, 0.7])), 'double') 5 tests, 5 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/ncx2inv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/ncx2inv.m ***** demo ## Plot various iCDFs from the noncentral chi-squared distribution p = 0.001:0.001:0.999; x1 = ncx2inv (p, 2, 1); x2 = ncx2inv (p, 2, 2); x3 = ncx2inv (p, 2, 3); x4 = ncx2inv (p, 4, 1); x5 = ncx2inv (p, 4, 2); x6 = ncx2inv (p, 4, 3); plot (p, x1, '-r', p, x2, '-g', p, x3, '-k', ... p, x4, '-m', p, x5, '-c', p, x6, '-y') grid on ylim ([0, 10]) legend ({'df = 2, λ = 1', 'df = 2, λ = 2', ... 'df = 2, λ = 3', 'df = 4, λ = 1', ... 'df = 4, λ = 2', 'df = 4, λ = 3'}, 'location', 'northwest') title ('Noncentral chi-squared iCDF') xlabel ('probability') ylabel ('values in x') ***** demo ## Compare the noncentral chi-squared CDF with LAMBDA = 2 to the ## chi-squared CDF with the same number of degrees of freedom (4). p = 0.001:0.001:0.999; x1 = ncx2inv (p, 4, 2); x2 = chi2inv (p, 4); plot (p, x1, '-', p, x2, '-'); grid on ylim ([0, 10]) legend ({'Noncentral χ^2(4,2)', 'χ^2(4)'}, 'location', 'northwest') title ('Noncentral chi-squared vs chi-squared quantile functions') xlabel ('probability') ylabel ('values in x') ***** test x = [0,0.3443,0.7226,1.1440,1.6220,2.1770,2.8436,3.6854,4.8447,6.7701,Inf]; assert_equal (ncx2inv ([0:0.1:1], 2, 1), x, 1e-4); ***** test x = [0,0.8295,1.6001,2.3708,3.1785,4.0598,5.0644,6.2765,7.8763,10.4199,Inf]; assert_equal (ncx2inv ([0:0.1:1], 2, 3), x, 1e-4); ***** test x = [0,0.5417,1.3483,2.1796,3.0516,4.0003,5.0777,6.3726,8.0748,10.7686,Inf]; assert_equal (ncx2inv ([0:0.1:1], 1, 4), x, 1e-4); ***** test x = [0.1808, 0.6456, 1.1842, 1.7650, 2.3760, 3.0105]; assert_equal (ncx2inv (0.05, [1, 2, 3, 4, 5, 6], 4), x, 1e-4); ***** test x = [0.4887, 0.6699, 0.9012, 1.1842, 1.5164, 1.8927]; assert_equal (ncx2inv (0.05, 3, [1, 2, 3, 4, 5, 6]), x, 1e-4); ***** test x = [1.3941, 1.6824, 2.0103, 2.3760, NaN, 3.2087]; assert_equal (ncx2inv (0.05, 5, [1, 2, 3, 4, -1, 6]), x, 1e-4); ***** test assert_equal (ncx2inv (0.996, 5, 8), 35.51298862765576, 3e-13); ***** error ncx2inv () ***** error ncx2inv (1) ***** error ncx2inv (1, 2) ***** error ... ncx2inv (ones (3), ones (2), ones (2)) ***** error ... ncx2inv (ones (2), ones (3), ones (2)) ***** error ... ncx2inv (ones (2), ones (2), ones (3)) ***** error ncx2inv (int32 (2), 2, 2) ***** error ncx2inv (true, 2, 2) ***** error ncx2inv ('a', 2, 2) ***** error ncx2inv (i, 2, 2) ***** error ncx2inv (2, i, 2) ***** error ncx2inv (2, 2, i) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/raylinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/raylinv.m ***** demo ## Plot various iCDFs from the Rayleigh distribution p = 0.001:0.001:0.999; x1 = raylinv (p, 0.5); x2 = raylinv (p, 1); x3 = raylinv (p, 2); x4 = raylinv (p, 3); x5 = raylinv (p, 4); plot (p, x1, '-b', p, x2, 'g', p, x3, '-r', p, x4, '-m', p, x5, '-k') grid on ylim ([0, 10]) legend ({'σ = 0,5', 'σ = 1', 'σ = 2', ... 'σ = 3', 'σ = 4'}, 'location', 'northwest') title ('Rayleigh iCDF') xlabel ('probability') ylabel ('values in x') ***** test p = 0:0.1:0.5; sigma = 1:6; x = raylinv (p, sigma); expected_x = [0.0000, 0.9181, 2.0041, 3.3784, 5.0538, 7.0645]; assert_equal (x, expected_x, 0.001); ***** test p = 0:0.1:0.5; x = raylinv (p, 0.5); expected_x = [0.0000, 0.2295, 0.3340, 0.4223, 0.5054, 0.5887]; assert_equal (x, expected_x, 0.001); ***** error raylinv () ***** error raylinv (1) ***** error ... raylinv (ones (3), ones (2)) ***** error ... raylinv (ones (2), ones (3)) ***** error raylinv (int32 (2), 2) ***** error raylinv (true, 2) ***** error raylinv ('a', 2) ***** error raylinv (i, 2) ***** error raylinv (2, i) 11 tests, 11 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/gumbelinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/gumbelinv.m ***** demo ## Plot various iCDFs from the Gumbel distribution p = 0.001:0.001:0.999; x1 = gumbelinv (p, 0.5, 2); x2 = gumbelinv (p, 1.0, 2); x3 = gumbelinv (p, 1.5, 3); x4 = gumbelinv (p, 3.0, 4); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', p, x4, '-c') grid on ylim ([-5, 20]) legend ({'μ = 0.5, β = 2', 'μ = 1.0, β = 2', ... 'μ = 1.5, β = 3', 'μ = 3.0, β = 4'}, 'location', 'northwest') title ('Gumbel iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p, x p = [0, 0.05, 0.5 0.95]; x = [-Inf, -1.0972, 0.3665, 2.9702]; ***** assert_equal (gumbelinv (p), x, 1e-4) ***** assert_equal (gumbelinv (p, zeros (1,4), ones (1,4)), x, 1e-4) ***** assert_equal (gumbelinv (p, 0, ones (1,4)), x, 1e-4) ***** assert_equal (gumbelinv (p, zeros (1,4), 1), x, 1e-4) ***** assert_equal (gumbelinv (p, [0, -Inf, NaN, Inf], 1), [-Inf, -Inf, NaN, Inf], 1e-4) ***** assert_equal (gumbelinv (p, 0, [Inf, NaN, -1, 0]), [-Inf, NaN, NaN, NaN], 1e-4) ***** assert_equal (gumbelinv ([p(1:2), NaN, p(4)], 0, 1), [x(1:2), NaN, x(4)], 1e-4) ***** assert_equal (gumbelinv ([p, NaN], 0, 1), [x, NaN], 1e-4) ***** assert_equal (gumbelinv (single ([p, NaN]), 0, 1), single ([x, NaN]), 1e-4) ***** assert_equal (gumbelinv ([p, NaN], single (0), 1), single ([x, NaN]), 1e-4) ***** assert_equal (gumbelinv ([p, NaN], 0, single (1)), single ([x, NaN]), 1e-4) p = [0.05, 0.5, 0.95]; x = gumbelinv(p); ***** assert_equal (gumbelcdf (x), p, 1e-4) ***** error gumbelinv () ***** error gumbelinv (1,2,3,4,5,6) ***** error ... gumbelinv (ones (3), ones (2), ones (2)) ***** error ... [p, plo, pup] = gumbelinv (2, 3, 4, [1, 2]) ***** error ... [p, plo, pup] = gumbelinv (1, 2, 3) ***** error [p, plo, pup] = ... gumbelinv (1, 2, 3, [1, 0; 0, 1], 0) ***** error [p, plo, pup] = ... gumbelinv (1, 2, 3, [1, 0; 0, 1], 1.22) ***** error gumbelinv (int32 (2), 2, 2) ***** error gumbelinv (true, 2, 2) ***** error gumbelinv ('a', 2, 2) ***** error gumbelinv (i, 2, 2) ***** error gumbelinv (2, i, 2) ***** error gumbelinv (2, 2, i) ***** error ... [p, plo, pup] = gumbelinv (1, 2, 3, [-1, 10; -Inf, -Inf], 0.04) 26 tests, 26 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/wblpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/wblpdf.m ***** demo ## Plot various PDFs from the Weibull distribution x = 0:0.001:2.5; y1 = wblpdf (x, 1, 0.5); y2 = wblpdf (x, 1, 1); y3 = wblpdf (x, 1, 1.5); y4 = wblpdf (x, 1, 5); plot (x, y1, '-b', x, y2, '-r', x, y3, '-m', x, y4, '-g') grid on ylim ([0, 2.5]) legend ({'λ = 5, k = 0.5', 'λ = 9, k = 1', ... 'λ = 6, k = 1.5', 'λ = 2, k = 5'}, 'location', 'northeast') title ('Weibull PDF') xlabel ('values in x') ylabel ('density') ***** shared x,y x = [-1 0 0.5 1 Inf]; y = [0, exp(-x(2:4)), 0]; ***** assert_equal (wblpdf (x, ones (1,5), ones (1,5)), y) ***** assert_equal (wblpdf (x, 1, ones (1,5)), y) ***** assert_equal (wblpdf (x, ones (1,5), 1), y) ***** assert_equal (wblpdf (x, [0 NaN Inf 1 1], 1), [NaN NaN NaN y(4:5)]) ***** assert_equal (wblpdf (x, 1, [0 NaN Inf 1 1]), [NaN NaN NaN y(4:5)]) ***** assert_equal (wblpdf ([x, NaN], 1, 1), [y, NaN]) ***** assert_equal (wblpdf (single ([x, NaN]), 1, 1), single ([y, NaN])) ***** assert_equal (wblpdf ([x, NaN], single (1), 1), single ([y, NaN])) ***** assert_equal (wblpdf ([x, NaN], 1, single (1)), single ([y, NaN])) ***** error wblpdf (int32 (2), 1, 1) ***** error wblpdf (true, 1, 1) ***** error wblpdf ('a', 1, 1) ***** error wblpdf () ***** error wblpdf (1,2,3,4) ***** error wblpdf (ones (3), ones (2), ones (2)) ***** error wblpdf (ones (2), ones (3), ones (2)) ***** error wblpdf (ones (2), ones (2), ones (3)) ***** error wblpdf (i, 2, 2) ***** error wblpdf (2, i, 2) ***** error wblpdf (2, 2, i) 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/bvtcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/bvtcdf.m ***** test x = [1, 2]; rho = [1, 0.5; 0.5, 1]; df = 4; assert_equal (bvtcdf (x, rho(2), df), mvtcdf (x, rho, df), 1e-14); ***** test x = [3, 2;2, 4;1, 5]; rho = [1, 0.5; 0.5, 1]; df = 4; assert_equal (bvtcdf (x, rho(2), df), mvtcdf (x, rho, df), 1e-14); ***** error bvtcdf (int32 ([0, 0]), 0.5, 5) ***** error bvtcdf ([true, true], 0.5, 5) ***** error bvtcdf ('ab', 0.5, 5) 5 tests, 5 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/geopdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/geopdf.m ***** demo ## Plot various PDFs from the geometric distribution x = 0:10; y1 = geopdf (x, 0.2); y2 = geopdf (x, 0.5); y3 = geopdf (x, 0.7); plot (x, y1, '*b', x, y2, '*g', x, y3, '*r') grid on ylim ([0, 0.8]) legend ({'ps = 0.2', 'ps = 0.5', 'ps = 0.7'}, 'location', 'northeast') title ('Geometric PDF') xlabel ('values in x (number of failures)') ylabel ('density') ***** shared x, y x = [-1 0 1 Inf]; y = [0, 1/2, 1/4, 0]; ***** assert_equal (geopdf (x, 0.5*ones (1,4)), y) ***** assert_equal (geopdf (x, 0.5), y) ***** assert_equal (geopdf (x, 0.5*[-1 NaN 4 1]), [NaN NaN NaN y(4)]) ***** assert_equal (geopdf ([x, NaN], 0.5), [y, NaN]) ***** assert_equal (geopdf (single ([x, NaN]), 0.5), single ([y, NaN]), 5*eps ('single')) ***** assert_equal (geopdf ([x, NaN], single (0.5)), single ([y, NaN]), 5*eps ('single')) ***** error geopdf (true, 0.5) ***** error geopdf ('a', 0.5) ***** assert_equal (class (geopdf (int32 (2), 0.5)), 'double') ***** error geopdf () ***** error geopdf (1) ***** error geopdf (1,2,3) ***** error geopdf (ones (3), ones (2)) ***** error geopdf (ones (2), ones (3)) ***** error geopdf (i, 2) ***** error geopdf (2, i) 16 tests, 16 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/invginv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/invginv.m ***** demo ## Plot various iCDFs from the inverse Gaussian distribution p = 0.001:0.001:0.999; x1 = invginv (p, 1, 0.2); x2 = invginv (p, 1, 1); x3 = invginv (p, 1, 3); x4 = invginv (p, 3, 0.2); x5 = invginv (p, 3, 1); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', p, x4, '-c', p, x5, '-y') grid on ylim ([0, 3]) legend ({'μ = 1, σ = 0.2', 'μ = 1, σ = 1', 'μ = 1, σ = 3', ... 'μ = 3, σ = 0.2', 'μ = 3, σ = 1'}, 'location', 'northwest') title ('Inverse Gaussian iCDF') xlabel ('probability') ylabel ('x') ***** shared p, x p = [0, 0.3829, 0.6827, 1]; x = [0, 0.5207, 1.0376, Inf]; ***** assert_equal (invginv (p, 1, 1), x, 1e-4); ***** assert_equal (invginv (p, 1, ones (1,4)), x, 1e-4); ***** assert_equal (invginv (p, 1, [-1, 0, 1, 1]), [NaN, NaN, x(3:4)], 1e-4) ***** assert_equal (invginv (p, [-1, 0, 1, 1], 1), [NaN, NaN, x(3:4)], 1e-4) ***** assert_equal (class (invginv (single ([p, NaN]), 0, 1)), "single") ***** assert_equal (class (invginv ([p, NaN], single (0), 1)), "single") ***** assert_equal (class (invginv ([p, NaN], 0, single (1))), "single") ***** error invginv (1) ***** error invginv (1, 2) ***** error ... invginv (1, ones (2), ones (3)) ***** error ... invginv (ones (2), 1, ones (3)) ***** error ... invginv (ones (2), ones (3), 1) ***** error invginv (int32 (2), 2, 3) ***** error invginv (true, 2, 3) ***** error invginv ('a', 2, 3) ***** error invginv (i, 2, 3) ***** error invginv (1, i, 3) ***** error invginv (1, 2, i) 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/evpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/evpdf.m ***** demo ## Plot various PDFs from the Extreme value distribution x = -10:0.001:10; y1 = evpdf (x, 0.5, 2); y2 = evpdf (x, 1.0, 2); y3 = evpdf (x, 1.5, 3); y4 = evpdf (x, 3.0, 4); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', x, y4, '-c') grid on ylim ([0, 0.2]) legend ({'μ = 0.5, σ = 2', 'μ = 1.0, σ = 2', ... 'μ = 1.5, σ = 3', 'μ = 3.0, σ = 4'}, 'location', 'northeast') title ('Extreme value PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y0, y1 x = [-5, 0, 1, 2, 3]; y0 = [0.0067, 0.3679, 0.1794, 0.0046, 0]; y1 = [0.0025, 0.2546, 0.3679, 0.1794, 0.0046]; ***** assert_equal (evpdf (x), y0, 1e-4) ***** assert_equal (evpdf (x, zeros (1,5), ones (1,5)), y0, 1e-4) ***** assert_equal (evpdf (x, ones (1,5), ones (1,5)), y1, 1e-4) ***** error evpdf () ***** error ... evpdf (ones (3), ones (2), ones (2)) ***** error evpdf (int32 (2), 2, 2) ***** error evpdf (true, 2, 2) ***** error evpdf ('a', 2, 2) ***** error evpdf (i, 2, 2) ***** error evpdf (2, i, 2) ***** error evpdf (2, 2, i) 11 tests, 11 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/cauchypdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/cauchypdf.m ***** demo ## Plot various PDFs from the Cauchy distribution x = -5:0.01:5; y1 = cauchypdf (x, 0, 0.5); y2 = cauchypdf (x, 0, 1); y3 = cauchypdf (x, 0, 2); y4 = cauchypdf (x, -2, 1); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', x, y4, '-c') grid on xlim ([-5, 5]) ylim ([0, 0.7]) legend ({'x0 = 0, γ = 0.5', 'x0 = 0, γ = 1', ... 'x0 = 0, γ = 2', 'x0 = -2, γ = 1'}, 'location', 'northeast') title ('Cauchy PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y x = [-1 0 0.5 1 2]; y = 1/pi * ( 2 ./ ((x-1).^2 + 2^2) ); ***** assert_equal (cauchypdf (x, ones (1,5), 2*ones (1,5)), y) ***** assert_equal (cauchypdf (x, 1, 2*ones (1,5)), y) ***** assert_equal (cauchypdf (x, ones (1,5), 2), y) ***** assert_equal (cauchypdf (x, [-Inf 1 NaN 1 Inf], 2), [NaN y(2) NaN y(4) NaN]) ***** assert_equal (cauchypdf (x, 1, 2*[0 1 NaN 1 Inf]), [NaN y(2) NaN y(4) NaN]) ***** assert_equal (cauchypdf ([x, NaN], 1, 2), [y, NaN]) ***** assert_equal (cauchypdf (single ([x, NaN]), 1, 2), single ([y, NaN]), eps ('single')) ***** assert_equal (cauchypdf ([x, NaN], single (1), 2), single ([y, NaN]), eps ('single')) ***** assert_equal (cauchypdf ([x, NaN], 1, single (2)), single ([y, NaN]), eps ('single')) ***** test x = rand (10, 1); assert_equal (cauchypdf (x, 0, 1), tpdf (x, 1), eps); ***** error cauchypdf () ***** error cauchypdf (1) ***** error ... cauchypdf (1, 2) ***** error cauchypdf (1, 2, 3, 4) ***** error ... cauchypdf (ones (3), ones (2), ones (2)) ***** error ... cauchypdf (ones (2), ones (3), ones (2)) ***** error ... cauchypdf (ones (2), ones (2), ones (3)) ***** error cauchypdf (int32 (2), 4, 3) ***** error cauchypdf (true, 4, 3) ***** error cauchypdf ('a', 4, 3) ***** error cauchypdf (i, 4, 3) ***** error cauchypdf (1, i, 3) ***** error cauchypdf (1, 4, i) 23 tests, 23 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/binornd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/binornd.m ***** assert_equal (size (binornd (2, 1/2)), [1 1]) ***** assert_equal (size (binornd (2 * ones (2, 1), 1/2)), [2, 1]) ***** assert_equal (size (binornd (2 * ones (2, 2), 1/2)), [2, 2]) ***** assert_equal (size (binornd (2, 1/2 * ones (2, 1))), [2, 1]) ***** assert_equal (size (binornd (1, 1/2 * ones (2, 2))), [2, 2]) ***** assert_equal (size (binornd (ones (2, 1), 1)), [2, 1]) ***** assert_equal (size (binornd (ones (2, 2), 1)), [2, 2]) ***** assert_equal (size (binornd (2, 1/2, 3)), [3, 3]) ***** assert_equal (size (binornd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (binornd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (binornd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (binornd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (binornd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (binornd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (binornd (1, 1, [])), [0, 0]) ***** assert_equal (size (binornd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (binornd (1, 1/2, -1)), [0, 0]) ***** assert_equal (size (binornd (1, 1/2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (binornd (1, 1/2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (binornd (1, 1)), "double") ***** assert_equal (class (binornd (1, single (0))), "single") ***** assert_equal (class (binornd (1, single ([0, 0]))), "single") ***** assert_equal (class (binornd (1, single (1), 2)), "single") ***** assert_equal (class (binornd (1, single ([1, 1]), 1, 2)), "single") ***** assert_equal (class (binornd (single (1), 1, 2)), "single") ***** assert_equal (class (binornd (single ([1, 1]), 1, 1, 2)), "single") ***** error binornd () ***** error binornd (1) ***** error ... binornd (ones (3), ones (2)) ***** error ... binornd (ones (2), ones (3)) ***** error binornd (i, 2) ***** error binornd (1, i) ***** error ... binornd (1, 1/2, 1.2) ***** error ... binornd (1, 1/2, ones (2)) ***** error ... binornd (1, 1/2, [2 0 2.5]) ***** error ... binornd (1, 1/2, 2, 1.5, 5) ***** error ... binornd (2, 1/2 * ones (2), 3) ***** error ... binornd (2, 1/2 * ones (2), [3, 2]) ***** error ... binornd (2, 1/2 * ones (2), 3, 2) ***** error ... binornd (2 * ones (2), 1/2, 3) ***** error ... binornd (2 * ones (2), 1/2, [3, 2]) ***** error ... binornd (2 * ones (2), 1/2, 3, 2) 42 tests, 42 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/logipdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/logipdf.m ***** demo ## Plot various PDFs from the logistic distribution x = -5:0.01:20; y1 = logipdf (x, 5, 2); y2 = logipdf (x, 9, 3); y3 = logipdf (x, 9, 4); y4 = logipdf (x, 6, 2); y5 = logipdf (x, 2, 1); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', x, y4, '-c', x, y5, '-m') grid on ylim ([0, 0.3]) legend ({'μ = 5, σ = 2', 'μ = 9, σ = 3', 'μ = 9, σ = 4', ... 'μ = 6, σ = 2', 'μ = 2, σ = 1'}, 'location', 'northeast') title ('Logistic PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y x = [-Inf -log(4) 0 log(4) Inf]; y = [0, 0.16, 1/4, 0.16, 0]; ***** assert_equal (logipdf ([x, NaN], 0, 1), [y, NaN], eps) ***** assert_equal (logipdf (x, 0, [-2, -1, 0, 1, 2]), [nan(1, 3), y([4:5])], eps) ***** assert_equal (logipdf (single ([x, NaN]), 0, 1), single ([y, NaN]), eps ('single')) ***** assert_equal (logipdf ([x, NaN], single (0), 1), single ([y, NaN]), eps ('single')) ***** assert_equal (logipdf ([x, NaN], 0, single (1)), single ([y, NaN]), eps ('single')) ***** error logipdf () ***** error logipdf (1) ***** error ... logipdf (1, 2) ***** error ... logipdf (1, ones (2), ones (3)) ***** error ... logipdf (ones (2), 1, ones (3)) ***** error ... logipdf (ones (2), ones (3), 1) ***** error logipdf (int32 (2), 2, 3) ***** error logipdf (true, 2, 3) ***** error logipdf ('a', 2, 3) ***** error logipdf (i, 2, 3) ***** error logipdf (1, i, 3) ***** error logipdf (1, 2, i) 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/trirnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/trirnd.m ***** assert_equal (size (trirnd (1, 1.5, 2)), [1, 1]) ***** assert_equal (size (trirnd (1 * ones (2, 1), 1.5, 2)), [2, 1]) ***** assert_equal (size (trirnd (1 * ones (2, 2), 1.5, 2)), [2, 2]) ***** assert_equal (size (trirnd (1, 1.5 * ones (2, 1), 2)), [2, 1]) ***** assert_equal (size (trirnd (1, 1.5 * ones (2, 2), 2)), [2, 2]) ***** assert_equal (size (trirnd (1, 1.5, 2 * ones (2, 1))), [2, 1]) ***** assert_equal (size (trirnd (1, 1.5, 2 * ones (2, 2))), [2, 2]) ***** assert_equal (size (trirnd (1, 1.5, 2, 3)), [3, 3]) ***** assert_equal (size (trirnd (1, 1.5, 2, [4, 1])), [4, 1]) ***** assert_equal (size (trirnd (1, 1.5, 2, 4, 1)), [4, 1]) ***** assert_equal (size (trirnd (1, 1.5, 2, [])), [0, 0]) ***** assert_equal (size (trirnd (1, 1.5, 2, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (trirnd (1, 5, 3, -1)), [0, 0]) ***** assert_equal (size (trirnd (1, 5, 3, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (trirnd (1, 5, 3, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (trirnd (1, 1.5, 2)), "double") ***** assert_equal (class (trirnd (single (1), 1.5, 2)), "single") ***** assert_equal (class (trirnd (single ([1, 1]), 1.5, 2)), "single") ***** assert_equal (class (trirnd (1, single (1.5), 2)), "single") ***** assert_equal (class (trirnd (1, single ([1.5, 1.5]), 2)), "single") ***** assert_equal (class (trirnd (1, 1.5, single (1.5))), "single") ***** assert_equal (class (trirnd (1, 1.5, single ([2, 2]))), "single") ***** error trirnd () ***** error trirnd (1) ***** error trirnd (1, 2) ***** error ... trirnd (ones (3), 5 * ones (2), ones (2)) ***** error ... trirnd (ones (2), 5 * ones (3), ones (2)) ***** error ... trirnd (ones (2), 5 * ones (2), ones (3)) ***** error trirnd (i, 5, 3) ***** error trirnd (1, 5+i, 3) ***** error trirnd (1, 5, i) ***** error ... trirnd (1, 5, 3, 1.2) ***** error ... trirnd (1, 5, 3, ones (2)) ***** error ... trirnd (1, 5, 3, [2 0 2.5]) ***** error ... trirnd (1, 5, 3, 2, 1.5, 5) ***** error ... trirnd (2, 5 * ones (2), 2, 3) ***** error ... trirnd (2, 5 * ones (2), 2, [3, 2]) ***** error ... trirnd (2, 5 * ones (2), 2, 3, 2) 38 tests, 38 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/nakainv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/nakainv.m ***** demo ## Plot various iCDFs from the Nakagami distribution p = 0.001:0.001:0.999; x1 = nakainv (p, 0.5, 1); x2 = nakainv (p, 1, 1); x3 = nakainv (p, 1, 2); x4 = nakainv (p, 1, 3); x5 = nakainv (p, 2, 1); x6 = nakainv (p, 2, 2); x7 = nakainv (p, 5, 1); plot (p, x1, '-r', p, x2, '-g', p, x3, '-y', p, x4, '-m', ... p, x5, '-k', p, x6, '-b', p, x7, '-c') grid on ylim ([0, 3]) legend ({'μ = 0.5, ω = 1', 'μ = 1, ω = 1', 'μ = 1, ω = 2', ... 'μ = 1, ω = 3', 'μ = 2, ω = 1', 'μ = 2, ω = 2', ... 'μ = 5, ω = 1'}, 'location', 'northwest') title ('Nakagami iCDF') xlabel ('probability') ylabel ('values in x') ***** shared p, y p = [-Inf, -1, 0, 1/2, 1, 2, Inf]; y = [NaN, NaN, 0, 0.83255461115769769, Inf, NaN, NaN]; ***** assert_equal (nakainv (p, ones (1,7), ones (1,7)), y, eps) ***** assert_equal (nakainv (p, 1, 1), y, eps) ***** assert_equal (nakainv (p, [1, 1, 1, NaN, 1, 1, 1], 1), [y(1:3), NaN, y(5:7)], eps) ***** assert_equal (nakainv (p, 1, [1, 1, 1, NaN, 1, 1, 1]), [y(1:3), NaN, y(5:7)], eps) ***** assert_equal (nakainv ([p, NaN], 1, 1), [y, NaN], eps) ***** assert_equal (nakainv (single ([p, NaN]), 1, 1), single ([y, NaN])) ***** assert_equal (nakainv ([p, NaN], single (1), 1), single ([y, NaN])) ***** assert_equal (nakainv ([p, NaN], 1, single (1)), single ([y, NaN])) ***** error nakainv () ***** error nakainv (1) ***** error nakainv (1, 2) ***** error ... nakainv (ones (3), ones (2), ones (2)) ***** error ... nakainv (ones (2), ones (3), ones (2)) ***** error ... nakainv (ones (2), ones (2), ones (3)) ***** error nakainv (int32 (2), 4, 3) ***** error nakainv (true, 4, 3) ***** error nakainv ('a', 4, 3) ***** error nakainv (i, 4, 3) ***** error nakainv (1, i, 3) ***** error nakainv (1, 4, i) 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/unifrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/unifrnd.m ***** assert_equal (size (unifrnd (1, 1)), [1 1]) ***** assert_equal (size (unifrnd (1, ones (2,1))), [2, 1]) ***** assert_equal (size (unifrnd (1, ones (2,2))), [2, 2]) ***** assert_equal (size (unifrnd (ones (2,1), 1)), [2, 1]) ***** assert_equal (size (unifrnd (ones (2,2), 1)), [2, 2]) ***** assert_equal (size (unifrnd (1, 1, 3)), [3, 3]) ***** assert_equal (size (unifrnd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (unifrnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (unifrnd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (unifrnd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (unifrnd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (unifrnd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (unifrnd (1, 1, [])), [0, 0]) ***** assert_equal (size (unifrnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (unifrnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (unifrnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (unifrnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (unifrnd (1, 1)), "double") ***** assert_equal (class (unifrnd (1, single (1))), "single") ***** assert_equal (class (unifrnd (1, single ([1, 1]))), "single") ***** assert_equal (class (unifrnd (single (1), 1)), "single") ***** assert_equal (class (unifrnd (single ([1, 1]), 1)), "single") ***** error unifrnd () ***** error unifrnd (1) ***** error ... unifrnd (ones (3), ones (2)) ***** error ... unifrnd (ones (2), ones (3)) ***** error unifrnd (i, 2, 3) ***** error unifrnd (1, i, 3) ***** error ... unifrnd (1, 2, 1.2) ***** error ... unifrnd (1, 2, ones (2)) ***** error ... unifrnd (1, 2, [2 0 2.5]) ***** error ... unifrnd (1, 2, 2, 1.5, 5) ***** error ... unifrnd (2, ones (2), 3) ***** error ... unifrnd (2, ones (2), [3, 2]) ***** error ... unifrnd (2, ones (2), 3, 2) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/mvncdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/mvncdf.m ***** demo mu = [1, -1]; Sigma = [0.9, 0.4; 0.4, 0.3]; [X1, X2] = meshgrid (linspace (-1, 3, 25)', linspace (-3, 1, 25)'); X = [X1(:), X2(:)]; p = mvncdf (X, mu, Sigma); Z = reshape (p, 25, 25); surf (X1, X2, Z); title ('Bivariate Normal Distribution'); ylabel 'X1' xlabel 'X2' ***** demo mu = [0, 0]; Sigma = [0.25, 0.3; 0.3, 1]; p = mvncdf ([0 0], [1 1], mu, Sigma); x1 = -3:.2:3; x2 = -3:.2:3; [X1, X2] = meshgrid (x1, x2); X = [X1(:), X2(:)]; p = mvnpdf (X, mu, Sigma); p = reshape (p, length (x2), length (x1)); contour (x1, x2, p, [0.0001, 0.001, 0.01, 0.05, 0.15, 0.25, 0.35]); xlabel ('x'); ylabel ('p'); title ('Probability over Rectangular Region'); line ([0, 0, 1, 1, 0], [1, 0, 0, 1, 1], 'Linestyle', '--', 'Color', 'k'); ***** test fD = (-2:2)'; X = repmat (fD, 1, 4); p = mvncdf (X); assert_equal (p, [0; 0.0006; 0.0625; 0.5011; 0.9121], ones (5, 1) * 1e-4); ***** test mu = [1, -1]; Sigma = [0.9, 0.4; 0.4, 0.3]; [X1,X2] = meshgrid (linspace (-1, 3, 25)', linspace (-3, 1, 25)'); X = [X1(:), X2(:)]; p = mvncdf (X, mu, Sigma); p_out = [0.00011878988774500, 0.00034404112322371, ... 0.00087682502191813, 0.00195221905058185, ... 0.00378235566873474, 0.00638175749734415, ... 0.00943764224329656, 0.01239164888125426, ... 0.01472750274376648, 0.01623228313374828]'; assert_equal (p([1:10]), p_out, 1e-16); ***** test mu = [1, -1]; Sigma = [0.9, 0.4; 0.4, 0.3]; [X1,X2] = meshgrid (linspace (-1, 3, 25)', linspace (-3, 1, 25)'); X = [X1(:), X2(:)]; p = mvncdf (X, mu, Sigma); p_out = [0.8180695783608276, 0.8854485749482751, ... 0.9308108777385832, 0.9579855743025508, ... 0.9722897881414742, 0.9788150170059926, ... 0.9813597788804785, 0.9821977956568989, ... 0.9824283794464095, 0.9824809345614861]'; assert_equal (p([616:625]), p_out, 3e-16); ***** test mu = [0, 0]; Sigma = [0.25, 0.3; 0.3, 1]; [p, err] = mvncdf ([0, 0], [1, 1], mu, Sigma); assert_equal (p, 0.2097424404755626, 1e-16); assert_equal (err, 1e-08); ***** test x = [1 2]; mu = [0.5 1.5]; sigma = [1.0, 0.5; 0.5, 1.0]; p = mvncdf (x, mu, sigma); assert_equal (p, 0.546244443857090, 1e-15); ***** test x = [1 2]; mu = [0.5 1.5]; sigma = [1.0, 0.5; 0.5, 1.0]; a = [-inf 0]; p = mvncdf (a, x, mu, sigma); assert_equal (p, 0.482672935215631, 1e-15); ***** test # MATLAB parity: an options field missing or empty takes its default rho = [1, 0.5; 0.5, 1]; p = 1 / 3; o = statset ('TolFun', 1e-4); assert_equal (mvncdf ([0, 0], [0, 0], rho, o), p, 1e-8); o = struct ('TolFun', 1e-4); assert_equal (mvncdf ([0, 0], [0, 0], rho, o), p, 1e-8); assert_equal (mvncdf ([0, 0], [0, 0], rho, struct ('Display', 'final')), ... p, 1e-8); ***** error mvncdf (int32 ([0, 0])) ***** error mvncdf ([true, true]) ***** error mvncdf ('ab') ***** error ... mvncdf ([0, 0], [0, 0], eye (2), struct ('Display', 'bogus')) ***** error p = mvncdf (randn (25,26), [], eye (26)); ***** error p = mvncdf (randn (25,8), [], eye (9)); ***** error p = mvncdf (randn (25,4), randn (25,5), [], eye (4)); ***** error p = mvncdf (randn (25,4), randn (25,4), [2, 3; 2, 3], eye (4)); ***** error p = mvncdf (randn (25,4), randn (25,4), ones (1, 5), eye (4)); ***** error p = mvncdf ([-inf, 0], [1, 2], [0.5, 1.5], [1.0, 0.5; 0.5, 1.0], option) 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/bvncdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/bvncdf.m ***** demo mu = [1, -1]; sigma = [0.9, 0.4; 0.4, 0.3]; [X1, X2] = meshgrid (linspace (-1, 3, 25)', linspace (-3, 1, 25)'); x = [X1(:), X2(:)]; p = bvncdf (x, mu, sigma); Z = reshape (p, 25, 25); surf (X1, X2, Z); title ('Bivariate Normal Distribution'); ylabel 'X1' xlabel 'X2' ***** test mu = [1, -1]; sigma = [0.9, 0.4; 0.4, 0.3]; [X1,X2] = meshgrid (linspace (-1, 3, 25)', linspace (-3, 1, 25)'); x = [X1(:), X2(:)]; p = bvncdf (x, mu, sigma); p_out = [0.00011878988774500, 0.00034404112322371, ... 0.00087682502191813, 0.00195221905058185, ... 0.00378235566873474, 0.00638175749734415, ... 0.00943764224329656, 0.01239164888125426, ... 0.01472750274376648, 0.01623228313374828]'; assert_equal (p([1:10]), p_out, 1e-16); ***** test mu = [1, -1]; sigma = [0.9, 0.4; 0.4, 0.3]; [X1,X2] = meshgrid (linspace (-1, 3, 25)', linspace (-3, 1, 25)'); x = [X1(:), X2(:)]; p = bvncdf (x, mu, sigma); p_out = [0.8180695783608276, 0.8854485749482751, ... 0.9308108777385832, 0.9579855743025508, ... 0.9722897881414742, 0.9788150170059926, ... 0.9813597788804785, 0.9821977956568989, ... 0.9824283794464095, 0.9824809345614861]'; assert_equal (p([616:625]), p_out, 3e-16); ***** test ## Test infinite limits mu = [0, 0]; sigma = [1 0.5; 0.5 1]; assert_equal (bvncdf ([Inf, Inf], mu, sigma), 1); assert_equal (bvncdf ([-Inf, 2], mu, sigma), 0); assert_equal (bvncdf ([1, -Inf], mu, sigma), 0); assert_equal (bvncdf ([0.5, Inf], mu, sigma), normcdf (0.5), eps); assert_equal (bvncdf ([Inf, 0.5], mu, sigma), normcdf (0.5), eps); ***** error bvncdf (int32 ([0, 0]), [0, 0], eye (2)) ***** error bvncdf ([true, true], [0, 0], eye (2)) ***** error bvncdf ('ab', [0, 0], eye (2)) ***** error bvncdf (randn (25,3), [], [1, 1; 1, 1]); ***** error bvncdf (randn (25,2), [], [1, 1; 1, 1]); ***** error bvncdf (randn (25,2), [], ones (3, 2)); 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/nakacdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/nakacdf.m ***** demo ## Plot various CDFs from the Nakagami distribution x = 0:0.01:3; p1 = nakacdf (x, 0.5, 1); p2 = nakacdf (x, 1, 1); p3 = nakacdf (x, 1, 2); p4 = nakacdf (x, 1, 3); p5 = nakacdf (x, 2, 1); p6 = nakacdf (x, 2, 2); p7 = nakacdf (x, 5, 1); plot (x, p1, '-r', x, p2, '-g', x, p3, '-y', x, p4, '-m', ... x, p5, '-k', x, p6, '-b', x, p7, '-c') grid on xlim ([0, 3]) legend ({'μ = 0.5, ω = 1', 'μ = 1, ω = 1', 'μ = 1, ω = 2', ... 'μ = 1, ω = 3', 'μ = 2, ω = 1', 'μ = 2, ω = 2', ... 'μ = 5, ω = 1'}, 'location', 'southeast') title ('Nakagami CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y x = [-1, 0, 1, 2, Inf]; y = [0, 0, 0.63212055882855778, 0.98168436111126578, 1]; ***** assert_equal (nakacdf (x, ones (1,5), ones (1,5)), y, eps) ***** assert_equal (nakacdf (x, 1, 1), y, eps) ***** assert_equal (nakacdf (x, [1, 1, NaN, 1, 1], 1), [y(1:2), NaN, y(4:5)]) ***** assert_equal (nakacdf (x, 1, [1, 1, NaN, 1, 1]), [y(1:2), NaN, y(4:5)]) ***** assert_equal (nakacdf ([x, NaN], 1, 1), [y, NaN], eps) ***** assert_equal (nakacdf (single ([x, NaN]), 1, 1), single ([y, NaN]), eps ('single')) ***** assert_equal (nakacdf ([x, NaN], single (1), 1), single ([y, NaN]), eps ('single')) ***** assert_equal (nakacdf ([x, NaN], 1, single (1)), single ([y, NaN]), eps ('single')) ***** error nakacdf () ***** error nakacdf (1) ***** error nakacdf (1, 2) ***** error nakacdf (1, 2, 3, 'tail') ***** error nakacdf (1, 2, 3, 4) ***** error ... nakacdf (ones (3), ones (2), ones (2)) ***** error ... nakacdf (ones (2), ones (3), ones (2)) ***** error ... nakacdf (ones (2), ones (2), ones (3)) ***** error nakacdf (int32 (2), 2, 2) ***** error nakacdf (true, 2, 2) ***** error nakacdf ('a', 2, 2) ***** error nakacdf (i, 2, 2) ***** error nakacdf (2, i, 2) ***** error nakacdf (2, 2, i) 22 tests, 22 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/binopdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/binopdf.m ***** demo ## Plot various PDFs from the binomial distribution x = 0:40; y1 = binopdf (x, 20, 0.5); y2 = binopdf (x, 20, 0.7); y3 = binopdf (x, 40, 0.5); plot (x, y1, '*b', x, y2, '*g', x, y3, '*r') grid on ylim ([0, 0.25]) legend ({'n = 20, ps = 0.5', 'n = 20, ps = 0.7', ... 'n = 40, ps = 0.5'}, 'location', 'northeast') title ('Binomial PDF') xlabel ('values in x (number of successes)') ylabel ('density') ***** shared x, y x = [-1 0 1 2 3]; y = [0 1/4 1/2 1/4 0]; ***** assert_equal (binopdf (x, 2 * ones (1, 5), 0.5 * ones (1, 5)), y, eps) ***** assert_equal (binopdf (x, 2, 0.5 * ones (1, 5)), y, eps) ***** assert_equal (binopdf (x, 2 * ones (1, 5), 0.5), y, eps) ***** assert_equal (binopdf (x, 2 * [0 -1 NaN 1.1 1], 0.5), [0 NaN NaN NaN 0]) ***** assert_equal (binopdf (x, 2, 0.5 * [0 -1 NaN 3 1]), [0 NaN NaN NaN 0]) ***** assert_equal (binopdf ([x, NaN], 2, 0.5), [y, NaN], eps) ***** assert_equal (binopdf (cat (3, x, x), 2, 0.5), cat (3, y, y), eps) ***** assert_equal (binopdf (1, 1, 1), 1) ***** assert_equal (binopdf (0, 3, 0), 1) ***** assert_equal (binopdf (2, 2, 1), 1) ***** assert_equal (binopdf (1, 2, 1), 0) ***** assert_equal (binopdf (0, 1.1, 0), NaN) ***** assert_equal (binopdf (1, 2, -1), NaN) ***** assert_equal (binopdf (1, 2, 1.5), NaN) ***** assert_equal (binopdf ([], 1, 1), []) ***** assert_equal (binopdf (1, [], 1), []) ***** assert_equal (binopdf (1, 1, []), []) ***** assert_equal (binopdf (ones (1, 0), 2, .5), ones (1, 0)) ***** assert_equal (binopdf (ones (0, 1), 2, .5), ones (0, 1)) ***** assert_equal (binopdf (ones (0, 1, 2), 2, .5), ones (0, 1, 2)) ***** assert_equal (binopdf (1, ones (0, 1, 2), .5), ones (0, 1, 2)) ***** assert_equal (binopdf (1, 2, ones (0, 1, 2)), ones (0, 1, 2)) ***** assert_equal (binopdf (ones (1, 0, 2), 2, .5), ones (1, 0, 2)) ***** assert_equal (binopdf (ones (1, 2, 0), 2, .5), ones (1, 2, 0)) ***** assert_equal (binopdf (ones (0, 1, 2), NaN, .5), ones (0, 1, 2)) ***** assert_equal (binopdf (ones (0, 1, 2), 2, NaN), ones (0, 1, 2)) ***** assert_equal (binopdf (single ([x, NaN]), 2, 0.5), single ([y, NaN])) ***** assert_equal (binopdf ([x, NaN], single (2), 0.5), single ([y, NaN])) ***** assert_equal (binopdf ([x, NaN], 2, single (0.5)), single ([y, NaN])) ***** error binopdf () ***** error binopdf (1) ***** error binopdf (1, 2) ***** error binopdf (1, 2, 3, 4) ***** error ... binopdf (ones (3), ones (2), ones (2)) ***** error ... binopdf (ones (2), ones (3), ones (2)) ***** error ... binopdf (ones (2), ones (2), ones (3)) ***** error binopdf (true, 2, 2) ***** error binopdf ('a', 2, 2) ***** assert_equal (class (binopdf (int32 (2), 2, 2)), 'double') ***** error binopdf (i, 2, 2) ***** error binopdf (2, i, 2) ***** error binopdf (2, 2, i) 42 tests, 42 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/copulapdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/copulapdf.m ***** test x = [0.2:0.2:0.6; 0.2:0.2:0.6]; theta = [1; 2]; y = copulapdf ('Clayton', x, theta); expected_p = [0.9872; 0.7295]; assert_equal (y, expected_p, 0.001); ***** test x = [0.2:0.2:0.6; 0.2:0.2:0.6]; y = copulapdf ('Gumbel', x, 2); expected_p = [0.9468; 0.9468]; assert_equal (y, expected_p, 0.001); ***** test x = [0.2, 0.6; 0.2, 0.6]; theta = [1; 2]; y = copulapdf ('Frank', x, theta); expected_p = [0.9378; 0.8678]; assert_equal (y, expected_p, 0.001); ***** test x = [0.2, 0.6; 0.2, 0.6]; theta = [0.3; 0.7]; y = copulapdf ('AMH', x, theta); expected_p = [0.9540; 0.8577]; assert_equal (y, expected_p, 0.001); ***** error copulapdf ('Clayton', int32 ([0, 0]), 2) ***** error copulapdf ('Clayton', [true, true], 2) ***** error copulapdf ('Clayton', 'ab', 2) ***** test x = [0.1, 0.2; 0.3, 0.6; 0.5, 0.4; 0.7, 0.9; 0.45, 0.55]; y = copulapdf ('Gaussian', x, 0.5); assert_equal (y, [1.60177371945198; 0.998741486235102; 1.14241401106385; ... 1.31299420633171; 1.13661012971028], 1e-12); y = copulapdf ('Gaussian', x, -0.3); assert_equal (y, [0.653989319149703; 1.07700187314878; 1.04496288532534; ... 0.76398020459843; 1.05211178116014], 1e-12); ***** test # an uncorrelated Gaussian copula is the independence copula x = [0.1, 0.2; 0.3, 0.6; 0.5, 0.4; 0.7, 0.9; 0.45, 0.55]; assert_equal (copulapdf ('Gaussian', x, 0), ones (5, 1), 1e-12); ***** test x = [0.1, 0.2; 0.3, 0.6; 0.5, 0.4; 0.7, 0.9; 0.45, 0.55]; y = copulapdf ('t', x, 0.5, 5); assert_equal (y, [1.66488234707408; 1.00205894407007; 1.24574194276063; ... 1.25091343011063; 1.24054754220011], 1e-12); y = copulapdf ('t', x, -0.3, 10); assert_equal (y, [0.644342340201519; 1.12031977908833; 1.09385787202575; ... 0.730314426588563; 1.10518920332876], 1e-12); ***** test # both elliptical families take a correlation matrix beyond two columns R = [1, 0.4, 0.2; 0.4, 1, 0.3; 0.2, 0.3, 1]; x = [0.2, 0.4, 0.6; 0.5, 0.5, 0.5]; assert_equal (copulapdf ('Gaussian', x, R), ... [1.1162786093147; 1.14859096884849], 1e-12); assert_equal (copulapdf ('t', x, R, 8), ... [1.19326414606185; 1.37528246652052], 1e-12); ***** test # the density integrates to one over the unit square g = ((1:40)' - 0.5) / 40; [A, B] = meshgrid (g, g); x = [A(:), B(:)]; assert_equal (sum (copulapdf ('Gaussian', x, 0.5)) / 1600, 1, 1e-3); assert_equal (sum (copulapdf ('t', x, 0.5, 6)) / 1600, 1, 1e-2); ***** error ... copulapdf ('Gaussian', [0.2, 0.4], [1, 2; 2, 1]) ***** error ... copulapdf ('t', [0.2, 0.4], 0.5) ***** error copulapdf ('Gaussian', [0.2, 0.4], 0.5, 5) ***** test x = [0.35, 0.62]; h = 1e-5; for theta = [-1, -0.4, 0.7, 1] fd = (copulacdf ('FGM', [x(1)+h, x(2)+h], theta) ... - copulacdf ('FGM', [x(1)+h, x(2)-h], theta) ... - copulacdf ('FGM', [x(1)-h, x(2)+h], theta) ... + copulacdf ('FGM', [x(1)-h, x(2)-h], theta)) / (4 * h * h); assert_equal (copulapdf ('FGM', x, theta), fd, 1e-6); endfor ***** test # the bivariate density in closed form x = [0.35, 0.62; 0.2, 0.3]; theta = 0.7; assert_equal (copulapdf ('FGM', x, theta), ... 1 + theta * (1 - 2 * x(:,1)) .* (1 - 2 * x(:,2)), 1e-14); ***** test # a zero parameter gives the independence copula x = [0.35, 0.62; 0.2, 0.3; 0.9, 0.1]; assert_equal (copulapdf ('FGM', x, 0), ones (3, 1), 1e-14); ***** test # one parameter per subset of order two or more beyond two variables x = [0.3, 0.5, 0.7]; theta = [0.1, 0.1, 0.1, 0.1]; assert_equal (copulapdf ('FGM', x, theta), 0.984, 1e-12); ***** test # a parameter set outside the family's linear constraints gives NaN assert_equal (copulapdf ('FGM', [0.3, 0.5], 2), NaN); ***** test # the density integrates to one over the unit square g = ((1:60)' - 0.5) / 60; [A, B] = meshgrid (g, g); x = [A(:), B(:)]; assert_equal (sum (copulapdf ('FGM', x, 0.7)) / 3600, 1, 1e-10); ***** error ... copulapdf ('FGM', [0.3, 0.5, 0.7], [0.1, 0.1]) 22 tests, 22 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/gumbelpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/gumbelpdf.m ***** demo ## Plot various PDFs from the Extreme value distribution x = -5:0.001:20; y1 = gumbelpdf (x, 0.5, 2); y2 = gumbelpdf (x, 1.0, 2); y3 = gumbelpdf (x, 1.5, 3); y4 = gumbelpdf (x, 3.0, 4); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', x, y4, '-c') grid on ylim ([0, 0.2]) legend ({'μ = 0.5, β = 2', 'μ = 1.0, β = 2', ... 'μ = 1.5, β = 3', 'μ = 3.0, β = 4'}, 'location', 'northeast') title ('Extreme value PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y0, y1 x = [-5, 0, 1, 2, 3]; y0 = [0, 0.3679, 0.2547, 0.1182, 0.0474]; y1 = [0, 0.1794, 0.3679, 0.2547, 0.1182]; ***** assert_equal (gumbelpdf (x), y0, 1e-4) ***** assert_equal (gumbelpdf (x, zeros (1,5), ones (1,5)), y0, 1e-4) ***** assert_equal (gumbelpdf (x, ones (1,5), ones (1,5)), y1, 1e-4) ***** error gumbelpdf () ***** error ... gumbelpdf (ones (3), ones (2), ones (2)) ***** error gumbelpdf (int32 (2), 2, 2) ***** error gumbelpdf (true, 2, 2) ***** error gumbelpdf ('a', 2, 2) ***** error gumbelpdf (i, 2, 2) ***** error gumbelpdf (2, i, 2) ***** error gumbelpdf (2, 2, i) 11 tests, 11 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/mnrnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/mnrnd.m ***** test n = 10; pk = [0.2, 0.5, 0.3]; r = mnrnd (n, pk); assert_equal (size (r), size (pk)); assert_equal (all ((all (r >= 0))(:)), true); assert_equal (all ((all (round (r) == r))(:)), true); assert_equal (all ((sum (r) == n)(:)), true); ***** test n = 10 * ones (3, 1); pk = [0.2, 0.5, 0.3]; r = mnrnd (n, pk); assert_equal (size (r), [length(n), length(pk)]); assert_equal (all ((all (r >= 0))(:)), true); assert_equal (all ((all (round (r) == r))(:)), true); assert_equal (all ((all (sum (r, 2) == n))(:)), true); ***** test n = (1:2)'; pk = [0.2, 0.5, 0.3; 0.1, 0.1, 0.8]; r = mnrnd (n, pk); assert_equal (size (r), size (pk)); assert_equal (all ((all (r >= 0))(:)), true); assert_equal (all ((all (round (r) == r))(:)), true); assert_equal (all ((all (sum (r, 2) == n))(:)), true); 3 tests, 3 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/copularnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/copularnd.m ***** test theta = 0.5; r = copularnd ('Gaussian', theta); assert_equal (size (r), [1, 2]); assert_equal (all ((all ((r >= 0) & (r <= 1)))(:)), true); ***** test theta = 0.5; df = 2; r = copularnd ('t', theta, df); assert_equal (size (r), [1, 2]); assert_equal (all ((all ((r >= 0) & (r <= 1)))(:)), true); ***** test theta = 0.5; r = copularnd ('Clayton', theta); assert_equal (size (r), [1, 2]); assert_equal (all ((all ((r >= 0) & (r <= 1)))(:)), true); ***** test theta = 0.5; n = 2; r = copularnd ('Clayton', theta, n); assert_equal (size (r), [n, 2]); assert_equal (all ((all ((r >= 0) & (r <= 1)))(:)), true); ***** test theta = [1; 2]; n = 2; d = 3; r = copularnd ('Clayton', theta, n, d); assert_equal (size (r), [n, d]); assert_equal (all ((all ((r >= 0) & (r <= 1)))(:)), true); ***** test rand ("seed", 7); for theta = [-5, -2, 2, 5, 10] r = copularnd ("Frank", theta, 4000); assert_equal (size (r), [4000, 2]); assert_equal (all (r(:) >= 0 & r(:) <= 1), true); rho = corr (tiedrank (r(:,1)), tiedrank (r(:,2))); assert_equal (rho, copulastat ("Frank", theta, "type", "Spearman"), 0.05); endfor ***** test rand ("seed", 11); for theta = [1.5, 2, 3, 5] r = copularnd ("Gumbel", theta, 4000); assert_equal (size (r), [4000, 2]); assert_equal (all (r(:) >= 0 & r(:) <= 1), true); rho = corr (tiedrank (r(:,1)), tiedrank (r(:,2))); assert_equal (rho, copulastat ("Gumbel", theta, "type", "Spearman"), 0.05); endfor ***** test # each family degenerates to independence at its own boundary rand ("seed", 13); r = copularnd ("Frank", 0, 3000); assert_equal (corr (tiedrank (r(:,1)), tiedrank (r(:,2))), 0, 0.06); r = copularnd ("Gumbel", 1, 3000); assert_equal (corr (tiedrank (r(:,1)), tiedrank (r(:,2))), 0, 0.06); ***** test # a parameter outside the family's range gives NaN rows assert_equal (copularnd ("Gumbel", 0.5, 2), NaN (2, 2)); assert_equal (copularnd ("Frank", Inf, 2), NaN (2, 2)); ***** test # the default is a single bivariate draw rand ("seed", 3); assert_equal (size (copularnd ("Frank", 3)), [1, 2]); assert_equal (size (copularnd ("Gumbel", 2)), [1, 2]); assert_equal (size (copularnd ("Gumbel", 2, 5)), [5, 2]); ***** error ... copularnd ("Frank", 3, 5, 3) ***** error ... copularnd ("Gumbel", 2, 5, 3) ***** test rand ("seed", 21); for theta = [-0.9, -0.5, 0.5, 0.9] r = copularnd ("AMH", theta, 4000); assert_equal (size (r), [4000, 2]); assert_equal (all (r(:) >= 0 & r(:) <= 1), true); rho = corr (tiedrank (r(:,1)), tiedrank (r(:,2))); assert_equal (rho, copulastat ("AMH", theta, "type", "Spearman"), 0.05); endfor ***** test rand ("seed", 23); for theta = [-1, -0.5, 0.5, 1] r = copularnd ("FGM", theta, 4000); assert_equal (size (r), [4000, 2]); assert_equal (all (r(:) >= 0 & r(:) <= 1), true); rho = corr (tiedrank (r(:,1)), tiedrank (r(:,2))); assert_equal (rho, copulastat ("FGM", theta, "type", "Spearman"), 0.05); endfor ***** test # both are the independence copula at a zero parameter rand ("seed", 29); r = copularnd ("AMH", 0, 4000); assert_equal (corr (tiedrank (r(:,1)), tiedrank (r(:,2))), 0, 0.05); r = copularnd ("FGM", 0, 4000); assert_equal (corr (tiedrank (r(:,1)), tiedrank (r(:,2))), 0, 0.05); ***** test # a parameter outside the family's range gives NaN rows assert_equal (copularnd ("AMH", 1, 2), NaN (2, 2)); assert_equal (copularnd ("AMH", -1.5, 2), NaN (2, 2)); assert_equal (copularnd ("FGM", 1.5, 2), NaN (2, 2)); ***** error ... copularnd ("AMH", 0.5, 5, 3) ***** error ... copularnd ("FGM", 0.5, 5, 3) 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/gamcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/gamcdf.m ***** demo ## Plot various CDFs from the Gamma distribution x = 0:0.01:20; p1 = gamcdf (x, 1, 2); p2 = gamcdf (x, 2, 2); p3 = gamcdf (x, 3, 2); p4 = gamcdf (x, 5, 1); p5 = gamcdf (x, 9, 0.5); p6 = gamcdf (x, 7.5, 1); p7 = gamcdf (x, 0.5, 1); plot (x, p1, '-r', x, p2, '-g', x, p3, '-y', x, p4, '-m', ... x, p5, '-k', x, p6, '-b', x, p7, '-c') grid on legend ({'α = 1, β = 2', 'α = 2, β = 2', 'α = 3, β = 2', ... 'α = 5, β = 1', 'α = 9, β = 0.5', 'α = 7.5, β = 1', ... 'α = 0.5, β = 1'}, 'location', 'southeast') title ('Gamma CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y, u x = [-1, 0, 0.5, 1, 2, Inf]; y = [0, gammainc(x(2:end), 1)]; u = [0, NaN, NaN, 1, 0.1353352832366127, 0]; ***** assert_equal (gamcdf (x, ones (1,6), ones (1,6)), y, eps) ***** assert_equal (gamcdf (x, ones (1,6), ones (1,6), []), y, eps) ***** assert_equal (gamcdf (x, 1, ones (1,6)), y, eps) ***** assert_equal (gamcdf (x, ones (1,6), 1), y, eps) ***** assert_equal (gamcdf (x, [0, -Inf, NaN, Inf, 1, 1], 1), [1, NaN, NaN, 0, y(5:6)], eps) ***** assert_equal (gamcdf (x, [0, -Inf, NaN, Inf, 1, 1], 1, 'upper'), u, eps) ***** assert_equal (gamcdf (x, 1, [0, -Inf, NaN, Inf, 1, 1]), [NaN, NaN, NaN, 0, y(5:6)], eps) ***** assert_equal (gamcdf ([x(1:2), NaN, x(4:6)], 1, 1), [y(1:2), NaN, y(4:6)], eps) ***** assert_equal (gamcdf ([x, NaN], 1, 1), [y, NaN]) ***** assert_equal (gamcdf (single ([x, NaN]), 1, 1), single ([y, NaN]), eps ('single')) ***** assert_equal (gamcdf ([x, NaN], single (1), 1), single ([y, NaN]), eps ('single')) ***** assert_equal (gamcdf ([x, NaN], 1, single (1)), single ([y, NaN]), eps ('single')) ***** error gamcdf () ***** error gamcdf (1) ***** error gamcdf (1, 2, 3, 4, 5, 6, 7) ***** error gamcdf (1, 2, 3, 'uper') ***** error gamcdf (1, 2, 3, 4, 5, 'uper') ***** error gamcdf (2, 3, 4, [1, 2]) ***** error ... [p, plo, pup] = gamcdf (1, 2, 3) ***** error ... [p, plo, pup] = gamcdf (1, 2, 3, 'upper') ***** error [p, plo, pup] = ... gamcdf (1, 2, 3, [1, 0; 0, 1], 0) ***** error [p, plo, pup] = ... gamcdf (1, 2, 3, [1, 0; 0, 1], 1.22) ***** error [p, plo, pup] = ... gamcdf (1, 2, 3, [1, 0; 0, 1], 'alpha', 'upper') ***** error ... gamcdf (ones (3), ones (2), ones (2)) ***** error ... gamcdf (ones (2), ones (3), ones (2)) ***** error ... gamcdf (ones (2), ones (2), ones (3)) ***** error gamcdf (int32 (2), 2, 2) ***** error gamcdf (true, 2, 2) ***** error gamcdf ('a', 2, 2) ***** error gamcdf (i, 2, 2) ***** error gamcdf (2, i, 2) ***** error gamcdf (2, 2, i) ***** error ... [p, plo, pup] = gamcdf (1, 2, 3, [1, 0; 0, -inf], 0.04) 33 tests, 33 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/expcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/expcdf.m ***** demo ## Plot various CDFs from the exponential distribution x = 0:0.01:5; p1 = expcdf (x, 2/3); p2 = expcdf (x, 1.0); p3 = expcdf (x, 2.0); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r') grid on legend ({'μ = 2/3', 'μ = 1', 'μ = 2'}, 'location', 'southeast') title ('Exponential CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, p x = [-1 0 0.5 1 Inf]; p = [0, 1 - exp(-x(2:end)/2)]; ***** assert_equal (expcdf (x, 2 * ones (1, 5)), p, 1e-16) ***** assert_equal (expcdf (x, 2), p, 1e-16) ***** assert_equal (expcdf (x, 2 * [1, 0, NaN, 1, 1]), [0, NaN, NaN, p(4:5)], 1e-16) ***** assert_equal (expcdf ([x, NaN], 2), [p, NaN], 1e-16) ***** assert_equal (expcdf (single ([x, NaN]), 2), single ([p, NaN])) ***** assert_equal (expcdf ([x, NaN], single (2)), single ([p, NaN])) ***** test [p, plo, pup] = expcdf (1, 2, 3); assert_equal (p, 0.39346934028737, 1e-14); assert_equal (plo, 0.08751307220484, 1e-14); assert_equal (pup, 0.93476821257933, 1e-14); ***** test [p, plo, pup] = expcdf (1, 2, 2, 0.1); assert_equal (p, 0.39346934028737, 1e-14); assert_equal (plo, 0.14466318041675, 1e-14); assert_equal (pup, 0.79808291849140, 1e-14); ***** test [p, plo, pup] = expcdf (1, 2, 2, 0.1, 'upper'); assert_equal (p, 0.60653065971263, 1e-14); assert_equal (plo, 0.20191708150860, 1e-14); assert_equal (pup, 0.85533681958325, 1e-14); ***** error expcdf () ***** error expcdf (1, 2 ,3 ,4 ,5, 6) ***** error expcdf (1, 2, 3, 4, 'uper') ***** error ... expcdf (ones (3), ones (2)) ***** error ... expcdf (2, 3, [1, 2]) ***** error ... [p, plo, pup] = expcdf (1, 2) ***** error [p, plo, pup] = ... expcdf (1, 2, 3, 0) ***** error [p, plo, pup] = ... expcdf (1, 2, 3, 1.22) ***** error [p, plo, pup] = ... expcdf (1, 2, 3, 'alpha', 'upper') ***** error expcdf (int32 (2), 2) ***** error expcdf (true, 2) ***** error expcdf ('a', 2) ***** error expcdf (i, 2) ***** error expcdf (2, i) ***** error ... [p, plo, pup] = expcdf (1, 2, -1, 0.04) 24 tests, 24 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/nakapdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/nakapdf.m ***** demo ## Plot various PDFs from the Nakagami distribution x = 0:0.01:3; y1 = nakapdf (x, 0.5, 1); y2 = nakapdf (x, 1, 1); y3 = nakapdf (x, 1, 2); y4 = nakapdf (x, 1, 3); y5 = nakapdf (x, 2, 1); y6 = nakapdf (x, 2, 2); y7 = nakapdf (x, 5, 1); plot (x, y1, '-r', x, y2, '-g', x, y3, '-y', x, y4, '-m', ... x, y5, '-k', x, y6, '-b', x, y7, '-c') grid on xlim ([0, 3]) ylim ([0, 2]) legend ({'μ = 0.5, ω = 1', 'μ = 1, ω = 1', 'μ = 1, ω = 2', ... 'μ = 1, ω = 3', 'μ = 2, ω = 1', 'μ = 2, ω = 2', ... 'μ = 5, ω = 1'}, 'location', 'northeast') title ('Nakagami PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y x = [-1, 0, 1, 2, Inf]; y = [0, 0, 0.73575888234288467, 0.073262555554936715, 0]; ***** assert_equal (nakapdf (x, ones (1,5), ones (1,5)), y, eps) ***** assert_equal (nakapdf (x, 1, 1), y, eps) ***** assert_equal (nakapdf (x, [1, 1, NaN, 1, 1], 1), [y(1:2), NaN, y(4:5)], eps) ***** assert_equal (nakapdf (x, 1, [1, 1, NaN, 1, 1]), [y(1:2), NaN, y(4:5)], eps) ***** assert_equal (nakapdf ([x, NaN], 1, 1), [y, NaN], eps) ***** assert_equal (nakapdf (single ([x, NaN]), 1, 1), single ([y, NaN])) ***** assert_equal (nakapdf ([x, NaN], single (1), 1), single ([y, NaN])) ***** assert_equal (nakapdf ([x, NaN], 1, single (1)), single ([y, NaN])) ***** error nakapdf () ***** error nakapdf (1) ***** error nakapdf (1, 2) ***** error ... nakapdf (ones (3), ones (2), ones (2)) ***** error ... nakapdf (ones (2), ones (3), ones (2)) ***** error ... nakapdf (ones (2), ones (2), ones (3)) ***** error nakapdf (int32 (2), 4, 3) ***** error nakapdf (true, 4, 3) ***** error nakapdf ('a', 4, 3) ***** error nakapdf (i, 4, 3) ***** error nakapdf (1, i, 3) ***** error nakapdf (1, 4, i) 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/raylpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/raylpdf.m ***** demo ## Plot various PDFs from the Rayleigh distribution x = 0:0.01:10; y1 = raylpdf (x, 0.5); y2 = raylpdf (x, 1); y3 = raylpdf (x, 2); y4 = raylpdf (x, 3); y5 = raylpdf (x, 4); plot (x, y1, '-b', x, y2, 'g', x, y3, '-r', x, y4, '-m', x, y5, '-k') grid on ylim ([0, 1.25]) legend ({'σ = 0,5', 'σ = 1', 'σ = 2', ... 'σ = 3', 'σ = 4'}, 'location', 'northeast') title ('Rayleigh PDF') xlabel ('values in x') ylabel ('density') ***** test x = 0:0.5:2.5; sigma = 1:6; y = raylpdf (x, sigma); expected_y = [0.0000, 0.1212, 0.1051, 0.0874, 0.0738, 0.0637]; assert_equal (y, expected_y, 0.001); ***** test x = 0:0.5:2.5; y = raylpdf (x, 0.5); expected_y = [0.0000, 1.2131, 0.5413, 0.0667, 0.0027, 0.0000]; assert_equal (y, expected_y, 0.001); ***** error raylpdf () ***** error raylpdf (1) ***** error ... raylpdf (ones (3), ones (2)) ***** error ... raylpdf (ones (2), ones (3)) ***** error raylpdf (int32 (2), 2) ***** error raylpdf (true, 2) ***** error raylpdf ('a', 2) ***** error raylpdf (i, 2) ***** error raylpdf (2, i) 11 tests, 11 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/ncx2cdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/ncx2cdf.m ***** demo ## Plot various CDFs from the noncentral chi-squared distribution x = 0:0.1:10; p1 = ncx2cdf (x, 2, 1); p2 = ncx2cdf (x, 2, 2); p3 = ncx2cdf (x, 2, 3); p4 = ncx2cdf (x, 4, 1); p5 = ncx2cdf (x, 4, 2); p6 = ncx2cdf (x, 4, 3); plot (x, p1, '-r', x, p2, '-g', x, p3, '-k', ... x, p4, '-m', x, p5, '-c', x, p6, '-y') grid on xlim ([0, 10]) legend ({'df = 2, λ = 1', 'df = 2, λ = 2', ... 'df = 2, λ = 3', 'df = 4, λ = 1', ... 'df = 4, λ = 2', 'df = 4, λ = 3'}, 'location', 'southeast') title ('Noncentral chi-squared CDF') xlabel ('values in x') ylabel ('probability') ***** demo ## Compare the noncentral chi-squared CDF with LAMBDA = 2 to the ## chi-squared CDF with the same number of degrees of freedom (4). x = 0:0.1:10; p1 = ncx2cdf (x, 4, 2); p2 = chi2cdf (x, 4); plot (x, p1, '-', x, p2, '-') grid on xlim ([0, 10]) legend ({'Noncentral χ^2(4,2)', 'χ^2(4)'}, 'location', 'northwest') title ('Noncentral chi-squared vs chi-squared CDFs') xlabel ('values in x') ylabel ('probability') ***** test x = -2:0.1:2; p = ncx2cdf (x, 10, 1); assert_equal (p([1:21]), zeros (1, 21), 3e-84); assert_equal (p(22), 1.521400636466575e-09, 1e-14); assert_equal (p(30), 6.665480510026046e-05, 1e-14); assert_equal (p(41), 0.002406447308399836, 1e-14); ***** test p = ncx2cdf (12, 10, 3); assert_equal (p, 0.4845555602398649, 1e-14); ***** test p = ncx2cdf (2, 3, 2); assert_equal (p, 0.2207330870741212, 1e-14); ***** test p = ncx2cdf (2, 3, 2, 'upper'); assert_equal (p, 0.7792669129258789, 1e-14); ***** test p = ncx2cdf ([3, 6], 3, 2, 'upper'); assert_equal (p, [0.6423318186400054, 0.3152299878943012], 1e-14); ***** error ncx2cdf () ***** error ncx2cdf (1) ***** error ncx2cdf (1, 2) ***** error ncx2cdf (1, 2, 3, 'tail') ***** error ncx2cdf (1, 2, 3, 4) ***** error ... ncx2cdf (ones (3), ones (2), ones (2)) ***** error ... ncx2cdf (ones (2), ones (3), ones (2)) ***** error ... ncx2cdf (ones (2), ones (2), ones (3)) ***** error ncx2cdf (int32 (2), 2, 2) ***** error ncx2cdf (true, 2, 2) ***** error ncx2cdf ('a', 2, 2) ***** error ncx2cdf (i, 2, 2) ***** error ncx2cdf (2, i, 2) ***** error ncx2cdf (2, 2, i) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/hygeinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/hygeinv.m ***** demo ## Plot various iCDFs from the hypergeometric distribution p = 0.001:0.001:0.999; x1 = hygeinv (p, 500, 50, 100); x2 = hygeinv (p, 500, 60, 200); x3 = hygeinv (p, 500, 70, 300); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r') grid on ylim ([0, 60]) legend ({'m = 500, k = 50, n = 100', 'm = 500, k = 60, n = 200', ... 'm = 500, k = 70, n = 300'}, 'location', 'northwest') title ('Hypergeometric iCDF') xlabel ('probability') ylabel ('values in p (number of successes)') ***** shared p p = [-1 0 0.5 1 2]; ***** assert_equal (hygeinv (p, 4*ones (1,5), 2*ones (1,5), 2*ones (1,5)), [NaN 0 1 2 NaN]) ***** assert_equal (hygeinv (p, 4*ones (1,5), 2, 2), [NaN 0 1 2 NaN]) ***** assert_equal (hygeinv (p, 4, 2*ones (1,5), 2), [NaN 0 1 2 NaN]) ***** assert_equal (hygeinv (p, 4, 2, 2*ones (1,5)), [NaN 0 1 2 NaN]) ***** assert_equal (hygeinv (p, 4*[1 -1 NaN 1.1 1], 2, 2), [NaN NaN NaN NaN NaN]) ***** assert_equal (hygeinv (p, 4, 2*[1 -1 NaN 1.1 1], 2), [NaN NaN NaN NaN NaN]) ***** assert_equal (hygeinv (p, 4, 5, 2), [NaN NaN NaN NaN NaN]) ***** assert_equal (hygeinv (p, 4, 2, 2*[1 -1 NaN 1.1 1]), [NaN NaN NaN NaN NaN]) ***** assert_equal (hygeinv (p, 4, 2, 5), [NaN NaN NaN NaN NaN]) ***** assert_equal (hygeinv ([p(1:2) NaN p(4:5)], 4, 2, 2), [NaN 0 NaN 2 NaN]) ***** assert_equal (hygeinv ([p, NaN], 4, 2, 2), [NaN 0 1 2 NaN NaN]) ***** assert_equal (hygeinv (single ([p, NaN]), 4, 2, 2), single ([NaN 0 1 2 NaN NaN])) ***** assert_equal (hygeinv ([p, NaN], single (4), 2, 2), single ([NaN 0 1 2 NaN NaN])) ***** assert_equal (hygeinv ([p, NaN], 4, single (2), 2), single ([NaN 0 1 2 NaN NaN])) ***** assert_equal (hygeinv ([p, NaN], 4, 2, single (2)), single ([NaN 0 1 2 NaN NaN])) ***** error hygeinv () ***** error hygeinv (1) ***** error hygeinv (1,2) ***** error hygeinv (1,2,3) ***** error ... hygeinv (ones (2), ones (3), 1, 1) ***** error ... hygeinv (1, ones (2), ones (3), 1) ***** error ... hygeinv (1, 1, ones (2), ones (3)) ***** error hygeinv (int32 (2), 2, 2, 2) ***** error hygeinv (true, 2, 2, 2) ***** error hygeinv ('a', 2, 2, 2) ***** error hygeinv (i, 2, 2, 2) ***** error hygeinv (2, i, 2, 2) ***** error hygeinv (2, 2, i, 2) ***** error hygeinv (2, 2, 2, i) 29 tests, 29 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/ncx2rnd.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/ncx2rnd.m ***** assert_equal (size (ncx2rnd (1, 1)), [1, 1]) ***** assert_equal (size (ncx2rnd (1, ones (2, 1))), [2, 1]) ***** assert_equal (size (ncx2rnd (1, ones (2, 2))), [2, 2]) ***** assert_equal (size (ncx2rnd (ones (2, 1), 1)), [2, 1]) ***** assert_equal (size (ncx2rnd (ones (2, 2), 1)), [2, 2]) ***** assert_equal (size (ncx2rnd (1, 1, 3)), [3, 3]) ***** assert_equal (size (ncx2rnd (1, 1, [4, 1])), [4, 1]) ***** assert_equal (size (ncx2rnd (1, 1, 4, 1)), [4, 1]) ***** assert_equal (size (ncx2rnd (1, 1, 4, 1, 5)), [4, 1, 5]) ***** assert_equal (size (ncx2rnd (1, 1, 0, 1)), [0, 1]) ***** assert_equal (size (ncx2rnd (1, 1, 1, 0)), [1, 0]) ***** assert_equal (size (ncx2rnd (1, 1, 1, 2, 0, 5)), [1, 2, 0, 5]) ***** assert_equal (size (ncx2rnd (1, 1, [])), [0, 0]) ***** assert_equal (size (ncx2rnd (1, 1, [2, 0, 2, 1])), [2, 0, 2]) ***** assert_equal (size (ncx2rnd (1, 2, -1)), [0, 0]) ***** assert_equal (size (ncx2rnd (1, 2, [2, -1, 2])), [2, 0, 2]) ***** assert_equal (size (ncx2rnd (1, 2, 2, -1, 5)), [2, 0, 5]) ***** assert_equal (class (ncx2rnd (1, 1)), "double") ***** assert_equal (class (ncx2rnd (1, single (1))), "single") ***** assert_equal (class (ncx2rnd (1, single ([1, 1]))), "single") ***** assert_equal (class (ncx2rnd (single (1), 1)), "single") ***** assert_equal (class (ncx2rnd (single ([1, 1]), 1)), "single") ***** error ncx2rnd () ***** error ncx2rnd (1) ***** error ... ncx2rnd (ones (3), ones (2)) ***** error ... ncx2rnd (ones (2), ones (3)) ***** error ncx2rnd (i, 2) ***** error ncx2rnd (1, i) ***** error ... ncx2rnd (1, 2, 1.2) ***** error ... ncx2rnd (1, 2, ones (2)) ***** error ... ncx2rnd (1, 2, [2 0 2.5]) ***** error ... ncx2rnd (1, 2, 2, 1.5, 5) ***** error ... ncx2rnd (2, ones (2), 3) ***** error ... ncx2rnd (2, ones (2), [3, 2]) ***** error ... ncx2rnd (2, ones (2), 3, 2) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/laplacepdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/laplacepdf.m ***** demo ## Plot various PDFs from the Laplace distribution x = -10:0.01:10; y1 = laplacepdf (x, 0, 1); y2 = laplacepdf (x, 0, 2); y3 = laplacepdf (x, 0, 4); y4 = laplacepdf (x, -5, 4); plot (x, y1, '-b', x, y2, '-g', x, y3, '-r', x, y4, '-c') grid on xlim ([-10, 10]) ylim ([0, 0.6]) legend ({'μ = 0, β = 1', 'μ = 0, β = 2', ... 'μ = 0, β = 4', 'μ = -5, β = 4'}, 'location', 'northeast') title ('Laplace PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y x = [-Inf -log(2) 0 log(2) Inf]; y = [0, 1/4, 1/2, 1/4, 0]; ***** assert_equal (laplacepdf ([x, NaN], 0, 1), [y, NaN]) ***** assert_equal (laplacepdf (x, 0, [-2, -1, 0, 1, 2]), [nan(1, 3), 0.25, 0]) ***** assert_equal (laplacepdf (single ([x, NaN]), 0, 1), single ([y, NaN])) ***** assert_equal (laplacepdf ([x, NaN], single (0), 1), single ([y, NaN])) ***** assert_equal (laplacepdf ([x, NaN], 0, single (1)), single ([y, NaN])) ***** error laplacepdf () ***** error laplacepdf (1) ***** error ... laplacepdf (1, 2) ***** error laplacepdf (1, 2, 3, 4) ***** error ... laplacepdf (1, ones (2), ones (3)) ***** error ... laplacepdf (ones (2), 1, ones (3)) ***** error ... laplacepdf (ones (2), ones (3), 1) ***** error laplacepdf (int32 (2), 2, 3) ***** error laplacepdf (true, 2, 3) ***** error laplacepdf ('a', 2, 3) ***** error laplacepdf (i, 2, 3) ***** error laplacepdf (1, i, 3) ***** error laplacepdf (1, 2, i) 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/loglinv.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/loglinv.m ***** demo ## Plot various iCDFs from the log-logistic distribution p = 0.001:0.001:0.999; x1 = loglinv (p, log (1), 1/0.5); x2 = loglinv (p, log (1), 1); x3 = loglinv (p, log (1), 1/2); x4 = loglinv (p, log (1), 1/4); x5 = loglinv (p, log (1), 1/8); plot (p, x1, '-b', p, x2, '-g', p, x3, '-r', p, x4, '-c', p, x5, '-m') ylim ([0, 20]) grid on legend ({'σ = 2 (β = 0.5)', 'σ = 1 (β = 1)', 'σ = 0.5 (β = 2)', ... 'σ = 0.25 (β = 4)', 'σ = 0.125 (β = 8)'}, 'location', 'northwest') title ('Log-logistic iCDF') xlabel ('probability') ylabel ('x') text (0.03, 12.5, 'μ = 0 (α = 1), values of σ (β) as shown in legend') ***** shared p, out1, out2 p = [-1, 0, 0.2, 0.5, 0.8, 0.95, 1, 2]; out1 = [NaN, 0, 0.25, 1, 4, 19, Inf, NaN]; out2 = [NaN, 0, 0.0424732, 2.718282, 173.970037, 18644.695061, Inf, NaN]; ***** assert_equal (loglinv (p, 0, 1), out1, 1e-8) ***** assert_equal (loglinv (p, 0, 1), out1, 1e-8) ***** assert_equal (loglinv (p, 1, 3), out2, 1e-6) ***** assert_equal (class (loglinv (single (1), 2, 3)), "single") ***** assert_equal (class (loglinv (1, single (2), 3)), "single") ***** assert_equal (class (loglinv (1, 2, single (3))), "single") ***** error loglinv (1) ***** error loglinv (1, 2) ***** error ... loglinv (1, ones (2), ones (3)) ***** error ... loglinv (ones (2), 1, ones (3)) ***** error ... loglinv (ones (2), ones (3), 1) ***** error loglinv (int32 (2), 2, 3) ***** error loglinv (true, 2, 3) ***** error loglinv ('a', 2, 3) ***** error loglinv (i, 2, 3) ***** error loglinv (1, i, 3) ***** error loglinv (1, 2, i) 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/unidpdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/unidpdf.m ***** demo ## Plot various PDFs from the discrete uniform distribution x = 0:10; y1 = unidpdf (x, 5); y2 = unidpdf (x, 9); plot (x, y1, '*b', x, y2, '*g') grid on xlim ([0, 10]) ylim ([0, 0.25]) legend ({'N = 5', 'N = 9'}, 'location', 'northeast') title ('Discrete uniform PDF') xlabel ('values in x') ylabel ('density') ***** shared x, y x = [-1 0 1 2 10 11]; y = [0 0 0.1 0.1 0.1 0]; ***** assert_equal (unidpdf (x, 10*ones (1,6)), y) ***** assert_equal (unidpdf (x, 10), y) ***** assert_equal (unidpdf (x, 10*[0 NaN 1 1 1 1]), [NaN NaN y(3:6)]) ***** assert_equal (unidpdf ([x, NaN], 10), [y, NaN]) ***** assert_equal (unidpdf (single ([x, NaN]), 10), single ([y, NaN])) ***** assert_equal (unidpdf ([x, NaN], single (10)), single ([y, NaN])) ***** error unidpdf () ***** error unidpdf (1) ***** error ... unidpdf (ones (3), ones (2)) ***** error ... unidpdf (ones (2), ones (3)) ***** error unidpdf (true, 2) ***** error unidpdf ('a', 2) ***** assert_equal (class (unidpdf (int32 (2), 2)), 'double') ***** error unidpdf (i, 2) ***** error unidpdf (2, i) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/unidcdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/unidcdf.m ***** demo ## Plot various CDFs from the discrete uniform distribution x = 0:10; p1 = unidcdf (x, 5); p2 = unidcdf (x, 9); plot (x, p1, '*b', x, p2, '*g') grid on xlim ([0, 10]) ylim ([0, 1]) legend ({'N = 5', 'N = 9'}, 'location', 'southeast') title ('Discrete uniform CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y x = [0 1 2.5 10 11]; y = [0, 0.1 0.2 1.0 1.0]; ***** assert_equal (unidcdf (x, 10*ones (1,5)), y) ***** assert_equal (unidcdf (x, 10*ones (1,5), 'upper'), 1 - y) ***** assert_equal (unidcdf (x, 10), y) ***** assert_equal (unidcdf (x, 10, 'upper'), 1 - y) ***** assert_equal (unidcdf (x, 10*[0 1 NaN 1 1]), [NaN 0.1 NaN y(4:5)]) ***** assert_equal (unidcdf ([x(1:2) NaN Inf x(5)], 10), [y(1:2) NaN 1 y(5)]) ***** assert_equal (unidcdf ([x, NaN], 10), [y, NaN]) ***** assert_equal (unidcdf (single ([x, NaN]), 10), single ([y, NaN])) ***** assert_equal (unidcdf ([x, NaN], single (10)), single ([y, NaN])) ***** error unidcdf () ***** error unidcdf (1) ***** error unidcdf (1, 2, 3) ***** error unidcdf (1, 2, 'tail') ***** error ... unidcdf (ones (3), ones (2)) ***** error ... unidcdf (ones (2), ones (3)) ***** error unidcdf (true, 2) ***** error unidcdf ('a', 2) ***** assert_equal (class (unidcdf (int32 (2), 2)), 'double') ***** error unidcdf (i, 2) ***** error unidcdf (2, i) 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Distribution_Functions/logicdf.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Distribution_Functions/logicdf.m ***** demo ## Plot various CDFs from the logistic distribution x = -5:0.01:20; p1 = logicdf (x, 5, 2); p2 = logicdf (x, 9, 3); p3 = logicdf (x, 9, 4); p4 = logicdf (x, 6, 2); p5 = logicdf (x, 2, 1); plot (x, p1, '-b', x, p2, '-g', x, p3, '-r', x, p4, '-c', x, p5, '-m') grid on legend ({'μ = 5, σ = 2', 'μ = 9, σ = 3', 'μ = 9, σ = 4', ... 'μ = 6, σ = 2', 'μ = 2, σ = 1'}, 'location', 'southeast') title ('Logistic CDF') xlabel ('values in x') ylabel ('probability') ***** shared x, y x = [-Inf -log(3) 0 log(3) Inf]; y = [0, 1/4, 1/2, 3/4, 1]; ***** assert_equal (logicdf ([x, NaN], 0, 1), [y, NaN], eps) ***** assert_equal (logicdf (x, 0, [-2, -1, 0, 1, 2]), [nan(1, 3), 0.75, 1], eps) ***** assert_equal (logicdf (single ([x, NaN]), 0, 1), single ([y, NaN]), eps ('single')) ***** assert_equal (logicdf ([x, NaN], single (0), 1), single ([y, NaN]), eps ('single')) ***** assert_equal (logicdf ([x, NaN], 0, single (1)), single ([y, NaN]), eps ('single')) ***** error logicdf () ***** error logicdf (1) ***** error ... logicdf (1, 2) ***** error logicdf (1, 2, 3, 'tail') ***** error logicdf (1, 2, 3, 4) ***** error ... logicdf (1, ones (2), ones (3)) ***** error ... logicdf (ones (2), 1, ones (3)) ***** error ... logicdf (ones (2), ones (3), 1) ***** error logicdf (int32 (2), 2, 3) ***** error logicdf (true, 2, 3) ***** error logicdf ('a', 2, 3) ***** error logicdf (i, 2, 3) ***** error logicdf (1, i, 3) ***** error logicdf (1, 2, i) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Machine_Learning/templateKernel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/templateKernel.m ***** test # the default template names its learner and nothing else T = templateKernel (); assert_equal (class (T), 'struct'); assert_equal (T.Method, 'Kernel'); assert_equal (T.Type, 'classification'); assert_equal (numfields (T), 2); ***** test # an option given is stored under its own name, as it stands T = templateKernel ('Learner', 'logistic', 'NumExpansionDimensions', 128); assert_equal (numfields (T), 4); assert_equal (T.Learner, 'logistic'); assert_equal (T.NumExpansionDimensions, 128); ***** test # a name the learner does not know is not refused here T = templateKernel ('NoSuchOption', 42); assert_equal (T.NoSuchOption, 42); ***** error ... templateKernel ('KernelScale') ***** error ... templateKernel (42, 1) ***** error ... templateKernel ('not a name', 1) 6 tests, 6 passed, 0 known failure, 0 skipped [inst/Machine_Learning/ClassificationKNN.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/ClassificationKNN.m ***** demo ## Create a k-nearest neighbor classifier for Fisher's iris data with k = 5. ## Evaluate some model predictions on new data. load fisheriris x = meas; y = species; xc = [min(x); mean(x); max(x)]; obj = fitcknn (x, y, 'NumNeighbors', 5, 'Standardize', 1); [label, score, cost] = predict (obj, xc) ***** demo load fisheriris x = meas; y = species; obj = fitcknn (x, y, 'NumNeighbors', 5, 'Standardize', 1); ## Create a cross-validated model CVMdl = crossval (obj) ***** demo load fisheriris x = meas; y = species; covMatrix = cov (x); ## Fit the k-NN model using the 'mahalanobis' distance ## and the custom covariance matrix obj = fitcknn (x, y, 'NumNeighbors', 5, 'Distance','mahalanobis', ... 'Cov', covMatrix); ## Create a partition model using cvpartition Partition = cvpartition (size (x, 1), 'kfold', 12); ## Create cross-validated model using 'cvPartition' name-value argument CVMdl = crossval (obj, 'cvPartition', Partition) ## Access the trained model from first fold of cross-validation CVMdl.Trained{1} ***** demo X = [1, 2; 3, 4; 5, 6]; Y = {'A'; 'B'; 'A'}; model = fitcknn (X, Y); customLossFun = @(C, S, W, Cost) sum (W .* sum (abs (C - S), 2)); ## Calculate loss using custom loss function L = loss (model, X, Y, 'LossFun', customLossFun) ***** demo X = [1, 2; 3, 4; 5, 6]; Y = {'A'; 'B'; 'A'}; model = fitcknn (X, Y); ## Calculate loss using 'mincost' loss function L = loss (model, X, Y, 'LossFun', 'mincost') ***** demo X = [1, 2; 3, 4; 5, 6]; Y = ['1'; '2'; '3']; model = fitcknn (X, Y); X_test = [3, 3; 5, 7]; Y_test = ['1'; '2']; ## Specify custom Weights W = [1; 2]; L = loss (model, X_test, Y_test, 'LossFun', 'logit', 'Weights', W); ***** demo load fisheriris mdl = fitcknn (meas, species); X = mean (meas); Y = {'versicolor'}; m = margin (mdl, X, Y) ***** demo X = [1, 2; 4, 5; 7, 8; 3, 2]; Y = [2; 1; 3; 2]; ## Train the model mdl = fitcknn (X, Y); ## Specify Vars and Labels Vars = 1; Labels = 2; ## Calculate partialDependence [pd, x, y] = partialDependence (mdl, Vars, Labels); ***** demo X = [1, 2; 4, 5; 7, 8; 3, 2]; Y = [2; 1; 3; 2]; ## Train the model mdl = fitcknn (X, Y); ## Specify Vars and Labels Vars = 1; Labels = 1; queryPoints = linspace (0, 1, 3)'; ## Calculate partialDependence using queryPoints [pd, x, y] = partialDependence (mdl, Vars, Labels, 'QueryPoints', ... queryPoints) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; f = @(d1,d2) sqrt (sum ((d1 - d2) .^ 2, 2)); a = ClassificationKNN (x, y, 'Distance', f); ***** test # A row missing a predictor takes the class of largest prior X = [(1:10)', mod((1:10)', 3)]; y = [1; 1; 1; 1; 1; 1; 2; 2; 2; 2]; Mdl = ClassificationKNN (X, y); [label, score, cost] = predict (Mdl, [NaN, 1]); assert_equal (label, 1); assert_equal (score, [NaN, NaN]); assert_equal (cost, [NaN, NaN]); Mdl = ClassificationKNN (X, y, 'Prior', [0.3, 0.7]); assert_equal (predict (Mdl, [NaN, 1]), 2); ***** test load fisheriris X = meas(1:130,[1, 3]); Y = species(1:130); k = (1:130)'; w = (1 + mod (k, 4)) .* (1 + (k > 50) + 2 * (k > 100)); Q = [5, 1.5; 6, 4.5; 6.5, 5.2; 5.8, 4.9; 6.3, 4.9; 5.7, 4.5]; Mdl = fitcknn (X, Y, 'Weights', w, 'NumNeighbors', 5); assert_equal (Mdl.Prior, [0.185185185185185, 0.37037037037037, ... 0.444444444444444], 1e-14); assert_equal (Mdl.W([1, 51, 101])', [2, 8, 8] / 675, 1e-15); [~, s] = predict (Mdl, Q); assert_equal (s, [1, 0, 0; 0, 1, 0; 0, 0.157894736842105, 0.842105263157895; 0, 0.133333333333333, 0.866666666666667; 0, 0.25, 0.75; 0, 1, 0], 1e-14); ***** test load fisheriris X = meas(1:130,[1, 3]); Y = species(1:130); k = (1:130)'; w = (1 + mod (k, 4)) .* (1 + (k > 50) + 2 * (k > 100)); Q = [5, 1.5; 6, 4.5; 6.5, 5.2; 5.8, 4.9; 6.3, 4.9; 5.7, 4.5]; Mdl = fitcknn (X, Y, 'Weights', w, 'NumNeighbors', 5, 'Prior', 'uniform'); [~, s] = predict (Mdl, Q); assert_equal (s, [1, 0, 0; 0, 1, 0; 0, 0.183673469387755, 0.816326530612245; 0, 0.155844155844156, 0.844155844155844; 0, 0.285714285714286, 0.714285714285714; 0, 1, 0], 1e-14); ***** test load fisheriris X = meas(1:130,[1, 3]); Y = species(1:130); k = (1:130)'; w = (1 + mod (k, 4)) .* (1 + (k > 50) + 2 * (k > 100)); Q = [5, 1.5; 6, 4.5; 6.5, 5.2; 5.8, 4.9; 6.3, 4.9; 5.7, 4.5]; Mdl = fitcknn (X, Y, 'NumNeighbors', 5, 'Prior', 'uniform'); [~, s] = predict (Mdl, Q); assert_equal (s, [1, 0, 0; 0, 1, 0; 0, 0.130434782608696, 0.869565217391304; 0, 0.130434782608696, 0.869565217391304; 0, 0.285714285714286, 0.714285714285714; 0, 1, 0], 1e-14); ***** test load fisheriris X = meas(1:130,[1, 3]); Y = species(1:130); k = (1:130)'; w = (1 + mod (k, 4)) .* (1 + (k > 50) + 2 * (k > 100)); Q = [5, 1.5; 6, 4.5; 6.5, 5.2; 5.8, 4.9; 6.3, 4.9; 5.7, 4.5]; Mdl = fitcknn (X, Y, 'Weights', w, 'NumNeighbors', 5, ... 'DistanceWeight', 'inverse'); [~, s] = predict (Mdl, Q); assert_equal (s, [1, 0, 0; 0, 1, 0; 0, 0.080216792482354, 0.919783207517646; 0, 0.165685424949237, 0.834314575050763; 0, 0.5, 0.5; 0, 1, 0], 1e-14); ***** test load fisheriris X = meas(1:130,[1, 3]); Y = species(1:130); k = (1:130)'; w = (1 + mod (k, 4)) .* (1 + (k > 50) + 2 * (k > 100)); Mdl = fitcknn (X, Y, 'Weights', w, 'NumNeighbors', 5, 'Standardize', true); assert_equal (Mdl.Mu, [6.06414814814815, 4.35066666666667], 1e-13); assert_equal (Mdl.Sigma, [0.872766097166902, 1.62323758619346], 1e-13); ***** test load fisheriris X = meas(1:130,[1, 3]); Y = species(1:130); k = (1:130)'; w = (1 + mod (k, 4)) .* (1 + (k > 50) + 2 * (k > 100)); Q = [5, 1.5; 6, 4.5; 6.5, 5.2; 5.8, 4.9; 6.3, 4.9; 5.7, 4.5]; Mdl = fitcknn (X, Y, 'Weights', w, 'NumNeighbors', 5); Mdl.Prior = [0.2, 0.3, 0.5]; assert_equal (Mdl.W([1, 51, 101])', [0.0032, 0.0096, ... 0.0133333333333333], 1e-15); [~, s] = predict (Mdl, Q); assert_equal (s, [1, 0, 0; 0, 1, 0; 0, 0.118942731277533, 0.881057268722467; 0, 0.0997229916897507, 0.900277008310249; 0, 0.193548387096774, 0.806451612903226; 0, 1, 0], 1e-14); ***** test load fisheriris X = meas(1:130,[1, 3]); Y = species(1:130); k = (1:130)'; w = (1 + mod (k, 4)) .* (1 + (k > 50) + 2 * (k > 100)); Mdl = fitcknn (X, Y, 'Weights', w, 'NumNeighbors', 5); assert_equal (resubLoss (Mdl), 0.0681481481481481, 1e-14); assert_equal (loss (Mdl, X, Y), 0.0592592592592593, 1e-14); w([2, 60]) = 0; Mdl = fitcknn (X, Y, 'Weights', w, 'NumNeighbors', 5); assert_equal (Mdl.NumObservations, 128); ***** test load fisheriris X = meas(1:130,[1, 3]); Y = species(1:130); Mdl = fitcknn (X, Y, 'NumNeighbors', 4); [~, s] = predict (Mdl, [6.3, 4.9]); assert_equal (s, [0, 0.5, 0.5], 1e-15); k = (1:130)'; w = (1 + mod (k, 4)) .* (1 + (k > 50) + 2 * (k > 100)); Mdl = fitcknn (X, Y, 'Weights', w, 'NumNeighbors', 5); assert_equal (resubEdge (Mdl), 0.86407659007327, 1e-13); ***** test load fisheriris X = meas(51:150, 1:2); ys = species(51:150); yc = categorical (ys); Mdl = fitcknn (X, yc); assert_equal (loss (Mdl, X, ys), 0.12, 1e-15); assert_equal (loss (Mdl, X, string (ys)), 0.12, 1e-15); assert_equal (loss (Mdl, X, yc), 0.12, 1e-15); assert_equal (numel (margin (Mdl, X, ys)), 100); assert_equal (edge (Mdl, X, ys), edge (Mdl, X, yc), 1e-15); assert_equal (loss (fitcknn (X, ys), X, yc), 0.12, 1e-15); ***** error ... fitcknn ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', 'a') ***** error ... fitcknn ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', ones (2, 2)) ***** error ... fitcknn ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', [1, 2]) ***** error ... fitcknn ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', -ones (4, 1)) ***** error ... x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; f = @(d1,d2) sqrt (dot (d1, d2)); a = ClassificationKNN (x, y, 'Distance', f); ***** error ... x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; f = @(d1,d2) sqrt (sum ((d1 - d2) .^ 2, 1)); a = ClassificationKNN (x, y, 'Distance', f); ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; f = @(d1,d2) sqrt (sum ((d1 - d2) .^ 2, 2)); a = ClassificationKNN (x, y, 'NSMethod', 'exhaustive', 'Distance', ... 'cityblock'); a.Distance = f; assert_equal (a.Distance, f); assert_equal (isempty (a.DistParameter), true); ***** error ... x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = ClassificationKNN (x, y, 'NSMethod', 'exhaustive'); a.Distance = @(d1,d2) sqrt (dot (d1, d2)); ***** error ... x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = ClassificationKNN (x, y, 'NSMethod', 'exhaustive'); a.Distance = @(d1,d2) sqrt (sum ((d1 - d2) .^ 2, 1)); ***** error ... x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = ClassificationKNN (x, y); a.Distance = @(d1,d2) sqrt (sum ((d1 - d2) .^ 2, 2)); ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = ClassificationKNN (x, y); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.X, a.Y, a.NumNeighbors}, {x, y, 1}) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = ClassificationKNN (x, y, 'NSMethod', 'exhaustive'); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.X, a.Y, a.NumNeighbors}, {x, y, 1}) assert_equal ({a.NSMethod, a.Distance}, {'exhaustive', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; k = 10; a = ClassificationKNN (x, y, 'NumNeighbors' ,k); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.X, a.Y, a.NumNeighbors}, {x, y, 4}) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = ones (4, 11); y = ['a'; 'a'; 'b'; 'b']; k = 10; a = ClassificationKNN (x, y, 'NumNeighbors' ,k); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.X, a.Y, a.NumNeighbors}, {x, y, 4}) assert_equal ({a.NSMethod, a.Distance}, {'exhaustive', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; k = 10; a = ClassificationKNN (x, y, 'NumNeighbors' ,k, 'NSMethod', 'exhaustive'); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.X, a.Y, a.NumNeighbors}, {x, y, 4}) assert_equal ({a.NSMethod, a.Distance}, {'exhaustive', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; k = 10; a = ClassificationKNN (x, y, 'NumNeighbors' ,k, 'Distance', 'hamming'); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.X, a.Y, a.NumNeighbors}, {x, y, 4}) assert_equal ({a.NSMethod, a.Distance}, {'exhaustive', 'hamming'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; weights = ones (4,1); a = ClassificationKNN (x, y, 'Standardize', 1); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.X, a.Y, a.NumNeighbors}, {x, y, 1}) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) assert_equal ({a.Sigma}, {std(x, [], 1)}) assert_equal ({a.Mu}, {[3.75, 4.25, 4.75]}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; weights = ones (4,1); a = ClassificationKNN (x, y, 'Standardize', false); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.X, a.Y, a.NumNeighbors}, {x, y, 1}) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) assert_equal ({a.Sigma}, {[]}) assert_equal ({a.Mu}, {[]}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; s = ones (1, 3); a = ClassificationKNN (x, y, 'Scale' , s, 'Distance', 'seuclidean'); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.DistParameter}, {s}) assert_equal ({a.NSMethod, a.Distance}, {'exhaustive', 'seuclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = ClassificationKNN (x, y, 'Exponent' , 5, 'Distance', 'minkowski'); assert_equal (class (a), "ClassificationKNN"); assert_equal (a.DistParameter, 5) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'minkowski'}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = ClassificationKNN (x, y, 'Exponent' , 5, 'Distance', 'minkowski', ... 'NSMethod', 'exhaustive'); assert_equal (class (a), "ClassificationKNN"); assert_equal (a.DistParameter, 5) assert_equal ({a.NSMethod, a.Distance}, {'exhaustive', 'minkowski'}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = ClassificationKNN (x, y, 'BucketSize' , 20, 'distance', 'mahalanobis'); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.NSMethod, a.Distance}, {'exhaustive', 'mahalanobis'}) assert_equal ({a.BucketSize}, {20}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = ClassificationKNN (x, y, 'IncludeTies', true); assert_equal (class (a), "ClassificationKNN"); assert_equal (a.IncludeTies, true); assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = ClassificationKNN (x, y); assert_equal (class (a), "ClassificationKNN"); assert_equal (a.IncludeTies, false); assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = ClassificationKNN (x, y); assert_equal (class (a), "ClassificationKNN") assert_equal (a.Prior, [0.5, 0.5]) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; prior = [0.5, 0.5]; a = ClassificationKNN (x, y, 'Prior', 'empirical'); assert_equal (class (a), "ClassificationKNN") assert_equal (a.Prior, prior) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'a'; 'b']; prior = [0.75, 0.25]; a = ClassificationKNN (x, y, 'Prior', 'empirical'); assert_equal (class (a), "ClassificationKNN") assert_equal (a.Prior, prior) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'a'; 'b']; prior = [0.5, 0.5]; a = ClassificationKNN (x, y, 'Prior', 'uniform'); assert_equal (class (a), "ClassificationKNN") assert_equal (a.Prior, prior) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; cost = [0, 1; 1, 0]; a = ClassificationKNN (x, y, 'Cost', cost); assert_equal (class (a), "ClassificationKNN") assert_equal (a.Cost, [0, 1; 1, 0]) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; cost = [0, 1; 1, 0]; a = ClassificationKNN (x, y, 'Cost', cost, 'Distance', 'hamming' ); assert_equal (class (a), "ClassificationKNN") assert_equal (a.Cost, [0, 1; 1, 0]) assert_equal ({a.NSMethod, a.Distance}, {'exhaustive', 'hamming'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2; 3, 4; 5,6; 5, 8]; y = {'9'; '9'; '6'; '7'}; a = ClassificationKNN (x, y); assert_equal (a.Prior, [0.25, 0.25, 0.5]) ***** test load fisheriris x = meas; y = species; ClassNames = {'setosa', 'versicolor', 'virginica'}; a = ClassificationKNN (x, y, 'ClassNames', ClassNames); assert_equal (a.ClassNames, ClassNames') ***** test # A categorical 'ClassNames' keeps only the classes it names load fisheriris Mdl = ClassificationKNN (meas, categorical (species), 'ClassNames', ... categorical ({'versicolor'; 'virginica'})); assert_equal (Mdl.NumObservations, 100); assert_equal (class (Mdl.ClassNames), 'categorical'); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcknn (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcknn (Xch, Ycell); assert_equal (size (Mc.ClassNames), [2, 10]); assert_equal (cellstr (Mc.ClassNames), Ms.ClassNames); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcknn (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcknn (Xch, Ycell); pch = predict (Mc, Xch); assert_equal (columns (pch), 10); assert_equal (cellstr (pch), predict (Ms, Xch)); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcknn (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcknn (Xch, Ycell); assert_equal (loss (Mc, Xch, Ych), loss (Ms, Xch, Ycell), 1e-12); assert_equal (margin (Mc, Xch, Ych), margin (Ms, Xch, Ycell), 1e-12); assert_equal (edge (Mc, Xch, Ych), edge (Ms, Xch, Ycell), 1e-12); ***** test Xpad = [1 2; 3 4; 1.1 2.1; 3.1 4.1; 1.2 2.2; 3.2 4.2]; Ypad = char ({"ab", "abcd", "ab", "abcd", "ab", "abcd"}); rand ("state", 1); randn ("state", 1); Mp = fitcknn (Xpad, Ypad); assert_equal (size (Mp.ClassNames), [2, 4]); assert_equal (Mp.ClassNames(1,:), "ab "); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); Xmiss = Xch; Xmiss(3,2) = NaN; rand ("state", 1); randn ("state", 1); Md = fitcknn (Xmiss, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcknn (Xmiss, Ycell); assert_equal (size (Md.ClassNames), [2, 10]); assert_equal (cellstr (Md.ClassNames), Ms.ClassNames); ***** test load fisheriris rand ("state", 1); randn ("state", 1); Mf = fitcknn (meas, char (species), ... "ClassNames", char ({"versicolor", "virginica"})); assert_equal (rows (Mf.ClassNames), 2); assert_equal (cellstr (Mf.ClassNames), {"versicolor"; "virginica"}); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcknn (Xch, Ych); fname = tempname (); savemodel (Mc, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.ClassNames, Mc.ClassNames); assert_equal (predict (M2, Xch), predict (Mc, Xch)); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcknn (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcknn (Xch, Ycell); rand ("state", 2); cvc = crossval (Mc, "KFold", 3); rand ("state", 2); cvs = crossval (Ms, "KFold", 3); assert_equal (cellstr (kfoldPredict (cvc)), kfoldPredict (cvs)); ***** test ## CacheSize defaults to 1000 and is reported, where MATLAB hides it. X = [1, 2; 3, 4; 5, 6; 7, 8; 2, 2]; Mdl = fitcknn (X, [1; 1; 2; 2; 1]); assert_equal (Mdl.CacheSize, 1000); assert_equal (any (strcmp (properties (Mdl), 'CacheSize')), true); ***** test ## It is settable after fitting and through fitcknn alike. X = [1, 2; 3, 4; 5, 6; 7, 8; 2, 2]; Mdl = fitcknn (X, [1; 1; 2; 2; 1]); Mdl.CacheSize = 5000; assert_equal (Mdl.CacheSize, 5000); Mdl2 = fitcknn (X, [1; 1; 2; 2; 1], "CacheSize", 250); assert_equal (Mdl2.CacheSize, 250); ***** test ## It changes nothing: the model keeps no cache to size. X = [1, 2; 3, 4; 5, 6; 7, 8; 2, 2]; y = [1; 1; 2; 2; 1]; Mdl = fitcknn (X, y, "CacheSize", 1); Mdl2 = fitcknn (X, y, "CacheSize", 1e6); [l1, s1] = predict (Mdl, X); [l2, s2] = predict (Mdl2, X); assert_equal (l1, l2); assert_equal (s1, s2); ***** error ... fitcknn (ones (5, 2), [1; 1; 1; 2; 2], "CacheSize", 0) ***** error ... fitcknn (ones (5, 2), [1; 1; 1; 2; 2], "CacheSize", [1, 2]) ***** error ... fitcknn (ones (5, 2), [1; 1; 1; 2; 2], "CacheSize", Inf) ***** test Mdl = fitcknn (ones (5, 2), [1; 1; 1; 2; 2]); fail ("Mdl.CacheSize = -1", ... "ClassificationKNN: 'CacheSize' must be a positive finite scalar."); ***** error ClassificationKNN () ***** error ... ClassificationKNN (ones (4, 1)) ***** error ... ClassificationKNN (ones (4,2), ones (1,4)) ***** error ... ClassificationKNN (ones (5,3), ones (5,1), 'standardize', 'a') ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'scale', [1 1], 'standardize', true) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'PredictorNames', ['A']) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'PredictorNames', 'A') ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'PredictorNames', {'A', 'B', 'C'}) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'ResponseName', {'Y'}) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'ResponseName', 1) ***** error ... ClassificationKNN (ones (10,2), ones (10,1), 'ClassNames', @(x)x) ***** error ... ClassificationKNN (ones (10,2), ones (10,1), 'ClassNames', {1}) ***** error ... ClassificationKNN (ones (10,2), ones (10,1), 'ClassNames', [1, 2]) ***** error ... ClassificationKNN (ones (5,2), ['a';'b';'a';'a';'b'], 'ClassNames', ['a';'c']) ***** error ... ClassificationKNN (ones (5,2), {'a';'b';'a';'a';'b'}, 'ClassNames', {'a','c'}) ***** error ... ClassificationKNN (ones (10,2), logical (ones (10,1)), 'ClassNames', [true, false]) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'BreakTies', 1) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'BreakTies', {'1'}) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'BreakTies', 'some') ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Prior', {'1', '2'}) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Cost', [1, 2]) ***** error ... Mdl = fitcknn ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]); Mdl.Cost = 1:4; ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Cost', 'string') ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Cost', {eye(2)}) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'NumNeighbors', 0) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'NumNeighbors', 15.2) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'NumNeighbors', 'asd') ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Distance', 'somemetric') ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Distance', ... @(v,m)sqrt (repmat (v,rows (m),1)-m,2)) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Distance', ... @(v,m)sqrt (sum (sumsq (repmat (v,rows (m),1)-m,2)))) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Distance', [1 2 3]) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Distance', {'mahalanobis'}) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Distance', logical (5)) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'DistanceWeight', @(x)sum (x)) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'DistanceWeight', 'text') ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'DistanceWeight', [1 2 3]) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Scale', 'scale') ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Scale', {[1 2 3]}) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'standardize', true, 'scale', [1 1]) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Cov', ones (2), 'Distance', 'mahalanobis') ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'scale', [1 1], 'Cov', ones (2)) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Exponent', 12.5) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Exponent', -3) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Exponent', 'three') ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Exponent', {3}) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'NSMethod', {'kdtree'}) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'NSMethod', 3) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'NSMethod', 'some') ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'IncludeTies', 'some') ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'BucketSize', 42.5) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'BucketSize', -50) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'BucketSize', 'some') ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'BucketSize', {50}) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'some', 'some') ***** error ... ClassificationKNN ([1;2;3;'a';4], ones (5,1)) ***** error ... ClassificationKNN ([1;2;3;Inf;4], ones (5,1)) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Prior', [1 2]) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Cost', [1 2; 1 3]) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Scale', [1 1]) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Scale', [1 1 1], 'Distance', 'seuclidean') ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Scale', [1 -1], 'Distance', 'seuclidean') ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Cov', eye (2)) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Cov', eye (3), 'Distance', 'mahalanobis') ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Exponent', 3) ***** error ... ClassificationKNN (ones (5,2), ones (5,1), 'Distance', 'hamming', 'NSMethod', 'kdtree') ***** shared x, y load fisheriris x = meas; y = species; ***** test xc = [min(x); mean(x); max(x)]; obj = fitcknn (x, y, 'NumNeighbors', 5); [l, s, c] = predict (obj, xc); assert_equal (l, {'setosa'; 'versicolor'; 'virginica'}) assert_equal (s, [1, 0, 0; 0, 1, 0; 0, 0, 1]) assert_equal (c, [0, 1, 1; 1, 0, 1; 1, 1, 0]) ***** test xc = [min(x); mean(x); max(x)]; obj = fitcknn (x, categorical (y), 'NumNeighbors', 5); l = predict (obj, xc); assert_equal (l, categorical ({'setosa'; 'versicolor'; 'virginica'})) ***** test xc = [min(x); mean(x); max(x)]; obj = fitcknn (x, y, 'NumNeighbors', 5, 'Standardize', 1); [l, s, c] = predict (obj, xc); assert_equal (l, {'versicolor'; 'versicolor'; 'virginica'}) assert_equal (s, [0.4, 0.6, 0; 0, 1, 0; 0, 0, 1], 1e-15) assert_equal (c, [0.6, 0.4, 1; 1, 0, 1; 1, 1, 0], 1e-15) ***** test xc = [min(x); mean(x); max(x)]; obj = fitcknn (x, y, 'NumNeighbors', 10, 'distance', 'mahalanobis'); [l, s, c] = predict (obj, xc); assert_equal (s, [0.3, 0.7, 0; 0, 0.9, 0.1; 0.2, 0.2, 0.6], 1e-4) assert_equal (c, [0.7, 0.3, 1; 1, 0.1, 0.9; 0.8, 0.8, 0.4], 1e-4) ***** test xc = [min(x); mean(x); max(x)]; obj = fitcknn (x, y, 'NumNeighbors', 10, 'distance', 'cosine'); [l, s, c] = predict (obj, xc); assert_equal (l, {'setosa'; 'versicolor'; 'virginica'}) assert_equal (s, [1, 0, 0; 0, 1, 0; 0, 0.3, 0.7], 1e-4) assert_equal (c, [0, 1, 1; 1, 0, 1; 1, 0.7, 0.3], 1e-4) ***** test xc = [5.2, 4.1, 1.5, 0.1; 5.1, 3.8, 1.9, 0.4; ... 5.1, 3.8, 1.5, 0.3; 4.9, 3.6, 1.4, 0.1]; obj = fitcknn (x, y, 'NumNeighbors', 5); [l, s, c] = predict (obj, xc); assert_equal (l, {'setosa'; 'setosa'; 'setosa'; 'setosa'}) assert_equal (s, [1, 0, 0; 1, 0, 0; 1, 0, 0; 1, 0, 0]) assert_equal (c, [0, 1, 1; 0, 1, 1; 0, 1, 1; 0, 1, 1]) ***** test xc = [5, 3, 5, 1.45]; obj = fitcknn (x, y, 'NumNeighbors', 5); [l, s, c] = predict (obj, xc); assert_equal (l, {'versicolor'}) assert_equal (s, [0, 0.6, 0.4], 1e-4) assert_equal (c, [1, 0.4, 0.6], 1e-4) ***** test xc = [5, 3, 5, 1.45]; obj = fitcknn (x, y, 'NumNeighbors', 10, 'distance', 'minkowski', 'Exponent', 5); [l, s, c] = predict (obj, xc); assert_equal (l, {'versicolor'}) assert_equal (s, [0, 0.5, 0.5], 1e-4) assert_equal (c, [1, 0.5, 0.5], 1e-4) ***** test xc = [5, 3, 5, 1.45]; obj = fitcknn (x, y, 'NumNeighbors', 10, 'distance', 'jaccard'); [l, s, c] = predict (obj, xc); assert_equal (l, {'setosa'}) assert_equal (s, [0.9, 0.1, 0], 1e-4) assert_equal (c, [0.1, 0.9, 1], 1e-4) ***** test xc = [5, 3, 5, 1.45]; obj = fitcknn (x, y, 'NumNeighbors', 10, 'distance', 'mahalanobis'); [l, s, c] = predict (obj, xc); assert_equal (l, {'versicolor'}) assert_equal (s, [0.1000, 0.5000, 0.4000], 1e-4) assert_equal (c, [0.9000, 0.5000, 0.6000], 1e-4) ***** test xc = [5, 3, 5, 1.45]; obj = fitcknn (x, y, 'NumNeighbors', 5, 'distance', 'jaccard'); [l, s, c] = predict (obj, xc); assert_equal (l, {'setosa'}) assert_equal (s, [0.8, 0.2, 0], 1e-4) assert_equal (c, [0.2, 0.8, 1], 1e-4) ***** test xc = [5, 3, 5, 1.45]; obj = fitcknn (x, y, 'NumNeighbors', 5, 'distance', 'seuclidean'); [l, s, c] = predict (obj, xc); assert_equal (l, {'versicolor'}) assert_equal (s, [0, 1, 0], 1e-4) assert_equal (c, [1, 0, 1], 1e-4) ***** test xc = [5, 3, 5, 1.45]; obj = fitcknn (x, y, 'NumNeighbors', 10, 'distance', 'chebychev'); [l, s, c] = predict (obj, xc); assert_equal (l, {'versicolor'}) assert_equal (s, [0, 0.7, 0.3], 1e-4) assert_equal (c, [1, 0.3, 0.7], 1e-4) ***** test xc = [5, 3, 5, 1.45]; obj = fitcknn (x, y, 'NumNeighbors', 10, 'distance', 'cityblock'); [l, s, c] = predict (obj, xc); assert_equal (l, {'versicolor'}) assert_equal (s, [0, 0.6, 0.4], 1e-4) assert_equal (c, [1, 0.4, 0.6], 1e-4) ***** test xc = [5, 3, 5, 1.45]; obj = fitcknn (x, y, 'NumNeighbors', 10, 'distance', 'cosine'); [l, s, c] = predict (obj, xc); assert_equal (l, {'virginica'}) assert_equal (s, [0, 0.1, 0.9], 1e-4) assert_equal (c, [1, 0.9, 0.1], 1e-4) ***** test xc = [5, 3, 5, 1.45]; obj = fitcknn (x, y, 'NumNeighbors', 10, 'distance', 'correlation'); [l, s, c] = predict (obj, xc); assert_equal (l, {'virginica'}) assert_equal (s, [0, 0.1, 0.9], 1e-4) assert_equal (c, [1, 0.9, 0.1], 1e-4) ***** test xc = [5, 3, 5, 1.45]; obj = fitcknn (x, y, 'NumNeighbors', 30, 'distance', 'spearman'); [l, s, c] = predict (obj, xc); assert_equal (l, {'versicolor'}) assert_equal (s, [0, 1, 0], 1e-4) assert_equal (c, [1, 0, 1], 1e-4) ***** test xc = [5, 3, 5, 1.45]; obj = fitcknn (x, y, 'NumNeighbors', 30, 'distance', 'hamming'); [l, s, c] = predict (obj, xc); assert_equal (l, {'setosa'}) assert_equal (s, [0.4333, 0.3333, 0.2333], 1e-4) assert_equal (c, [0.5667, 0.6667, 0.7667], 1e-4) ***** test xc = [5, 3, 5, 1.45]; obj = fitcknn (x, y, 'NumNeighbors', 5, 'distance', 'hamming'); [l, s, c] = predict (obj, xc); assert_equal (l, {'setosa'}) assert_equal (s, [0.8, 0.2, 0], 1e-4) assert_equal (c, [0.2, 0.8, 1], 1e-4) ***** test xc = [min(x); mean(x); max(x)]; obj = fitcknn (x, y, 'NumNeighbors', 10, 'distance', 'correlation'); [l, s, c] = predict (obj, xc); assert_equal (l, {'setosa'; 'versicolor'; 'virginica'}) assert_equal (s, [1, 0, 0; 0, 1, 0; 0, 0.4, 0.6], 1e-4) assert_equal (c, [0, 1, 1; 1, 0, 1; 1, 0.6, 0.4], 1e-4) ***** test xc = [min(x); mean(x); max(x)]; obj = fitcknn (x, y, 'NumNeighbors', 10, 'distance', 'hamming'); [l, s, c] = predict (obj, xc); assert_equal (l, {'setosa';'setosa';'setosa'}) assert_equal (s, [0.9, 0.1, 0; 1, 0, 0; 0.5, 0, 0.5], 1e-4) assert_equal (c, [0.1, 0.9, 1; 0, 1, 1; 0.5, 1, 0.5], 1e-4) ***** error ... predict (ClassificationKNN (ones (4,2), ones (4,1))) ***** error ... predict (ClassificationKNN (ones (4,2), ones (4,1)), []) ***** error ... predict (ClassificationKNN (ones (4,2), ones (4,1)), 1) ***** test load fisheriris model = fitcknn (meas, species, 'NumNeighbors', 5); X = mean (meas); Y = {'versicolor'}; L = loss (model, X, Y); assert_equal (L, 0) ***** test load fisheriris model = fitcknn (meas, species, 'NumNeighbors', 5); L = loss (model, meas, species, 'LossFun', 'binodeviance'); assert_equal (L, 0.1413, 1e-4) ***** test load fisheriris model = fitcknn (meas, species); L = loss (model, meas, species, 'LossFun', 'binodeviance'); assert_equal (L, 0.1269, 1e-4) ***** test X = [1, 2; 3, 4; 5, 6]; Y = {'A'; 'B'; 'A'}; model = fitcknn (X, Y); X_test = [1, 6; 3, 3]; Y_test = {'A'; 'B'}; L = loss (model, X_test, Y_test); assert_equal (abs (L - 0.6667) > 1e-5, true) ***** test X = [1, 2; 3, 4; 5, 6]; Y = {'A'; 'B'; 'A'}; model = fitcknn (X, Y); X_with_nan = [1, 2; NaN, 4]; Y_test = {'A'; 'B'}; L = loss (model, X_with_nan, Y_test); assert_equal (abs (L - 0.3333) < 1e-4, true) ***** test X = [1, 2; 3, 4; 5, 6]; Y = {'A'; 'B'; 'A'}; model = fitcknn (X, Y); X_with_nan = [1, 2; NaN, 4]; Y_test = {'A'; 'B'}; L = loss (model, X_with_nan, Y_test, 'LossFun', 'logit'); assert_equal (isnan (L), true) ***** test X = [1, 2; 3, 4; 5, 6]; Y = {'A'; 'B'; 'A'}; model = fitcknn (X, Y); customLossFun = @(C, S, W, Cost) sum (W .* sum (abs (C - S), 2)); L = loss (model, X, Y, 'LossFun', customLossFun); assert_equal (L, 0) ***** test X = [1, 2; 3, 4; 5, 6]; Y = [1; 2; 1]; model = fitcknn (X, Y); L = loss (model, X, Y, 'LossFun', 'classiferror'); assert_equal (L, 0) ***** test X = [1, 2; 3, 4; 5, 6]; Y = [true; false; true]; model = fitcknn (X, Y); L = loss (model, X, Y, 'LossFun', 'binodeviance'); assert_equal (abs (L - 0.1269) < 1e-4, true) ***** test X = [1, 2; 3, 4; 5, 6]; Y = ['1'; '2'; '1']; model = fitcknn (X, Y); L = loss (model, X, Y, 'LossFun', 'classiferror'); assert_equal (L, 0) ***** test X = [1, 2; 3, 4; 5, 6]; Y = ['1'; '2'; '3']; model = fitcknn (X, Y); X_test = [3, 3]; Y_test = ['1']; L = loss (model, X_test, Y_test, 'LossFun', 'quadratic'); assert_equal (L, 1) ***** test X = [1, 2; 3, 4; 5, 6]; Y = ['1'; '2'; '3']; model = fitcknn (X, Y); X_test = [3, 3; 5, 7]; Y_test = ['1'; '2']; L = loss (model, X_test, Y_test, 'LossFun', 'classifcost'); assert_equal (L, 1) ***** test X = [1, 2; 3, 4; 5, 6]; Y = ['1'; '2'; '3']; model = fitcknn (X, Y); X_test = [3, 3; 5, 7]; Y_test = ['1'; '2']; L = loss (model, X_test, Y_test, 'LossFun', 'hinge'); assert_equal (L, 1) ***** test X = [1, 2; 3, 4; 5, 6]; Y = ['1'; '2'; '3']; model = fitcknn (X, Y); X_test = [3, 3; 5, 7]; Y_test = ['1'; '2']; W = [1; 2]; L = loss (model, X_test, Y_test, 'LossFun', 'logit', 'Weights', W); assert_equal (abs (L - 0.6931) < 1e-4, true) ***** error ... loss (ClassificationKNN (ones (4,2), ones (4,1))) ***** error ... loss (ClassificationKNN (ones (4,2), ones (4,1)), ones (4,2)) ***** error ... loss (ClassificationKNN (ones (40,2), randi ([1, 2], 40, 1)), [], zeros (2)) ***** error ... loss (ClassificationKNN (ones (40,2), randi ([1, 2], 40, 1)), 1, zeros (2)) ***** error ... loss (ClassificationKNN (ones (4,2), ones (4,1)), ones (4,2), ... ones (4,1), 'LossFun') ***** error ... loss (ClassificationKNN (ones (4,2), ones (4,1)), ones (4,2), ones (3,1)) ***** error ... loss (ClassificationKNN (ones (4,2), ones (4,1)), ones (4,2), ... ones (4,1), 'LossFun', 'a') ***** error ... loss (ClassificationKNN (ones (4,2), ones (4,1)), ones (4,2), ... ones (4,1), 'Bogus', 1) ***** error ... loss (ClassificationKNN (ones (4,2), ones (4,1)), ones (4,2), ... ones (4,1), 'Weights', 'w') ***** error ... loss (ClassificationKNN (ones (4,2), ones (4,1)), ones (4,2), ... ones (4,1), 'Weights', ones (2, 2)) ***** error ... loss (ClassificationKNN (ones (4,2), ones (4,1)), ones (4,2), ... ones (4,1), 'Weights', ones (3,1)) ***** test load fisheriris mdl = fitcknn (meas, species, 'NumNeighbors', 5); X = mean (meas); Y = {'versicolor'}; m = margin (mdl, X, Y); assert_equal (m, 1) ***** test X = [1, 2; 3, 4; 5, 6]; Y = [1; 2; 3]; mdl = fitcknn (X, Y); m = margin (mdl, X, Y); assert_equal (m, [1; 1; 1]) ***** test X = [7, 8; 9, 10]; Y = ['1'; '2']; mdl = fitcknn (X, Y); m = margin (mdl, X, Y); assert_equal (m, [1; 1]) ***** test X = [11, 12]; Y = {'1'}; mdl = fitcknn (X, Y); m = margin (mdl, X, Y); assert_equal (isnan (m), true) ***** test X = [1, 2; 3, 4; 5, 6]; Y = [1; 2; 3]; mdl = fitcknn (X, Y); X1 = [15, 16]; Y1 = [1]; m = margin (mdl, X1, Y1); assert_equal (m, -1) ***** error ... margin (ClassificationKNN (ones (4,2), ones (4,1))) ***** error ... margin (ClassificationKNN (ones (4,2), ones (4,1)), ones (4,2)) ***** error ... margin (ClassificationKNN (ones (40,2), randi ([1, 2], 40, 1)), [], zeros (2)) ***** error ... margin (ClassificationKNN (ones (40,2), randi ([1, 2], 40, 1)), 1, zeros (2)) ***** error ... margin (ClassificationKNN (ones (4,2), ones (4,1)), ones (4,2), ones (3,1)) ***** shared X, Y, mdl X = [1, 2; 4, 5; 7, 8; 3, 2]; Y = [2; 1; 3; 2]; mdl = fitcknn (X, Y); ***** test Vars = 1; Labels = 2; [pd, x, y] = partialDependence (mdl, Vars, Labels); pdm = [0.7500, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000]; assert_equal (pd, pdm) ***** test Vars = 1; Labels = 2; [pd, x, y] = partialDependence (mdl, Vars, Labels, ... 'NumObservationsToSample', 5); pdm = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; assert_equal (all ((abs (pdm - pd) < 1)(:)), true) ***** test Vars = [1, 2]; Labels = 1; queryPoints = {linspace(0, 1, 3)', linspace(0, 1, 3)'}; [pd, x, y] = partialDependence (mdl, Vars, Labels, 'QueryPoints', ... queryPoints); pdm = [0, 0, 0; 0, 0, 0; 0, 0, 0]; assert_equal (pd, pdm) ***** test Vars = 1; Labels = [1; 2]; [pd, x, y] = partialDependence (mdl, Vars, Labels); pdm = [0.2500, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.2500, 0.2500, 0.2500, ... 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, ... 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, ... 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, ... 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, ... 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, 0.2500, ... 0.2500, 0.2500; 0.7500, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, ... 0.5000, 0.5000, 0.5000]; assert_equal (pd, pdm) ***** test Vars = [1, 2]; Labels = [1; 2]; queryPoints = {linspace(0, 1, 3)', linspace(0, 1, 3)'}; [pd, x, y] = partialDependence (mdl, Vars, Labels, 'QueryPoints', queryPoints); pdm(:,:,1) = [0, 0, 0; 1, 1, 1]; pdm(:,:,2) = [0, 0, 0; 1, 1, 1]; pdm(:,:,3) = [0, 0, 0; 1, 1, 1]; assert_equal (pd, pdm) ***** test X1 = [1; 2; 4; 5; 7; 8; 3; 2]; X2 = ['2'; '3'; '1'; '3'; '1'; '3'; '2'; '2']; X = [X1, double(X2)]; Y = [1; 2; 3; 3; 2; 1; 2; 1]; mdl = fitcknn (X, Y, 'ClassNames', {'1', '2', '3'}); Vars = 1; Labels = 1; [pd, x, y] = partialDependence (mdl, Vars, Labels); pdm = [1.0000, 0.6250, 0.6250, 0.6250, 0.6250, 0.6250, 0.6250, 0.6250, ... 0.6250, 0.6250, 0.6250, 0.6250, 0.6250, 0.6250, 0.6250, 0.6250, 0.6250, ... 0.6250, 0.6250, 0.6250, 0.6250, 0.6250, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.3750, ... 0.3750, 0.3750, 0.3750, 0.3750, 0.3750, 0.3750, 0.3750, 0.3750, 0.3750, ... 0.3750, 0.3750, 0.3750, 0.3750, 0.7500, 0.7500, 0.7500, 0.7500, 0.7500, ... 0.7500, 0.7500, 0.7500]; assert_equal (pd, pdm) ***** test X1 = [1; 2; 4; 5; 7; 8; 3; 2]; X2 = ['2'; '3'; '1'; '3'; '1'; '3'; '2'; '2']; X = [X1, double(X2)]; Y = [1; 2; 3; 3; 2; 1; 2; 1]; predictorNames = {'Feature1', 'Feature2'}; mdl = fitcknn (X, Y, 'PredictorNames', predictorNames); Vars = 'Feature1'; Labels = 1; [pd, x, y] = partialDependence (mdl, Vars, Labels); pdm = [1.0000, 0.6250, 0.6250, 0.6250, 0.6250, 0.6250, 0.6250, 0.6250, ... 0.6250, 0.6250, 0.6250, 0.6250, 0.6250, 0.6250, 0.6250, 0.6250, 0.6250, ... 0.6250, 0.6250, 0.6250, 0.6250, 0.6250, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.3750, ... 0.3750, 0.3750, 0.3750, 0.3750, 0.3750, 0.3750, 0.3750, 0.3750, 0.3750, ... 0.3750, 0.3750, 0.3750, 0.3750, 0.7500, 0.7500, 0.7500, 0.7500, 0.7500, ... 0.7500, 0.7500, 0.7500]; assert_equal (pd, pdm) ***** test X1 = [1; 2; 4; 5; 7; 8; 3; 2]; X2 = ['2'; '3'; '1'; '3'; '1'; '3'; '2'; '2']; X = [X1, double(X2)]; Y = [1; 2; 3; 3; 2; 1; 2; 1]; predictorNames = {'Feature1', 'Feature2'}; mdl = fitcknn (X, Y, 'PredictorNames', predictorNames); new_X1 = [10; 5; 6; 8; 9; 20; 35; 6]; new_X2 = ['2'; '2'; '1'; '2'; '1'; '3'; '3'; '2']; new_X = [new_X1, double(new_X2)]; Vars = 'Feature1'; Labels = 1; [pd, x, y] = partialDependence (mdl, Vars, Labels, new_X); pdm = [0, 0, 0, 0, 0, 0.2500, 0.2500, 0.2500, 0.2500, 0.7500, 0.7500, ... 0.7500, 0.7500, 0.7500, 0.7500, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, ... 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, ... 1.0000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; assert_equal (pd, pdm) ***** test load fisheriris Mdl = fitcknn (meas, species, 'NumNeighbors', 5); [pd, x] = partialDependence (Mdl, 4, 'versicolor', ... 'QueryPoints', [0.5; 1; 1.5; 2]); assert_equal (pd, [0.5013333333, 0.452, 0.384, 0.236], 1e-10); [pd, x] = partialDependence (Mdl, 3, {'setosa'; 'virginica'}); assert_equal (size (pd), [2, 100]); assert_equal (pd(:,[1, 100]), [1, 0; 0, 0.9466666667], 1e-10); [pd, x] = partialDependence (Mdl, 2, 'virginica', meas(1:60,:)); assert_equal (pd([1, 50, 100]), [0.01666666667, 0, 0.003333333333], 1e-10); assert_equal (x([1, 100]), [2.3; 4.4], 1e-12); ***** test # points of the default grid, rows following y and columns x load fisheriris Mdl = fitcknn (meas, species, 'NumNeighbors', 5); gx = linspace (min (meas(:,1)), max (meas(:,1)), 100)'; gy = linspace (min (meas(:,3)), max (meas(:,3)), 100)'; pd = partialDependence (Mdl, [1, 3], 'versicolor', ... 'QueryPoints', {gx([1, 2, 60, 100]), ... gy([1, 2, 50, 100])}); assert_equal (size (pd), [4, 4]); assert_equal ([pd(1,1), pd(1,2), pd(2,1), pd(4,1), pd(1,4), pd(3,3)], ... [0, 0, 0, 0.09733333333, 0, 0.9933333333], 1e-10); ***** shared x, y, obj load fisheriris x = meas; y = species; covMatrix = cov (x); obj = fitcknn (x, y, 'NumNeighbors', 5, 'Distance', ... 'mahalanobis', 'Cov', covMatrix); ***** test status = warning; warning ('off'); rand ('seed', 23); CVMdl = crossval (obj); warning (status); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (CVMdl.KFold == 10, true) assert_equal (CVMdl.ModelParameters.NumNeighbors == 5, true) assert_equal (strcmp (CVMdl.ModelParameters.Distance, 'mahalanobis'), true) assert_equal (class (CVMdl.Trained{1}), "ClassificationKNN") assert_equal (isempty (CVMdl.Trained{1}.Mu), true) ***** test status = warning; warning ('off'); rand ('seed', 23); CVMdl = crossval (obj, 'KFold', 5); warning (status); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (CVMdl.KFold == 5, true) assert_equal (CVMdl.ModelParameters.NumNeighbors == 5, true) assert_equal (strcmp (CVMdl.ModelParameters.Distance, 'mahalanobis'), true) assert_equal (class (CVMdl.Trained{1}), "ClassificationKNN") assert_equal (isempty (CVMdl.Trained{1}.Mu), isempty (obj.Mu)) ***** test status = warning; warning ('off'); rand ('seed', 23); CVMdl = crossval (obj, 'HoldOut', 0.2); warning (status); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (CVMdl.ModelParameters.NumNeighbors == 5, true) assert_equal (strcmp (CVMdl.ModelParameters.Distance, 'mahalanobis'), true) assert_equal (class (CVMdl.Trained{1}), "ClassificationKNN") assert_equal (isempty (CVMdl.Trained{1}.Mu), isempty (obj.Mu)) ***** test obj = fitcknn (x, y, 'NumNeighbors', 10, 'Distance', 'cityblock'); status = warning; warning ('off'); rand ('seed', 23); CVMdl = crossval (obj, 'HoldOut', 0.2); warning (status); CVMdl = crossval (obj, 'LeaveOut', 'on'); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (CVMdl.ModelParameters.NumNeighbors == 10, true) assert_equal (strcmp (CVMdl.ModelParameters.Distance, 'cityblock'), true) assert_equal (class (CVMdl.Trained{1}), "ClassificationKNN") assert_equal (isempty (CVMdl.Trained{1}.Mu), isempty (obj.Mu)) ***** test obj = fitcknn (x, y, 'NumNeighbors', 10, 'Distance', 'cityblock'); status = warning; warning ('off'); rand ('seed', 23); partition = cvpartition (y, 'KFold', 3); warning (status); CVMdl = crossval (obj, 'cvPartition', partition); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal (CVMdl.KFold == 3, true) assert_equal (CVMdl.ModelParameters.NumNeighbors == 10, true) assert_equal (strcmp (CVMdl.ModelParameters.Distance, 'cityblock'), true) assert_equal (class (CVMdl.Trained{1}), "ClassificationKNN") assert_equal (isempty (CVMdl.Trained{1}.Mu), isempty (obj.Mu)) ***** error ... crossval (ClassificationKNN (ones (4,2), ones (4,1)), 'kfold') ***** error... crossval (ClassificationKNN (ones (4,2), ones (4,1)), 'kfold', 12, 'holdout', 0.2) ***** error ... crossval (ClassificationKNN (ones (4,2), ones (4,1)), 'kfold', 'a') ***** error ... crossval (ClassificationKNN (ones (4,2), ones (4,1)), 'holdout', 2) ***** error ... crossval (ClassificationKNN (ones (4,2), ones (4,1)), 'leaveout', 1) ***** error ... crossval (ClassificationKNN (ones (4,2), ones (4,1)), 'cvpartition', 1) ***** error ... savemodel (ClassificationKNN ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])) ***** error ... savemodel (ClassificationKNN ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), 1) ***** error ... savemodel (ClassificationKNN ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), ['ab'; 'cd']) ***** test x = [1, 2; 3, 4; 5, 6; 7, 8; 2, 3]; y = [1; 2; 1; 2; 1]; for k = [5, 6, 20] a = fitcknn (x, y, 'NumNeighbors', k); assert_equal (a.NumNeighbors, 5); assert_equal (predict (a, [2, 2; 6, 6]), [1; 1]); endfor ***** test load fisheriris Mdl = fitcknn (meas, species, 'NumNeighbors', 5); [~, s0] = predict (Mdl, meas(60,:)); Mdl.ScoreTransform = 'logit'; [~, s1] = predict (Mdl, meas(60,:)); assert_equal (s1, 1 ./ (1 + exp (-s0)), 1e-12); ***** test load fisheriris Mdl = fitcknn (meas, species, 'NumNeighbors', 5); [~, s0] = predict (Mdl, meas(1:6,:)); Mdl.ScoreTransform = 'logit'; [~, s1] = predict (Mdl, meas(1:6,:)); assert_equal (s1, 1 ./ (1 + exp (-s0)), 1e-12); ***** test load fisheriris Mdl = fitcknn (meas, species, 'ScoreTransform', 'doublelogit'); [~, s1] = predict (Mdl, meas(1,:)); [~, s6] = predict (Mdl, meas(1:6,:)); assert_equal (s6(1,:), s1, 1e-12); ***** test load fisheriris Mdl = fitcknn (meas, species, 'ScoreTransform', 'doublelogit'); [~, s] = predict (Mdl, meas(1:4,:)); assert_equal (s, repmat ([0.880797077977882, 0.5, 0.5], 4, 1), 1e-12); ***** test load fisheriris Mdl = fitcknn (meas, species, 'NumNeighbors', 4); [~, s0] = predict (Mdl, meas(60,:)); Mdl.ScoreTransform = 'invlogit'; [~, s] = predict (Mdl, meas(60,:)); assert_equal (s, log (s0 ./ (1 - s0)), 1e-12); ***** test load fisheriris Mdl = fitcknn (meas, species, 'NumNeighbors', 5); [~, s0] = predict (Mdl, meas(1:3,:)); Mdl.ScoreTransform = 'none'; assert_equal (class (Mdl.ScoreTransform), 'char'); [~, s1] = predict (Mdl, meas(1:3,:)); assert_equal (s1, s0); ***** test load fisheriris X = meas; Y = grp2idx (species); Mdl = fitcknn (X, Y); assert_equal (Mdl.RowsUsed, []); assert_equal (class (Mdl.RowsUsed), 'double'); assert_equal (Mdl.NumObservations, 150); assert_equal (rows (Mdl.X), 150); ***** test load fisheriris X = meas; Y = grp2idx (species); Y(5) = NaN; Mdl = fitcknn (X, Y); assert_equal (class (Mdl.RowsUsed), 'logical'); assert_equal (size (Mdl.RowsUsed), [150, 1]); assert_equal (sum (Mdl.RowsUsed), 149); assert_equal (Mdl.RowsUsed(5), false); assert_equal (Mdl.NumObservations, 149); assert_equal (rows (Mdl.X), 149); ***** test load fisheriris X = meas; X(3,2) = NaN; Y = grp2idx (species); Mdl = fitcknn (X, Y); assert_equal (Mdl.RowsUsed, []); assert_equal (Mdl.NumObservations, 150); assert_equal (rows (Mdl.X), 150); assert_equal (sum (isnan (Mdl.X(:))), 1); ***** test load fisheriris Mdl = fitcknn (meas, species); assert_equal (Mdl.Mu, []); assert_equal (Mdl.Sigma, []); ***** test load fisheriris X = meas; X(3,2) = NaN; X(17,4) = NaN; X(140,1) = NaN; Mdl = fitcknn (X, species, 'Standardize', true); assert_equal (Mdl.Mu, [5.8362416107382593, 3.0563758389261766, ... 3.7580000000000031, 1.2046979865771823], 1e-13); assert_equal (Mdl.Sigma, [0.82627581654893234, 0.43717801242449683, ... 1.7652982332594667, 0.76196186774754338], 1e-13); assert_equal (Mdl.Mu(3), mean (meas(:,3)), 1e-13); ***** test load fisheriris i3 = [1:50, 51:80, 101:120]; Mdl = fitcknn (meas(i3,:), species(i3), 'Prior', 'uniform'); assert_equal (Mdl.Prior, [1, 1, 1] / 3, 1e-14); assert_equal (Mdl.W(1), 1/150, 1e-14); assert_equal (Mdl.W(51), 1/90, 1e-14); assert_equal (Mdl.W(81), 1/60, 1e-14); ***** test load fisheriris i3 = [1:50, 51:80, 101:120]; Mdl = fitcknn (meas(i3,:), species(i3)); assert_equal (Mdl.W(1), 0.01, 1e-14); Mdl.Prior = [0.98, 0.01, 0.01]; assert_equal (Mdl.W(1), 0.0196, 1e-14); ***** test load fisheriris Mdl = fitcknn (meas, species); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2), 'ClassificationKNN'); assert_equal (M2.NumObservations, Mdl.NumObservations); assert_equal (M2.PredictorNames, Mdl.PredictorNames); assert_equal (class (M2.ScoreTransform), class (Mdl.ScoreTransform)); assert_equal (predict (M2, meas(1:5,:)), predict (Mdl, meas(1:5,:))); ***** test load fisheriris Mdl = fitcknn (meas, species, 'NumNeighbors', 1); Mdl.NumNeighbors = 50; Mdl.DistanceWeight = 'inverse'; Mdl.Distance = 'cityblock'; M2 = fitcknn (meas, species, 'NumNeighbors', 50, ... 'DistanceWeight', 'inverse', 'Distance', 'cityblock'); assert_equal (predict (Mdl, meas), predict (M2, meas)); ***** test load fisheriris Mdl = fitcknn (meas, species); Mdl.NumNeighbors = 1000; assert_equal (Mdl.NumNeighbors, 150); ***** test load fisheriris Mdl = fitcknn (meas, species); assert_equal (Mdl.NSMethod, 'kdtree'); Mdl.Distance = 'minkowski'; assert_equal (Mdl.NSMethod, 'kdtree'); assert_equal (Mdl.DistParameter, 2); ***** test load fisheriris Mdl = fitcknn (meas, species, 'Distance', 'minkowski', ... 'NSMethod', 'exhaustive'); Mdl.DistParameter = 3; Mdl.Distance = 'euclidean'; assert_equal (Mdl.DistParameter, []); Mdl.Distance = 'minkowski'; assert_equal (Mdl.DistParameter, 2); ***** test load fisheriris Mdl = fitcknn (meas, species, 'Distance', 'minkowski', ... 'NSMethod', 'exhaustive'); Mdl.DistParameter = 3; Mdl.Distance = 'minkowski'; assert_equal (Mdl.DistParameter, 3); ***** test load fisheriris Mdl = fitcknn (meas, species, 'NSMethod', 'exhaustive'); Mdl.Distance = 'seuclidean'; assert_equal (Mdl.DistParameter, std (meas), 1e-12); ***** test load fisheriris Mdl = fitcknn (meas, species, 'NSMethod', 'exhaustive'); Mdl.Distance = 'mahalanobis'; assert_equal (Mdl.DistParameter, cov (meas), 1e-12); ***** test Mdl = fitcknn ([1, 0; 2, 0; 50, 0; 51, 0], {'b';'a';'a';'b'}, ... 'NumNeighbors', 2, 'NSMethod', 'exhaustive'); assert_equal (Mdl.DistanceWeight, 'equal'); [label, score] = predict (Mdl, [0, 0]); assert_equal (label, {'a'}); assert_equal (score, [0.5, 0.5], 1e-6); ***** test Mdl = fitcknn ([1, 0; 2, 0; 50, 0; 51, 0], {'b';'a';'a';'b'}, ... 'NumNeighbors', 2, 'DistanceWeight', 'inverse', ... 'NSMethod', 'exhaustive'); [label, score] = predict (Mdl, [0, 0]); assert_equal (label, {'b'}); assert_equal (score, [1/3, 2/3], 1e-6); ***** test Mdl = fitcknn ([1, 0; 2, 0; 50, 0; 51, 0], {'b';'a';'a';'b'}, ... 'NumNeighbors', 2, 'DistanceWeight', 'squaredinverse', ... 'NSMethod', 'exhaustive'); [label, score] = predict (Mdl, [0, 0]); assert_equal (label, {'b'}); assert_equal (score, [0.2, 0.8], 1e-6); ***** test Mdl = fitcknn ([1, 0; 2, 0; 50, 0; 51, 0], {'b';'a';'a';'b'}, ... 'NumNeighbors', 2, 'NSMethod', 'exhaustive'); Mdl.BreakTies = 'smallest'; assert_equal (predict (Mdl, [0, 0]), {'a'}); Mdl.BreakTies = 'nearest'; assert_equal (predict (Mdl, [0, 0]), {'b'}); ***** test x = [0, 0; 0, 0; 1, 1; 1, 1; 2, 2; 2, 2]; y = {'a'; 'b'; 'a'; 'b'; 'a'; 'b'}; Mdl = fitcknn (x, y, 'NumNeighbors', 1, 'NSMethod', 'exhaustive'); [~, score] = predict (Mdl, [0.5, 0.5]); assert_equal (score, [1, 0]); Mdl.IncludeTies = true; [~, score] = predict (Mdl, [0.5, 0.5]); assert_equal (score, [0.5, 0.5]); ***** test load fisheriris Mdl = fitcknn (meas, species, 'DistanceWeight', 'squaredinverse'); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.DistanceWeight, 'squaredinverse'); assert_equal (predict (M2, meas), predict (Mdl, meas)); ***** error ... Mdl = fitcknn (ones (5, 2), [1;1;1;2;2]); Mdl.NumNeighbors = 0; ***** error ... Mdl = fitcknn (ones (5, 2), [1;1;1;2;2]); Mdl.NumNeighbors = 2.5; ***** error ... Mdl = fitcknn (ones (5, 2), [1;1;1;2;2]); Mdl.BreakTies = 'bogus'; ***** error ... Mdl = fitcknn (ones (5, 2), [1;1;1;2;2]); Mdl.IncludeTies = 2; ***** error ... Mdl = fitcknn (ones (5, 2), [1;1;1;2;2]); Mdl.DistanceWeight = 'bogus'; ***** error ... load fisheriris; Mdl = fitcknn (meas, species); ... Mdl.Distance = 'mahalanobis'; ***** error ... load fisheriris; ... Mdl = fitcknn (meas, species, 'NSMethod', 'exhaustive'); ... Mdl.DistParameter = 2; ***** error ... load fisheriris; ... Mdl = fitcknn (meas, species, 'Distance', 'minkowski', ... 'NSMethod', 'exhaustive'); ... Mdl.DistParameter = 0; ***** error ... load fisheriris; ... Mdl = fitcknn (meas, species, 'Distance', 'seuclidean', ... 'NSMethod', 'exhaustive'); ... Mdl.DistParameter = ones (1, 3); ***** error ... load fisheriris; ... Mdl = fitcknn (meas, species, 'Distance', 'mahalanobis', ... 'NSMethod', 'exhaustive'); ... Mdl.DistParameter = -eye (4); ***** error ... load fisheriris; ... Mdl = fitcknn (meas, species, 'Distance', 'seuclidean', ... 'NSMethod', 'exhaustive'); ... Mdl.DistParameter = zeros (1, 4); ***** test load fisheriris Mdl = fitcknn (meas, species, 'NumNeighbors', 5); assert_equal (edge (Mdl, meas, species), 0.9253333333, 1e-9); assert_equal (edge (Mdl, meas, species), ... mean (margin (Mdl, meas, species)), 1e-12); ***** test load fisheriris Mdl = fitcknn (meas, species, 'NumNeighbors', 5); assert_equal (edge (Mdl, meas, species, 'Weights', (1:150)'), ... 0.9265719286, 1e-9); ***** test load fisheriris Mdl = fitcknn (meas, species, 'NumNeighbors', 5); assert_equal (resubEdge (Mdl), 0.9253333333, 1e-9); assert_equal (resubLoss (Mdl), 1/30, 1e-12); assert_equal (sum (resubMargin (Mdl)), 138.8, 1e-9); ***** test load fisheriris Mdl = fitcknn (meas, species); assert_equal (resubLoss (Mdl), 0); assert_equal (resubEdge (Mdl), 1); ***** test load fisheriris Mdl = fitcknn (meas, species, 'NumNeighbors', 5); [label, score, cost] = resubPredict (Mdl); [l2, s2, c2] = predict (Mdl, meas); assert_equal (label, l2); assert_equal (score, s2); assert_equal (cost, c2); ***** error ... load fisheriris; edge (fitcknn (meas, species), meas) ***** error ... load fisheriris; ... edge (fitcknn (meas, species), meas, species, 'Weights', ones (3, 1)) ***** error ... load fisheriris; edge (fitcknn (meas, species), meas, species, 'Nope', 1) ***** test load fisheriris Mdl = fitcknn (meas, species); assert_equal (class (Mdl.BinEdges), 'cell'); assert_equal (Mdl.BinEdges, {}); ***** test load fisheriris Mdl = fitcknn (meas, species); assert_equal (Mdl.CategoricalPredictors, []); assert_equal (size (Mdl.CategoricalPredictors), [0, 0]); assert_equal (Mdl.ExpandedPredictorNames, Mdl.PredictorNames); assert_equal (size (Mdl.ExpandedPredictorNames), [1, 4]); ***** test load fisheriris Mdl = fitcknn (meas, species); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.CategoricalPredictors, Mdl.CategoricalPredictors); assert_equal (M2.ExpandedPredictorNames, Mdl.ExpandedPredictorNames); ***** test load fisheriris Mdl = fitcknn (meas, species); S = struct ('ClassNames', {{'virginica'; 'setosa'; 'versicolor'}}, ... 'ClassificationCosts', [0, 1, 2; 3, 0, 4; 5, 6, 0]); Mdl.Cost = S; assert_equal (Mdl.Cost, [0, 4, 3; 6, 0, 5; 1, 2, 0]); ***** error ... load fisheriris Mdl = fitcknn (meas, species); Mdl.Cost = ones (3); ***** test load fisheriris Mdl = fitcknn (meas, species); assert_equal (isempty (Mdl.HyperparameterOptimizationResults), true); ***** test load fisheriris Mdl = fitcknn (meas, species); assert_equal (fieldnames (Mdl.ModelParameters)', {'NumNeighbors', ... 'NSMethod', 'Distance', 'BucketSize', 'IncludeTies', 'DistanceWeight', ... 'BreakTies', 'Exponent', 'Cov', 'Scale', 'StandardizeData', 'Version', ... 'Method', 'Type'}); ***** test load fisheriris MP = fitcknn (meas, species).ModelParameters; assert_equal (MP.NumNeighbors, 1); assert_equal (MP.NSMethod, 'kdtree'); assert_equal (MP.Distance, 'euclidean'); assert_equal (MP.BucketSize, 50); assert_equal (MP.IncludeTies, false); assert_equal (MP.DistanceWeight, 'equal'); assert_equal (MP.BreakTies, 'smallest'); ***** test load fisheriris MP = fitcknn (meas, species).ModelParameters; assert_equal (MP.Version, 1); assert_equal (MP.Method, 'KNN'); assert_equal (MP.Type, 'classification'); ***** test load fisheriris MP = fitcknn (meas, species, 'NSMethod', 'exhaustive').ModelParameters; assert_equal (isempty (MP.BucketSize), true); ***** test load fisheriris Mdl = fitcknn (meas, species, 'Distance', 'mahalanobis'); assert_equal (isempty (Mdl.ModelParameters.Cov), true); assert_equal (size (Mdl.DistParameter), [4, 4]); ***** test load fisheriris C = cov (meas); MP = fitcknn (meas, species, 'Distance', 'mahalanobis', ... 'Cov', C).ModelParameters; assert_equal (MP.Cov, C); ***** test load fisheriris MP = fitcknn (meas, species, 'Distance', 'minkowski', ... 'Exponent', 3).ModelParameters; assert_equal (MP.Exponent, 3); assert_equal (isempty (MP.Cov), true); ***** test load fisheriris MP = fitcknn (meas, species, 'Distance', 'minkowski').ModelParameters; assert_equal (MP.Exponent, 2); ***** test load fisheriris MP = fitcknn (meas, species, 'Distance', 'seuclidean').ModelParameters; assert_equal (isempty (MP.Scale), true); ***** test load fisheriris MP = fitcknn (meas, species, 'NSMethod', 'exhaustive', ... 'BucketSize', 30).ModelParameters; assert_equal (isempty (MP.BucketSize), true); ***** test load fisheriris MP = fitcknn (meas, species, 'NSMethod', 'kdtree', ... 'BucketSize', 30).ModelParameters; assert_equal (MP.BucketSize, 30); ***** test load fisheriris S = std (meas); MP = fitcknn (meas, species, 'Distance', 'seuclidean', ... 'Scale', S).ModelParameters; assert_equal (MP.Scale, S); ***** test load fisheriris MP = fitcknn (meas, species, 'Standardize', true).ModelParameters; assert_equal (MP.StandardizeData, true); assert_equal (class (MP.StandardizeData), 'logical'); ***** test load fisheriris MP = fitcknn (meas, species, 'NumNeighbors', 10, ... 'DistanceWeight', 'inverse', ... 'BreakTies', 'nearest', 'IncludeTies', true).ModelParameters; assert_equal (MP.NumNeighbors, 10); assert_equal (MP.DistanceWeight, 'inverse'); assert_equal (MP.BreakTies, 'nearest'); assert_equal (MP.IncludeTies, true); ***** test load fisheriris Mdl = fitcknn (meas, species, 'Distance', 'seuclidean', ... 'NSMethod', 'exhaustive'); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.NSMethod, 'exhaustive'); assert_equal (M2.Distance, 'seuclidean'); assert_equal (M2.DistParameter, Mdl.DistParameter); assert_equal (predict (M2, meas(1:5,:)), predict (Mdl, meas(1:5,:))); ***** test load fisheriris Mdl = fitcknn (meas, species, 'Distance', 'mahalanobis'); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.Distance, 'mahalanobis'); assert_equal (M2.DistParameter, Mdl.DistParameter); assert_equal (predict (M2, meas(1:5,:)), predict (Mdl, meas(1:5,:))); ***** test load fisheriris Mdl = fitcknn (meas, species, 'Distance', 'manhattan'); assert_equal (Mdl.NSMethod, 'kdtree'); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.Distance, 'manhattan'); assert_equal (predict (M2, meas(1:5,:)), predict (Mdl, meas(1:5,:))); ***** test load fisheriris b = strcmp (species, 'setosa'); Mdl = fitcknn (meas, b, 'Cost', [0, 2; 5, 0]); [label, ~, cost] = predict (Mdl, meas([1, 51],:)); assert_equal (label, [true; false]); assert_equal (cost, [5, 0; 0, 2]); ***** test load fisheriris Mdl = fitcknn (meas, species, 'NumNeighbors', 5); [~, score, cost] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (cost, 1 - score, 1e-15); ***** test load fisheriris Mdl = fitcknn (meas, species, 'NumNeighbors', 5); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); T = {'identity', @(x) x; 'doublelogit', @(x) 1 ./ (1 + exp (-2 * x)); ... 'invlogit', @(x) log (x ./ (1 - x)); ... 'logit', @(x) 1 ./ (1 + exp (-x)); ... 'sign', @(x) sign (x); 'symmetric', @(x) 2 * x - 1; ... 'symmetriclogit', @(x) 2 ./ (1 + exp (-x)) - 1}; for i = 1:rows (T) Mdl.ScoreTransform = T{i,1}; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, T{i,2}(raw), 1e-12); assert_equal (l, label); endfor ## ismax marks the largest score of each observation, ties to the first. [~, k] = max (raw, [], 2); e = zeros (size (raw)); e(sub2ind (size (raw), (1:rows (raw))', k)) = 1; Mdl.ScoreTransform = 'ismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, e); Mdl.ScoreTransform = 'symmetricismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, 2 * e - 1); ***** test load fisheriris Mdl = fitcknn (meas, species, 'NumNeighbors', 5); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); Mdl.ScoreTransform = @(x) x .^ 2; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, raw .^ 2, 1e-12); assert_equal (l, label); ***** shared XC, yb, y3 k = (0:119)'; c1 = mod (k, 3) + 1; c3 = 10 * (mod (floor (k / 2), 2) + 1); XC = [c1, c3]; yb = 5 * (c1 == 2) + 0.5 * sin (k) - 3 * (c3 == 20) + 0.1 * cos (k) > 1; y3 = mod (c1 + floor (k / 7), 3) + 1; ***** test # MATLAB parity: every predictor categorical compares levels Mdl = ClassificationKNN (XC, yb, 'CategoricalPredictors', 'all'); assert_equal (Mdl.Distance, 'hamming'); assert_equal (Mdl.CategoricalPredictors, [1, 2]); assert_equal (Mdl.ExpandedPredictorNames, {'x1', 'x2'}); [label, s] = predict (Mdl, [1, 10; 2, 20; 4, 10]); assert_equal (label, [false; true; false]); assert_equal (s, [1, 0; 0, 1; 1, 0]); ***** test # MATLAB parity: five neighbours by Hamming distance, three classes Mdl = ClassificationKNN (XC, y3, 'CategoricalPredictors', 'all', ... 'NumNeighbors', 5); [label, s] = predict (Mdl, [1, 10; 2, 20; 4, 10]); assert_equal (label, [2; 1; 2]); assert_equal (s, [0, 0.6, 0.4; 0.6, 0.2, 0.2; 0.2, 0.4, 0.4], 1e-12); ***** test # a given distance is kept, and folds take 'all' Mdl = ClassificationKNN (XC, yb, 'CategoricalPredictors', 'all', ... 'Distance', 'cityblock'); assert_equal (Mdl.Distance, 'cityblock'); CV = crossval (ClassificationKNN (XC, yb, 'CategoricalPredictors', ... 'all'), 'KFold', 3); assert_equal (CV.Trained{1}.Distance, 'hamming'); assert_equal (CV.Trained{1}.CategoricalPredictors, [1, 2]); ***** error ... ClassificationKNN (XC, yb, 'CategoricalPredictors', 1) ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcknn (T, 'Species'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcknn (T, 'Species'); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcknn (T, 'Species'); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** test load fisheriris w = (1:150)'; Mdl = fitcknn (meas, species); assert_equal (resubLoss (Mdl, 'LossFun', 'classiferror', 'Weights', w), ... loss (Mdl, meas, species, 'LossFun', 'classiferror', ... 'Weights', w)); ***** error ... fitcknn (ones (4, 2), [1; 1; 2; 2], 'Weights', int8 ([1; 1; 1; 1])) ***** error ... fitcknn (ones (4, 2), [1; 1; 2; 2], 'Weights', true (4, 1)) ***** test ## Single weights are stored single, summing to one load fisheriris w = 1 + (1:150)' / 7; Mdl = fitcknn (meas, species, 'Weights', single (w)); assert_equal (class (Mdl.W), 'single'); assert_equal (sum (double (Mdl.W)), 1, 1e-6); ***** test ## Single weights compute as double load fisheriris w = 1 + (1:150)' / 7; A = fitcknn (meas, species, 'Weights', single (w)); B = fitcknn (meas, species, 'Weights', double (single (w))); assert_equal (nthargout (2, @predict, A, meas), nthargout (2, @predict, ... B, meas)); ***** test ## A constant predictor is left unscaled by standardization X = [linspace(0, 1, 20)', ones(20, 1)]; Mdl = ClassificationKNN (X, [ones(10, 1); 2 * ones(10, 1)], 'Standardize', true); assert_equal (Mdl.Sigma(2), 1); 294 tests, 294 passed, 0 known failure, 0 skipped [inst/Machine_Learning/ClassificationBaggedEnsemble.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/ClassificationBaggedEnsemble.m ***** test # MATLAB parity: the properties of a bagged ensemble load fisheriris Mdl = ClassificationBaggedEnsemble (meas, species, 'NumLearningCycles', 3); assert_equal (numel (properties (Mdl)), 29); assert_equal (Mdl.Method, 'Bag'); assert_equal (Mdl.TrainedWeights, [1; 1; 1]); assert_equal (Mdl.FitInfo, []); assert_equal (Mdl.FitInfoDescription, 'None'); assert_equal (Mdl.FResample, 1); assert_equal (Mdl.Replace, true); assert_equal (size (Mdl.UseObsForLearner), [150, 3]); assert_equal (isfield (Mdl.ModelParameters, 'LearnRate'), false); ***** test # MATLAB parity: the scores are the mean of the trees' probabilities load fisheriris rng (5); Mdl = ClassificationBaggedEnsemble (meas, species, 'NumLearningCycles', 5); [~, s] = predict (Mdl, meas); P = zeros (150, 3); for t = 1:5 [~, st] = predict (Mdl.Trained{t}, meas); [~, k] = ismember (Mdl.Trained{t}.ClassNames, Mdl.ClassNames); P(:,k) += st; endfor assert_equal (s, P / 5, 1e-15); ***** test # MATLAB parity: a subset of trees is averaged over the subset load fisheriris rng (5); Mdl = ClassificationBaggedEnsemble (meas, species, 'NumLearningCycles', 3); [~, s] = predict (Mdl, meas(1:2,:), 'Learners', [1, 3]); [~, a] = predict (Mdl.Trained{1}, meas(1:2,:)); [~, b] = predict (Mdl.Trained{3}, meas(1:2,:)); assert_equal (s, (a + b) / 2, 1e-15); ***** test # MATLAB parity: each tree draws FResample of the rows load fisheriris rng (8); Mdl = ClassificationBaggedEnsemble (meas, species, ... 'NumLearningCycles', 3, ... 'Replace', 'off', 'FResample', 0.5); assert_equal (sum (Mdl.UseObsForLearner), [75, 75, 75]); assert_equal (Mdl.Trained{1}.NodeSize(1), 75); R = ClassificationBaggedEnsemble (meas, species, 'NumLearningCycles', 1, ... 'FResample', 0.5); assert_equal (R.Trained{1}.NodeSize(1), 75); ***** test # MATLAB parity: the bootstrap draws in proportion to the weights load fisheriris rng (9); w = [10 * ones(50, 1); ones(100, 1)]; Mdl = ClassificationBaggedEnsemble (meas, species, ... 'NumLearningCycles', 20, 'Weights', w); assert_equal (Mdl.Prior, [5, 0.5, 0.5] / 6, 1e-15); share = mean (sum (Mdl.UseObsForLearner(1:50,:)) / 50); assert_equal (share > 0.85, true); ***** test # resuming adds the new trees' samples load fisheriris Mdl = ClassificationBaggedEnsemble (meas, species, 'NumLearningCycles', 2); Mdl = resume (Mdl, 2); assert_equal (class (Mdl), 'ClassificationBaggedEnsemble'); assert_equal (Mdl.NumTrained, 4); assert_equal (size (Mdl.UseObsForLearner), [150, 4]); assert_equal (Mdl.ModelParameters.NLearn, 4); ***** test # MATLAB parity: the cumulative loss of the bagged trees load fisheriris Mdl = ClassificationBaggedEnsemble (meas, species, 'NumLearningCycles', 3); L = resubLoss (Mdl, 'Mode', 'cumulative'); assert_equal (size (L), [3, 1]); assert_equal (L(end), resubLoss (Mdl), 1e-15); assert_equal (class (compact (Mdl)), 'CompactClassificationEnsemble'); ***** error ... ClassificationBaggedEnsemble (1) ***** error ... load fisheriris ClassificationBaggedEnsemble (meas, species, 'Method', 'AdaBoostM2') ***** error ... load fisheriris ClassificationBaggedEnsemble (meas, species, 'LearnRate', 0.5) ***** error ... load fisheriris predict (ClassificationBaggedEnsemble (meas, species, ... 'NumLearningCycles', 1)) ***** test # MATLAB parity: the importance of a bagged ensemble is the mean load fisheriris rng (1); Mdl = ClassificationBaggedEnsemble (meas, species, 'NumLearningCycles', 5); I = cell2mat (cellfun (@(t) predictorImportance (t), Mdl.Trained, ... 'UniformOutput', false)); assert_equal (predictorImportance (Mdl), mean (I), 1e-15); ***** test # MATLAB parity: out-of-bag predictions invert UseObsForLearner load fisheriris rng (2); Mdl = ClassificationBaggedEnsemble (meas, species, 'NumLearningCycles', 6); U = ! Mdl.UseObsForLearner; [l1, s1] = oobPredict (Mdl); [l2, s2] = predict (Mdl, meas, 'UseObsForLearner', U); assert_equal (l1, l2); assert_equal (isequaln (s1, s2), true); r = find (all (Mdl.UseObsForLearner, 2)); assert_equal (all (isnan (s1(r,:))(:)), true); ***** test # MATLAB parity: the out-of-bag loss leaves out rows in every bag load fisheriris rng (2); Mdl = ClassificationBaggedEnsemble (meas, species, 'NumLearningCycles', 6); [~, s] = oobPredict (Mdl); have = ! any (isnan (s), 2); g = grp2idx (species); st = s(sub2ind (size (s), (1:150)', g)); so = s; so(sub2ind (size (s), (1:150)', g)) = -Inf; miss = st <= max (so, [], 2); assert_equal (oobLoss (Mdl), mean (miss(have)), 1e-15); U = ! Mdl.UseObsForLearner; assert_equal (oobLoss (Mdl, 'Mode', 'cumulative'), ... loss (Mdl, meas, species, 'UseObsForLearner', U, ... 'Mode', 'cumulative'), 1e-15); assert_equal (oobLoss (Mdl, 'Learners', [2, 4]), ... loss (Mdl, meas, species, 'UseObsForLearner', U, ... 'Learners', [2, 4]), 1e-15); ***** test # MATLAB parity: the out-of-bag edge and margins load fisheriris rng (2); Mdl = ClassificationBaggedEnsemble (meas, species, 'NumLearningCycles', 6); U = ! Mdl.UseObsForLearner; assert_equal (oobEdge (Mdl), edge (Mdl, meas, species, ... 'UseObsForLearner', U), 1e-15); m = oobMargin (Mdl); assert_equal (isequaln (m, margin (Mdl, meas, species, ... 'UseObsForLearner', U)), true); assert_equal (oobEdge (Mdl), mean (m(! isnan (m))), 1e-14); ***** test # MATLAB parity: permuted importance of one tree is zero or infinite load fisheriris rng (4); Mdl = ClassificationBaggedEnsemble (meas, species, 'NumLearningCycles', 1); imp = oobPermutedPredictorImportance (Mdl); assert_equal (size (imp), [1, 4]); assert_equal (all (imp == 0 | isinf (imp)), true); ***** test # MATLAB parity: a constant predictor has zero permuted importance load fisheriris rng (5); Mdl = ClassificationBaggedEnsemble ([meas, ones(150, 1)], species, ... 'NumLearningCycles', 20); imp = oobPermutedPredictorImportance (Mdl); assert_equal (imp(5), 0); assert_equal (size (oobPermutedPredictorImportance (Mdl, ... 'Learners', 1:5)), ... [1, 5]); ***** test # MATLAB parity: permuting a petal measurement matters most load fisheriris rng (3); Mdl = ClassificationBaggedEnsemble (meas, species, 'NumLearningCycles', 60); imp = oobPermutedPredictorImportance (Mdl); assert_equal (min (imp(3:4)) > max (imp(1:2)), true); ***** error ... load fisheriris oobPredict (ClassificationBaggedEnsemble (meas, species, ... 'NumLearningCycles', 1), ... 'UseObsForLearner', true (150, 1)) ***** error ... load fisheriris oobLoss (ClassificationBaggedEnsemble (meas, species, ... 'NumLearningCycles', 1), 'Mode') ***** error ... load fisheriris oobLoss (ClassificationBaggedEnsemble (meas, species, ... 'NumLearningCycles', 1), ... 'Weights', ones (150, 1)) ***** error ... load fisheriris oobEdge (ClassificationBaggedEnsemble (meas, species, ... 'NumLearningCycles', 1), ... 'LossFun', 'hinge') ***** error ... load fisheriris oobMargin (ClassificationBaggedEnsemble (meas, species, ... 'NumLearningCycles', 1), ... 'Mode', 'cumulative') ***** error ... load fisheriris oobPermutedPredictorImportance (ClassificationBaggedEnsemble (meas, ... species, 'NumLearningCycles', 1), ... 'Learners', 2) ***** error ... load fisheriris oobPermutedPredictorImportance (ClassificationBaggedEnsemble (meas, ... species, 'NumLearningCycles', 1), ... 'Options', struct ()) ***** error ... load fisheriris oobPermutedPredictorImportance (ClassificationBaggedEnsemble (meas, ... species, 'NumLearningCycles', 1), ... 'Bogus', struct ()) ***** shared X2, Y2, S load fisheriris X2 = meas(51:150,:); Y2 = species(51:150); S = templateTree ('MaxNumSplits', 1); ***** test # MATLAB parity: drawing every row without replacement is plain boosting M = ClassificationBaggedEnsemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 5, 'Learners', S, ... 'FResample', 1, 'Replace', 'off'); assert_equal (M.Method, 'AdaBoostM1'); assert_equal (M.CombineWeights, 'WeightedSum'); assert_equal (M.UseObsForLearner, true (100, 5)); assert_equal (M.TrainedWeights', [1.37576765652097, 0.99353411077441, ... 0.883434373403997, 0.554364192108759, ... 0.268194447432049], 1e-12); ***** test # MATLAB parity: a resampling boosting method draws with replacement M = ClassificationBaggedEnsemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 5, 'Learners', S, ... 'Resample', 'on'); assert_equal ([M.FResample, M.Replace], [1, true]); assert_equal (size (M.UseObsForLearner), [100, M.NumTrained]); assert_equal (M.FitInfo * 100, round (M.FitInfo * 100), 1e-9); ***** test # MATLAB parity: AdaBoostM1 reweights only the rows it drew M = ClassificationBaggedEnsemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 4, 'Learners', S, ... 'FResample', 0.5, 'Replace', 'off'); y = 2 * strcmp (Y2, M.ClassNames{1}) - 1; d = M.W / sum (M.W); for t = 1:M.NumTrained u = M.UseObsForLearner(:,t); h = 2 * strcmp (predict (M.Trained{t}, X2), M.ClassNames{1}) - 1; e = sum (d(u) .* (h(u) != y(u))) / sum (d(u)); assert_equal (M.FitInfo(t), e, 1e-12); s0 = sum (d(u)); d(u) = d(u) .* exp (-M.TrainedWeights(t) * y(u) .* h(u)); d(u) = d(u) / sum (d(u)) * s0; endfor ***** test # MATLAB parity: GentleBoost reweights only the rows it drew M = ClassificationBaggedEnsemble (X2, Y2, 'Method', 'GentleBoost', ... 'NumLearningCycles', 4, 'Learners', S, ... 'FResample', 0.5, 'Replace', 'off'); y = 2 * strcmp (Y2, M.ClassNames{1}) - 1; d = M.W / sum (M.W); for t = 1:M.NumTrained u = M.UseObsForLearner(:,t); h = predict (M.Trained{t}, X2); assert_equal (M.FitInfo(t), ... sum (d(u) .* (y(u) - h(u)) .^ 2) / sum (d(u)), 1e-12); s0 = sum (d(u)); d(u) = d(u) .* exp (-y(u) .* h(u)); d(u) = d(u) / sum (d(u)) * s0; endfor ***** test # MATLAB parity: LogitBoost moves the score of the rows it drew M = ClassificationBaggedEnsemble (X2, Y2, 'Method', 'LogitBoost', ... 'NumLearningCycles', 4, 'Learners', S, ... 'FResample', 0.5, 'Replace', 'off'); y01 = double (strcmp (Y2, M.ClassNames{1})); w0 = M.W / sum (M.W); w = w0; F = zeros (100, 1); for t = 1:M.NumTrained u = M.UseObsForLearner(:,t); p = 1 ./ (1 + exp (-F)); z = (y01 - p) ./ (p .* (1 - p)); h = predict (M.Trained{t}, X2); assert_equal (M.FitInfo(t), ... sum (w(u) .* (z(u) - h(u)) .^ 2) / sum (w(u)), 1e-10); F(u) += h(u) / 2; s0 = sum (w(u)); pu = 1 ./ (1 + exp (-F(u))); w(u) = w0(u) .* pu .* (1 - pu); w(u) = w(u) / sum (w(u)) * s0; endfor ***** test # MATLAB parity: AdaBoostM2 keeps one weight per observation load fisheriris M = ClassificationBaggedEnsemble (meas, species, 'Method', 'AdaBoostM2', ... 'NumLearningCycles', 3, 'Learners', S, ... 'FResample', 0.5, 'Replace', 'off'); g = grp2idx (species); tru = sub2ind ([150, 3], (1:150)', g); w = M.W / sum (M.W); for t = 1:M.NumTrained u = M.UseObsForLearner(:,t); [~, P] = predict (M.Trained{t}, meas); hy = P(tru); L = 1 - hy + P; L(tru) = 0; e = sum (w(u) .* sum (L(u,:), 2)) / sum (w(u)) / 4; assert_equal (M.FitInfo(t), e, 1e-12); E = exp (-M.TrainedWeights(t) * (1 + hy - P)); E(tru) = 0; s0 = sum (w(u)); w(u) = w(u) .* sum (E(u,:), 2); w(u) = w(u) / sum (w(u)) * s0; endfor ***** test # MATLAB parity: out-of-bag scores sum the learners that did not draw M = ClassificationBaggedEnsemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 8, 'Learners', S, ... 'Resample', 'on'); [~, s] = oobPredict (M); out = ! M.UseObsForLearner; man = zeros (100, 1); for t = 1:M.NumTrained h = 2 * strcmp (predict (M.Trained{t}, X2), M.ClassNames{1}) - 1; man += M.TrainedWeights(t) * h .* out(:,t); endfor k = any (out, 2); assert_equal (s(k,1), man(k), 1e-12); ***** test # resume grows the record of the rows each learner drew M = ClassificationBaggedEnsemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 2, 'Learners', S, ... 'FResample', 0.7, 'Replace', 'off'); R = resume (M, 2); assert_equal (size (R.UseObsForLearner), [100, R.NumTrained]); ***** test # a resampled boosting ensemble cross-validates with its learning rate M = ClassificationBaggedEnsemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 2, 'Learners', S, ... 'FResample', 0.7, 'LearnRate', 0.5); CV = crossval (M, 'KFold', 3); assert_equal (CV.Trainable{1}.LearnRate, 0.5); assert_equal (class (CV.Trainable{1}), 'ClassificationBaggedEnsemble'); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcensemble (T, 'Species', 'Method', 'Bag'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcensemble (T, 'Species', 'Method', 'Bag'); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcensemble (T, 'Species', 'Method', 'Bag'); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); 38 tests, 38 passed, 0 known failure, 0 skipped [inst/Machine_Learning/RegressionLinear.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/RegressionLinear.m ***** shared X, Y load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); X = X(ok,:); Y = MPG(ok); ***** demo ## Fit fuel consumption on four engine measurements and read the ## coefficients and the insensitive band the fit chose for itself. load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); Mdl = RegressionLinear (X(ok,:), MPG(ok)) yFit = predict (Mdl, X(find (ok, 3),:)) ***** demo ## Least squares has no insensitive band, so Epsilon is empty, and its ## loss is the mean squared error the fit minimizes. load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); Mdl = RegressionLinear (X(ok,:), MPG(ok), 'Learner', 'leastsquares'); band = Mdl.Epsilon mse = loss (Mdl, X(ok,:), MPG(ok)) ***** test ## The model reports the surface MATLAB reports Mdl = RegressionLinear (X, Y); assert_equal (class (Mdl), 'RegressionLinear'); assert_equal (Mdl.Learner, 'svm'); assert_equal (Mdl.FittedLoss, 'epsiloninsensitive'); assert_equal (Mdl.Regularization, 'ridge (L2)'); assert_equal (Mdl.ResponseTransform, 'none'); assert_equal (Mdl.ResponseName, 'Y'); assert_equal (Mdl.PredictorNames, {'x1', 'x2', 'x3', 'x4'}); assert_equal (Mdl.ExpandedPredictorNames, {'x1', 'x2', 'x3', 'x4'}); assert_equal (Mdl.CategoricalPredictors, []); assert_equal (size (Mdl.Beta), [4, 1]); ***** test ## The properties are the ones MATLAB lists, in its order Mdl = RegressionLinear (X, Y); assert_equal (sort (properties (Mdl)), ... sort ({'Epsilon'; 'ResponseTransform'; 'PredictorNames'; ... 'CategoricalPredictors'; 'ResponseName'; ... 'ExpandedPredictorNames'; 'Learner'; 'Beta'; ... 'Bias'; 'FittedLoss'; 'Lambda'; 'ModelParameters'; ... 'Regularization'})); ***** test ## A least squares ridge fit reproduces R2024a's coefficients Mdl = RegressionLinear (X, Y, 'Learner', 'leastsquares', ... 'Solver', 'lbfgs', 'BetaTolerance', 0, ... 'GradientTolerance', 1e-12, ... 'IterationLimit', 20000); assert_equal (Mdl.Beta, [-0.060147206634135; -0.00667928082241265; ... -0.0375377897819825; -0.00608459830980712], 1e-7); assert_equal (Mdl.Bias, 48.1149099265466, 1e-6); assert_equal (Mdl.FittedLoss, 'mse'); assert_equal (Mdl.Epsilon, []); assert_equal (loss (Mdl, X, Y), 15.9484134801834, 1e-6); ***** test ## Epsilon defaults to the interquartile range over 13.49, R2024a's own ## estimate of the standard deviation of the response Mdl = RegressionLinear (X, Y); assert_equal (Mdl.Epsilon, 0.926612305411416, 1e-12); assert_equal (Mdl.Epsilon, iqr (Y) / 13.49, 1e-15); ***** test ## A response of no spread has no interquartile range to scale, and the ## band falls back on a tenth Mdl = RegressionLinear (ones (10, 2), 5 * ones (10, 1)); assert_equal (Mdl.Epsilon, 0.1); ***** test ## The epsilon-insensitive loss is not differentiable at the edge of the ## band, so the line search gives up short of a minimum and where it stops ## follows the last bits: 2.8273 here, 3.4883 under clang and on macOS, ## against the 2.82717018548797 R2024a reaches. Assert the identity the ## reported objective holds at whichever point it stops. Mdl = RegressionLinear (X, Y, 'Learner', 'svm', 'Solver', 'lbfgs', ... 'BetaTolerance', 0, 'GradientTolerance', 1e-12, ... 'IterationLimit', 20000); assert_equal (Mdl.FitInfo_.Objective, ... loss (Mdl, X, Y, 'LossFun', 'epsiloninsensitive') ... + 0.5 * Mdl.Lambda * sum (Mdl.Beta .^ 2), 1e-12); ***** test ## Lambda defaults to the reciprocal of the observations that were used Mdl = RegressionLinear (X, Y); assert_equal (Mdl.Lambda, 1 / 93, 1e-15); ***** test ## A vector of strengths fits one model per value, sorted ascending, and ## every method reports one column per value Mdl = RegressionLinear (X, Y, 'Lambda', [0.1, 0.001, 0.01]); assert_equal (Mdl.Lambda, [0.001, 0.01, 0.1]); assert_equal (size (Mdl.Beta), [4, 3]); assert_equal (size (Mdl.Bias), [1, 3]); assert_equal (size (predict (Mdl, X(1:4,:))), [4, 3]); assert_equal (size (loss (Mdl, X, Y)), [1, 3]); ***** test ## selectModels keeps the strengths it is given and drops the rest Mdl = RegressionLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]); sub = selectModels (Mdl, [1, 3]); assert_equal (sub.Lambda, [0.001, 0.1]); assert_equal (sub.Beta, Mdl.Beta(:,[1, 3])); ***** test ## A lasso penalty drives coefficients to exactly zero Mdl = RegressionLinear (X, Y, 'Learner', 'leastsquares', ... 'Regularization', 'lasso', 'Lambda', 100); assert_equal (Mdl.Regularization, 'lasso (L1)'); assert_equal (sum (Mdl.Beta == 0) > 0, true); ***** test ## With the penalty all but switched off, a least squares fit is ordinary ## least squares, whichever solver ran. This is what pins the solvers to ## a value that is known independently of either of them. b = [ones(rows (X), 1), X] \ Y; Ml = RegressionLinear (X, Y, 'Learner', 'leastsquares', ... 'Regularization', 'lasso', 'Lambda', 1e-8, ... 'BetaTolerance', 0, 'GradientTolerance', 1e-14, ... 'IterationLimit', 200000); Mr = RegressionLinear (X, Y, 'Learner', 'leastsquares', ... 'Solver', 'lbfgs', 'Lambda', 1e-8, ... 'BetaTolerance', 0, 'GradientTolerance', 1e-14, ... 'IterationLimit', 200000); ## Relative, so every coefficient is held to the same number of figures: ## an absolute tolerance is far stricter on the largest of them, and how ## close a solver stops to the closed form answer varies with the BLAS. assert_equal (Ml.Beta, b(2:end), -1e-3); assert_equal (Ml.Bias, b(1), 1e-4); assert_equal (Mr.Beta, b(2:end), -1e-3); assert_equal (Mr.Bias, b(1), 1e-4); ***** test ## A response transform reaches predict Mdl = RegressionLinear (X, Y, 'Learner', 'leastsquares'); plain = predict (Mdl, X(1:5,:)); Mdl.ResponseTransform = 'exp'; assert_equal (Mdl.ResponseTransform, 'exp'); assert_equal (predict (Mdl, X(1:5,:)), exp (plain), 1e-12); ***** test ## FitBias false leaves the intercept at zero Mdl = RegressionLinear (X, Y, 'FitBias', false); assert_equal (Mdl.Bias, 0); ***** test ## Observations may be given down the columns instead Mr = RegressionLinear (X, Y, 'Learner', 'leastsquares'); Mc = RegressionLinear (X', Y, 'Learner', 'leastsquares', ... 'ObservationsIn', 'columns'); assert_equal (Mr.Beta, Mc.Beta, 1e-12); ***** test ## A row with a missing predictor or a missing response is dropped, and ## Lambda follows the count that survived Xn = X; Xn(3,2) = NaN; Mdl = RegressionLinear (Xn, Y); assert_equal (Mdl.Lambda, 1 / 92, 1e-15); ***** test ## A saved model reads back as the same model Mdl = RegressionLinear (X, Y, 'Learner', 'leastsquares'); fname = tempname (); savemodel (Mdl, fname); Mnew = loadmodel (fname); delete (fname); assert_equal (class (Mnew), 'RegressionLinear'); assert_equal (Mnew.Beta, Mdl.Beta); assert_equal (predict (Mnew, X(1:5,:)), predict (Mdl, X(1:5,:))); ***** test ## LossTolerance: the engine's loss test is on the objective VALUE, not on ## its change, so linearSolve must switch it off with -Inf. This fit is ## the one that catches it: an exact linear relation at a vanishing ## penalty drives the objective through 1e-6 long before the coefficients ## are right, and with the engine's default the fit stops five iterations ## early with them out by 1.6e-4. If this test starts failing, look at ## opt.LossTolerance in linearSolve before anything else. randn ('seed', 7); Xe = randn (60, 3); btrue = [2; -3; 0.5]; Ye = Xe * btrue + 4; Mdl = RegressionLinear (Xe, Ye, 'Learner', 'leastsquares', ... 'Solver', 'lbfgs', 'Lambda', 1e-10, ... 'BetaTolerance', 0, 'GradientTolerance', 1e-14, ... 'IterationLimit', 20000); assert_equal (Mdl.Beta, btrue, 1e-8); assert_equal (Mdl.Bias, 4, 1e-8); ***** test ## HessianHistorySize reaches the solver rather than only being recorded: ## a one-pair history takes several times the iterations a fifteen-pair ## one does on the same problem. Fifteen is MATLAB's documented default ## for fitrlinear, where the engine's own default is ten. bf = RegressionLinear (X, Y); assert_equal (bf.ModelParameters.Solver, {'bfgs'}); assert_equal (bf.ModelParameters.HessianHistorySize, []); lb = RegressionLinear (X, Y, 'Solver', 'lbfgs'); assert_equal (lb.ModelParameters.HessianHistorySize, 15); opts = {'Learner', 'leastsquares', 'Solver', 'lbfgs', 'BetaTolerance', 0, ... 'GradientTolerance', 1e-10, 'IterationLimit', 5000}; short = RegressionLinear (X, Y, opts{:}, 'HessianHistorySize', 1); long = RegressionLinear (X, Y, opts{:}, 'HessianHistorySize', 15); assert_equal (short.FitInfo_.NumIterations ... > long.FitInfo_.NumIterations, true); ***** test ## The regression counterpart keeps the documented 0.1 where the ## classifier takes 1, confirmed on R2026a; the convergence check count ## is 2 on both, where the documentation says 5 Mdl = RegressionLinear (X, Y, 'Solver', 'dual'); assert_equal (Mdl.ModelParameters.DeltaGradientTolerance, 0.1); assert_equal (Mdl.ModelParameters.NumCheckConvergence, 2); assert_equal (Mdl.ModelParameters.PassLimit, 10); ***** test # A row missing a predictor predicts the lower median of the response X = [(1:10)', mod((1:10)', 3)]; Mdl = RegressionLinear (X, (1:10)'); assert_equal (predict (Mdl, [NaN, 1]), 5); ***** test # The lower median is weighted X = [(1:10)', mod((1:10)', 3)]; Mdl = RegressionLinear (X, (1:10)', 'Weights', [ones(9, 1); 10]); assert_equal (predict (Mdl, [NaN, 1]), 10); ***** error RegressionLinear (ones (5, 2)) ***** error ... RegressionLinear (ones (10, 2), ones (10, 1), 'Learner') ***** error ... RegressionLinear (ones (10, 2), ones (10, 1), 'Learner', 'logistic') ***** error ... RegressionLinear (ones (10, 2), ones (10, 1), 'Epsilon', -1) ***** error ... RegressionLinear (ones (10, 2), ones (10, 1), 'Learner', 'leastsquares', ... 'Epsilon', 1) ***** error ... RegressionLinear (ones (10, 2), ones (10, 1), 'Regularization', 'elastic') ***** error ... RegressionLinear (ones (10, 2), ones (10, 1), 'Lambda', Inf) ***** error ... RegressionLinear (ones (10, 2), ones (10, 1), 'Solver', 'newton') ***** error ... RegressionLinear (ones (10, 2), ones (10, 1), 'IterationLimit', 0) ***** error ... RegressionLinear (ones (10, 2), ones (10, 1), 'Nonsense', 1) ***** error RegressionLinear ({1, 2; 3, 4}, [1; 2]) ***** error RegressionLinear ([], []) ***** error ... RegressionLinear (ones (10, 2), {1, 2}) ***** error ... RegressionLinear (ones (10, 2), ones (3, 1)) ***** error ... RegressionLinear (ones (10, 2), ones (10, 1), 'Weights', ones (3, 1)) ***** error ... RegressionLinear (ones (10, 2), ones (10, 1), 'Regularization', 'ridge', ... 'Solver', 'sparsa') ***** error ... RegressionLinear (ones (10, 2), ones (10, 1), 'Regularization', 'lasso', ... 'Solver', 'lbfgs') ***** error ... RegressionLinear (ones (10, 2), ones (10, 1), 'Learner', 'leastsquares', ... 'Solver', 'dual') ***** error ... RegressionLinear (ones (10, 2), ones (10, 1), 'PredictorNames', {'a'}) ***** error ... predict (RegressionLinear (ones (10, 2), ones (10, 1))) ***** error ... predict (RegressionLinear (ones (10, 2), ones (10, 1)), []) ***** error ... predict (RegressionLinear (ones (10, 2), ones (10, 1)), ones (3, 5)) ***** error ... loss (RegressionLinear (ones (10, 2), ones (10, 1)), ones (10, 2)) ***** error ... loss (RegressionLinear (ones (10, 2), ones (10, 1)), ones (10, 2), ... ones (10, 1), 'LossFun', 'hinge') ***** error ... loss (RegressionLinear (ones (10, 2), ones (10, 1)), ones (10, 2), ... ones (10, 1), 'Bogus', 1) ***** error ... loss (RegressionLinear (ones (10, 2), ones (10, 1), 'Learner', ... 'leastsquares'), ones (10, 2), ones (10, 1), ... 'LossFun', 'epsiloninsensitive') ***** error ... loss (RegressionLinear (ones (10, 2), ones (10, 1)), ones (10, 2), ... ones (3, 1)) ***** error ... selectModels (RegressionLinear (ones (10, 2), ones (10, 1), 'Lambda', ... [0.1, 0.2]), 5) ***** test load fisheriris Mdl = fitrlinear (meas(:,2:4), meas(:,1)); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); T = {'identity', @(x) x; 'exp', @(x) exp (x); 'log', @(x) log (x)}; for i = 1:rows (T) Mdl.ResponseTransform = T{i,1}; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, T{i,2}(raw), 1e-12); endfor ***** test load fisheriris Mdl = fitrlinear (meas(:,2:4), meas(:,1)); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); Mdl.ResponseTransform = @(x) x .^ 2; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, raw .^ 2, 1e-12); ***** shared Xc, Dc, yc c1 = repmat ([1; 2; 3], 20, 1); x2 = sin ((1:60)'); c3 = repmat ([10; 10; 20; 20], 15, 1); Xc = [c1, x2, c3]; Dc = [c1 == 1, c1 == 2, c1 == 3, x2, c3 == 10, c3 == 20]; yc = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 20) + 0.1 * cos ((1:60)'); ***** test # MATLAB parity: a categorical predictor is dummy coded in its place Mdl = RegressionLinear (Xc, yc, 'CategoricalPredictors', [1, 3]); assert_equal (Mdl.CategoricalPredictors, [1, 3]); assert_equal (Mdl.ExpandedPredictorNames, {'x1 == 1', 'x1 == 2', ... 'x1 == 3', 'x2', 'x3 == 10', 'x3 == 20'}); H = RegressionLinear (Dc, yc); assert_equal (Mdl.Beta, H.Beta, 1e-12); assert_equal (predict (Mdl, Xc(1:5,:)), predict (H, Dc(1:5,:)), 1e-12); ***** test # MATLAB parity: 'all' codes every predictor, reported as indices Mdl = RegressionLinear (Xc(:,[1, 3]), yc, 'CategoricalPredictors', 'all'); assert_equal (Mdl.CategoricalPredictors, [1, 2]); assert_equal (numel (Mdl.ExpandedPredictorNames), 5); ***** test # MATLAB parity: levels need not be integers Mdl = RegressionLinear ([Xc(:,1) + 0.5, Xc(:,2)], yc, ... 'CategoricalPredictors', 1); assert_equal (Mdl.ExpandedPredictorNames, {'x1 == 1.5', 'x1 == 2.5', ... 'x1 == 3.5', 'x2'}); ***** test # a level the training data did not hold predicts the lower median Mdl = RegressionLinear (Xc, yc, 'CategoricalPredictors', [1, 3]); yhat = predict (Mdl, [4, 0, 10; 2.5, 0, 20; NaN, 0, 10; 2, 0, 20]); ys = sort (yc); assert_equal (yhat(1:3), repmat (ys(ceil (numel (ys) / 2)), 3, 1)); assert_equal (isnan (yhat(4)), false); ***** test # a NaN in a categorical predictor leaves the row out of the fit X2 = Xc; X2(1,1) = NaN; Mdl = RegressionLinear (X2, yc, 'CategoricalPredictors', [1, 3]); H = RegressionLinear (Xc(2:end,:), yc(2:end), ... 'CategoricalPredictors', [1, 3]); assert_equal (Mdl.Beta, H.Beta, 1e-12); ***** test # the coding travels with a saved model Mdl = RegressionLinear (Xc, yc, 'CategoricalPredictors', [1, 3]); fname = [tempname(), '.mdl']; savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (predict (M2, Xc(1:5,:)), predict (Mdl, Xc(1:5,:))); ***** error ... RegressionLinear (Xc, yc, 'CategoricalPredictors', 4) ***** error ... RegressionLinear (Xc, yc, 'CategoricalPredictors', logical ([1, 0])) ***** error ... RegressionLinear (Xc, yc, 'CategoricalPredictors', 0) ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,2:3); y = meas(:,1); T = table (X(:,1), X(:,2), 'VariableNames', {'SW', 'PL'}); T.SL = y; Mdl = fitrlinear (T, 'SL'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'SL'), a); assert_equal (loss (Mdl, T), a); ***** error ... fitrlinear ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', 'Weights', int8 ([1; 1; 1; 1])) ***** error ... fitrlinear ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', 'Weights', true (4, 1)) ***** error X = [1, 2; 3, 4; 5, 6; 7, 8]; y = (1:4)'; loss (fitrlinear (X, y), X, y, 'Weights', int8 ([1; 1; 1; 1])) ***** test ## Single weights compute as double load fisheriris X = meas(:,2:4); y = meas(:,1); w = 1 + (1:150)' / 7; A = fitrlinear (X, y, 'Weights', single (w)); B = fitrlinear (X, y, 'Weights', double (single (w))); assert_equal (predict (A, X), predict (B, X)); 65 tests, 65 passed, 0 known failure, 0 skipped [inst/Machine_Learning/CompactTreeBagger.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/CompactTreeBagger.m ***** demo ## Compact a random forest and classify new flowers with it. The compact ## ensemble keeps the trees but not the training data. load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3]) ***** test # a compact ensemble predicts as the ensemble it came from load fisheriris rng (1); B = TreeBagger (5, meas, species); C = compact (B); assert_equal (class (C), 'CompactTreeBagger'); [la, sa] = predict (B, meas); [lc, sc] = predict (C, meas); assert_equal (lc, la); assert_equal (sc, sa); assert_equal (C.ClassNames, B.ClassNames); assert_equal (C.DefaultYfit, B.DefaultYfit); ***** test # a compact ensemble keeps the ensemble's categorical predictors Xc = [1, 2; 2, 3; 3, 4; 1, 5; 2, 6; 3, 7; 1, 8; 2, 9]; yc = [1; 1; 2; 2; 1; 2; 1; 2]; C = compact (TreeBagger (3, Xc, yc, 'CategoricalPredictors', 1)); assert_equal (C.CategoricalPredictors, 1); C = compact (TreeBagger (3, Xc, yc)); assert_equal (C.CategoricalPredictors, []); ***** test # MATLAB parity: combining keeps the first ensemble's default load fisheriris rng (1); C1 = setDefaultYfit (compact (TreeBagger (3, meas, species)), ''); C2 = compact (TreeBagger (4, meas, species)); C = combine (C1, C2); assert_equal (C.NumTrees, 7); assert_equal (C.DefaultYfit, {''}); ***** test # a missing default leaves an observation without a prediction load fisheriris rng (1); C = setDefaultYfit (compact (TreeBagger (4, meas, species)), ''); U = true (150, 4); U(1,:) = false; label = predict (C, meas(1:2,:), 'UseInstanceForTree', U(1:2,:)); assert_equal (label(1), {''}); m = margin (C, meas(1:2,:), species(1:2), 'Mode', 'ensemble', ... 'UseInstanceForTree', U(1:2,:)); assert_equal (isnan (m), [true; false]); miss = ! strcmp (predict (C, meas(2:end,:)), species(2:end)); e = error (C, meas, species, 'Mode', 'ensemble', 'UseInstanceForTree', U); assert_equal (e, sum (miss) / 149, 1e-15); ***** test # 'MostPopular' restores the class of greatest prior probability load fisheriris rng (1); C = setDefaultYfit (compact (TreeBagger (2, meas, species)), ''); C = setDefaultYfit (C, 'MostPopular'); assert_equal (C.DefaultYfit, {'setosa'}); ***** test # a regression default is any numeric scalar load fisheriris rng (1); C = compact (TreeBagger (2, meas(:,2:4), meas(:,1), 'Method', 'regression')); C = setDefaultYfit (C, 3); assert_equal (C.DefaultYfit, 3); ***** test # MATLAB parity: combining adds up the split counts load fisheriris rng (1); C1 = compact (TreeBagger (3, meas, species)); C2 = compact (TreeBagger (4, meas, species)); C = combine (C1, C2); assert_equal (C.NumPredictorSplit, ... C1.NumPredictorSplit + C2.NumPredictorSplit, 1e-14); assert_equal (C.DeltaCriterionDecisionSplit, ... (3 * C1.DeltaCriterionDecisionSplit ... + 4 * C2.DeltaCriterionDecisionSplit) / 7, 1e-14); assert_equal (C.SurrogateAssociation, eye (4)); ***** test # MATLAB parity: proximity is the share of trees sharing a leaf load fisheriris rng (1); C = compact (TreeBagger (6, meas, species, 'MinLeafSize', 5)); X = meas(1:3:end,:); P = zeros (rows (X)); for t = 1:6 [~, ~, nd] = predict (C.Trees{t}, X); P += nd == nd'; endfor prox = proximity (C, X); assert_equal (prox, P / 6, 1e-15); assert_equal (diag (prox), ones (50, 1)); ***** test # a regression ensemble has proximities too load fisheriris rng (1); C = compact (TreeBagger (3, meas(:,2:4), meas(:,1), 'Method', 'regression')); [~, n1] = predict (C.Trees{1}, meas(1:2,2:4)); [~, n2] = predict (C.Trees{2}, meas(1:2,2:4)); [~, n3] = predict (C.Trees{3}, meas(1:2,2:4)); p12 = mean ([n1(1) == n1(2), n2(1) == n2(2), n3(1) == n3(2)]); assert_equal (proximity (C, meas(1:2,2:4)), [1, p12; p12, 1], 1e-15); ***** test # MATLAB parity: the outlier measure within each class load fisheriris rng (1); C = compact (TreeBagger (8, meas, species, 'MinLeafSize', 5)); P = proximity (C, meas); g = grp2idx (species); om = zeros (150, 1); for k = 2:3 raw = 50 ./ sum (P(g == k, g == k) .^ 2, 2); om(g == k) = abs (raw - median (raw)) / median (abs (raw - median (raw))); endfor out = outlierMeasure (C, meas, 'Labels', species); assert_equal (out(g > 1), om(g > 1), 1e-12); ***** test # MATLAB parity: a proximity matrix may be given in place of the data load fisheriris rng (1); C = compact (TreeBagger (8, meas, species, 'MinLeafSize', 5)); P = proximity (C, meas); assert_equal (outlierMeasure (C, P, 'Data', 'proximity', ... 'Labels', species), ... outlierMeasure (C, meas, 'Labels', species)); ***** test # MATLAB parity: without labels every observation is one class C = compact (TreeBagger (1, [1; 2; 3; 4], [1; 1; 2; 2])); P = [1, 0.2, 0.6, 0.1, 0.3; 0.2, 1, 0.4, 0.7, 0.5; ... 0.6, 0.4, 1, 0.2, 0.8; 0.1, 0.7, 0.2, 1, 0.3; ... 0.3, 0.5, 0.8, 0.3, 1]; assert_equal (outlierMeasure (C, P, 'Data', 'proximity'), ... [2.482051282051284; 0; 1; 1.609249646059462; ... 0.531400966183575], 1e-12); ***** test # MATLAB parity: a zero median absolute deviation gives the raw measure C = compact (TreeBagger (1, [1; 2; 3; 4], [1; 1; 2; 2])); P = [1, 1, 1, 0.5; 1, 1, 1, 0.5; 1, 1, 1, 0.5; 0.5, 0.5, 0.5, 1]; assert_equal (outlierMeasure (C, P, 'Data', 'proximity'), ... [1.230769230769231; 1.230769230769231; ... 1.230769230769231; 2.285714285714286], 1e-12); assert_equal (outlierMeasure (C, [1, 1, 0; 1, 1, 0; 0, 0, 1], ... 'Data', 'proximity'), [1.5; 1.5; 3]); ***** test # MATLAB parity: a class of one or two observations gives zeros load fisheriris C = compact (TreeBagger (1, meas, species)); P = [1, 1, 1, 0, 0, 0; 1, 1, 1, 0, 0, 0; 1, 1, 1, 0, 0, 0; ... 0, 0, 0, 1, 1, 1; 0, 0, 0, 1, 1, 1; 0, 0, 0, 1, 1, 1]; lab = {'setosa'; 'setosa'; 'virginica'; 'virginica'; 'virginica'; ... 'virginica'}; assert_equal (outlierMeasure (C, P, 'Data', 'proximity', 'Labels', lab), ... [0; 0; 4; 4/3; 4/3; 4/3], 1e-15); assert_equal (outlierMeasure (C, [1, 0.5; 0.5, 0.8], 'Data', ... 'proximity'), [0; 0]); ***** test # MATLAB parity: scaling applies cmdscale to one less the proximity load fisheriris rng (1); C = compact (TreeBagger (5, meas, species, 'MinLeafSize', 5)); X = meas(1:5:end,:); [S, E] = mdsprox (C, X); [S0, E0] = cmdscale (1 - proximity (C, X)); assert_equal (S, S0); assert_equal (E, E0); [S1, E1] = mdsprox (C, proximity (C, X), 'Data', 'proximity'); assert_equal (S1, S0); ***** test # the scaled coordinates are drawn one class per color load fisheriris rng (1); C = compact (TreeBagger (5, meas, species, 'MinLeafSize', 5)); h = figure ('visible', 'off'); unwind_protect mdsprox (C, meas, 'Colors', 'rb', 'Labels', species); kids = get (gca, 'children'); assert_equal (numel (kids), 2); assert_equal (sort (cellfun (@numel, get (kids, 'xdata'))), [50; 50]); assert_equal (ishold (), false); unwind_protect_cleanup close (h); end_unwind_protect ***** test # three coordinates are drawn in three dimensions load fisheriris rng (1); C = compact (TreeBagger (5, meas, species, 'MinLeafSize', 5)); h = figure ('visible', 'off'); unwind_protect S = mdsprox (C, meas, 'Colors', 'k', 'MDSCoordinates', [1, 2, 3]); kids = get (gca, 'children'); assert_equal (numel (kids), 1); assert_equal (get (kids, 'zdata')(:), S(:,3)); unwind_protect_cleanup close (h); end_unwind_protect ***** shared x, y, C, R load fisheriris x = meas; y = species; C = compact (TreeBagger (2, x, y)); R = compact (TreeBagger (2, x(:,2:4), x(:,1), 'Method', 'regression')); ***** error CompactTreeBagger () ***** error CompactTreeBagger (1) ***** error predict (C) ***** error margin (C, x) ***** error ... meanMargin (C, x) ***** error error (C, x) ***** error combine (C) ***** error ... combine (C, 1) ***** error ... combine (C, R) ***** error ... combine (C, compact (TreeBagger (1, x, y, 'Prior', 'uniform', ... 'ClassNames', {'virginica'; 'versicolor'; 'setosa'}))) ***** error ... combine (C, compact (TreeBagger (1, x, y, 'PredictorNames', ... {'a', 'b', 'c', 'd'}))) ***** error ... setDefaultYfit (C) ***** error ... setDefaultYfit (compact (TreeBagger (1, x, strcmp (y, 'setosa'))), '') ***** error ... setDefaultYfit (C, 'setosa') ***** error ... setDefaultYfit (R, 'mean') ***** error proximity (C) ***** error ... proximity (C, {1}) ***** error ... proximity (C, ones (2, 3)) ***** error ... outlierMeasure (C) ***** error ... outlierMeasure (C, x, 'Data') ***** error ... outlierMeasure (C, x, 'Colors', 'r') ***** error ... outlierMeasure (C, x, 'Data', 'distance') ***** error ... outlierMeasure (C, x, 'Data', 'proximity') ***** error ... outlierMeasure (C, x, 'Labels', y(1:10)) ***** error mdsprox (C) ***** error ... mdsprox (C, x(1:10,:), 'Colors', 1) ***** error ... mdsprox (C, x(1:10,:), 'MDSCoordinates', 1) ***** error ... mdsprox (C, x(1:10,:), 'Colors', 'r', 'MDSCoordinates', [1, 200]) ***** error ... mdsprox (C, x(1:10,:), 'MDSCoordinates', [1, 200]) ***** error ... outlierMeasure (C, x(1:2,:), 'Labels', {'rose'; 'setosa'}) ***** error ... outlierMeasure (C, x(1:2,:), 'Labels', [1; 2]) ***** error ... outlierMeasure (R, x(1:2,2:4), 'Labels', [1; 2]) ***** error ... mdsprox (C, x(1:2,:), 'Labels', {''; 'setosa'}) ***** test # the levels travel with the model, and predict reads a table by name load fisheriris T = table (meas(:,1), meas(:,2), 'VariableNames', {'SL', 'SW'}); T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); T.Species = categorical (species); B = TreeBagger (20, T, 'Species'); CB = compact (B); assert_equal (CB.PredictorLevels, B.PredictorLevels); assert_equal (predict (CB, T(:, [4, 3, 2, 1])), predict (CB, T)); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (TreeBagger (20, T, 'Species')); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (TreeBagger (20, T, 'Species')); a = error (Mdl, X, y); assert_equal (error (Mdl, T(:,1:2), y), a); assert_equal (error (Mdl, T, 'Species'), a); assert_equal (error (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (TreeBagger (20, T, 'Species')); a = meanMargin (Mdl, X, y); assert_equal (meanMargin (Mdl, T(:,1:2), y), a); assert_equal (meanMargin (Mdl, T, 'Species'), a); assert_equal (meanMargin (Mdl, T), a); ***** test # a table is matched to the predictors by name load fisheriris T = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = categorical (species); Mdl = compact (TreeBagger (20, T, 'Species')); a = proximity (Mdl, meas); assert_equal (proximity (Mdl, T(:,1:4)), a); assert_equal (proximity (Mdl, T(:,[5, 4, 2, 3, 1])), a); ***** test # a table is matched to the predictors by name load fisheriris T = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = categorical (species); Mdl = compact (TreeBagger (20, T, 'Species')); a = outlierMeasure (Mdl, meas, 'Labels', species); assert_equal (outlierMeasure (Mdl, T(:,1:4), 'Labels', species), a); assert_equal (outlierMeasure (Mdl, T(:,[5, 4, 2, 3, 1]), ... 'Labels', species), a); ***** test # a table is matched to the predictors by name load fisheriris T = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = categorical (species); Mdl = compact (TreeBagger (20, T, 'Species')); a = mdsprox (Mdl, meas); assert_equal (mdsprox (Mdl, T(:,1:4)), a); assert_equal (mdsprox (Mdl, T(:,[5, 4, 2, 3, 1])), a); 57 tests, 57 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitcdiscr.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitcdiscr.m ***** demo ## Train a linear discriminant classifier for Gamma = 0.5 ## and plot the decision boundaries. load fisheriris idx = ! strcmp (species, 'setosa'); X = meas(idx,3:4); Y = cast (strcmpi (species(idx), 'virginica'), 'double'); obj = fitcdiscr (X, Y, 'Gamma', 0.5) x1 = [min(X(:,1)):0.03:max(X(:,1))]; x2 = [min(X(:,2)):0.02:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; pred = predict (obj, XGrid); gidx = logical (pred); figure scatter (XGrid(gidx,1), XGrid(gidx,2), 'markerfacecolor', 'magenta'); hold on scatter (XGrid(! gidx,1), XGrid(! gidx,2), 'markerfacecolor', 'red'); plot (X(Y == 0, 1), X(Y == 0, 2), 'ko', X(Y == 1, 1), X(Y == 1, 2), 'kx'); xlabel ('Petal length (cm)'); ylabel ('Petal width (cm)'); title ('Linear Discriminant Analysis Decision Boundary'); legend ({'Versicolor Region', 'Virginica Region', ... 'Sampled Versicolor', 'Sampled Virginica'}, ... 'location', 'northwest') axis tight hold off ***** demo ## Fit from a table, and predict on one load fisheriris T = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = categorical (species); ## A model formula names the response and the predictors together, and ## holds main effects only Mdl = fitcdiscr (T, 'Species ~ PL + PW'); Mdl.PredictorNames Mdl.ResponseName ## predict matches the table's variables by name, so a column the model ## was not fitted on is passed over label = predict (Mdl, T(1:5,:)); label' ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'Gamma', 0.5); [label, score, cost] = predict (Mdl, [2, 2, 2, 2]); assert_equal (label, {'versicolor'}) assert_equal (score, [0, 0.9999, 0.0001], 1e-4) assert_equal (cost, [1, 0.0001, 0.9999], 1e-4) [label, score, cost] = predict (Mdl, [2.5, 2.5, 2.5, 2.5]); assert_equal (label, {'versicolor'}) assert_equal (score, [0, 0.6368, 0.3632], 1e-4) assert_equal (cost, [1, 0.3632, 0.6368], 1e-4) assert_equal (class (Mdl), "ClassificationDiscriminant"); assert_equal ({Mdl.X, Mdl.Y, Mdl.NumObservations}, {meas, species, 150}) assert_equal ({Mdl.DiscrimType, Mdl.ResponseName}, {'linear', 'Y'}) assert_equal ({Mdl.Gamma, Mdl.MinGamma}, {0.5, 0}) assert_equal (Mdl.ClassNames, unique (species)) sigma = [0.265008, 0.046361, 0.083757, 0.019201; ... 0.046361, 0.115388, 0.027622, 0.016355; ... 0.083757, 0.027622, 0.185188, 0.021333; ... 0.019201, 0.016355, 0.021333, 0.041882]; assert_equal (Mdl.Sigma, sigma, 1e-6) mu = [5.0060, 3.4280, 1.4620, 0.2460; ... 5.9360, 2.7700, 4.2600, 1.3260; ... 6.5880, 2.9740, 5.5520, 2.0260]; assert_equal (Mdl.Mu, mu, 1e-14) assert_equal (Mdl.LogDetSigma, -8.6884, 1e-4) ***** error fitcdiscr () ***** error fitcdiscr (ones (4,1)) ***** error fitcdiscr (ones (4,2), ones (4, 1), 'K') ***** error fitcdiscr (ones (4,2), ones (3, 1)) ***** error fitcdiscr (ones (4,2), ones (3, 1), 'K', 2) ***** test # MATLAB parity: classes given as text are sorted load fisheriris k = [101:150, 1:50, 51:100]; Mdl = fitcdiscr (meas(k,:), species(k)); assert_equal (Mdl.ClassNames, {'setosa'; 'versicolor'; 'virginica'}); ***** test # MATLAB parity: a given ClassNames order is kept load fisheriris Mdl = fitcdiscr (meas(1:150,:), species(1:150), ... 'ClassNames', {'virginica'; 'setosa'; 'versicolor'}); assert_equal (Mdl.ClassNames, {'virginica'; 'setosa'; 'versicolor'}); ***** error ... load fisheriris fitcdiscr (meas, species, 'ClassNames', [3, 1, 2]) ***** shared fdiT load fisheriris fdiT = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); fdiT.Species = categorical (species); ***** test # the response is named by a column and the rest are predictors Mdl = fitcdiscr (fdiT, 'Species'); assert_equal (Mdl.PredictorNames, {'SL', 'SW', 'PL', 'PW'}); assert_equal (Mdl.ResponseName, 'Species'); ***** test # a model formula names the response and the predictors together Mdl = fitcdiscr (fdiT, 'Species ~ PL + PW'); assert_equal (Mdl.PredictorNames, {'PL', 'PW'}); ***** test # predict takes a table, matched by name and not by position Mdl = fitcdiscr (fdiT, 'Species'); a = predict (Mdl, fdiT); assert_equal (class (a), 'categorical'); assert_equal (predict (Mdl, fdiT(:, [5, 4, 3, 2, 1])), a); ***** test # the levels travel with the model when it is made compact Mdl = fitcdiscr (fdiT, 'Species'); CMdl = compact (Mdl); assert_equal (CMdl.PredictorLevels, Mdl.PredictorLevels); assert_equal (predict (CMdl, fdiT), predict (Mdl, fdiT)); ***** error load fisheriris M = table (meas(:,1), 'VariableNames', {'SL'}); M.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); M.Species = categorical (species); fitcdiscr (M, 'Species'); ***** error ... fitcdiscr (fdiT, 'NoSuch') ***** error ... predict (fitcdiscr (fdiT, 'Species'), fdiT(:, [1, 3, 4, 5])) 16 tests, 16 passed, 0 known failure, 0 skipped [inst/Machine_Learning/ClassificationGAM.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/ClassificationGAM.m ***** demo ## Train a GAM classifier for binary classification ## using specific data and plot the decision boundaries. ## Define specific data X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ... 6, 7; 7, 8; 8, 8; 9, 9; 10, 10]; Y = [0; 0; 0; 0; 0; ... 1; 1; 1; 1; 1]; ## Train the GAM model obj = fitcgam (X, Y, 'Interactions', 'all') ## Create a grid of values for prediction x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid); ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = [0; 0; 1; 1]; PredictorNames = {'Feature1', 'Feature2', 'Feature3'}; a = ClassificationGAM (x, y, 'FitMethod', 'splines', ... 'PredictorNames', PredictorNames); assert_equal (class (a), "ClassificationGAM"); assert_equal ({a.X, a.Y, a.NumObservations}, {x, y, 4}) assert_equal ({a.NumPredictors, a.ResponseName}, {3, 'Y'}) assert_equal (a.ClassNames, [0; 1]) assert_equal (a.PredictorNames, PredictorNames) assert_equal (a.BaseModel.Intercept, 0) ***** test load fisheriris inds = strcmp (species,'versicolor') | strcmp (species,'virginica'); X = meas(inds, :); Y = species(inds, :)'; Y = strcmp (Y, 'virginica')'; a = ClassificationGAM (X, Y, 'FitMethod', 'splines', ... 'Formula', 'Y ~ x1 + x2 + x3 + x4 + x1:x2 + x2:x3'); assert_equal (class (a), "ClassificationGAM"); assert_equal ({a.X, a.Y, a.NumObservations}, {X, Y, 100}) assert_equal ({a.NumPredictors, a.ResponseName}, {4, 'Y'}) assert_equal (a.ClassNames, logical ([0; 1])) assert_equal (a.Formula, 'Y ~ x1 + x2 + x3 + x4 + x1:x2 + x2:x3') assert_equal (a.PredictorNames, {'x1', 'x2', 'x3', 'x4'}) assert_equal (a.ModelwInt.Intercept, 0) ***** test X = [2, 3, 5; 4, 6, 8; 1, 2, 3; 7, 8, 9; 5, 4, 3]; Y = [0; 1; 0; 1; 1]; a = ClassificationGAM (X, Y, 'FitMethod', 'splines', ... 'Knots', [4, 4, 4], 'Order', [3, 3, 3]); assert_equal (class (a), "ClassificationGAM"); assert_equal ({a.X, a.Y, a.NumObservations}, {X, Y, 5}) assert_equal ({a.NumPredictors, a.ResponseName}, {3, 'Y'}) assert_equal (a.ClassNames, [0; 1]) assert_equal (a.PredictorNames, {'x1', 'x2', 'x3'}) assert_equal (a.Knots, [4, 4, 4]) assert_equal (a.Order, [3, 3, 3]) assert_equal (a.DoF, [7, 7, 7]) assert_equal (a.BaseModel.Intercept, 0.4055, 1e-1) ***** test ## Test uniform prior x = [1, 2; 3, 4; 5, 6; 7, 8]; y = [0; 0; 1; 1]; a = ClassificationGAM (x, y, 'Prior', 'uniform'); assert_equal (a.Prior, [0.5, 0.5], 1e-6); ***** test ## Test empirical prior x = [1, 2; 3, 4; 5, 6; 7, 8; 9, 10]; y = [0; 0; 0; 1; 1]; a = ClassificationGAM (x, y, 'Prior', 'empirical'); assert_equal (a.Prior, [0.6, 0.4], 1e-6); ***** test ## Test numeric prior x = [1, 2; 3, 4; 5, 6; 7, 8]; y = [0; 0; 1; 1]; a = ClassificationGAM (x, y, 'Prior', [0.7, 0.3]); assert_equal (a.Prior, [0.7, 0.3], 1e-6); ***** test ## Test default prior (empirical) x = [1, 2; 3, 4; 5, 6; 7, 8; 9, 10; 11, 12]; y = [0; 0; 0; 1; 1; 1]; a = ClassificationGAM (x, y); assert_equal (a.Prior, [0.5, 0.5], 1e-6); ***** test ## Test prior normalization x = [1, 2; 3, 4; 5, 6; 7, 8]; y = [0; 0; 1; 1]; a = ClassificationGAM (x, y, 'Prior', [2, 1]); assert_equal (a.Prior, [2/3, 1/3], 1e-6); ***** test # A categorical 'ClassNames' is accepted load fisheriris y = categorical (species(51:150)); Mdl = ClassificationGAM (meas(51:150,:), y, 'ClassNames', ... categorical ({'versicolor'; 'virginica'})); assert_equal (class (Mdl.ClassNames), 'categorical'); assert_equal (numel (Mdl.ClassNames), 2); ***** test # An unused category of a categorical response is not a class load fisheriris y = categorical (species); Mdl = ClassificationGAM (meas(51:150,:), y(51:150)); assert_equal (cellstr (Mdl.ClassNames), {'versicolor'; 'virginica'}); assert_equal (predict (Mdl, meas(51,:)), y(51)); ***** test k = (1:60)'; X = [mod(k*7,11)-5, mod(k*3,11)-5, mod(k*5,11)-5]; y = double (X(:,1).*X(:,2) > 0) + 1; Mdl = fitcgam (X, y, "Interactions", "all"); assert_equal (Mdl.Interactions, [1, 2; 1, 3; 2, 3]); ***** test k = (1:60)'; X = [mod(k*7,11)-5, mod(k*3,11)-5, mod(k*5,11)-5]; y = double (X(:,1).*X(:,2) > 0) + 1; Mdl = fitcgam (X, y); assert_equal (size (Mdl.Interactions), [0, 2]); assert_equal (class (Mdl.Interactions), "double"); ***** test k = (1:60)'; X = [mod(k*7,11)-5, mod(k*3,11)-5, mod(k*5,11)-5]; y = double (X(:,1).*X(:,2) > 0) + 1; Mc = fitcgam (X, y, "Interactions", 2); Ml = fitcgam (X, y, "Interactions", logical ([1, 1, 0; 0, 1, 1])); assert_equal (Mc.Interactions, [1, 2; 1, 3]); assert_equal (Ml.Interactions, [1, 2; 2, 3]); ***** test k = (1:60)'; X = [mod(k*7,11)-5, mod(k*3,11)-5, mod(k*5,11)-5]; y = double (X(:,1).*X(:,2) > 0) + 1; Mdl = fitcgam (X, y, "FitMethod", "splines", ... "Formula", "Y ~ x1 + x2 + x1:x2"); assert_equal (Mdl.Interactions, [1, 2]); assert_equal (rows (Mdl.IntMatrix), 3); ***** test k = (1:60)'; X = [mod(k*7,11)-5, mod(k*3,11)-5, mod(k*5,11)-5]; y = double (X(:,1).*X(:,2) > 0) + 1; Mdl = fitcgam (X, y, "Interactions", "all"); assert_equal (compact (Mdl).Interactions, Mdl.Interactions); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcgam (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcgam (Xch, Ycell); assert_equal (size (Mc.ClassNames), [2, 10]); assert_equal (cellstr (Mc.ClassNames), Ms.ClassNames); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcgam (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcgam (Xch, Ycell); pch = predict (Mc, Xch); assert_equal (columns (pch), 10); assert_equal (cellstr (pch), predict (Ms, Xch)); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcgam (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcgam (Xch, Ycell); assert_equal (loss (Mc, Xch, Ych), loss (Ms, Xch, Ycell), 1e-12); assert_equal (margin (Mc, Xch, Ych), margin (Ms, Xch, Ycell), 1e-12); assert_equal (edge (Mc, Xch, Ych), edge (Ms, Xch, Ycell), 1e-12); ***** test Xpad = [1 2; 3 4; 1.1 2.1; 3.1 4.1; 1.2 2.2; 3.2 4.2]; Ypad = char ({"ab", "abcd", "ab", "abcd", "ab", "abcd"}); rand ("state", 1); randn ("state", 1); Mp = fitcgam (Xpad, Ypad); assert_equal (size (Mp.ClassNames), [2, 4]); assert_equal (Mp.ClassNames(1,:), "ab "); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); Xmiss = Xch; Xmiss(3,2) = NaN; rand ("state", 1); randn ("state", 1); Md = fitcgam (Xmiss, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcgam (Xmiss, Ycell); assert_equal (size (Md.ClassNames), [2, 10]); assert_equal (cellstr (Md.ClassNames), Ms.ClassNames); ***** test load fisheriris rand ("state", 1); randn ("state", 1); Mf = fitcgam (meas, char (species), ... "ClassNames", char ({"versicolor", "virginica"})); assert_equal (rows (Mf.ClassNames), 2); assert_equal (cellstr (Mf.ClassNames), {"versicolor"; "virginica"}); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcgam (Xch, Ych); fname = tempname (); savemodel (Mc, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.ClassNames, Mc.ClassNames); assert_equal (predict (M2, Xch), predict (Mc, Xch)); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcgam (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcgam (Xch, Ycell); rand ("state", 2); cvc = crossval (Mc, "KFold", 3); rand ("state", 2); cvs = crossval (Ms, "KFold", 3); assert_equal (cellstr (kfoldPredict (cvc)), kfoldPredict (cvs)); ***** test load fisheriris bai = ! strcmp (species, "setosa"); Xai = meas(bai,2:4); Yai = species(bai); Aai = addInteractions (fitcgam (Xai, Yai), "all"); Bai = fitcgam (Xai, Yai, "Interactions", "all"); assert_equal (Aai.Interactions, Bai.Interactions); assert_equal (Aai.ModelwInt, Bai.ModelwInt); assert_equal (predict (Aai, Xai), predict (Bai, Xai)); ***** test load fisheriris bai = ! strcmp (species, "setosa"); Xai = meas(bai,2:4); Yai = species(bai); Cai = fitcgam (Xai, Yai); Aai = addInteractions (Cai, "all"); assert_equal (predict (Aai, Xai, "IncludeInteractions", false), ... predict (Cai, Xai)); ***** test load fisheriris bai = ! strcmp (species, "setosa"); Xai = meas(bai,2:4); Yai = species(bai); Aai = addInteractions (fitcgam (Xai, Yai, 'FitMethod', 'splines'), 2); assert_equal (Aai.Interactions, [1, 2; 1, 3]); Lai = addInteractions (fitcgam (Xai, Yai, 'FitMethod', 'splines'), ... logical ([1 1 0; 0 1 1])); assert_equal (Lai.Interactions, [1, 2; 2, 3]); ***** test load fisheriris bai = ! strcmp (species, "setosa"); Xai = meas(bai,2:4); Yai = species(bai); Aai = addInteractions (fitcgam (Xai, Yai), 2); assert_equal (rows (Aai.Interactions), 2); assert_equal (Aai.Interactions(1,:), [2, 3]); Lai = addInteractions (fitcgam (Xai, Yai), logical ([1 1 0; 0 1 1])); assert_equal (Lai.Interactions, [1, 2; 2, 3]); All = addInteractions (fitcgam (Xai, Yai), "all"); assert_equal (All.Interactions(1,:), [2, 3]); assert_equal (sortrows (All.Interactions), [1, 2; 1, 3; 2, 3]); ***** test load fisheriris X = meas(51:150,:); Y = species(51:150); A = fitcgam (X, Y, 'NumTreesPerPredictor', 5); B = resume (A, 10); C = fitcgam (X, Y, 'NumTreesPerPredictor', 15); assert_equal (B.ModelParameters.NumTreesPerPredictor, 15); [~, sB] = predict (B, X); [~, sC] = predict (C, X); assert_equal (sB, sC, 1e-12); ***** test ## A model carrying interactions gains interaction trees, and its predictor ## shape functions are left where they were. load fisheriris X = meas(51:150,:); Y = species(51:150); A = fitcgam (X, Y, 'NumTreesPerPredictor', 5, 'Interactions', 3, ... 'NumTreesPerInteraction', 4); B = resume (A, 10); assert_equal (B.ModelParameters.NumTreesPerPredictor, 5); assert_equal (B.ModelParameters.NumTreesPerInteraction, 14); assert_equal (B.TreeModel.ShapeValues, A.TreeModel.ShapeValues); C = fitcgam (X, Y, 'NumTreesPerPredictor', 5, 'Interactions', 3, ... 'NumTreesPerInteraction', 14); [~, sB] = predict (B, X); [~, sC] = predict (C, X); assert_equal (sB, sC, 1e-12); ***** test ## The selected pairs survive, and resuming twice accumulates. load fisheriris X = meas(51:150,:); Y = species(51:150); A = fitcgam (X, Y, 'NumTreesPerPredictor', 5, 'Interactions', 3, ... 'NumTreesPerInteraction', 4); B = resume (resume (A, 10), 6); assert_equal (B.Interactions, A.Interactions); assert_equal (B.ModelParameters.NumTreesPerInteraction, 20); assert_equal (B.ModelParameters.NumTreesPerPredictor, 5); ***** test ## The model handed in is not modified. load fisheriris X = meas(51:150,:); Y = species(51:150); A = fitcgam (X, Y, 'NumTreesPerPredictor', 5); B = resume (A, 10); assert_equal (A.ModelParameters.NumTreesPerPredictor, 5); assert_equal (B.ModelParameters.NumTreesPerPredictor, 15); ***** test # a row missing a predictor is kept, and without a spline score it ## takes the class of largest prior x = linspace (0, 1, 30)'; X = [x, cos(4 * x)]; y = [ones(18, 1); 2 * ones(12, 1)]; Mdl = ClassificationGAM (X, y, 'FitMethod', 'splines'); [label, score] = predict (Mdl, [0.5, 0.2; NaN, 0.2]); assert_equal (size (label), [2, 1]); assert_equal (label(2), 1); assert_equal (score(2,:), [NaN, NaN]); ***** test # MATLAB parity: a missing value adds nothing from its term k = (1:200)'; X = [sin(k), cos(2 * k), mod(k, 5)]; y = 2 * sin (k) + X(:,2) .^ 2 + 0.3 * X(:,3); Q = [0.5, 0.2, 1; NaN, 0.2, 1; 0.5, NaN, 1; NaN, NaN, NaN; 0.1, 0.2, 1; ... NaN, 0.7, 3; NaN, NaN, 1]; Mdl = ClassificationGAM (X, y > median (y)); [label, score] = predict (Mdl, Q); assert_equal (label', [true, false, true, true, true, true, false]); assert_equal (score(4,2), 1 / (1 + exp (-Mdl.Intercept)), 1e-14); ***** test # MATLAB parity: 'Prior' weighs the fit as the matching 'Weights' do k = (1:200)'; X = [sin(k), cos(2 * k), mod(k, 5)]; y = 2 * sin (k) + X(:,2) .^ 2 + 0.3 * X(:,3); yc = y > median (y); w = 0.2 * ! yc / sum (! yc) + 0.8 * yc / sum (yc); M0 = ClassificationGAM (X, yc, 'NumTreesPerPredictor', 50); M1 = ClassificationGAM (X, yc, 'Prior', [0.2, 0.8], ... 'NumTreesPerPredictor', 50); M2 = ClassificationGAM (X, yc, 'Weights', w, 'NumTreesPerPredictor', 50); M3 = ClassificationGAM (X, yc, 'Weights', 3 * w, ... 'NumTreesPerPredictor', 50); assert_equal (M2.Prior, [0.2, 0.8], 1e-12); assert_equal ([sum(M1.W(! yc)), sum(M1.W(yc))], [0.2, 0.8], 1e-12); assert_equal (M2.Intercept, M1.Intercept, 1e-10); assert_equal (M3.Intercept, M1.Intercept, 1e-10); assert_equal (M1.Intercept != M0.Intercept, true); ***** test # MATLAB parity: an empirical prior is each class's share of the weight k = (1:200)'; X = [sin(k), cos(2 * k), mod(k, 5)]; y = 2 * sin (k) + X(:,2) .^ 2 + 0.3 * X(:,3); Mdl = ClassificationGAM (X, y > median (y), 'Weights', 1 + mod (k, 3), ... 'NumTreesPerPredictor', 10); assert_equal (Mdl.Prior, [0.498753117207, 0.501246882793], 1e-12); ***** test # MATLAB parity: categorical predictors are split by sets of levels k = (0:119)'; c1 = mod (k, 3) + 1; x2 = sin (k); c3 = 10 * (mod (floor (k / 2), 2) + 1); X = [c1, x2, c3]; y = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 20) + 0.1 * cos (k); Q = [1, 0, 10; 2, 0, 10; 3, 0, 10; 1, 0, 20; 1, 0.5, 10; 4, 0, 10; ... NaN, 0, 10; 2.5, 0, 20]; Mdl = ClassificationGAM (X, y > 1, 'CategoricalPredictors', [1, 3], ... 'NumTreesPerPredictor', 1); assert_equal (Mdl.CategoricalPredictors, [1, 3]); assert_equal (Mdl.BinEdges{1}, []); [~, s] = predict (Mdl, Q); assert_equal (s(:,2), [0.11920292; 0.88079708; 0.11920292; 0.11920292; ... 0.11920292; 0.33924363; 0.33924363; ... 0.33924363], 1e-8); ***** test # MATLAB parity: categorical predictors with the default budget k = (0:119)'; c1 = mod (k, 3) + 1; x2 = sin (k); c3 = 10 * (mod (floor (k / 2), 2) + 1); X = [c1, x2, c3]; y = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 20) + 0.1 * cos (k); Q = [1, 0, 10; 2, 0, 10; 3, 0, 10; 1, 0, 20; 1, 0.5, 10; 4, 0, 10; ... NaN, 0, 10; 2.5, 0, 20]; Mdl = ClassificationGAM (X, y > 1, 'CategoricalPredictors', [1, 3]); assert_equal (predict (Mdl, Q), logical ([0; 1; 0; 0; 0; 0; 0; 0])); ***** test # MATLAB parity: a row missing a predictor is fitted, not dropped k = (1:200)'; X = [sin(k), cos(2 * k), mod(k, 5)]; y = 2 * sin (k) + X(:,2) .^ 2 + 0.3 * X(:,3); yc = y > median (y); X(1:5,1) = NaN; Mdl = ClassificationGAM (X, yc, 'NumTreesPerPredictor', 5); assert_equal (Mdl.Intercept, 0.0570640590529, 1e-10); [~, s] = resubPredict (Mdl); assert_equal (s(1:8,2)', [0.560351428119, 0.717900932422, ... 0.93278347118, 0.717900932422, ... 0.026714476491, 0.0252640986738, ... 0.998403457947, 0.998403457947], 1e-10); ***** test # MATLAB parity: a pair tree of one split selects no interaction k = (1:200)'; X = [sin(k), cos(2 * k), mod(k, 5)]; y = 2 * sin (k) + X(:,2) .^ 2 + 0.3 * X(:,3); S = warning ('off', 'all'); unwind_protect Mdl = ClassificationGAM (X, y > median (y), 'Interactions', 1, ... 'MaxNumSplitsPerInteraction', 1, ... 'NumTreesPerPredictor', 5); unwind_protect_cleanup warning (S); end_unwind_protect assert_equal (Mdl.Interactions, zeros (0, 2)); ***** test # MATLAB parity: pair trees are fitted to the rows, on their own grid k = (1:200)'; X = [sin(k), cos(2 * k), mod(k, 5)]; y = 2 * sin (k) + X(:,2) .^ 2 + 0.3 * X(:,3); P = [0, -0.99, 0; 0, -0.42, 2; 0, 0.33, 1; 0, 0.78, 4]; Mdl = ClassificationGAM (X, y > median (y), 'NumTreesPerPredictor', 5, ... 'Interactions', 1, ... 'NumTreesPerInteraction', 2, ... 'MaxNumSplitsPerInteraction', 4); assert_equal (Mdl.Interactions, [1, 3]); assert_equal (Mdl.Intercept, 0.108918646053, 1e-10); [~, s1] = predict (Mdl, P); [~, s0] = predict (Mdl, P, 'IncludeInteractions', false); pc = log (s1(:,2) ./ s1(:,1)) - log (s0(:,2) ./ s0(:,1)); assert_equal (pc, [-1.052063091; 1.368982697; 1.368982697; ... 2.759514023], 1e-8); ***** test # resuming the interaction phase adds trees a longer run would add k = (1:200)'; X = [sin(k), cos(2 * k), mod(k, 5)]; y = 2 * sin (k) + X(:,2) .^ 2 + 0.3 * X(:,3); P = [0, -0.99, 0; 0, -0.42, 2; 0, 0.33, 1; 0, 0.78, 4]; M1 = ClassificationGAM (X, y > median (y), 'NumTreesPerPredictor', 5, ... 'Interactions', 1, 'NumTreesPerInteraction', 1, ... 'MaxNumSplitsPerInteraction', 4); M2 = ClassificationGAM (X, y > median (y), 'NumTreesPerPredictor', 5, ... 'Interactions', 1, 'NumTreesPerInteraction', 2, ... 'MaxNumSplitsPerInteraction', 4); [~, s1] = predict (resume (M1, 1), P); [~, s2] = predict (M2, P); assert_equal (s1, s2, 1e-12); ***** test # MATLAB parity: a missing value stops at the node that splits on it k = (1:200)'; X = [sin(k), cos(2 * k), mod(k, 5)]; y = 2 * sin (k) + X(:,2) .^ 2 + 0.3 * X(:,3); yc = y > median (y); X(1:5,1) = NaN; X(6:10,3) = NaN; P = [-0.99, 0, 0; -0.33, 0, 2; 0.33, 0, 4; 0.99, 0, 1; ... NaN, 0, 0; -0.9, 0, NaN; 0.9, 0, NaN; NaN, 0, NaN]; Mdl = ClassificationGAM (X, yc, 'NumTreesPerPredictor', 5, ... 'Interactions', logical ([1, 0, 1]), ... 'NumTreesPerInteraction', 2, ... 'MaxNumSplitsPerInteraction', 4); assert_equal (Mdl.Interactions, [1, 3]); assert_equal (Mdl.Intercept, 0.193222952248, 1e-10); [~, s1] = predict (Mdl, P); [~, s0] = predict (Mdl, P, 'IncludeInteractions', false); pc = log (s1(:,2) ./ s1(:,1)) - log (s0(:,2) ./ s0(:,1)); assert_equal (pc, [-2.768730478; -1.120470644; 3.467791398; ... 2.253371556; 0.09617229376; -1.145305518; ... 1.63875225; 0.09617229376], 1e-8); ***** error ... load fisheriris; ... resume (fitcgam (meas(51:150,:), species(51:150), 'NumTreesPerPredictor', 5)) ***** error ... load fisheriris; ... resume (fitcgam (meas(51:150,:), species(51:150), 'FitMethod', 'splines'), 5) ***** error ... load fisheriris; ... resume (fitcgam (meas(51:150,:), species(51:150), 'NumTreesPerPredictor', 5), 0) ***** error ... load fisheriris; ... resume (fitcgam (meas(51:150,:), species(51:150), 'NumTreesPerPredictor', 5), 2.5) ***** error ... load fisheriris; ... resume (fitcgam (meas(51:150,:), species(51:150), 'NumTreesPerPredictor', 5), [1, 2]) ***** error ... load fisheriris bai = ! strcmp (species, "setosa"); Mai = fitcgam (meas(bai,2:4), species(bai), "Interactions", 2); addInteractions (Mai, "all") ***** error ... load fisheriris bai = ! strcmp (species, "setosa"); addInteractions (fitcgam (meas(bai,2:4), species(bai), ... "FitMethod", "splines", ... "Formula", "Y ~ x1 + x2 + x1:x2"), "all") ***** error ... load fisheriris bai = ! strcmp (species, "setosa"); addInteractions (fitcgam (meas(bai,2:4), species(bai)), {1}) ***** error ... ClassificationGAM (ones (10, 2), [0; 1; 0; 1; 0; 1; 0; 1; 0; 1], ... 'CategoricalPredictors', 3) ***** error ... ClassificationGAM (ones (10, 2), [0; 1; 0; 1; 0; 1; 0; 1; 0; 1], ... 'FitMethod', 'splines', 'CategoricalPredictors', 1) ***** error ... ClassificationGAM (ones (10, 2), [ones(5,1); zeros(5,1)], 'Weights', 'a') ***** error ... ClassificationGAM (ones (10, 2), [ones(5,1); zeros(5,1)], ... 'Weights', ones (2, 2)) ***** error ... ClassificationGAM (ones (10, 2), [ones(5,1); zeros(5,1)], 'Weights', [1, 2]) ***** error ... ClassificationGAM (ones (10, 2), [ones(5,1); zeros(5,1)], 'Weights', ... -ones (10, 1)) ***** error ... ClassificationGAM ([(1:10)', mod((1:10)', 3)], [ones(5,1); zeros(5,1)], ... 'Weights', ones (10, 1), 'FitMethod', 'splines') ***** error ... ClassificationGAM (ones (4,2), ones (4,1), 'Prior', [1]) ***** error ... ClassificationGAM (ones (4,2), ones (4,1), 'Prior', [1, 2, 3]) ***** error ... ClassificationGAM (ones (4,2), ones (4,1), 'Prior', {1, 2}) ***** error ... ClassificationGAM (ones (4,2), ones (4,1), 'Prior', 'invalid') ***** error ClassificationGAM () ***** error ... ClassificationGAM (ones (4, 1)) ***** error ... ClassificationGAM (ones (4,2), ones (1,4)) ***** error ... ClassificationGAM (ones (5,2), ones (5,1), 'PredictorNames', ['A']) ***** error ... ClassificationGAM (ones (5,2), ones (5,1), 'PredictorNames', 'A') ***** error ... ClassificationGAM (ones (5,2), ones (5,1), 'PredictorNames', {'A', 'B', 'C'}) ***** error ... ClassificationGAM (ones (5,2), ones (5,1), 'ResponseName', {'Y'}) ***** error ... ClassificationGAM (ones (5,2), ones (5,1), 'ResponseName', 1) ***** error ... ClassificationGAM (ones (10,2), ones (10,1), 'ClassNames', @(x)x) ***** error ... ClassificationGAM (ones (10,2), ones (10,1), 'ClassNames', {1}) ***** error ... ClassificationGAM (ones (10,2), ones (10,1), 'ClassNames', [1, 2]) ***** error ... ClassificationGAM (ones (5,2), ['a';'b';'a';'a';'b'], 'ClassNames', ['a';'c']) ***** error ... ClassificationGAM (ones (5,2), {'a';'b';'a';'a';'b'}, 'ClassNames', {'a','c'}) ***** error ... ClassificationGAM (ones (10,2), logical (ones (10,1)), 'ClassNames', [true, false]) ***** error ... ClassificationGAM (ones (5,2), ones (5,1), 'Cost', [1, 2]) ***** error ... Mdl = fitcgam ([1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1], [0; 0; 1; 1]); Mdl.Cost = 1:4; ***** error ... ClassificationGAM (ones (5,2), ones (5,1), 'Cost', 'string') ***** error ... ClassificationGAM (ones (5,2), ones (5,1), 'Cost', {eye(2)}) ***** test x = [1, 2; 3, 4; 5, 6; 7, 8; 9, 10]; y = [1; 0; 1; 0; 1]; a = ClassificationGAM (x, y, 'FitMethod', 'splines', ... 'interactions', 'all'); l = [1; 0; 1; 0; 1]; s = [0.0334, 0.9666; 0.9648, 0.0352; 0.0334, 0.9666; ... 0.9648, 0.0352; 0.0334, 0.9666]; [labels, scores] = predict (a, x); assert_equal (class (a), "ClassificationGAM"); assert_equal ({a.X, a.Y, a.NumObservations}, {x, y, 5}) assert_equal ({a.NumPredictors, a.ResponseName}, {2, 'Y'}) assert_equal (a.ClassNames, [0; 1]) assert_equal (a.PredictorNames, {'x1', 'x2'}) assert_equal (a.ModelwInt.Intercept, 0.4055, 1e-1) assert_equal (labels, l) assert_equal (scores, s, 1e-1) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = [0; 0; 1; 1]; interactions = [false, true, false; true, false, true; false, true, false]; a = fitcgam (x, y, 'FitMethod', 'splines', ... 'learningrate', 0.2, 'interactions', interactions); [label, score] = predict (a, x, 'includeinteractions', true); l = [0; 0; 1; 1]; s = [0.9725, 0.0275; 0.9895, 0.0105; 0.0070, 0.9930; 0.0238, 0.9762]; assert_equal (class (a), "ClassificationGAM"); assert_equal ({a.X, a.Y, a.NumObservations}, {x, y, 4}) assert_equal ({a.NumPredictors, a.ResponseName}, {3, 'Y'}) assert_equal (a.ClassNames, [0; 1]) assert_equal (a.PredictorNames, {'x1', 'x2', 'x3'}) assert_equal (a.ModelwInt.Intercept, 0) assert_equal (label, l) assert_equal (score, s, 1e-1) ***** error ... predict (ClassificationGAM (ones (4,2), ones (4,1))) ***** error ... predict (ClassificationGAM (ones (4,2), ones (4,1)), []) ***** error ... predict (ClassificationGAM (ones (4,2), ones (4,1)), 1) ***** error ... predict (ClassificationGAM (ones (4,2), ones (4,1)), ones (4,2), 'Bogus') ***** error ... predict (ClassificationGAM (ones (4,2), ones (4,1)), ones (4,2), 'Bogus', 1) ***** test Xn = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; Mn = fitcgam (Xn, [1; 1; 2; 2], 'FitMethod', 'splines'); assert_equal (Mn.BaseModel.Intercept, 0, 1e-12); [label, score] = predict (Mn, Xn); assert_equal (label, [1; 1; 2; 2]); assert_equal (all (isfinite (score(:))), true); ***** test Xn = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; Mn = fitcgam (Xn, [5; 5; 9; 9], 'FitMethod', 'splines'); assert_equal (Mn.BaseModel.Intercept, 0, 1e-12); assert_equal (predict (Mn, Xn), [5; 5; 9; 9]); ***** test Xn = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; M0 = fitcgam (Xn, [0; 0; 1; 1], 'FitMethod', 'splines'); assert_equal (M0.BaseModel.Intercept, 0, 1e-12); assert_equal (predict (M0, Xn), [0; 0; 1; 1]); ***** test load fisheriris X = meas(51:150,1:2); Y = species(51:150); f = 1:3:100; t = Y(f); t(strcmp (t, 'versicolor')) = {'ZZ'}; t(strcmp (t, 'virginica')) = {'versicolor'}; t(strcmp (t, 'ZZ')) = {'virginica'}; Y(f) = t; o = {'NumTreesPerPredictor', 1, 'MaxNumSplitsPerPredictor', 1, ... 'Interactions', 0}; g1 = (4.8:0.1:8.0)'; g2 = (1.9:0.1:3.9)'; M = fitcgam (X, Y, o{:}); M.ScoreTransform = 'none'; [~, s0] = predict (M, [4.8, 1.9]); [~, sA] = predict (M, [g1, repmat(1.9, numel (g1), 1)]); [~, sB] = predict (M, [repmat(4.8, numel (g2), 1), g2]); ## the first predictor is what it is fitted alone, the second is not assert_equal (max (sA(:,2)) - s0(1,2), 1.19047619047619, 1e-12); assert_equal (max (sB(:,2)) - s0(1,2), 1.04232804232804, 1e-12); A1 = fitcgam (X(:,1), Y, o{:}); A1.ScoreTransform = 'none'; [~, a0] = predict (A1, 4.8); [~, aA] = predict (A1, g1); assert_equal (max (aA(:,2)) - a0(1,2), 1.19047619047619, 1e-12); A2 = fitcgam (X(:,2), Y, o{:}); A2.ScoreTransform = 'none'; [~, b0] = predict (A2, 1.9); [~, bB] = predict (A2, g2); assert_equal (max (bB(:,2)) - b0(1,2), 1.33333333333333, 1e-12); ***** test load fisheriris X = meas(51:150,1:2); Y = species(51:150); f = 1:3:100; t = Y(f); t(strcmp (t, 'versicolor')) = {'ZZ'}; t(strcmp (t, 'virginica')) = {'versicolor'}; t(strcmp (t, 'ZZ')) = {'virginica'}; Y(f) = t; o = {'NumTreesPerPredictor', 1, 'MaxNumSplitsPerPredictor', 1, ... 'Interactions', 0}; S = fitcgam (X(:,[2, 1]), Y, o{:}); S.ScoreTransform = 'none'; g1 = (4.8:0.1:8.0)'; g2 = (1.9:0.1:3.9)'; [~, t0] = predict (S, [1.9, 4.8]); [~, tA] = predict (S, [repmat(1.9, numel (g1), 1), g1]); [~, tB] = predict (S, [g2, repmat(4.8, numel (g2), 1)]); assert_equal (max (tB(:,2)) - t0(1,2), 1.33333333333333, 1e-12); assert_equal (max (tA(:,2)) - t0(1,2), 1.04497354497354, 1e-12); ***** test load fisheriris ii = [51:100, 101:120]'; X = meas(ii,1:2); Y = species(ii); f = 1:4:numel (ii); t = Y(f); t(strcmp (t, 'versicolor')) = {'ZZ'}; t(strcmp (t, 'virginica')) = {'versicolor'}; t(strcmp (t, 'ZZ')) = {'virginica'}; Y(f) = t; assert_equal (sum (strcmp (Y, 'virginica')), 28); M1 = fitcgam (X, Y, 'NumTreesPerPredictor', 1, ... 'MaxNumSplitsPerPredictor', 1, 'Interactions', 0); assert_equal (M1.Intercept, -0.4, 1e-12); M2 = fitcgam (X, Y, 'NumTreesPerPredictor', 2, ... 'MaxNumSplitsPerPredictor', 1, 'Interactions', 0); assert_equal (M2.Intercept, -0.43634347574616, 1e-11); M3 = fitcgam (X, Y, 'NumTreesPerPredictor', 3, ... 'MaxNumSplitsPerPredictor', 1, 'Interactions', 0); assert_equal (M3.Intercept, -0.4460203997322, 1e-11); ***** test Xn = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; assert_equal (predict (fitcgam (Xn, [1; 1; 2; 2]), Xn), [1; 1; 1; 1]); assert_equal (predict (fitcgam (Xn, [5; 5; 9; 9]), Xn), [5; 5; 5; 5]); assert_equal (predict (fitcgam (Xn, [0; 0; 1; 1]), Xn), [0; 0; 0; 0]); ***** test Y9 = repmat ({'a'}, 9, 1); Y9(6:9) = {'b'}; M9 = fitcgam ((1:9)', Y9, 'NumTreesPerPredictor', 1, ... 'MaxNumSplitsPerPredictor', 1, 'Interactions', 0); M9.ScoreTransform = 'none'; [~, s9] = predict (M9, (1:9)'); assert_equal (max (s9(:,2)) - min (s9(:,2)), 0, 1e-12); Y10 = repmat ({'a'}, 10, 1); Y10(6:10) = {'b'}; M10 = fitcgam ((1:10)', Y10, 'NumTreesPerPredictor', 1, ... 'MaxNumSplitsPerPredictor', 1, 'Interactions', 0); M10.ScoreTransform = 'none'; [~, s10] = predict (M10, (1:10)'); assert_equal (max (s10(:,2)) - min (s10(:,2)) > 1, true); ***** shared x, y, obj x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1; 4, 5, 6]; y = [0; 0; 1; 1; 0]; obj = fitcgam (x, y); ***** test status = warning; warning ('off'); rand ('seed', 23); CVMdl = crossval (obj); warning (status); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (CVMdl.KFold == 5, true) assert_equal (class (CVMdl.Trained{1}), "CompactClassificationGAM") assert_equal (CVMdl.CrossValidatedModel, "GAM") ***** test status = warning; warning ('off'); rand ('seed', 23); CVMdl = crossval (obj, 'KFold', 2); warning (status); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (CVMdl.KFold == 2, true) assert_equal (class (CVMdl.Trained{1}), "CompactClassificationGAM") assert_equal (CVMdl.CrossValidatedModel, "GAM") ***** test status = warning; warning ('off'); rand ('seed', 23); CVMdl = crossval (obj, 'HoldOut', 0.2); warning (status); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (class (CVMdl.Trained{1}), "CompactClassificationGAM") assert_equal (CVMdl.CrossValidatedModel, "GAM") ***** test status = warning; warning ('off'); rand ('seed', 23); partition = cvpartition (y, 'KFold', 3); warning (status); CVMdl = crossval (obj, 'cvPartition', partition); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal (CVMdl.KFold == 3, true) assert_equal (class (CVMdl.Trained{1}), "CompactClassificationGAM") assert_equal (CVMdl.CrossValidatedModel, "GAM") ***** error ... crossval (obj, 'kfold') ***** error... crossval (obj, 'kfold', 12, 'holdout', 0.2) ***** error ... crossval (obj, 'kfold', 'a') ***** error ... crossval (obj, 'holdout', 2) ***** error ... crossval (obj, 'leaveout', 1) ***** error ... crossval (obj, 'cvpartition', 1) ***** error ... savemodel (ClassificationGAM ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])) ***** error ... savemodel (ClassificationGAM ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), 1) ***** error ... savemodel (ClassificationGAM ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), ['ab'; 'cd']) ***** test Mdl = fitcgam ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]); Mdl.ScoreTransform = 'symmetric'; assert_equal (class (Mdl.ScoreTransform), 'char'); assert_equal (Mdl.ScoreTransform, 'symmetric'); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcgam (meas(inds,:), species(inds), 'FitMethod', 'splines'); assert_equal (Mdl.Intercept, Mdl.BaseModel.Intercept); assert_equal (size (Mdl.W), [Mdl.NumObservations, 1]); assert_equal (sum (Mdl.W), 1, 1e-12); assert_equal (Mdl.CategoricalPredictors, []); assert_equal (Mdl.ExpandedPredictorNames, Mdl.PredictorNames); ***** test assert_equal (fitcgam ([1;2;3;4], [7;3;7;3]).ClassNames, [3; 7]); assert_equal (fitcgam ([1;2;3;4], logical ([1;0;1;0])).ClassNames, ... logical ([0; 1])); assert_equal (fitcgam ([1;2;3;4], {'b';'a';'b';'a'}).ClassNames, ... {'a'; 'b'}); assert_equal (fitcgam ([1;2;3;4], ['b';'a';'b';'a']).ClassNames, ['a';'b']); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcgam (meas(inds,:), species(inds)); Mdl.ScoreTransform = 'none'; [~, raw] = predict (Mdl, meas(inds,:)); Mdl.ScoreTransform = 'symmetric'; [~, s1] = predict (Mdl, meas(inds,:)); assert_equal (s1, 2 * raw - 1, 1e-12); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); X = meas(inds,:); Y = species(inds); Mdl = fitcgam (X, Y); m = margin (Mdl, X, Y); assert_equal (edge (Mdl, X, Y), mean (m), 1e-12); ## The weights are normalized within each class to that class's prior, ## not divided by their total, so a class keeps the influence its prior ## gives it however the weights inside it are spread. w = [ones(50, 1); 3 * ones(50, 1)]; wn = w; wn(1:50) = w(1:50) / sum (w(1:50)) * Mdl.Prior(1); wn(51:100) = w(51:100) / sum (w(51:100)) * Mdl.Prior(2); assert_equal (edge (Mdl, X, Y, 'Weights', w), ... sum (wn .* m) / sum (wn), 1e-12); ## Scaling a whole class leaves the edge where it was. assert_equal (edge (Mdl, X, Y, 'Weights', w), ... edge (Mdl, X, Y, 'Weights', [ones(50,1); ones(50,1)]), 1e-12); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); X = meas(inds,:); Y = species(inds); Mdl = fitcgam (X, Y); assert_equal (resubPredict (Mdl), predict (Mdl, X)); assert_equal (resubMargin (Mdl), margin (Mdl, X, Y)); assert_equal (resubEdge (Mdl), edge (Mdl, X, Y)); assert_equal (resubLoss (Mdl), loss (Mdl, X, Y)); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); X = meas(inds,:); Y = species(inds); Mdl = fitcgam (X, Y); names = {'binodeviance', 'classifcost', 'classiferror', 'exponential', ... 'hinge', 'logit', 'mincost', 'quadratic'}; for k = 1:numel (names) L = loss (Mdl, X, Y, 'LossFun', names{k}); assert_equal (isscalar (L) && isfinite (L), true); endfor ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcgam (meas(inds,:), species(inds)); Mdl.Cost = [0, 2; 5, 0]; assert_equal (Mdl.Cost, [0, 2; 5, 0]); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); X = meas(inds,:); Mdl = fitcgam (X, species(inds), 'FitMethod', 'splines', ... 'Interactions', 'all', 'NumIterations', 20); Mdl.ScoreTransform = 'symmetric'; fname = tempname (); savemodel (Mdl, fname); Mdl2 = loadmodel (fname); delete (fname); assert_equal (Mdl2.Intercept, Mdl.Intercept); assert_equal (Mdl2.W, Mdl.W); assert_equal (Mdl2.ExpandedPredictorNames, Mdl.ExpandedPredictorNames); assert_equal (Mdl2.ModelwInt.Parameters(1).coefs, ... Mdl.ModelwInt.Parameters(1).coefs); assert_equal (Mdl2.ScoreTransform, 'symmetric'); [label, score] = predict (Mdl, X); [label2, score2] = predict (Mdl2, X); assert_equal (label2, label); assert_equal (score2, score); ***** shared x, y, Mdl load fisheriris inds = ! strcmp (species, 'virginica'); x = meas(inds,:); y = species(inds); Mdl = fitcgam (x, y); ***** error ... margin (Mdl, x) ***** error ... margin (Mdl, [], y) ***** error ... margin (Mdl, 1, y) ***** error ... margin (Mdl, x, []) ***** error ... margin (Mdl, x, y(1:10)) ***** error ... edge (Mdl, x) ***** error ... edge (Mdl, x, y, 'Weights') ***** error ... edge (Mdl, x, y, 'LossFun', 'hinge') ***** error ... edge (Mdl, x, y, 'Weights', 'a') ***** error ... edge (Mdl, x, y, 'Weights', ones (2, 2)) ***** error ... edge (Mdl, x, y, 'Weights', [1, 2, 3]) ***** error ... loss (Mdl, x) ***** error ... loss (Mdl, x, y, 'LossFun') ***** error ... loss (Mdl, x, y, 'LossFun', 1) ***** error ... loss (Mdl, x, y, 'LossFun', 'nonsense') ***** error ... loss (Mdl, x, y, 'Bogus', 1) ***** test load fisheriris X = meas(1:100,:); Y = grp2idx (species(1:100)); Mdl = fitcgam (X, Y); assert_equal (Mdl.RowsUsed, []); assert_equal (class (Mdl.RowsUsed), 'double'); assert_equal (Mdl.NumObservations, 100); assert_equal (rows (Mdl.X), 100); assert_equal (rows (Mdl.W), 100); ***** test load fisheriris X = meas(1:100,:); Y = grp2idx (species(1:100)); Y(5) = NaN; Mdl = fitcgam (X, Y); assert_equal (class (Mdl.RowsUsed), 'logical'); assert_equal (size (Mdl.RowsUsed), [100, 1]); assert_equal (sum (Mdl.RowsUsed), 99); assert_equal (Mdl.RowsUsed(5), false); assert_equal (Mdl.NumObservations, 99); assert_equal (rows (Mdl.X), 99); assert_equal (rows (Mdl.W), 99); ***** test load fisheriris X = meas(1:100,:); X(3,2) = NaN; Y = grp2idx (species(1:100)); Mdl = fitcgam (X, Y); assert_equal (Mdl.RowsUsed, []); assert_equal (Mdl.NumObservations, 100); assert_equal (rows (Mdl.X), 100); assert_equal (sum (isnan (Mdl.X(:))), 1); ***** test load fisheriris i2 = [1:50, 51:80]; Mdl = fitcgam (meas(i2,:), species(i2)); assert_equal (Mdl.Prior, [0.625, 0.375], 1e-14); assert_equal (Mdl.W(1), 0.0125, 1e-14); Mdl = fitcgam (meas(i2,:), species(i2), 'Prior', 'uniform'); assert_equal (Mdl.W(1), 0.01, 1e-14); assert_equal (Mdl.W(51), 1/60, 1e-14); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcgam (meas(inds,:), species(inds)); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2), 'ClassificationGAM'); assert_equal (M2.NumObservations, Mdl.NumObservations); assert_equal (M2.PredictorNames, Mdl.PredictorNames); assert_equal (class (M2.ScoreTransform), class (Mdl.ScoreTransform)); assert_equal (predict (M2, meas(1:5,:)), predict (Mdl, meas(1:5,:))); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcgam (meas(inds,:), species(inds)); assert_equal (Mdl.ScoreTransform, 'logit'); [~, scores] = predict (Mdl, meas(1:6,:)); assert_equal (sum (scores, 2), ones (6, 1), 1e-12); assert_equal (all (scores(:) >= 0 & scores(:) <= 1), true); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcgam (meas(inds,:), species(inds)); [~, post] = predict (Mdl, meas(1:6,:)); Mdl.ScoreTransform = 'none'; [~, raw] = predict (Mdl, meas(1:6,:)); assert_equal (sum (raw, 2), zeros (6, 1), 1e-12); assert_equal (1 ./ (1 + exp (-raw)), post, 1e-12); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcgam (meas(inds,:), species(inds)); assert_equal (class (Mdl.BinEdges), 'cell'); assert_equal (numel (Mdl.BinEdges), 4); assert_equal (numel (Mdl.BinEdges{1}), 27); Msp = fitcgam (meas(inds,:), species(inds), 'FitMethod', 'splines'); assert_equal (Msp.BinEdges, {}); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcgam (meas(inds,:), species(inds)); S = struct ('ClassNames', {{'versicolor'; 'setosa'}}, ... 'ClassificationCosts', [0, 1; 2, 0]); Mdl.Cost = S; assert_equal (Mdl.Cost, [0, 2; 1, 0]); ***** error ... load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcgam (meas(inds,:), species(inds)); Mdl.Cost = ones (2); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcgam (meas(inds,:), species(inds), 'FitMethod', 'boostedtrees'); assert_equal (Mdl.FitMethod, 'boostedtrees'); assert_equal (numel (Mdl.BinEdges), 4); assert_equal (numel (Mdl.BinEdges{1}), 27); assert_equal (numel (fieldnames (Mdl.ModelParameters)), 13); assert_equal (Mdl.ModelParameters.Type, 'classification'); assert_equal (Mdl.ModelParameters.Method, 'GAM'); ***** test Mdl = fitcgam ([1, 2; 2, 3; 3, 4; 4, 5; 5, 6; 6, 7], [0;0;0;1;1;1], ... 'FitMethod', 'boostedtrees'); MP = Mdl.ModelParameters; assert_equal (MP.NumTreesPerPredictor, 300); assert_equal (MP.NumTreesPerInteraction, 100); assert_equal (MP.MaxNumSplitsPerPredictor, 1); assert_equal (MP.MaxNumSplitsPerInteraction, 4); assert_equal (MP.InitialLearnRateForPredictors, 1); assert_equal (MP.InitialLearnRateForInteractions, 1); assert_equal (MP.MaxPValue, 1); assert_equal (MP.NumPrint, 10); assert_equal (MP.VerbosityLevel, 0); ***** test Mdl = fitcgam ([1, 2; 2, 3; 3, 4; 4, 5; 5, 6; 6, 7], [0;0;0;1;1;1], ... 'FitMethod', 'boostedtrees'); assert_equal (isfield (Mdl.ReasonForTermination, 'PredictorTrees'), true); assert_equal (isfield (Mdl.ReasonForTermination, 'InteractionTrees'), true); assert_equal (Mdl.ReasonForTermination.InteractionTrees, ''); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcgam (meas(inds,:), species(inds), 'FitMethod', 'boostedtrees', ... 'Interactions', 'all'); assert_equal (rows (Mdl.Interactions), 6); assert_equal (columns (Mdl.Interactions), 2); assert_equal (numel (Mdl.PairDetectionBinEdges{1}), 7); assert_equal (! isempty (Mdl.ReasonForTermination.InteractionTrees), true); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); X = meas(inds,:); Mdl = fitcgam (X, species(inds), 'FitMethod', 'boostedtrees'); [label, score] = predict (Mdl, X); assert_equal (numel (label), rows (X)); assert_equal (sum (score, 2), ones (rows (X), 1), 1e-12); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); X = meas(inds,:); Mdl = fitcgam (X, species(inds), 'FitMethod', 'boostedtrees'); CMdl = compact (Mdl); assert_equal (CMdl.FitMethod, 'boostedtrees'); assert_equal (CMdl.BinEdges, Mdl.BinEdges); assert_equal (predict (CMdl, X), predict (Mdl, X)); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); X = meas(inds,:); Mdl = fitcgam (X, species(inds), 'FitMethod', 'boostedtrees'); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.FitMethod, 'boostedtrees'); assert_equal (M2.TreeModel.ShapeValues, Mdl.TreeModel.ShapeValues); assert_equal (predict (M2, X), predict (Mdl, X)); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcgam (meas(inds,:), species(inds), 'FitMethod', 'splines'); assert_equal (Mdl.FitMethod, 'splines'); assert_equal (Mdl.BinEdges, {}); assert_equal (isempty (Mdl.TreeModel), true); assert_equal (Mdl.Knots, [5, 5, 5, 5]); ***** error ... fitcgam ([1;2;3;4], [0;0;1;1], 'FitMethod', 'nonsense') ***** error ... fitcgam ([1;2;3;4], [0;0;1;1], 'FitMethod', 5) ***** error ... fitcgam ([1;2;3;4], [0;0;1;1], 'FitMethod', 'boostedtrees', 'Knots', 4) ***** error ... fitcgam ([1;2;3;4], [0;0;1;1], 'FitMethod', 'splines', 'MaxPValue', 0.5) ***** error ... fitcgam ([1;2;3;4], [0;0;1;1], 'FitMethod', 'boostedtrees', ... 'NumTreesPerPredictor', 0) ***** error ... fitcgam ([1;2;3;4], [0;0;1;1], 'FitMethod', 'boostedtrees', ... 'NumTreesPerInteraction', 1.5) ***** error ... fitcgam ([1;2;3;4], [0;0;1;1], 'FitMethod', 'boostedtrees', ... 'MaxNumSplitsPerPredictor', -1) ***** error ... fitcgam ([1;2;3;4], [0;0;1;1], 'FitMethod', 'boostedtrees', ... 'MaxNumSplitsPerInteraction', 'a') ***** error ... fitcgam ([1;2;3;4], [0;0;1;1], 'FitMethod', 'boostedtrees', ... 'InitialLearnRateForPredictors', 0) ***** error ... fitcgam ([1;2;3;4], [0;0;1;1], 'FitMethod', 'boostedtrees', ... 'InitialLearnRateForInteractions', 2) ***** error ... fitcgam ([1;2;3;4], [0;0;1;1], 'FitMethod', 'boostedtrees', 'Verbose', -1) ***** error ... fitcgam ([1;2;3;4], [0;0;1;1], 'FitMethod', 'boostedtrees', 'NumPrint', 0) ***** error ... fitcgam ([1;2;3;4], [0;0;1;1], 'FitMethod', 'boostedtrees', 'MaxPValue', 2) ***** test load fisheriris b = ! strcmp (species, 'virginica'); Mdl = fitcgam (meas(b,:), species(b)); assert_equal (isempty (Mdl.HyperparameterOptimizationResults), true); ***** test load fisheriris Mdl = fitcgam (meas, strcmp (species, 'setosa')); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); T = {'identity', @(x) x; 'doublelogit', @(x) 1 ./ (1 + exp (-2 * x)); ... 'invlogit', @(x) log (x ./ (1 - x)); ... 'logit', @(x) 1 ./ (1 + exp (-x)); ... 'sign', @(x) sign (x); 'symmetric', @(x) 2 * x - 1; ... 'symmetriclogit', @(x) 2 ./ (1 + exp (-x)) - 1}; for i = 1:rows (T) Mdl.ScoreTransform = T{i,1}; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, T{i,2}(raw), 1e-12); assert_equal (l, label); endfor ## ismax marks the largest score of each observation, ties to the first. [~, k] = max (raw, [], 2); e = zeros (size (raw)); e(sub2ind (size (raw), (1:rows (raw))', k)) = 1; Mdl.ScoreTransform = 'ismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, e); Mdl.ScoreTransform = 'symmetricismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, 2 * e - 1); ***** test load fisheriris Mdl = fitcgam (meas, strcmp (species, 'setosa')); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); Mdl.ScoreTransform = @(x) x .^ 2; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, raw .^ 2, 1e-12); assert_equal (l, label); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(51:150,1:2); y = categorical (species(51:150)); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcgam (T, 'Species'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(51:150,1:2); y = categorical (species(51:150)); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcgam (T, 'Species'); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(51:150,1:2); y = categorical (species(51:150)); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcgam (T, 'Species'); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** test load fisheriris X = meas(51:150,1); Y = species(51:150); M = fitcgam (X, Y, 'FitMethod', 'splines', 'Knots', 5, 'DoF', 9); assert_equal ([M.Knots, M.Order, M.DoF], [5, 4, 9]); M = fitcgam (X, Y, 'FitMethod', 'splines', 'DoF', 9, 'Knots', 5); assert_equal ([M.Knots, M.Order, M.DoF], [5, 4, 9]); M = fitcgam (X, Y, 'FitMethod', 'splines', 'Order', 2, 'DoF', 9); assert_equal ([M.Knots, M.Order, M.DoF], [7, 2, 9]); ***** error ... ClassificationGAM (ones (10,2), [ones(5,1); zeros(5,1)], ... 'FitMethod', 'splines', 'Knots', 5, 'Order', 3, 'DoF', 8) ***** error ... ClassificationGAM (ones (10,2), [ones(5,1); zeros(5,1)], ... 'FitMethod', 'splines', 'Interactions', 1, ... 'Formula', 'Y ~ x1 + x2') ***** error ... ClassificationGAM (ones (10,2), [ones(5,1); zeros(5,1)], 'Bogus', 1) ***** error ... ClassificationGAM ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', ... int8 ([1; 1; 1; 1])) ***** error ... ClassificationGAM ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', ... true (4, 1)) ***** error ... loss (ClassificationGAM ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2]), ... [1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', int8 ([1; 1; 1; 1])) ***** test ## Single weights are stored single, summing to one load fisheriris X = meas(51:end,:); Y = species(51:end); w = 1 + (1:100)' / 7; Mdl = ClassificationGAM (X, Y, 'Weights', single (w)); assert_equal (class (Mdl.W), 'single'); assert_equal (sum (double (Mdl.W)), 1, 1e-6); ***** test ## Single weights compute as double, to the precision of the stored W load fisheriris X = meas(51:end,:); Y = species(51:end); w = 1 + (1:100)' / 7; A = ClassificationGAM (X, Y, 'Weights', single (w)); B = ClassificationGAM (X, Y, 'Weights', double (single (w))); assert_equal (nthargout (2, @predict, A, X), ... nthargout (2, @predict, B, X), 1e-8); 178 tests, 178 passed, 0 known failure, 0 skipped [inst/Machine_Learning/RegressionPartitionedModel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/RegressionPartitionedModel.m ***** test rand ('seed', 42); randn ('seed', 42); X = randn (40, 2); Y = X(:,1) - 2 * X(:,2); Mdl = fitrnet (X, Y, 'IterationLimit', 30); CVMdl = crossval (Mdl, 'KFold', 4); assert_equal (class (CVMdl), 'RegressionPartitionedModel'); assert_equal (CVMdl.KFold, 4); assert_equal (numel (CVMdl.Trained), 4); assert_equal (class (CVMdl.Trained{1}), 'CompactRegressionNeuralNetwork'); assert_equal (CVMdl.CrossValidatedModel, 'NeuralNetwork'); assert_equal (CVMdl.NumObservations, 40); assert_equal (CVMdl.ResponseName, 'Y'); assert_equal (class (CVMdl.Partition), 'cvpartition'); ***** test rand ('seed', 42); randn ('seed', 42); X = randn (40, 2); Y = X(:,1) + X(:,2); CVMdl = crossval (fitrsvm (X, Y), 'KFold', 4); assert_equal (class (CVMdl.Trained{1}), 'CompactRegressionSVM'); assert_equal (CVMdl.CrossValidatedModel, 'SVM'); ***** test load fisheriris CVMdl = crossval (fitrgam (meas(1:20,1:3), meas(1:20,4)), 'KFold', 4); assert_equal (class (CVMdl.Trained{1}), 'CompactRegressionGAM'); assert_equal (CVMdl.CrossValidatedModel, 'GAM'); assert_equal (CVMdl.NumObservations, 20); ## The learner's thirteen fields come through, with NLearn added and the ## three tags reissued for this class, so fourteen in all. assert_equal (isstruct (CVMdl.ModelParameters), true); assert_equal (numfields (CVMdl.ModelParameters), 14); assert_equal (isfield (CVMdl.ModelParameters, 'NumTreesPerPredictor'), true); assert_equal (CVMdl.ModelParameters.Method, 'PartitionedModel'); ***** test # a GAM fold is fitted with the weights of the rows it holds k = (1:60)'; X = [sin(k), cos(2 * k)]; y = 2 * sin (k) + X(:,2) .^ 2; w = 1 + mod (k, 3); CVMdl = crossval (RegressionGAM (X, y, 'Weights', w), 'KFold', 3); idx = training (CVMdl.Partition, 1); F = fitrgam (X(idx,:), y(idx), 'Weights', w(idx)); assert_equal (CVMdl.Trained{1}.Intercept, F.Intercept, 1e-10); ***** error ... RegressionPartitionedModel (1, cvpartition (10, 'KFold', 2)) ***** test rand ('seed', 42); randn ('seed', 42); X = randn (30, 2); Y = X(:,1) * 2; CVMdl = crossval (fitrsvm (X, Y), 'KFold', 5); yFit = kfoldPredict (CVMdl); assert_equal (size (yFit), [30, 1]); assert_equal (any (isnan (yFit)), false); ***** test rand ('seed', 42); randn ('seed', 42); X = randn (40, 2); Y = X(:,1); CVMdl = crossval (fitrsvm (X, Y), 'Holdout', 0.25); yFit = kfoldPredict (CVMdl); assert_equal (CVMdl.KFold, 1); assert_equal (sum (! isnan (yFit)), sum (test (CVMdl.Partition, 1))); assert_equal (sum (isnan (yFit)), sum (training (CVMdl.Partition, 1))); ***** test rand ('seed', 42); randn ('seed', 42); X = randn (12, 2); Y = X(:,1) + 1; CVMdl = crossval (fitrsvm (X, Y), 'Leaveout', 'on'); assert_equal (CVMdl.KFold, 12); assert_equal (any (isnan (kfoldPredict (CVMdl))), false); ***** test rand ('seed', 42); randn ('seed', 42); X = randn (30, 2); Y = X(:,2); cvp = cvpartition (30, 'KFold', 3); CVMdl = crossval (fitrsvm (X, Y), 'CVPartition', cvp); assert_equal (CVMdl.KFold, 3); assert_equal (CVMdl.Partition.NumObservations, 30); ***** test rand ('seed', 42); randn ('seed', 42); X = randn (40, 2); Y = X(:,1) - X(:,2); CVMdl = crossval (fitrsvm (X, Y), 'KFold', 4); yFit = kfoldPredict (CVMdl); assert_equal (kfoldLoss (CVMdl), mean ((Y - yFit) .^ 2), 1e-12); assert_equal (kfoldLoss (CVMdl, 'LossFun', 'mse'), ... kfoldLoss (CVMdl), 1e-12); ***** test rand ('seed', 42); randn ('seed', 42); X = randn (40, 2); Y = X(:,1) * 3; CVMdl = crossval (fitrsvm (X, Y), 'KFold', 4); yFit = kfoldPredict (CVMdl); L = kfoldLoss (CVMdl, 'Mode', 'individual'); assert_equal (size (L), [4, 1]); idx = test (CVMdl.Partition, 2); assert_equal (L(2), mean ((Y(idx) - yFit(idx)) .^ 2), 1e-12); ***** test rand ('seed', 42); randn ('seed', 42); X = randn (40, 2); Y = X(:,2) - 1; CVMdl = crossval (fitrsvm (X, Y), 'KFold', 4); yFit = kfoldPredict (CVMdl); idx = test (CVMdl.Partition, 1) | test (CVMdl.Partition, 3); assert_equal (kfoldLoss (CVMdl, 'Folds', [1, 3]), ... mean ((Y(idx) - yFit(idx)) .^ 2), 1e-12); assert_equal (numel (kfoldLoss (CVMdl, 'Folds', [2, 4], ... 'Mode', 'individual')), 2); ***** test rand ('seed', 42); randn ('seed', 42); X = randn (40, 2); Y = X(:,1) * 2; CVMdl = crossval (fitrsvm (X, Y, 'Epsilon', 0.4), 'KFold', 4); yFit = kfoldPredict (CVMdl); assert_equal (kfoldLoss (CVMdl, 'LossFun', 'epsiloninsensitive'), ... mean (max (0, abs (Y - yFit) - 0.4)), 1e-12); ***** test rand ('seed', 42); randn ('seed', 42); X = randn (30, 2); Y = X(:,1); CVMdl = crossval (fitrsvm (X, Y), 'KFold', 3); yFit = kfoldPredict (CVMdl); f = @(y, yf, w) sum (w .* abs (y - yf)); assert_equal (kfoldLoss (CVMdl, 'LossFun', f), ... mean (abs (Y - yFit)), 1e-12); ***** test rand ('seed', 42); randn ('seed', 42); X = [randn(20, 2); NaN, 1]; Y = [randn(20, 1); 3]; Mdl = fitrsvm (X, Y); CVMdl = crossval (Mdl, 'KFold', 4); assert_equal (CVMdl.NumObservations, 21); assert_equal (rows (CVMdl.X), 21); assert_equal (numel (kfoldPredict (CVMdl)), 21); ***** test load fisheriris CVMdl = crossval (fitrgp (meas(:,1:3), meas(:,4)), 'KFold', 5); [yFit, ySD, yInt] = kfoldPredict (CVMdl); assert_equal (size (yFit), [150, 1]); assert_equal (size (ySD), [150, 1]); assert_equal (size (yInt), [150, 2]); assert_equal (all (ySD > 0), true); assert_equal (yFit, kfoldPredict (CVMdl), 1e-12); ***** test load fisheriris CVMdl = crossval (fitrgp (meas(:,1:3), meas(:,4)), 'KFold', 5); [yFit, ySD, yInt] = kfoldPredict (CVMdl); z = norminv (0.975); assert_equal (yInt, [yFit - z * ySD, yFit + z * ySD], 1e-12); [~, ~, yInt90] = kfoldPredict (CVMdl, 'Alpha', 0.10); z90 = norminv (0.95); assert_equal (yInt90, [yFit - z90 * ySD, yFit + z90 * ySD], 1e-12); assert_equal (all (diff (yInt90, 1, 2) < diff (yInt, 1, 2)), true); ***** test load fisheriris CVMdl = crossval (fitrgp (meas(:,1:3), meas(:,4)), 'KFold', 5); [yFit, ySD, yInt] = kfoldPredict (CVMdl); idx = test (CVMdl.Partition, 2); [p, s, i] = predict (CVMdl.Trained{2}, meas(idx,1:3)); assert_equal (p, yFit(idx), 1e-12); assert_equal (s, ySD(idx), 1e-12); assert_equal (i, yInt(idx,:), 1e-12); ***** test load fisheriris CVMdl = crossval (fitrgp (meas(:,1:3), meas(:,4)), 'Holdout', 0.3); [yFit, ySD, yInt] = kfoldPredict (CVMdl); untested = isnan (yFit); assert_equal (any (untested), true); assert_equal (isnan (ySD), untested); assert_equal (isnan (yInt), [untested, untested]); ***** test load fisheriris CVMdl = crossval (fitrgp (meas(:,1:3), meas(:,4)), 'KFold', 5); [yFit, ySD, yInt] = kfoldPredict (CVMdl); CVMdl.ResponseTransform = @(x) 2 * x; [yFit2, ySD2, yInt2] = kfoldPredict (CVMdl); assert_equal (yFit2, 2 * yFit, 1e-12); assert_equal (ySD2, ySD, 1e-12); assert_equal (yInt2, 2 * yInt, 1e-12); ***** test load fisheriris cvp = cvpartition ('CustomPartition', repmat ((1:5)', 30, 1)); CVMdl = crossval (fitrgp (meas(:,1:3), meas(:,4)), 'CVPartition', cvp); [yFit, ySD, yInt] = kfoldPredict (CVMdl); assert_equal (yFit(1), 0.21819014717001, 1e-9); assert_equal (ySD(1), 0.17986522125163, 1e-9); assert_equal (yInt(1,:), [-0.13433920855451, 0.57071950289454], 1e-9); assert_equal (sum (abs (yFit)), 179.61497470708, 1e-6); assert_equal (sum (abs (ySD)), 27.747043040728, 1e-6); [~, ~, yInt90] = kfoldPredict (CVMdl, 'Alpha', 0.10); assert_equal (yInt90(1,:), [-0.077661814368161, 0.51404210870819], 1e-9); ***** error ... load fisheriris; ... CVMdl = crossval (fitrsvm (meas(:,1:3), meas(:,4)), 'KFold', 3); ... [yFit, ySD] = kfoldPredict (CVMdl); ***** error ... load fisheriris; ... CVMdl = crossval (fitrgam (meas(:,1:3), meas(:,4)), 'KFold', 3); ... [yFit, ySD, yInt] = kfoldPredict (CVMdl); ***** error ... load fisheriris; ... CVMdl = crossval (fitrsvm (meas(:,1:3), meas(:,4)), 'KFold', 3); ... kfoldPredict (CVMdl, 'Alpha', 0.1); ***** error ... load fisheriris; ... CVMdl = crossval (fitrgp (meas(:,1:3), meas(:,4)), 'KFold', 3); ... kfoldPredict (CVMdl, 'Alpha'); ***** error ... load fisheriris; ... CVMdl = crossval (fitrgp (meas(:,1:3), meas(:,4)), 'KFold', 3); ... kfoldPredict (CVMdl, 'Alpha', 2); ***** error ... load fisheriris; ... CVMdl = crossval (fitrgp (meas(:,1:3), meas(:,4)), 'KFold', 3); ... kfoldPredict (CVMdl, 'Bogus', 1); ***** test # MATLAB parity: a cross-validated regression tree, over compact folds load carsmall X = [Weight, Cylinders, Horsepower]; a = fitrtree (X, MPG); cvModel = crossval (a, 'KFold', 5); assert_equal (class (cvModel), "RegressionPartitionedModel"); assert_equal (cvModel.CrossValidatedModel, "Tree"); assert_equal (class (cvModel.Trained{1}), "CompactRegressionTree"); assert_equal (cvModel.KFold, 5); assert_equal (cvModel.NumObservations, 94); assert_equal (cvModel.ResponseTransform, 'none'); ***** test # A tree fold is grown with the parameters the parent was grown with load carsmall X = [Weight, Cylinders, Horsepower]; a = fitrtree (X, MPG, 'MinLeafSize', 15, 'QuadraticErrorTolerance', 0.01); cvModel = crossval (a, 'KFold', 3); assert_equal (cvModel.ModelParameters.SplitCriterion, 'mse'); assert_equal (cvModel.ModelParameters.MinLeaf, 15); assert_equal (cvModel.ModelParameters.QEToler, 0.01); assert_equal (min (cvModel.Trained{1}.NodeSize) >= 15, true); ***** test # kfoldPredict answers every observation of a cross-validated tree load carsmall X = [Weight, Cylinders, Horsepower]; cvModel = crossval (fitrtree (X, MPG), 'KFold', 5); yFit = kfoldPredict (cvModel); assert_equal (size (yFit), [94, 1]); assert_equal (any (isnan (yFit)), false); assert_equal (kfoldLoss (cvModel) > 0, true); assert_equal (size (kfoldLoss (cvModel, 'Mode', 'individual')), [5, 1]); ***** error load carsmall X = [Weight, Cylinders, Horsepower]; [y, sd] = kfoldPredict (crossval (fitrtree (X, MPG), 'KFold', 3)); ***** error ... RegressionPartitionedModel () ***** error ... RegressionPartitionedModel (fitrsvm (ones (5, 2), [1; 2; 3; 4; 5])) ***** error ... RegressionPartitionedModel (5, cvpartition (5, 'KFold', 2)) ***** error ... RegressionPartitionedModel (fitcnet (ones (4, 2), [1; 1; 2; 2]), ... cvpartition (4, 'KFold', 2)) ***** error ... RegressionPartitionedModel (fitrsvm (ones (5, 2), [1; 2; 3; 4; 5]), 5) ***** error ... RegressionPartitionedModel (fitrsvm (ones (5, 2), [1; 2; 3; 4; 5]), ... cvpartition (9, 'KFold', 3)) ***** shared CVR rand ('seed', 42); randn ('seed', 42); CVR = crossval (fitrsvm (randn (20, 2), randn (20, 1)), 'KFold', 4); ***** error ... kfoldLoss (CVR, 'Mode') ***** error ... kfoldLoss (CVR, 5, 1) ***** error ... kfoldLoss (CVR, 'LossFun', 5) ***** error ... kfoldLoss (CVR, 'LossFun', 'mae') ***** error ... kfoldLoss (CVR, 'LossFun', @(y, yf, w) [1, 2]) ***** error ... kfoldLoss (CVR, 'Mode', 'nope') ***** error ... kfoldLoss (CVR, 'Folds', 0) ***** error ... kfoldLoss (CVR, 'Folds', 9) ***** error ... kfoldLoss (CVR, 'Nope', 1) ***** error ... kfoldLoss (crossval (fitrnet (randn (20, 2), randn (20, 1), ... 'IterationLimit', 5), 'KFold', 4), ... 'LossFun', 'epsiloninsensitive') ***** test load fisheriris CVMdl = crossval (fitrsvm (meas(:,1:3), meas(:,4)), 'KFold', 3); assert_equal (class (CVMdl.BinEdges), 'cell'); assert_equal (CVMdl.BinEdges, {}); ***** test load fisheriris CVMdl = crossval (fitrgam (meas(:,1:3), meas(:,4), ... 'ResponseTransform', 'exp'), 'KFold', 3); assert_equal (CVMdl.ResponseTransform, 'exp'); assert_equal (CVMdl.Trained{1}.ResponseTransform, 'none'); ***** test load fisheriris CVMdl = crossval (fitrnet (meas(:,1:3), meas(:,4), ... 'ResponseTransform', 'exp'), 'KFold', 3); assert_equal (CVMdl.ResponseTransform, 'exp'); assert_equal (CVMdl.Trained{1}.ResponseTransform, 'none'); ***** test load fisheriris CVMdl = crossval (fitrgp (meas(:,1:3), meas(:,4), ... 'ResponseTransform', 'exp'), 'KFold', 3); assert_equal (CVMdl.ResponseTransform, 'exp'); assert_equal (CVMdl.Trained{1}.ResponseTransform, 'none'); ***** test load fisheriris CVMdl = crossval (fitrsvm (meas(:,1:3), meas(:,4)), 'KFold', 3); y0 = kfoldPredict (CVMdl); CVMdl.ResponseTransform = @(x) x + 100; y1 = kfoldPredict (CVMdl); assert_equal (CVMdl.Trained{1}.ResponseTransform, 'none'); assert_equal (y1, y0 + 100, 1e-12); ***** test load fisheriris CVMdl = crossval (fitrsvm (meas(:,1:3), meas(:,4)), 'KFold', 3); before = kfoldLoss (CVMdl); CVMdl.ResponseTransform = @(x) x + 100; assert (kfoldLoss (CVMdl) > before); ***** test load fisheriris CVMdl = crossval (fitrnet (meas(:,1:3), meas(:,4)), 'KFold', 3); y0 = kfoldPredict (CVMdl); CVMdl.ResponseTransform = 'none'; assert_equal (kfoldPredict (CVMdl), y0); ***** test assert_equal (any (strcmp (methods ("RegressionPartitionedModel"), ... "foldLoss_")), false); ***** test load fisheriris Mdl = fitrgam (meas(:,2:4), meas(:,1), 'FitMethod', 'boostedtrees'); CVMdl = crossval (Mdl, 'KFold', 3); assert_equal (class (CVMdl), 'RegressionPartitionedModel'); assert_equal (numel (CVMdl.Trained), 3); assert_equal (CVMdl.Trained{1}.FitMethod, 'boostedtrees'); assert_equal (numel (kfoldPredict (CVMdl)), rows (meas)); ***** test load fisheriris Mdl = fitrgam (meas(1:60,1:3), meas(1:60,4), 'FitMethod', 'splines', ... 'Knots', 4); CVMdl = crossval (Mdl, 'KFold', 3); assert_equal (CVMdl.Trained{1}.FitMethod, 'splines'); assert_equal (isfield (CVMdl.Trained{1}.BaseModel, 'Intercept'), true); ***** test ## kfoldfun hands over seven arguments, the fold's model first. load fisheriris CV = crossval (fitrgam (meas(:,2:4), meas(:,1)), "KFold", 3); seen = kfoldfun (CV, @(M, Xtr, Ytr, Wtr, Xte, Yte, Wte) ... [rows(Xtr), rows(Yte), columns(Xtr)]); assert_equal (size (seen), [3, 3]); assert_equal (seen(:,1) + seen(:,2), repmat (150, 3, 1)); assert_equal (seen(:,3), repmat (3, 3, 1)); ***** test ## The use it exists for: a held-out mean squared error per fold. load fisheriris CV = crossval (fitrgam (meas(:,2:4), meas(:,1)), "KFold", 3); f = @(M, Xtr, Ytr, Wtr, Xte, Yte, Wte) mean ((predict (M, Xte) - Yte) .^ 2); mse = kfoldfun (CV, f); assert_equal (size (mse), [3, 1]); assert_equal (all (mse > 0), true); ***** error ... kfoldfun (crossval (fitrgam (ones (8, 2), (1:8)'), "KFold", 2)) ***** error ... kfoldfun (crossval (fitrgam (ones (8, 2), (1:8)'), "KFold", 2), "nope") ***** test ## The property order is MATLAB's, measured on R2024a. load fisheriris CVMdl = crossval (fitrsvm (meas(:,2:4), meas(:,1)), "KFold", 3); assert_equal (sort (properties (CVMdl)), ... sort ({'ResponseTransform'; 'CrossValidatedModel'; ... 'PredictorNames'; 'CategoricalPredictors'; ... 'ResponseName'; 'NumObservations'; 'X'; 'Y'; 'W'; ... 'ModelParameters'; 'Trained'; 'KFold'; 'Partition'; ... 'BinEdges'; 'IsStandardDeviationFit'; ... 'NumTrainedPerFold'})); ***** test ## IsStandardDeviationFit comes from the model for a GAM backing and is ## empty for every other, one class serving all of them. load fisheriris CVg = crossval (fitrgam (meas(:,2:4), meas(:,1)), "KFold", 3); assert_equal (islogical (CVg.IsStandardDeviationFit), true); assert_equal (CVg.IsStandardDeviationFit, false); CVs = crossval (fitrsvm (meas(:,2:4), meas(:,1)), "KFold", 3); assert_equal (isempty (CVs.IsStandardDeviationFit), true); ***** test ## NumTrainedPerFold reports what each fold actually fitted. On this ## fixture every fold uses its whole budget, which is what R2024a reports ## for it as well. load fisheriris CVMdl = crossval (fitrgam (meas(:,2:4), meas(:,1)), "KFold", 3); n = CVMdl.NumTrainedPerFold; assert_equal (sort (fieldnames (n)), {"InteractionTrees"; "PredictorTrees"}); assert_equal (n.PredictorTrees, [300, 300, 300]); assert_equal (n.InteractionTrees, [0, 0, 0]); ***** test ## Empty for a backing that fits no trees. load fisheriris CVMdl = crossval (fitrsvm (meas(:,2:4), meas(:,1)), "KFold", 3); assert_equal (isempty (CVMdl.NumTrainedPerFold), true); ***** test load fisheriris Mdl = fitrsvm (meas(:,2:4), meas(:,1), 'KernelFunction', 'polynomial', ... 'PolynomialOrder', 2); CVMdl = crossval (Mdl, 'KFold', 3); assert_equal (CVMdl.ModelParameters.KernelPolynomialOrder, 2); assert_equal (numel (CVMdl.Trained), 3); ***** test load fisheriris CVMdl = crossval (fitrsvm (meas(:,2:4), meas(:,1)), 'KFold', 3); MP = CVMdl.ModelParameters; assert_equal (MP.Method, 'PartitionedModel'); assert_equal (MP.Type, 'regression'); assert_equal (MP.Version, 1); assert_equal (MP.NLearn, 3); assert_equal (MP.SVMtype, 'eps_svr'); ***** test load fisheriris MP = crossval (fitrgp (meas(:,2:4), meas(:,1)), 'KFold', 3).ModelParameters; assert_equal (MP.FitMethod, 'Exact'); assert_equal (MP.Method, 'PartitionedModel'); ***** test load fisheriris Mdl = crossval (fitrsvm (meas(:,2:4), meas(:,1)), 'KFold', 3); Mdl.ResponseTransform = 'none'; raw = kfoldPredict (Mdl); T = {'identity', @(x) x; 'exp', @(x) exp (x); 'log', @(x) log (x)}; for i = 1:rows (T) Mdl.ResponseTransform = T{i,1}; yhat = kfoldPredict (Mdl); assert_equal (yhat, T{i,2}(raw), 1e-12); endfor ***** test load fisheriris Mdl = crossval (fitrsvm (meas(:,2:4), meas(:,1)), 'KFold', 3); Mdl.ResponseTransform = 'none'; raw = kfoldPredict (Mdl); Mdl.ResponseTransform = @(x) x .^ 2; yhat = kfoldPredict (Mdl); assert_equal (yhat, raw .^ 2, 1e-12); ***** test ## A support vector regression fold is fitted with its rows' weights load fisheriris X = meas(:,2:4); y = meas(:,1); w = 1 + (1:150)' / 7; CVMdl = crossval (fitrsvm (X, y, 'Weights', w), 'KFold', 3); idx = training (CVMdl.Partition, 1); Mdl = fitrsvm (X(idx,:), y(idx), 'Weights', CVMdl.W(idx), ... 'Epsilon', CVMdl.ModelParameters.Epsilon); assert_equal (predict (CVMdl.Trained{1}, X), predict (Mdl, X), 1e-14); ***** test ## A neural network fold is fitted with its rows' weights load fisheriris w = 1 + (1:150)' / 7; Mdl = fitrnet (meas(:,2:4), meas(:,1), 'LayerSizes', 3, 'Weights', w); rand ('seed', 7); CVMdl = crossval (Mdl, 'KFold', 3); idx = training (CVMdl.Partition, 1); rand ('seed', 7); cvpartition (150, 'KFold', 3); F = fitrnet (meas(idx,2:4), meas(idx,1), 'LayerSizes', 3, ... 'Weights', Mdl.W(idx)); assert_equal (predict (CVMdl.Trained{1}, meas(:,2:4)), ... predict (F, meas(:,2:4)), 1e-10); 72 tests, 72 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitrlinear.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitrlinear.m ***** demo ## Fit a linear regression to fuel consumption and read what the ## optimization did. load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); [Mdl, FitInfo] = fitrlinear (X(ok,:), MPG(ok), 'Learner', 'leastsquares') ***** demo ## Fit from a table, and predict on one load fisheriris T = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); ## A column holding levels is a categorical predictor without being named ## one T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ## The response is named by its column, and everything else is a predictor Mdl = fitrlinear (T, 'SL'); Mdl.PredictorNames Mdl.CategoricalPredictors ## A model formula names them instead, holding main effects only Mdl2 = fitrlinear (T, 'SL ~ PL + Wide'); Mdl2.PredictorNames ## predict reads a table by the names the model was fitted on, so the ## columns may come in any order and may carry more than the model needs yFit = predict (Mdl, T(1:5, [5, 4, 3, 2, 1])); yFit' ***** test ## The driver returns what the class constructor returns load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); M1 = fitrlinear (X(ok,:), MPG(ok)); M2 = RegressionLinear (X(ok,:), MPG(ok)); assert_equal (class (M1), 'RegressionLinear'); assert_equal (M1.Beta, M2.Beta); assert_equal (M1.Epsilon, M2.Epsilon); ***** test ## The options reach the model load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); Mdl = fitrlinear (X(ok,:), MPG(ok), 'Learner', 'leastsquares', ... 'Lambda', 0.02, 'ResponseName', 'mpg'); assert_equal (Mdl.Learner, 'leastsquares'); assert_equal (Mdl.Lambda, 0.02); assert_equal (Mdl.ResponseName, 'mpg'); ***** test ## The second output describes the optimization load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); [~, FitInfo] = fitrlinear (X(ok,:), MPG(ok)); assert_equal (FitInfo.Solver, {'bfgs'}); assert_equal (FitInfo.Lambda, 1 / 93, 1e-15); assert_equal (isfield (FitInfo, 'Objective'), true); ***** test ## A cross-validation option returns a partitioned model instead load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); X = X(ok,:); Y = MPG(ok); CVMdl = fitrlinear (X, Y, 'KFold', 5); assert_equal (class (CVMdl), 'RegressionPartitionedLinear'); assert_equal (CVMdl.KFold, 5); assert_equal (numel (CVMdl.Trained), 5); ***** test ## 'CrossVal' on gives the ten folds it defaults to, and 'off' the model ## itself load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); X = X(ok,:); Y = MPG(ok); CVMdl = fitrlinear (X, Y, 'CrossVal', 'on'); assert_equal (CVMdl.KFold, 10); assert_equal (class (fitrlinear (X, Y, 'CrossVal', 'off')), ... 'RegressionLinear'); ***** error ... [Mdl, FitInfo] = fitrlinear (ones (10, 2), ones (10, 1), 'KFold', 3); ***** error fitrlinear (ones (5, 2)) ***** error ... fitrlinear (ones (10, 2), ones (10, 1), 'Learner') ***** error ... fitrlinear (ones (10, 2), ones (10, 1), 'Learner', 'logistic') ***** shared frlT load fisheriris frlT = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); ***** test # the response is named by a column and the rest are predictors Mdl = fitrlinear (frlT, 'SL'); assert_equal (Mdl.PredictorNames, {'SW', 'PL', 'PW'}); assert_equal (Mdl.ResponseName, 'SL'); ***** test # a model formula names the response and the predictors together Mdl = fitrlinear (frlT, 'SL ~ PL + PW'); assert_equal (Mdl.PredictorNames, {'PL', 'PW'}); ***** test # predict takes a table, matched by name and not by position Mdl = fitrlinear (frlT, 'SL'); a = predict (Mdl, frlT); assert_equal (predict (Mdl, frlT(:, [4, 3, 2, 1])), a); ***** test # a cross-validated fit takes a table too Mdl = fitrlinear (frlT, 'SL', 'KFold', 3); assert_equal (class (Mdl), 'RegressionPartitionedLinear'); ***** error ... fitrlinear (frlT, 'NoSuch') 14 tests, 14 passed, 0 known failure, 0 skipped [inst/Machine_Learning/templateLinear.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/templateLinear.m ***** test # the default template names its learner and nothing else T = templateLinear (); assert_equal (class (T), 'struct'); assert_equal (T.Method, 'Linear'); assert_equal (T.Type, 'classification'); assert_equal (numfields (T), 2); ***** test # an option given is stored under its own name, as it stands T = templateLinear ('Learner', 'logistic', 'Lambda', 1e-4); assert_equal (numfields (T), 4); assert_equal (T.Learner, 'logistic'); assert_equal (T.Lambda, 1e-4); ***** test # a name the learner does not know is not refused here T = templateLinear ('NoSuchOption', 42); assert_equal (T.NoSuchOption, 42); ***** error ... templateLinear ('KernelScale') ***** error ... templateLinear (42, 1) ***** error ... templateLinear ('not a name', 1) 6 tests, 6 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitrensemble.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitrensemble.m ***** demo ## Boost regression trees to predict sepal length from the other three ## measurements, and watch the training error fall as trees are added. load fisheriris X = meas(:,2:4); y = meas(:,1); Mdl = fitrensemble (X, y, 'NumLearningCycles', 50, 'LearnRate', 0.1); plot (loss (Mdl, X, y, 'Mode', 'cumulative')); xlabel ('Number of trees'); ylabel ('Training mean squared error'); ***** demo ## A bagged ensemble of regression trees predicts by averaging its trees. load fisheriris rng (42); Mdl = fitrensemble (meas(:,2:4), meas(:,1), 'Method', 'Bag', ... 'NumLearningCycles', 30); yfit = predict (Mdl, meas([1, 51, 101], 2:4)) ***** demo ## Fit from a table, and predict on one load fisheriris T = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ## A model formula names the response and the predictors together, and ## holds main effects only Mdl = fitrensemble (T, 'SL ~ PL + Wide'); Mdl.PredictorNames Mdl.ResponseName ## predict matches the table's variables by name, so a column the model ## was not fitted on is passed over yFit = predict (Mdl, T(1:5,:)); yFit' ***** shared X, y, S load fisheriris X = meas(:,2:4); y = meas(:,1); S = templateTree ('MaxNumSplits', 1); ***** test # MATLAB parity: LSBoost on decision stumps Mdl = fitrensemble (X, y, 'NumLearningCycles', 4, 'Learners', S); assert_equal (class (Mdl), 'RegressionEnsemble'); assert_equal (Mdl.TrainedWeights, ones (4, 1)); assert_equal (Mdl.FitInfo, [0.263279369032793; 0.185334478476685; ... 0.176267398277275; 0.159714716160712], 1e-13); assert_equal (Mdl.Trained{2}.CutPoint(1), 6.05, 1e-12); assert_equal (Mdl.Trained{2}.NodeMean(2:3)', ... [-0.070535138620251, 1.105050505050500], 1e-12); ***** test # MATLAB parity: the first tree fits the response itself Mdl = fitrensemble (X, y, 'NumLearningCycles', 4, 'Learners', S); assert_equal (Mdl.Trained{1}.NodeMean(1), mean (y), 1e-12); assert_equal (predict (Mdl, X([1, 51],:)), ... [5.085793612916077; 6.335321158531990], 1e-13); ***** test # MATLAB parity: the learning rate shrinks each tree's step Mdl = fitrensemble (X, y, 'NumLearningCycles', 3, 'Learners', S, ... 'LearnRate', 0.1); assert_equal (Mdl.TrainedWeights, 0.1 * ones (3, 1), 1e-15); assert_equal (Mdl.FitInfo, [0.263279369032793; 0.258079095922867; ... 0.253496179589799], 1e-13); assert_equal (Mdl.Trained{2}.CutPoint(1), 3.95, 1e-12); assert_equal (predict (Mdl, X([1, 51],:)), ... [1.391715765572467; 1.746807161347196], 1e-13); ***** test # MATLAB parity: observation weights enter every tree w = [5 * ones(50, 1); ones(100, 1)]; Mdl = fitrensemble (X, y, 'NumLearningCycles', 2, 'Learners', S, ... 'Weights', w); assert_equal (Mdl.W([1, 51])', [5 / 350, 1 / 350], 1e-15); assert_equal (Mdl.FitInfo, [0.185825250456633; 0.147589707296206], 1e-13); assert_equal (predict (Mdl, X([1, 51],:)), ... [4.988922545877216; 6.342390194075585], 1e-13); ***** test # MATLAB parity: LSBoost with its default trees Mdl = fitrensemble (X, y, 'NumLearningCycles', 3); assert_equal (Mdl.FitInfo, [0.079108234913235; 0.058774516561726; ... 0.050203817681049], 1e-13); assert_equal (predict (Mdl, X([1, 2, 51, 52, 101, 150],:)), ... [5.09375; 4.58949494949495; 6.874251054542892; ... 6.212370889253637; 6.607394901394901; ... 6.032614996997739], 1e-12); ***** test # MATLAB parity: the defaults of a regression ensemble Mdl = fitrensemble (X, y, 'NumLearningCycles', 2); assert_equal (Mdl.Method, 'LSBoost'); assert_equal (Mdl.ModelParameters.LearnRate, 1); assert_equal (Mdl.CombineWeights, 'WeightedSum'); assert_equal (Mdl.ResponseTransform, 'none'); ***** test # MATLAB parity: 'Bag' returns a bagged ensemble Mdl = fitrensemble (X, y, 'Method', 'Bag', 'NumLearningCycles', 2); assert_equal (class (Mdl), 'RegressionBaggedEnsemble'); assert_equal (Mdl.CombineWeights, 'WeightedAverage'); ***** test # MATLAB parity: progress is printed after every NPrint trees out = evalc (["fitrensemble (X, y, 'NumLearningCycles', 4, ", ... "'Learners', S, 'NPrint', 2);"]); assert_equal (out, sprintf (["Training LSBoost...\n", ... "Grown weak learners: 2\n", ... "Grown weak learners: 4\n"])); ***** error fitrensemble (X) ***** error ... fitrensemble (X, y, 'Method') ***** test # MATLAB parity: 'KFold' returns a cross-validated ensemble CV = fitrensemble (X, y, 'NumLearningCycles', 2, 'Learners', S, 'KFold', 3); assert_equal (class (CV), 'RegressionPartitionedEnsemble'); assert_equal (CV.KFold, 3); ***** error ... fitrensemble (X, y, 'KFold', 5, 'CrossVal', 'on') ***** error ... fitrensemble (X, y, 'KFold', 0) ***** test # MATLAB parity: LSBoost that resamples is a bagged ensemble load fisheriris M = fitrensemble (meas(:,2:4), meas(:,1), 'NumLearningCycles', 3, ... 'FResample', 0.5); assert_equal (class (M), 'RegressionBaggedEnsemble'); assert_equal (M.Method, 'LSBoost'); assert_equal (M.CombineWeights, 'WeightedSum'); ***** shared X, yr, Xq k = (0:119)'; c = mod (k, 4) + 1; j = floor (k / 4); x2 = mod (k * 7, 10); X = [c, x2]; yb = (c == 1) | (c == 2 & mod (j, 4) != 0) | (c == 3 & mod (j, 4) == 0) ... | (x2 > 7); yr = [3; 1; 4; 1.5]; yr = yr(c) + 0.1 * sin (k) + 0.2 * x2; Xq = [1, 0; 3, 5; 5, 0; NaN, 2; 2.5, 9]; ***** test # MATLAB parity: LSBoost trees split a categorical predictor Mdl = fitrensemble (X, yr, 'Method', 'LSBoost', 'NumLearningCycles', 4, ... 'CategoricalPredictors', 1); assert_equal (Mdl.CategoricalPredictors, 1); assert_equal (Mdl.Trained{1}.CutCategories(1,:), {[2, 4], [1, 3]}); ## The first two rows pass a node of the fourth tree where two partitions ## gain the same to 5e-15, which rounding decides; the others do not. yhat = predict (Mdl, Xq); assert_equal (yhat(3:5)', [3.2692634, 3.2028144, 3.4104563], 1e-6); ***** shared freT load fisheriris freT = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); freT.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ***** test # the response is named by a column and the rest are predictors Mdl = fitrensemble (freT, 'SL'); assert_equal (Mdl.PredictorNames, {'SW', 'PL', 'PW', 'Wide'}); assert_equal (Mdl.ResponseName, 'SL'); assert_equal (Mdl.CategoricalPredictors, 4); ***** test # a model formula names the response and the predictors together Mdl = fitrensemble (freT, 'SL ~ PL + Wide'); assert_equal (Mdl.PredictorNames, {'PL', 'Wide'}); ***** test # predict takes a table, matched by name and not by position Mdl = fitrensemble (freT, 'SL'); a = predict (Mdl, freT); assert_equal (numel (a), 150); assert_equal (predict (Mdl, freT(:, [5, 4, 3, 2, 1])), a); ***** test # the levels travel with the model when it is made compact Mdl = fitrensemble (freT, 'SL'); CMdl = compact (Mdl); assert_equal (CMdl.PredictorLevels, Mdl.PredictorLevels); assert_equal (predict (CMdl, freT), predict (Mdl, freT)); ***** error ... fitrensemble (freT, 'NoSuch') 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Machine_Learning/CompactRegressionGP.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/CompactRegressionGP.m ***** demo ## A compact model predicts what the full model predicts, and carries none ## of the training data. x = linspace (0, 1, 20)'; y = sin (2*pi*x) + 0.05 * cos (9*x); Mdl = fitrgp (x, y); CMdl = compact (Mdl) xq = [0.15; 0.55; 0.85]; [yq, ysd] = predict (CMdl, xq) ***** test ## The compact model carries the fitted surface and nothing that describes ## the training data x = linspace (0, 1, 15)'; y = cos (3*x) + 0.1 * sin (11*x); Mdl = RegressionGP (x, y); CMdl = compact (Mdl); assert_equal (class (CMdl), 'CompactRegressionGP'); assert_equal (CMdl.Beta, Mdl.Beta); assert_equal (CMdl.Sigma, Mdl.Sigma); assert_equal (CMdl.KernelFunction, Mdl.KernelFunction); assert_equal (CMdl.KernelInformation, Mdl.KernelInformation); assert_equal (CMdl.Alpha, Mdl.Alpha); assert_equal (CMdl.ActiveSetVectors, Mdl.ActiveSetVectors); assert_equal (CMdl.ResponseName, Mdl.ResponseName); assert_equal (CMdl.PredictorNames, Mdl.PredictorNames); ***** test ## It predicts exactly what the full model predicts, standard deviation ## and interval included, because it predicts through the same code x = linspace (0, 1, 20)'; y = sin (2*pi*x) + 0.1 * cos (7*x); Mdl = RegressionGP (x, y); CMdl = compact (Mdl); xq = [0.05; 0.33; 0.5; 0.77; 0.95]; [y1, s1, i1] = predict (Mdl, xq); [y2, s2, i2] = predict (CMdl, xq); assert_equal (y2, y1, 1e-14); assert_equal (s2, s1, 1e-14); assert_equal (i2, i1, 1e-14); ***** test ## The R2024a values, reached through the compact model x = linspace (0, 1, 20)'; y = sin (2*pi*x) + 0.1 * cos (7*x); CMdl = compact (RegressionGP (x, y)); xq = [0.05; 0.33; 0.5; 0.77; 0.95]; assert_equal (predict (CMdl, xq), ... [0.404401855406521; 0.809355242891053; ... -0.093708552144171; -0.928420803239529; ... -0.217104024154071], 1e-7); ***** test ## The interval level is settable here as it is on the full model x = linspace (0, 1, 15)'; y = cos (3*x) + 0.1 * sin (11*x); CMdl = compact (RegressionGP (x, y)); xq = [0.2; 0.6]; [yp, ysd, yint] = predict (CMdl, xq); assert_equal (yint(:,2) - yp, norminv (0.975) * ysd, 1e-12); [~, ~, yint90] = predict (CMdl, xq, 'Alpha', 0.10); assert (all (yint90(:,2) - yint90(:,1) < yint(:,2) - yint(:,1))); ***** test ## Standardization is carried over, so the compact model transforms new ## data the way the full model did X = [linspace(0, 10, 20)', linspace(-5, 5, 20)']; y = 0.3 * X(:,1) - 0.2 * X(:,2); Mdl = RegressionGP (X, y, 'Standardize', true); CMdl = compact (Mdl); assert_equal (CMdl.PredictorLocation, Mdl.PredictorLocation); assert_equal (CMdl.PredictorScale, Mdl.PredictorScale); assert_equal (predict (CMdl, X), predict (Mdl, X), 1e-14); ***** test ## loss on the compact model agrees with loss on the full one x = linspace (0, 1, 15)'; y = cos (3*x) + 0.1 * sin (11*x); Mdl = RegressionGP (x, y); CMdl = compact (Mdl); assert_equal (loss (CMdl, x, y), loss (Mdl, x, y), 1e-14); assert_equal (loss (CMdl, x, y, 'LossFun', 'mae'), ... loss (Mdl, x, y, 'LossFun', 'mae'), 1e-14); w = linspace (1, 2, 15)'; assert_equal (loss (CMdl, x, y, 'Weights', w), ... loss (Mdl, x, y, 'Weights', w), 1e-14); ***** test ## A compact model saved and loaded predicts what it predicted before x = linspace (0, 1, 15)'; y = cos (3*x) + 0.1 * sin (11*x); CMdl = compact (RegressionGP (x, y)); fname = tempname (); savemodel (CMdl, fname); CMdl2 = loadmodel (fname); delete (fname); assert_equal (class (CMdl2), 'CompactRegressionGP'); assert_equal (CMdl2.Beta, CMdl.Beta); assert_equal (CMdl2.Sigma, CMdl.Sigma); assert_equal (CMdl2.Alpha, CMdl.Alpha); assert_equal (CMdl2.ActiveSetVectors, CMdl.ActiveSetVectors); assert_equal (predict (CMdl2, x), predict (CMdl, x), 1e-14); ***** test ## A response transform survives compacting x = linspace (0, 1, 12)'; y = cos (3*x); Mdl = RegressionGP (x, y, 'ResponseTransform', 'exp'); CMdl = compact (Mdl); assert_equal (CMdl.ResponseTransform, 'exp'); assert_equal (predict (CMdl, x), predict (Mdl, x), 1e-14); ***** test # A row missing a predictor predicts the lower median of the response X = [(1:10)', mod((1:10)', 3)]; Mdl = compact (RegressionGP (X, (1:10)')); assert_equal (predict (Mdl, [NaN, 1]), 5); ***** error CompactRegressionGP () ***** error ... CompactRegressionGP (5) ***** error ... predict (compact (RegressionGP (ones (5, 2), ones (5, 1)))) ***** error ... predict (compact (RegressionGP (ones (5, 2), ones (5, 1))), []) ***** error ... predict (compact (RegressionGP (ones (5, 2), ones (5, 1))), ones (3, 3)) ***** error ... predict (compact (RegressionGP (ones (5, 2), ones (5, 1))), ... ones (3, 2), 'Alpha', 2) ***** error ... predict (compact (RegressionGP (ones (5, 2), ones (5, 1))), ... ones (3, 2), 'bogus', 1) ***** error ... loss (compact (RegressionGP (ones (5, 2), ones (5, 1))), ones (3, 2)) ***** error ... loss (compact (RegressionGP (ones (5, 2), ones (5, 1))), 'a', ones (3, 1)) ***** error ... loss (compact (RegressionGP (ones (5, 2), ones (5, 1))), ... ones (3, 2), ones (2, 1)) ***** error ... loss (compact (RegressionGP (ones (5, 2), ones (5, 1))), ... ones (3, 2), ones (3, 1), 'Bogus', 1) ***** error ... loss (compact (RegressionGP (ones (5, 2), ones (5, 1))), ones (3, 2), ... ones (3, 1), 'LossFun', 'bogus') ***** test load fisheriris Mdl = compact (fitrgp (meas(:,2:4), meas(:,1))); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); T = {'identity', @(x) x; 'exp', @(x) exp (x); 'log', @(x) log (x)}; for i = 1:rows (T) Mdl.ResponseTransform = T{i,1}; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, T{i,2}(raw), 1e-12); endfor ***** test load fisheriris Mdl = compact (fitrgp (meas(:,2:4), meas(:,1))); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); Mdl.ResponseTransform = @(x) x .^ 2; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, raw .^ 2, 1e-12); ***** test # a compact model codes new data as the full model does c1 = repmat ([1; 2; 3], 20, 1); x2 = sin ((1:60)'); X = [c1, x2]; y = 5 * (c1 == 2) + 0.5 * x2 + 0.1 * cos ((1:60)'); Mdl = fitrgp (X, y, 'CategoricalPredictors', 1); CMdl = compact (Mdl); Xq = [1, 0; 3, 0.5; 4, 0]; assert_equal (predict (CMdl, Xq), predict (Mdl, Xq)); assert_equal (CMdl.ExpandedPredictorNames, Mdl.ExpandedPredictorNames); ***** test # the levels travel with the model, and predict reads a table by name load fisheriris T = table (meas(:,2), meas(:,3), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'SL'}); T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); Mdl = fitrgp (T, 'SL'); CMdl = compact (Mdl); assert_equal (CMdl.PredictorLevels, Mdl.PredictorLevels); assert_equal (predict (CMdl, T(:, [4, 3, 2, 1])), predict (CMdl, T)); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,2:3); y = meas(:,1); T = table (X(:,1), X(:,2), 'VariableNames', {'SW', 'PL'}); T.SL = y; Mdl = compact (fitrgp (T, 'SL')); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'SL'), a); assert_equal (loss (Mdl, T), a); ***** error X = [1, 2; 3, 4; 5, 6; 7, 8]; y = (1:4)'; loss (compact (fitrgp (X, y)), X, y, 'Weights', int8 ([1; 1; 1; 1])) 27 tests, 27 passed, 0 known failure, 0 skipped [inst/Machine_Learning/CompactClassificationNaiveBayes.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/CompactClassificationNaiveBayes.m ***** test # MATLAB parity: the surface a compact model reports load fisheriris CMdl = compact (fitcnb (meas, species)); assert_equal (class (CMdl), 'CompactClassificationNaiveBayes'); assert_equal (CMdl.ClassNames, unique (species)); assert_equal (CMdl.Prior, [1/3, 1/3, 1/3], 1e-15); assert_equal (CMdl.Cost, [0, 1, 1; 1, 0, 1; 1, 1, 0]); assert_equal (CMdl.ResponseName, 'Y'); assert_equal (CMdl.PredictorNames, {'x1', 'x2', 'x3', 'x4'}); assert_equal (CMdl.DistributionNames, ... {'normal', 'normal', 'normal', 'normal'}); assert_equal (CMdl.ScoreTransform, 'none'); ***** test # the properties a compact model does not carry load fisheriris CMdl = compact (fitcnb (meas, species)); assert_equal (isprop (CMdl, 'X'), false); assert_equal (isprop (CMdl, 'Y'), false); assert_equal (isprop (CMdl, 'W'), false); assert_equal (isprop (CMdl, 'NumObservations'), false); assert_equal (isprop (CMdl, 'RowsUsed'), false); assert_equal (isprop (CMdl, 'ModelParameters'), false); ***** test # MATLAB parity: it classifies exactly as the model it came from load fisheriris Mdl = fitcnb (meas, species); CMdl = compact (Mdl); [ml, ms, mc] = predict (Mdl, meas); [cl, cs, cc] = predict (CMdl, meas); assert_equal (cl, ml); assert_equal (cs, ms); assert_equal (cc, mc); ***** test # MATLAB parity: loss, edge, margin and logp load fisheriris CMdl = compact (fitcnb (meas, species)); assert_equal (loss (CMdl, meas, species), 0.04, 1e-14); assert_equal (loss (CMdl, meas, species, 'LossFun', 'hinge'), ... 0.052784701267562, 1e-12); assert_equal (edge (CMdl, meas, species), 0.894430597464877, 1e-12); assert_equal (sum (margin (CMdl, meas, species)), ... 134.164589619731402, 1e-10); assert_equal (logp (CMdl, meas)(1), 1.026591235856343, 1e-12); ***** test # MATLAB parity: edge on a set missing a class load fisheriris CMdl = compact (fitcnb (meas, species)); r = 51:150; assert_equal (edge (CMdl, meas(r,:), species(r)), 0.8416458962, 1e-10); ***** test # a kernel model compacts, densities and all load fisheriris Mdl = fitcnb (meas, species, 'DistributionNames', 'kernel'); CMdl = compact (Mdl); assert_equal (CMdl.Kernel, {'normal', 'normal', 'normal', 'normal'}); assert_equal (CMdl.Width, Mdl.Width); assert_equal (class (CMdl.DistributionParameters{1,1}), ... 'prob.KernelDistribution'); assert_equal (predict (CMdl, meas), predict (Mdl, meas)); ***** test # Cost and Prior may be assigned on a compact model too load fisheriris CMdl = compact (fitcnb (meas, species)); CMdl.Cost = [0, 2, 2; 2, 0, 2; 2, 2, 0]; assert_equal (CMdl.Cost, [0, 2, 2; 2, 0, 2; 2, 2, 0]); CMdl.Prior = [0.2, 0.3, 0.5]; assert_equal (CMdl.Prior, [0.2, 0.3, 0.5], 1e-15); CMdl.ScoreTransform = 'logit'; assert_equal (CMdl.ScoreTransform, 'logit'); ***** test # a categorical model compacts, levels and all X = [1, 2; 1, 3; 2, 2; 2, 3; 1, 2; 3, 1; 3, 3; 2, 1; 1, 1; 3, 2; ... 2, 2; 1, 3; 3, 1; 2, 3; 1, 1; 3, 2; 2, 1; 1, 2; 3, 3; 2, 2]; Y = [repmat({'a'}, 10, 1); repmat({'b'}, 10, 1)]; Mdl = fitcnb (X, Y, 'DistributionNames', 'mvmn', ... 'CategoricalPredictors', [1, 2]); CMdl = compact (Mdl); assert_equal (CMdl.CategoricalLevels{1}, [1; 2; 3]); assert_equal (CMdl.CategoricalPredictors, [1, 2]); assert_equal (predict (CMdl, X), predict (Mdl, X)); assert_equal (loss (CMdl, X, Y), 0.45, 1e-14); ***** test # a multinomial model compacts, and keeps its character DistributionNames C = [2, 0, 1; 1, 3, 0; 0, 1, 4; 3, 1, 0; ... 0, 2, 2; 1, 0, 3; 4, 1, 1; 0, 3, 2]; L = [repmat({'x'}, 4, 1); repmat({'y'}, 4, 1)]; CMdl = compact (fitcnb (C, L, 'DistributionNames', 'mn')); assert_equal (CMdl.DistributionNames, 'mn'); [label, score] = predict (CMdl, [1, 1, 1; 4, 0, 0]); assert_equal (label, {'x'; 'x'}); assert_equal (score(2,1), 0.769060987976952, 1e-12); ***** test # an unseen level falls back to the prior on a compact model too Z = [1, 1; 1, 1; 1, 2; 1, 2; 1, 1; 1, 2; 2, 2; 2, 1]; G = [repmat({'p'}, 6, 1); repmat({'q'}, 2, 1)]; CMdl = compact (fitcnb (Z, G, 'DistributionNames', 'mvmn', ... 'CategoricalPredictors', [1, 2])); [~, score] = predict (CMdl, [3, 1]); assert_equal (score, [0.75, 0.25], 1e-12); assert_equal (logp (CMdl, [3, 1]), -Inf); ***** test load fisheriris CMdl = compact (fitcnb (meas, species)); fname = tempname (); savemodel (CMdl, fname); C2 = loadmodel (fname); delete (fname); assert_equal (class (C2), 'CompactClassificationNaiveBayes'); p = properties (CMdl); for i = 1:numel (p) assert_equal (C2.(p{i}), CMdl.(p{i})); endfor assert_equal (predict (C2, meas(1:10,:)), predict (CMdl, meas(1:10,:))); ***** test load fisheriris CMdl = compact (fitcnb (meas, species, 'DistributionNames', 'kernel')); fname = tempname (); savemodel (CMdl, fname); C2 = loadmodel (fname); delete (fname); assert_equal (class (C2.DistributionParameters{1,1}), ... 'prob.KernelDistribution'); assert_equal (C2.Width, CMdl.Width); assert_equal (predict (C2, meas(1:10,:)), predict (CMdl, meas(1:10,:))); ***** error ... savemodel (compact (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]))) ***** error ... savemodel (compact (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])), 1) ***** error ... savemodel (compact (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])), ... ['ab'; 'cd']) ***** error ... CompactClassificationNaiveBayes () ***** error ... CompactClassificationNaiveBayes (5) ***** error ... predict (compact (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])), []) ***** error ... predict (compact (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])), ones (2, 3)) ***** error ... loss (compact (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])), [1, 2; 2, 3; 3, 4; 4, 5]) ***** error ... loss (compact (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])), [1, 2; 2, 3; 3, 4; 4, 5], ... [1; 1; 2; 2], 'LossFun', 'nope') ***** error ... loss (compact (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])), ... [1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], 'Bogus', 1) ***** error ... margin (compact (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])), [1, 2; 2, 3; 3, 4; 4, 5]) ***** error ... edge (compact (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])), [1, 2; 2, 3; 3, 4; 4, 5]) ***** error ... logp (compact (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])), []) ***** test load fisheriris Mdl = compact (fitcnb (meas, species)); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); T = {'identity', @(x) x; 'doublelogit', @(x) 1 ./ (1 + exp (-2 * x)); ... 'invlogit', @(x) log (x ./ (1 - x)); ... 'logit', @(x) 1 ./ (1 + exp (-x)); ... 'sign', @(x) sign (x); 'symmetric', @(x) 2 * x - 1; ... 'symmetriclogit', @(x) 2 ./ (1 + exp (-x)) - 1}; for i = 1:rows (T) Mdl.ScoreTransform = T{i,1}; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, T{i,2}(raw), 1e-12); assert_equal (l, label); endfor ## ismax marks the largest score of each observation, ties to the first. [~, k] = max (raw, [], 2); e = zeros (size (raw)); e(sub2ind (size (raw), (1:rows (raw))', k)) = 1; Mdl.ScoreTransform = 'ismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, e); Mdl.ScoreTransform = 'symmetricismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, 2 * e - 1); ***** test load fisheriris Mdl = compact (fitcnb (meas, species)); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); Mdl.ScoreTransform = @(x) x .^ 2; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, raw .^ 2, 1e-12); assert_equal (l, label); ***** test # the levels a predictor was coded through travel with the model load fisheriris T = table (meas(:,1), meas(:,2), 'VariableNames', {'SL', 'SW'}); T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); T.Species = categorical (species); CMdl = compact (fitcnb (T, 'Species')); assert_equal (numel (CMdl.PredictorLevels), 3); assert_equal (CMdl.PredictorLevels{3}, {'narrow', 'wide'}); ***** test # predict takes a table, read by name and not by position load fisheriris T = table (meas(:,1), meas(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = categorical (species); CMdl = compact (fitcnb (T, 'Species')); a = predict (CMdl, T); assert_equal (class (a), 'categorical'); assert_equal (predict (CMdl, T(:, [3, 2, 1])), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcnb (T, 'Species')); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcnb (T, 'Species')); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcnb (T, 'Species')); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** test # a table is matched to the predictors by name load fisheriris T = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = categorical (species); Mdl = compact (fitcnb (T, 'Species')); a = logp (Mdl, meas); assert_equal (logp (Mdl, T(:,1:4)), a); assert_equal (logp (Mdl, T(:,[5, 4, 2, 3, 1])), a); ***** error ... loss (compact (fitcnb ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2])), ... [1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', int8 ([1; 1; 1; 1])) 34 tests, 34 passed, 0 known failure, 0 skipped [inst/Machine_Learning/CompactRegressionEnsemble.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/CompactRegressionEnsemble.m ***** shared X, y, C load fisheriris X = meas(:,2:4); y = meas(:,1); C = compact (fitrensemble (X, y, 'NumLearningCycles', 4, ... 'Learners', templateTree ('MaxNumSplits', 1))); ***** test # MATLAB parity: the properties of a compact regression ensemble assert_equal (numel (properties (C)), 10); assert_equal (C.NumTrained, 4); assert_equal (isprop (C, 'X'), false); ***** test # MATLAB parity: predictions over a subset of the trees assert_equal (predict (C, X(1:2,:), 'Learners', [2, 4]), ... [0.061599937710460; 0.061599937710460], 1e-13); ***** test # MATLAB parity: a row no tree may predict is NaN U = true (2, 4); U(1,:) = false; U(2,[1, 3]) = false; yf = predict (C, X(1:2,:), 'UseObsForLearner', U); assert_equal (isnan (yf(1)), true); assert_equal (yf(2), 0.061599937710460, 1e-13); ***** test # MATLAB parity: the loss in its three modes assert_equal (loss (C, X, y), 0.159714716160712, 1e-13); assert_equal (loss (C, X, y, 'Mode', 'cumulative'), ... [0.263279369032794; 0.185334478476685; ... 0.176267398277276; 0.159714716160713], 1e-13); assert_equal (loss (C, X, y, 'Mode', 'individual'), ... [0.263279369032794; 34.658932998586877; ... 34.730819835683143; 35.008549381231070], 1e-11); assert_equal (loss (C, X, y, 'Learners', [1, 3]), 0.245973792973264, 1e-13); ***** test # MATLAB parity: weights are normalized to sum to one w = [2 * ones(50, 1); ones(100, 1)]; assert_equal (loss (C, X, y, 'Weights', w), 0.150822300473683, 1e-13); ***** test # MATLAB parity: a custom loss gets normalized weights f = @(Y, Yf, W) sum (W .* abs (Y - Yf)) / sum (W); assert_equal (loss (C, X, y, 'LossFun', f), 0.321254856340782, 1e-13); w = [3 * ones(50, 1); ones(100, 1)]; assert_equal (loss (C, X, y, 'LossFun', @(Y, Yf, W) sum (W), ... 'Weights', w), 1, 1e-14); assert_equal (loss (C, X, y, 'LossFun', @(Y, Yf, W) W(1), ... 'Weights', w), 0.012, 1e-15); ***** test # MATLAB parity: a missing response is left out of the loss C3 = removeLearners (C, 4); yn = y; yn(3) = NaN; assert_equal (loss (C3, X, yn), 0.177018571063146, 1e-13); assert_equal (loss (C3, X, y, 'Mode', 'cumulative', 'Weights', ... [3 * ones(50, 1); ones(100, 1)]), ... [0.218707467544654; 0.164143043739940; ... 0.149902130360542], 1e-13); ***** test # MATLAB parity: removing trees D = removeLearners (C, [1, 3]); assert_equal (D.NumTrained, 2); assert_equal (predict (D, X(1:2,:)), [0.061599937710460; ... 0.061599937710460], 1e-13); ***** error ... CompactRegressionEnsemble (1) ***** error ... predict (C) ***** error ... predict (C, {1}) ***** error ... predict (C, ones (2, 4)) ***** error ... predict (C, X, 'Learners') ***** error ... predict (C, X, 'Mode', 'ensemble') ***** error ... predict (C, X, 'Learners', 5) ***** error ... predict (C, X, 'UseObsForLearner', true (2, 4)) ***** error ... loss (C, X) ***** error ... loss (C, X, y, 'Mode', 'all') ***** error ... loss (C, X, y, 'Weights', ones (3, 1)) ***** error ... loss (C, X, y, 'LossFun', 'mae') ***** error ... loss (C, X, {1}) ***** error ... loss (C, X, y(1:3)) ***** error ... loss (C, X, y, 'Weights', zeros (150, 1)) ***** error ... removeLearners (C) ***** error ... removeLearners (C, 5) ***** error ... D = C; D.ResponseTransform = 1; ***** test # MATLAB parity: importance is the weighted average over the trees M = fitrensemble (X, y, 'NumLearningCycles', 3, 'LearnRate', 0.5, ... 'Learners', templateTree ('MaxNumSplits', 1)); [imp, ma] = predictorImportance (compact (M)); assert_equal (imp, [0, 0.223154680811778, 0], 1e-13); assert_equal (ma, []); ***** test # MATLAB parity: a row no tree may predict is left out of the loss U = true (150, 4); U(1,:) = false; e = mean ((predict (C, X(2:end,:)) - y(2:end)) .^ 2); assert_equal (loss (C, X, y, 'UseObsForLearner', U), e, 1e-14); ***** test # the levels travel with the model, and predict reads a table by name load fisheriris T = table (meas(:,2), meas(:,3), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'SL'}); T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); Mdl = fitrensemble (T, 'SL'); CMdl = compact (Mdl); assert_equal (CMdl.PredictorLevels, Mdl.PredictorLevels); a = predict (CMdl, T); assert_equal (predict (CMdl, T(:, [4, 3, 2, 1])), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,2:3); y = meas(:,1); T = table (X(:,1), X(:,2), 'VariableNames', {'SW', 'PL'}); T.SL = y; Mdl = compact (fitrensemble (T, 'SL')); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'SL'), a); assert_equal (loss (Mdl, T), a); ***** error ... loss (compact (fitrensemble ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', ... 'NumLearningCycles', 3)), ... [1, 2; 3, 4; 5, 6; 7, 8], (1:4)', 'Weights', int8 ([1; 1; 1; 1])) 31 tests, 31 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitckernel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitckernel.m ***** demo ## Fit a Gaussian kernel classifier to the two overlapping iris species ## and read what the optimization did. load fisheriris X = meas(51:end,:); Y = species(51:end); [Mdl, FitInfo] = fitckernel (X, Y) ***** demo ## Fit from a table, and predict on one load fisheriris inds = ! strcmp (species, 'setosa'); X = meas(inds,:); T = table (X(:,1), X(:,2), X(:,3), X(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = categorical (species(inds)); ## A column holding levels is a categorical predictor without being named ## one T.Wide = categorical (X(:,2) > 2.9, [false true], {'narrow', 'wide'}); ## The response is named by its column, and everything else is a predictor Mdl = fitckernel (T, 'Species'); Mdl.PredictorNames Mdl.CategoricalPredictors ## A model formula names them instead, holding main effects only Mdl2 = fitckernel (T, 'Species ~ PL + Wide'); Mdl2.PredictorNames ## predict reads a table by the names the model was fitted on, so the ## columns may come in any order and may carry more than the model needs label = predict (Mdl, T(1:5, [6, 5, 4, 3, 2, 1])); label' ***** test ## The driver returns a kernel classifier load fisheriris Mdl = fitckernel (meas(51:end,:), species(51:end)); assert_equal (class (Mdl), 'ClassificationKernel'); assert_equal (Mdl.NumExpansionDimensions, 128); ***** test ## The options reach the model load fisheriris Mdl = fitckernel (meas(51:end,:), species(51:end), ... 'Learner', 'logistic', 'KernelScale', 2, ... 'NumExpansionDimensions', 64); assert_equal (Mdl.Learner, 'logistic'); assert_equal (Mdl.KernelScale, 2); assert_equal (Mdl.NumExpansionDimensions, 64); ***** test ## The second output describes the optimization load fisheriris [~, FitInfo] = fitckernel (meas(51:end,:), species(51:end)); assert_equal (FitInfo.Solver, 'LBFGS-fast'); assert_equal (FitInfo.LossFunction, 'hinge'); assert_equal (FitInfo.Lambda, 0.01); ***** test ## A cross-validation option returns a partitioned model instead load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = fitckernel (X, Y, 'KFold', 5); assert_equal (class (CVMdl), 'ClassificationPartitionedKernel'); assert_equal (CVMdl.KFold, 5); assert_equal (numel (CVMdl.Trained), 5); ***** test ## 'CrossVal' on gives the ten folds it defaults to, and 'off' the model ## itself load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = fitckernel (X, Y, 'CrossVal', 'on'); assert_equal (CVMdl.KFold, 10); assert_equal (class (fitckernel (X, Y, 'CrossVal', 'off')), ... 'ClassificationKernel'); ***** error ... [Mdl, FitInfo] = fitckernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'KFold', 3); ***** error fitckernel (ones (5, 2)) ***** error ... fitckernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Learner') ***** error ... fitckernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Learner', 'tree') ***** test # MATLAB parity: classes given as text are sorted load fisheriris k = [101:150, 51:100]; Mdl = fitckernel (meas(k,:), species(k)); assert_equal (Mdl.ClassNames, {'versicolor'; 'virginica'}); ***** test # MATLAB parity: a given ClassNames order is kept load fisheriris Mdl = fitckernel (meas(51:150,:), species(51:150), ... 'ClassNames', {'virginica'; 'versicolor'}); assert_equal (Mdl.ClassNames, {'virginica'; 'versicolor'}); ***** error ... load fisheriris fitckernel (meas(51:150,:), species(51:150), 'ClassNames', [3, 2]) ***** error ... load fisheriris fitckernel (meas(51:150,:), species(51:150), ... 'ClassNames', {'virginica'; 'rose'}) ***** shared fckT load fisheriris fckI = ! strcmp (species, 'setosa'); fckX = meas(fckI,:); fckT = table (fckX(:,1), fckX(:,2), 'VariableNames', {'SL', 'SW'}); fckT.Species = categorical (species(fckI)); ***** test # the response is named by a column and the rest are predictors Mdl = fitckernel (fckT, 'Species'); assert_equal (Mdl.PredictorNames, {'SL', 'SW'}); assert_equal (Mdl.ResponseName, 'Species'); ***** test # predict takes a table, matched by name and not by position Mdl = fitckernel (fckT, 'Species'); a = predict (Mdl, fckT); assert_equal (predict (Mdl, fckT(:, [3, 2, 1])), a); ***** test # a cross-validated fit takes a table too Mdl = fitckernel (fckT, 'Species', 'KFold', 3); assert_equal (class (Mdl), 'ClassificationPartitionedKernel'); ***** error ... fitckernel (fckT, 'NoSuch') 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitcecoc.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitcecoc.m ***** demo ## Fit from a table, and predict on one load fisheriris T = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = categorical (species); ## A column holding levels is a categorical predictor without being named ## one T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ## The response is named by its column, and everything else is a predictor Mdl = fitcecoc (T, 'Species'); Mdl.PredictorNames Mdl.CategoricalPredictors ## A model formula names them instead, holding main effects only Mdl2 = fitcecoc (T, 'Species ~ PL + PW'); Mdl2.PredictorNames ## predict reads a table by the names the model was fitted on, so the ## columns may come in any order label = predict (Mdl, T(1:5, [6, 5, 4, 3, 2, 1])); label' ***** test # MATLAB parity: the default fit and what it reports load fisheriris Mdl = fitcecoc (meas, species); assert_equal (class (Mdl), 'ClassificationECOC'); assert_equal (numel (properties (Mdl)), 22); assert_equal (Mdl.CodingName, 'onevsone'); assert_equal (Mdl.BinaryLoss, 'hinge'); assert_equal (Mdl.CodingMatrix, [1, 1, 0; -1, 0, 1; 0, -1, -1]); assert_equal (Mdl.LearnerWeights, [2/3, 2/3, 2/3], 1e-12); assert_equal (Mdl.NumObservations, 150); ***** test # MATLAB parity: the loss of the default fit ## Our binary SVM is LIBSVM where MATLAB's is SMO, so the scores differ in ## the fourth digit on the pair that is not separable; the labels they ## lead to do not. load fisheriris Mdl = fitcecoc (meas, species); assert_equal (resubLoss (Mdl), 0.0066666666666667, 1e-12); ***** test # MATLAB parity: a tree code reproduces the decoding exactly ## Our trees match MATLAB's on this fixture, so the whole path can be ## compared and not only the labels. Measured on R2024a. load fisheriris Mdl = fitcecoc (meas, species, 'Learners', 'tree'); assert_equal (Mdl.BinaryLoss, 'quadratic'); [~, NegLoss] = predict (Mdl, meas([1, 20, 51, 70, 101, 130], :)); assert_equal (NegLoss, ... [0, -1, -2; ... 0, -1, -2; ... -2, 0, -1; ... -2, 0, -1; ... -2, -0.956994328922495, -0.000472589792060491; ... -2, -0.444444444444445, -0.111111111111111], 1e-12); ***** test # MATLAB parity: the default binary loss follows the learner load fisheriris for p = {{'svm', 'hinge'}, {'tree', 'quadratic'}, {'knn', 'quadratic'}, ... {'naivebayes', 'quadratic'}, {'discriminant', 'quadratic'}} Mdl = fitcecoc (meas, species, 'Learners', p{1}{1}); assert_equal (Mdl.BinaryLoss, p{1}{2}); endfor ***** test # MATLAB parity: a learner keeping no data gives a compact model load fisheriris assert_equal (class (fitcecoc (meas, species, 'Learners', 'linear')), ... 'CompactClassificationECOC'); assert_equal (class (fitcecoc (meas, species, 'Learners', 'kernel')), ... 'CompactClassificationECOC'); ***** test # a template carries the options its learner is fitted with load fisheriris Mdl = fitcecoc (meas, species, 'Learners', templateTree ('MaxNumSplits', 2)); assert_equal (Mdl.BinaryLearners{1}.ModelParameters.MaxSplits, 2); ***** test # MATLAB parity: the coding design is taken by name load fisheriris Mdl = fitcecoc (meas, species, 'Coding', 'onevsall'); assert_equal (Mdl.CodingName, 'onevsall'); assert_equal (Mdl.CodingMatrix, 2 * eye (3) - 1); assert_equal (numel (Mdl.BinaryLearners), 3); ***** test # MATLAB parity: a coding matrix given outright is 'custom' load fisheriris M = [1, 0, -1; -1, 1, 0; 0, -1, 1]; Mdl = fitcecoc (meas, species, 'Coding', M); assert_equal (Mdl.CodingName, 'custom'); assert_equal (Mdl.CodingMatrix, M); ***** test # what an observation was to each learner is its class's row load fisheriris Mdl = fitcecoc (meas, species); assert_equal (Mdl.BinaryY(1,:), [1, 1, 0]); assert_equal (Mdl.BinaryY(51,:), [-1, 0, 1]); assert_equal (Mdl.BinaryY(101,:), [0, -1, -1]); ***** test # MATLAB parity: a cross-validation option gives a partitioned model load fisheriris CV = fitcecoc (meas, species, 'KFold', 5); assert_equal (class (CV), 'ClassificationPartitionedECOC'); assert_equal (CV.KFold, 5); assert_equal (class (fitcecoc (meas, species, 'Holdout', 0.3)), ... 'ClassificationPartitionedECOC'); ***** test # MATLAB parity: a character matrix response counts a class per row load fisheriris Mdl = fitcecoc (meas, char (species)); assert_equal (size (Mdl.CodingMatrix), [3, 3]); assert_equal (predict (Mdl, meas([1, 60, 120], :)), ... char ({'setosa'; 'versicolor'; 'virginica'})); ***** error ... fitcecoc (ones (8, 2), [1; 2; 1; 2; 1; 2; 1; 2], 'KFold', 2, 'Holdout', 0.3) ***** error fitcecoc (ones (4, 2)) ***** error ... fitcecoc (ones (4, 2), [1; 2; 1; 2], 'Coding') ***** error ... fitcecoc (ones (4, 2), [1; 2; 1]) ***** error ... fitcecoc (ones (4, 2), [1; 2; 1; 2], 'Learners', 'nosuch') ***** error ... fitcecoc (ones (4, 2), [1; 2; 1; 2], 'FitPosterior', true) ***** error ... fitcecoc (ones (4, 2), [1; 2; 1; 2], 'NoSuch', 1) ***** test # MATLAB parity: classes given as text are sorted load fisheriris k = [101:150, 1:50, 51:100]; Mdl = fitcecoc (meas(k,:), species(k)); assert_equal (Mdl.ClassNames, {'setosa'; 'versicolor'; 'virginica'}); ***** test # MATLAB parity: a given ClassNames order is kept load fisheriris Mdl = fitcecoc (meas(1:150,:), species(1:150), ... 'ClassNames', {'virginica'; 'setosa'; 'versicolor'}); assert_equal (Mdl.ClassNames, {'virginica'; 'setosa'; 'versicolor'}); ***** error ... load fisheriris fitcecoc (meas, species, 'ClassNames', [3, 1, 2]) ***** error ... load fisheriris fitcecoc (meas, species, 'ClassNames', {'setosa'; 'rose'}) ***** test # MATLAB parity: GentleBoost ensembles as binary learners load fisheriris T = templateEnsemble ('GentleBoost', 5, templateTree ('MaxNumSplits', 1)); Mdl = fitcecoc (meas, species, 'Learners', T); assert_equal (Mdl.BinaryLoss, 'exponential'); assert_equal (resubLoss (Mdl), 1/30, 1e-14); [~, NegLoss] = predict (Mdl, meas([51, 120],:)); assert_equal (NegLoss, [-74.2065795512883, -0.017199167383083, ... -4.030127061700748; -74.2065795512883, ... -0.197045791294161, -0.32160454535994], 1e-12); ***** test # MATLAB parity: LogitBoost ensembles as binary learners load fisheriris T = templateEnsemble ('LogitBoost', 5, templateTree ('MaxNumSplits', 1)); Mdl = fitcecoc (meas, species, 'Learners', T); assert_equal (Mdl.BinaryLoss, 'binodeviance'); assert_equal (resubLoss (Mdl), 1/30, 1e-14); [~, NegLoss] = predict (Mdl, meas([51, 120],:)); assert_equal (NegLoss, [-4.844912733252615, -0.002477430762383, ... -1.86787026045674; -4.844912733252615, ... -0.163235262337723, -0.365681737695726], 1e-12); ***** test # MATLAB parity: the weights of an AdaBoostM1 binary learner load fisheriris T = templateEnsemble ('AdaBoostM1', 5, templateTree ('MaxNumSplits', 1)); Mdl = fitcecoc (meas, species, 'Learners', T); assert_equal (Mdl.BinaryLoss, 'exponential'); assert_equal (Mdl.BinaryLearners{3}.TrainedWeights', ... [1.375767656520975, 0.993534110774411, ... 0.883434373403998, 0.554364192108758, ... 0.268194447432047], 1e-12); ***** test # MATLAB parity: bagged and random subspace ensembles read posteriors load fisheriris Mdl = fitcecoc (meas, species, 'Learners', ... templateEnsemble ('Bag', 3, 'tree')); assert_equal (Mdl.BinaryLoss, 'quadratic'); assert_equal (class (Mdl.BinaryLearners{1}), 'ClassificationBaggedEnsemble'); Mdl = fitcecoc (meas, species, 'Learners', ... templateEnsemble ('Subspace', 3, 'knn', ... 'NPredToSample', 2)); assert_equal (Mdl.BinaryLoss, 'quadratic'); ***** test # MATLAB parity: an ensemble named as the learner is LogitBoost load fisheriris Mdl = fitcecoc (meas, species, 'Learners', 'ensemble'); assert_equal (Mdl.ModelParameters.BinaryLearners.Method, 'LogitBoost'); assert_equal (Mdl.ModelParameters.BinaryLearners.NLearn, 100); assert_equal (Mdl.BinaryLoss, 'binodeviance'); assert_equal (Mdl.BinaryLearners{1}.NumTrained, 100); ***** test # an ensemble of binary learners cross-validates load fisheriris T = templateEnsemble ('GentleBoost', 3, templateTree ('MaxNumSplits', 1)); CV = crossval (fitcecoc (meas, species, 'Learners', T), 'KFold', 3); assert_equal (class (CV), 'ClassificationPartitionedECOC'); ***** test # RUSBoost binary scores are the weighted mean of tree probabilities load fisheriris T = templateEnsemble ('RUSBoost', 5, templateTree ('MaxNumSplits', 1)); Mdl = fitcecoc (meas, species, 'Learners', T); assert_equal (Mdl.BinaryLoss, 'quadratic'); B = Mdl.BinaryLearners{1}; [~, s] = predict (B, meas(51,:)); [~, ~, PBScore] = predict (Mdl, meas(51,:)); assert_equal (PBScore(1), s(2) / sum (B.TrainedWeights), 1e-14); assert_equal (all (PBScore >= 0 & PBScore <= 1), true); assert_equal (isfinite (resubLoss (Mdl)), true); ***** error ... load fisheriris fitcecoc (meas, species, 'Learners', templateEnsemble ('LSBoost', 5, 'tree')) ***** shared fecT load fisheriris fecT = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); fecT.Species = categorical (species); fecT.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ***** test # the response is named by a column and the rest are predictors Mdl = fitcecoc (fecT, 'Species'); assert_equal (Mdl.PredictorNames, {'SL', 'SW', 'PL', 'PW', 'Wide'}); assert_equal (Mdl.ResponseName, 'Species'); assert_equal (Mdl.CategoricalPredictors, 5); ***** test # a model formula names the response and the predictors together Mdl = fitcecoc (fecT, 'Species ~ PW + SL'); assert_equal (Mdl.PredictorNames, {'PW', 'SL'}); assert_equal (isempty (Mdl.CategoricalPredictors), true); ***** test # the response may be given beside a table of predictors Mdl = fitcecoc (fecT(:,1:4), fecT.Species); assert_equal (Mdl.PredictorNames, {'SL', 'SW', 'PL', 'PW'}); assert_equal (Mdl.ResponseName, 'Y'); ***** test # predict takes a table, matched by name and not by position Mdl = fitcecoc (fecT, 'Species'); a = predict (Mdl, fecT); assert_equal (class (a), 'categorical'); assert_equal (predict (Mdl, fecT(:, [6, 5, 4, 3, 2, 1])), a); ***** test # the levels travel with the model when it is made compact Mdl = fitcecoc (fecT, 'Species'); CMdl = compact (Mdl); assert_equal (CMdl.PredictorLevels, Mdl.PredictorLevels); assert_equal (predict (CMdl, fecT), predict (Mdl, fecT)); ***** error ... fitcecoc (fecT, 'NoSuch') ***** error ... fitcecoc (fecT, 'Species ~ SL*PW') ***** error ... predict (fitcecoc (fecT, 'Species'), fecT(:, [1, 3, 4, 5, 6])) 38 tests, 38 passed, 0 known failure, 0 skipped [inst/Machine_Learning/ClassificationECOC.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/ClassificationECOC.m ***** test # MATLAB parity: the property surface a fit reports load fisheriris Mdl = ClassificationECOC (meas, species); assert_equal (class (Mdl), 'ClassificationECOC'); assert_equal (numel (properties (Mdl)), 22); assert_equal (Mdl.ResponseName, 'Y'); assert_equal (Mdl.ClassNames, unique (species)); assert_equal (Mdl.Prior, [1/3, 1/3, 1/3], 1e-14); assert_equal (Mdl.Cost, ones (3) - eye (3)); assert_equal (Mdl.ScoreTransform, 'none'); assert_equal (Mdl.CategoricalPredictors, []); ***** test # the binary learners are one per column of the coding matrix load fisheriris Mdl = ClassificationECOC (meas, species, 'Coding', 'ternarycomplete'); assert_equal (columns (Mdl.CodingMatrix), 6); assert_equal (numel (Mdl.BinaryLearners), 6); assert_equal (numel (Mdl.LearnerWeights), 6); ***** test # MATLAB parity: resubstitution answers the training data load fisheriris Mdl = ClassificationECOC (meas, species, 'Learners', 'tree'); assert_equal (resubLoss (Mdl), 0.02, 1e-12); label = resubPredict (Mdl); assert_equal (sum (! strcmp (label, species)), 3); ***** test # a margin is positive exactly where the label was right load fisheriris Mdl = ClassificationECOC (meas, species, 'Learners', 'tree'); m = resubMargin (Mdl); right = strcmp (resubPredict (Mdl), species); assert_equal (m > 0, right); assert_equal (sum (! right), 3); ***** test # compact keeps the learners and drops the data load fisheriris Mdl = ClassificationECOC (meas, species); CMdl = compact (Mdl); assert_equal (class (CMdl), 'CompactClassificationECOC'); assert_equal (CMdl.CodingMatrix, Mdl.CodingMatrix); assert_equal (predict (CMdl, meas(1:5,:)), predict (Mdl, meas(1:5,:))); assert_equal (isprop (CMdl, 'X'), false); ***** test # a class the coding matrix leaves out of every column is refused load fisheriris M = [1, 1; -1, 0; 0, -1]; assert_equal (columns (ClassificationECOC (meas, species, ... 'Coding', M).CodingMatrix), 2); ***** test # crossval returns the ECOC partitioned class, not the general one load fisheriris CV = crossval (ClassificationECOC (meas, species, 'Learners', 'tree')); assert_equal (class (CV), 'ClassificationPartitionedECOC'); assert_equal (CV.KFold, 10); assert_equal (CV.CodingMatrix, [1, 1, 0; -1, 0, 1; 0, -1, -1]); ***** test # discarding support vectors changes nothing the model answers ## The linear model stands in for the vectors exactly, so the labels and ## the loss are what they were and only the memory is gone. load fisheriris Mdl = fitcecoc (meas, species); assert_equal (size (Mdl.BinaryLearners{1}.SupportVectors), [3, 4]); D = discardSupportVectors (Mdl); assert_equal (class (D), 'ClassificationECOC'); assert_equal (size (D.BinaryLearners{1}.SupportVectors), [0, 0]); assert_equal (isempty (D.BinaryLearners{1}.Alpha), true); assert_equal (predict (D, meas), predict (Mdl, meas)); assert_equal (resubLoss (D), 0.0066666666666667, 1e-12); ***** warning ... load fisheriris; ... discardSupportVectors (fitcecoc (meas, species, 'Learners', 'tree')); ***** test # a code of trees is returned unchanged by discardSupportVectors load fisheriris Mdl = fitcecoc (meas, species, 'Learners', 'tree'); ## The state is saved and put back rather than switched on: 'on' would ## enable warning classes Octave disables by default and leak them into ## every test that runs after this one. w = warning ('off', 'all'); D = discardSupportVectors (Mdl); warning (w); assert_equal (predict (D, meas), predict (Mdl, meas)); ***** test # selectModels narrows every binary learner to the same strengths load fisheriris ## The constructor is used and not fitcecoc: a linear learner keeps no ## training data, so the fit route gives back the compact model. LC = ClassificationECOC (meas, species, ... 'Learners', templateLinear ('Lambda', [1e-4, 1e-3, 1e-2])); assert_equal (LC.BinaryLearners{1}.Lambda, [1e-4, 1e-3, 1e-2], 1e-12); S = selectModels (LC, 2); assert_equal (class (S), 'ClassificationECOC'); for j = 1:numel (S.BinaryLearners) assert_equal (S.BinaryLearners{j}.Lambda, 1e-3, 1e-12); endfor ***** error ... load fisheriris; ... selectModels (fitcecoc (meas, species)) ***** error ... load fisheriris; ... selectModels (fitcecoc (meas, species, 'Learners', 'tree'), 1) ***** test # An unused category of a categorical response is not a class load fisheriris y = categorical (species); Mdl = ClassificationECOC (meas(51:150,:), y(51:150)); assert_equal (cellstr (Mdl.ClassNames), {'versicolor'; 'virginica'}); assert_equal (size (Mdl.CodingMatrix), [2, 1]); ***** error ... crossval (ClassificationECOC (ones (4, 2), [1; 2; 1; 2]), 'KFold', 1) ***** error ... Mdl = ClassificationECOC (ones (4, 2), [1; 2; 1; 2]); ... crossval (Mdl, 'KFold', 2, 'Holdout', 0.3) ***** error ... ClassificationECOC (ones (4, 2)) ***** error ... ClassificationECOC (ones (4, 2), [1; 2; 1; 2], 'Coding') ***** error ... ClassificationECOC (ones (4, 2), [1; 2; 1]) ***** error ... ClassificationECOC (ones (4, 2), [1; 2; 1; 2], 'Coding', [2; -2]) ***** error ... ClassificationECOC (ones (4, 2), [1; 2; 1; 2], 'Coding', [1; 1]) ***** error ... ClassificationECOC (ones (4, 2), [1; 2; 1; 2], 'Coding', [1, -1; -1, 1]) ***** error ... ClassificationECOC (ones (4, 2), [1; 2; 1; 2], 'Coding', {1}) ***** shared Xc, y3 k = (0:119)'; c1 = mod (k, 3) + 1; c3 = 10 * (mod (floor (k / 2), 2) + 1); Xc = [c1, sin(k), c3]; y3 = mod (c1 + floor (k / 7), 3) + 1; ***** test # MATLAB parity: every binary learner gets the categorical predictors Mdl = ClassificationECOC (Xc, y3, 'CategoricalPredictors', [1, 3]); assert_equal (Mdl.CategoricalPredictors, [1, 3]); assert_equal (Mdl.ExpandedPredictorNames, {'x1', 'x2', 'x3'}); L = Mdl.BinaryLearners{1}; assert_equal (L.CategoricalPredictors, [1, 3]); assert_equal (L.ExpandedPredictorNames, {'x1 == 1', 'x1 == 2', ... 'x1 == 3', 'x2', 'x3 == 10', 'x3 == 20'}); assert_equal (compact (Mdl).CategoricalPredictors, [1, 3]); ***** test # tree learners take them too, and so do the folds Mdl = ClassificationECOC (Xc, y3, 'CategoricalPredictors', [1, 3], ... 'Learners', 'tree'); assert_equal (Mdl.BinaryLearners{1}.CategoricalPredictors, [1, 3]); CV = crossval (Mdl, 'KFold', 3); assert_equal (CV.Trained{1}.CategoricalPredictors, [1, 3]); ***** test # MATLAB parity: nearest neighbour learners compare levels Mdl = ClassificationECOC (Xc(:,[1, 3]), y3, 'CategoricalPredictors', ... 'all', 'Learners', 'knn'); assert_equal (Mdl.BinaryLearners{1}.Distance, 'hamming'); ***** error ... ClassificationECOC (Xc, y3, 'CategoricalPredictors', 4) ***** error ... ClassificationECOC (Xc, y3, 'CategoricalPredictors', 1, ... 'Learners', 'discriminant') ***** test # equal weights that differ only by rounding reach any learner load fisheriris y = [ones(60, 1); 2 * ones(50, 1); 3 * ones(40, 1)]; Mdl = ClassificationECOC (meas, y, 'Learners', 'knn'); assert_equal (numel (Mdl.BinaryLearners), 3); Mdl = ClassificationECOC (meas, y); assert_equal (class (Mdl.BinaryLearners{1}), 'ClassificationSVM'); ***** test # MATLAB parity: a learner without weights reports its side's prior load fisheriris y = [ones(60, 1); 2 * ones(50, 1); 3 * ones(40, 1)]; Mdl = ClassificationECOC (meas, y, 'Learners', 'knn', 'Prior', 'uniform'); assert_equal (Mdl.BinaryLearners{1}.Prior, [0.5, 0.5], 1e-12); Mdl = ClassificationECOC (meas(11:150,:), y(11:150)); assert_equal (Mdl.BinaryLearners{1}.Prior, [50, 50] / 100, 1e-12); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcecoc (T, 'Species'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcecoc (T, 'Species'); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcecoc (T, 'Species'); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** test load fisheriris Mdl = ClassificationECOC (meas, species, 'FitPosterior', false); assert_equal (class (Mdl), 'ClassificationECOC'); ***** error ... fitcecoc ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', ... int8 ([1; 1; 1; 1])) ***** error ... fitcecoc ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', true (4, 1)) ***** test ## Single weights are stored single, summing to one load fisheriris w = 1 + (1:150)' / 7; Mdl = fitcecoc (meas, species, 'Weights', single (w), 'Learners', 'tree'); assert_equal (class (Mdl.W), 'single'); assert_equal (sum (double (Mdl.W)), 1, 1e-6); ***** test ## Weights varying within a class reach discriminant learners, as R2024a load fisheriris Mdl = ClassificationECOC (meas, species, 'Learners', 'discriminant', ... 'Weights', 1 + (1:150)' / 7); [~, NegLoss] = predict (Mdl, meas(134,:)); assert_equal (NegLoss, [-2, -0.2957570199841673, -0.2080860771266001], ... 1e-12); ***** test ## Weights varying within a class reach nearest neighbour learners load fisheriris Mdl = ClassificationECOC (meas, species, ... 'Learners', templateKNN ('NumNeighbors', 5), ... 'Weights', 1 + (1:150)' / 7); [~, NegLoss] = predict (Mdl, meas(58,:)); assert_equal (NegLoss, [-1.211303329864724, 0, -1.291948491155047], 1e-12); ***** test ## Weights varying within a class reach support vector machine learners load fisheriris Mdl = ClassificationECOC (meas, species, 'Learners', 'svm', ... 'Weights', 1 + (1:150)' / 7); [~, NegLoss] = predict (Mdl, meas(23,:)); assert_equal (NegLoss, [0, -0.749030561477596, -3.406162840589479], 2e-3); ***** test ## Weights varying within a class reach naive Bayes learners, as R2024a load fisheriris Mdl = ClassificationECOC (meas, species, 'Learners', 'naivebayes', ... 'Weights', 1 + (1:150)' / 7); [~, NegLoss] = predict (Mdl, meas(51,:)); assert_equal (NegLoss, [-2, -0.1264612831076871, -0.4152333784029093], ... 1e-12); 41 tests, 41 passed, 0 known failure, 0 skipped [inst/Machine_Learning/RegressionNeuralNetwork.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/RegressionNeuralNetwork.m ***** test rand ('seed', 42); X = linspace (-1, 1, 40)'; Y = 2 * X + 0.5; Mdl = RegressionNeuralNetwork (X, Y, 'IterationLimit', 50); assert_equal (class (Mdl), 'RegressionNeuralNetwork'); assert_equal (Mdl.LayerSizes, 10); assert_equal (Mdl.Activations, 'relu'); assert_equal (Mdl.OutputLayerActivation, 'none'); assert_equal (Mdl.LearningRate, 0.003); assert_equal (Mdl.IterationLimit, 50); assert_equal (isempty (Mdl.Mu), true); assert_equal (Mdl.Solver, 'LBFGS'); assert_equal (Mdl.NumObservations, 40); assert_equal (Mdl.NumPredictors, 1); assert_equal (Mdl.ResponseName, 'Y'); assert_equal (Mdl.PredictorNames, {'x1'}); ***** test rand ('seed', 42); randn ('seed', 42); X = linspace (-2, 2, 60)'; Y = 30 * X + 100; Mdl = RegressionNeuralNetwork (X, Y, 'IterationLimit', 400); assert_equal (rows (Mdl.LayerWeights{end}), 1); yFit = predict (Mdl, X); assert_equal (size (yFit), [60, 1]); assert_equal (max (yFit) > 50, true); ***** test rand ('seed', 7); randn ('seed', 7); X = linspace (-2, 2, 80)'; Y = 3 * X.^2 - 1 + randn (80, 1) * 0.05; Mdl = RegressionNeuralNetwork (X, Y, 'LayerSizes', [12, 12], ... 'IterationLimit', 600); assert_equal (sqrt (resubLoss (Mdl)) < 0.2, true); ***** test rand ('seed', 42); randn ('seed', 42); X = linspace (0, 1, 50)'; Y = 4 * X - 2; Mdl = RegressionNeuralNetwork (X, Y, 'IterationLimit', 200, ... 'Solver', 'sgd'); h = Mdl.TrainingHistory; assert_equal (class (h), 'table'); assert_equal (h.Properties.VariableNames, ... {'Iteration', 'TrainingLoss', 'Time', 'ValidationLoss', ... 'ValidationChecks'}); assert_equal (rows (h), 200); assert_equal (h.Iteration', 1:200); assert_equal (h.TrainingLoss(end) < h.TrainingLoss(1), true); assert_equal (h.TrainingLoss(end), resubLoss (Mdl), 1e-12); ***** test rand ('seed', 42); X = linspace (0, 1, 30)'; Mdl = RegressionNeuralNetwork (X, 2 * X, 'Solver', 'sgd', ... 'IterationLimit', 25); assert_equal (fieldnames (Mdl.ConvergenceInfo), ... {'Iterations'; 'TrainingLoss'; 'Time'; ... 'ValidationLoss'; 'ValidationChecks'; 'History'}); assert_equal (numel (Mdl.ConvergenceInfo.TrainingLoss), 1); assert_equal (rows (Mdl.ConvergenceInfo.History), 25); assert_equal (Mdl.ConvergenceInfo.TrainingLoss, ... Mdl.ConvergenceInfo.History.TrainingLoss(end)); assert_equal (Mdl.ConvergenceInfo.Time > 0, true); ***** test rand ('seed', 42); randn ('seed', 42); X = [randn(30, 2); randn(30, 2) + 3]; Y = X(:,1) - 2 * X(:,2); Mdl = RegressionNeuralNetwork (X, Y, 'IterationLimit', 100); assert_equal (predict (Mdl, X), resubPredict (Mdl)); ***** test rand ('seed', 42); randn ('seed', 42); X = [randn(60, 1), randn(60, 1) * 1000]; Y = X(:,1) + X(:,2) / 1000; Mdl = RegressionNeuralNetwork (X, Y, 'Standardize', true, ... 'IterationLimit', 300); assert_equal (size (Mdl.Mu), [1, 2]); assert_equal (size (Mdl.Sigma), [1, 2]); assert_equal (predict (Mdl, X), resubPredict (Mdl)); assert_equal (sqrt (resubLoss (Mdl)) < std (Y), true); ***** test rand ('seed', 42); X = [linspace(0, 1, 20)', ones(20, 1)]; Mdl = RegressionNeuralNetwork (X, X(:,1), 'Standardize', true, ... 'IterationLimit', 50); assert_equal (Mdl.Sigma(2), 1); assert_equal (all (isfinite (resubPredict (Mdl))), true); ***** test rand ('seed', 42); X = linspace (0, 1, 30)'; Mdl = RegressionNeuralNetwork (X, 2 * X, 'LayerSizes', [4, 6], ... 'Activations', {'tanh', 'sigmoid'}, ... 'IterationLimit', 20); assert_equal (Mdl.LayerSizes, [4, 6]); assert_equal (Mdl.Activations, {'tanh', 'sigmoid'}); assert_equal (numel (Mdl.LayerWeights), 3); assert_equal (size (Mdl.LayerWeights{1}), [4, 1]); assert_equal (size (Mdl.LayerWeights{2}), [6, 4]); assert_equal (size (Mdl.LayerWeights{3}), [1, 6]); assert_equal (Mdl.ModelParameters.Activations, {'tanh', 'sigmoid'}); assert_equal (Mdl.ModelParameters.OutputLayerActivation, 'none'); ***** test X = linspace (0, 1, 20)'; rand ('seed', 42); M1 = RegressionNeuralNetwork (X, 2 * X, 'OutputLayerActivation', 'none', ... 'IterationLimit', 10); rand ('seed', 42); M2 = RegressionNeuralNetwork (X, 2 * X, 'OutputLayerActivation', ... 'linear', 'IterationLimit', 10); assert_equal (predict (M1, X), predict (M2, X)); ***** test rand ('seed', 42); X = [linspace(0, 1, 12)'; NaN; 0.5]; Y = [2 * linspace(0, 1, 12)'; 1; NaN]; Mdl = RegressionNeuralNetwork (X, Y, 'IterationLimit', 20); assert_equal (Mdl.NumObservations, 13); assert_equal (sum (Mdl.RowsUsed), 13); assert_equal (Mdl.RowsUsed(13:14), [true; false]); assert_equal (numel (resubPredict (Mdl)), 13); ***** test rand ('seed', 42); X = linspace (0, 1, 25)'; Mdl = RegressionNeuralNetwork (X, 2 * X, 'IterationLimit', 10); assert_equal (size (Mdl.W), [25, 1]); assert_equal (sum (Mdl.W), 1, 1e-12); assert_equal (Mdl.W, ones (25, 1) / 25, 1e-12); ***** test rand ('seed', 42); randn ('seed', 42); X = linspace (0, 1, 30)'; Y = 3 * X + 1; Mdl = RegressionNeuralNetwork (X, Y, 'IterationLimit', 100); yFit = predict (Mdl, X); assert_equal (loss (Mdl, X, Y), mean ((Y - yFit) .^ 2), 1e-12); assert_equal (loss (Mdl, X, Y, 'LossFun', 'mse'), loss (Mdl, X, Y), 1e-12); w = rand (30, 1) + 0.1; assert_equal (loss (Mdl, X, Y, 'Weights', w), ... loss (Mdl, X, Y, 'Weights', 7 * w), 1e-12); assert_equal (loss (Mdl, X, Y, 'Weights', w), ... sum ((w / sum (w)) .* (Y - yFit) .^ 2), 1e-12); ***** test rand ('seed', 42); X = linspace (0, 1, 20)'; Y = 2 * X; Mdl = RegressionNeuralNetwork (X, Y, 'IterationLimit', 50); f = @(y, yf, w) sum (w .* abs (y - yf)); yFit = predict (Mdl, X); assert_equal (loss (Mdl, X, Y, 'LossFun', f), ... mean (abs (Y - yFit)), 1e-12); ***** test rand ('seed', 42); randn ('seed', 42); X = linspace (0, 1, 21)'; Y = [3 * linspace(0, 1, 20)'; NaN]; Mdl = RegressionNeuralNetwork (X, Y, 'IterationLimit', 80); Xu = X(Mdl.RowsUsed, :); Yu = Y(Mdl.RowsUsed); assert_equal (resubLoss (Mdl), loss (Mdl, Xu, Yu), 1e-12); assert_equal (resubLoss (Mdl, 'Weights', ones (20, 1)), ... loss (Mdl, Xu, Yu), 1e-12); ***** test rand ('seed', 42); X = linspace (0, 1, 20)'; Y = 2 * X + 1; Mdl = RegressionNeuralNetwork (X, Y, 'IterationLimit', 50); raw = predict (Mdl, X); Mdl.ResponseTransform = 'exp'; assert_equal (predict (Mdl, X), exp (raw), 1e-12); Mdl.ResponseTransform = @(y) 2 * y; assert_equal (predict (Mdl, X), 2 * raw, 1e-12); Mdl.ResponseTransform = 'none'; assert_equal (predict (Mdl, X), raw, 1e-12); ***** test rand ('seed', 42); X = linspace (0, 1, 20)'; Mdl = RegressionNeuralNetwork (X, 2 * X, 'ResponseTransform', 'identity', ... 'IterationLimit', 20); assert_equal (class (Mdl.ResponseTransform), 'char'); assert_equal (Mdl.ResponseTransform, 'none'); # identity is stored as none ***** test rand ('seed', 42); randn ('seed', 42); X = linspace (0, 1, 30)'; Y = 4 * X - 1; Mdl = RegressionNeuralNetwork (X, Y, 'LayerSizes', [6, 4], ... 'Solver', 'sgd', 'IterationLimit', 60); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2), 'RegressionNeuralNetwork'); assert_equal (M2.LayerWeights, Mdl.LayerWeights); assert_equal (M2.LayerBiases, Mdl.LayerBiases); assert_equal (M2.NumObservations, Mdl.NumObservations); assert_equal (M2.LayerSizes, Mdl.LayerSizes); assert_equal (M2.ResponseName, Mdl.ResponseName); assert_equal (M2.W, Mdl.W); assert_equal (predict (M2, X), predict (Mdl, X)); assert_equal (rows (M2.TrainingHistory), 60); assert_equal (M2.TrainingHistory.TrainingLoss, ... Mdl.TrainingHistory.TrainingLoss); ***** test rand ('seed', 42); randn ('seed', 42); X = [randn(40, 2); randn(40, 2) + 2]; Y = X(:,1) - X(:,2); Mdl = RegressionNeuralNetwork (X, Y, 'IterationLimit', 100); CMdl = compact (Mdl); assert_equal (class (CMdl), 'CompactRegressionNeuralNetwork'); assert_equal (predict (CMdl, X), predict (Mdl, X)); assert_equal (loss (CMdl, X, Y), loss (Mdl, X, Y)); ***** test rand ('seed', 42); randn ('seed', 42); X = randn (30, 2); Y = X(:,1) - X(:,2); Mdl = fitrnet (X, Y, 'IterationLimit', 20); CVMdl = crossval (Mdl, 'KFold', 3); assert_equal (class (CVMdl), 'RegressionPartitionedModel'); assert_equal (CVMdl.KFold, 3); assert_equal (CVMdl.CrossValidatedModel, 'NeuralNetwork'); assert_equal (numel (kfoldPredict (CVMdl)), 30); assert_equal (isfinite (kfoldLoss (CVMdl)), true); ***** test x = linspace (0, 1, 40)'; Mdl = fitrnet (x, sin (2*pi*x), "IterationLimit", 50, "Solver", "lbfgs"); assert_equal (Mdl.Solver, "LBFGS"); assert_equal (Mdl.TrainingHistory.Properties.VariableNames, ... {"Iteration", "TrainingLoss", "Gradient", "Step", ... "Time", "ValidationLoss", "ValidationChecks"}); ***** test x = linspace (0, 1, 40)'; Mdl = fitrnet (x, sin (2*pi*x), "IterationLimit", 50, "Solver", "lbfgs"); ci = Mdl.ConvergenceInfo; assert_equal (isfield (ci, "Gradient"), true); assert_equal (isfield (ci, "Step"), true); assert_equal (isfield (ci, "ConvergenceCriterion"), true); ***** test x = linspace (0, 1, 40)'; Mdl = fitrnet (x, sin (2*pi*x), "Solver", "sgd", "IterationLimit", 20); assert_equal (Mdl.Solver, "Gradient Descent"); assert_equal (columns (Mdl.TrainingHistory), 5); ***** test x = linspace (0, 1, 40)'; Mdl = fitrnet (x, sin (2*pi*x), "IterationLimit", 20); assert_equal (Mdl.Solver, "LBFGS"); assert_equal (Mdl.TrainingHistory.Properties.VariableNames, ... {"Iteration", "TrainingLoss", "Gradient", "Step", ... "Time", "ValidationLoss", "ValidationChecks"}); ***** test x = linspace (0, 1, 40)'; Mdl = fitrnet (x, sin (2*pi*x), "IterationLimit", 30, "Solver", "lbfgs"); fname = tempname (); savemodel (Mdl, fname); Mdl2 = loadmodel (fname); delete (fname); assert_equal (table2cell (Mdl2.TrainingHistory), ... table2cell (Mdl.TrainingHistory)); ***** test # A row missing a predictor predicts the lower median of the response X = [(1:10)', mod((1:10)', 3)]; Mdl = RegressionNeuralNetwork (X, (1:10)'); assert_equal (predict (Mdl, [NaN, 1]), 5); ***** error ... fitrnet (ones (5, 2), [1; 2; 3; 4; 5], "Solver", "sgd", ... "GradientTolerance", 1e-8) ***** error ... fitrnet (ones (5, 2), [1; 2; 3; 4; 5], "Solver", "lbfgs", "LearningRate", 0.1) ***** error ... fitrnet (ones (5, 2), [1; 2; 3; 4; 5], "Solver", "bogus") ***** error ... fitrnet (ones (5, 2), [1; 2; 3; 4; 5], "Solver", "lbfgs", "LossTolerance", NaN) ***** error ... crossval (fitrnet (randn (12, 2), randn (12, 1), ... 'IterationLimit', 20), 'KFold') ***** error ... crossval (fitrnet (randn (12, 2), randn (12, 1), ... 'IterationLimit', 20), ... 'KFold', 3, 'Leaveout', 'on') ***** error ... crossval (fitrnet (randn (12, 2), randn (12, 1), ... 'IterationLimit', 20), 'KFold', 1) ***** error ... crossval (fitrnet (randn (12, 2), randn (12, 1), ... 'IterationLimit', 20), 'Holdout', 1) ***** error ... crossval (fitrnet (randn (12, 2), randn (12, 1), ... 'IterationLimit', 20), 'Leaveout', 1) ***** error ... crossval (fitrnet (randn (12, 2), randn (12, 1), ... 'IterationLimit', 20), 'CVPartition', 1) ***** error ... crossval (fitrnet (randn (12, 2), randn (12, 1), ... 'IterationLimit', 20), 'Nope', 1) ***** error ... RegressionNeuralNetwork () ***** error ... RegressionNeuralNetwork (ones (10, 2)) ***** error ... RegressionNeuralNetwork (ones (10, 2), ones (5, 1)) ***** error ... RegressionNeuralNetwork (ones (5, 2), {'a'; 'b'; 'c'; 'd'; 'e'}) ***** error ... RegressionNeuralNetwork (ones (5, 2), complex (ones (5, 1))) ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 3)) ***** error ... RegressionNeuralNetwork ([1; Inf; 3], [1; 2; 3]) ***** error ... RegressionNeuralNetwork ([1; 2; 3], [1; Inf; 3]) ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), 'Standardize', 'yes') ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), 'PredictorNames', 'a') ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), 'PredictorNames', {'a'}) ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), 'ResponseName', 5) ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), 'ResponseTransform', 5) ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), ... 'ResponseTransform', 'nope') ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), ... 'ResponseTransform', @(y) [y; y]) ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), 'LayerSizes', -1) ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), 'LayerSizes', 2.5) ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), 'LearningRate', 0) ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), ... 'LearningRate', [0.1, 0.2]) ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), 'Activations', 5) ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), 'Activations', 'softmax') ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), ... 'Activations', {'relu', 'nope'}) ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), ... 'OutputLayerActivation', 5) ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), ... 'OutputLayerActivation', 'softmax') ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), 'IterationLimit', 0) ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), 'IterationLimit', 2.5) ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), 'DisplayInfo', 'yes') ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), 'Prior', 1) ***** error ... RegressionNeuralNetwork (ones (5, 2), ones (5, 1), 'LayerSizes', [4, 4], ... 'Activations', {'relu', 'relu', 'relu'}) ***** error ... predict (RegressionNeuralNetwork ([1; 2; 3], [1; 2; 3], ... 'IterationLimit', 5)) ***** error ... predict (RegressionNeuralNetwork ([1; 2; 3], [1; 2; 3], ... 'IterationLimit', 5), []) ***** error ... predict (RegressionNeuralNetwork ([1; 2; 3], [1; 2; 3], ... 'IterationLimit', 5), ones (2, 3)) ***** shared RNNMdl rand ('seed', 42); RNNMdl = RegressionNeuralNetwork ([1; 2; 3; 4], [2; 4; 6; 8], ... 'IterationLimit', 10); ***** error ... loss (RNNMdl) ***** error ... loss (RNNMdl, [1; 2]) ***** error ... loss (RNNMdl, [1; 2], [2; 4], 'Weights') ***** error ... loss (RNNMdl, [], [2; 4]) ***** error ... loss (RNNMdl, ones (2, 3), [2; 4]) ***** error ... loss (RNNMdl, [1; 2], []) ***** error ... loss (RNNMdl, [1; 2], {'a'; 'b'}) ***** error ... loss (RNNMdl, [1; 2], [2; 4; 6]) ***** error ... loss (RNNMdl, [1; 2], [2; 4], 'LossFun', 5) ***** error ... loss (RNNMdl, [1; 2], [2; 4], 'LossFun', 'mae') ***** error ... loss (RNNMdl, [1; 2], [2; 4], 'LossFun', @(y, yf, w) [1, 2]) ***** error ... loss (RNNMdl, [1; 2], [2; 4], 'Weights', {'a'}) ***** error ... loss (RNNMdl, [1; 2], [2; 4], 'Weights', ones (2, 2)) ***** error ... loss (RNNMdl, [1; 2], [2; 4], 'Weights', [1; 2; 3]) ***** error ... loss (RNNMdl, [1; 2], [2; 4], 'Nope', 1) ***** error ... loss (RNNMdl, [1; 2], [2; 4], 5, 1) ***** error ... savemodel (RNNMdl) ***** error ... savemodel (RNNMdl, 5) ***** error ... RNNMdl.ResponseTransform = 'nope'; ***** test load fisheriris X = meas(:,2:4); Y = meas(:,1); Mdl = fitrnet (X, Y, 'IterationLimit', 20); assert_equal (Mdl.RowsUsed, []); assert_equal (class (Mdl.RowsUsed), 'double'); assert_equal (Mdl.NumObservations, 150); assert_equal (rows (Mdl.X), 150); assert_equal (rows (Mdl.W), 150); ***** test load fisheriris X = meas(:,2:4); Y = meas(:,1); Y(5) = NaN; Mdl = fitrnet (X, Y, 'IterationLimit', 20); assert_equal (class (Mdl.RowsUsed), 'logical'); assert_equal (size (Mdl.RowsUsed), [150, 1]); assert_equal (sum (Mdl.RowsUsed), 149); assert_equal (Mdl.RowsUsed(5), false); assert_equal (Mdl.NumObservations, 149); assert_equal (rows (Mdl.X), 149); assert_equal (rows (Mdl.W), 149); ***** test load fisheriris X = meas(:,2:4); X(3,2) = NaN; Y = meas(:,1); Mdl = fitrnet (X, Y, 'IterationLimit', 20); assert_equal (Mdl.RowsUsed, []); assert_equal (Mdl.NumObservations, 150); assert_equal (rows (Mdl.X), 150); assert_equal (sum (isnan (Mdl.X(:))), 1); ***** test load fisheriris X = meas(:,2:4); X(7,2) = NaN; X(120,3) = NaN; Mdl = fitrnet (X, meas(:,1), 'Standardize', true, 'IterationLimit', 20); assert_equal (Mdl.Mu, [3.0608108108108096, 3.7655405405405395, ... 1.203378378378378], 1e-13); assert_equal (Mdl.Sigma, [0.43214937187299296, 1.7636045663278643, ... 0.76339873235638711], 1e-13); ***** test load fisheriris X = meas(:,2:4); Y = meas(:,1); Mdl = fitrnet (X, Y, 'IterationLimit', 20); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2), 'RegressionNeuralNetwork'); assert_equal (M2.NumObservations, Mdl.NumObservations); assert_equal (M2.PredictorNames, Mdl.PredictorNames); assert_equal (class (M2.ResponseTransform), class (Mdl.ResponseTransform)); assert_equal (predict (M2, X(1:5,:)), predict (Mdl, X(1:5,:)), 1e-12); ***** test load fisheriris Mdl = fitrnet (meas(:,1:3), meas(:,4), 'IterationLimit', 10); assert_equal (class (Mdl.BinEdges), 'cell'); assert_equal (Mdl.BinEdges, {}); ***** test load fisheriris Mdl = fitrnet (meas(:,1:3), meas(:,4), 'IterationLimit', 20); assert_equal (isempty (Mdl.HyperparameterOptimizationResults), true); ***** test load fisheriris Mdl = fitrnet (meas(:,2:4), meas(:,1)); assert_equal (fieldnames (Mdl.ModelParameters)', {'LayerSizes', ... 'Activations', 'OutputLayerActivation', 'LayerWeightsInitializers', ... 'Solver', 'LearningRate', 'IterationLimit', 'GradientTolerance', ... 'LossTolerance', 'StepTolerance', 'DisplayInfo', 'StandardizeData', ... 'Version', 'Method', 'Type'}); ***** test load fisheriris MP = fitrnet (meas(:,2:4), meas(:,1)).ModelParameters; assert_equal (MP.LayerSizes, 10); assert_equal (MP.Activations, 'relu'); assert_equal (MP.OutputLayerActivation, 'none'); assert_equal (MP.Version, 1); assert_equal (MP.Method, 'NeuralNetwork'); assert_equal (MP.Type, 'regression'); ***** test load fisheriris MP = fitrnet (meas(:,2:4), meas(:,1), 'LayerSizes', [4, 4], ... 'Activations', {'gelu', 'sigmoid'}).ModelParameters; assert_equal (size (MP), [1, 1]); assert_equal (MP.Activations, {'gelu', 'sigmoid'}); assert_equal (MP.LayerWeightsInitializers, {'he', 'glorot', 'glorot'}); ***** test load fisheriris MP = fitrnet (meas(:,2:4), meas(:,1)).ModelParameters; assert_equal (MP.LayerWeightsInitializers, {'he', 'glorot'}); ***** test load fisheriris Mdl = fitrnet (meas(:,2:4), meas(:,1), 'LayerSizes', [4, 4, 4], ... 'Activations', 'gelu'); assert_equal (Mdl.ModelParameters.LayerWeightsInitializers, ... {'he', 'he', 'he', 'glorot'}); ***** test load fisheriris Mdl = fitrnet (meas(:,2:4), meas(:,1)); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); T = {'identity', @(x) x; 'exp', @(x) exp (x); 'log', @(x) log (x)}; for i = 1:rows (T) Mdl.ResponseTransform = T{i,1}; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, T{i,2}(raw), 1e-12); endfor ***** test load fisheriris Mdl = fitrnet (meas(:,2:4), meas(:,1)); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); Mdl.ResponseTransform = @(x) x .^ 2; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, raw .^ 2, 1e-12); ***** shared Xc, Dc, yr, Xq, Dq k = (0:119)'; c1 = mod (k, 3) + 1; x2 = sin (k); c3 = 10 * (mod (floor (k / 2), 2) + 1); Xc = [c1, x2, c3]; Dc = [c1 == 1, c1 == 2, c1 == 3, x2, c3 == 10, c3 == 20]; yr = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 20) + 0.1 * cos (k); yc = yr > 1; Xq = [1, 0, 10; 2, 0.5, 20]; Dq = [1, 0, 0, 0, 1, 0; 0, 1, 0, 0.5, 0, 1]; ***** test # MATLAB parity: a categorical predictor is dummy coded in its place rand ('seed', 1); randn ('seed', 1); Mdl = RegressionNeuralNetwork (Xc, yr, 'CategoricalPredictors', [1, 3], ... 'LayerSizes', 4); rand ('seed', 1); randn ('seed', 1); H = RegressionNeuralNetwork (Dc, yr, 'LayerSizes', 4); assert_equal (Mdl.ExpandedPredictorNames, {'x1 == 1', 'x1 == 2', ... 'x1 == 3', 'x2', 'x3 == 10', 'x3 == 20'}); assert_equal (Mdl.LayerWeights{1}, H.LayerWeights{1}, 1e-12); assert_equal (predict (Mdl, Xq), predict (H, Dq), 1e-12); assert_equal (resubPredict (Mdl), resubPredict (H), 1e-12); ***** test # a level the fit did not see, or a missing value, predicts the median Mdl = RegressionNeuralNetwork (Xc, yr, 'CategoricalPredictors', [1, 3], ... 'LayerSizes', 4); yhat = predict (Mdl, [4, 0, 10; 1, NaN, 10; 1, 0, 10]); ys = sort (yr); assert_equal (yhat(1:2), repmat (ys(ceil (numel (ys) / 2)), 2, 1)); assert_equal (isnan (yhat(3)), false); ***** test # MATLAB parity: the coded columns are not standardized Mdl = RegressionNeuralNetwork (Xc, yr, 'CategoricalPredictors', [1, 3], ... 'LayerSizes', 4, 'Standardize', true); assert_equal (Mdl.Mu([1:3, 5:6]), zeros (1, 5)); assert_equal (Mdl.Sigma([1:3, 5:6]), ones (1, 5)); ***** test # the coding travels with saved models and cross-validation folds Mdl = RegressionNeuralNetwork (Xc, yr, 'CategoricalPredictors', [1, 3], ... 'LayerSizes', 4); fname = [tempname(), '.mdl']; savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (predict (M2, Xq), predict (Mdl, Xq)); CV = crossval (Mdl, 'KFold', 3); assert_equal (CV.Trained{1}.CategoricalPredictors, [1, 3]); ***** error ... RegressionNeuralNetwork (Xc, yr, 'CategoricalPredictors', 4) ***** test # the class may be built from a table as the fitter builds it load fisheriris T = table (meas(:,2), meas(:,3), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'SL'}); Mdl = RegressionNeuralNetwork (T, 'SL'); assert_equal (Mdl.PredictorNames, {'SW', 'PL'}); assert_equal (Mdl.ResponseName, 'SL'); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,2:3); y = meas(:,1); T = table (X(:,1), X(:,2), 'VariableNames', {'SW', 'PL'}); T.SL = y; Mdl = fitrnet (T, 'SL'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'SL'), a); assert_equal (loss (Mdl, T), a); ***** error ... RegressionNeuralNetwork ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', ... 'Weights', int8 ([1; 1; 1; 1])) ***** error ... RegressionNeuralNetwork ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', ... 'Weights', true (4, 1)) ***** error ... RegressionNeuralNetwork ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', ... 'Weights', [1; 1]) ***** error ... RegressionNeuralNetwork ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', ... 'Weights', [1; -1; 1; 1]) ***** test ## A weight of two fits as the observation given twice load fisheriris X = meas(51:130,2:4); y = meas(51:130,1); w = ones (80, 1); w(1:10) = 2; rand ('seed', 1); A = RegressionNeuralNetwork (X, y, 'LayerSizes', 1, 'Weights', w); rand ('seed', 1); B = RegressionNeuralNetwork ([X; X(1:10,:)], [y; y(1:10)], ... 'LayerSizes', 1); assert_equal (predict (A, X), predict (B, X), 1e-10); ***** test ## Single weights are stored single, summing to one load fisheriris Mdl = RegressionNeuralNetwork (meas(:,2:4), meas(:,1), 'LayerSizes', 3, ... 'Weights', single (1 + (1:150)' / 7)); assert_equal (class (Mdl.W), 'single'); assert_equal (sum (double (Mdl.W)), 1, 1e-6); ***** test ## Standardization weighs the observations, as R2024a does load fisheriris Mdl = RegressionNeuralNetwork (meas(:,2:4), meas(:,1), 'LayerSizes', 3, ... 'Weights', 1 + (1:150)' / 7, ... 'Standardize', true); assert_equal (Mdl.Mu, [2.965608080808081, 4.573050505050505, ... 1.55819797979798], 1e-14); assert_equal (Mdl.Sigma, [0.3809861139391035, 1.433169957562235, ... 0.6470320013330532], 1e-14); ***** test ## resubLoss weighs the observations by W unless given weights load fisheriris w = 1 + (1:150)' / 7; Mdl = RegressionNeuralNetwork (meas(:,2:4), meas(:,1), 'LayerSizes', 3, ... 'Weights', w); assert_equal (resubLoss (Mdl), ... loss (Mdl, meas(:,2:4), meas(:,1), 'Weights', w), 1e-15); 117 tests, 117 passed, 0 known failure, 0 skipped [inst/Machine_Learning/ClassificationKernel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/ClassificationKernel.m ***** demo ## Separate the two overlapping iris species through a randomized ## Gaussian kernel, and read the model the fit produced. load fisheriris X = meas(51:end,:); Y = species(51:end); Mdl = ClassificationKernel (X, Y) predict (Mdl, X([1, 51],:)) ***** demo ## The box constraint and the regularization strength are two names for ## the same quantity: setting either fixes the other. load fisheriris X = meas(51:end,:); Y = species(51:end); Mdl = ClassificationKernel (X, Y, 'BoxConstraint', 4); Mdl.BoxConstraint Mdl.Lambda ***** test ## The model reports the surface MATLAB reports load fisheriris X = meas(51:end,:); Y = species(51:end); Mdl = ClassificationKernel (X, Y); assert_equal (class (Mdl), 'ClassificationKernel'); assert_equal (Mdl.ClassNames, {'versicolor'; 'virginica'}); assert_equal (Mdl.Learner, 'svm'); assert_equal (Mdl.FittedLoss, 'hinge'); assert_equal (Mdl.Regularization, 'ridge (L2)'); assert_equal (Mdl.ScoreTransform, 'none'); assert_equal (Mdl.KernelScale, 1); assert_equal (Mdl.BoxConstraint, 1); assert_equal (Mdl.Lambda, 0.01); assert_equal (Mdl.NumExpansionDimensions, 128); assert_equal (Mdl.Mu, []); assert_equal (Mdl.Sigma, []); assert_equal (Mdl.PredictorNames, {'x1', 'x2', 'x3', 'x4'}); ***** test ## The properties are the ones MATLAB lists, in its order load fisheriris Mdl = ClassificationKernel (meas(51:end,:), species(51:end)); assert_equal (sort (properties (Mdl)), ... sort ({'BoxConstraint'; 'ClassNames'; 'Prior'; 'Cost'; ... 'ScoreTransform'; 'PredictorNames'; ... 'CategoricalPredictors'; 'ResponseName'; ... 'ExpandedPredictorNames'; 'NumExpansionDimensions'; ... 'FittedLoss'; 'Lambda'; 'ModelParameters'; ... 'Regularization'; 'KernelScale'; 'Learner'; 'Mu'; ... 'Sigma'})); ***** test ## The default expansion is MATLAB's, two to the power of five more than ## the base two logarithm of the predictors, capped at fifteen X = randn (40, 2); Y = [ones(20, 1); 2 * ones(20, 1)]; assert_equal (ClassificationKernel (X, Y).NumExpansionDimensions, 64); assert_equal (ClassificationKernel (randn (40, 32), Y) ... .NumExpansionDimensions, 1024); ***** test ## Lambda and the box constraint are reciprocal through the number of ## observations, and either one may be the one that is given load fisheriris X = meas(51:end,:); Y = species(51:end); Mb = ClassificationKernel (X, Y, 'BoxConstraint', 3); assert_equal (Mb.Lambda, 1 / 300, 1e-15); assert_equal (Mb.BoxConstraint, 3); Ml = ClassificationKernel (X, Y, 'Lambda', 0.05); assert_equal (Ml.Lambda, 0.05); assert_equal (Ml.BoxConstraint, 0.2, 1e-15); ***** test ## Standardizing records the means and deviations MATLAB records load fisheriris Mdl = ClassificationKernel (meas(51:end,:), species(51:end), ... 'Standardize', true); assert_equal (Mdl.Mu, [6.262, 2.872, 4.906, 1.676], 1e-12); assert_equal (Mdl.Sigma, [0.662834440074967, 0.332751006494695, ... 0.82557846264289, 0.424768504986284], 1e-12); ***** test ## A logistic learner fits the deviance and reports posteriors load fisheriris X = meas(51:end,:); Mdl = ClassificationKernel (X, species(51:end), 'Learner', 'logistic'); assert_equal (Mdl.FittedLoss, 'logit'); assert_equal (Mdl.ScoreTransform, 'logit'); [~, score] = predict (Mdl, X(1:5,:)); assert_equal (sum (score, 2), ones (5, 1), 1e-12); ***** test ## A support vector machine leaves the scores untransformed, so they are ## a value and its negative load fisheriris X = meas(51:end,:); Mdl = ClassificationKernel (X, species(51:end)); [~, score] = predict (Mdl, X(1:5,:)); assert_equal (score(:,1), -score(:,2), 1e-12); ***** test ## The fit separates the two species it was given, whatever basis it drew load fisheriris X = meas(51:end,:); Y = species(51:end); Mdl = ClassificationKernel (X, Y); assert_equal (loss (Mdl, X, Y) < 0.15, true); assert_equal (edge (Mdl, X, Y) > 0, true); ***** test ## On a set holding one class the edge is still the mean margin load fisheriris X = meas(51:100,:); Y = species(51:100); Mdl = ClassificationKernel (meas(51:end,:), species(51:end)); assert_equal (edge (Mdl, X, Y), mean (margin (Mdl, X, Y)), 1e-14); ***** test ## margin is the true class score less the other, and the labels follow ## the sign of the raw score load fisheriris X = meas(51:end,:); Y = species(51:end); Mdl = ClassificationKernel (X, Y); m = margin (Mdl, X, Y); assert_equal (size (m), [100, 1]); assert_equal (mean (m > 0), 1 - loss (Mdl, X, Y), 1e-12); ***** test ## Predicting through the model's own basis is what makes it a model at ## all: the same rows give the same scores every time it is asked load fisheriris X = meas(51:end,:); Mdl = ClassificationKernel (X, species(51:end)); [~, s1] = predict (Mdl, X(1:10,:)); [~, s2] = predict (Mdl, X(1:10,:)); assert_equal (s1, s2); ***** test ## A wider kernel gives a smoother rule, so it fits the training data ## less closely than a narrow one does load fisheriris X = meas(51:end,:); Y = species(51:end); Mnarrow = ClassificationKernel (X, Y, 'KernelScale', 0.5, ... 'Lambda', 1e-4); Mwide = ClassificationKernel (X, Y, 'KernelScale', 20, 'Lambda', 1e-4); assert_equal (loss (Mnarrow, X, Y) <= loss (Mwide, X, Y), true); ***** test ## resume continues from the coefficients the model already holds, so it ## cannot leave the objective higher than it found it load fisheriris X = meas(51:end,:); Y = species(51:end); Mdl = ClassificationKernel (X, Y, 'IterationLimit', 3); before = Mdl.FitInfo_.ObjectiveValue; Mdl = resume (Mdl, X, Y, 'IterationLimit', 500); assert_equal (class (Mdl), 'ClassificationKernel'); assert_equal (Mdl.FitInfo_.ObjectiveValue <= before, true); assert_equal (Mdl.ModelParameters.IterationLimit, 500); ***** test ## The fit information is MATLAB's kernel structure, not its linear one load fisheriris Mdl = ClassificationKernel (meas(51:end,:), species(51:end)); F = Mdl.FitInfo_; assert_equal (fieldnames (F), {'Solver'; 'LossFunction'; 'Lambda'; ... 'BetaTolerance'; 'GradientTolerance'; ... 'ObjectiveValue'; 'GradientMagnitude'; ... 'RelativeChangeInBeta'; 'FitTime'; ... 'History'}); assert_equal (F.Solver, 'LBFGS-fast'); assert_equal (F.LossFunction, 'hinge'); assert_equal (F.Lambda, 0.01); ***** test ## A cost matrix reaches the fit through the prior, as it does for the ## linear classifier load fisheriris X = meas(51:end,:); Y = species(51:end); Mdl = ClassificationKernel (X, Y, 'Cost', [0, 4; 1, 0]); assert_equal (Mdl.Cost, [0, 4; 1, 0]); assert_equal (Mdl.Prior, [0.5, 0.5]); ***** test ## A saved model reads back as the same model, the random basis included load fisheriris X = meas(51:end,:); Mdl = ClassificationKernel (X, species(51:end)); fname = tempname (); savemodel (Mdl, fname); Mnew = loadmodel (fname); delete (fname); assert_equal (class (Mnew), 'ClassificationKernel'); [~, s1] = predict (Mdl, X(1:5,:)); [~, s2] = predict (Mnew, X(1:5,:)); assert_equal (s1, s2); ***** test ## The labels come back in the type the response was given in, a ## character matrix included load fisheriris X = meas(51:end,:); Y = species(51:end); Mchar = ClassificationKernel (X, char (Y)); assert_equal (size (Mchar.ClassNames), [2, 10]); assert_equal (size (predict (Mchar, X(1:3,:))), [3, 10]); Mnum = ClassificationKernel (X, double (strcmp (Y, 'virginica'))); assert_equal (Mnum.ClassNames, [0; 1]); assert_equal (class (predict (Mnum, X(1:3,:))), 'double'); ***** test ## A character matrix response names one class per row, and every method ## answers the same through it as through the equivalent cell array load fisheriris X = meas(51:end,:); Yc = species(51:end); Ym = char (Yc); rand ('seed', 11); randn ('seed', 11); Mc = ClassificationKernel (X, Yc); rand ('seed', 11); randn ('seed', 11); Mm = ClassificationKernel (X, Ym); assert_equal (cellstr (Mm.ClassNames), Mc.ClassNames); assert_equal (cellstr (predict (Mm, X)), predict (Mc, X)); assert_equal (margin (Mm, X, Ym), margin (Mc, X, Yc)); assert_equal (edge (Mm, X, Ym), edge (Mc, X, Yc)); assert_equal (loss (Mm, X, Ym), loss (Mc, X, Yc)); ***** test ## 'ClassNames' selects a subset when it is given as a character matrix load fisheriris Mdl = ClassificationKernel (meas, char (species), 'ClassNames', ... char ({'versicolor', 'virginica'})); assert_equal (size (Mdl.ClassNames), [2, 10]); assert_equal (cellstr (Mdl.ClassNames), {'versicolor'; 'virginica'}); ***** test ## resume keeps no observation weights, because the model keeps no data: ## a weighted fit resumed without them continues against uniform ones, ## and passing them back restores the weighted fit. MATLAB behaves the ## same way, measured on R2024a. load fisheriris X = meas(51:end,:); Y = species(51:end); w = (1:100)'; rand ('seed', 4); randn ('seed', 4); Mdl = ClassificationKernel (X, Y, 'IterationLimit', 5, 'Weights', w); kept = resume (Mdl, X, Y, 'IterationLimit', 400, 'Weights', w); lost = resume (Mdl, X, Y, 'IterationLimit', 400); assert_equal (kept.FitInfo_.ObjectiveValue ... != lost.FitInfo_.ObjectiveValue, true); rand ('seed', 4); randn ('seed', 4); direct = ClassificationKernel (X, Y, 'IterationLimit', 405, 'Weights', w); assert_equal (kept.FitInfo_.ObjectiveValue, ... direct.FitInfo_.ObjectiveValue, 1e-3); ***** test ## A character matrix response survives a round trip through savemodel ## and loadmodel, the random basis with it load fisheriris X = meas(51:end,:); Ym = char (species(51:end)); Mdl = ClassificationKernel (X, Ym); fname = tempname (); savemodel (Mdl, fname); Mnew = loadmodel (fname); delete (fname); assert_equal (Mnew.ClassNames, Mdl.ClassNames); assert_equal (predict (Mnew, X(1:5,:)), predict (Mdl, X(1:5,:))); ***** test # A categorical 'ClassNames' is accepted load fisheriris y = categorical (species(51:150)); Mdl = ClassificationKernel (meas(51:150,:), y, 'ClassNames', ... categorical ({'versicolor'; 'virginica'})); assert_equal (class (Mdl.ClassNames), 'categorical'); assert_equal (numel (Mdl.ClassNames), 2); ***** test # An unused category of a categorical response is not a class load fisheriris y = categorical (species); Mdl = ClassificationKernel (meas(51:150,:), y(51:150)); assert_equal (cellstr (Mdl.ClassNames), {'versicolor'; 'virginica'}); ***** test # A row missing a predictor takes the class of largest prior X = [(1:10)', mod((1:10)', 3)]; y = [1; 1; 1; 1; 1; 1; 2; 2; 2; 2]; Mdl = ClassificationKernel (X, y); [label, score] = predict (Mdl, [NaN, 1]); assert_equal (label, 1); assert_equal (score, [NaN, NaN]); Mdl = ClassificationKernel (X, y, 'Prior', [0.3, 0.7]); assert_equal (predict (Mdl, [NaN, 1]), 2); ***** error ... ClassificationKernel (ones (5, 2)) ***** error ... ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Learner') ***** error ... ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Learner', ... 'tree') ***** error ... ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'NumExpansionDimensions', 0) ***** error ... ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'KernelScale', -1) ***** error ... ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Lambda', -1) ***** error ... ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'BoxConstraint', 0) ***** error ... ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Lambda', ... 0.1, 'BoxConstraint', 2) ***** error ... ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Learner', ... 'logistic', 'BoxConstraint', 2) ***** error ... ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'Standardize', 'yes') ***** error ... ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'IterationLimit', -5) ***** error ... ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Verbose', 2) ***** error ... ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Nonsense', 1) ***** error ... ClassificationKernel ({1, 2; 3, 4}, [1; 2]) ***** error ClassificationKernel ([], []) ***** error ... ClassificationKernel (ones (10, 2), [1; 2]) ***** error ... ClassificationKernel (ones (9, 2), [1; 1; 1; 2; 2; 2; 3; 3; 3]) ***** error ... ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Cost', ... ones (3)) ***** error ... predict (ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)]), ... ones (3, 5)) ***** error ... predict (ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)]), []) ***** error ... margin (ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)]), ... ones (3, 2)) ***** error ... loss (ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)]), ... ones (10, 2), [ones(5,1); 2*ones(5,1)], 'LossFun', 'mse') ***** error ... loss (ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)]), ... ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Bogus', 1) ***** error ... resume (ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)]), ... ones (10, 2)) ***** error ... resume (ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)]), ... ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'IterationLimit', 0) ***** error ... resume (ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)]), ... ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Nonsense', 1) ***** error ... resume (ClassificationKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)]), ... ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Weights', -1) ***** test load fisheriris Mdl = fitckernel (meas, strcmp (species, 'setosa')); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); T = {'identity', @(x) x; 'doublelogit', @(x) 1 ./ (1 + exp (-2 * x)); ... 'invlogit', @(x) log (x ./ (1 - x)); ... 'logit', @(x) 1 ./ (1 + exp (-x)); ... 'sign', @(x) sign (x); 'symmetric', @(x) 2 * x - 1; ... 'symmetriclogit', @(x) 2 ./ (1 + exp (-x)) - 1}; for i = 1:rows (T) Mdl.ScoreTransform = T{i,1}; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, T{i,2}(raw), 1e-12); assert_equal (l, label); endfor ## ismax marks the largest score of each observation, ties to the first. [~, k] = max (raw, [], 2); e = zeros (size (raw)); e(sub2ind (size (raw), (1:rows (raw))', k)) = 1; Mdl.ScoreTransform = 'ismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, e); Mdl.ScoreTransform = 'symmetricismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, 2 * e - 1); ***** test load fisheriris Mdl = fitckernel (meas, strcmp (species, 'setosa')); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); Mdl.ScoreTransform = @(x) x .^ 2; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, raw .^ 2, 1e-12); assert_equal (l, label); ***** shared Xc, Dc, yc c1 = repmat ([1; 2; 3], 20, 1); x2 = sin ((1:60)'); c3 = repmat ([10; 10; 20; 20], 15, 1); Xc = [c1, x2, c3]; Dc = [c1 == 1, c1 == 2, c1 == 3, x2, c3 == 10, c3 == 20]; yc = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 20) + 0.1 * cos ((1:60)') > 1; ***** test # MATLAB parity: the kernel expands the dummy coded predictors randn ('seed', 9); rand ('seed', 9); Mdl = ClassificationKernel (Xc, yc, 'CategoricalPredictors', [1, 3]); randn ('seed', 9); rand ('seed', 9); H = ClassificationKernel (Dc, yc); assert_equal (Mdl.ExpandedPredictorNames, {'x1 == 1', 'x1 == 2', ... 'x1 == 3', 'x2', 'x3 == 10', 'x3 == 20'}); assert_equal (Mdl.NumExpansionDimensions, 256); [~, s] = predict (Mdl, Xc(1:5,:)); [~, sh] = predict (H, Dc(1:5,:)); assert_equal (s, sh, 1e-12); ***** test # MATLAB parity: the coded columns are not standardized Mdl = ClassificationKernel (Xc, yc, 'CategoricalPredictors', [1, 3], ... 'Standardize', true); assert_equal (Mdl.Mu([1:3, 5:6]), zeros (1, 5)); assert_equal (Mdl.Sigma([1:3, 5:6]), ones (1, 5)); assert_equal (Mdl.Mu(4), mean (Xc(:,2)), 1e-12); ***** test # a level the training data did not hold is scored NaN Mdl = ClassificationKernel (Xc, yc, 'CategoricalPredictors', [1, 3]); [~, s] = predict (Mdl, [4, 0, 10; 2, 0, 20]); assert_equal (isnan (s(:,1))', [true, false]); ***** error ... ClassificationKernel (Xc, yc, 'CategoricalPredictors', 4) ***** error ... ClassificationKernel (Xc, yc, 'CategoricalPredictors', logical ([1, 0])) ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(51:150,1:2); y = categorical (species(51:150)); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitckernel (T, 'Species'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(51:150,1:2); y = categorical (species(51:150)); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitckernel (T, 'Species'); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(51:150,1:2); y = categorical (species(51:150)); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitckernel (T, 'Species'); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** test # the response is named or given beside the table load fisheriris X = meas(51:150,1:2); y = categorical (species(51:150)); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitckernel (T, 'Species', 'IterationLimit', 5); [~, a] = predict (resume (Mdl, X, y, 'IterationLimit', 20), X); [~, b] = predict (resume (Mdl, T(:,1:2), y, 'IterationLimit', 20), X); assert_equal (b, a); [~, b] = predict (resume (Mdl, T, 'Species', 'IterationLimit', 20), X); assert_equal (b, a); [~, b] = predict (resume (Mdl, T(:,[3, 2, 1]), 'Species'), X); [~, c] = predict (resume (Mdl, X, y), X); assert_equal (b, c); ***** error ... load fisheriris T = table (meas(51:150,1), meas(51:150,2), 'VariableNames', {'SL', 'SW'}); T.Species = categorical (species(51:150)); resume (fitckernel (T, 'Species'), T) ***** error ... load fisheriris T = table (meas(51:150,1), meas(51:150,2), 'VariableNames', {'SL', 'SW'}); T.Species = categorical (species(51:150)); resume (fitckernel (T, 'Species'), T, 'IterationLimit', 5) ***** error ... fitckernel ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', ... int8 ([1; 1; 1; 1])) ***** error ... fitckernel ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', true (4, 1)) ***** error X = [1, 2; 3, 4; 5, 6; 7, 8]; Y = [1; 1; 2; 2]; loss (fitckernel (X, Y), X, Y, 'Weights', int8 ([1; 1; 1; 1])) ***** error X = [1, 2; 3, 4; 5, 6; 7, 8]; Y = [1; 1; 2; 2]; resume (fitckernel (X, Y), X, Y, 'Weights', int8 ([1; 1; 1; 1])) ***** test ## Single weights compute as double load fisheriris X = meas(51:end,:); Y = species(51:end); w = 1 + (1:100)' / 7; rand ('seed', 1); randn ('seed', 1); A = fitckernel (X, Y, 'Weights', single (w)); rand ('seed', 1); randn ('seed', 1); B = fitckernel (X, Y, 'Weights', double (single (w))); assert_equal (nthargout (2, @predict, A, X), nthargout (2, @predict, B, X)); 69 tests, 69 passed, 0 known failure, 0 skipped [inst/Machine_Learning/RegressionGP.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/RegressionGP.m ***** demo ## Fit a Gaussian process to noisy observations of a smooth function and ## show the prediction interval widening away from the data. x = [0.1; 0.3; 0.4; 0.7; 0.9; 1.4; 1.6; 1.9]'; x = x(:); y = sin (3 * x) + 0.05 * cos (11 * x); Mdl = fitrgp (x, y); xq = linspace (-0.2, 2.2, 200)'; [yq, ~, yint] = predict (Mdl, xq); figure ('visible', 'off'); hold on; plot (xq, yint(:,1), 'r:'); plot (xq, yint(:,2), 'r:'); plot (xq, yq, 'b-'); plot (x, y, 'ko'); hold off; xlabel ('x'); ylabel ('y'); title ('Gaussian process regression with 95% prediction interval'); ***** test ## The model reports the surface MATLAB reports x = linspace (0, 1, 20)'; y = sin (2*pi*x) + 0.1 * cos (7*x); Mdl = RegressionGP (x, y); assert_equal (class (Mdl), 'RegressionGP'); assert_equal (Mdl.NumObservations, 20); assert_equal (Mdl.FitMethod, 'Exact'); assert_equal (Mdl.PredictMethod, 'Exact'); assert_equal (Mdl.BasisFunction, 'Constant'); assert_equal (Mdl.KernelFunction, 'SquaredExponential'); assert_equal (Mdl.ResponseName, 'Y'); assert_equal (Mdl.PredictorNames, {'x1'}); assert_equal (Mdl.ResponseTransform, 'none'); ***** test ## BinEdges is an empty cell, as it is for every learner that does no ## binning: a Gaussian process takes its predictors as they are x = linspace (0, 1, 20)'; Mdl = RegressionGP (x, sin (2*pi*x)); assert_equal (class (Mdl.BinEdges), 'cell'); assert_equal (Mdl.BinEdges, {}); ***** test ## The fitted covariance parameters and noise match R2024a x = linspace (0, 1, 20)'; y = sin (2*pi*x) + 0.1 * cos (7*x); Mdl = RegressionGP (x, y); assert_equal (Mdl.KernelInformation.KernelParameters, ... [0.386370514454926; 1.505132511329997], 1e-8); assert_equal (Mdl.Beta, -0.072781321631854, 1e-7); assert_equal (Mdl.Sigma, 0.006877618228324, 1e-7); assert_equal (Mdl.LogLikelihood, 47.574057509534278, 1e-4); ***** test ## 'lbfgs' finds the same optimum the dense solver does x = linspace (0, 1, 20)'; y = sin (2*pi*x) + 0.1 * cos (7*x); Mdl = RegressionGP (x, y, 'Optimizer', 'lbfgs'); ## Relative, and loose: the likelihood surface is flat here, so where the ## search stops is decided by the last bits of the arithmetic and moves by ## about 1e-6 between platforms. The likelihood is what pins this optimum, ## and the test below holds it to 1e-8. assert_equal (Mdl.KernelInformation.KernelParameters, ... [0.386370514454926; 1.505132511329997], -1e-4); assert_equal (Mdl.Beta, -0.072781321631854, -1e-4); ***** test ## The likelihood agrees far more tightly than the parameters do, because ## the surface is flat there: a 2e-7 move in the parameters buys 2e-10 of ## likelihood. Comparing the parameters alone understates the agreement. x = linspace (0, 1, 20)'; y = sin (2*pi*x) + 0.1 * cos (7*x); Mq = RegressionGP (x, y, 'Optimizer', 'quasinewton'); Ml = RegressionGP (x, y, 'Optimizer', 'lbfgs'); assert_equal (Ml.LogLikelihood, Mq.LogLikelihood, 1e-8); ***** test ## The optimizer that ran is recorded x = linspace (0, 1, 20)'; y = sin (2*pi*x) + 0.1 * cos (7*x); Mdl = RegressionGP (x, y, 'Optimizer', 'lbfgs'); assert_equal (Mdl.ModelParameters.Optimizer, 'lbfgs'); ***** test ## predict reproduces the R2024a values, and the standard deviation is ## that of a response, so it carries the noise x = linspace (0, 1, 20)'; y = sin (2*pi*x) + 0.1 * cos (7*x); Mdl = RegressionGP (x, y); xq = [0.05; 0.33; 0.5; 0.77; 0.95]; [yp, ysd, yint] = predict (Mdl, xq); assert_equal (yp, [0.404401855406521; 0.809355242891053; ... -0.093708552144171; -0.928420803239529; ... -0.217104024154071], 1e-7); assert_equal (ysd, [0.008117035802727; 0.007747238553279; ... 0.007727093294465; 0.007796728197045; ... 0.008117035802754], 1e-6); assert_equal (size (yint), [5, 2]); assert (all (yint(:,1) < yp)); assert (all (yint(:,2) > yp)); ***** test ## The interval is the normal quantile of the level times the standard ## deviation, so a looser level gives a narrower interval x = linspace (0, 1, 20)'; y = sin (2*pi*x) + 0.1 * cos (7*x); Mdl = RegressionGP (x, y); xq = [0.05; 0.33; 0.5]; [yp, ysd, yint] = predict (Mdl, xq); assert_equal (yint(:,2) - yp, norminv (0.975) * ysd, 1e-12); [~, ~, yint90] = predict (Mdl, xq, 'Alpha', 0.10); assert_equal (yint90(:,2) - yp, norminv (0.95) * ysd, 1e-12); assert (all (yint90(:,2) - yint90(:,1) < yint(:,2) - yint(:,1))); ***** test ## FitMethod 'none' keeps the documented initial values, estimates nothing ## and has no likelihood to report x = linspace (0, 1, 20)'; y = sin (2*pi*x) + 0.1 * cos (7*x); Mdl = RegressionGP (x, y, 'FitMethod', 'none'); assert_equal (Mdl.FitMethod, 'None'); assert_equal (Mdl.Sigma, std (y) / sqrt (2), 1e-14); assert_equal (Mdl.KernelInformation.KernelParameters, ... [mean(std (x)); std(y) / sqrt(2)], 1e-14); assert_equal (Mdl.Beta, 0); assert_equal (Mdl.LogLikelihood, []); ***** test ## The parameters of each covariance function are named as MATLAB names ## them, and there is one length scale per predictor for the ARD kernels X = [linspace(0, 1, 15)', cos(linspace(0, 3, 15))']; y = X(:,1) .^ 2 + 0.3 * X(:,2); M1 = RegressionGP (X, y, 'KernelFunction', 'squaredexponential'); assert_equal (M1.KernelInformation.KernelParameterNames, ... {'SigmaL'; 'SigmaF'}); M2 = RegressionGP (X, y, 'KernelFunction', 'rationalquadratic'); assert_equal (M2.KernelInformation.KernelParameterNames, ... {'SigmaL'; 'AlphaRQ'; 'SigmaF'}); M3 = RegressionGP (X, y, 'KernelFunction', 'ardmatern32'); assert_equal (M3.KernelInformation.KernelParameterNames, ... {'LengthScale1'; 'LengthScale2'; 'SigmaF'}); assert_equal (numel (M3.KernelInformation.KernelParameters), 3); ***** test ## The name of the covariance function is stored capitalized, as MATLAB ## stores it, whatever spelling the caller used x = linspace (0, 1, 12)'; y = cos (3*x); Mdl = RegressionGP (x, y, 'KernelFunction', 'ardmatern52'); assert_equal (Mdl.KernelFunction, 'ARDMatern52'); assert_equal (Mdl.KernelInformation.Name, 'ARDMatern52'); ***** test ## The explicit basis has one coefficient per term, and none has none X = [linspace(0, 1, 15)', cos(linspace(0, 3, 15))']; y = X(:,1) .^ 2 + 0.3 * X(:,2); assert_equal (numel (RegressionGP (X, y, 'BasisFunction', 'none').Beta), 0); assert_equal (numel (RegressionGP (X, y, ... 'BasisFunction', 'constant').Beta), 1); assert_equal (numel (RegressionGP (X, y, ... 'BasisFunction', 'linear').Beta), 3); assert_equal (numel (RegressionGP (X, y, ... 'BasisFunction', 'pureQuadratic').Beta), 5); ***** test ## Standardizing records the location and scale it used, and predict ## applies the same transformation X = [linspace(0, 10, 20)', linspace(-5, 5, 20)']; y = 0.3 * X(:,1) - 0.2 * X(:,2); Mdl = RegressionGP (X, y, 'Standardize', true); assert_equal (Mdl.PredictorLocation, mean (X, 1), 1e-14); assert_equal (Mdl.PredictorScale, std (X, 0, 1), 1e-14); assert_equal (predict (Mdl, X(1:3,:)), y(1:3), 1e-3); ***** test ## Without standardizing there is no location or scale to report x = linspace (0, 1, 12)'; Mdl = RegressionGP (x, cos (3*x)); assert_equal (Mdl.PredictorLocation, []); assert_equal (Mdl.PredictorScale, []); ***** test ## A held noise is not estimated x = linspace (0, 1, 15)'; y = cos (3*x) + 0.1 * sin (11*x); Mdl = RegressionGP (x, y, 'ConstantSigma', true, 'Sigma', 0.3); assert_equal (Mdl.Sigma, 0.3, 1e-14); ***** test ## The noise cannot go below its lower bound x = linspace (0, 1, 15)'; y = cos (3*x); Mdl = RegressionGP (x, y, 'SigmaLowerBound', 0.05); assert (Mdl.Sigma >= 0.05); ***** test ## The active set of an exactly fitted model is the whole training data x = linspace (0, 1, 15)'; Mdl = RegressionGP (x, cos (3*x)); assert_equal (Mdl.ActiveSetSize, 15); assert_equal (Mdl.ActiveSetVectors, x); assert_equal (Mdl.IsActiveSetVector, true (15, 1)); assert_equal (Mdl.ActiveSetMethod, 'Random'); ***** test ## resubPredict is predict on the training data x = linspace (0, 1, 15)'; y = cos (3*x) + 0.1 * sin (11*x); Mdl = RegressionGP (x, y); assert_equal (resubPredict (Mdl), predict (Mdl, x), 1e-14); ***** test ## The default loss is the mean squared error, and it is small for a model ## that interpolates its own training data closely x = linspace (0, 1, 20)'; y = sin (2*pi*x) + 0.1 * cos (7*x); Mdl = RegressionGP (x, y); assert_equal (loss (Mdl, x, y), mean ((y - predict (Mdl, x)) .^ 2), 1e-14); assert_equal (resubLoss (Mdl), loss (Mdl, x, y), 1e-14); assert (resubLoss (Mdl) < 1e-4); ***** test ## The other loss functions, and weights x = linspace (0, 1, 15)'; y = cos (3*x) + 0.1 * sin (11*x); Mdl = RegressionGP (x, y); r = y - predict (Mdl, x); assert_equal (loss (Mdl, x, y, 'LossFun', 'mae'), mean (abs (r)), 1e-14); w = linspace (1, 2, 15)'; assert_equal (loss (Mdl, x, y, 'Weights', w), ... sum (w .* r .^ 2) / sum (w), 1e-14); mae = @(a, b) mean (abs (a - b)); assert_equal (loss (Mdl, x, y, 'LossFun', mae), mean (abs (r)), 1e-14); ***** test ## The leave-one-out residuals and the effective parameter count match ## R2024a, and neither refits the model x = linspace (0, 1, 20)'; y = sin (2*pi*x) + 0.1 * cos (7*x); Mdl = RegressionGP (x, y); [loores, neff] = postFitStatistics (Mdl); assert_equal (size (loores), [20, 1]); assert_equal (loores(1:4), [0.006483807954955; -0.002405391043015; ... -0.000899188010473; 0.000975297024791], 1e-6); assert_equal (neff, 7.186830203018070, 1e-5); ***** test ## The leave-one-out residuals are larger than the fitted residuals, since ## each leaves out the observation it is about x = linspace (0, 1, 20)'; y = sin (2*pi*x) + 0.1 * cos (7*x); Mdl = RegressionGP (x, y); loores = postFitStatistics (Mdl); assert (all (abs (loores) >= abs (y - predict (Mdl, x)) - 1e-12)); ***** test ## compact keeps what predicts and drops the rest, and predicts the same x = linspace (0, 1, 15)'; y = cos (3*x) + 0.1 * sin (11*x); Mdl = RegressionGP (x, y); CMdl = compact (Mdl); assert_equal (class (CMdl), 'CompactRegressionGP'); assert_equal (predict (CMdl, x), predict (Mdl, x), 1e-14); [y1, s1] = predict (Mdl, x); [y2, s2] = predict (CMdl, x); assert_equal (s1, s2, 1e-14); ***** test ## crossval returns a partitioned model over the observations trained on x = linspace (0, 1, 20)'; y = cos (3*x) + 0.1 * sin (11*x); Mdl = RegressionGP (x, y); CVMdl = crossval (Mdl, 'KFold', 4); assert_equal (class (CVMdl), 'RegressionPartitionedModel'); assert_equal (CVMdl.KFold, 4); assert_equal (CVMdl.CrossValidatedModel, 'GP'); assert_equal (numel (CVMdl.Trained), 4); assert_equal (class (CVMdl.Trained{1}), 'CompactRegressionGP'); assert_equal (size (kfoldPredict (CVMdl)), [20, 1]); ***** test ## A model saved and loaded predicts what it predicted before x = linspace (0, 1, 15)'; y = cos (3*x) + 0.1 * sin (11*x); Mdl = RegressionGP (x, y); fname = tempname (); savemodel (Mdl, fname); Mdl2 = loadmodel (fname); delete (fname); assert_equal (class (Mdl2), 'RegressionGP'); assert_equal (Mdl2.NumObservations, Mdl.NumObservations); assert_equal (Mdl2.Beta, Mdl.Beta); assert_equal (Mdl2.Sigma, Mdl.Sigma); assert_equal (Mdl2.KernelInformation.KernelParameters, ... Mdl.KernelInformation.KernelParameters); assert_equal (Mdl2.LogLikelihood, Mdl.LogLikelihood); assert_equal (predict (Mdl2, x), predict (Mdl, x), 1e-14); ***** test ## A response transform is applied to the prediction and reported as text x = linspace (0, 1, 12)'; y = cos (3*x); Mdl = RegressionGP (x, y, 'ResponseTransform', 'exp'); assert_equal (Mdl.ResponseTransform, 'exp'); Mdl2 = RegressionGP (x, y); assert_equal (predict (Mdl, x), exp (predict (Mdl2, x)), 1e-12); ***** test ## A row with a missing response is dropped, and RowsUsed says which x = linspace (0, 1, 12)'; y = cos (3*x); y(4) = NaN; Mdl = RegressionGP (x, y); assert_equal (Mdl.NumObservations, 11); assert_equal (Mdl.RowsUsed, [true(3,1); false; true(8,1)]); ***** test ## With no missing value RowsUsed is empty, as it is for every learner x = linspace (0, 1, 12)'; Mdl = RegressionGP (x, cos (3*x)); assert_equal (Mdl.RowsUsed, []); ***** test ## Observation weights default to equal shares summing to one x = linspace (0, 1, 12)'; Mdl = RegressionGP (x, cos (3*x)); assert_equal (Mdl.W, ones (12, 1) / 12); ***** test ## A supplied covariance function is used, and reproduces the built-in one ## it imitates x = linspace (0, 1, 15)'; y = cos (3*x) + 0.1 * sin (11*x); kfcn = @(a, b, th) th(2)^2 * exp (-0.5 * ((a - b') / th(1)) .^ 2); M1 = RegressionGP (x, y, 'KernelFunction', kfcn, ... 'KernelParameters', [0.4; 1.2], 'FitMethod', 'none'); M2 = RegressionGP (x, y, 'KernelFunction', 'squaredexponential', ... 'KernelParameters', [0.4; 1.2], 'FitMethod', 'none'); assert_equal (predict (M1, x), predict (M2, x), 1e-12); ***** test # A row missing a predictor counts, but is left out of the fit X = [(1:10)', mod((1:10)', 3)]; X(1,1) = NaN; Mdl = RegressionGP (X, (1:10)'); assert_equal (Mdl.NumObservations, 10); assert_equal (Mdl.RowsUsed, []); assert_equal (Mdl.ActiveSetSize, 9); assert_equal (Mdl.IsActiveSetVector, [false; true(9, 1)]); assert_equal (predict (Mdl, [NaN, 1]), 6); yFit = resubPredict (Mdl); assert_equal (yFit(1), 6); ***** error RegressionGP (ones (5, 2)) ***** error ... RegressionGP (ones (5, 2), ones (4, 1)) ***** error ... RegressionGP ('a', ones (5, 1)) ***** error ... RegressionGP (ones (5, 2), 'a') ***** error ... RegressionGP (ones (5, 2), ones (5, 1), 'Standardize') ***** error ... RegressionGP (ones (5, 2), ones (5, 1), 'bogus', 1) ***** error ... RegressionGP (ones (5, 2), ones (5, 1), 'KernelFunction', 5) ***** error ... RegressionGP (ones (5, 2), ones (5, 1), 'KernelFunction', 'bogus') ***** error ... RegressionGP (ones (5, 2), ones (5, 1), 'KernelParameters', [-1, 2]) ***** error ... RegressionGP (ones (5, 2), ones (5, 1), 'BasisFunction', 5) ***** error ... RegressionGP (ones (5, 2), ones (5, 1), 'BasisFunction', 'bogus') ***** error ... RegressionGP (ones (5, 2), ones (5, 1), 'Sigma', -1) ***** error ... RegressionGP (ones (5, 2), ones (5, 1), 'ConstantSigma', 5) ***** error ... RegressionGP (ones (5, 2), ones (5, 1), 'SigmaLowerBound', 0) ***** error ... RegressionGP (ones (5, 2), ones (5, 1), 'FitMethod', 'fic') ***** error ... RegressionGP (ones (5, 2), ones (5, 1), 'FitMethod', 'bogus') ***** error ... RegressionGP (ones (5, 2), ones (5, 1), 'PredictMethod', 'bcd') ***** error ... RegressionGP (ones (5, 2), ones (5, 1), 'Optimizer', 'fmincon') ***** error ... RegressionGP (ones (5, 2), ones (5, 1), 'Optimizer', 'bogus') ***** error ... RegressionGP (ones (5, 2), ones (5, 1), 'Standardize', 5) ***** error ... RegressionGP (ones (5, 2), ones (5, 1), 'PredictorNames', {'a'}) ***** error ... RegressionGP (ones (5, 2), ones (5, 1), 'ResponseName', 5) ***** error ... predict (RegressionGP (ones (5, 2), ones (5, 1))) ***** error ... predict (RegressionGP (ones (5, 2), ones (5, 1)), []) ***** error ... predict (RegressionGP (ones (5, 2), ones (5, 1)), ones (3, 3)) ***** error ... predict (RegressionGP (ones (5, 2), ones (5, 1)), ones (3, 2), 'Alpha', 2) ***** error ... predict (RegressionGP (ones (5, 2), ones (5, 1)), ones (3, 2), 'bogus', 1) ***** error ... loss (RegressionGP (ones (5, 2), ones (5, 1)), ones (3, 2)) ***** error ... loss (RegressionGP (ones (5, 2), ones (5, 1)), ones (3, 2), ... ones (3, 1), 'LossFun', 'bogus') ***** error ... loss (RegressionGP (ones (5, 2), ones (5, 1)), ones (3, 2), ... ones (3, 1), 'bogus', 1) ***** test load fisheriris Mdl = fitrgp (meas(:,1:3), meas(:,4)); assert_equal (isempty (Mdl.ActiveSetHistory), true); assert_equal (isempty (Mdl.BCDInformation), true); fname = tempname (); unwind_protect savemodel (Mdl, fname); M2 = loadmodel (fname); assert_equal (isempty (M2.ActiveSetHistory), true); assert_equal (isempty (M2.BCDInformation), true); unwind_protect_cleanup if (exist (fname, 'file')) delete (fname); endif end_unwind_protect ***** error ... crossval (RegressionGP (ones (10, 2), ones (10, 1)), 'KFold', 1) ***** error ... crossval (RegressionGP (ones (10, 2), ones (10, 1)), 'Holdout', 2) ***** error ... crossval (RegressionGP (ones (10, 2), ones (10, 1)), 'Leaveout', 1) ***** error ... crossval (RegressionGP (ones (10, 2), ones (10, 1)), 'CVPartition', 1) ***** error ... crossval (RegressionGP (ones (10, 2), ones (10, 1)), 'KFold', 3, ... 'Holdout', 0.2) ***** error ... crossval (RegressionGP (ones (10, 2), ones (10, 1)), 'bogus', 1) ***** test load fisheriris Mdl = fitrgp (meas(:,1:3), meas(:,4)); assert_equal (isempty (Mdl.HyperparameterOptimizationResults), true); ***** test load fisheriris Mdl = fitrgp (meas(:,2:4), meas(:,1)); assert_equal (fieldnames (Mdl.ModelParameters)', {'KernelFunction', ... 'KernelParameters', 'BasisFunction', 'Beta', 'Sigma', 'FitMethod', ... 'PredictMethod', 'ActiveSetSize', 'ActiveSetMethod', 'Standardize', ... 'Optimizer', 'ConstantSigma', 'SigmaLowerBound', 'Version', 'Method', ... 'Type'}); ***** test load fisheriris MP = fitrgp (meas(:,2:4), meas(:,1)).ModelParameters; assert_equal (MP.Beta, 0); assert_equal (isempty (MP.Sigma), true); assert_equal (isempty (MP.KernelParameters), true); assert_equal (MP.ActiveSetSize, 150); assert_equal (MP.ActiveSetMethod, 'Random'); ***** test load fisheriris Mdl = fitrgp (meas(:,2:4), meas(:,1), 'Beta', 3, 'Sigma', 0.7, ... 'KernelParameters', [2; 0.5]); assert_equal (Mdl.ModelParameters.Beta, 3); assert_equal (Mdl.ModelParameters.Sigma, 0.7); assert_equal (Mdl.ModelParameters.KernelParameters, [2; 0.5]); assert_equal (abs (Mdl.Beta - 3) > 1, true); assert_equal (abs (Mdl.Sigma - 0.7) > 0.1, true); ***** test load fisheriris MP = fitrgp (meas(:,2:4), meas(:,1), ... 'BasisFunction', 'linear').ModelParameters; assert_equal (MP.Beta, zeros (4, 1)); ***** test load fisheriris MP = fitrgp (meas(:,2:4), meas(:,1)).ModelParameters; assert_equal (MP.SigmaLowerBound > 0, true); assert_equal (MP.Version, 1); assert_equal (MP.Method, 'GP'); assert_equal (MP.Type, 'regression'); ***** test load fisheriris Mdl = fitrgp (meas(:,2:4), meas(:,1)); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); T = {'identity', @(x) x; 'exp', @(x) exp (x); 'log', @(x) log (x)}; for i = 1:rows (T) Mdl.ResponseTransform = T{i,1}; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, T{i,2}(raw), 1e-12); endfor ***** test load fisheriris Mdl = fitrgp (meas(:,2:4), meas(:,1)); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); Mdl.ResponseTransform = @(x) x .^ 2; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, raw .^ 2, 1e-12); ***** shared Xc, Dc, yc c1 = repmat ([1; 2; 3], 20, 1); x2 = sin ((1:60)'); c3 = repmat ([10; 10; 20; 20], 15, 1); Xc = [c1, x2, c3]; Dc = [c1 == 1, c1 == 2, c1 == 3, x2, c3 == 10, c3 == 20]; yc = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 20) + 0.1 * cos ((1:60)'); ***** test # MATLAB parity: a categorical predictor is dummy coded in its place Mdl = RegressionGP (Xc, yc, 'CategoricalPredictors', [1, 3]); H = RegressionGP (Dc, yc); assert_equal (Mdl.ExpandedPredictorNames, {'x1 == 1', 'x1 == 2', ... 'x1 == 3', 'x2', 'x3 == 10', 'x3 == 20'}); assert_equal (size (Mdl.X), [60, 3]); assert_equal (predict (Mdl, Xc(1:5,:)), predict (H, Dc(1:5,:)), 1e-8); ***** test # MATLAB parity: an ARD kernel has a length scale per coded column Mdl = RegressionGP (Xc, yc, 'CategoricalPredictors', [1, 3], ... 'KernelFunction', 'ardsquaredexponential', ... 'Standardize', true); assert_equal (numel (Mdl.KernelInformation.KernelParameters), 7); assert_equal (Mdl.PredictorLocation([1:3, 5:6]), zeros (1, 5)); assert_equal (Mdl.PredictorScale([1:3, 5:6]), ones (1, 5)); ***** test # a level the training data did not hold predicts the lower median Mdl = RegressionGP (Xc, yc, 'CategoricalPredictors', [1, 3]); yhat = predict (Mdl, [4, 0, 10; 2, 0, 20]); ys = sort (yc); assert_equal (yhat(1), ys(ceil (numel (ys) / 2))); assert_equal (isnan (yhat(2)), false); ***** test # cross-validation folds keep the categorical predictors Mdl = RegressionGP (Xc, yc, 'CategoricalPredictors', [1, 3]); CV = crossval (Mdl, 'KFold', 3); assert_equal (CV.Trained{1}.CategoricalPredictors, [1, 3]); ***** error ... RegressionGP (Xc, yc, 'CategoricalPredictors', 4) ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,2:3); y = meas(:,1); T = table (X(:,1), X(:,2), 'VariableNames', {'SW', 'PL'}); T.SL = y; Mdl = fitrgp (T, 'SL'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'SL'), a); assert_equal (loss (Mdl, T), a); ***** error ... RegressionGP ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', 'Weights', ... int8 ([1; 1; 1; 1])) ***** error ... RegressionGP ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', 'Weights', true (4, 1)) ***** error X = [1, 2; 3, 4; 5, 6; 7, 8]; y = (1:4)'; loss (RegressionGP (X, y), X, y, 'Weights', int8 ([1; 1; 1; 1])) ***** test ## Single weights are stored single, summing to one load fisheriris X = meas(:,2:4); y = meas(:,1); w = 1 + (1:150)' / 7; Mdl = RegressionGP (X, y, 'Weights', single (w)); assert_equal (class (Mdl.W), 'single'); assert_equal (sum (double (Mdl.W)), 1, 1e-6); 86 tests, 86 passed, 0 known failure, 0 skipped [inst/Machine_Learning/CompactRegressionTree.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/CompactRegressionTree.m ***** test # MATLAB parity: the surface a compact regression tree reports load carsmall X = [Weight, Cylinders, Horsepower]; CMdl = compact (RegressionTree (X, MPG)); assert_equal (class (CMdl), 'CompactRegressionTree'); assert_equal (numel (properties (CMdl)), 28); assert_equal (CMdl.NumNodes, 37); assert_equal (CMdl.ResponseName, 'Y'); assert_equal (CMdl.PredictorNames, {'x1', 'x2', 'x3'}); assert_equal (CMdl.ResponseTransform, 'none'); assert_equal (CMdl.CategoricalPredictors, []); ***** test # The compact tree carries the node table the model it came from has load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG); CMdl = compact (Mdl); assert_equal (CMdl.Children, Mdl.Children); assert_equal (CMdl.Parent, Mdl.Parent); assert_equal (CMdl.NodeSize, Mdl.NodeSize); assert_equal (CMdl.NodeMean, Mdl.NodeMean, 1e-15); assert_equal (CMdl.NodeError, Mdl.NodeError, 1e-15); assert_equal (CMdl.NodeProbability, Mdl.NodeProbability, 1e-15); assert_equal (CMdl.NodeRisk, Mdl.NodeRisk, 1e-15); assert_equal (CMdl.PruneList, Mdl.PruneList); assert_equal (CMdl.PruneAlpha, Mdl.PruneAlpha, 1e-12); assert_equal (CMdl.CutPredictor, Mdl.CutPredictor); assert_equal (CMdl.CutType, Mdl.CutType); ***** test # MATLAB parity: what a tree with no categories and no surrogates holds load carsmall CMdl = compact (RegressionTree ([Weight, Cylinders, Horsepower], MPG)); assert_equal (size (CMdl.CutCategories), [37, 2]); assert_equal (size (CMdl.CategoricalSplit), [0, 0]); assert_equal (size (CMdl.SurrogateCutPredictor), [0, 1]); assert_equal (size (CMdl.SurrogateCutPoint), [0, 0]); ***** test # MATLAB parity: predict answers exactly as the full model does load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG); CMdl = compact (Mdl); [y1, n1] = predict (Mdl, X); [y2, n2] = predict (CMdl, X); assert_equal ({y1, n1}, {y2, n2}); assert_equal (predict (CMdl, X([1, 20, 60], :))', ... [17.25, 12.3333333333333, 29.1], 1e-12); ***** test # MATLAB parity: loss, importance and the node ranges of a compact tree load carsmall X = [Weight, Cylinders, Horsepower]; CMdl = compact (RegressionTree (X, MPG)); assert_equal (loss (CMdl, X, MPG), 5.5828069902791, 1e-12); assert_equal (predictorImportance (CMdl), [2.5904, 0.1006, 0.5499], 1e-4); r = nodeVariableRange (CMdl, 4); assert_equal (r.x1, [-Inf, 3085.5], 1e-12); assert_equal (r.x3, [-Inf, 89], 1e-12); assert_equal (fieldnames (nodeVariableRange (CMdl, 1)), cell (0, 1)); ***** test # MATLAB parity: the text form of a compact tree load carsmall X = [Weight, Cylinders, Horsepower]; CMdl = compact (RegressionTree (X, MPG, 'MinLeafSize', 15)); lines = strsplit (strtrim (evalc ('view (CMdl)')), "\n"); assert_equal (numel (lines), 10); assert_equal (lines{1}, 'Decision tree for regression'); assert_equal (lines{2}, ... '1 if x1<3085.5 then node 2 elseif x1>=3085.5 then node 3 else 23.7181'); assert_equal (lines{6}, '5 fit = 24.0882'); ***** test # A node that holds rows back is discounted on the compact tree too load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG, 'MinLeafSize', 15); assert_equal (predictorImportance (compact (Mdl)), ... predictorImportance (Mdl), 1e-15); assert_equal (predictorImportance (compact (Mdl)), ... [11.253155105041, 0, 1.49831354224175], 1e-12); ***** test # The response transform travels with the compact model load carsmall X = [Weight, Cylinders, Horsepower]; CMdl = compact (RegressionTree (X, MPG, 'ResponseTransform', 'exp')); assert_equal (CMdl.ResponseTransform, 'exp'); assert_equal (predict (CMdl, X(1, :)), exp (17.25), -1e-12); CMdl.ResponseTransform = @(y) 2 * y; assert_equal (predict (CMdl, X(1, :)), 34.5, 1e-12); ***** test # A compact model saved and loaded answers exactly as it did load carsmall X = [Weight, Cylinders, Horsepower]; CMdl = compact (RegressionTree (X, MPG)); fname = tempname (); unwind_protect savemodel (CMdl, fname); New = loadmodel (fname); assert_equal (class (New), 'CompactRegressionTree'); assert_equal (New.NumNodes, CMdl.NumNodes); assert_equal (New.NodeRisk, CMdl.NodeRisk, 1e-15); assert_equal (New.CutPredictor, CMdl.CutPredictor); assert_equal (predict (New, X), predict (CMdl, X)); assert_equal (predictorImportance (New), ... predictorImportance (CMdl), 1e-15); unwind_protect_cleanup delete (fname); end_unwind_protect ***** error CompactRegressionTree () ***** error CompactRegressionTree (5) ***** error predict (compact (RegressionTree (ones (4, 2), (1:4)'))) ***** error predict (compact (RegressionTree (ones (4, 2), (1:4)')), []) ***** error predict (compact (RegressionTree (ones (4, 2), (1:4)')), 'a') ***** error predict (compact (RegressionTree (ones (4, 2), (1:4)')), ones (2, 5)) ***** error loss (compact (RegressionTree (ones (4, 2), (1:4)')), ones (4, 2)) ***** error loss (compact (RegressionTree (ones (4, 2), (1:4)')), ones (4, 2), ... (1:4)', 'LossFun', 'mad') ***** error loss (compact (RegressionTree (ones (4, 2), (1:4)')), ones (4, 2), ... (1:4)', 'Weights', [1, 2]) ***** error ... loss (compact (RegressionTree (ones (4, 2), (1:4)')), ones (4, 2), ... (1:4)', 'Bogus', 1) ***** error nodeVariableRange (compact (RegressionTree (ones (4, 2), (1:4)')), 999) ***** error savemodel (compact (RegressionTree (ones (4, 2), (1:4)'))) ***** error savemodel (compact (RegressionTree (ones (4, 2), (1:4)')), 5) ***** error CMdl = compact (RegressionTree (ones (4, 2), (1:4)')); CMdl.ResponseTransform = 'bogus'; ***** test # a compact tree keeps and uses the level sets of its cuts k = (0:99)'; c = mod (k, 5) + 1; means = [3, 1, 4, 1.5, 5]; y = means(c)' + 0.1 * sin (k); Full = fitrtree (c, y, 'CategoricalPredictors', 1, 'MaxNumSplits', 2); Mdl = compact (Full); assert_equal (Mdl.CutCategories, Full.CutCategories); assert_equal (predict (Mdl, [1; 2; 6]), predict (Full, [1; 2; 6])); assert_equal (nodeVariableRange (Mdl, 3), struct ('x1', [1, 3, 5])); fname = [tempname(), '.mdl']; savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (predict (M2, [1; 2; 6]), predict (Mdl, [1; 2; 6])); ***** shared crtT, crtM load fisheriris crtT = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); crtT.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); crtM = compact (fitrtree (crtT, 'SL')); ***** test # the levels a predictor was coded through travel with the model assert_equal (numel (crtM.PredictorLevels), 4); assert_equal (crtM.PredictorLevels{4}, {'narrow', 'wide'}); ***** test # predict takes a table, read by name and not by position a = predict (crtM, crtT); assert_equal (numel (a), 150); assert_equal (predict (crtM, crtT(:, [5, 4, 3, 2, 1])), a); ***** test # a matrix is still taken load fisheriris CMdl = compact (fitrtree (meas(:,2:4), meas(:,1))); assert_equal (numel (predict (CMdl, meas(:,2:4))), 150); ***** error ... predict (crtM, crtT(:, [1, 3, 4, 5])) ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,2:3); y = meas(:,1); T = table (X(:,1), X(:,2), 'VariableNames', {'SW', 'PL'}); T.SL = y; Mdl = compact (fitrtree (T, 'SL')); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'SL'), a); assert_equal (loss (Mdl, T), a); ***** error ... loss (compact (fitrtree ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)')), ones (4, ... 2), (1:4)', ... 'Weights', int8 ([1; 1; 1; 1])) 30 tests, 30 passed, 0 known failure, 0 skipped [inst/Machine_Learning/ClassificationNeuralNetwork.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/ClassificationNeuralNetwork.m ***** test # A categorical 'ClassNames' keeps only the classes it names load fisheriris Mdl = ClassificationNeuralNetwork (meas, categorical (species), ... 'ClassNames', categorical ({'versicolor'; 'virginica'})); assert_equal (Mdl.NumObservations, 100); assert_equal (class (Mdl.ClassNames), 'categorical'); ***** test load fisheriris Mdl = fitcnet (meas, species, "IterationLimit", 50, "Solver", "lbfgs"); assert_equal (Mdl.Solver, "LBFGS"); assert_equal (columns (Mdl.TrainingHistory), 7); assert_equal (Mdl.TrainingHistory.Properties.VariableNames, ... {"Iteration", "TrainingLoss", "Gradient", "Step", ... "Time", "ValidationLoss", "ValidationChecks"}); ***** test load fisheriris Mdl = fitcnet (meas, species, "IterationLimit", 50, "Solver", "lbfgs"); ci = Mdl.ConvergenceInfo; assert_equal (isfield (ci, "Gradient"), true); assert_equal (isfield (ci, "Step"), true); assert_equal (isfield (ci, "ConvergenceCriterion"), true); assert_equal (isfield (ci, "Accuracy"), false); ***** test load fisheriris Mdl = fitcnet (meas, species, "Solver", "sgd", "IterationLimit", 20); assert_equal (Mdl.Solver, "Gradient Descent"); assert_equal (isfield (Mdl.ConvergenceInfo, "Accuracy"), true); assert_equal (columns (Mdl.TrainingHistory), 6); ***** test load fisheriris Mdl = fitcnet (meas, species, "IterationLimit", 20); assert_equal (Mdl.Solver, "LBFGS"); assert_equal (isfield (Mdl.ConvergenceInfo, "Accuracy"), false); assert_equal (fieldnames (Mdl.ConvergenceInfo), ... {"Iterations"; "TrainingLoss"; "Gradient"; "Step"; ... "Time"; "ValidationLoss"; "ValidationChecks"; ... "ConvergenceCriterion"; "History"}); assert_equal (Mdl.TrainingHistory.Properties.VariableNames, ... {"Iteration", "TrainingLoss", "Gradient", "Step", ... "Time", "ValidationLoss", "ValidationChecks"}); assert_equal (Mdl.ConvergenceInfo.Iterations, rows (Mdl.TrainingHistory)); ***** test load fisheriris rand ("state", 3); randn ("state", 3); Ms = fitcnet (meas, species, "IterationLimit", 200, "Solver", "sgd"); rand ("state", 3); randn ("state", 3); Ml = fitcnet (meas, species, "IterationLimit", 200, "Solver", "lbfgs"); ls = Ms.ConvergenceInfo.TrainingLoss(end); ll = Ml.ConvergenceInfo.TrainingLoss(end); assert_equal (ll < ls, true); assert_equal (height (Ml.TrainingHistory) < height (Ms.TrainingHistory), ... true); ***** test load fisheriris Mdl = fitcnet (meas, species, "IterationLimit", 30, "Solver", "lbfgs"); fname = tempname (); savemodel (Mdl, fname); Mdl2 = loadmodel (fname); delete (fname); assert_equal (table2cell (Mdl2.TrainingHistory), ... table2cell (Mdl.TrainingHistory)); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcnet (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcnet (Xch, Ycell); assert_equal (size (Mc.ClassNames), [2, 10]); assert_equal (cellstr (Mc.ClassNames), Ms.ClassNames); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcnet (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcnet (Xch, Ycell); pch = predict (Mc, Xch); assert_equal (columns (pch), 10); assert_equal (cellstr (pch), predict (Ms, Xch)); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcnet (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcnet (Xch, Ycell); assert_equal (loss (Mc, Xch, Ych), loss (Ms, Xch, Ycell), 1e-12); assert_equal (margin (Mc, Xch, Ych), margin (Ms, Xch, Ycell), 1e-12); assert_equal (edge (Mc, Xch, Ych), edge (Ms, Xch, Ycell), 1e-12); ***** test Xpad = [1 2; 3 4; 1.1 2.1; 3.1 4.1; 1.2 2.2; 3.2 4.2]; Ypad = char ({"ab", "abcd", "ab", "abcd", "ab", "abcd"}); rand ("state", 1); randn ("state", 1); Mp = fitcnet (Xpad, Ypad); assert_equal (size (Mp.ClassNames), [2, 4]); assert_equal (Mp.ClassNames(1,:), "ab "); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); Xmiss = Xch; Xmiss(3,2) = NaN; rand ("state", 1); randn ("state", 1); Md = fitcnet (Xmiss, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcnet (Xmiss, Ycell); assert_equal (size (Md.ClassNames), [2, 10]); assert_equal (cellstr (Md.ClassNames), Ms.ClassNames); ***** test load fisheriris rand ("state", 1); randn ("state", 1); Mf = fitcnet (meas, char (species), ... "ClassNames", char ({"versicolor", "virginica"})); assert_equal (rows (Mf.ClassNames), 2); assert_equal (cellstr (Mf.ClassNames), {"versicolor"; "virginica"}); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcnet (Xch, Ych); fname = tempname (); savemodel (Mc, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.ClassNames, Mc.ClassNames); assert_equal (predict (M2, Xch), predict (Mc, Xch)); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcnet (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcnet (Xch, Ycell); rand ("state", 2); cvc = crossval (Mc, "KFold", 3); rand ("state", 2); cvs = crossval (Ms, "KFold", 3); assert_equal (cellstr (kfoldPredict (cvc)), kfoldPredict (cvs)); ***** test # A row missing a predictor takes the class of largest prior X = [(1:10)', mod((1:10)', 3)]; y = [1; 1; 1; 1; 1; 1; 2; 2; 2; 2]; Mdl = ClassificationNeuralNetwork (X, y); [label, score] = predict (Mdl, [NaN, 1]); assert_equal (label, 1); assert_equal (score, [NaN, NaN]); Mdl = ClassificationNeuralNetwork (X, y, 'Prior', [0.3, 0.7]); assert_equal (predict (Mdl, [NaN, 1]), 2); ***** error ... fitcnet (ones (5, 2), [1; 1; 2; 2; 2], "Solver", "sgd", ... "GradientTolerance", 1e-8) ***** error ... fitcnet (ones (5, 2), [1; 1; 2; 2; 2], "Solver", "sgd", "LossTolerance", 1) ***** error ... fitcnet (ones (5, 2), [1; 1; 2; 2; 2], "Solver", "sgd", ... "StepTolerance", 1e-8) ***** error ... fitcnet (ones (5, 2), [1; 1; 2; 2; 2], "Solver", "lbfgs", "LearningRate", 0.1) ***** error ... fitcnet (ones (5, 2), [1; 1; 2; 2; 2], "Solver", "bogus") ***** error ... fitcnet (ones (5, 2), [1; 1; 2; 2; 2], "Solver", "lbfgs", "GradientTolerance", -1) ***** error ... fitcnet (ones (5, 2), [1; 1; 2; 2; 2], "Solver", "lbfgs", "StepTolerance", -1) ***** error ... fitcnet (ones (5, 2), [1; 1; 2; 2; 2], "Solver", "lbfgs", "LossTolerance", NaN) ***** error ... ClassificationNeuralNetwork () ***** error ... ClassificationNeuralNetwork (ones (10,2)) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (5,1)) ***** error ... ClassificationNeuralNetwork (ones (5,3), ones (5,1), 'standardize', 'a') ***** error ... ClassificationNeuralNetwork (ones (5,2), ones (5,1), 'PredictorNames', ['A']) ***** error ... ClassificationNeuralNetwork (ones (5,2), ones (5,1), 'PredictorNames', 'A') ***** error ... ClassificationNeuralNetwork (ones (5,2), ones (5,1), 'PredictorNames', {'A', 'B', 'C'}) ***** error ... ClassificationNeuralNetwork (ones (5,2), ones (5,1), 'ResponseName', {'Y'}) ***** error ... ClassificationNeuralNetwork (ones (5,2), ones (5,1), 'ResponseName', 1) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'ClassNames', @(x)x) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'ClassNames', {1}) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'ClassNames', [1, 2]) ***** error ... ClassificationNeuralNetwork (ones (5,2), ['a';'b';'a';'a';'b'], 'ClassNames', ['a';'c']) ***** error ... ClassificationNeuralNetwork (ones (5,2), {'a';'b';'a';'a';'b'}, 'ClassNames', {'a','c'}) ***** error ... ClassificationNeuralNetwork (ones (10,2), logical (ones (10,1)), 'ClassNames', [true, false]) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'LayerSizes', -1) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'LayerSizes', 0.5) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'LayerSizes', [1,-2]) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'LayerSizes', [10,20,30.5]) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'LearningRate', -0.1) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'LearningRate', [0.1, 0.01]) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'LearningRate', 'a') ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'Activations', 123) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'Activations', 'unsupported_type') ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'LayerSizes', [10, 5], ... 'Activations', {'sigmoid', 'unsupported_type'}) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'Activations', {'sigmoid', 'relu', 'softmax'}) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'OutputLayerActivation', 123) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'OutputLayerActivation', 'unsupported_type') ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'IterationLimit', -1) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'IterationLimit', 0.5) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'IterationLimit', [1,2]) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'ScoreTransform', [1,2]) ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'ScoreTransform', 'unsupported_type') ***** error ... ClassificationNeuralNetwork (ones (10,2), ones (10,1), 'some', 'some') ***** error ... ClassificationNeuralNetwork ([1;2;3;'a';4], ones (5,1)) ***** error ... ClassificationNeuralNetwork ([1;2;3;Inf;4], ones (5,1)) ***** shared x, y, objST, Mdl load fisheriris x = meas; y = grp2idx (species); Mdl = fitcnet (x, y, 'IterationLimit', 100); ***** error ... Mdl.ScoreTransform = 'a'; ***** error ... predict (Mdl) ***** error ... predict (Mdl, []) ***** error ... predict (Mdl, 1) ***** test status = warning; warning ('off'); rand ('seed', 23); CVMdl = crossval (Mdl, 'KFold', 5); warning (status); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (CVMdl.KFold == 5, true) assert_equal (class (CVMdl.Trained{1}), "CompactClassificationNeuralNetwork") assert_equal (CVMdl.CrossValidatedModel, "NeuralNetwork") ***** test status = warning; warning ('off'); rand ('seed', 23); CVMdl = crossval (Mdl, 'HoldOut', 0.2); warning (status); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (class (CVMdl.Trained{1}), "CompactClassificationNeuralNetwork") assert_equal (CVMdl.CrossValidatedModel, "NeuralNetwork") ***** error ... crossval (Mdl, 'KFold') ***** error ... crossval (Mdl, 'KFold', 5, 'leaveout', 'on') ***** error ... crossval (Mdl, 'KFold', 'a') ***** error ... crossval (Mdl, 'KFold', 1) ***** error ... crossval (Mdl, 'KFold', -1) ***** error ... crossval (Mdl, 'KFold', 11.5) ***** error ... crossval (Mdl, 'KFold', [1,2]) ***** error ... crossval (Mdl, 'Holdout', 'a') ***** error ... crossval (Mdl, 'Holdout', 11.5) ***** error ... crossval (Mdl, 'Holdout', -1) ***** error ... crossval (Mdl, 'Holdout', 0) ***** error ... crossval (Mdl, 'Holdout', 1) ***** error ... crossval (Mdl, 'Leaveout', 1) ***** error ... crossval (Mdl, 'CVPartition', 1) ***** error ... crossval (Mdl, 'CVPartition', 'a') ***** error ... crossval (Mdl, 'some', 'some') ***** test Mdl = fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], ... 'LayerSizes', [3, 2], 'IterationLimit', 20); fname = tempname (); savemodel (Mdl, fname); Mdl2 = loadmodel (fname); delete (fname); assert_equal (Mdl2.LayerWeights, Mdl.LayerWeights); assert_equal (Mdl2.LayerBiases, Mdl.LayerBiases); ***** test Mdl = fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], ... 'IterationLimit', 20, 'Prior', [0.25, 0.75]); Mdl.Cost = [0, 3; 5, 0]; fname = tempname (); savemodel (Mdl, fname); Mdl2 = loadmodel (fname); delete (fname); assert_equal (Mdl2.Cost, [0, 3; 5, 0]); assert_equal (Mdl2.Prior, [0.25, 0.75]); assert_equal (Mdl2.W, Mdl.W); assert_equal (Mdl2.ExpandedPredictorNames, Mdl.ExpandedPredictorNames); assert_equal (Mdl2.CategoricalPredictors, Mdl.CategoricalPredictors); ***** test Mdl = fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], ... 'Solver', 'sgd', 'IterationLimit', 25); fname = tempname (); savemodel (Mdl, fname); Mdl2 = loadmodel (fname); delete (fname); assert_equal (istable (Mdl2.TrainingHistory), true); assert_equal (height (Mdl2.TrainingHistory), 25); assert_equal (table2cell (Mdl2.TrainingHistory), ... table2cell (Mdl.TrainingHistory)); ***** test load fisheriris Mdl = fitcnet (meas, species, 'IterationLimit', 20); fname = tempname (); savemodel (Mdl, fname); Mdl2 = loadmodel (fname); delete (fname); [label, score] = predict (Mdl, meas); [label2, score2] = predict (Mdl2, meas); assert_equal (label2, label); assert_equal (score2, score); ***** test Mdl = fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], 'IterationLimit', 20); Mdl.ScoreTransform = 'symmetric'; fname = tempname (); savemodel (Mdl, fname); Mdl2 = loadmodel (fname); delete (fname); assert_equal (Mdl2.ScoreTransform, 'symmetric'); [~, s1] = predict (Mdl2, [1, 2; 4, 5]); [~, s2] = predict (Mdl, [1, 2; 4, 5]); assert_equal (s1, s2); ***** error ... savemodel (ClassificationNeuralNetwork ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])) ***** error ... savemodel (ClassificationNeuralNetwork ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), 1) ***** error ... savemodel (ClassificationNeuralNetwork ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), ['ab'; 'cd']) ***** test rand ('seed', 42); randn ('seed', 42); X = [randn(40, 2) * 0.3 + 3; randn(40, 2) * 0.3 - 3]; Y = [ones(40, 1); 2 * ones(40, 1)]; Mdl = fitcnet (X, Y, 'LayerSizes', [8, 8], 'IterationLimit', 400); [label, score] = predict (Mdl, [3, 3; -3, -3]); assert_equal (label, [1; 2]); assert_equal (all (abs (sum (score, 2) - 1) < 0.1), true); assert_equal (max (score(1,:)) > 0.8, true); assert_equal (max (score(2,:)) > 0.8, true); ***** test Mdl = fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]); assert_equal (Mdl.Activations, 'relu'); assert_equal (Mdl.OutputLayerActivation, 'softmax'); ***** test rand ('seed', 42); randn ('seed', 42); X = [randn(30, 2) * 0.4 + 2; randn(30, 2) * 0.4 - 2]; Y = [ones(30, 1); 2 * ones(30, 1)]; Mdl = fitcnet (X, Y, 'Solver', 'sgd', 'IterationLimit', 100); loss = Mdl.ConvergenceInfo.History.TrainingLoss; acc = Mdl.ConvergenceInfo.History.TrainingAccuracy; assert_equal (numel (loss), 100); assert_equal (numel (acc), 100); assert_equal (any (loss != 0), true); assert_equal (loss(end) < loss(1), true); ## ConvergenceInfo itself reports where the fit ended. assert_equal (Mdl.ConvergenceInfo.TrainingLoss, loss(end)); assert_equal (Mdl.ConvergenceInfo.Accuracy, acc(end)); assert_equal (mean (predict (Mdl, X) == Y) > 0.95, true); ***** test rand ('seed', 7); randn ('seed', 7); X = [randn(30, 2) * 0.3 + 3; randn(30, 2) * 0.3 - 3]; Y = [ones(30, 1); 2 * ones(30, 1)]; names = {'linear', 'sigmoid', 'relu', 'tanh', 'lrelu', 'elu', 'gelu'}; for k = 1:numel (names) Mdl = fitcnet (X, Y, 'LayerSizes', 8, 'Activations', names{k}, ... 'IterationLimit', 300); [label, score] = predict (Mdl, [3, 3; -3, -3]); assert_equal (label, [1; 2]); assert_equal (all (isfinite (score(:))), true); endfor ***** test Mdl = fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], ... 'LayerSizes', [3, 2], 'IterationLimit', 20); assert_equal (numel (Mdl.LayerWeights), 3); assert_equal (numel (Mdl.LayerBiases), 3); assert_equal (size (Mdl.LayerWeights{1}), [3, 2]); assert_equal (size (Mdl.LayerWeights{2}), [2, 3]); assert_equal (size (Mdl.LayerWeights{3}), [2, 2]); assert_equal (size (Mdl.LayerBiases{1}), [3, 1]); assert_equal (size (Mdl.LayerBiases{3}), [2, 1]); ***** test Mdl = fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], 'IterationLimit', 20); assert_equal (Mdl.Cost, [0, 1; 1, 0]); assert_equal (Mdl.Prior, [0.5, 0.5]); assert_equal (size (Mdl.W), [4, 1]); assert_equal (sum (Mdl.W), 1, 1e-12); assert_equal (Mdl.CategoricalPredictors, []); assert_equal (Mdl.ExpandedPredictorNames, Mdl.PredictorNames); ***** test Mdl = fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], ... 'Solver', 'sgd', 'IterationLimit', 25); assert_equal (istable (Mdl.TrainingHistory), true); assert_equal (height (Mdl.TrainingHistory), 25); assert_equal (Mdl.TrainingHistory.Properties.VariableNames, ... {'Iteration', 'TrainingLoss', 'TrainingAccuracy', ... 'Time', 'ValidationLoss', 'ValidationChecks'}); assert_equal (Mdl.TrainingHistory.Iteration', 1:25); ***** test rand ('seed', 42); randn ('seed', 42); X = [randn(30, 2) * 0.4 + 2; randn(30, 2) * 0.4 - 2]; Y = [ones(30, 1); 2 * ones(30, 1)]; Mdl = fitcnet (X, Y, 'IterationLimit', 200); m = margin (Mdl, X, Y); assert_equal (size (m), [60, 1]); assert_equal (all (m > 0), true); assert_equal (edge (Mdl, X, Y), mean (m), 1e-12); assert_equal (resubMargin (Mdl), m, 1e-12); assert_equal (resubEdge (Mdl), edge (Mdl, X, Y, 'Weights', Mdl.W), 1e-12); ***** test rand ('seed', 42); randn ('seed', 42); X = [randn(30, 2) * 0.4 + 2; randn(30, 2) * 0.4 - 2]; Y = [ones(30, 1); 2 * ones(30, 1)]; Mdl = fitcnet (X, Y, 'IterationLimit', 200); names = {'binodeviance', 'classifcost', 'classiferror', 'crossentropy', ... 'exponential', 'hinge', 'logit', 'mincost', 'quadratic'}; for k = 1:numel (names) L = loss (Mdl, X, Y, 'LossFun', names{k}); assert_equal (isscalar (L) && isfinite (L) && L >= 0, true); endfor assert_equal (loss (Mdl, X, Y), loss (Mdl, X, Y, 'LossFun', 'mincost')); assert_equal (resubLoss (Mdl), loss (Mdl, X, Y, 'Weights', Mdl.W), 1e-12); ***** test Mdl = fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 1; 2], 'IterationLimit', 20); assert_equal (Mdl.Prior, [0.75, 0.25], 1e-12); Mdl.Cost = [0, 2; 1, 0]; assert_equal (Mdl.Cost, [0, 2; 1, 0]); Mdl.Cost = []; assert_equal (Mdl.Cost, [0, 1; 1, 0]); ***** test Mdl = fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 1; 2], ... 'IterationLimit', 20, 'Prior', [0.25, 0.75]); assert_equal (Mdl.Prior, [0.25, 0.75]); assert_equal (Mdl.W, [0.25/3; 0.25/3; 0.25/3; 0.75], 1e-12); ***** error ... margin (fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), [1, 2]) ***** error ... loss (fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), [], [1]) ***** error ... loss (fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), [1, 2, 3], [1]) ***** error ... loss (fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), [1, 2], [1; 2]) ***** error ... loss (fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), [1, 2], 1, 'LossFun', 'bogus') ***** error ... loss (fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), [1, 2], 1, 'Bogus', 1) ***** error ... edge (fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), [1, 2], 1, 'bogus', 1) ***** error ... Mdl = fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]); Mdl.Cost = [0, 1, 2]; ***** error ... Mdl = fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]); Mdl.Cost = 1:4; ***** test load fisheriris X = meas; Y = grp2idx (species); Mdl = fitcnet (X, Y, 'IterationLimit', 20); assert_equal (Mdl.RowsUsed, []); assert_equal (class (Mdl.RowsUsed), 'double'); assert_equal (Mdl.NumObservations, 150); assert_equal (rows (Mdl.X), 150); assert_equal (rows (Mdl.W), 150); ***** test load fisheriris X = meas; Y = grp2idx (species); Y(5) = NaN; Mdl = fitcnet (X, Y, 'IterationLimit', 20); assert_equal (class (Mdl.RowsUsed), 'logical'); assert_equal (size (Mdl.RowsUsed), [150, 1]); assert_equal (sum (Mdl.RowsUsed), 149); assert_equal (Mdl.RowsUsed(5), false); assert_equal (Mdl.NumObservations, 149); assert_equal (rows (Mdl.X), 149); assert_equal (rows (Mdl.W), 149); ***** test load fisheriris X = meas; X(3,2) = NaN; Y = grp2idx (species); Mdl = fitcnet (X, Y, 'IterationLimit', 20); assert_equal (Mdl.RowsUsed, []); assert_equal (Mdl.NumObservations, 150); assert_equal (rows (Mdl.X), 150); assert_equal (sum (isnan (Mdl.X(:))), 1); ***** test load fisheriris Mdl = fitcnet (meas, species, 'IterationLimit', 20); assert_equal (Mdl.Mu, []); assert_equal (Mdl.Sigma, []); ***** test load fisheriris X = meas; X(3,2) = NaN; X(17,4) = NaN; X(140,1) = NaN; Mdl = fitcnet (X, species, 'Standardize', true, 'IterationLimit', 20); assert_equal (Mdl.Mu, [5.8405997732426291, 3.0547817460317455, ... 3.7612840136054406, 1.1980799319727886], 1e-13); assert_equal (Mdl.Sigma, [0.82803317153591371, 0.43533400398915184, ... 1.7640762592568813, 0.76297286301694878], 1e-13); ***** test load fisheriris i3 = [1:50, 51:80, 101:120]; Mdl = fitcnet (meas(i3,:), species(i3), 'IterationLimit', 20, ... 'Prior', [0.2, 0.3, 0.5]); assert_equal (Mdl.Prior, [0.2, 0.3, 0.5], 1e-14); assert_equal (Mdl.W(1), 0.004, 1e-14); assert_equal (Mdl.W(51), 0.01, 1e-14); assert_equal (Mdl.W(81), 0.025, 1e-14); ***** test load fisheriris i3 = [1:50, 51:80, 101:120]; Mdl = fitcnet (meas(i3,:), species(i3), 'IterationLimit', 20); Mdl.Cost = [0, 2, 3; 1, 0, 1; 1, 1, 0]; assert_equal (Mdl.Cost, [0, 2, 3; 1, 0, 1; 1, 1, 0]); ***** error ... load fisheriris; ... Mdl = fitcnet (meas, species, 'IterationLimit', 20); ... Mdl.Prior = [0.2, 0.3, 0.5]; ***** test load fisheriris Mdl = fitcnet (meas, species, 'IterationLimit', 20); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2), 'ClassificationNeuralNetwork'); assert_equal (M2.NumObservations, Mdl.NumObservations); assert_equal (M2.PredictorNames, Mdl.PredictorNames); assert_equal (class (M2.ScoreTransform), class (Mdl.ScoreTransform)); assert_equal (predict (M2, meas(1:5,:)), predict (Mdl, meas(1:5,:))); ***** test load fisheriris Mdl = fitcnet (meas, species, 'IterationLimit', 10); assert_equal (class (Mdl.BinEdges), 'cell'); assert_equal (Mdl.BinEdges, {}); ***** test load fisheriris Mdl = fitcnet (meas, species); S = struct ('ClassNames', {{'virginica'; 'setosa'; 'versicolor'}}, ... 'ClassificationCosts', [0, 1, 2; 3, 0, 4; 5, 6, 0]); Mdl.Cost = S; assert_equal (Mdl.Cost, [0, 4, 3; 6, 0, 5; 1, 2, 0]); ***** error ... load fisheriris Mdl = fitcnet (meas, species); Mdl.Cost = ones (3); ***** test load fisheriris Mdl = fitcnet (meas, species, 'IterationLimit', 20); assert_equal (isempty (Mdl.HyperparameterOptimizationResults), true); ***** test load fisheriris Mdl = fitcnet (meas, species); assert_equal (fieldnames (Mdl.ModelParameters)', {'LayerSizes', ... 'Activations', 'OutputLayerActivation', 'LayerWeightsInitializers', ... 'Solver', 'LearningRate', 'IterationLimit', 'GradientTolerance', ... 'LossTolerance', 'StepTolerance', 'DisplayInfo', 'StandardizeData', ... 'Version', 'Method', 'Type'}); ***** test load fisheriris MP = fitcnet (meas, species).ModelParameters; assert_equal (MP.LayerSizes, 10); assert_equal (MP.Activations, 'relu'); assert_equal (MP.OutputLayerActivation, 'softmax'); assert_equal (MP.Solver, 'LBFGS'); assert_equal (MP.IterationLimit, 1000); assert_equal (MP.GradientTolerance, 1e-6); assert_equal (MP.LossTolerance, 1e-6); assert_equal (MP.StepTolerance, 1e-6); assert_equal (MP.StandardizeData, false); ***** test load fisheriris MP = fitcnet (meas, species).ModelParameters; assert_equal (MP.Version, 1); assert_equal (MP.Method, 'NeuralNetwork'); assert_equal (MP.Type, 'classification'); ***** test load fisheriris MP = fitcnet (meas, species, 'LayerSizes', [5, 3], 'Activations', ... {'relu', 'tanh'}, 'Standardize', true, ... 'IterationLimit', 50).ModelParameters; assert_equal (size (MP), [1, 1]); assert_equal (MP.LayerSizes, [5, 3]); assert_equal (MP.Activations, {'relu', 'tanh'}); assert_equal (MP.StandardizeData, true); assert_equal (MP.IterationLimit, 50); ***** test load fisheriris MP = fitcnet (meas, species).ModelParameters; assert_equal (MP.LayerWeightsInitializers, {'he', 'glorot'}); ***** test load fisheriris Mdl = fitcnet (meas, species, 'LayerSizes', [5, 3], ... 'Activations', {'relu', 'tanh'}); assert_equal (Mdl.ModelParameters.LayerWeightsInitializers, ... {'he', 'glorot', 'glorot'}); ***** test load fisheriris MP = fitcnet (meas, species, 'Activations', 'sigmoid').ModelParameters; assert_equal (MP.LayerWeightsInitializers, {'glorot', 'glorot'}); ***** test load fisheriris Mdl = fitcnet (meas, species); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); T = {'identity', @(x) x; 'doublelogit', @(x) 1 ./ (1 + exp (-2 * x)); ... 'invlogit', @(x) log (x ./ (1 - x)); ... 'logit', @(x) 1 ./ (1 + exp (-x)); ... 'sign', @(x) sign (x); 'symmetric', @(x) 2 * x - 1; ... 'symmetriclogit', @(x) 2 ./ (1 + exp (-x)) - 1}; for i = 1:rows (T) Mdl.ScoreTransform = T{i,1}; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, T{i,2}(raw), 1e-12); assert_equal (l, label); endfor ## ismax marks the largest score of each observation, ties to the first. [~, k] = max (raw, [], 2); e = zeros (size (raw)); e(sub2ind (size (raw), (1:rows (raw))', k)) = 1; Mdl.ScoreTransform = 'ismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, e); Mdl.ScoreTransform = 'symmetricismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, 2 * e - 1); ***** test load fisheriris Mdl = fitcnet (meas, species); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); Mdl.ScoreTransform = @(x) x .^ 2; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, raw .^ 2, 1e-12); assert_equal (l, label); ***** shared Xc, Dc, yc, Xq, Dq k = (0:119)'; c1 = mod (k, 3) + 1; x2 = sin (k); c3 = 10 * (mod (floor (k / 2), 2) + 1); Xc = [c1, x2, c3]; Dc = [c1 == 1, c1 == 2, c1 == 3, x2, c3 == 10, c3 == 20]; yr = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 20) + 0.1 * cos (k); yc = yr > 1; Xq = [1, 0, 10; 2, 0.5, 20]; Dq = [1, 0, 0, 0, 1, 0; 0, 1, 0, 0.5, 0, 1]; ***** test # MATLAB parity: a categorical predictor is dummy coded in its place rand ('seed', 1); randn ('seed', 1); Mdl = ClassificationNeuralNetwork (Xc, yc, 'CategoricalPredictors', ... [1, 3], 'LayerSizes', 4); rand ('seed', 1); randn ('seed', 1); H = ClassificationNeuralNetwork (Dc, yc, 'LayerSizes', 4); assert_equal (Mdl.ExpandedPredictorNames, {'x1 == 1', 'x1 == 2', ... 'x1 == 3', 'x2', 'x3 == 10', 'x3 == 20'}); assert_equal (Mdl.LayerWeights{1}, H.LayerWeights{1}, 1e-12); [~, s] = predict (Mdl, Xq); [~, sh] = predict (H, Dq); assert_equal (s, sh, 1e-12); ***** test # MATLAB parity: a level the fit did not see has no score Mdl = ClassificationNeuralNetwork (Xc, yc, 'CategoricalPredictors', ... [1, 3], 'LayerSizes', 4); [label, s] = predict (Mdl, [4, 0, 10; 2.5, 0, 20]); assert_equal (all (isnan (s(:))), true); assert_equal (label, [false; false]); ***** test # a row missing a predictor has no score, whatever the activation load fisheriris Mdl = ClassificationNeuralNetwork (meas(51:150,:), species(51:150), ... 'LayerSizes', 4); [~, s] = predict (Mdl, [NaN, 3, 5, 2; 6, 3, 5, 2]); assert_equal (isnan (s(:,1))', [true, false]); ***** test # MATLAB parity: the coded columns are not standardized Mdl = ClassificationNeuralNetwork (Xc, yc, 'CategoricalPredictors', ... [1, 3], 'LayerSizes', 4, ... 'Standardize', true); assert_equal (Mdl.Mu([1:3, 5:6]), zeros (1, 5)); assert_equal (Mdl.Sigma([1:3, 5:6]), ones (1, 5)); ***** test # the coding travels with saved models and cross-validation folds Mdl = ClassificationNeuralNetwork (Xc, yc, 'CategoricalPredictors', ... [1, 3], 'LayerSizes', 4); fname = [tempname(), '.mdl']; savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); [~, s2] = predict (M2, Xq); [~, s] = predict (Mdl, Xq); assert_equal (s2, s); CV = crossval (Mdl, 'KFold', 3); assert_equal (CV.Trained{1}.CategoricalPredictors, [1, 3]); ***** error ... ClassificationNeuralNetwork (Xc, yc, 'CategoricalPredictors', 4) ***** test # the class may be built from a table as the fitter builds it load fisheriris T = table (meas(:,1), meas(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = categorical (species); Mdl = ClassificationNeuralNetwork (T, 'Species'); assert_equal (Mdl.PredictorNames, {'SL', 'SW'}); assert_equal (Mdl.ResponseName, 'Species'); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcnet (T, 'Species'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcnet (T, 'Species'); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcnet (T, 'Species'); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** error ... loss (fitcnet ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2]), ... [1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', int8 ([1; 1; 1; 1])) ***** error ... ClassificationNeuralNetwork ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], ... 'Weights', int8 ([1; 1; 1; 1])) ***** error ... ClassificationNeuralNetwork ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], ... 'Weights', true (4, 1)) ***** error ... ClassificationNeuralNetwork ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], ... 'Weights', [1; 1]) ***** error ... ClassificationNeuralNetwork ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], ... 'Weights', [1; -1; 1; 1]) ***** test ## A weight of two fits as the observation given twice load fisheriris X = meas(51:130,:); Y = species(51:130); w = ones (80, 1); w(1:10) = 2; rand ('seed', 1); A = ClassificationNeuralNetwork (X, Y, 'LayerSizes', 1, 'Weights', w); rand ('seed', 1); B = ClassificationNeuralNetwork ([X; X(1:10,:)], [Y; Y(1:10)], ... 'LayerSizes', 1); assert_equal (nthargout (2, @predict, A, X), ... nthargout (2, @predict, B, X), 1e-10); ***** test ## A prior weighs the fit as weights would, as R2024a weighs it load fisheriris X = meas(51:130,:); Y = species(51:130); w = [ones(50, 1) / 50; ones(30, 1) / 30]; rand ('seed', 1); A = ClassificationNeuralNetwork (X, Y, 'LayerSizes', 1, 'Prior', 'uniform'); rand ('seed', 1); B = ClassificationNeuralNetwork (X, Y, 'LayerSizes', 1, 'Weights', w); assert_equal (nthargout (2, @predict, A, X), ... nthargout (2, @predict, B, X), 1e-8); ***** test ## W sums to one and keeps the class of single weights load fisheriris w = ones (150, 1); w([3, 60, 120]) = 2; Mdl = ClassificationNeuralNetwork (meas, species, 'LayerSizes', 3, ... 'Weights', single (w)); assert_equal (class (Mdl.W), 'single'); assert_equal (double (Mdl.W(1)), 1 / 153, 1e-8); ***** test ## Rows of zero weight are left out, as R2024a leaves them load fisheriris w = ones (150, 1); w(5) = 0; Mdl = ClassificationNeuralNetwork (meas, species, 'LayerSizes', 3, ... 'Weights', w); assert_equal (Mdl.NumObservations, 149); ***** test ## Standardization weighs the observations by W, as R2024a does load fisheriris w = 1 + (1:150)' / 7; Mdl = ClassificationNeuralNetwork (meas, species, 'LayerSizes', 3, ... 'Weights', w, 'Standardize', true); assert_equal (Mdl.Mu, [6.153769696969698, 2.965608080808081, ... 4.573050505050506, 1.55819797979798], 1e-14); Mdl = ClassificationNeuralNetwork (meas, species, 'LayerSizes', 3, ... 'Weights', w, 'Standardize', true, ... 'Prior', 'uniform'); assert_equal (Mdl.Mu, [5.833297045931007, 3.054926460541555, ... 3.749907727492633, 1.199335039802964], 1e-14); ***** test ## A constant predictor is left unscaled by standardization X = [linspace(0, 1, 20)', ones(20, 1)]; Mdl = ClassificationNeuralNetwork (X, [ones(10, 1); 2 * ones(10, 1)], 'Standardize', true); assert_equal (Mdl.Sigma(2), 1); 153 tests, 153 passed, 0 known failure, 0 skipped [inst/Machine_Learning/ClassificationEnsemble.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/ClassificationEnsemble.m ***** shared X2, Y2, S load fisheriris X2 = meas(51:150,:); Y2 = species(51:150); S = templateTree ('MaxNumSplits', 1); ***** test # MATLAB parity: the properties of a boosted ensemble Mdl = ClassificationEnsemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 2, 'Learners', S); assert_equal (numel (properties (Mdl)), 26); assert_equal (Mdl.NumObservations, 100); assert_equal (Mdl.LearnerNames, {'Tree'}); assert_equal (Mdl.UsePredForLearner, []); assert_equal (Mdl.ReasonForTermination, ["Terminated normally after ", ... "completing the requested number of training cycles."]); assert_equal (size (Mdl.FitInfoDescription), [2, 1]); ***** test # MATLAB parity: the parameters of a boosted fit Mdl = ClassificationEnsemble (X2, Y2, 'Method', 'LogitBoost', ... 'NumLearningCycles', 2, 'Learners', S, ... 'LearnRate', 0.5); mp = Mdl.ModelParameters; assert_equal (mp.Type, 'classification'); assert_equal (mp.Method, 'LogitBoost'); assert_equal (mp.NLearn, 2); assert_equal (mp.LearnRate, 0.5); assert_equal (mp.LearnerTemplates.MaxNumSplits, 1); ***** test # MATLAB parity: resuming continues the fit exactly for m = {'AdaBoostM1', 'GentleBoost', 'LogitBoost'} M5 = ClassificationEnsemble (X2, Y2, 'Method', m{1}, ... 'NumLearningCycles', 5, 'Learners', S, ... 'LearnRate', 0.5); M3 = ClassificationEnsemble (X2, Y2, 'Method', m{1}, ... 'NumLearningCycles', 3, 'Learners', S, ... 'LearnRate', 0.5); R = resume (M3, 2); assert_equal (R.NumTrained, 5); assert_equal (R.ModelParameters.NLearn, 5); assert_equal (R.TrainedWeights, M5.TrainedWeights, 1e-14); assert_equal (R.FitInfo, M5.FitInfo, 1e-14); endfor ***** test # resuming AdaBoostM2 continues exactly, where MATLAB restarts load fisheriris M5 = ClassificationEnsemble (meas, species, 'Method', 'AdaBoostM2', ... 'NumLearningCycles', 5, 'Learners', S); R = resume (ClassificationEnsemble (meas, species, ... 'Method', 'AdaBoostM2', ... 'NumLearningCycles', 2, ... 'Learners', S), 3); assert_equal (R.TrainedWeights, M5.TrainedWeights, 1e-14); ***** test # an ensemble ended by a perfect learner grows no more load fisheriris Mdl = ClassificationEnsemble (meas, strcmp (species, 'setosa'), ... 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 2, 'Learners', S); assert_equal (resume (Mdl, 3).NumTrained, 1); ***** test # MATLAB parity: resubstitution with the training weights Mdl = ClassificationEnsemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 5, 'Learners', S); assert_equal (resubLoss (Mdl), 0.04, 1e-15); assert_equal (resubLoss (Mdl, 'LossFun', 'exponential'), ... 0.182079166822146, 1e-13); assert_equal (resubEdge (Mdl), 5.115272254726563, 1e-12); m = resubMargin (Mdl); assert_equal (m([1, 21]), [3.544074277136197; -1.958996348947703], 1e-12); assert_equal (resubPredict (Mdl), predict (Mdl, X2)); ***** test # compact keeps the learners and drops the data Mdl = ClassificationEnsemble (X2, Y2, 'Method', 'GentleBoost', ... 'NumLearningCycles', 3, 'Learners', S); C = compact (Mdl); assert_equal (class (C), 'CompactClassificationEnsemble'); [l1, s1] = predict (Mdl, X2); [l2, s2] = predict (C, X2); assert_equal (l2, l1); assert_equal (s2, s1); ***** test # the score transform can be set on a fitted ensemble Mdl = ClassificationEnsemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 5, 'Learners', S); Mdl.ScoreTransform = 'doublelogit'; [~, s] = predict (Mdl, X2(1,:)); assert_equal (s, [0.971916134164721, 0.028083865835279], 1e-13); ***** error ... ClassificationEnsemble (X2) ***** error ... ClassificationEnsemble (X2, Y2, 'Method') ***** error ... ClassificationEnsemble (X2, Y2, 'Foo', 1) ***** error ... ClassificationEnsemble (X2, Y2, 1, 1) ***** error ... ClassificationEnsemble (X2, Y2, 'NumLearningCycles', 0) ***** error ... ClassificationEnsemble (X2, Y2, 'LearnRate', 2) ***** error ... ClassificationEnsemble (X2, Y2, 'NPrint', 0) ***** error ... ClassificationEnsemble (X2, Y2, 'ResponseName', 1) ***** error ... ClassificationEnsemble (X2, Y2, 'FResample', 0) ***** error ... ClassificationEnsemble (X2, Y2, 'Replace', 1) ***** error ... ClassificationEnsemble (X2, Y2, 'Resample', 1) ***** error ... ClassificationEnsemble (X2, Y2, 'Method', 'RUSBoost', ... 'RatioToSmallest', [0, 0]) ***** error ... ClassificationEnsemble (X2, Y2, 'Method', 'RUSBoost', ... 'RatioToSmallest', [1, NaN]) ***** error ... ClassificationEnsemble (X2, Y2, 'Method', 'RUSBoost', ... 'RatioToSmallest', [1, 2, 3]) ***** error ... ClassificationEnsemble (X2, Y2, 'RatioToSmallest', 1) ***** error ... ClassificationEnsemble (X2, Y2, 'Method', 'RUSBoost', 'Resample', 'on') ***** error ... ClassificationEnsemble (X2, Y2, 'Learners', 'knn') ***** error ... ClassificationEnsemble (X2, Y2, 'Method', 1) ***** error ... ClassificationEnsemble (X2, Y2, 'Method', 'Boost') ***** error ... ClassificationEnsemble (X2, Y2, 'Method', 'robustboost') ***** error ... ClassificationEnsemble (X2, Y2, 'Method', 'Bag') ***** error ... load fisheriris ClassificationEnsemble (meas, species, 'Method', 'AdaBoostM1') ***** error ... ClassificationEnsemble (X2, Y2, 'Method', 'AdaBoostM2') ***** error ... ClassificationEnsemble (X2, Y2, 'FResample', 0.5) ***** error ... ClassificationEnsemble (X2, Y2, 'PredictorNames', {'a'}) ***** error ... resume (ClassificationEnsemble (X2, Y2, 'NumLearningCycles', 1)) ***** error ... resume (ClassificationEnsemble (X2, Y2, 'NumLearningCycles', 1), 0) ***** error ... resume (ClassificationEnsemble (X2, Y2, 'NumLearningCycles', 1), 1, 'NPrint') ***** error ... resume (ClassificationEnsemble (X2, Y2, 'NumLearningCycles', 1), 1, 'Foo', 1) ***** error ... resume (ClassificationEnsemble (X2, Y2, 'NumLearningCycles', 1), 1, ... 'NPrint', 0) ***** error ... predict (ClassificationEnsemble (X2, Y2, 'NumLearningCycles', 1)) ***** error ... loss (ClassificationEnsemble (X2, Y2, 'NumLearningCycles', 1), X2) ***** error ... edge (ClassificationEnsemble (X2, Y2, 'NumLearningCycles', 1), X2) ***** error ... margin (ClassificationEnsemble (X2, Y2, 'NumLearningCycles', 1), X2) ***** error ... resubLoss (ClassificationEnsemble (X2, Y2, 'NumLearningCycles', 1), 'Foo', 1) ***** error ... Mdl = ClassificationEnsemble (X2, Y2, 'NumLearningCycles', 1); Mdl.ScoreTransform = 1; ***** test # MATLAB parity: GentleBoost importance over its regression trees Mdl = ClassificationEnsemble (X2, Y2, 'Method', 'GentleBoost', ... 'NumLearningCycles', 3, 'Learners', S); assert_equal (predictorImportance (Mdl), ... [0, 0, 0.222096984079193, 0.388833770583033], 1e-13); ***** test # MATLAB parity: crossval equals cross-validating at fit time load fisheriris c = cvpartition (Y2, 'KFold', 5); M = ClassificationEnsemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 4, 'Learners', S); CV = crossval (M, 'CVPartition', c); F = fitcensemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 4, 'Learners', S, 'CVPartition', c); assert_equal (kfoldLoss (CV), kfoldLoss (F), 1e-15); assert_equal (crossval (M).KFold, 10); assert_equal (crossval (M, 'KFold', 3).KFold, 3); ***** error ... crossval (ClassificationEnsemble (X2, Y2, 'NumLearningCycles', 1), ... 'CrossVal', 'off') ***** error ... crossval (ClassificationEnsemble (X2, Y2, 'NumLearningCycles', 1), 'Foo', 1) ***** error ... load fisheriris ClassificationEnsemble (meas, species, 'Method', 'Subspace', ... 'Learners', 'tree') ***** error ... load fisheriris ClassificationEnsemble (meas, species, 'Method', 'Subspace', ... 'Learners', 'svm') ***** error ... ClassificationEnsemble (X2, Y2, 'NPredToSample', 0) ***** error ... load fisheriris ClassificationEnsemble (meas, species, 'Method', 'Subspace', ... 'NPredToSample', 4) ***** error ... ClassificationEnsemble (X2, Y2, 'NPredToSample', 2) ***** error ... ClassificationEnsemble (X2, Y2, 'NumLearningCycles', ... 'AllPredictorCombinations') ***** error ... load fisheriris ClassificationEnsemble (meas, species, 'Method', 'Subspace', ... 'LearnRate', 0.5) ***** error ... load fisheriris ClassificationEnsemble (meas, species, 'Method', 'Subspace', ... 'FResample', 0.5) ***** error ... load fisheriris ClassificationEnsemble (meas, species, 'Method', 'Subspace', ... 'Weights', [5 * ones(50, 1); ones(100, 1)]) ***** error ... load fisheriris predictorImportance (ClassificationEnsemble (meas, species, ... 'Method', 'Subspace', 'NumLearningCycles', 2)) ***** error ... load fisheriris resume (ClassificationEnsemble (meas, species, 'Method', 'Subspace', ... 'NumLearningCycles', 'AllPredictorCombinations'), 1) ***** shared X, yb k = (0:119)'; c = mod (k, 4) + 1; j = floor (k / 4); x2 = mod (k * 7, 10); X = [c, x2]; yb = (c == 1) | (c == 2 & mod (j, 4) != 0) | (c == 3 & mod (j, 4) == 0) ... | (x2 > 7); yr = [3; 1; 4; 1.5]; yr = yr(c) + 0.1 * sin (k) + 0.2 * x2; Xq = [1, 0; 3, 5; 5, 0; NaN, 2; 2.5, 9]; ***** test # the categorical predictors travel to compact models and folds Mdl = ClassificationEnsemble (X, yb, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 3, ... 'CategoricalPredictors', logical ([1, 0])); assert_equal (compact (Mdl).CategoricalPredictors, 1); CV = crossval (Mdl, 'KFold', 3); assert_equal (CV.CategoricalPredictors, 1); assert_equal (CV.Trained{1}.Trained{1}.CategoricalPredictors, 1); ***** test # a tree template's categorical options reach every tree t = templateTree ('MaxNumCategories', 3, 'MaxNumSplits', 3); Mdl = ClassificationEnsemble (X, yb, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 2, 'Learners', t, ... 'CategoricalPredictors', 1); assert_equal (Mdl.Trained{1}.CategoricalPredictors, 1); ***** error ... ClassificationEnsemble (X, yb, 'CategoricalPredictors', 3) ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcensemble (T, 'Species'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcensemble (T, 'Species'); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcensemble (T, 'Species'); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** error ... fitcensemble (ones (4, 2), [1; 1; 2; 2], 'Weights', int8 ([1; 1; 1; 1])) ***** error ... fitcensemble (ones (4, 2), [1; 1; 2; 2], 'Weights', true (4, 1)) ***** test ## Single weights are stored single, summing to one load fisheriris w = 1 + (1:150)' / 7; Mdl = fitcensemble (meas, species, 'Weights', single (w), ... 'NumLearningCycles', 10); assert_equal (class (Mdl.W), 'single'); assert_equal (sum (double (Mdl.W)), 1, 1e-6); ***** test ## Single weights compute as double load fisheriris w = 1 + (1:150)' / 7; A = fitcensemble (meas, species, 'Weights', single (w), ... 'NumLearningCycles', 10); B = fitcensemble (meas, species, 'Weights', double (single (w)), ... 'NumLearningCycles', 10); assert_equal (nthargout (2, @predict, A, meas), nthargout (2, @predict, ... B, meas)); 69 tests, 69 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitcsvm.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitcsvm.m ***** demo ## Use a subset of Fisher's iris data set load fisheriris inds = ! strcmp (species, 'setosa'); X = meas(inds, [3,4]); Y = species(inds); ## Train a linear SVM classifier SVMModel = fitcsvm (X, Y) ## Plot a scatter diagram of the data and circle the support vectors. sv = SVMModel.SupportVectors; figure gscatter (X(:,1), X(:,2), Y) hold on plot (sv(:,1), sv(:,2), 'ko', 'MarkerSize', 10) legend ('versicolor', 'virginica', 'Support Vector') hold off ***** demo ## Fit from a table, and predict on one load fisheriris inds = ! strcmp (species, 'setosa'); X = meas(inds,:); T = table (X(:,1), X(:,2), X(:,3), X(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = categorical (species(inds)); ## A column holding levels is a categorical predictor without being named ## one T.Wide = categorical (X(:,2) > 2.9, [false true], {'narrow', 'wide'}); ## The response is named by its column, and everything else is a predictor Mdl = fitcsvm (T, 'Species'); Mdl.PredictorNames Mdl.CategoricalPredictors ## predict reads a table by the names the model was fitted on, so the ## columns may come in any order label = predict (Mdl, T(1:5, [6, 5, 4, 3, 2, 1])); label' ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = {'a'; 'a'; 'b'; 'b'}; a = fitcsvm (x, y); assert_equal (class (a), "ClassificationSVM"); assert_equal ({a.X, a.Y}, {x, y}) assert_equal (a.NumObservations, 4) assert_equal ({a.ResponseName, a.PredictorNames}, {'Y', {'x1', 'x2', 'x3'}}) assert_equal (a.ModelParameters.SVMtype, "c_svc") assert_equal (a.ClassNames, {'a'; 'b'}) ***** test x = [1, 2; 2, 3; 3, 4; 4, 5; 2, 3; 3, 4; 2, 3; 3, 4; 2, 3; 3, 4]; y = [1; 1; -1; -1; 1; -1; -1; -1; -1; -1]; a = fitcsvm (x, y); assert_equal (class (a), "ClassificationSVM"); assert_equal ({a.X, a.Y, a.ModelParameters.KernelFunction}, {x, y, 'linear'}) assert_equal (a.ModelParameters.BoxConstraint, 1) assert_equal (a.ModelParameters.KernelOffset, 0) assert_equal (a.ClassNames, [-1; 1]) ***** test x = [1, 2; 2, 3; 3, 4; 4, 5; 2, 3; 3, 4; 2, 3; 3, 4; 2, 3; 3, 4]; y = [1; 1; -1; -1; 1; -1; -1; -1; -1; -1]; a = fitcsvm (x, y, 'KernelFunction', 'rbf', 'BoxConstraint', 2, ... 'KernelOffset', 2); assert_equal (class (a), "ClassificationSVM"); assert_equal ({a.X, a.Y, a.ModelParameters.KernelFunction}, {x, y, 'rbf'}) assert_equal (a.ModelParameters.BoxConstraint, 2) assert_equal (a.ModelParameters.KernelOffset, 2) assert_equal (isempty (a.Alpha), false) assert_equal (isempty (a.Beta), true) ***** test x = [1, 2; 2, 3; 3, 4; 4, 5; 2, 3; 3, 4; 2, 3; 3, 4; 2, 3; 3, 4]; y = [1; 1; -1; -1; 1; -1; -1; -1; -1; -1]; a = fitcsvm (x, y, 'KernelFunction', 'polynomial', 'PolynomialOrder', 3); assert_equal (class (a), "ClassificationSVM"); assert_equal ({a.X, a.Y, a.ModelParameters.KernelFunction}, {x, y, 'polynomial'}) assert_equal (a.ModelParameters.KernelPolynomialOrder, 3) assert_equal (isempty (a.Alpha), false) assert_equal (isempty (a.Beta), true) ***** test x = [1, 2; 2, 3; 3, 4; 4, 5; 2, 3; 3, 4; 2, 3; 3, 4; 2, 3; 3, 4]; y = [1; 1; -1; -1; 1; -1; -1; -1; -1; -1]; a = fitcsvm (x, y, 'KernelFunction', 'linear', 'PolynomialOrder', 3); assert_equal (class (a), "ClassificationSVM"); assert_equal ({a.X, a.Y, a.ModelParameters.KernelFunction}, {x, y, 'linear'}) assert_equal (isempty (a.ModelParameters.KernelPolynomialOrder), true) assert_equal (isempty (a.Alpha), false) assert_equal (isempty (a.Beta), false) assert_equal (size (a.Beta), [2, 1]) ***** test x = [1, 2; 2, 3; 3, 4; 4, 5; 2, 3; 3, 4; 2, 3; 3, 4; 2, 3; 3, 4]; y = [1; 1; -1; -1; 1; -1; -1; -1; -1; -1]; status = warning; warning ('off'); rand ('seed', 23); a = fitcsvm (x, y, 'KernelFunction', 'linear', 'CrossVal', 'on'); warning (status); assert_equal (class (a), "ClassificationPartitionedModel"); assert_equal ({a.X, a.Y, a.ModelParameters.KernelFunction}, {x, y, 'linear'}) assert_equal (isempty (a.ModelParameters.KernelPolynomialOrder), true) assert_equal (isempty (a.Trained{1}.Alpha), false) assert_equal (isempty (a.Trained{1}.Beta), false) ***** error fitcsvm () ***** error fitcsvm (ones (4,1)) ***** error fitcsvm (ones (4,2), ones (4, 1), 'KFold') ***** error fitcsvm (ones (4,2), ones (3, 1)) ***** error fitcsvm (ones (4,2), ones (3, 1), 'KFold', 2) ***** error fitcsvm (ones (4,2), ones (4, 1), 'CrossVal', 2) ***** error fitcsvm (ones (4,2), ones (4, 1), 'CrossVal', 'a') ***** error ... fitcsvm (ones (4,2), ones (4, 1), 'KFold', 10, 'Holdout', 0.3) ***** test # 'Leaveout' leaves one observation out of each fold load fisheriris k = [51:70, 101:120]; CVMdl = fitcsvm (meas(k,:), species(k), 'Leaveout', 'on'); assert_equal (CVMdl.KFold, 40); ***** test # MATLAB parity: classes given as text are sorted load fisheriris k = [101:150, 51:100]; Mdl = fitcsvm (meas(k,:), species(k)); assert_equal (Mdl.ClassNames, {'versicolor'; 'virginica'}); ***** test # MATLAB parity: a given ClassNames order is kept load fisheriris Mdl = fitcsvm (meas(51:150,:), species(51:150), ... 'ClassNames', {'virginica'; 'versicolor'}); assert_equal (Mdl.ClassNames, {'virginica'; 'versicolor'}); ***** test # the score columns follow a given ClassNames order load fisheriris Mdl = fitcsvm (meas(51:150,:), species(51:150), ... 'ClassNames', {'virginica'; 'versicolor'}); [label, s] = predict (Mdl, meas(51,:)); assert_equal (label, {'versicolor'}); assert_equal (s(2) > s(1), true); ***** error ... load fisheriris fitcsvm (meas(51:150,:), species(51:150), 'ClassNames', [3, 2]) ***** shared fcsT load fisheriris fcsI = ! strcmp (species, 'setosa'); fcsX = meas(fcsI,:); fcsT = table (fcsX(:,1), fcsX(:,2), fcsX(:,3), fcsX(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); fcsT.Species = categorical (species(fcsI)); fcsT.Wide = categorical (fcsX(:,2) > 2.9, [false true], ... {'narrow', 'wide'}); ***** test # the response is named by a column and the rest are predictors Mdl = fitcsvm (fcsT, 'Species'); assert_equal (Mdl.PredictorNames, {'SL', 'SW', 'PL', 'PW', 'Wide'}); assert_equal (Mdl.ResponseName, 'Species'); assert_equal (Mdl.CategoricalPredictors, 5); ***** test # a model formula names the response and the predictors together Mdl = fitcsvm (fcsT, 'Species ~ PW + SL'); assert_equal (Mdl.PredictorNames, {'PW', 'SL'}); assert_equal (isempty (Mdl.CategoricalPredictors), true); ***** test # the response may be given beside a table of predictors Mdl = fitcsvm (fcsT(:,1:4), fcsT.Species); assert_equal (Mdl.PredictorNames, {'SL', 'SW', 'PL', 'PW'}); assert_equal (Mdl.ResponseName, 'Y'); ***** test # predict takes a table, matched by name and not by position Mdl = fitcsvm (fcsT, 'Species'); a = predict (Mdl, fcsT); assert_equal (class (a), 'categorical'); assert_equal (predict (Mdl, fcsT(:, [6, 5, 4, 3, 2, 1])), a); ***** test # the levels travel with the model when it is made compact Mdl = fitcsvm (fcsT, 'Species'); CMdl = compact (Mdl); assert_equal (CMdl.PredictorLevels, Mdl.PredictorLevels); assert_equal (predict (CMdl, fcsT), predict (Mdl, fcsT)); ***** error ... fitcsvm (fcsT, 'NoSuch') ***** error ... fitcsvm (fcsT, 'Species ~ SL*PW') ***** error ... predict (fitcsvm (fcsT, 'Species'), fcsT(:, [1, 3, 4, 5, 6])) 27 tests, 27 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitcnet.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitcnet.m ***** demo ## 1. Train a network on Fisher's iris data and see what it got right load fisheriris Mdl = fitcnet (meas, species); pred_species = resubPredict (Mdl); confusionchart (species, pred_species, 'Title', ... 'Neural network classification of Fisher''s iris data'); ***** demo ## 2. Watching the fit converge load fisheriris Mdl = fitcnet (meas, species, 'IterationLimit', 400); ## TrainingHistory records what the solver converges on. The default ## solver is lbfgs, so that is the loss and the gradient norm; under ## 'sgd' it is the loss and the accuracy instead. h = Mdl.TrainingHistory; plotyy (h.Iteration, h.TrainingLoss, h.Iteration, h.Gradient); xlabel ('Iteration'); title ('Training loss, left, and gradient norm, right'); ***** demo ## 3. Rectified hidden layers train faster than sigmoid ones load fisheriris iters = [5, 10, 25, 50, 100, 200, 400]; L = zeros (2, numel (iters)); for k = 1:numel (iters) for a = 1:2 act = {'relu', 'sigmoid'}{a}; m = fitcnet (meas, species, 'Activations', act, ... 'IterationLimit', iters(k)); L(a,k) = loss (m, meas, species, 'LossFun', 'classiferror'); endfor endfor semilogx (iters, L(1,:), 'o-', iters, L(2,:), 's-', 'linewidth', 1.5); xlabel ('Iteration limit'); ylabel ('Misclassification rate'); legend ({'relu', 'sigmoid'}); title ('A sigmoid shrinks the gradient at every layer'); ***** demo ## 4. What the network learned, over two predictors load fisheriris X = meas(:,3:4); Mdl = fitcnet (X, species, 'LayerSizes', [12, 12], 'IterationLimit', 400); ## Ask about a grid and paint each point by the answer [gx, gy] = meshgrid (linspace (0.5, 7.5, 120), linspace (0, 3, 120)); [~, ~, region] = unique (predict (Mdl, [gx(:), gy(:)])); contourf (gx, gy, reshape (region, size (gx)), [1 2 3]); colormap (summer); hold on; gscatter (X(:,1), X(:,2), species, 'krb', 'ox+'); hold off; xlabel ('Petal length'); ylabel ('Petal width'); title ('Decision regions of a two-layer network'); ***** demo ## Fit from a table, and predict on one load fisheriris T = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = categorical (species); ## A column holding levels is a categorical predictor without being named ## one T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ## The response is named by its column, and everything else is a predictor Mdl = fitcnet (T, 'Species'); Mdl.PredictorNames Mdl.CategoricalPredictors ## predict reads a table by the names the model was fitted on, so the ## columns may come in any order label = predict (Mdl, T(1:5, [6, 5, 4, 3, 2, 1])); label' ***** test load fisheriris x = meas; y = grp2idx (species); Mdl = fitcnet (x, y, 'IterationLimit', 50); assert_equal (class (Mdl), "ClassificationNeuralNetwork"); assert_equal (numel (Mdl.LayerWeights), 2); assert_equal (size (Mdl.LayerWeights{1}), [10, 4]); assert_equal (size (Mdl.LayerBiases{1}), [10, 1]); assert_equal (size (Mdl.LayerWeights{2}), [3, 10]); assert_equal (size (Mdl.LayerBiases{2}), [3, 1]); ***** error fitcnet () ***** error fitcnet (ones (4,1)) ***** error fitcnet (ones (4,2), ones (4, 1), 'LayerSizes') ***** error fitcnet (ones (4,2), ones (3, 1)) ***** error fitcnet (ones (4,2), ones (3, 1), 'LayerSizes', 2) ***** test # MATLAB parity: classes given as text are sorted load fisheriris k = [101:150, 1:50, 51:100]; Mdl = fitcnet (meas(k,:), species(k)); assert_equal (Mdl.ClassNames, {'setosa'; 'versicolor'; 'virginica'}); ***** test # MATLAB parity: a given ClassNames order is kept load fisheriris Mdl = fitcnet (meas(1:150,:), species(1:150), ... 'ClassNames', {'virginica'; 'setosa'; 'versicolor'}); assert_equal (Mdl.ClassNames, {'virginica'; 'setosa'; 'versicolor'}); ***** error ... load fisheriris fitcnet (meas, species, 'ClassNames', [3, 1, 2]) ***** shared fcnT load fisheriris fcnT = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); fcnT.Species = categorical (species); fcnT.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ***** test # the response is named by a column and the rest are predictors Mdl = fitcnet (fcnT, 'Species'); assert_equal (Mdl.PredictorNames, {'SL', 'SW', 'PL', 'PW', 'Wide'}); assert_equal (Mdl.ResponseName, 'Species'); assert_equal (Mdl.CategoricalPredictors, 5); ***** test # a model formula names the response and the predictors together Mdl = fitcnet (fcnT, 'Species ~ PW + SL'); assert_equal (Mdl.PredictorNames, {'PW', 'SL'}); assert_equal (isempty (Mdl.CategoricalPredictors), true); ***** test # the response may be given beside a table of predictors Mdl = fitcnet (fcnT(:,1:4), fcnT.Species); assert_equal (Mdl.PredictorNames, {'SL', 'SW', 'PL', 'PW'}); assert_equal (Mdl.ResponseName, 'Y'); ***** test # predict takes a table, matched by name and not by position Mdl = fitcnet (fcnT, 'Species'); a = predict (Mdl, fcnT); assert_equal (class (a), 'categorical'); assert_equal (predict (Mdl, fcnT(:, [6, 5, 4, 3, 2, 1])), a); ***** test # the levels travel with the model when it is made compact Mdl = fitcnet (fcnT, 'Species'); CMdl = compact (Mdl); assert_equal (CMdl.PredictorLevels, Mdl.PredictorLevels); assert_equal (predict (CMdl, fcnT), predict (Mdl, fcnT)); ***** error ... fitcnet (fcnT, 'NoSuch') ***** error ... fitcnet (fcnT, 'Species ~ SL*PW') ***** error ... predict (fitcnet (fcnT, 'Species'), fcnT(:, [1, 3, 4, 5, 6])) 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitrtree.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitrtree.m ***** demo ## Grow a regression tree on the carsmall data and look at it load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = fitrtree (X, MPG, 'MinLeafSize', 15); ## The tree as text: a branch names its cut, a leaf names what it fits view (Mdl); ## How much each predictor contributed predictorImportance (Mdl) ## The mean squared error on the data it was fitted to resubLoss (Mdl) ***** demo ## Prune a tree back and watch the error rise as it gets smaller load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = fitrtree (X, MPG, 'MinLeafSize', 15); levels = 0:numel (Mdl.PruneAlpha) - 1; leaves = zeros (size (levels)); err = zeros (size (levels)); for ii = 1:numel (levels) sub = prune (Mdl, 'Level', levels(ii)); leaves(ii) = sum (! sub.IsBranchNode); err(ii) = resubLoss (sub); endfor [leaves(:), err(:)] ***** demo ## Fit from a table, and predict on one load fisheriris T = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); ## A column holding levels is a categorical predictor without being named ## one T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ## The response is named by its column, and everything else is a predictor Mdl = fitrtree (T, 'SL'); Mdl.PredictorNames Mdl.ResponseName Mdl.CategoricalPredictors ## A model formula names them instead Mdl2 = fitrtree (T, 'SL ~ PL + Wide'); Mdl2.PredictorNames ## predict matches the table's variables by name, so their order does not ## matter and a column the model was not fitted on is passed over yFit = predict (Mdl, T(1:5, [5, 3, 2, 1, 4])); yFit' ***** test # MATLAB parity: the tree a default fit grows on carsmall load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = fitrtree (X, MPG); assert_equal (class (Mdl), 'RegressionTree'); assert_equal (Mdl.NumNodes, 37); assert_equal (Mdl.NumObservations, 94); assert_equal (sum (Mdl.RowsUsed), 94); assert_equal (Mdl.NodeSize(1:9)', [94, 58, 36, 40, 17, 8, 28, 18, 22]); assert_equal (Mdl.CutPredictorIndex(1:5)', [1, 3, 3, 1, 2]); assert_equal (Mdl.CutPoint(1:5)', [3085.5, 89, 115, 2162, 5], 1e-12); ***** test # MATLAB parity: the node statistics of the carsmall tree load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = fitrtree (X, MPG); assert_equal (Mdl.NodeMean(1:5)', [23.7181, 28.7931, 15.5417, 30.9375, ... 24.0882], 1e-4); assert_equal (Mdl.NodeError(1:5)', [63.8859, 30.4400, 9.4219, 24.9648, ... 10.1834], 1e-4); assert_equal (Mdl.NodeProbability(1:3)', [94, 58, 36] / 94, 1e-14); assert_equal (Mdl.NodeRisk, Mdl.NodeProbability .* Mdl.NodeError, 1e-14); ***** test # MATLAB parity: predict, its two outputs and the loss load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = fitrtree (X, MPG); [yFit, node] = predict (Mdl, X([1, 20, 60], :)); assert_equal (node', [20, 13, 36]); assert_equal (yFit', [17.25, 12.3333333333333, 29.1], 1e-12); assert_equal (resubLoss (Mdl), 5.5828069902791, 1e-12); assert_equal (loss (Mdl, X, MPG), 5.5828069902791, 1e-12); ***** test # MATLAB parity: the pruning sequence of the carsmall tree ## One row of carsmall has no horsepower, and node 2 cuts on horsepower, ## so that row stops there and belongs to neither child. Its share of ## the node's error is part of the subtree's risk, which is what puts ## this alpha at 5.99 rather than 6.32. load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = fitrtree (X, MPG); assert_equal (Mdl.NodeSize(2) - sum (Mdl.NodeSize(Mdl.Children(2,:))), 1); assert_equal (Mdl.PruneList(1:5)', [17, 16, 14, 15, 13]); assert_equal (numel (Mdl.PruneAlpha), 18); assert_equal (Mdl.PruneAlpha(17), 5.99325416896717, 1e-12); assert_equal (Mdl.PruneAlpha(18), 41.4954735525515, 1e-11); ***** test # MATLAB parity: predictor importance discounts what a node holds back load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = fitrtree (X, MPG); assert_equal (predictorImportance (Mdl), ... [2.5904, 0.1006, 0.5499], 1e-4); Sub = fitrtree (X, MPG, 'MinLeafSize', 15); assert_equal (predictorImportance (Sub), ... [11.253155105041, 0, 1.49831354224175], 1e-12); ***** test # MATLAB parity: a smaller tree, its sequence and its text form load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = fitrtree (X, MPG, 'MinLeafSize', 15); assert_equal (Mdl.NumNodes, 9); assert_equal (Mdl.NodeSize', [94, 58, 36, 40, 17, 15, 21, 18, 22]); assert_equal (Mdl.PruneList', [4, 3, 1, 2, 0, 0, 0, 0, 0]); assert_equal (Mdl.PruneAlpha', [0, 1.56476063829787, 1.95238622931442, ... 5.99325416896717, 41.4954735525515], 1e-11); ***** test # MATLAB parity: the growth options that stop the tree early load carsmall X = [Weight, Cylinders, Horsepower]; assert_equal (fitrtree (X, MPG, 'MinParentSize', 20).NumNodes, 15); assert_equal (fitrtree (X, MPG, 'MinLeafSize', 15).NumNodes, 9); assert_equal (fitrtree (X, MPG, 'MaxNumSplits', 3).NumNodes, 7); assert_equal (fitrtree (X, MPG, 'MergeLeaves', 'off').NumNodes, 37); assert_equal (fitrtree (X, MPG, ... 'QuadraticErrorTolerance', 0.01).NumNodes, 27); ***** test # MATLAB parity: turning both reductions off leaves no sequence load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = fitrtree (X, MPG, 'MergeLeaves', 'off', 'Prune', 'off'); assert_equal (isempty (Mdl.PruneList), true); assert_equal (isempty (Mdl.PruneAlpha), true); ***** test # MATLAB parity: the weights a weighted fit reports and weighs by load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = fitrtree (X, MPG, 'Weights', (1:100)'); assert_equal (sum (Mdl.W), 1, 1e-14); assert_equal (Mdl.W(1), 0.000201328769881216, 1e-15); assert_equal (Mdl.NumNodes, 37); assert_equal (Mdl.NodeSize(1:5)', [94, 56, 38, 27, 29]); assert_equal (Mdl.NodeMean(1:3)', [26.469398026978, 30.3411058363586, ... 16.4660894660895], 1e-12); assert_equal (resubLoss (Mdl), 6.51484752783409, 1e-12); assert_equal (loss (Mdl, Mdl.X, Mdl.Y), 7.44189886464653, 1e-12); ***** test # MATLAB parity: the response transform reaches the prediction load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = fitrtree (X, MPG, 'ResponseTransform', @(y) 2 * y); assert_equal (Mdl.ResponseTransform, '@(y) 2 * y'); assert_equal (predict (Mdl, X([1, 20, 60], :))', ... [34.5, 24.6666666666667, 58.2], 1e-12); assert_equal (resubLoss (Mdl), 633.531443696713, 1e-10); ***** test # MATLAB parity: a number below the predictor count is kept load fisheriris Mdl = fitrtree (meas(:, 2:4), meas(:, 1), 'NumVariablesToSample', 2); assert_equal (Mdl.ModelParameters.NVarToSample, 2); ***** test # MATLAB parity: a number covering every predictor is reported 'all' load fisheriris Mdl = fitrtree (meas(:, 2:4), meas(:, 1), 'NumVariablesToSample', 5); assert_equal (Mdl.ModelParameters.NVarToSample, 'all'); ***** test # the generator's state reproduces a sampled tree load fisheriris rng (1); A = fitrtree (meas(:, 2:4), meas(:, 1), 'NumVariablesToSample', 1); rng (1); B = fitrtree (meas(:, 2:4), meas(:, 1), 'NumVariablesToSample', 1); assert_equal (A.CutPredictorIndex, B.CutPredictorIndex); assert_equal (isequaln (A.CutPoint, B.CutPoint), true); ***** test # MATLAB parity: a split budget spent inside a layer keeps the best load fisheriris T = fitrtree (meas(:,2:4), meas(:,1), 'MaxNumSplits', 10, 'MinLeafSize', 5); assert_equal (T.CutPredictorIndex', [2, 2, 2, 1, 2, 2, 0, 2, 1, 0, 0, ... 1, 2, 0, 0, 0, 0, 0, 0, 0, 0]); assert_equal (T.NodeSize', [150, 73, 77, 53, 20, 68, 9, 20, 33, 8, 12, ... 43, 25, 11, 9, 20, 13, 33, 10, 15, 10]); assert_equal (T.CutPoint(13), 5.65, 1e-12); ***** error fitrtree () ***** error fitrtree (ones (4, 1)) ***** error fitrtree (ones (4, 2), ones (4, 1), 'K') ***** error fitrtree (ones (4, 2), ones (3, 1)) ***** error fitrtree (ones (4, 2), ones (3, 1), 'K', 2) ***** test # MATLAB parity: a level absent from a node's rows stops there k = (0:95)'; xa = mod (k, 2); ca = mod (k, 4) + 1; ca(xa == 0 & ca == 4) = 3; y = 2 * xa + (ca >= 3) + 0.05 * cos (k); Mdl = fitrtree ([xa, ca], y, 'CategoricalPredictors', 2); assert_equal (Mdl.NumNodes, 7); assert_equal (Mdl.CutCategories(2,:), {1, 3}); [yhat, nd] = predict (Mdl, [0, 4; 1, 4; 0, 1]); assert_equal (nd', [2, 7, 4]); assert_equal (yhat', [0.50094374, 2.9994709, 0.00076071259], 1e-7); ***** shared frT load fisheriris frT = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); frT.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); frT.Flag = meas(:,1) > 5.8; ***** test # the response is named by a column and the rest are predictors Mdl = fitrtree (frT, 'SL'); assert_equal (Mdl.PredictorNames, {'SW', 'PL', 'PW', 'Wide', 'Flag'}); assert_equal (Mdl.ResponseName, 'SL'); assert_equal (class (Mdl), 'RegressionTree'); ***** test Mdl = fitrtree (frT, 'SL'); assert_equal (Mdl.CategoricalPredictors, [4, 5]); ***** test # 'CategoricalPredictors' adds to what the table says, not replaces it Mdl = fitrtree (frT, 'SL', 'CategoricalPredictors', 2); assert_equal (Mdl.CategoricalPredictors, [2, 4, 5]); ***** test # a model formula names the response and the predictors together Mdl = fitrtree (frT, 'SL ~ PL + Wide'); assert_equal (Mdl.PredictorNames, {'PL', 'Wide'}); assert_equal (Mdl.ResponseName, 'SL'); assert_equal (Mdl.CategoricalPredictors, 2); ***** test # the response may be given beside a table of predictors Mdl = fitrtree (frT(:,1:3), frT.SL); assert_equal (Mdl.PredictorNames, {'SW', 'PL', 'PW'}); assert_equal (Mdl.ResponseName, 'Y'); ***** test # a matrix is taken as it always was load fisheriris Mdl = fitrtree (meas(:,2:4), meas(:,1)); assert_equal (columns (Mdl.X), 3); assert_equal (isempty (Mdl.PredictorLevels), true); ***** error ... fitrtree (frT, 'NoSuch') ***** error ... fitrtree (frT, 'SL ~ PL*PW') ***** error ... fitrtree (frT, 'SL ~ nope') ***** error ... fitrtree (frT, 'SL ~ PL', 'PredictorNames', {'PL'}) 30 tests, 30 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitrkernel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitrkernel.m ***** demo ## Fit a Gaussian kernel regression to fuel consumption and read what the ## optimization did. load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); [Mdl, FitInfo] = fitrkernel (X(ok,:), MPG(ok)) ***** demo ## Fit from a table, and predict on one load fisheriris T = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); ## A model formula names the response and the predictors together, and ## holds main effects only Mdl = fitrkernel (T, 'SL ~ PL + PW'); Mdl.PredictorNames Mdl.ResponseName ## predict matches the table's variables by name, so a column the model ## was not fitted on is passed over yFit = predict (Mdl, T(1:5,:)); yFit' ***** test ## The driver returns a kernel regression model load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); Mdl = fitrkernel (X(ok,:), MPG(ok)); assert_equal (class (Mdl), 'RegressionKernel'); assert_equal (Mdl.Epsilon, 0.926612305411416, 1e-12); ***** test ## The options reach the model load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); Mdl = fitrkernel (X(ok,:), MPG(ok), 'Learner', 'leastsquares', ... 'Standardize', true, 'NumExpansionDimensions', 64); assert_equal (Mdl.Learner, 'leastsquares'); assert_equal (Mdl.NumExpansionDimensions, 64); assert_equal (Mdl.Mu, mean (X(ok,:)), 1e-12); ***** test ## The second output describes the optimization load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); [~, FitInfo] = fitrkernel (X(ok,:), MPG(ok)); assert_equal (FitInfo.Solver, 'LBFGS-fast'); assert_equal (FitInfo.LossFunction, 'epsiloninsensitive'); ***** test ## A cross-validation option returns a partitioned model instead load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); X = X(ok,:); Y = MPG(ok); CVMdl = fitrkernel (X, Y, 'KFold', 5); assert_equal (class (CVMdl), 'RegressionPartitionedKernel'); assert_equal (CVMdl.KFold, 5); assert_equal (numel (CVMdl.Trained), 5); ***** test ## 'CrossVal' on gives the ten folds it defaults to, and 'off' the model ## itself load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); X = X(ok,:); Y = MPG(ok); CVMdl = fitrkernel (X, Y, 'CrossVal', 'on'); assert_equal (CVMdl.KFold, 10); assert_equal (class (fitrkernel (X, Y, 'CrossVal', 'off')), ... 'RegressionKernel'); ***** error ... [Mdl, FitInfo] = fitrkernel (ones (10, 2), ones (10, 1), 'KFold', 3); ***** error fitrkernel (ones (5, 2)) ***** error ... fitrkernel (ones (10, 2), ones (10, 1), 'Learner') ***** error ... fitrkernel (ones (10, 2), ones (10, 1), 'Learner', 'logistic') ***** shared frkT load fisheriris frkT = table (meas(:,2), meas(:,3), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'SL'}); ***** test # the response is named by a column and the rest are predictors Mdl = fitrkernel (frkT, 'SL'); assert_equal (Mdl.PredictorNames, {'SW', 'PL'}); assert_equal (Mdl.ResponseName, 'SL'); ***** test # a model formula names the response and the predictors together Mdl = fitrkernel (frkT, 'SL ~ PL'); assert_equal (Mdl.PredictorNames, {'PL'}); ***** test # predict takes a table, matched by name and not by position Mdl = fitrkernel (frkT, 'SL'); a = predict (Mdl, frkT); assert_equal (predict (Mdl, frkT(:, [3, 2, 1])), a); ***** test # a cross-validated fit takes a table too Mdl = fitrkernel (frkT, 'SL', 'KFold', 3); assert_equal (class (Mdl), 'RegressionPartitionedKernel'); ***** error ... fitrkernel (frkT, 'NoSuch') 14 tests, 14 passed, 0 known failure, 0 skipped [inst/Machine_Learning/designecoc.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/designecoc.m ***** test # MATLAB parity: the pairwise design, three and four classes assert_equal (designecoc (3, 'onevsone'), [1, 1, 0; -1, 0, 1; 0, -1, -1]); assert_equal (designecoc (4, 'onevsone'), ... [1, 1, 1, 0, 0, 0; -1, 0, 0, 1, 1, 0; ... 0, -1, 0, -1, 0, 1; 0, 0, -1, 0, -1, -1]); ***** test # MATLAB parity: one class against the rest assert_equal (designecoc (3, 'onevsall'), [1, -1, -1; -1, 1, -1; -1, -1, 1]); assert_equal (designecoc (5, 'onevsall'), 2 * eye (5) - 1); ***** test # MATLAB parity: every split in two, the first class always +1 assert_equal (designecoc (3, 'binarycomplete'), ... [1, 1, 1; 1, -1, -1; -1, 1, -1]); assert_equal (designecoc (4, 'binarycomplete'), ... [1, 1, 1, 1, 1, 1, 1; 1, 1, 1, -1, -1, -1, -1; ... 1, -1, -1, 1, 1, -1, -1; -1, 1, -1, 1, -1, 1, -1]); ***** test # MATLAB parity: ordered classes, cut after each in turn assert_equal (designecoc (3, 'ordinal'), [-1, -1; 1, -1; 1, 1]); assert_equal (designecoc (4, 'ordinal'), ... [-1, -1, -1; 1, -1, -1; 1, 1, -1; 1, 1, 1]); ***** test # MATLAB parity: every split with classes left out assert_equal (designecoc (3, 'ternarycomplete'), ... [-1, -1, 0, 1, -1, -1; 1, -1, -1, -1, 0, 1; ... 0, 1, 1, 1, 1, 1]); ***** test # MATLAB parity: the widths of the five exact designs for K = [4, 5, 6, 10] assert_equal (columns (designecoc (K, 'onevsone')), K * (K - 1) / 2); assert_equal (columns (designecoc (K, 'onevsall')), K); assert_equal (columns (designecoc (K, 'ordinal')), K - 1); assert_equal (columns (designecoc (K, 'binarycomplete')), 2 ^ (K - 1) - 1); endfor ***** test # MATLAB parity: the ternary design grows as its closed form says assert_equal (columns (designecoc (6, 'ternarycomplete')), 301); ***** test # MATLAB parity: two classes are one column whatever the design for d = {'onevsone', 'onevsall', 'binarycomplete', 'ternarycomplete', ... 'ordinal'} assert_equal (designecoc (2, d{1}), [-1; 1]); endfor ***** test # a dense random design leaves no class out M = designecoc (10, 'denserandom', 'NumTrials', 20); assert_equal (rows (M), 10); assert_equal (any (M(:) == 0), false); ***** test # a sparse random design does leave classes out M = designecoc (10, 'sparserandom', 'NumTrials', 20); assert_equal (rows (M), 10); assert_equal (any (M(:) == 0), true); ***** test # every column of a random design trains a real learner M = designecoc (8, 'denserandom', 'NumTrials', 20); assert_equal (all (any (M > 0, 1) & any (M < 0, 1)), true); ***** test # a design is named without regard to case assert_equal (designecoc (4, 'OneVsAll'), designecoc (4, 'onevsall')); ***** warning ... designecoc (4, 'denserandom', 'NumTrials', 5); ***** warning ... designecoc (4, 'sparserandom', 'NumTrials', 5); ***** error designecoc (3) ***** error ... designecoc (3, 'onevsone', 'NumTrials') ***** error designecoc (1, 'onevsone') ***** error designecoc (2.5, 'onevsone') ***** error designecoc ('a', 'onevsone') ***** error designecoc (3, 42) ***** error designecoc (3, 'nosuch') ***** error ... designecoc (3, 'onevsone', 'NoSuch', 1) ***** error ... designecoc (3, 'denserandom', 'NumTrials', 0) 23 tests, 23 passed, 0 known failure, 0 skipped [inst/Machine_Learning/ClassificationNaiveBayes.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/ClassificationNaiveBayes.m ***** test # MATLAB parity: the surface a default fit reports load fisheriris Mdl = fitcnb (meas, species); assert_equal (class (Mdl), 'ClassificationNaiveBayes'); assert_equal (Mdl.NumObservations, 150); assert_equal (Mdl.ClassNames, unique (species)); assert_equal (Mdl.Prior, [1/3, 1/3, 1/3], 1e-15); assert_equal (Mdl.Cost, [0, 1, 1; 1, 0, 1; 1, 1, 0]); assert_equal (Mdl.ResponseName, 'Y'); assert_equal (Mdl.PredictorNames, {'x1', 'x2', 'x3', 'x4'}); assert_equal (Mdl.ExpandedPredictorNames, {'x1', 'x2', 'x3', 'x4'}); assert_equal (Mdl.DistributionNames, {'normal', 'normal', 'normal', 'normal'}); assert_equal (Mdl.ScoreTransform, 'none'); assert_equal (Mdl.CategoricalPredictors, []); assert_equal (Mdl.RowsUsed, []); ***** test # MATLAB parity: the properties a normal-distribution fit leaves unset load fisheriris Mdl = fitcnb (meas, species); assert_equal (Mdl.Mu, []); assert_equal (Mdl.Sigma, []); assert_equal (class (Mdl.BinEdges), 'cell'); assert_equal (Mdl.BinEdges, {}); assert_equal (Mdl.Width, NaN (3, 4)); assert_equal (Mdl.CategoricalLevels, cell (1, 4)); ***** test # MATLAB parity: the fitted normal parameters and the weights load fisheriris Mdl = fitcnb (meas, species); assert_equal (size (Mdl.DistributionParameters), [3, 4]); assert_equal (Mdl.DistributionParameters{1,1}, ... [5.005999999999998; 0.352489687213451], 1e-13); assert_equal (Mdl.DistributionParameters{2,3}, ... [4.260000000000001; 0.469910977239958], 1e-13); assert_equal (Mdl.W, repmat (1/150, 150, 1), 1e-15); assert_equal (sum (Mdl.W), 1, 1e-14); ***** test # MATLAB parity: predict returns the label, posterior and cost load fisheriris Mdl = fitcnb (meas, species); [label, score, cost] = predict (Mdl, meas(1:3,:)); assert_equal (label, {'setosa'; 'setosa'; 'setosa'}); assert_equal (score, repmat ([1, 0, 0], 3, 1), 1e-12); assert_equal (cost, repmat ([0, 1, 1], 3, 1), 1e-12); ***** test # MATLAB parity: resubstitution loss, edge and margin load fisheriris Mdl = fitcnb (meas, species); assert_equal (resubLoss (Mdl), 0.04, 1e-14); assert_equal (resubEdge (Mdl), 0.894430597464877, 1e-12); assert_equal (sum (resubMargin (Mdl)), 134.164589619731402, 1e-10); assert_equal (resubMargin (Mdl)(1:5), ones (5, 1), 1e-12); ***** test # MATLAB parity: resubPredict agrees with predict on the training data load fisheriris Mdl = fitcnb (meas, species); [rl, rs, rc] = resubPredict (Mdl); [pl, ps, pc] = predict (Mdl, meas); assert_equal (rl, pl); assert_equal (rs, ps); assert_equal (rc, pc); ***** test # MATLAB parity: every one of the eight loss functions load fisheriris Mdl = fitcnb (meas, species); assert_equal (loss (Mdl, meas, species), 0.04, 1e-14); assert_equal (loss (Mdl, meas, species, 'LossFun', 'mincost'), 0.04, 1e-14); assert_equal (loss (Mdl, meas, species, 'LossFun', 'classiferror'), ... 0.04, 1e-14); assert_equal (loss (Mdl, meas, species, 'LossFun', 'classifcost'), ... 0.04, 1e-14); assert_equal (loss (Mdl, meas, species, 'LossFun', 'binodeviance'), ... 0.149545751140664, 1e-12); assert_equal (loss (Mdl, meas, species, 'LossFun', 'exponential'), ... 0.395395632839880, 1e-12); assert_equal (loss (Mdl, meas, species, 'LossFun', 'hinge'), ... 0.052784701267562, 1e-12); assert_equal (loss (Mdl, meas, species, 'LossFun', 'logit'), ... 0.331045591275855, 1e-12); assert_equal (loss (Mdl, meas, species, 'LossFun', 'quadratic'), ... 0.033005648597277, 1e-12); ***** test # MATLAB parity: weighted loss and edge load fisheriris Mdl = fitcnb (meas, species); w = (1:150)' / sum (1:150); assert_equal (loss (Mdl, meas, species, 'Weights', w), ... 0.037013271417641, 1e-12); assert_equal (edge (Mdl, meas, species, 'Weights', w), ... 0.898902916457462, 1e-12); assert_equal (edge (Mdl, meas, species), 0.894430597464877, 1e-12); ***** test # MATLAB parity: edge on a set missing a class load fisheriris Mdl = fitcnb (meas, species); r = 51:150; assert_equal (edge (Mdl, meas(r,:), species(r)), 0.8416458962, 1e-10); ***** test # MATLAB parity: logp over all the classes load fisheriris Mdl = fitcnb (meas, species); lp = logp (Mdl, meas); assert_equal (numel (lp), 150); assert_equal (lp(1), 1.026591235856343, 1e-12); assert_equal (lp(5), 0.977098877116533, 1e-12); assert_equal (sum (lp), -309.559846128495394, 1e-10); ***** test # MATLAB parity: a given prior reweights the observations and the loss load fisheriris Mdl = fitcnb (meas, species, 'Prior', [0.2, 0.3, 0.5]); assert_equal (Mdl.Prior, [0.2, 0.3, 0.5], 1e-15); assert_equal (Mdl.W(1), 0.004, 1e-15); assert_equal (Mdl.W(51), 0.006, 1e-15); assert_equal (Mdl.W(101), 0.010, 1e-15); assert_equal (resubLoss (Mdl), 0.054, 1e-14); assert_equal (edge (Mdl, meas, species), 0.873545897578786, 1e-12); ***** test # MATLAB parity: a uniform prior, and a given cost load fisheriris Mdl = fitcnb (meas, species, 'Prior', 'uniform'); assert_equal (Mdl.Prior, [1/3, 1/3, 1/3], 1e-15); Mdl = fitcnb (meas, species, 'Cost', [0, 1, 2; 1, 0, 1; 2, 1, 0]); assert_equal (Mdl.Cost, [0, 1, 2; 1, 0, 1; 2, 1, 0]); ***** test # MATLAB parity: ScoreTransform is applied to the posterior load fisheriris Mdl = fitcnb (meas, species, 'ScoreTransform', 'logit'); assert_equal (Mdl.ScoreTransform, 'logit'); [~, score] = predict (Mdl, meas(1:2,:)); assert_equal (score, repmat ([0.731058578630005, 0.5, 0.5], 2, 1), 1e-12); ***** test # MATLAB parity: the kernel densities and their default bandwidths load fisheriris Mdl = fitcnb (meas, species, 'DistributionNames', 'kernel'); assert_equal (Mdl.DistributionNames, ... {'kernel', 'kernel', 'kernel', 'kernel'}); assert_equal (Mdl.Kernel, {'normal', 'normal', 'normal', 'normal'}); assert_equal (Mdl.Support, ... {'unbounded', 'unbounded', 'unbounded', 'unbounded'}); assert_equal (class (Mdl.DistributionParameters{1,1}), ... 'prob.KernelDistribution'); width = [0.143628884694882, 0.179536105868602, 0.071814442347441, ... 0.242194206816745; ... 0.251350548216043, 0.143628884694882, 0.251350548216043, ... 0.107721663521161; ... 0.287257769389764, 0.143628884694882, 0.323164990563484, ... 0.143628884694882]; assert_equal (Mdl.Width, width, 1e-12); ***** test # MATLAB parity: an explicit bandwidth, and a positive support load fisheriris Mdl = fitcnb (meas, species, 'DistributionNames', 'kernel', ... 'Kernel', 'triangle', 'Width', 0.5); assert_equal (Mdl.Kernel, {'triangle', 'triangle', 'triangle', 'triangle'}); assert_equal (Mdl.Width, repmat (0.5, 3, 4), 1e-15); x = [0.13; 0.41; 0.22; 1.87; 0.55; 0.09; 2.94; 0.31; 0.68; 0.17; ... 0.44; 3.61; 0.26; 0.72; 0.05; 1.13; 0.38; 0.91; 0.19; 4.52]; y = [1.02; 1.44; 0.87; 1.19; 2.63; 1.07; 0.95; 1.31; 1.76; 1.12; ... 0.99; 1.28; 3.41; 1.05; 1.21; 0.93; 1.38; 1.14; 1.09; 2.02]; G = [repmat({'a'}, 20, 1); repmat({'b'}, 20, 1)]; Mdl = fitcnb ([x; y], G, 'DistributionNames', 'kernel'); assert_equal (Mdl.Width, ... [0.237209723894721; 0.138012930266019], 1e-12); Mdl = fitcnb ([x; y], G, 'DistributionNames', 'kernel', ... 'Support', 'positive'); assert_equal (Mdl.Width, ... [0.675582146901479; 0.127329555528534], 1e-12); ***** test # MATLAB parity: a kernel model classifies as MATLAB does x = [0.13; 0.41; 0.22; 1.87; 0.55; 0.09; 2.94; 0.31; 0.68; 0.17; ... 0.44; 3.61; 0.26; 0.72; 0.05; 1.13; 0.38; 0.91; 0.19; 4.52]; y = [1.02; 1.44; 0.87; 1.19; 2.63; 1.07; 0.95; 1.31; 1.76; 1.12; ... 0.99; 1.28; 3.41; 1.05; 1.21; 0.93; 1.38; 1.14; 1.09; 2.02]; G = [repmat({'a'}, 20, 1); repmat({'b'}, 20, 1)]; Mdl = fitcnb ([x; y], G, 'DistributionNames', 'kernel'); [label, score] = predict (Mdl, [0.5; 1.5; 3.0]); assert_equal (label, {'a'; 'b'; 'a'}); assert_equal (score, [0.991485542298633, 0.008514457701367; ... 0.121739189175926, 0.878260810824074; ... 0.936549935287367, 0.063450064712633], 1e-12); assert_equal (resubLoss (Mdl), 0.075, 1e-14); ***** test # MATLAB parity: one distribution per predictor load fisheriris Mdl = fitcnb (meas, species, 'DistributionNames', ... {'normal', 'kernel', 'normal', 'kernel'}); assert_equal (Mdl.DistributionNames, ... {'normal', 'kernel', 'normal', 'kernel'}); assert_equal (class (Mdl.DistributionParameters{1,1}), 'double'); assert_equal (class (Mdl.DistributionParameters{1,2}), ... 'prob.KernelDistribution'); assert_equal (Mdl.DistributionParameters{1,2}.Bandwidth, ... 0.179536105868602, 1e-12); ***** test # MATLAB parity: ModelParameters load fisheriris Mdl = fitcnb (meas, species); assert_equal (fieldnames (Mdl.ModelParameters), ... {'DistributionNames'; 'Kernel'; 'Support'; 'Width'; ... 'StandardizeData'; 'Version'; 'Method'; 'Type'}); assert_equal (Mdl.ModelParameters.DistributionNames, 'normal'); assert_equal (Mdl.ModelParameters.Kernel, []); assert_equal (Mdl.ModelParameters.Method, 'NaiveBayes'); assert_equal (Mdl.ModelParameters.Type, 'classification'); assert_equal (Mdl.ModelParameters.Version, 1); Mdl = fitcnb (meas, species, 'DistributionNames', 'kernel'); assert_equal (Mdl.ModelParameters.DistributionNames, 'kernel'); assert_equal (Mdl.ModelParameters.Kernel, 'normal'); assert_equal (Mdl.ModelParameters.Support, 'unbounded'); assert_equal (isnan (Mdl.ModelParameters.Width), true); assert_equal (Mdl.ModelParameters.StandardizeData, 0); ***** test # naming a subset of the classes keeps only those observations load fisheriris Mdl = fitcnb (meas, species, 'ClassNames', {'setosa', 'virginica'}); assert_equal (Mdl.ClassNames, {'setosa'; 'virginica'}); assert_equal (Mdl.NumObservations, 100); assert_equal (sum (Mdl.RowsUsed), 100); assert_equal (size (Mdl.DistributionParameters), [2, 4]); assert_equal (Mdl.Prior, [0.5, 0.5], 1e-15); ***** test # a row holding a missing value is dropped, and RowsUsed says so load fisheriris X = meas; X(3,2) = NaN; X(77,4) = NaN; Mdl = fitcnb (X, species); assert_equal (Mdl.NumObservations, 148); assert_equal (sum (Mdl.RowsUsed), 148); assert_equal (Mdl.RowsUsed([3, 77]), [false; false]); assert_equal (size (Mdl.X), [150, 4]); ***** test # PredictorNames and ResponseName are carried through load fisheriris Mdl = fitcnb (meas, species, 'PredictorNames', {'a', 'b', 'c', 'd'}, ... 'ResponseName', 'flower'); assert_equal (Mdl.PredictorNames, {'a', 'b', 'c', 'd'}); assert_equal (Mdl.ExpandedPredictorNames, {'a', 'b', 'c', 'd'}); assert_equal (Mdl.ResponseName, 'flower'); ***** test # Cost and Prior may be assigned after fitting, and W follows the prior load fisheriris Mdl = fitcnb (meas, species); Mdl.Cost = [0, 2, 2; 2, 0, 2; 2, 2, 0]; assert_equal (Mdl.Cost, [0, 2, 2; 2, 0, 2; 2, 2, 0]); Mdl.Prior = [0.2, 0.3, 0.5]; assert_equal (Mdl.Prior, [0.2, 0.3, 0.5], 1e-15); assert_equal (Mdl.W(1), 0.004, 1e-15); assert_equal (Mdl.W(101), 0.010, 1e-15); ***** test # a numeric response is classified as a numeric response X = [1, 2; 1.1, 2.1; 5, 6; 5.2, 6.1; 0.9, 1.8; 5.1, 6.2]; Y = [1; 1; 2; 2; 1; 2]; Mdl = fitcnb (X, Y); assert_equal (Mdl.ClassNames, [1; 2]); assert_equal (predict (Mdl, [1, 2; 5, 6]), [1; 2]); ***** test # MATLAB parity: compact classifies identically to the model it came from load fisheriris Mdl = fitcnb (meas, species); CMdl = compact (Mdl); assert_equal (class (CMdl), 'CompactClassificationNaiveBayes'); [ml, ms] = predict (Mdl, meas); [cl, cs] = predict (CMdl, meas); assert_equal (cl, ml); assert_equal (cs, ms); assert_equal (loss (CMdl, meas, species), 0.04, 1e-14); assert_equal (edge (CMdl, meas, species), 0.894430597464877, 1e-12); ***** test # MATLAB parity: leave-one-out cross-validation load fisheriris Mdl = fitcnb (meas, species); CVMdl = crossval (Mdl, 'Leaveout', 'on'); assert_equal (class (CVMdl), 'ClassificationPartitionedModel'); assert_equal (CVMdl.KFold, 150); assert_equal (class (CVMdl.Trained{1}), 'CompactClassificationNaiveBayes'); assert_equal (kfoldLoss (CVMdl), 0.046666666666667, 1e-12); assert_equal (sum (strcmp (kfoldPredict (CVMdl), species)), 143); ***** test # a k-fold partition holds k folds, each a model of its own load fisheriris CVMdl = crossval (fitcnb (meas, species), 'KFold', 3); assert_equal (CVMdl.KFold, 3); assert_equal (numel (CVMdl.Trained), 3); assert_equal (class (CVMdl.Trained{3}), 'CompactClassificationNaiveBayes'); assert_equal (CVMdl.CrossValidatedModel, 'NaiveBayes'); ***** test # MATLAB parity: mvmn fits a smoothed distribution over the levels X = [1, 2; 1, 3; 2, 2; 2, 3; 1, 2; 3, 1; 3, 3; 2, 1; 1, 1; 3, 2; ... 2, 2; 1, 3; 3, 1; 2, 3; 1, 1; 3, 2; 2, 1; 1, 2; 3, 3; 2, 2]; Y = [repmat({'a'}, 10, 1); repmat({'b'}, 10, 1)]; Mdl = fitcnb (X, Y, 'DistributionNames', 'mvmn', ... 'CategoricalPredictors', [1, 2]); assert_equal (Mdl.DistributionNames, {'mvmn', 'mvmn'}); assert_equal (Mdl.CategoricalPredictors, [1, 2]); assert_equal (Mdl.CategoricalLevels{1}, [1; 2; 3]); assert_equal (Mdl.CategoricalLevels{2}, [1; 2; 3]); assert_equal (Mdl.DistributionParameters{1,1}, ... [0.384615384615385; 0.307692307692308; 0.307692307692308], ... 1e-12); assert_equal (Mdl.DistributionParameters{2,2}(2), ... 0.384615384615385, 1e-12); assert_equal (all (isnan (Mdl.Width(:))), true); assert_equal (size (Mdl.Width), [2, 2]); ***** test # MATLAB parity: an mvmn model classifies as MATLAB does X = [1, 2; 1, 3; 2, 2; 2, 3; 1, 2; 3, 1; 3, 3; 2, 1; 1, 1; 3, 2; ... 2, 2; 1, 3; 3, 1; 2, 3; 1, 1; 3, 2; 2, 1; 1, 2; 3, 3; 2, 2]; Y = [repmat({'a'}, 10, 1); repmat({'b'}, 10, 1)]; Mdl = fitcnb (X, Y, 'DistributionNames', 'mvmn', ... 'CategoricalPredictors', [1, 2]); [label, score] = predict (Mdl, [1, 1; 3, 3; 2, 2]); assert_equal (label, {'a'; 'a'; 'b'}); assert_equal (score(1,1), 0.555555555555556, 1e-12); assert_equal (score(3,2), 0.555555555555556, 1e-12); assert_equal (resubLoss (Mdl), 0.45, 1e-14); assert_equal (logp (Mdl, [1, 1; 3, 3]), ... [-2.239526957026909; -2.357309992683292], 1e-12); ***** test # MATLAB parity: a level a class never took keeps a probability Z = [1, 2; 1, 3; 1, 2; 1, 3; 1, 2; 2, 1; 2, 3; 2, 1; 2, 3; 2, 2]; G = [repmat({'p'}, 5, 1); repmat({'q'}, 5, 1)]; Mdl = fitcnb (Z, G, 'DistributionNames', 'mvmn', ... 'CategoricalPredictors', [1, 2]); assert_equal (Mdl.CategoricalLevels{1}, [1; 2]); assert_equal (Mdl.DistributionParameters{1,1}, ... [0.857142857142857; 0.142857142857143], 1e-12); assert_equal (Mdl.DistributionParameters{2,1}, ... [0.142857142857143; 0.857142857142857], 1e-12); [label, score] = predict (Mdl, [2, 2; 1, 1]); assert_equal (label, {'q'; 'p'}); assert_equal (score(1,:), [0.25, 0.75], 1e-12); ***** test # MATLAB parity: naming a predictor categorical makes it mvmn X = [1, 2; 1, 3; 2, 2; 2, 3; 1, 2; 3, 1; 3, 3; 2, 1; 1, 1; 3, 2; ... 2, 2; 1, 3; 3, 1; 2, 3; 1, 1; 3, 2; 2, 1; 1, 2; 3, 3; 2, 2]; Y = [repmat({'a'}, 10, 1); repmat({'b'}, 10, 1)]; Mdl = fitcnb (X, Y, 'CategoricalPredictors', [1, 2]); assert_equal (Mdl.DistributionNames, {'mvmn', 'mvmn'}); assert_equal (Mdl.CategoricalPredictors, [1, 2]); assert_equal (Mdl.DistributionParameters{1,1}(1), ... 0.384615384615385, 1e-12); ***** test # MATLAB parity: a normal and a categorical predictor side by side X = [1, 2; 1, 3; 2, 2; 2, 3; 1, 2; 3, 1; 3, 3; 2, 1; 1, 1; 3, 2; ... 2, 2; 1, 3; 3, 1; 2, 3; 1, 1; 3, 2; 2, 1; 1, 2; 3, 3; 2, 2]; Y = [repmat({'a'}, 10, 1); repmat({'b'}, 10, 1)]; Mdl = fitcnb (X, Y, 'DistributionNames', {'normal', 'mvmn'}, ... 'CategoricalPredictors', 2); assert_equal (Mdl.DistributionNames, {'normal', 'mvmn'}); assert_equal (isempty (Mdl.CategoricalLevels{1}), true); assert_equal (Mdl.CategoricalLevels{2}, [1; 2; 3]); assert_equal (Mdl.DistributionParameters{1,1}, ... [1.900000000000001; 0.875595035770913], 1e-12); assert_equal (Mdl.DistributionParameters{1,2}(2), ... 0.384615384615385, 1e-12); ***** test # MATLAB parity: mn over token counts C = [2, 0, 1; 1, 3, 0; 0, 1, 4; 3, 1, 0; ... 0, 2, 2; 1, 0, 3; 4, 1, 1; 0, 3, 2]; L = [repmat({'x'}, 4, 1); repmat({'y'}, 4, 1)]; Mdl = fitcnb (C, L, 'DistributionNames', 'mn'); assert_equal (Mdl.DistributionNames, 'mn'); assert_equal (class (Mdl.DistributionNames), 'char'); assert_equal (size (Mdl.DistributionParameters), [2, 3]); assert_equal (Mdl.DistributionParameters{1,1}, 0.368421052631579, 1e-12); assert_equal (Mdl.DistributionParameters{1,2}, 0.315789473684211, 1e-12); assert_equal (Mdl.DistributionParameters{2,3}, 0.409090909090909, 1e-12); assert_equal (Mdl.CategoricalPredictors, []); ***** test # MATLAB parity: an mn model classifies as MATLAB does C = [2, 0, 1; 1, 3, 0; 0, 1, 4; 3, 1, 0; ... 0, 2, 2; 1, 0, 3; 4, 1, 1; 0, 3, 2]; L = [repmat({'x'}, 4, 1); repmat({'y'}, 4, 1)]; Mdl = fitcnb (C, L, 'DistributionNames', 'mn'); [label, score] = predict (Mdl, [1, 1, 1; 4, 0, 0]); assert_equal (label, {'x'; 'x'}); assert_equal (score(1,1), 0.508585484679865, 1e-12); assert_equal (score(2,1), 0.769060987976952, 1e-12); assert_equal (resubLoss (Mdl), 0.25, 1e-14); ***** test # MATLAB parity: an unseen level falls back to the prior Z = [1, 1; 1, 1; 1, 2; 2, 2; 2, 2; 2, 1; 1, 1; 2, 2]; G = [repmat({'p'}, 4, 1); repmat({'q'}, 4, 1)]; Mdl = fitcnb (Z, G, 'DistributionNames', 'mvmn', ... 'CategoricalPredictors', [1, 2]); [~, score] = predict (Mdl, [1, 1]); assert_equal (score, [0.666666666666667, 0.333333333333333], 1e-12); [~, score, cost] = predict (Mdl, [3, 1]); assert_equal (score, [0.5, 0.5], 1e-12); assert_equal (cost, [0.5, 0.5], 1e-12); [~, score] = predict (Mdl, [3, 3]); assert_equal (score, [0.5, 0.5], 1e-12); assert_equal (logp (Mdl, [1, 1]), -1.386294361119891, 1e-12); assert_equal (logp (Mdl, [3, 1]), -Inf); ***** test # MATLAB parity: the fallback is the prior, not a uniform distribution Z = [1, 1; 1, 1; 1, 2; 1, 2; 1, 1; 1, 2; 2, 2; 2, 1]; G = [repmat({'p'}, 6, 1); repmat({'q'}, 2, 1)]; Mdl = fitcnb (Z, G, 'DistributionNames', 'mvmn', ... 'CategoricalPredictors', [1, 2]); assert_equal (Mdl.Prior, [0.75, 0.25], 1e-15); [~, score] = predict (Mdl, [3, 1]); assert_equal (score, [0.75, 0.25], 1e-12); Mdl = fitcnb (Z, G, 'DistributionNames', 'mvmn', ... 'CategoricalPredictors', [1, 2], 'Prior', [0.2, 0.8]); [label, score] = predict (Mdl, [3, 1]); assert_equal (score, [0.2, 0.8], 1e-12); assert_equal (label, {'q'}); ***** test # MATLAB parity: an informative predictor cannot rescue the row Z = [1, 1; 1, 1; 1, 2; 2, 2; 2, 2; 2, 1; 1, 1; 2, 2]; G = [repmat({'p'}, 4, 1); repmat({'q'}, 4, 1)]; Mdl = fitcnb (Z, G, 'DistributionNames', {'normal', 'mvmn'}, ... 'CategoricalPredictors', 2); [~, score] = predict (Mdl, [1, 3]); assert_equal (score, [0.5, 0.5], 1e-12); assert_equal (logp (Mdl, [1, 3]), -Inf); ***** warning ... fitcnb ([1, 2; 2, 1; 1, 1; 2, 2], [1; 1; 2; 2], ... 'DistributionNames', 'mvmn'); ***** test # the warning is not raised when the predictor is already categorical Mdl = fitcnb ([1, 2; 2, 1; 1, 1; 2, 2], [1; 1; 2; 2], ... 'DistributionNames', 'mvmn', 'CategoricalPredictors', 'all'); assert_equal (Mdl.CategoricalPredictors, [1, 2]); assert_equal (Mdl.DistributionNames, {'mvmn', 'mvmn'}); ***** test load fisheriris Mdl = fitcnb (meas, species); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2), 'ClassificationNaiveBayes'); p = properties (Mdl); for i = 1:numel (p) assert_equal (M2.(p{i}), Mdl.(p{i})); endfor assert_equal (predict (M2, meas(1:10,:)), predict (Mdl, meas(1:10,:))); ***** test load fisheriris Mdl = fitcnb (meas, species, 'DistributionNames', 'kernel'); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2.DistributionParameters{1,1}), ... 'prob.KernelDistribution'); assert_equal (M2.Width, Mdl.Width); assert_equal (predict (M2, meas(1:10,:)), predict (Mdl, meas(1:10,:))); assert_equal (logp (M2, meas(1:10,:)), logp (Mdl, meas(1:10,:)), 1e-12); ***** test load fisheriris X = [meas, round(meas(:,1))]; Mdl = fitcnb (X, species, 'DistributionNames', ... {'normal', 'kernel', 'normal', 'kernel', 'mvmn'}, ... 'CategoricalPredictors', 5, ... 'Cost', [0, 2, 1; 1, 0, 1; 1, 1, 0]); Mdl.ScoreTransform = 'logit'; fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.Cost, Mdl.Cost); assert_equal (M2.ScoreTransform, 'logit'); assert_equal (M2.CategoricalLevels, Mdl.CategoricalLevels); [l1, s1] = predict (Mdl, X(1:10,:)); [l2, s2] = predict (M2, X(1:10,:)); assert_equal (l2, l1); assert_equal (s2, s1); ***** test load fisheriris Mdl = fitcnb (meas(51:150,:), categorical (species(51:150))); assert_equal (categories (Mdl.ClassNames), {'versicolor'; 'virginica'}); ***** error ... savemodel (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])) ***** error ... savemodel (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), 1) ***** error ... savemodel (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), ['ab'; 'cd']) ***** error ... fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], 'DistributionNames', {'mn', 'normal'}) ***** error ... fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], 'CategoricalPredictors', 'some') ***** error ... fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], 'CategoricalPredictors', [true, true, true]) ***** error ... fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], 'CategoricalPredictors', 5) ***** test # MATLAB parity: predict skips a NaN predictor load fisheriris Mdl = fitcnb (meas, species); [label, score, cost] = predict (Mdl, [NaN, 3, 1, 0.2]); assert_equal (label, {'setosa'}); assert_equal (score, [1, 0, 0], 1e-12); assert_equal (cost, [0, 1, 1], 1e-12); [~, s1] = predict (Mdl, [5.1, 3.5, 1.4, 0.2]); [~, s2] = predict (Mdl, [5.1, NaN, 1.4, 0.2]); assert_equal (s2, s1, 1e-12); [~, s3] = predict (Mdl, [NaN, NaN, NaN, NaN]); assert_equal (s3, Mdl.Prior, 1e-12); ***** test # MATLAB parity: logp of an incomplete observation is NaN load fisheriris Mdl = fitcnb (meas, species); assert_equal (isnan (logp (Mdl, [NaN, 3, 1, 0.2])), true); assert_equal (isnan (logp (Mdl, [5.1, NaN, 1.4, 0.2])), true); assert_equal (logp (Mdl, [5.1, 3.5, 1.4, 0.2]), 1.026591235856343, 1e-12); ***** test # MATLAB parity: a row with a missing predictor still counts in a loss load fisheriris Mdl = fitcnb (meas, species); X = [meas; NaN, 3, 1, 0.2]; Y = [species; {'setosa'}]; assert_equal (loss (Mdl, X, Y), 0.04, 1e-14); assert_equal (loss (Mdl, X, Y, 'LossFun', 'classiferror'), 0.04, 1e-14); ***** test # MATLAB parity: a kernel fits data a normal cannot X = [1, 2; 2, 3; 3, 4; 10, 20; 10, 25]; Y = [1; 1; 1; 2; 2]; Mdl = fitcnb (X, Y, 'DistributionNames', 'kernel'); assert_equal (class (Mdl), 'ClassificationNaiveBayes'); assert_equal (Mdl.Width(2,1), 1, 1e-12); Mdl = fitcnb (X, Y, 'DistributionNames', 'mvmn', ... 'CategoricalPredictors', [1, 2]); assert_equal (Mdl.CategoricalLevels{1}, [1; 2; 3; 10]); ***** test # MATLAB parity: only the degenerate combination is refused X = [1, 2; 2, 3; 3, 4; 10, 20; 10, 25]; Y = [1; 1; 1; 2; 2]; Mdl = fitcnb (X, Y, 'DistributionNames', {'kernel', 'normal'}); assert_equal (Mdl.DistributionNames, {'kernel', 'normal'}); assert_equal (Mdl.DistributionParameters{2,2}, [22.5; 3.535533905932738], ... 1e-12); ***** test # A categorical 'ClassNames' keeps only the classes it names load fisheriris Mdl = ClassificationNaiveBayes (meas, categorical (species), ... 'ClassNames', categorical ({'versicolor'; 'virginica'})); assert_equal (Mdl.NumObservations, 100); assert_equal (class (Mdl.ClassNames), 'categorical'); ***** test # cellstr 'ClassNames' over a categorical response keep its type load fisheriris Mdl = ClassificationNaiveBayes (meas, categorical (species), ... 'ClassNames', {'virginica'; 'versicolor'}); assert_equal (class (Mdl.ClassNames), 'categorical'); assert_equal (cellstr (Mdl.ClassNames), {'virginica'; 'versicolor'}); assert_equal (Mdl.NumObservations, 100); ***** error ... ClassificationNaiveBayes ([1, 2; 2, 3; 3, 4; 4, 5]) ***** error ... ClassificationNaiveBayes ([1, 2; 2, 3; 3, 4; 4, 5], ones (4, 1), 'Prior') ***** error ... ClassificationNaiveBayes ('a', ones (4, 1)) ***** error ... ClassificationNaiveBayes ([1, 2; 2, 3; 3, 4; 4, 5], ones (3, 1)) ***** error ... ClassificationNaiveBayes ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], 'PredictorNames', 5) ***** error ... ClassificationNaiveBayes ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], 'PredictorNames', {'a'}) ***** error ... ClassificationNaiveBayes ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], 'ResponseName', 5) ***** error ... ClassificationNaiveBayes ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], 'ClassNames', [1, 3]) ***** error ... ClassificationNaiveBayes ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], 'nope', 1) ***** error ... ClassificationNaiveBayes ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], ... 'DistributionNames', 'poisson') ***** error ... ClassificationNaiveBayes ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], ... 'DistributionNames', {'normal'}) ***** error ... ClassificationNaiveBayes ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], ... 'DistributionNames', 'kernel', 'Kernel', 'cosine') ***** error ... ClassificationNaiveBayes ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], ... 'DistributionNames', 'kernel', 'Width', -1) ***** error ... predict (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])) ***** error ... predict (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), []) ***** error ... predict (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), ones (2, 3)) ***** error ... loss (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), [1, 2; 2, 3; 3, 4; 4, 5]) ***** error ... loss (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), [1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], ... 'LossFun', 'nope') ***** error ... loss (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), ... [1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], 'Bogus', 1) ***** error ... loss (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), [1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], ... 'Weights', [1, 2]) ***** error ... margin (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), [1, 2; 2, 3; 3, 4; 4, 5]) ***** error ... edge (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), [1, 2; 2, 3; 3, 4; 4, 5]) ***** error ... logp (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), []) ***** error ... crossval (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), 'KFold', 1) ***** error ... crossval (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), 'Leaveout', 5) ***** error ... crossval (fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), 'KFold', 2, 'Leaveout', 'on') ***** error ... fitcnb ([1, 2; 2, 3; 3, 4; 10, 20], [1; 1; 1; 2]) ***** error ... fitcnb ([1, 2; 2, 3; 3, 4; 10, 20; 10, 25], [1; 1; 1; 2; 2]) ***** error ... fitcnb ([1, 2; 2, 3; 3, 4; 10, 20; 10, 25], ... [{'alpha'}; {'alpha'}; {'alpha'}; {'beta'}; {'beta'}]) ***** error ... fitcnb ([1, 2; 2, 3; 3, 4; 10, 20; 10, 25], [1; 1; 1; 2; 2], ... 'PredictorNames', {'height', 'weight'}) ***** error ... fitcnb ([5, 2; 5, 3; 5, 4; 10, 20; 11, 25], [1; 1; 1; 2; 2]) ***** test load fisheriris Mdl = fitcnb (meas, species); assert_equal (isempty (Mdl.HyperparameterOptimizationResults), true); ***** test load fisheriris Mdl = fitcnb (meas, species); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); T = {'identity', @(x) x; 'doublelogit', @(x) 1 ./ (1 + exp (-2 * x)); ... 'invlogit', @(x) log (x ./ (1 - x)); ... 'logit', @(x) 1 ./ (1 + exp (-x)); ... 'sign', @(x) sign (x); 'symmetric', @(x) 2 * x - 1; ... 'symmetriclogit', @(x) 2 ./ (1 + exp (-x)) - 1}; for i = 1:rows (T) Mdl.ScoreTransform = T{i,1}; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, T{i,2}(raw), 1e-12); assert_equal (l, label); endfor ## ismax marks the largest score of each observation, ties to the first. [~, k] = max (raw, [], 2); e = zeros (size (raw)); e(sub2ind (size (raw), (1:rows (raw))', k)) = 1; Mdl.ScoreTransform = 'ismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, e); Mdl.ScoreTransform = 'symmetricismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, 2 * e - 1); ***** test load fisheriris Mdl = fitcnb (meas, species); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); Mdl.ScoreTransform = @(x) x .^ 2; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, raw .^ 2, 1e-12); assert_equal (l, label); ***** test # the class may be built from a table as the fitter builds it load fisheriris T = table (meas(:,1), meas(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = categorical (species); Mdl = ClassificationNaiveBayes (T, 'Species'); assert_equal (Mdl.PredictorNames, {'SL', 'SW'}); assert_equal (Mdl.ResponseName, 'Species'); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcnb (T, 'Species'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcnb (T, 'Species'); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcnb (T, 'Species'); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** test # a table is matched to the predictors by name load fisheriris T = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = categorical (species); Mdl = fitcnb (T, 'Species'); a = logp (Mdl, meas); assert_equal (logp (Mdl, T(:,1:4)), a); assert_equal (logp (Mdl, T(:,[5, 4, 2, 3, 1])), a); ***** error ... loss (fitcnb ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2]), ... [1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', int8 ([1; 1; 1; 1])) ***** error ... ClassificationNaiveBayes ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], ... 'Weights', int8 ([1; 1; 1; 1])) ***** error ... ClassificationNaiveBayes ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], ... 'Weights', true (4, 1)) ***** error ... ClassificationNaiveBayes ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], ... 'Weights', [1; 1]) ***** error ... ClassificationNaiveBayes ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], ... 'Weights', [1; -1; 1; 1]) ***** test ## An empirical prior and a normal density weigh the observations load fisheriris Mdl = ClassificationNaiveBayes (meas, species, 'Weights', 1 + (1:150)' / 7); assert_equal (Mdl.Prior, [0.1313131313131313, 0.3333333333333333, ... 0.5353535353535354], 1e-15); assert_equal (Mdl.DistributionParameters{1,1}, ... [5.0008; 0.3400154735180538], 1e-13); ***** test ## A kernel density weighs the observations, its bandwidth does not load fisheriris Mdl = ClassificationNaiveBayes (meas, species, ... 'Weights', 1 + (1:150)' / 7, ... 'DistributionNames', 'kernel'); Mdl0 = ClassificationNaiveBayes (meas, species, ... 'DistributionNames', 'kernel'); assert_equal (Mdl.Width, Mdl0.Width); [~, Posterior] = predict (Mdl, meas(51,:)); assert_equal (Posterior, [0, 0.7141545707763224, 0.2858454292236776], 1e-12); ***** test ## A multivariate multinomial counts the observations by their weights load fisheriris Mdl = ClassificationNaiveBayes (round (meas), species, ... 'Weights', 1 + (1:150)' / 7, ... 'DistributionNames', 'mvmn'); assert_equal (Mdl.DistributionParameters{1,1}, ... [0.09258741258741258; 0.7655944055944056; ... 0.1054545454545455; 0.01818181818181818; ... 0.01818181818181818], 1e-15); warning: ClassificationNaiveBayes: the 'mvmn' distribution was named for a predictor that is not in 'CategoricalPredictors', which is updated to include every 'mvmn' predictor. warning: called from ClassificationNaiveBayes at line 599 column 11 __test__ at line 5 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 3958 column 2 ***** test ## A multinomial counts the tokens by their weights load fisheriris Mdl = ClassificationNaiveBayes (round (meas * 2), species, ... 'Weights', 1 + (1:150)' / 7, ... 'DistributionNames', 'mn'); assert_equal ([Mdl.DistributionParameters{1,:}], ... [0.4954405908994194, 0.3390224626888355, ... 0.1481959937992036, 0.01734095261254141], 1e-15); ***** test ## Rows of zero weight are left out, as R2024a leaves them load fisheriris w = 1 + (1:150)' / 7; w(5) = 0; Mdl = ClassificationNaiveBayes (meas, species, 'Weights', w); assert_equal (Mdl.NumObservations, 149); assert_equal (Mdl.RowsUsed(5), false); ***** test ## Single weights are stored single, summing to one load fisheriris Mdl = ClassificationNaiveBayes (meas, species, ... 'Weights', single (1 + (1:150)' / 7)); assert_equal (class (Mdl.W), 'single'); assert_equal (sum (double (Mdl.W)), 1, 1e-6); ***** test ## resubLoss weighs the observations by W, as R2024a does load fisheriris Mdl = ClassificationNaiveBayes (meas, species, 'Weights', 1 + (1:150)' / 7); assert_equal (resubLoss (Mdl), 0.06141414141414142, 1e-15); ***** test ## Reassigning the prior keeps W in proportion to the weights load fisheriris w = 1 + (1:150)' / 7; Mdl = ClassificationNaiveBayes (meas, species, 'Weights', w); Mdl.Prior = [1, 1, 1] / 3; assert_equal (Mdl.W(1:50), w(1:50) / sum (w(1:50)) / 3, 1e-15); ***** test ## A weighted kernel model saves and loads with its weights load fisheriris Mdl = ClassificationNaiveBayes (meas, species, ... 'Weights', 1 + (1:150)' / 7, ... 'DistributionNames', 'kernel'); fname = [tempname(), '.mat']; savemodel (Mdl, fname); Mdl2 = loadmodel (fname); delete (fname); assert_equal (nthargout (2, @predict, Mdl2, meas(51,:)), ... nthargout (2, @predict, Mdl, meas(51,:)), 1e-15); 109 tests, 109 passed, 0 known failure, 0 skipped [inst/Machine_Learning/RegressionTree.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/RegressionTree.m ***** test # MATLAB parity: the surface a default fit reports load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG); assert_equal (class (Mdl), 'RegressionTree'); assert_equal (numel (properties (Mdl)), 36); assert_equal (Mdl.NumObservations, 94); assert_equal (Mdl.ResponseName, 'Y'); assert_equal (Mdl.PredictorNames, {'x1', 'x2', 'x3'}); assert_equal (Mdl.ExpandedPredictorNames, {'x1', 'x2', 'x3'}); assert_equal (Mdl.ResponseTransform, 'none'); assert_equal (Mdl.CategoricalPredictors, []); assert_equal (sum (Mdl.W), 1, 1e-14); assert_equal (Mdl.W(1), 1 / 94, 1e-15); ***** test # MATLAB parity: the parameters a default fit reports load carsmall X = [Weight, Cylinders, Horsepower]; MP = RegressionTree (X, MPG).ModelParameters; assert_equal (MP.SplitCriterion, 'mse'); assert_equal (MP.PruneCriterion, 'mse'); assert_equal ({MP.MinParent, MP.MinLeaf, MP.MaxSplits}, {10, 1, 93}); assert_equal ({MP.MergeLeaves, MP.Prune}, {'on', 'on'}); assert_equal (MP.QEToler, 1e-6); assert_equal ({MP.NSurrogate, MP.MaxCat, MP.AlgCat}, {0, 10, 'auto'}); assert_equal ({MP.Method, MP.Type}, {'Tree', 'regression'}); ***** test # MATLAB parity: what a tree with no categories and no surrogates holds load carsmall Mdl = RegressionTree ([Weight, Cylinders, Horsepower], MPG); assert_equal (size (Mdl.CutCategories), [37, 2]); assert_equal (size (Mdl.CategoricalSplit), [0, 0]); assert_equal (size (Mdl.SurrogateCutPredictor), [0, 1]); assert_equal (size (Mdl.SurrogateCutPoint), [0, 0]); assert_equal (Mdl.BinEdges, {}); assert_equal (Mdl.HyperparameterOptimizationResults, []); ***** test # A missing response drops its row, a missing predictor does not load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG); assert_equal (Mdl.NumObservations, 94); assert_equal (numel (Mdl.RowsUsed), 100); assert_equal (sum (Mdl.RowsUsed), 94); assert_equal (Mdl.NodeSize(1), 94); ## the row with no horsepower is kept, and node 2 cuts on horsepower assert_equal (Mdl.NodeSize(2) - sum (Mdl.NodeSize(Mdl.Children(2,:))), 1); ***** test # MATLAB parity: a row missing the split predictor stops at that node load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG); [yFit, node] = predict (Mdl, [NaN, NaN, NaN]); assert_equal (node, 1); assert_equal (yFit, Mdl.NodeMean(1), 1e-15); [yFit, node] = predict (Mdl, [2000, 4, NaN]); assert_equal (node, 2); assert_equal (yFit, Mdl.NodeMean(2), 1e-15); ***** test # MATLAB parity: prune takes a subtree out of the sequence load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG, 'MinLeafSize', 15); sub = prune (Mdl, 'Level', 1); assert_equal (sub.NumNodes, 7); assert_equal (sub.NodeSize', [94, 58, 36, 40, 17, 18, 22]); assert_equal (sub.PruneList', [3, 2, 0, 1, 0, 0, 0]); assert_equal (sub.PruneAlpha', [0, 1.95238622931442, ... 5.99325416896717, 41.4954735525515], 1e-11); ***** test # MATLAB parity: a level of two, and level zero changing nothing load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG, 'MinLeafSize', 15); assert_equal (prune (Mdl, 'Level', 2).NumNodes, 5); assert_equal (prune (Mdl, 'Level', 0).NumNodes, 9); assert_equal (prune (Mdl).NumNodes, 9); assert_equal (prune (Mdl, 'Alpha', 100).NumNodes, 1); assert_equal (prune (Mdl, 'Alpha', 0).NumNodes, 9); assert_equal (prune (Mdl, 'Nodes', 2).NumNodes, 5); ***** warning load carsmall X = [Weight, Cylinders, Horsepower]; sub = prune (RegressionTree (X, MPG, 'MinLeafSize', 15), 'Level', 9); ***** test # MATLAB parity: the range of each predictor on the path to a node load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG); assert_equal (fieldnames (nodeVariableRange (Mdl, 1)), cell (0, 1)); r = nodeVariableRange (Mdl, 4); assert_equal (r.x1, [-Inf, 3085.5], 1e-12); assert_equal (r.x3, [-Inf, 89], 1e-12); ***** test # MATLAB parity: the text form of the tree load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG, 'MinLeafSize', 15); lines = strsplit (strtrim (evalc ('view (Mdl)')), "\n"); assert_equal (numel (lines), 10); assert_equal (lines{1}, 'Decision tree for regression'); assert_equal (lines{2}, ... '1 if x1<3085.5 then node 2 elseif x1>=3085.5 then node 3 else 23.7181'); assert_equal (lines{6}, '5 fit = 24.0882'); ***** test # The node numbers are right aligned on the widest of them load carsmall X = [Weight, Cylinders, Horsepower]; lines = strsplit (strtrim (evalc ('view (RegressionTree (X, MPG))')), "\n"); assert_equal (numel (lines), 38); assert_equal (lines{2}(1:2), ' 1'); assert_equal (lines{11}(1:2), '10'); ***** test # The loss takes a function handle over the true, fitted and weights load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG); r = Mdl.Y - resubPredict (Mdl); mae = @(y, yf, w) sum (w .* abs (y - yf)); assert_equal (loss (Mdl, Mdl.X, Mdl.Y, 'LossFun', mae), ... mean (abs (r)), 1e-12); assert_equal (loss (Mdl, Mdl.X, Mdl.Y, 'LossFun', 'mse'), ... resubLoss (Mdl), 1e-14); ***** test # resubPredict answers exactly as predict on the training data load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG); assert_equal (resubPredict (Mdl), predict (Mdl, Mdl.X)); ***** test # The response transform is parsed by name as well as by handle load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG, 'ResponseTransform', 'exp'); assert_equal (Mdl.ResponseTransform, 'exp'); assert_equal (predict (Mdl, X(1, :)), exp (17.25), -1e-12); Mdl.ResponseTransform = 'none'; assert_equal (predict (Mdl, X(1, :)), 17.25, 1e-12); ***** test # A tree of one node answers its mean everywhere Mdl = RegressionTree ((1:5)', [2; 2; 2; 2; 2]); assert_equal (Mdl.NumNodes, 1); assert_equal (Mdl.NodeMean, 2); assert_equal (Mdl.NodeError, 0); assert_equal (Mdl.NodeRisk, 0); assert_equal (predict (Mdl, 99), 2); assert_equal (predictorImportance (Mdl), 0); ***** test # A model saved and loaded answers exactly as it did load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG); fname = tempname (); unwind_protect savemodel (Mdl, fname); New = loadmodel (fname); assert_equal (class (New), 'RegressionTree'); assert_equal (New.NumNodes, Mdl.NumNodes); assert_equal (New.NodeRisk, Mdl.NodeRisk, 1e-15); assert_equal (New.PruneAlpha, Mdl.PruneAlpha, 1e-12); assert_equal (New.CutPredictor, Mdl.CutPredictor); assert_equal (predict (New, X), predict (Mdl, X)); unwind_protect_cleanup delete (fname); end_unwind_protect ***** test # MATLAB parity: a small fixture, every node and every alpha x = (1:12)'; y = [1; 1; 1; 1; 5; 5; 5; 5; 20; 20; 20; 20]; Mdl = RegressionTree (x, y, 'MinParentSize', 2); assert_equal (Mdl.NumNodes, 5); assert_equal (Mdl.NodeSize', [12, 8, 4, 4, 4]); assert_equal (Mdl.NodeMean', [8.66666666666666, 3, 20, 1, 5], 1e-13); assert_equal (Mdl.NodeError', [66.8888888888889, 4, 0, 0, 0], 1e-12); assert_equal (Mdl.NodeRisk', [66.8888888888889, 2.66666666666667, ... 0, 0, 0], 1e-12); assert_equal (Mdl.PruneList', [2, 1, 0, 0, 0]); assert_equal (Mdl.PruneAlpha', [0, 2.66666666666667, ... 64.2222222222222], 1e-12); assert_equal (predictorImportance (Mdl), 33.4444444444444, 1e-12); ***** test # MATLAB parity: a fixture grown to one observation per leaf x = (1:8)'; y = [1; 2; 10; 11; 30; 31; 60; 61]; Mdl = RegressionTree (x, y, 'MinParentSize', 2); assert_equal (Mdl.NumNodes, 15); assert_equal (Mdl.NodeSize', [8, 6, 2, 4, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1]); assert_equal (Mdl.NodeMean(1:5)', [25.75, 14.1666666666667, 60.5, ... 6, 30.5], 1e-13); assert_equal (Mdl.NodeRisk(1:5)', [512.9375, 110.354166666667, 0.0625, ... 10.25, 0.0625], 1e-12); assert_equal (Mdl.PruneList', [4, 3, 1, 2, 1, 0, 0, 1, 1, 0, 0, 0, 0, ... 0, 0]); assert_equal (Mdl.PruneAlpha', [0, 0.0625, 10.125, 100.041666666667, ... 402.520833333333], 1e-11); assert_equal (predictorImportance (Mdl), 73.2767857142857, 1e-12); ***** test # MATLAB parity: compact drops the data and answers identically load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG); CMdl = compact (Mdl); assert_equal (class (CMdl), 'CompactRegressionTree'); assert_equal (numel (properties (CMdl)), 28); assert_equal (predict (CMdl, X), predict (Mdl, X)); assert_equal (CMdl.NodeRisk, Mdl.NodeRisk, 1e-15); assert_equal (predictorImportance (CMdl), predictorImportance (Mdl), 1e-15); ***** test # MATLAB parity: crossval returns a partitioned model over compacts load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG); CVMdl = crossval (Mdl); assert_equal (class (CVMdl), 'RegressionPartitionedModel'); assert_equal (CVMdl.CrossValidatedModel, 'Tree'); assert_equal (class (CVMdl.Trained{1}), 'CompactRegressionTree'); assert_equal (CVMdl.KFold, 10); assert_equal (CVMdl.NumObservations, 94); assert_equal (CVMdl.ResponseName, 'Y'); assert_equal (CVMdl.W, Mdl.W, 1e-15); ***** test # Each way of asking for a partition gives the folds it names load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG); assert_equal (crossval (Mdl, 'KFold', 5).KFold, 5); assert_equal (crossval (Mdl, 'Holdout', 0.3).KFold, 1); assert_equal (crossval (Mdl, 'Leaveout', 'on').KFold, 94); assert_equal (crossval (Mdl, 'CVPartition', ... cvpartition (94, 'KFold', 4)).KFold, 4); ***** test # A fold is grown with the parameters the parent was grown with load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG, 'MinLeafSize', 7, 'MergeLeaves', 'off', ... 'QuadraticErrorTolerance', 0.01); CVMdl = crossval (Mdl, 'KFold', 3); assert_equal (CVMdl.ModelParameters.MinLeaf, 7); assert_equal (CVMdl.ModelParameters.MergeLeaves, 'off'); assert_equal (CVMdl.ModelParameters.QEToler, 0.01); assert_equal (CVMdl.Trained{1}.PredictorNames, Mdl.PredictorNames); ***** test # kfoldPredict answers every observation out of fold load carsmall X = [Weight, Cylinders, Horsepower]; CVMdl = crossval (RegressionTree (X, MPG), 'KFold', 5); yFit = kfoldPredict (CVMdl); assert_equal (size (yFit), [94, 1]); assert_equal (any (isnan (yFit)), false); assert_equal (kfoldLoss (CVMdl) > 0, true); ***** test # cvloss over a fixture whose folds all answer alike ## The two groups are separated by a gap no fold can straddle, so every ## fold grows the same tree and answers the held-out row exactly. Left ## with one leaf, a fold's tree answers the mean of the thirty-nine rows ## it saw, which is 200/39 away from whichever value was held out, ## whichever group that row came from. x = [(1:20)'; (101:120)']; y = [zeros(20, 1); 10 * ones(20, 1)]; Mdl = RegressionTree (x, y); assert_equal (Mdl.NumNodes, 3); [E, SE, Nleaf, BestLevel] = cvloss (Mdl, 'SubTrees', 'all', 'KFold', 40); assert_equal (E', [0, (200 / 39) ^ 2], 1e-12); assert_equal (SE', [0, 0], 1e-12); assert_equal (Nleaf', [2, 1]); assert_equal (BestLevel, 0); ***** test # cvloss reports one row per subtree asked for load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG, 'MinLeafSize', 15); [E, SE, Nleaf, BestLevel] = cvloss (Mdl, 'SubTrees', 'all'); assert_equal (size (E), [5, 1]); assert_equal (size (SE), [5, 1]); assert_equal (Nleaf', [5, 4, 3, 2, 1]); assert_equal (all (E > 0), true); assert_equal (BestLevel >= 0 && BestLevel <= 4, true); ## the root alone answers the mean, so it can do no better than the whole assert_equal (E(5) > E(1), true); ***** test # cvloss defaults to the unpruned tree alone load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG, 'MinLeafSize', 15); [E, SE, Nleaf, BestLevel] = cvloss (Mdl); assert_equal (size (E), [1, 1]); assert_equal (Nleaf, 5); assert_equal (BestLevel, 0); assert_equal (E > 0, true); ***** test # A subset of the levels is answered in the order it was asked for load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG, 'MinLeafSize', 15); [E, SE, Nleaf, BestLevel] = cvloss (Mdl, 'SubTrees', [0, 2, 4]); assert_equal (Nleaf', [5, 3, 1]); assert_equal (any (BestLevel == [0, 2, 4]), true); ***** test # The fold count and the tree size rule are the ones asked for load carsmall X = [Weight, Cylinders, Horsepower]; Mdl = RegressionTree (X, MPG, 'MinLeafSize', 15); assert_equal (size (cvloss (Mdl, 'KFold', 5)), [1, 1]); [~, ~, ~, bmin] = cvloss (Mdl, 'SubTrees', 'all', 'TreeSize', 'min'); [~, ~, ~, bse] = cvloss (Mdl, 'SubTrees', 'all', 'TreeSize', 'se'); assert_equal (bmin >= 0 && bmin <= 4, true); assert_equal (bse >= 0 && bse <= 4, true); ***** test # cvloss weighs the loss as the fit weighed it ## A weighted fit whose folds all answer alike. The heavier group pulls ## the one-leaf answer towards itself, and the loss counts each row by ## its weight rather than by its share of the rows. x = [(1:20)'; (101:120)']; y = [zeros(20, 1); 10 * ones(20, 1)]; Mdl = RegressionTree (x, y, 'Weights', [ones(20, 1); 3 * ones(20, 1)]); E = cvloss (Mdl, 'SubTrees', 'all', 'KFold', 40); assert_equal (E(1), 0, 1e-12); assert_equal (E(2) > 0 && E(2) < 100, true); ***** test # More folds than observations are reduced to one fold each x = [(1:20)'; (101:120)']; y = [zeros(20, 1); 10 * ones(20, 1)]; Mdl = RegressionTree (x, y); ws = warning ('off', 'all'); unwind_protect E = cvloss (Mdl, 'KFold', 500, 'SubTrees', 'all'); unwind_protect_cleanup warning (ws); end_unwind_protect assert_equal (E', [0, (200 / 39) ^ 2], 1e-12); ***** error RegressionTree () ***** error RegressionTree (ones (4, 2)) ***** error RegressionTree (ones (4, 2), (1:4)', 'K') ***** error RegressionTree ('a', (1:4)') ***** error RegressionTree (ones (4, 2), {'a'; 'b'; 'c'; 'd'}) ***** error RegressionTree (ones (4, 2), (1:3)') ***** error RegressionTree (ones (4, 2), (1:4)', 'PredictorNames', 'a') ***** error RegressionTree (ones (4, 2), (1:4)', 'PredictorNames', {'a'}) ***** error RegressionTree (ones (4, 2), (1:4)', 'ResponseName', 5) ***** error RegressionTree (ones (4, 2), (1:4)', 'ResponseTransform', 5) ***** error RegressionTree (ones (4, 2), (1:4)', 'ResponseTransform', 'bogus') ***** error RegressionTree (ones (4, 2), (1:4)', 'Weights', 'a') ***** error RegressionTree (ones (4, 2), (1:4)', 'Weights', ones (2, 2)) ***** error RegressionTree (ones (4, 2), (1:4)', 'Weights', [1, 2, 3]) ***** error RegressionTree (ones (4, 2), (1:4)', 'Weights', -ones (4, 1)) ***** error RegressionTree (ones (4, 2), (1:4)', 'MaxNumSplits', -1) ***** error RegressionTree (ones (4, 2), (1:4)', 'MinLeafSize', 0) ***** error RegressionTree (ones (4, 2), (1:4)', 'MinParentSize', 0) ***** error RegressionTree (ones (4, 2), (1:4)', 'MergeLeaves', 'x') ***** error RegressionTree (ones (4, 2), (1:4)', 'Prune', 'x') ***** error RegressionTree (ones (4, 2), (1:4)', 'QuadraticErrorTolerance', -1) ***** error RegressionTree (ones (4, 2), (1:4)', 'SplitCriterion', 'gdi') ***** error RegressionTree (ones (4, 2), (1:4)', 'PruneCriterion', 'error') ***** error RegressionTree (ones (4, 2), (1:4)', 'Surrogate', 'on') ***** error RegressionTree (ones (4, 2), (1:4)', 'KFold', 5) ***** error RegressionTree (ones (4, 2), (1:4)', 'Bogus', 1) ***** error RegressionTree (ones (4, 2), nan (4, 1)) ***** error predict (RegressionTree (ones (4, 2), (1:4)')) ***** error predict (RegressionTree (ones (4, 2), (1:4)'), []) ***** error predict (RegressionTree (ones (4, 2), (1:4)'), 'a') ***** error predict (RegressionTree (ones (4, 2), (1:4)'), ones (2, 5)) ***** error loss (RegressionTree (ones (4, 2), (1:4)'), ones (4, 2)) ***** error loss (RegressionTree (ones (4, 2), (1:4)'), ones (4, 2), (1:4)', 'LossFun') ***** error loss (RegressionTree (ones (4, 2), (1:4)'), ones (4, 2), (1:4)', ... 'LossFun', 5) ***** error loss (RegressionTree (ones (4, 2), (1:4)'), ones (4, 2), (1:4)', ... 'LossFun', 'mad') ***** error loss (RegressionTree (ones (4, 2), (1:4)'), ones (4, 2), (1:4)', ... 'LossFun', @(y, f, w) [1, 2]) ***** error loss (RegressionTree (ones (4, 2), (1:4)'), ones (4, 2), (1:4)', ... 'Weights', 'a') ***** error loss (RegressionTree (ones (4, 2), (1:4)'), ones (4, 2), (1:4)', ... 'Weights', ones (2, 2)) ***** error loss (RegressionTree (ones (4, 2), (1:4)'), ones (4, 2), (1:4)', ... 'Weights', [1, 2]) ***** error loss (RegressionTree (ones (4, 2), (1:4)'), ones (4, 2), (1:4)', 'Bogus', 1) ***** error loss (RegressionTree (ones (4, 2), (1:4)'), ones (4, 2), (1:3)') ***** error prune (RegressionTree (ones (4, 2), (1:4)'), 'Level') ***** error prune (RegressionTree (ones (4, 2), (1:4)'), 'Level', 1, 'Alpha', 1) ***** error prune (RegressionTree (ones (4, 2), (1:4)'), 'Level', -1) ***** error prune (RegressionTree (ones (4, 2), (1:4)'), 'Alpha', -1) ***** error prune (RegressionTree (ones (4, 2), (1:4)'), 'Nodes', 999) ***** error prune (RegressionTree (ones (4, 2), (1:4)'), 'Bogus', 1) ***** error nodeVariableRange (RegressionTree (ones (4, 2), (1:4)')) ***** error nodeVariableRange (RegressionTree (ones (4, 2), (1:4)'), 999) ***** error cvloss (RegressionTree (ones (4, 2), (1:4)'), 'SubTrees') ***** error load carsmall cvloss (RegressionTree ([Weight, Cylinders], MPG), 'SubTrees', -1) ***** error load carsmall cvloss (RegressionTree ([Weight, Cylinders], MPG), 'SubTrees', [2, 1]) ***** error load carsmall X = [Weight, Cylinders, Horsepower]; cvloss (RegressionTree (X, MPG, 'MinLeafSize', 15), 'SubTrees', 99) ***** error load carsmall cvloss (RegressionTree ([Weight, Cylinders], MPG), 'TreeSize', 'x') ***** error load carsmall cvloss (RegressionTree ([Weight, Cylinders], MPG), 'KFold', 1) ***** error load carsmall cvloss (RegressionTree ([Weight, Cylinders], MPG), 'Bogus', 1) ***** error load carsmall cvloss (RegressionTree ([Weight, Cylinders], MPG, 'Prune', 'off', ... 'MergeLeaves', 'off')) ***** error crossval (RegressionTree (ones (4, 2), (1:4)'), 'KFold') ***** error crossval (RegressionTree (ones (4, 2), (1:4)'), 'KFold', 2, 'Holdout', 0.3) ***** error crossval (RegressionTree (ones (4, 2), (1:4)'), 'KFold', 1) ***** error crossval (RegressionTree (ones (4, 2), (1:4)'), 'Holdout', 2) ***** error crossval (RegressionTree (ones (4, 2), (1:4)'), 'Leaveout', 'x') ***** error crossval (RegressionTree (ones (4, 2), (1:4)'), 'CVPartition', 5) ***** error crossval (RegressionTree (ones (4, 2), (1:4)'), 'Bogus', 1) ***** error savemodel (RegressionTree (ones (4, 2), (1:4)')) ***** error savemodel (RegressionTree (ones (4, 2), (1:4)'), 5) ***** error RegressionTree (ones (4, 2), [1; 2; 3; 4], 'NumVariablesToSample', 0) ***** error RegressionTree (ones (4, 2), [1; 2; 3; 4], 'NumVariablesToSample', 1.5) ***** error RegressionTree (ones (4, 2), [1; 2; 3; 4], 'NumVariablesToSample', 'some') ***** shared Xr, yr k = (0:99)'; c = mod (k, 5) + 1; means = [3, 1, 4, 1.5, 5]; yr = means(c)' + 0.1 * sin (k); Xr = [c, mod(k * 3, 8)]; ***** test # MATLAB parity: levels are ordered by their mean response Mdl = RegressionTree (Xr, yr, 'CategoricalPredictors', 1); assert_equal (Mdl.NumNodes, 39); assert_equal (Mdl.CutCategories(1,:), {[2, 4], [1, 3, 5]}); [yhat, nd] = predict (Mdl, [1, 0; 3, 0; 6, 0; NaN, 0]); assert_equal (yhat', [2.9817303, 4.0402625, 2.9003792, 2.9003792], 1e-7); assert_equal (nd', [12, 24, 1, 1]); ***** test # a categorical predictor may be named rather than indexed Mdl = RegressionTree (Xr, yr, 'PredictorNames', {'grp', 'val'}, ... 'CategoricalPredictors', {'grp'}); assert_equal (Mdl.CategoricalPredictors, 1); assert_equal (Mdl.CutCategories(1,:), {[2, 4], [1, 3, 5]}); ***** test # MATLAB parity: view and nodeVariableRange of a categorical cut Mdl = RegressionTree (Xr(:,1), yr, 'CategoricalPredictors', 1, ... 'MaxNumSplits', 2); txt = evalc ('view (Mdl)'); assert_equal (! isempty (strfind (txt, ['1 if x1 in {2 4} then node 2', ... ' elseif x1 in {1 3 5} then node 3 else 2.90038'])), true); assert_equal (! isempty (strfind (txt, ['3 if x1=1 then node 4', ... ' elseif x1 in {3 5} then node 5 else 4.00008'])), true); assert_equal (nodeVariableRange (Mdl, 3), struct ('x1', [1, 3, 5])); ***** test # MaxNumCategories is recorded, and the level sets are saved Mdl = RegressionTree (Xr, yr, 'CategoricalPredictors', 1, ... 'MaxNumCategories', 2); assert_equal (Mdl.ModelParameters.MaxCat, 2); assert_equal (Mdl.NumNodes, 39); fname = [tempname(), '.mdl']; savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (predict (M2, Xr), predict (Mdl, Xr)); ***** error ... RegressionTree (Xr, yr, 'CategoricalPredictors', 3) ***** error ... RegressionTree (Xr, yr, 'MaxNumCategories', 1.5) ***** error ... RegressionTree (Xr, yr, 'AlgorithmForCategorical', 'pca') ***** shared rtT, rtM load fisheriris rtT = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); rtT.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); rtM = fitrtree (rtT, 'SL'); ***** test # the class may be built from a table as the fitter builds it Mdl = RegressionTree (rtT, 'SL'); assert_equal (Mdl.PredictorNames, rtM.PredictorNames); assert_equal (Mdl.CategoricalPredictors, rtM.CategoricalPredictors); ***** test # predict takes a table yFit = predict (rtM, rtT); assert_equal (numel (yFit), 150); assert_equal (isnumeric (yFit), true); ***** test a = predict (rtM, rtT); b = predict (rtM, rtT(:, [5, 4, 3, 2, 1])); assert_equal (a, b); T = rtT; T.Extra = (1:150)'; assert_equal (predict (rtM, T), a); ***** test # a matrix is still taken, as the model was fitted from one before load fisheriris Mdl = fitrtree (meas(:,2:4), meas(:,1)); assert_equal (numel (predict (Mdl, meas(:,2:4))), 150); ***** test # the levels travel with the model when it is made compact CMdl = compact (rtM); assert_equal (CMdl.PredictorLevels, rtM.PredictorLevels); assert_equal (predict (CMdl, rtT), predict (rtM, rtT)); ***** error ... predict (rtM, rtT(:, [1, 3, 4, 5])) ***** shared lrtT, lrtM load fisheriris lrtT = table (meas(:,2), meas(:,3), 'VariableNames', {'SW', 'PL'}); lrtT.SL = meas(:,1); lrtM = fitrtree (lrtT, 'SL'); ***** test # the response is named, left out, or given beside the table a = loss (lrtM, [lrtT.SW, lrtT.PL], lrtT.SL); assert_equal (loss (lrtM, lrtT(:,1:2), lrtT.SL), a); assert_equal (loss (lrtM, lrtT, 'SL'), a); assert_equal (loss (lrtM, lrtT), a); ***** test # an even number of arguments after the table is all name-value a = loss (lrtM, lrtT, 'LossFun', 'mse'); assert_equal (loss (lrtM, lrtT, 'SL', 'LossFun', 'mse'), a); ***** test # a table is read by name, so the order of its columns does not matter assert_equal (loss (lrtM, lrtT(:, [3, 2, 1])), loss (lrtM, lrtT)); ***** error ... loss (lrtM, lrtT, 'NoSuch') ***** error ... loss (lrtM, lrtT(:,1:2)) ***** error ... RegressionTree ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', 'Weights', ... int8 ([1; 1; 1; 1])) ***** error ... RegressionTree ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', 'Weights', true (4, 1)) ***** test ## Single weights are stored single, summing to one load fisheriris X = meas(:,2:4); y = meas(:,1); w = 1 + (1:150)' / 7; Mdl = RegressionTree (X, y, 'Weights', single (w)); assert_equal (class (Mdl.W), 'single'); assert_equal (sum (double (Mdl.W)), 1, 1e-6); ***** test ## Single weights compute as double load fisheriris X = meas(:,2:4); y = meas(:,1); w = 1 + (1:150)' / 7; A = RegressionTree (X, y, 'Weights', single (w)); B = RegressionTree (X, y, 'Weights', double (single (w))); assert_equal (predict (A, X), predict (B, X)); 121 tests, 121 passed, 0 known failure, 0 skipped [inst/Machine_Learning/RegressionBaggedEnsemble.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/RegressionBaggedEnsemble.m ***** test # MATLAB parity: the properties of a bagged regression ensemble load fisheriris Mdl = RegressionBaggedEnsemble (meas(:,2:4), meas(:,1), ... 'NumLearningCycles', 3); assert_equal (numel (properties (Mdl)), 27); assert_equal (Mdl.Method, 'Bag'); assert_equal (Mdl.TrainedWeights, [1; 1; 1]); assert_equal (Mdl.FitInfo, []); assert_equal (Mdl.FitInfoDescription, 'None'); assert_equal (Mdl.FResample, 1); assert_equal (Mdl.Replace, true); assert_equal (size (Mdl.UseObsForLearner), [150, 3]); assert_equal (isfield (Mdl.ModelParameters, 'LearnRate'), false); ***** test # MATLAB parity: the prediction is the mean of the trees load fisheriris rng (5); Mdl = RegressionBaggedEnsemble (meas(:,2:4), meas(:,1), ... 'NumLearningCycles', 4); P = zeros (150, 1); for t = 1:4 P += predict (Mdl.Trained{t}, meas(:,2:4)); endfor assert_equal (predict (Mdl, meas(:,2:4)), P / 4, 1e-14); assert_equal (min (cellfun (@(t) min (t.NodeSize), Mdl.Trained)) >= 5, true); ***** test # MATLAB parity: each tree draws FResample of the rows load fisheriris rng (5); Mdl = RegressionBaggedEnsemble (meas(:,2:4), meas(:,1), ... 'NumLearningCycles', 2, ... 'FResample', 0.5, 'Replace', 'off'); assert_equal (sum (Mdl.UseObsForLearner), [75, 75]); assert_equal (Mdl.Trained{1}.NodeSize(1), 75); ***** test # MATLAB parity: the bootstrap draws in proportion to the weights load fisheriris rng (4); w = [10 * ones(50, 1); ones(100, 1)]; Mdl = RegressionBaggedEnsemble (meas(:,2:4), meas(:,1), ... 'NumLearningCycles', 20, 'Weights', w); assert_equal ([sum(Mdl.W(1:50)), sum(Mdl.W(51:150))], [5, 1] / 6, 1e-15); share = mean (sum (Mdl.UseObsForLearner(1:50,:)) / 50); assert_equal (share > 0.85, true); ***** test # MATLAB parity: a row no tree may predict is NaN load fisheriris rng (5); Mdl = RegressionBaggedEnsemble (meas(:,2:4), meas(:,1), ... 'NumLearningCycles', 4); U = false (2, 4); U(2,1) = true; yf = predict (Mdl, meas(1:2,2:4), 'UseObsForLearner', U); assert_equal (isnan (yf(1)), true); assert_equal (yf(2), predict (Mdl.Trained{1}, meas(2,2:4)), 1e-15); ***** test # resuming adds the new trees' samples load fisheriris Mdl = RegressionBaggedEnsemble (meas(:,2:4), meas(:,1), ... 'NumLearningCycles', 2); Mdl = resume (Mdl, 2); assert_equal (class (Mdl), 'RegressionBaggedEnsemble'); assert_equal (Mdl.NumTrained, 4); assert_equal (size (Mdl.UseObsForLearner), [150, 4]); assert_equal (class (compact (Mdl)), 'CompactRegressionEnsemble'); ***** error ... RegressionBaggedEnsemble (1) ***** error ... load fisheriris RegressionBaggedEnsemble (meas(:,2:4), meas(:,1), 'Method', 'LSBoost') ***** error ... load fisheriris RegressionBaggedEnsemble (meas(:,2:4), meas(:,1), 'LearnRate', 0.5) ***** error ... load fisheriris predict (RegressionBaggedEnsemble (meas(:,2:4), meas(:,1), ... 'NumLearningCycles', 1)) ***** test # MATLAB parity: out-of-bag predictions invert UseObsForLearner load fisheriris rng (5); Mdl = RegressionBaggedEnsemble (meas(:,2:4), meas(:,1), ... 'NumLearningCycles', 6); U = ! Mdl.UseObsForLearner; assert_equal (isequaln (oobPredict (Mdl), ... predict (Mdl, meas(:,2:4), ... 'UseObsForLearner', U)), true); assert_equal (oobLoss (Mdl), loss (Mdl, meas(:,2:4), meas(:,1), ... 'UseObsForLearner', U), 1e-15); assert_equal (oobLoss (Mdl, 'Mode', 'cumulative'), ... loss (Mdl, meas(:,2:4), meas(:,1), ... 'UseObsForLearner', U, 'Mode', 'cumulative'), 1e-14); ***** test # MATLAB parity: the out-of-bag loss leaves out rows in every bag load fisheriris rng (5); Mdl = RegressionBaggedEnsemble (meas(:,2:4), meas(:,1), ... 'NumLearningCycles', 6); yf = oobPredict (Mdl); have = ! isnan (yf); assert_equal (oobLoss (Mdl), mean ((yf(have) - meas(have,1)) .^ 2), 1e-14); ***** test # MATLAB parity: the importance of a bagged regression ensemble load fisheriris rng (6); Mdl = RegressionBaggedEnsemble (meas(:,2:4), meas(:,1), ... 'NumLearningCycles', 5); I = cell2mat (cellfun (@(t) predictorImportance (t), Mdl.Trained, ... 'UniformOutput', false)); assert_equal (predictorImportance (Mdl), mean (I), 1e-15); ***** test # MATLAB parity: a constant predictor has zero permuted importance load fisheriris rng (7); Mdl = RegressionBaggedEnsemble ([meas(:,2:4), ones(150, 1)], meas(:,1), ... 'NumLearningCycles', 20); imp = oobPermutedPredictorImportance (Mdl); assert_equal (size (imp), [1, 4]); assert_equal (imp(4), 0); assert_equal (all (imp(1:3) > 0), true); ***** error ... load fisheriris oobPredict (RegressionBaggedEnsemble (meas(:,2:4), meas(:,1), ... 'NumLearningCycles', 1), ... 'Mode', 'ensemble') ***** error ... load fisheriris oobLoss (RegressionBaggedEnsemble (meas(:,2:4), meas(:,1), ... 'NumLearningCycles', 1), ... 'Weights', ones (150, 1)) ***** error ... load fisheriris oobPermutedPredictorImportance (RegressionBaggedEnsemble (meas(:,2:4), ... meas(:,1), 'NumLearningCycles', 1), ... 'Options', struct ()) ***** error ... load fisheriris oobPermutedPredictorImportance (RegressionBaggedEnsemble (meas(:,2:4), ... meas(:,1), 'NumLearningCycles', 1), ... 'Bogus', struct ()) ***** shared Xr, yr, tr load fisheriris Xr = meas(:,2:4); yr = meas(:,1); tr = templateTree ('MaxNumSplits', 3); ***** test # MATLAB parity: LSBoost drawing every row without replacement is plain M = RegressionBaggedEnsemble (Xr, yr, 'Method', 'LSBoost', ... 'NumLearningCycles', 4, 'Learners', tr, ... 'FResample', 1, 'Replace', 'off'); P = fitrensemble (Xr, yr, 'NumLearningCycles', 4, 'Learners', tr); assert_equal (M.FitInfo, P.FitInfo, 1e-12); assert_equal (predict (M, Xr(1:5,:)), predict (P, Xr(1:5,:)), 1e-12); assert_equal ([M.FResample, M.Replace], [1, false]); ***** test # MATLAB parity: resampled LSBoost measures its fit over every row M = RegressionBaggedEnsemble (Xr, yr, 'Method', 'LSBoost', ... 'NumLearningCycles', 4, 'Learners', tr, ... 'Resample', 'on'); assert_equal (size (M.UseObsForLearner), [150, 4]); W = M.W / sum (M.W); F = zeros (150, 1); for t = 1:4 h = predict (M.Trained{t}, Xr); assert_equal (M.FitInfo(t), sum (W .* (yr - F - h) .^ 2), 1e-12); F += M.TrainedWeights(t) * h; endfor ***** test # a resampled LSBoost cross-validates with its learning rate M = RegressionBaggedEnsemble (Xr, yr, 'Method', 'LSBoost', ... 'NumLearningCycles', 2, 'Learners', tr, ... 'FResample', 0.7, 'LearnRate', 0.5); CV = crossval (M, 'KFold', 3); assert_equal (CV.Trainable{1}.LearnRate, 0.5); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,2:3); y = meas(:,1); T = table (X(:,1), X(:,2), 'VariableNames', {'SW', 'PL'}); T.SL = y; Mdl = fitrensemble (T, 'SL', 'Method', 'Bag'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'SL'), a); assert_equal (loss (Mdl, T), a); 22 tests, 22 passed, 0 known failure, 0 skipped [inst/Machine_Learning/templateDiscriminant.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/templateDiscriminant.m ***** test # the default template names its learner and nothing else T = templateDiscriminant (); assert_equal (class (T), 'struct'); assert_equal (T.Method, 'Discriminant'); assert_equal (T.Type, 'classification'); assert_equal (numfields (T), 2); ***** test # an option given is stored under its own name, as it stands T = templateDiscriminant ('DiscrimType', 'quadratic'); assert_equal (numfields (T), 3); assert_equal (T.DiscrimType, 'quadratic'); ***** test # a name the learner does not know is not refused here T = templateDiscriminant ('NoSuchOption', 42); assert_equal (T.NoSuchOption, 42); ***** error ... templateDiscriminant ('KernelScale') ***** error ... templateDiscriminant (42, 1) ***** error ... templateDiscriminant ('not a name', 1) 6 tests, 6 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitcensemble.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitcensemble.m ***** demo ## Boost decision stumps to tell versicolor from virginica, and see how ## the training error falls as the stumps accumulate. load fisheriris X = meas(51:150,:); Y = species(51:150); Mdl = fitcensemble (X, Y, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 20, ... 'Learners', templateTree ('MaxNumSplits', 1)); err = loss (Mdl, X, Y, 'Mode', 'cumulative'); plot (err); xlabel ('Number of stumps'); ylabel ('Training error'); ***** demo ## A bagged ensemble of trees classifies all three species, and scores ## each flower with the average of its trees' class probabilities. load fisheriris rng (42); Mdl = fitcensemble (meas, species, 'Method', 'Bag', ... 'NumLearningCycles', 30); [label, scores] = predict (Mdl, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3]) ***** demo ## Fit from a table, and predict on one load fisheriris T = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = categorical (species); ## A column holding levels is a categorical predictor without being named ## one T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ## The response is named by its column, and everything else is a predictor Mdl = fitcensemble (T, 'Species'); Mdl.PredictorNames Mdl.CategoricalPredictors ## predict reads a table by the names the model was fitted on, so the ## columns may come in any order label = predict (Mdl, T(1:5, [6, 5, 4, 3, 2, 1])); label' ***** shared X2, Y2, S load fisheriris X2 = meas(51:150,:); Y2 = species(51:150); S = templateTree ('MaxNumSplits', 1); ***** test # MATLAB parity: AdaBoostM1 on decision stumps Mdl = fitcensemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 5, 'Learners', S); assert_equal (Mdl.TrainedWeights, [1.375767656520975; 0.993534110774411; ... 0.883434373403998; 0.554364192108758; ... 0.268194447432047], 1e-13); assert_equal (Mdl.FitInfo, [0.06; 0.120567375886525; 0.145932163187856; ... 0.248108033048671; 0.369028016476793], 1e-13); cuts = cellfun (@(t) t.CutPoint(1), Mdl.Trained); assert_equal (cuts, [1.75; 4.95; 4.45; 4.95; 5.15], 1e-12); ***** test # MATLAB parity: the scores of AdaBoostM1 are signed learner weights Mdl = fitcensemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 5, 'Learners', S); [label, s] = predict (Mdl, X2([1, 21, 51],:)); assert_equal (label, {'versicolor'; 'virginica'; 'virginica'}); assert_equal (s(:,1), [1.772037138568098; -0.979498174473852; ... -2.966566396022673], 1e-13); assert_equal (s(:,2), -s(:,1)); ***** test # MATLAB parity: the learning rate shrinks AdaBoostM1 Mdl = fitcensemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 4, 'Learners', S, ... 'LearnRate', 0.5); assert_equal (Mdl.TrainedWeights, [0.687883828260487; 0.595450620008897; ... 0.406803001473525; 0.320537560668013], 1e-13); assert_equal (Mdl.FitInfo(2:4), [0.084570915580601; 0.164212646508385; ... 0.217184427004775], 1e-13); ***** test # MATLAB parity: a uniform prior sets the starting weights load fisheriris Yv = strcmp (species(41:150), 'virginica'); Mdl = fitcensemble (meas(41:150,:), Yv, ... 'Method', 'AdaBoostM1', 'NumLearningCycles', 3, ... 'Learners', S, 'Prior', 'uniform'); assert_equal (Mdl.W([1, 110])', [0.5 / 60, 0.5 / 50], 1e-15); assert_equal (Mdl.TrainedWeights, [1.406116776793511; 1.083890239183778; ... 0.818511561052510], 1e-13); ***** test # MATLAB parity: a cost multiplies the starting weights Mdl = fitcensemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 3, 'Learners', S, ... 'Cost', [0, 1; 5, 0]); assert_equal (Mdl.W([1, 51])', [0.01, 0.01], 1e-15); assert_equal (Mdl.FitInfo, [0.036666666666667; 0.125511167033658; ... 0.225018706839040], 1e-13); [~, s] = predict (Mdl, X2(1,:)); assert_equal (s(1), 3.223215778029441, 1e-13); ***** test # MATLAB parity: AdaBoostM2 on decision stumps load fisheriris Mdl = fitcensemble (meas, species, 'Method', 'AdaBoostM2', ... 'NumLearningCycles', 4, 'Learners', S); assert_equal (Mdl.TrainedWeights, [0.549306144334059; 0.496958723838212; ... 0.495870843211405; 0.456824643135089], 1e-13); assert_equal (Mdl.FitInfo, [0.25; 0.270139003161550; 0.270568199265314; ... 0.286253661231616], 1e-13); [~, s] = predict (Mdl, meas([1, 101],:)); assert_equal (s, [1.393875268391962, 0.557069431281369, ... 0.048015654845434; 0, 0.600192648565954, ... 1.398767705952811], 1e-13); ***** test # MATLAB parity: GentleBoost on decision stumps Mdl = fitcensemble (X2, Y2, 'Method', 'GentleBoost', ... 'NumLearningCycles', 3, 'Learners', S); assert_equal (class (Mdl.Trained{1}), 'CompactRegressionTree'); assert_equal (Mdl.TrainedWeights, [1; 1; 1]); assert_equal (Mdl.FitInfo, [0.220611916264090; 0.327133481554914; ... 0.606925714189402], 1e-13); [~, s] = predict (Mdl, X2([1, 21, 51],:)); assert_equal (s(:,1), [2.112004327552702; -0.903893073252190; ... -2.537346885979990], 1e-13); ***** test # MATLAB parity: GentleBoost with its default trees Mdl = fitcensemble (X2, Y2, 'Method', 'GentleBoost', ... 'NumLearningCycles', 4); assert_equal (Mdl.FitInfo, [0.08; 0.157657738520697; 0.188119628350251; ... 0.290921726710326], 1e-13); assert_equal (resubLoss (Mdl, 'LossFun', 'exponential'), ... 0.054188751279988, 1e-13); assert_equal (resubEdge (Mdl), 7.127687492916048, 1e-12); ***** test # the learning rate shrinks GentleBoost, where MATLAB only rescales Mdl = fitcensemble (X2, Y2, 'Method', 'GentleBoost', ... 'NumLearningCycles', 3, 'Learners', S, ... 'LearnRate', 0.5); assert_equal (Mdl.TrainedWeights, [0.5; 0.5; 0.5]); assert_equal (Mdl.FitInfo(1), 0.220611916264090, 1e-13); assert_equal (abs (Mdl.FitInfo(2) - 0.327133481554914) > 1e-3, true); ***** test # MATLAB parity: LogitBoost on decision stumps Mdl = fitcensemble (X2, Y2, 'Method', 'LogitBoost', ... 'NumLearningCycles', 3, 'Learners', S); assert_equal (Mdl.TrainedWeights, [0.5; 0.5; 0.5]); assert_equal (Mdl.FitInfo, [0.882447665056360; 0.883091315814675; ... 1.164564532959708], 1e-13); [~, s] = predict (Mdl, X2([1, 21, 51],:)); assert_equal (s(:,1), [1.906010018452977; 0.134673464507728; ... -2.170659689353640], 1e-13); ***** test # MATLAB parity: the learning rate shrinks LogitBoost Mdl = fitcensemble (X2, Y2, 'Method', 'LogitBoost', ... 'NumLearningCycles', 3, 'Learners', S, ... 'LearnRate', 0.5); assert_equal (Mdl.TrainedWeights, [0.25; 0.25; 0.25]); assert_equal (Mdl.FitInfo, [0.882447665056360; 0.826287268663811; ... 0.840635802435344], 1e-13); ***** test # MATLAB parity: LogitBoost with its default trees Mdl = fitcensemble (X2, Y2, 'Method', 'LogitBoost', ... 'NumLearningCycles', 6); assert_equal (Mdl.FitInfo, [0.32; 0.341307860560587; ... 0.516570570389474; 0.548550758138539; ... 0.890006883416469; 0.341774284666034], 1e-12); [~, s] = predict (Mdl, X2([1, 2, 21, 100],:)); assert_equal (s(:,1), [4.582296394974635; 4.239663719918038; ... 0.504944771289154; -2.839026377180836], 1e-12); ***** test # MATLAB parity: an error of exactly one half does not stop the fit X = repmat ([0, 0; 0, 1; 1, 0; 1, 1], 10, 1); Y = repmat ([0; 1; 1; 0], 10, 1); Mdl = fitcensemble (X, Y, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 3, 'Learners', S); assert_equal (Mdl.NumTrained, 3); assert_equal (Mdl.FitInfo, [0.5; 0.5; 0.5], 1e-14); ***** test # a perfect learner is kept and ends the fit, where MATLAB drops it load fisheriris Mdl = fitcensemble (meas, strcmp (species, 'setosa'), ... 'Method', 'AdaBoostM1', 'NumLearningCycles', 3, ... 'Learners', S); assert_equal (Mdl.NumTrained, 1); assert_equal (Mdl.ReasonForTermination, ... 'Classification error from the last weak learner is zero.'); assert_equal (Mdl.TrainedWeights, log ((1 - eps) / eps) / 2, 1e-12); assert_equal (resubLoss (Mdl), 0); ***** test # a perfect AdaBoostM2 learner is kept too load fisheriris Mdl = fitcensemble (meas, species, 'NumLearningCycles', 5); assert_equal (Mdl.Method, 'AdaBoostM2'); assert_equal (Mdl.NumTrained, 1); assert_equal (Mdl.ReasonForTermination, ... 'Pseudo-loss from the last weak learner is zero.'); assert_equal (resubLoss (Mdl), 0); ***** test # MATLAB parity: LogitBoost is the default for two classes Mdl = fitcensemble (X2, Y2, 'NumLearningCycles', 2); assert_equal (class (Mdl), 'ClassificationEnsemble'); assert_equal (Mdl.Method, 'LogitBoost'); assert_equal (Mdl.CombineWeights, 'WeightedSum'); ***** test # MATLAB parity: 'Bag' returns a bagged ensemble load fisheriris Mdl = fitcensemble (meas, species, 'Method', 'Bag', ... 'NumLearningCycles', 2); assert_equal (class (Mdl), 'ClassificationBaggedEnsemble'); assert_equal (Mdl.CombineWeights, 'WeightedAverage'); ***** test # MATLAB parity: progress is printed after every NPrint learners out = evalc (["fitcensemble (X2, Y2, 'Method', 'AdaBoostM1', ", ... "'NumLearningCycles', 4, 'Learners', S, 'NPrint', 2);"]); assert_equal (out, sprintf (["Training AdaBoostM1...\n", ... "Grown weak learners: 2\n", ... "Grown weak learners: 4\n"])); ***** error fitcensemble (X2) ***** error ... fitcensemble (X2, Y2, 'Method') ***** test # MATLAB parity: 'CrossVal' gives ten folds CV = fitcensemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 2, 'Learners', S, 'CrossVal', 'on'); assert_equal (class (CV), 'ClassificationPartitionedEnsemble'); assert_equal (CV.KFold, 10); M = fitcensemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 2, 'Learners', S, 'CrossVal', 'off'); assert_equal (class (M), 'ClassificationEnsemble'); ***** error ... fitcensemble (X2, Y2, 'KFold', 5, 'Holdout', 0.2) ***** error ... fitcensemble (X2, Y2, 'KFold', 1) ***** error ... fitcensemble (X2, Y2, 'Holdout', 1) ***** error ... fitcensemble (X2, Y2, 'CrossVal', true) ***** error ... fitcensemble (X2, Y2, 'Leaveout', 1) ***** error ... fitcensemble (X2, Y2, 'CVPartition', 5) ***** error ... fitcensemble (X2, Y2, 'CVPartition', cvpartition (50, 'KFold', 5)) ***** test # Subspace of discriminants over every pair, in nchoosek order load fisheriris Mdl = fitcensemble (meas, species, 'Method', 'Subspace', ... 'NumLearningCycles', 'AllPredictorCombinations', ... 'NPredToSample', 2, 'Learners', 'discriminant'); assert_equal (Mdl.NumTrained, 6); assert_equal (Mdl.CombineWeights, 'WeightedAverage'); assert_equal (Mdl.TrainedWeights, ones (6, 1)); assert_equal (Mdl.FitInfo, []); assert_equal (Mdl.LearnerNames, {'Discriminant'}); assert_equal (Mdl.UsePredForLearner, logical ([1, 1, 1, 0, 0, 0; ... 1, 0, 0, 1, 1, 0; ... 0, 1, 0, 1, 0, 1; ... 0, 0, 1, 0, 1, 1])); assert_equal (class (Mdl.Trained{1}), 'CompactClassificationDiscriminant'); assert_equal (Mdl.Trained{1}.PredictorNames, {'x1', 'x2'}); ***** test # MATLAB parity: Subspace scores are the mean of the learners load fisheriris Mdl = fitcensemble (meas, species, 'Method', 'Subspace', ... 'NumLearningCycles', 'AllPredictorCombinations', ... 'NPredToSample', 2, 'Learners', 'discriminant'); [~, s] = predict (Mdl, meas([51, 120],:)); assert_equal (s, [0.000000674895093, 0.834981379863075, ... 0.165017945241832; 0.000000043609969, ... 0.560291808349626, 0.439708148040405], 1e-12); assert_equal (resubLoss (Mdl), 0.046666666666667, 1e-13); ***** test # MATLAB parity: Subspace of nearest neighbours is the default load fisheriris Mdl = fitcensemble (meas, species, 'Method', 'Subspace', ... 'NumLearningCycles', 'AllPredictorCombinations', ... 'NPredToSample', 2); assert_equal (Mdl.LearnerNames, {'KNN'}); [~, s] = predict (Mdl, meas([101, 120],:)); assert_equal (s, [0, 1/6, 5/6; 0, 0.5, 0.5], 1e-15); assert_equal (resubLoss (Mdl), 0.006666666666667, 1e-13); ***** test # MATLAB parity: a nearest neighbour template over every triple load fisheriris Mdl = fitcensemble (meas, species, 'Method', 'Subspace', ... 'NumLearningCycles', 'AllPredictorCombinations', ... 'NPredToSample', 3, ... 'Learners', templateKNN ('NumNeighbors', 5)); assert_equal (Mdl.NumTrained, 4); [~, s] = predict (Mdl, meas([71, 120],:)); assert_equal (s, [0, 0.4, 0.6; 0, 0.55, 0.45], 1e-15); ***** test # MATLAB parity: single predictors are taken in order load fisheriris Mdl = fitcensemble (meas(51:150,:), species(51:150), ... 'Method', 'Subspace', ... 'NumLearningCycles', 'AllPredictorCombinations', ... 'Learners', 'discriminant'); assert_equal (Mdl.UsePredForLearner, logical (eye (4))); [~, s] = predict (Mdl, meas([51, 101],:)); assert_equal (s, [0.558349136121729, 0.441650863878271; ... 0.195748544656556, 0.804251455343444], 1e-12); assert_equal (resubLoss (Mdl), 0.06, 1e-15); ***** test # random subspaces draw distinct predictors load fisheriris rng (9); Mdl = fitcensemble (meas, species, 'Method', 'Subspace', ... 'NumLearningCycles', 8, 'NPredToSample', 2, ... 'Learners', 'discriminant'); assert_equal (sum (Mdl.UsePredForLearner), 2 * ones (1, 8)); D = fitcensemble (meas, species, 'Method', 'Subspace', ... 'NumLearningCycles', 3); assert_equal (sum (D.UsePredForLearner), ones (1, 3)); ***** test # MATLAB parity: the score transform applies to the averaged scores load fisheriris Mdl = fitcensemble (meas, species, 'Method', 'Subspace', ... 'NumLearningCycles', 'AllPredictorCombinations', ... 'NPredToSample', 2, 'Learners', 'discriminant'); [~, s0] = predict (Mdl, meas(1,:)); Mdl.ScoreTransform = 'logit'; [~, s] = predict (Mdl, meas(1,:)); assert_equal (s, 1 ./ (1 + exp (-s0)), 1e-15); ***** test # MATLAB parity: a cross-validated Subspace refits every combination load fisheriris CV = fitcensemble (meas, species, 'Method', 'Subspace', ... 'NumLearningCycles', 'AllPredictorCombinations', ... 'NPredToSample', 2, 'Learners', 'discriminant', ... 'KFold', 3); assert_equal (CV.NumTrainedPerFold, [6, 6, 6]); ***** shared Xi, Yi, T1 load fisheriris Xi = meas([1:10, 51:100, 101:130],:); Yi = species([1:10, 51:100, 101:130]); T1 = templateTree ('MaxNumSplits', 1); ***** test # MATLAB parity: RUSBoost sampling every row of imbalanced classes Mdl = fitcensemble (Xi, Yi, 'Method', 'RUSBoost', 'Learners', T1, ... 'NumLearningCycles', 6, 'RatioToSmallest', [1, 5, 3]); assert_equal (Mdl.FitInfo', [0.195372503840246, 0.273203444497188, ... 0.342324146410416, 0.391679747239235, ... 0.424713594905408, 0.446828084418694], 1e-13); assert_equal (Mdl.TrainedWeights', [0.707735710111105, ... 0.489214930830132, ... 0.326477050756789, ... 0.220128470123600, ... 0.151726482595071, ... 0.106747454637321], 1e-13); assert_equal (Mdl.CombineWeights, 'WeightedSum'); assert_equal (Mdl.FitInfoDescription{2}, ... strcat ('Element t of this vector is the weighted loss', ... ' from hypothesis t.')); ***** test # MATLAB parity: RUSBoost scores are weighted sums of probabilities Mdl = fitcensemble (Xi, Yi, 'Method', 'RUSBoost', 'Learners', T1, ... 'NumLearningCycles', 6, 'RatioToSmallest', [1, 5, 3]); [~, s] = predict (Mdl, Xi([1, 61],:)); assert_equal (s, [0.322908080492584, 1.582249594413660, ... 0.096872424147775; 0, 0.071501074966215, ... 1.930529024087804], 1e-13); ***** test # MATLAB parity: RUSBoost starts from the observation weights Mdl = fitcensemble (Xi, Yi, 'Method', 'RUSBoost', 'Learners', T1, ... 'NumLearningCycles', 5, 'RatioToSmallest', [1, 5, 3], ... 'Weights', (1:90)'); assert_equal (Mdl.FitInfo', [0.135468889789166, 0.227297593785240, ... 0.325572187192910, 0.392977365900961, ... 0.433450832378125], 1e-13); ***** test # MATLAB parity: RUSBoost starts from the prior Mdl = fitcensemble (Xi, Yi, 'Method', 'RUSBoost', 'Learners', T1, ... 'NumLearningCycles', 5, 'RatioToSmallest', [1, 5, 3], ... 'Prior', 'uniform'); assert_equal (Mdl.FitInfo', [0.297695852534562, 0.363195690083740, ... 0.405887261979897, 0.433634399973484, ... 0.452182830272981], 1e-13); ***** test # MATLAB parity: RUSBoost starts from the cost Mdl = fitcensemble (Xi, Yi, 'Method', 'RUSBoost', 'Learners', T1, ... 'NumLearningCycles', 5, 'RatioToSmallest', [1, 5, 3], ... 'Cost', [0, 1, 1; 2, 0, 1; 1, 3, 0]); assert_equal (Mdl.FitInfo', [0.170084816462736, 0.253339506885676, ... 0.332687545823290, 0.389034394725378, ... 0.425567217510485], 1e-13); ***** test # MATLAB parity: RUSBoost on two classes load fisheriris Mdl = fitcensemble (meas(51:140,:), species(51:140), ... 'Method', 'RUSBoost', 'Learners', T1, ... 'NumLearningCycles', 6, 'RatioToSmallest', [1.25, 1]); assert_equal (Mdl.FitInfo', [0.122427983539095, 0.303342803047074, ... 0.440725113503495, 0.483823466199863, ... 0.495606380578646, 0.498805931770484], 1e-13); ***** test # MATLAB parity: the learning rate shrinks RUSBoost load fisheriris Mdl = fitcensemble (meas, species, 'Method', 'RUSBoost', 'Learners', T1, ... 'NumLearningCycles', 6, 'LearnRate', 0.5); assert_equal (Mdl.FitInfo', [0.25, 0.266721039894768, ... 0.280862713503484, 0.292850544622122, ... 0.303050532217282, 0.311767644857868], 1e-13); assert_equal (Mdl.TrainedWeights', [0.274653072167027, ... 0.252830721199463, ... 0.235046573619133, ... 0.220394911259144, ... 0.208203335984824, ... 0.197967081018013], 1e-13); ***** test # MATLAB parity: each class draws RatioToSmallest times the smallest Mdl = fitcensemble (Xi, Yi, 'Method', 'RUSBoost', 'Learners', T1, ... 'NumLearningCycles', 1, 'RatioToSmallest', 0.5); assert_equal (Mdl.Trained{1}.ClassCount(1,:), [5, 5, 5]); ***** test # MATLAB parity: sample sizes round half away from zero load fisheriris k = [101:110, 51:100]; Mdl = fitcensemble (meas(k,:), species(k), 'Method', 'RUSBoost', ... 'Learners', T1, 'NumLearningCycles', 1, ... 'RatioToSmallest', [1, 1.25]); assert_equal (Mdl.Trained{1}.ClassCount(1,:), [10, 13]); ***** test # MATLAB parity: a class smaller than its sample is oversampled Mdl = fitcensemble (Xi, Yi, 'Method', 'RUSBoost', 'Learners', T1, ... 'NumLearningCycles', 1, 'RatioToSmallest', [2, 1, 1]); assert_equal (Mdl.Trained{1}.ClassCount(1,:), [20, 10, 10]); ***** test # MATLAB parity: RUSBoost samples in proportion to the weights load fisheriris k = [101:110, 51:90]; w = [ones(20, 1); 1e-8 * ones(30, 1)]; Mdl = fitcensemble (meas(k,:), species(k), 'Method', 'RUSBoost', ... 'NumLearningCycles', 1, 'Weights', w, ... 'Learners', templateTree ('MaxNumSplits', 3)); assert_equal (Mdl.Trained{1}.CutPoint(1), 1.65, 1e-14); ***** test # a cross-validated RUSBoost keeps its ratios CV = fitcensemble (Xi, Yi, 'Method', 'RUSBoost', 'Learners', T1, ... 'NumLearningCycles', 3, 'RatioToSmallest', [1, 2, 2], ... 'KFold', 3); assert_equal (CV.Trainable{1}.RatioToSmallest, [1, 2, 2]); assert_equal (CV.NumTrainedPerFold, [3, 3, 3]); ***** test # MATLAB parity: classes given as text are sorted load fisheriris k = [101:150, 51:100]; Mdl = fitcensemble (meas(k,:), species(k), 'NumLearningCycles', 2); assert_equal (Mdl.ClassNames, {'versicolor'; 'virginica'}); ***** test # MATLAB parity: a given ClassNames order is kept load fisheriris Mdl = fitcensemble (meas(51:150,:), species(51:150), ... 'NumLearningCycles', 2, ... 'ClassNames', {'virginica'; 'versicolor'}); assert_equal (Mdl.ClassNames, {'virginica'; 'versicolor'}); ***** test # the score columns follow a given ClassNames order load fisheriris Mdl = fitcensemble (meas(51:150,:), species(51:150), ... 'NumLearningCycles', 2, ... 'ClassNames', {'virginica'; 'versicolor'}); [label, s] = predict (Mdl, meas(51,:)); assert_equal (label, {'versicolor'}); assert_equal (s(2) > s(1), true); ***** error ... load fisheriris fitcensemble (meas, species, 'ClassNames', [3, 1, 2]) ***** error ... load fisheriris fitcensemble (meas, species, 'ClassNames', {'setosa'; 'rose'}) ***** test # MATLAB parity: a boosting method that resamples is a bagged ensemble load fisheriris S = templateTree ('MaxNumSplits', 1); X2 = meas(51:150,:); Y2 = species(51:150); assert_equal (class (fitcensemble (X2, Y2, 'Learners', S, ... 'NumLearningCycles', 2, ... 'FResample', 0.5)), ... 'ClassificationBaggedEnsemble'); M = fitcensemble (X2, Y2, 'Learners', S, 'NumLearningCycles', 2, ... 'Replace', 'off'); assert_equal (class (M), 'ClassificationBaggedEnsemble'); assert_equal (M.Method, 'LogitBoost'); M = fitcensemble (meas, species, 'Learners', S, 'NumLearningCycles', 2, ... 'Resample', 'on'); assert_equal (M.Method, 'AdaBoostM2'); ***** error ... load fisheriris fitcensemble (meas, species, 'Method', 'RUSBoost', 'Resample', 'on') ***** shared Xt, Yt, St load fisheriris Xt = meas(51:150,:); Yt = species(51:150); St = templateTree ('MaxNumSplits', 1); ***** test # MATLAB parity: TotalBoost edges, margins and termination Mdl = fitcensemble (Xt, Yt, 'Method', 'TotalBoost', ... 'NumLearningCycles', 20, 'Learners', St); assert_equal (Mdl.NumTrained, 20); assert_equal (size (Mdl.FitInfo), [20, 101]); assert_equal (Mdl.FitInfo(1,1), 0.814814814814815, 1e-14); assert_equal (Mdl.FitInfo(:,end)', [0.77938808373591, 0.76044474400507, ... 0.733474571057422, 0.713600406110363, 0.674985664146386, ... 0.617169871251258, 0.545304010166485, 0.481644597614076, ... 0.406905671288418, 0.305738947836862, 0.248186856286276, ... 0.223985203507107, 0.206293794856975, 0.190855934857519, ... 0.174375765970188, 0.164345799335436, 0.152347022022222, ... 0.156330779459034, 0.138184070638576, 0.13354613032089], 5e-5); assert_equal (sum (Mdl.TrainedWeights), 1, 1e-12); assert_equal (Mdl.ModelParameters.MarginPrecision, 0.01); assert_equal (Mdl.CombineWeights, 'WeightedSum'); assert_equal (numel (Mdl.FitInfoDescription), 4); ***** test # MATLAB parity: TotalBoost stops and weights its learners Mdl = fitcensemble (Xt, Yt, 'Method', 'TotalBoost', 'NumLearningCycles', ... 20, 'Learners', St, 'MarginPrecision', 0.3); assert_equal (Mdl.NumTrained, 3); assert_equal (Mdl.ReasonForTermination, ... 'No improvement in the last iteration.'); assert_equal (Mdl.FitInfo(:,end)', [0.77938808373591, ... 0.676485226347579, 0.363399531924414], 1e-6); assert_equal (Mdl.TrainedWeights', [0.321673618833505, ... 0.344387693465888, 0.333938687700607], 1e-6); ***** test # MATLAB parity: a larger MarginPrecision holds the edges lower Mdl = fitcensemble (Xt, Yt, 'Method', 'TotalBoost', 'NumLearningCycles', ... 20, 'Learners', St, 'MarginPrecision', 0.5); assert_equal (Mdl.FitInfo(:,end)', [0.77938808373591, ... 0.654956941202807, 0.314330389584896], 1e-6); assert_equal (Mdl.TrainedWeights', [0.312047586212885, ... 0.338803356427739, 0.349149057359376], 1e-6); ***** test # MATLAB parity: TotalBoost with MarginPrecision 0.1 keeps ten trees ## R2024a's quadprog stops a little short of each step's optimum, and the ## shortfall compounds, so late edges agree only to a few parts in 1e4. Mdl = fitcensemble (Xt, Yt, 'Method', 'TotalBoost', 'NumLearningCycles', ... 20, 'Learners', St, 'MarginPrecision', 0.1); assert_equal (Mdl.NumTrained, 10); assert_equal (Mdl.FitInfo(:,end)', [0.77938808373591, ... 0.717802322505678, 0.566889939927384, 0.413011741373863, ... 0.254813551545311, 0.198534963191251, 0.248289227195743, ... 0.151913855148981, 0.18012529479998, 0.145075739302781], 1e-3); ***** test # MATLAB parity: a first tree with no error leaves TotalBoost empty Mdl = fitcensemble (Xt, Yt, 'Method', 'TotalBoost', 'NumLearningCycles', 5); assert_equal (Mdl.NumTrained, 0); assert_equal (Mdl.ReasonForTermination, ... 'No improvement in the last iteration.'); ***** test # MATLAB parity: TotalBoost starts from the observation weights Mdl = fitcensemble (Xt, Yt, 'Method', 'TotalBoost', 'NumLearningCycles', ... 6, 'Learners', St, 'Weights', (1:100)'); assert_equal (Mdl.FitInfo(:,end)', [0.853081762279423, ... 0.833229884995196, 0.794516592483876, 0.729979583810379, ... 0.701779537592642, 0.663396027611383], 1e-5); ***** test # MATLAB parity: a three-class margin is the lead over the next class load fisheriris Mdl = fitcensemble (meas, species, 'Method', 'TotalBoost', ... 'NumLearningCycles', 8, 'Learners', St); assert_equal (Mdl.NumTrained, 8); assert_equal (Mdl.FitInfo(1,[1, 51, 101, 151]), [1, 0, 0, 1/3], 1e-12); ***** test # MATLAB parity: TotalBoost scores are weighted sums of 2p - 1 Mdl = fitcensemble (Xt, Yt, 'Method', 'TotalBoost', 'NumLearningCycles', ... 20, 'Learners', St, 'MarginPrecision', 0.3); [~, s] = predict (Mdl, Xt([1, 51],:)); man = zeros (2, 2); for t = 1:Mdl.NumTrained [~, p] = predict (Mdl.Trained{t}, Xt([1, 51],:)); man += Mdl.TrainedWeights(t) * (2 * p - 1); endfor assert_equal (s, man, 1e-12); ***** test # MATLAB parity: LPBoost edges and margins up to its first tie Mdl = fitcensemble (Xt, Yt, 'Method', 'LPBoost', 'NumLearningCycles', 4, ... 'Learners', St); assert_equal (Mdl.NumTrained, 4); assert_equal (size (Mdl.FitInfo), [4, 101]); assert_equal (Mdl.FitInfo(1,1), 0.814814814814815, 1e-14); assert_equal (Mdl.FitInfo(:,end)', [0.77938808373591, 1, ... 0.999999999999991, 0.999999999999966], 1e-12); assert_equal (Mdl.ModelParameters.MarginPrecision, 0.01); assert_equal (Mdl.CombineWeights, 'WeightedSum'); assert_equal (numel (Mdl.FitInfoDescription), 4); ***** test # MATLAB parity: LPBoost stops on the gap to the linear program Y = [repmat({'a'}, 60, 1); repmat({'b'}, 40, 1)]; Mdl = fitcensemble (ones (100, 1), Y, 'Method', 'LPBoost', ... 'NumLearningCycles', 4, 'Learners', St); assert_equal (Mdl.NumTrained, 2); assert_equal (Mdl.ReasonForTermination, ... 'No improvement in the last iteration.'); assert_equal (Mdl.FitInfo(:,end)', [0.04, 1], 1e-12); assert_equal (Mdl.TrainedWeights', [5/6, 1/6], 1e-9); ***** test # MATLAB parity: a gap within MarginPrecision leaves the tree out Y = [repmat({'a'}, 60, 1); repmat({'b'}, 40, 1)]; Mdl = fitcensemble (ones (100, 1), Y, 'Method', 'LPBoost', ... 'NumLearningCycles', 4, 'Learners', St, ... 'MarginPrecision', 0.05); assert_equal (Mdl.NumTrained, 1); assert_equal (Mdl.TrainedWeights, 1); ***** test # MATLAB parity: the first LPBoost tree is held to the same gap Y = [repmat({'a'}, 52, 1); repmat({'b'}, 48, 1)]; Mdl = fitcensemble (ones (100, 1), Y, 'Method', 'LPBoost', ... 'NumLearningCycles', 4, 'Learners', St, ... 'MarginPrecision', 0.05); assert_equal (Mdl.NumTrained, 0); assert_equal (size (Mdl.FitInfo), [0, 101]); ***** test # LPBoost weights maximise the smallest margin, summing to one Mdl = fitcensemble (Xt, Yt, 'Method', 'LPBoost', 'NumLearningCycles', ... 20, 'Learners', St, 'MarginPrecision', 0.5); assert_equal (sum (Mdl.TrainedWeights), 1, 1e-12); assert_equal (min (Mdl.FitInfo(:,1:end-1)' * Mdl.TrainedWeights), 0, 1e-12); ***** test # MATLAB parity: a three-class LPBoost starts from the class margins load fisheriris Mdl = fitcensemble (meas, species, 'Method', 'LPBoost', ... 'NumLearningCycles', 3, 'Learners', St); assert_equal (Mdl.FitInfo(:,end)', [1/3, 1, 1], 1e-12); ***** error ... fitcensemble (Xt, Yt, 'Method', 'LPBoost', 'LearnRate', 0.5) ***** error ... fitcensemble (Xt, Yt, 'Method', 'LPBoost', 'Resample', 'on') ***** error ... fitcensemble (Xt, Yt, 'Method', 'TotalBoost', 'LearnRate', 0.5) ***** error ... fitcensemble (Xt, Yt, 'Method', 'TotalBoost', 'MarginPrecision', 2) ***** error ... fitcensemble (Xt, Yt, 'Method', 'AdaBoostM1', 'MarginPrecision', 0.1) ***** error ... fitcensemble (Xt, Yt, 'Method', 'TotalBoost', 'Resample', 'on') ***** shared X, yb, Xq k = (0:119)'; c = mod (k, 4) + 1; j = floor (k / 4); x2 = mod (k * 7, 10); X = [c, x2]; yb = (c == 1) | (c == 2 & mod (j, 4) != 0) | (c == 3 & mod (j, 4) == 0) ... | (x2 > 7); yr = [3; 1; 4; 1.5]; yr = yr(c) + 0.1 * sin (k) + 0.2 * x2; Xq = [1, 0; 3, 5; 5, 0; NaN, 2; 2.5, 9]; ***** test # MATLAB parity: AdaBoostM1 trees split a categorical predictor Mdl = fitcensemble (X, yb, 'Method', 'AdaBoostM1', 'NumLearningCycles', ... 5, 'CategoricalPredictors', 1); assert_equal (Mdl.CategoricalPredictors, 1); assert_equal (Mdl.Trained{1}.CategoricalPredictors, 1); assert_equal (Mdl.Trained{1}.CutCategories(1,:), {[1, 2], [3, 4]}); [~, s] = predict (Mdl, Xq); assert_equal (s, [-2.91316, 2.91316; 0.131366, -0.131366; ... -2.91316, 2.91316; -2.91316, 2.91316; ... -2.91316, 2.91316], 1e-5); ***** test # MATLAB parity: 'all' names every predictor for the trees Mdl = fitcensemble (X, yb, 'Method', 'Bag', 'NumLearningCycles', 3, ... 'CategoricalPredictors', 'all'); assert_equal (Mdl.CategoricalPredictors, [1, 2]); assert_equal (Mdl.Trained{1}.CategoricalPredictors, [1, 2]); assert_equal (Mdl.ExpandedPredictorNames, {'x1', 'x2'}); ***** error ... fitcensemble (X, yb, 'Method', 'Subspace', 'CategoricalPredictors', 1) ***** shared fceT load fisheriris fceT = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); fceT.Species = categorical (species); fceT.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ***** test # the response is named by a column and the rest are predictors Mdl = fitcensemble (fceT, 'Species'); assert_equal (Mdl.PredictorNames, {'SL', 'SW', 'PL', 'PW', 'Wide'}); assert_equal (Mdl.ResponseName, 'Species'); assert_equal (Mdl.CategoricalPredictors, 5); ***** test # a model formula names the response and the predictors together Mdl = fitcensemble (fceT, 'Species ~ PW + SL'); assert_equal (Mdl.PredictorNames, {'PW', 'SL'}); ***** test # predict takes a table, matched by name and not by position Mdl = fitcensemble (fceT, 'Species'); a = predict (Mdl, fceT); assert_equal (class (a), 'categorical'); assert_equal (predict (Mdl, fceT(:, [6, 5, 4, 3, 2, 1])), a); ***** test # a bagged ensemble answers through its parent, so it reads a table too Mdl = fitcensemble (fceT, 'Species', 'Method', 'Bag'); assert_equal (class (Mdl), 'ClassificationBaggedEnsemble'); assert_equal (class (predict (Mdl, fceT)), 'categorical'); ***** test # the levels travel with the model when it is made compact Mdl = fitcensemble (fceT, 'Species'); CMdl = compact (Mdl); assert_equal (CMdl.PredictorLevels, Mdl.PredictorLevels); assert_equal (predict (CMdl, fceT), predict (Mdl, fceT)); ***** error ... fitcensemble (fceT, 'NoSuch') ***** error ... fitcensemble (fceT, 'Species ~ SL*PW') 85 tests, 85 passed, 0 known failure, 0 skipped [inst/Machine_Learning/RegressionEnsemble.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/RegressionEnsemble.m ***** shared X, y, S load fisheriris X = meas(:,2:4); y = meas(:,1); S = templateTree ('MaxNumSplits', 1); ***** test # MATLAB parity: the properties of a boosted regression ensemble Mdl = RegressionEnsemble (X, y, 'NumLearningCycles', 2, 'Learners', S); assert_equal (numel (properties (Mdl)), 24); assert_equal (Mdl.Regularization, []); assert_equal (Mdl.NumObservations, 150); assert_equal (Mdl.LearnerNames, {'Tree'}); assert_equal (Mdl.UsePredForLearner, []); assert_equal (Mdl.ReasonForTermination, ["Terminated normally after ", ... "completing the requested number of training cycles."]); assert_equal (Mdl.FitInfoDescription{2}, ["Element t of this vector ", ... "is the weighted residual from learner t."]); ***** test # MATLAB parity: the parameters of an LSBoost fit Mdl = RegressionEnsemble (X, y, 'NumLearningCycles', 2, 'Learners', S, ... 'LearnRate', 0.5); mp = Mdl.ModelParameters; assert_equal (mp.Type, 'regression'); assert_equal (mp.Method, 'LSBoost'); assert_equal (mp.NLearn, 2); assert_equal (mp.LearnRate, 0.5); ***** test # MATLAB parity: resuming continues the fit exactly M4 = RegressionEnsemble (X, y, 'NumLearningCycles', 4, 'Learners', S, ... 'LearnRate', 0.5); M2 = RegressionEnsemble (X, y, 'NumLearningCycles', 2, 'Learners', S, ... 'LearnRate', 0.5); R = resume (M2, 2); assert_equal (R.NumTrained, 4); assert_equal (R.ModelParameters.NLearn, 4); assert_equal (R.FitInfo, M4.FitInfo, 1e-14); assert_equal (R.TrainedWeights, M4.TrainedWeights); ***** test # MATLAB parity: resubstitution with the training weights Mdl = RegressionEnsemble (X, y, 'NumLearningCycles', 3, 'Learners', S); assert_equal (resubLoss (Mdl), 0.176267398277276, 1e-13); yf = resubPredict (Mdl); assert_equal (yf(1:2), [4.953658536585365; 4.953658536585365], 1e-13); w = [5 * ones(50, 1); ones(100, 1)]; Mw = RegressionEnsemble (X, y, 'NumLearningCycles', 2, 'Learners', S, ... 'Weights', w); assert_equal (resubLoss (Mw), 0.147589707296207, 1e-13); assert_equal (loss (Mw, X, y), 0.181635131105396, 1e-13); ***** test # MATLAB parity: a missing response drops its row from the fit yn = y; yn(3) = NaN; Mdl = RegressionEnsemble (X, yn, 'NumLearningCycles', 2, 'Learners', S); assert_equal (Mdl.NumObservations, 149); assert_equal (sum (Mdl.RowsUsed), 149); ***** test # MATLAB parity: the response transform applies to predictions only M0 = RegressionEnsemble (X, y, 'NumLearningCycles', 3, 'Learners', S); Mt = RegressionEnsemble (X, y, 'NumLearningCycles', 3, 'Learners', S, ... 'ResponseTransform', @(z) 2 * z); assert_equal (Mt.FitInfo, M0.FitInfo); assert_equal (predict (Mt, X(1,:)), 9.907317073170731, 1e-13); assert_equal (loss (Mt, X, y), 35.174803723282551, 1e-11); ***** test # the response transform can be set on a fitted ensemble Mdl = RegressionEnsemble (X, y, 'NumLearningCycles', 3, 'Learners', S); Mdl.ResponseTransform = @(z) z + 1; assert_equal (predict (Mdl, X(1,:)), 5.953658536585365, 1e-13); assert_equal (loss (Mdl, X, y), 1.176267398277276, 1e-12); ***** test # compact keeps the trees and drops the data Mdl = RegressionEnsemble (X, y, 'NumLearningCycles', 3, 'Learners', S); C = compact (Mdl); assert_equal (class (C), 'CompactRegressionEnsemble'); assert_equal (predict (C, X), predict (Mdl, X)); ***** error RegressionEnsemble (X) ***** error ... RegressionEnsemble (X, y, 'Method') ***** error ... RegressionEnsemble (X, y, 'Foo', 1) ***** error ... RegressionEnsemble (X, y, 1, 1) ***** error ... RegressionEnsemble (X, y, 'Method', 1) ***** error ... RegressionEnsemble (X, y, 'Method', 'AdaBoostM1') ***** error ... RegressionEnsemble (X, y, 'NumLearningCycles', 0) ***** error ... RegressionEnsemble (X, y, 'LearnRate', 0) ***** error ... RegressionEnsemble (X, y, 'NPrint', 'on') ***** error ... RegressionEnsemble (X, y, 'ResponseName', 1) ***** error ... RegressionEnsemble (X, y, 'FResample', 2) ***** error ... RegressionEnsemble (X, y, 'Replace', true) ***** error ... RegressionEnsemble (X, y, 'Resample', true) ***** error ... RegressionEnsemble (X, y, 'NumBins', 10) ***** error ... RegressionEnsemble (X, y, 'Learners', 'svm') ***** error ... RegressionEnsemble (X, y, 'Method', 'Bag') ***** error ... RegressionEnsemble (X, y, 'Resample', 'on') ***** error ... RegressionEnsemble (X, y, 'PredictorNames', {'a'}) ***** error ... RegressionEnsemble (X, y, 'Weights', -ones (150, 1)) ***** error ... resume (RegressionEnsemble (X, y, 'NumLearningCycles', 1)) ***** error ... resume (RegressionEnsemble (X, y, 'NumLearningCycles', 1), 0) ***** error ... resume (RegressionEnsemble (X, y, 'NumLearningCycles', 1), 1, 'NPrint') ***** error ... resume (RegressionEnsemble (X, y, 'NumLearningCycles', 1), 1, 'Foo', 1) ***** error ... resume (RegressionEnsemble (X, y, 'NumLearningCycles', 1), 1, ... 'NPrint', 0) ***** error ... predict (RegressionEnsemble (X, y, 'NumLearningCycles', 1)) ***** error ... loss (RegressionEnsemble (X, y, 'NumLearningCycles', 1), X) ***** error ... resubLoss (RegressionEnsemble (X, y, 'NumLearningCycles', 1), 'Foo', 1) ***** test # MATLAB parity: crossval equals cross-validating at fit time c = cvpartition (150, 'KFold', 4); M = RegressionEnsemble (X, y, 'NumLearningCycles', 2, 'Learners', S); CV = crossval (M, 'CVPartition', c); F = fitrensemble (X, y, 'NumLearningCycles', 2, 'Learners', S, ... 'CVPartition', c); assert_equal (class (CV), 'RegressionPartitionedEnsemble'); assert_equal (kfoldLoss (CV), kfoldLoss (F), 1e-15); ***** error ... crossval (RegressionEnsemble (X, y, 'NumLearningCycles', 1), 'Foo', 1) ***** shared X, y, tt, E load fisheriris X = meas(:,2:4); y = meas(:,1); tt = templateTree ('MaxNumSplits', 3); E = fitrensemble (X, y, 'Method', 'LSBoost', 'NumLearningCycles', 20, ... 'Learners', tt); ***** test # MATLAB parity: the default penalties of regularize R = regularize (E).Regularization; assert_equal (fieldnames (R), {'Method'; 'TrainedWeights'; 'Lambda'; ... 'ResubstitutionMSE'; 'CombineWeights'}); assert_equal (R.Method, 'Lasso'); assert_equal (size (R.TrainedWeights), [20, 10]); assert_equal (R.Lambda(1), 0); assert_equal (R.Lambda([2, 10]), [0.0346843052641099, 34.6843052641099], ... 1e-12); ***** test # MATLAB parity: lasso weights where R2024a converges R = regularize (E, 'Lambda', [0.01, 0.05, 0.1]).Regularization; assert_equal (R.TrainedWeights(:,[2, 3]), ... [0.998558425788861, 0.997116851577722; zeros(19, 2)], 1e-9); assert_equal (R.TrainedWeights(:,1), [0.99983699976111; ... 0.688155074556548; 0.205495438447582; 0.0983109617173514; ... 0; 0.314714964487384; zeros(14, 1)], 1e-6); assert_equal (R.ResubstitutionMSE(2:3), ... [0.141433481267387, 0.141649717399058], 1e-12); assert_equal (R.ResubstitutionMSE(1), 0.0981895827257545, 1e-6); ***** test # MATLAB parity: observation weights enter the fit and the error Ew = fitrensemble (X, y, 'Method', 'LSBoost', 'NumLearningCycles', 20, ... 'Learners', tt, 'Weights', (1:150)' / 150); R = regularize (Ew, 'Lambda', 0.1).Regularization; assert_equal (R.TrainedWeights, [0.997413841751991; zeros(19, 1)], 1e-9); assert_equal (R.ResubstitutionMSE, 0.136057521685236, 1e-12); assert_equal (regularize (Ew).Regularization.Lambda(end), ... 38.6673940301219, 1e-12); ***** test # MATLAB parity: the weights are never negative Elr = fitrensemble (X, y, 'Method', 'LSBoost', 'NumLearningCycles', 20, ... 'Learners', tt, 'LearnRate', 0.1); R = regularize (Elr, 'Lambda', [0, 0.01]).Regularization; assert_equal (all (R.TrainedWeights(:) >= 0), true); ***** test # regularize leaves the trained weights as they were Er = regularize (E, 'Lambda', 0.1); assert_equal (Er.TrainedWeights, E.TrainedWeights); ***** test # MATLAB parity: shrink keeps the weighted trees, largest first C = shrink (regularize (E, 'Lambda', 0.01)); assert_equal (class (C), 'CompactRegressionEnsemble'); assert_equal (C.CombineWeights, 'WeightedSum'); assert_equal (C.NumTrained, 5); assert_equal (C.TrainedWeights, [0.99983699976111; 0.688155074556548; ... 0.314714964487384; 0.205495438447582; ... 0.0983109617173514], 1e-6); ***** test # MATLAB parity: a weight equal to the threshold is dropped Er = regularize (E, 'Lambda', 0.01); C = shrink (Er); assert_equal (shrink (Er, 'Threshold', C.TrainedWeights(5)).NumTrained, 4); ***** test # MATLAB parity: shrink regularizes first when given penalties assert_equal (shrink (E, 'Lambda', 0.01).NumTrained, 5); ***** test # MATLAB parity: an ensemble not regularized keeps its trees C = shrink (E); assert_equal (C.NumTrained, 20); assert_equal (C.TrainedWeights, ones (20, 1)); ***** test # MATLAB parity: a shrunk bagged ensemble sums its weighted trees B = fitrensemble (X, y, 'Method', 'Bag', 'NumLearningCycles', 5); Br = regularize (B, 'Lambda', 0.001); C = shrink (Br); assert_equal (C.CombineWeights, 'WeightedSum'); P = zeros (3, 5); for t = 1:5 P(:,t) = predict (B.Trained{t}, X(1:3,:)); endfor assert_equal (predict (C, X(1:3,:)), ... P * Br.Regularization.TrainedWeights, 1e-12); ***** test # MATLAB parity: cvshrink pools the held-out error over the folds cvp = cvpartition (150, 'KFold', 3); [vals, nlearn] = cvshrink (E, 'CVPartition', cvp, 'Lambda', [0.01, 0.1], ... 'Threshold', [0, 0.5]); sse = zeros (2, 2); counts = zeros (2, 2); for k = 1:3 tr = training (cvp, k); te = test (cvp, k); Ek = regularize (fitrensemble (X(tr,:), y(tr), 'Method', 'LSBoost', ... 'NumLearningCycles', 20, ... 'Learners', tt), 'Lambda', [0.01, 0.1]); for a = 1:2 for b = 1:2 thr = [0, 0.5]; Ck = shrink (Ek, 'WeightColumn', a, 'Threshold', thr(b)); sse(a,b) += sum ((y(te) - predict (Ck, X(te,:))) .^ 2) / 150; counts(a,b) += Ck.NumTrained; endfor endfor endfor assert_equal (vals, sse, 1e-12); assert_equal (nlearn, counts / 3); ***** test # MATLAB parity: cvshrink takes the penalties of a regularized ensemble cvp = cvpartition (150, 'KFold', 3); vals = cvshrink (regularize (E, 'Lambda', [0.01, 0.1]), 'CVPartition', cvp); assert_equal (size (vals), [2, 1]); ***** test # resume empties the regularization Er = resume (regularize (E, 'Lambda', 0.1), 2); assert_equal (Er.NumTrained, 22); assert_equal (Er.Regularization, []); ***** error ... regularize (E, 'Lambda', -1) ***** error ... regularize (E, 'MaxIter', 0) ***** error ... regularize (E, 'RelTol', 0) ***** error ... regularize (E, 'Npass', 3) ***** error ... regularize (E, 'Threshold', 0.1) ***** error ... regularize (E, 'Lambda') ***** error ... shrink (E, 'WeightColumn', 1.5) ***** error ... shrink (regularize (E, 'Lambda', 0.1), 'WeightColumn', 2) ***** error ... shrink (E, 'Threshold', -1) ***** error ... shrink (E, 'Threshold', [0, 1]) ***** error ... cvshrink (E) ***** error ... cvshrink (E, 'Lambda', 0.1, 'Foo', 1) ***** shared X, yr k = (0:119)'; c = mod (k, 4) + 1; j = floor (k / 4); x2 = mod (k * 7, 10); X = [c, x2]; yb = (c == 1) | (c == 2 & mod (j, 4) != 0) | (c == 3 & mod (j, 4) == 0) ... | (x2 > 7); yr = [3; 1; 4; 1.5]; yr = yr(c) + 0.1 * sin (k) + 0.2 * x2; Xq = [1, 0; 3, 5; 5, 0; NaN, 2; 2.5, 9]; ***** test # bagged regression trees and folds take the categorical predictors Mdl = fitrensemble (X, yr, 'Method', 'Bag', 'NumLearningCycles', 3, ... 'CategoricalPredictors', 1); assert_equal (Mdl.CategoricalPredictors, 1); assert_equal (Mdl.Trained{1}.CategoricalPredictors, 1); CV = crossval (Mdl, 'KFold', 3); assert_equal (CV.Trained{1}.Trained{1}.CategoricalPredictors, 1); ***** error ... RegressionEnsemble (X, yr, 'CategoricalPredictors', 3) ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,2:3); y = meas(:,1); T = table (X(:,1), X(:,2), 'VariableNames', {'SW', 'PL'}); T.SL = y; Mdl = fitrensemble (T, 'SL'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'SL'), a); assert_equal (loss (Mdl, T), a); ***** error ... fitrensemble ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', 'Weights', ... int8 ([1; 1; 1; 1])) ***** error ... fitrensemble ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', 'Weights', true (4, 1)) ***** test ## Single weights are stored single, summing to one load fisheriris X = meas(:,2:4); y = meas(:,1); w = 1 + (1:150)' / 7; Mdl = fitrensemble (X, y, 'Weights', single (w), 'NumLearningCycles', 10); assert_equal (class (Mdl.W), 'single'); assert_equal (sum (double (Mdl.W)), 1, 1e-6); 68 tests, 68 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitrgam.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitrgam.m ***** demo rng (42); # Train a RegressionGAM Model for synthetic values f1 = @(x) cos (3 *x); f2 = @(x) x .^ 3; # generate x1 and x2 for f1 and f2 x1 = 2 * rand (50, 1) - 1; x2 = 2 * rand (50, 1) - 1; # calculate y y = f1(x1) + f2(x2); # add noise y = y + y .* 0.2 .* rand (50,1); X = [x1, x2]; # create an object a = fitrgam (X, y, 'FitMethod', 'splines', 'tol', 1e-3) ***** demo ## Fit from a table, and predict on one load fisheriris T = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); ## A column holding levels is a categorical predictor without being named ## one T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ## A model formula names the response and the predictors together, and ## holds main effects only Mdl = fitrgam (T, 'SL ~ PL + Wide'); Mdl.PredictorNames Mdl.ResponseName ## predict matches the table's variables by name, so a column the model ## was not fitted on is passed over yFit = predict (Mdl, T(1:5,:)); yFit' ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = [1; 2; 3; 4]; a = fitrgam (x, y, 'FitMethod', 'splines'); assert_equal ({a.X, a.Y}, {x, y}) assert_equal ({a.BaseModel.Intercept}, {2.5000}) assert_equal ({a.Knots, a.Order, a.DoF}, {[5, 5, 5], [3, 3, 3], [8, 8, 8]}) assert_equal ({a.NumObservations, a.NumPredictors}, {4, 3}) assert_equal ({a.ResponseName, a.PredictorNames}, {'Y', {'x1', 'x2', 'x3'}}) assert_equal ({a.Formula}, {[]}) ***** test x = [1, 2, 3, 4; 4, 5, 6, 7; 7, 8, 9, 1; 3, 2, 1, 2]; y = [1; 2; 3; 4]; pnames = {'A', 'B', 'C', 'D'}; formula = 'Y ~ A + B + C + D + A:C'; intMat = logical ([1,0,0,0;0,1,0,0;0,0,1,0;0,0,0,1;1,0,1,0]); a = fitrgam (x, y, 'FitMethod', 'splines', ... 'predictors', pnames, 'formula', formula); assert_equal (a.IntMatrix, double (intMat)) assert_equal ({a.ResponseName, a.PredictorNames}, {'Y', pnames}) assert_equal (a.Formula, formula) ***** error fitrgam () ***** error fitrgam (ones (10,2)) ***** error fitrgam (ones (4,2), ones (4, 1), 'K') ***** error fitrgam (ones (4,2), ones (3, 1)) ***** error fitrgam (ones (4,2), ones (3, 1), 'K', 2) ***** shared frgT load fisheriris frgT = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); frgT.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ***** test # the response is named by a column and the rest are predictors Mdl = fitrgam (frgT, 'SL'); assert_equal (Mdl.PredictorNames, {'SW', 'PL', 'PW', 'Wide'}); assert_equal (Mdl.ResponseName, 'SL'); assert_equal (Mdl.CategoricalPredictors, 4); ***** test # a model formula names the response and the predictors together Mdl = fitrgam (frgT, 'SL ~ PL + Wide'); assert_equal (Mdl.PredictorNames, {'PL', 'Wide'}); assert_equal (Mdl.CategoricalPredictors, 2); ***** test # the response may be given beside a table of predictors Mdl = fitrgam (frgT(:,1:3), frgT.SL); assert_equal (Mdl.PredictorNames, {'SW', 'PL', 'PW'}); assert_equal (Mdl.ResponseName, 'Y'); ***** test # predict takes a table, matched by name and not by position Mdl = fitrgam (frgT, 'SL'); a = predict (Mdl, frgT); assert_equal (numel (a), 150); assert_equal (predict (Mdl, frgT(:, [5, 4, 3, 2, 1])), a); ***** test # the levels travel with the model when it is made compact Mdl = fitrgam (frgT, 'SL'); CMdl = compact (Mdl); assert_equal (CMdl.PredictorLevels, Mdl.PredictorLevels); assert_equal (predict (CMdl, frgT), predict (Mdl, frgT)); ***** error ... fitrgam (frgT, 'NoSuch') ***** error ... fitrgam (frgT, 'SL ~ PL*PW') ***** error ... predict (fitrgam (frgT, 'SL'), frgT(:, [1, 3, 4, 5])) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Machine_Learning/ClassificationSVM.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/ClassificationSVM.m ***** demo ## Create a Support Vector Machine classifier and determine margin for test ## data. load fisheriris ## Select indices of the non-setosa species inds = ! strcmp (species, 'setosa'); ## Select features and labels for non-setosa species X = meas(inds, 3:4); Y = grp2idx (species(inds)); ## Convert labels to +1 and -1 unique_classes = unique (Y); Y(Y == unique_classes(1)) = -1; Y(Y == unique_classes(2)) = 1; ## Partition data for training and testing cv = cvpartition (Y, 'HoldOut', 0.15); X_train = X(training(cv), :); Y_train = Y(training(cv)); X_test = X(test (cv), :); Y_test = Y(test (cv)); ## Train the SVM model CVSVMModel = fitcsvm (X_train, Y_train); ## Calculate margins m = margin (CVSVMModel, X_test, Y_test); disp (m); ***** demo ## Create a Support Vector Machine classifier and determine loss for test ## data. load fisheriris ## Select indices of the non-setosa species inds = ! strcmp (species, 'setosa'); ## Select features and labels for non-setosa species X = meas(inds, 3:4); Y = grp2idx (species(inds)); ## Convert labels to +1 and -1 unique_classes = unique (Y); Y(Y == unique_classes(1)) = -1; Y(Y == unique_classes(2)) = 1; ## Randomly partition the data into training and testing sets cv = cvpartition (Y, 'HoldOut', 0.3); # 30% data for testing, 60% for training X_train = X(training(cv), :); Y_train = Y(training(cv)); X_test = X(test (cv), :); Y_test = Y(test (cv)); ## Train the SVM model SVMModel = fitcsvm (X_train, Y_train); ## Calculate loss L = loss (SVMModel,X_test,Y_test,'LossFun','binodeviance') L = loss (SVMModel,X_test,Y_test,'LossFun','classiferror') L = loss (SVMModel,X_test,Y_test,'LossFun','exponential') L = loss (SVMModel,X_test,Y_test,'LossFun','hinge') L = loss (SVMModel,X_test,Y_test,'LossFun','logit') L = loss (SVMModel,X_test,Y_test,'LossFun','quadratic') ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1; 4, 5, 6; 7, 8, 9; ... 3, 2, 1; 4, 5, 6; 7, 8, 9; 3, 2, 1; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = [1; 2; 3; 4; 2; 3; 4; 2; 3; 4; 2; 3; 4]; a = ClassificationSVM (x, y, 'ClassNames', [1, 2]); assert_equal (class (a), "ClassificationSVM"); m = logical ([1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0]'); assert_equal (a.RowsUsed, m); assert_equal ({a.X, a.Y}, {x(m,:), y(m)}) assert_equal (a.NumObservations, 5) assert_equal ({a.ResponseName, a.PredictorNames}, {'Y', {'x1', 'x2', 'x3'}}) assert_equal ({a.ClassNames, a.ModelParameters.SVMtype}, {[1; 2], 'c_svc'}) ***** test x = [1, 2; 2, 3; 3, 4; 4, 5; 2, 3; 3, 4; 2, 3; 3, 4; 2, 3; 3, 4]; y = [1; 1; -1; -1; 1; -1; -1; -1; -1; -1]; a = ClassificationSVM (x, y); assert_equal (class (a), "ClassificationSVM"); assert_equal ({a.X, a.Y, a.ModelParameters.KernelFunction}, {x, y, 'linear'}) assert_equal (a.ModelParameters.BoxConstraint, 1) assert_equal (a.ClassNames, [-1; 1]) assert_equal (a.ModelParameters.KernelOffset, 0) ***** test x = [1, 2; 2, 3; 3, 4; 4, 5; 2, 3; 3, 4; 2, 3; 3, 4; 2, 3; 3, 4]; y = [1; 1; -1; -1; 1; -1; -1; -1; -1; -1]; a = ClassificationSVM (x, y, 'KernelFunction', 'rbf', 'BoxConstraint', 2, ... 'KernelOffset', 2); assert_equal (class (a), "ClassificationSVM"); assert_equal ({a.X, a.Y, a.ModelParameters.KernelFunction}, {x, y, 'rbf'}) assert_equal (a.ModelParameters.BoxConstraint, 2) assert_equal (a.ModelParameters.KernelOffset, 2) ***** test x = [1, 2; 2, 3; 3, 4; 4, 5; 2, 3; 3, 4; 2, 3; 3, 4; 2, 3; 3, 4]; y = [1; 1; -1; -1; 1; -1; -1; -1; -1; -1]; a = ClassificationSVM (x, y, 'KernelFunction', 'polynomial', ... 'PolynomialOrder', 3); assert_equal (class (a), "ClassificationSVM"); assert_equal ({a.X, a.Y, a.ModelParameters.KernelFunction}, {x, y, 'polynomial'}) assert_equal (a.ModelParameters.KernelPolynomialOrder, 3) ***** test randn ('seed', 42); lab = double (randn (40, 1) > 0) + 1; X = [randn(40, 3); NaN, 1, 1]; Y = [lab; 1]; Mdl = fitcsvm (X, Y); assert_equal (Mdl.RowsUsed, []); assert_equal (rows (Mdl.X), Mdl.NumObservations); ***** test randn ('seed', 42); lab = double (randn (40, 1) > 0) + 1; X = [randn(40, 3); NaN, 1, 1]; Y = [lab; 1]; Mdl = fitcsvm (X, Y); assert_equal (Mdl.NumObservations, 41); assert_equal (Mdl.RowsUsed, []); assert_equal (resubPredict (Mdl), predict (Mdl, Mdl.X)); ***** test randn ('seed', 42); X = randn (31, 2); Y = [double(randn (30, 1) > 0) + 1; NaN]; Mdl = fitcsvm (X, Y); fname = tempname (); savemodel (Mdl, fname); d = load (fname); d.RowsUsed = double (d.RowsUsed); save ('-binary', fname, '-struct', 'd'); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2.RowsUsed), 'logical'); assert_equal (rows (M2.X(M2.RowsUsed, :)), M2.NumObservations); ***** test load fisheriris Yb = strcmp (species, 'setosa'); Mdl = fitcsvm (meas, Yb); assert_equal (Mdl.Prior, [2/3, 1/3], 1e-12); assert_equal (Mdl.Cost, [0, 1; 1, 0]); Yu = [repmat({'a'}, 120, 1); repmat({'b'}, 30, 1)]; M2 = fitcsvm (meas, Yu); assert_equal (M2.Prior, [0.8, 0.2], 1e-12); assert_equal (fitcsvm (meas, Yu, 'Prior', 'uniform').Prior, [0.5, 0.5]); assert_equal (fitcsvm (meas, Yu, 'Prior', [3, 1]).Prior, [0.75, 0.25]); ***** test load fisheriris Yu = [repmat({'a'}, 120, 1); repmat({'b'}, 30, 1)]; base = fitcsvm (meas, Yu); assert_equal (isequal (fitcsvm (meas, Yu, 'Prior', [0.5, 0.5]).Alpha, ... base.Alpha), false); assert_equal (isequal (fitcsvm (meas, Yu, 'Cost', [0, 5; 1, 0]).Alpha, ... base.Alpha), false); same = fitcsvm (meas, Yu, 'Prior', 'empirical', 'Cost', [0, 1; 1, 0]); assert_equal (same.Alpha, base.Alpha); assert_equal (same.Bias, base.Bias); ***** test load fisheriris X = meas(51:150,:); Yb = strcmp (species(51:150), 'versicolor'); Ypm = ones (100, 1); Ypm(Yb) = -1; Mdl = fitcsvm (X, Yb, 'KernelFunction', 'linear'); assert_equal (loss (Mdl, X, Ypm, 'LossFun', 'classiferror'), 0.01, 1e-12); assert_equal (loss (Mdl, X, Ypm, 'LossFun', 'classifcost'), 0.01, 1e-12); assert_equal (loss (Mdl, X, Ypm, 'LossFun', 'mincost'), 0.01, 1e-12); Mc = fitcsvm (X, Yb, 'KernelFunction', 'linear', 'Cost', [0, 4; 1, 0]); assert_equal (loss (Mc, X, Ypm, 'LossFun', 'classifcost'), 0.04, 1e-12); assert_equal (loss (Mc, X, Ypm, 'LossFun', 'mincost'), 0.04, 1e-12); ***** test load fisheriris X = meas(51:150,:); Yb = strcmp (species(51:150), 'versicolor'); assert_equal (resubLoss (fitcsvm (X, Yb, 'KernelFunction', 'linear')), ... 0.01, 1e-12); assert_equal (resubLoss (fitcsvm (X, double (Yb) + 1, ... 'KernelFunction', 'linear')), 0.01, 1e-12); assert_equal (resubLoss (fitcsvm (X, species(51:150), ... 'KernelFunction', 'linear')), 0.01, 1e-12); ***** test load fisheriris X = meas(51:150,:); Yb = strcmp (species(51:150), 'versicolor'); Ypm = ones (100, 1); Ypm(Yb) = -1; Mdl = fitcsvm (X, Yb, 'KernelFunction', 'linear', 'Cost', [0, 4; 1, 0]); CMdl = compact (Mdl); assert_equal (CMdl.Prior, Mdl.Prior); assert_equal (CMdl.Cost, Mdl.Cost); for f = {'classiferror', 'classifcost', 'mincost'} assert_equal (loss (CMdl, X, Ypm, 'LossFun', f{1}), ... loss (Mdl, X, Ypm, 'LossFun', f{1}), 1e-12); endfor ***** test load fisheriris keep = ! strcmp (species, "setosa"); X = meas(keep,:); y = species(keep); Mdl = fitcsvm (X, y, "KernelFunction", "linear"); D = discardSupportVectors (Mdl); assert_equal (class (D), "ClassificationSVM"); assert_equal (isempty (D.Alpha), true); assert_equal (isempty (D.SupportVectors), true); assert_equal (isempty (D.SupportVectorLabels), true); assert_equal (D.Beta, Mdl.Beta); assert_equal (D.Bias, Mdl.Bias); assert_equal (D.IsSupportVector, Mdl.IsSupportVector); ***** test load fisheriris keep = ! strcmp (species, "setosa"); X = meas(keep,:); y = species(keep); Mdl = fitcsvm (X, y, "KernelFunction", "linear"); D = discardSupportVectors (Mdl); assert_equal (predict (D, X), predict (Mdl, X), 1e-10); ***** test load fisheriris keep = ! strcmp (species, "setosa"); X = meas(keep,:); y = species(keep); Mdl = fitcsvm (X, y, "KernelFunction", "linear"); D = discardSupportVectors (Mdl); assert_equal (rows (Mdl.Model.SVs) > 1, true); assert_equal (rows (D.Model.SVs), 1); assert_equal (predict (discardSupportVectors (D), X), predict (D, X)); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcsvm (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcsvm (Xch, Ycell); assert_equal (size (Mc.ClassNames), [2, 10]); assert_equal (cellstr (Mc.ClassNames), Ms.ClassNames); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcsvm (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcsvm (Xch, Ycell); pch = predict (Mc, Xch); assert_equal (columns (pch), 10); assert_equal (cellstr (pch), predict (Ms, Xch)); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcsvm (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcsvm (Xch, Ycell); assert_equal (loss (Mc, Xch, Ych), loss (Ms, Xch, Ycell), 1e-12); assert_equal (margin (Mc, Xch, Ych), margin (Ms, Xch, Ycell), 1e-12); assert_equal (edge (Mc, Xch, Ych), edge (Ms, Xch, Ycell), 1e-12); ***** test Xpad = [1 2; 3 4; 1.1 2.1; 3.1 4.1; 1.2 2.2; 3.2 4.2]; Ypad = char ({"ab", "abcd", "ab", "abcd", "ab", "abcd"}); rand ("state", 1); randn ("state", 1); Mp = fitcsvm (Xpad, Ypad); assert_equal (size (Mp.ClassNames), [2, 4]); assert_equal (Mp.ClassNames(1,:), "ab "); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); Xmiss = Xch; Xmiss(3,2) = NaN; rand ("state", 1); randn ("state", 1); Md = fitcsvm (Xmiss, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcsvm (Xmiss, Ycell); assert_equal (size (Md.ClassNames), [2, 10]); assert_equal (cellstr (Md.ClassNames), Ms.ClassNames); ***** test load fisheriris rand ("state", 1); randn ("state", 1); Mf = fitcsvm (meas, char (species), ... "ClassNames", char ({"versicolor", "virginica"})); assert_equal (rows (Mf.ClassNames), 2); assert_equal (cellstr (Mf.ClassNames), {"versicolor"; "virginica"}); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcsvm (Xch, Ych); fname = tempname (); savemodel (Mc, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.ClassNames, Mc.ClassNames); assert_equal (predict (M2, Xch), predict (Mc, Xch)); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcsvm (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcsvm (Xch, Ycell); rand ("state", 2); cvc = crossval (Mc, "KFold", 3); rand ("state", 2); cvs = crossval (Ms, "KFold", 3); assert_equal (cellstr (kfoldPredict (cvc)), kfoldPredict (cvs)); ***** test # A row missing a predictor takes the class of largest prior X = [(1:10)', mod((1:10)', 3)]; y = [1; 1; 1; 1; 1; 1; 2; 2; 2; 2]; Mdl = ClassificationSVM (X, y); [label, score, cost] = predict (Mdl, [NaN, 1]); assert_equal (label, 1); assert_equal (score, [NaN, NaN]); assert_equal (cost, [NaN, NaN]); Mdl = ClassificationSVM (X, y, 'Prior', [0.3, 0.7]); assert_equal (predict (Mdl, [NaN, 1]), 2); ***** test # resubPredict on a row missing a predictor X = [NaN, 1; (2:10)', mod((2:10)', 3)]; y = [1; 1; 1; 1; 1; 1; 2; 2; 2; 2]; [label, score, cost] = resubPredict (ClassificationSVM (X, y)); assert_equal (label(1), 1); assert_equal (score(1,:), [NaN, NaN]); assert_equal (cost(1,:), [NaN, NaN]); ***** test load fisheriris X = meas(51:150,[1, 3]); Y = species(51:150); k = (1:100)'; w = (1 + mod (k, 4)) .* (1 + 2 * (k > 50)); Mdl = fitcsvm (X, Y, 'Weights', w); assert_equal (Mdl.Prior, [0.25, 0.75], 1e-15); assert_equal (Mdl.W([1, 51])', [0.004, 0.024], 1e-15); assert_equal (Mdl.BoxConstraints([1, 2, 51])', [0.4, 0.6, 2.4], 1e-14); assert_equal (sum (Mdl.IsSupportVector), 33); assert_equal (resubLoss (Mdl), 0.036, 1e-15); assert_equal (loss (Mdl, X, Y), 0.035, 1e-15); ***** test load fisheriris X = meas(51:150,[1, 3]); Y = species(51:150); k = (1:100)'; w = (1 + mod (k, 4)) .* (1 + 2 * (k > 50)); Mdl = fitcsvm (X, Y, 'Weights', w, 'Prior', 'uniform'); assert_equal (Mdl.W([1, 51])', [0.008, 0.016], 1e-15); assert_equal (Mdl.BoxConstraints([1, 2, 51])', [0.8, 1.2, 1.6], 1e-14); ***** test load fisheriris X = meas(51:150,[1, 3]); Y = species(51:150); k = (1:100)'; w = (1 + mod (k, 4)) .* (1 + 2 * (k > 50)); Mdl = fitcsvm (X, Y, 'Weights', w, 'Cost', [0, 1; 2, 0]); assert_equal (Mdl.W([1, 51])', [0.004, 0.024], 1e-15); assert_equal (Mdl.BoxConstraints([1, 51])', ... [0.228571428571429, 2.74285714285714], 1e-14); ***** test load fisheriris X = meas(51:150,[1, 3]); Y = species(51:150); k = (1:100)'; w = (1 + mod (k, 4)) .* (1 + 2 * (k > 50)); Mdl = fitcsvm (X, Y, 'Weights', w, 'Standardize', true); assert_equal (Mdl.Mu, [6.4276, 5.2492], 1e-13); assert_equal (Mdl.Sigma, [0.614100287471456, 0.737655900905504], 1e-14); ***** test load fisheriris X = meas(51:150,[1, 3]); Y = species(51:150); k = (1:100)'; w = (1 + mod (k, 4)) .* (1 + 2 * (k > 50)); w([2, 60]) = 0; Mdl = fitcsvm (X, Y, 'Weights', w); assert_equal (Mdl.NumObservations, 98); ***** test load fisheriris Xo = meas(51:100,[1, 3]); M = fitcsvm (Xo, ones (50, 1)); [lab, s] = predict (M, [6, 4.3; 5, 3.5; 7, 4.7; 5.5, 5]); assert_equal (lab, ones (4, 1)); assert_equal (size (s), [4, 1]); assert_equal (resubLoss (M), 0); Mw = fitcsvm (Xo, ones (50, 1), 'Weights', 1 + mod ((1:50)', 4)); assert_equal (Mw.Bias, M.Bias); assert_equal (Mw.BoxConstraints, ones (50, 1)); assert_equal (Mw.W(1:2)', [0.016, 0.024], 1e-15); lab = predict (fitcsvm (Xo, repmat ({'a'}, 50, 1)), [5, 3.5; 7, 4.7]); assert_equal (lab, {'a'; 'a'}); ***** test load fisheriris Xo = meas(51:100,[1, 3]); M = fitcsvm (Xo, ones (50, 1), 'KernelFunction', 'linear', 'Nu', 0.5); assert_equal (M.Bias, -998.52, 1e-10); assert_equal (sum (M.IsSupportVector), 25); M = fitcsvm (Xo, ones (50, 1), 'KernelFunction', 'linear', 'Nu', 0.1); assert_equal (M.Bias, -179.52, 1e-10); [~, s] = predict (M, Xo); assert_equal (min (s(M.IsSupportVector)), 0, 1e-10); ***** test load fisheriris Xo = meas(51:100,[1, 3]); M = fitcsvm (Xo, ones (50, 1), 'OutlierFraction', 0.1); assert_equal (M.Nu, 0.5); [~, s] = predict (M, Xo); assert_equal (mean (s < 0), 0.1); ***** test load fisheriris M = fitcsvm (meas(51:100,[1, 3]), ones (50, 1), 'KernelFunction', ... 'linear', 'Nu', 0.5); assert_equal (resubLoss (M, 'LossFun', 'classifcost'), 0); assert_equal (resubLoss (M, 'LossFun', 'binodeviance'), ... 0.0144818627743958, 1e-12); assert_equal (resubLoss (M, 'LossFun', 'exponential'), ... 0.0235456917291944, 1e-12); assert_equal (resubLoss (M, 'LossFun', 'hinge'), 0.02, 1e-12); assert_equal (resubLoss (M, 'LossFun', 'logit'), 0.0171271559174886, 1e-12); assert_equal (resubLoss (M, 'LossFun', 'quadratic'), 68502.381296, 1e-6); Q = [6, 4.3; 5, 3.5; 7, 4.7; 5.5, 5; 6.2, 4.5]; assert_equal (margin (M, Q, ones (5, 1)), NaN (5, 1)); assert_equal (edge (M, Q, ones (5, 1)), NaN); assert_equal (resubEdge (M), NaN); assert_equal (margin (compact (M), Q, ones (5, 1)), NaN (5, 1)); ***** warning ... ClassificationSVM ((1:20)' * 1000, repmat ([1; 2], 10, 1), ... 'KernelFunction', 'polynomial'); ***** error ... fitcsvm ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', 'a') ***** error ... fitcsvm ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', ones (2, 2)) ***** error ... fitcsvm ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', [1, 2]) ***** error ... fitcsvm ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', -ones (4, 1)) ***** error ... load fisheriris keep = ! strcmp (species, "setosa"); X = meas(keep,:); y = species(keep); discardSupportVectors (fitcsvm (X, y, "KernelFunction", "rbf")) ***** error ... fitcsvm (ones (10,2), [1;1;1;1;1;2;2;2;2;2], 'Prior', 'nope') ***** error ... fitcsvm (ones (10,2), [1;1;1;1;1;2;2;2;2;2], 'Cost', [0, 1]) ***** error ... fitcsvm (ones (10,2), [1;1;1;1;1;2;2;2;2;2], 'Prior', [1, 1, 1]) ***** error ... fitcsvm (ones (10,2), [1;1;1;1;1;2;2;2;2;2], 'Cost', eye (3)) ***** test load fisheriris Yb = strcmp (species, 'setosa'); Mdl = fitcsvm (meas, Yb); assert_equal (size (Mdl.W), [150, 1]); assert_equal (sum (Mdl.W), 1, 1e-12); assert_equal (Mdl.W, ones (150, 1) / 150, 1e-12); assert_equal (Mdl.CategoricalPredictors, []); assert_equal (Mdl.ExpandedPredictorNames, Mdl.PredictorNames); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.W, Mdl.W); assert_equal (M2.ExpandedPredictorNames, Mdl.ExpandedPredictorNames); ***** test rand ('seed', 42); randn ('seed', 42); n = 80; A = [randn(n,1) + 1, (randn(n,1) + 1) * 1000]; B = [randn(n,1) - 1, (randn(n,1) - 1) * 1000]; X = [A; B]; Y = [ones(n,1); 2 * ones(n,1)]; Mdl = fitcsvm (X, Y, 'Standardize', true, 'KernelFunction', 'rbf'); assert_equal (mean (resubPredict (Mdl) == Y) > 0.85, true); assert_equal (predict (Mdl, X), resubPredict (Mdl)); Mu = mean (X, 1); Sg = std (X, [], 1); byhand = fitcsvm ((X - Mu) ./ Sg, Y, 'Standardize', false, ... 'KernelFunction', 'rbf'); assert_equal (mean (resubPredict (Mdl) == Y), ... mean (resubPredict (byhand) == Y)); ***** test # the fit does not depend on what the two classes are called ## LIBSVM reorders a two-class problem labelled -1 and +1 so that its ## first class is the +1 one, and the class indices are what it is given ## so that this cannot reach the labels read back. Before, a numeric ## response went through as it stood and every label came back the other ## one: on this fixture resubLoss was 1 rather than 0. rand ('seed', 42); randn ('seed', 42); X = [randn(20, 2); randn(20, 2) + 6]; truth = [ones(20, 1); 2 * ones(20, 1)]; names = {[-1; 1], [1; 2], [0; 1], [5; 7], [2; 1]}; for i = 1:numel (names) lab = names{i}; Mdl = ClassificationSVM (X, lab(truth)); assert_equal (resubLoss (Mdl), 0); assert_equal (predict (Mdl, X), lab(truth)); endfor ***** test # a numeric response and a textual one give the same fit rand ('seed', 42); randn ('seed', 42); X = [randn(20, 2); randn(20, 2) + 6]; truth = [ones(20, 1); 2 * ones(20, 1)]; num = ClassificationSVM (X, [-1; 1](truth)); txt = ClassificationSVM (X, {'neg', 'pos'}'(truth)); [~, snum] = predict (num, X); [~, stxt] = predict (txt, X); assert_equal (snum, stxt, 1e-12); assert_equal (num.Beta, txt.Beta, 1e-12); ***** test # A categorical 'ClassNames' is accepted load fisheriris y = categorical (species(51:150)); Mdl = ClassificationSVM (meas(51:150,:), y, 'ClassNames', ... categorical ({'versicolor'; 'virginica'})); assert_equal (class (Mdl.ClassNames), 'categorical'); assert_equal (numel (Mdl.ClassNames), 2); ***** test # An unused category of a categorical response is not a class load fisheriris y = categorical (species); Mdl = ClassificationSVM (meas(51:150,:), y(51:150)); assert_equal (cellstr (Mdl.ClassNames), {'versicolor'; 'virginica'}); assert_equal (predict (Mdl, meas(51,:)), y(51)); ***** error ClassificationSVM () ***** error ... ClassificationSVM (ones (10,2)) ***** error ... ClassificationSVM (ones (10,2), ones (5,1)) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'Standardize', 'a') ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'PredictorNames', ['x1';'x2']) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'PredictorNames', {'x1','x2','x3'}) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'ResponseName', {'Y'}) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'ResponseName', 21) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'ClassNames', @(x)x) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'ClassNames', {1}) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'ClassNames', [1, 2]) ***** error ... ClassificationSVM (ones (5,2), ['a';'b';'a';'a';'b'], 'ClassNames', ['a';'c']) ***** error ... ClassificationSVM (ones (5,2), {'a';'b';'a';'a';'b'}, 'ClassNames', {'a','c'}) ***** error ... ClassificationSVM (ones (10,2), logical (ones (10,1)), 'ClassNames', [true, false]) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'svmtype', 123) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'svmtype', 'some_type') ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'OutlierFraction', -1) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'KernelFunction', 123) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'KernelFunction', 'fcn') ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'PolynomialOrder', -1) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'PolynomialOrder', 0.5) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'PolynomialOrder', [1,2]) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'KernelScale', -1) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'KernelScale', 0) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'KernelScale', [1, 2]) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'KernelScale', 'invalid') ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'KernelOffset', -1) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'KernelOffset', [1,2]) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'BoxConstraint', -1) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'BoxConstraint', 0) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'BoxConstraint', [1, 2]) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'BoxConstraint', 'invalid') ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'nu', -0.5) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'nu', 0) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'nu', 1.5) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'CacheSize', -1) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'CacheSize', [1,2]) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'Tolerance', -0.1) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'Tolerance', [0.1,0.2]) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'shrinking', 2) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'shrinking', -1) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'shrinking', [1 0]) ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'invalid_name', 'c_svc') ***** error ... ClassificationSVM (ones (10,2), ones (10,1), 'SVMtype', 'c_svc') ***** error ... ClassificationSVM (ones (10,2), [1;1;1;1;2;2;2;2;3;3]) ***** error ... ClassificationSVM ([ones(9,2);2,Inf], ones (10,1)) ***** shared x, y, x_train, x_test, y_train, y_test, objST load fisheriris inds = ! strcmp (species, 'setosa'); x = meas(inds, 3:4); y = grp2idx (species(inds)); ***** test xc = [min(x); mean(x); max(x)]; obj = fitcsvm (x, y, 'KernelFunction', 'rbf', 'Tolerance', 1e-7); assert_equal (isempty (obj.Beta), true) assert_equal (sum (obj.IsSupportVector), numel (obj.Alpha)) [label, score] = predict (obj, xc); assert_equal (label, [1; 2; 2]); ## R2024a's scores. assert_equal (score(:,1), [0.9813697204; -0.1752955874; ... -0.9410361822], 5e-4); assert_equal (score(:,1), -score(:,2), eps) ***** test obj = fitcsvm (x, y); assert_equal (obj.Beta, [2.182926829268275; 2.253658536585344], 1e-5) assert_equal (sum (obj.IsSupportVector), numel (obj.Alpha)) assert_equal (numel (obj.Alpha), 24) assert_equal (obj.Bias, -14.415, 1e-3) xc = [min(x); mean(x); max(x)]; label = predict (obj, xc); assert_equal (label, [1; 2; 2]); ***** test ## a linear kernel has a primal representation, one coefficient per predictor obj = fitcsvm (x, y); assert_equal (size (obj.Beta), [2, 1]); assert_equal (obj.Beta, [2.182926829268275; 2.253658536585344], 1e-5); assert_equal (obj.Beta, ... obj.SupportVectors' * (obj.Alpha .* obj.SupportVectorLabels)); ***** test ## a nonlinear kernel has none, but keeps the dual coefficients obj = fitcsvm (x, y, 'KernelFunction', 'rbf'); assert_equal (isempty (obj.Beta), true); assert_equal (numel (obj.Alpha), sum (obj.IsSupportVector)); ***** test obj = fitcsvm (x, y, 'KernelScale', 2); assert_equal (obj.Beta, [3.19512195122; 2.55609756098], 1e-6); ***** test obj = fitcsvm (x, y, 'KernelScale', 2); assert_equal (obj.Bias, -10.0870731707, 1e-6); ***** test obj = fitcsvm (x, y, 'KernelScale', 2); Q = x([1, 30, 60, 90],:); [~, score] = predict (obj, Q); assert_equal (score(:,2), (Q / 2) * obj.Beta + obj.Bias, 1e-12); ***** test obj = fitcsvm (x, y, 'KernelFunction', 'gaussian', 'KernelScale', 2); [~, score] = predict (obj, x([1, 30, 60, 90],:)); assert_equal (score(:,2), [-0.827757529685; -2.17748767098; ... 2.25809330158; 1.59440000202], 1e-6); ***** test obj = fitcsvm (x, y, 'KernelFunction', 'polynomial', 'KernelScale', 2, ... 'PolynomialOrder', 2); [~, score] = predict (obj, x([1, 30, 60, 90],:)); assert_equal (score(:,2), [-1.23481189405; -4.72633601992; ... 6.48549554678; 2.83864647222], 2e-3); ***** test obj = fitcsvm (x, y, 'KernelFunction', 'gaussian', 'KernelScale', 2); assert_equal (obj.SupportVectors, x(obj.IsSupportVector,:)); ***** test obj = fitcsvm (x, ones (100, 1), 'KernelFunction', 'gaussian', ... 'KernelScale', 2, 'Nu', 0.3); assert_equal (obj.Bias, -13.4656686131, 1e-6); ***** test obj = fitcsvm (x, ones (100, 1), 'KernelFunction', 'linear', 'Nu', 0.3); assert_equal (unique (obj.SupportVectorLabels), 1); ***** test obj = fitcsvm (x, ones (100, 1), 'KernelFunction', 'linear', 'Nu', 0.3); assert_equal (obj.Beta, [119.2; 36.4], 1e-9); ***** test ## Parameters reach the engine at full precision. obj = fitcsvm (x, y, 'BoxConstraint', 1e-7); assert_equal (max (obj.Alpha), 1e-7, 1e-20); ***** test obj = fitcsvm (x, y, 'BoxConstraint', 0.1234567891); assert_equal (max (obj.Alpha), 0.1234567891, 1e-15); ***** test obj = fitcsvm (x, ones (100, 1), 'Nu', 1e-7); assert_equal (sum (obj.Alpha), 1e-5, 1e-18); ***** test ## MATLAB adds KernelOffset to the Gram matrix, which changes no fit. A = fitcsvm (x, y, 'KernelFunction', 'polynomial'); B = fitcsvm (x, y, 'KernelFunction', 'polynomial', 'KernelOffset', 0.5); [~, sA] = predict (A, x); [~, sB] = predict (B, x); assert_equal (sB, sA); ***** test obj = fitcsvm (x, y, 'KernelScale', 2); [~, s1] = predict (obj, x); [~, s2] = predict (discardSupportVectors (obj), x); assert_equal (s2, s1, 1e-12); ***** test ## the dual coefficients are magnitudes; their class is in the labels obj = fitcsvm (x, y); assert_equal (any (obj.Alpha < 0), false); assert_equal (max (obj.Alpha) <= 1, true); assert_equal (size (obj.SupportVectorLabels), [24, 1]); assert_equal (unique (obj.SupportVectorLabels)', [-1, 1]); ***** test ## the support vector indicator is logical, one entry per observation obj = fitcsvm (x, y); assert_equal (class (obj.IsSupportVector), 'logical'); assert_equal (size (obj.IsSupportVector), [100, 1]); assert_equal (sum (obj.IsSupportVector), 24); ***** test obj = fitcsvm (x, y); xc = [min(x); mean(x); max(x)]; batch = predict (obj, xc); for i = 1:rows (xc) assert_equal (predict (obj, xc(i,:)), batch(i)); endfor ***** test obj = fitcsvm (x, y, 'KernelFunction', 'rbf', 'Tolerance', 1e-7); xc = [min(x); mean(x); max(x)]; [bl, bs] = predict (obj, xc); [l1, s1] = predict (obj, xc(1,:)); assert_equal (l1, bl(1)); assert_equal (size (l1), [1, 1]); assert_equal (size (s1), [1, 2]); assert_equal (s1, bs(1,:), 2e-5); ***** test obj = compact (fitcsvm (x, y)); xc = [min(x); mean(x); max(x)]; batch = predict (obj, xc); assert_equal (predict (obj, xc(1,:)), batch(1)); ***** error ... predict (ClassificationSVM (ones (40,2), ones (40,1))) ***** error ... predict (ClassificationSVM (ones (40,2), ones (40,1)), []) ***** error ... predict (ClassificationSVM (ones (40,2), ones (40,1)), 1) ***** test objST = fitcsvm (x, y); ***** error ... objST.ScoreTransform = 'a'; [labels, scores] = predict (objST, x); [labels, scores] = resubPredict (objST); ***** test rand ('seed', 1); CVSVMModel = fitcsvm (x, y, 'KernelFunction', 'rbf', 'HoldOut', 0.15, ... 'Tolerance', 1e-7); obj = CVSVMModel.Trained{1}; testInds = test (CVSVMModel.Partition); ## R2024a's margins, fitted on the same training rows with the prior the ## fold inherits, [0.5 0.5]. Every one of the fifteen is classified ## correctly, so every margin is positive. expected_margin = [2.185059262; 0.993999246; 1.999333315; 3.078654435; ... 2.977495193; 2.191955906; 3.269512295; 2.323010586; ... 3.185859883; 3.140175181; 1.701291423; 3.210493533; ... 1.034142171; 3.033060133; 2.799817759]; computed_margin = margin (obj, x(testInds,:), y(testInds,:)); assert_equal (computed_margin, expected_margin, 2e-3); assert (all (computed_margin > 0)); ***** error ... margin (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1))) ***** error ... margin (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), zeros (2)) ***** error ... margin (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), [], zeros (2)) ***** error ... margin (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), 1, zeros (2)) ***** error ... margin (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), zeros (2), []) ***** error ... margin (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), zeros (2), 1) ***** test rand ('seed', 1); CVSVMModel = fitcsvm (x, y, 'KernelFunction', 'rbf', 'HoldOut', 0.15); obj = CVSVMModel.Trained{1}; testInds = test (CVSVMModel.Partition); L1 = loss (obj, x(testInds,:), y(testInds,:), 'LossFun', 'binodeviance'); L2 = loss (obj, x(testInds,:), y(testInds,:), 'LossFun', 'classiferror'); L3 = loss (obj, x(testInds,:), y(testInds,:), 'LossFun', 'exponential'); L4 = loss (obj, x(testInds,:), y(testInds,:), 'LossFun', 'hinge'); L5 = loss (obj, x(testInds,:), y(testInds,:), 'LossFun', 'logit'); L6 = loss (obj, x(testInds,:), y(testInds,:), 'LossFun', 'quadratic'); ## R2024a's losses, fitted on the same training rows with the prior the ## fold inherits, [0.5 0.5]. assert_equal (L1, 0.1057769174, 5e-4); assert_equal (L2, 0, 5e-4); assert_equal (L3, 0.3138559104, 5e-4); assert_equal (L4, 0.07547010872, 5e-4); assert_equal (L5, 0.2681965038, 5e-4); assert_equal (L6, 0.1954123863, 5e-4); ***** error ... loss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1))) ***** error ... loss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), zeros (2)) ***** error ... loss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), zeros (2), ... ones (2,1), 'LossFun') ***** error ... loss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), [], zeros (2)) ***** error ... loss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), 1, zeros (2)) ***** error ... loss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), zeros (2), []) ***** error ... loss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), zeros (2), 1) ***** error ... loss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), zeros (2), ... ones (2,1), 'LossFun', 1) ***** error ... loss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), zeros (2), ... ones (2,1), 'LossFun', 'some') ***** error ... loss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), zeros (2), ... ones (2,1), 'Weights', ['a','b']) ***** error ... loss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), zeros (2), ... ones (2,1), 'Weights', ones (2, 2)) ***** error ... loss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), zeros (2), ... ones (2,1), 'Weights', 'a') ***** error ... loss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), zeros (2), ... ones (2,1), 'Weights', [1,2,3]) ***** error ... loss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), zeros (2), ... ones (2,1), 'Weights', 3) ***** error ... loss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), zeros (2), ... ones (2,1), 'some', 'some') ***** error ... resubLoss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), 'LossFun') ***** error ... resubLoss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), 'LossFun', 1) ***** error ... resubLoss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), 'LossFun', 'some') ***** error ... resubLoss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), 'Weights', ['a','b']) ***** error ... resubLoss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), ... 'Weights', ones (2, 2)) ***** error ... resubLoss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), 'Weights', 'a') ***** error ... resubLoss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), 'Weights', [1,2,3]) ***** error ... resubLoss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), 'Weights', 3) ***** error ... resubLoss (ClassificationSVM (ones (40,2), randi ([1, 2], 40, 1)), 'some', 'some') ***** test SVMModel = fitcsvm (x, y); status = warning; warning ('off'); rand ('seed', 23); CVMdl = crossval (SVMModel, 'KFold', 5); warning (status); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (CVMdl.KFold == 5, true) assert_equal (class (CVMdl.Trained{1}), "CompactClassificationSVM") assert_equal (CVMdl.CrossValidatedModel, "SVM") ***** test obj = fitcsvm (x, y); status = warning; warning ('off'); rand ('seed', 23); CVMdl = crossval (obj, 'HoldOut', 0.2); warning (status); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (class (CVMdl.Trained{1}), "CompactClassificationSVM") assert_equal (CVMdl.CrossValidatedModel, "SVM") ***** test obj = fitcsvm (x, y); status = warning; warning ('off'); rand ('seed', 23); CVMdl = crossval (obj, 'LeaveOut', 'on'); warning (status); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (class (CVMdl.Trained{1}), "CompactClassificationSVM") assert_equal (CVMdl.CrossValidatedModel, "SVM") ***** error ... crossval (ClassificationSVM (ones (40,2),randi ([1, 2], 40, 1)), 'KFold') ***** error ... crossval (ClassificationSVM (ones (40,2),randi ([1, 2], 40, 1)), ... 'KFold', 5, 'leaveout', 'on') ***** error ... crossval (ClassificationSVM (ones (40,2),randi ([1, 2], 40, 1)), 'KFold', 'a') ***** error ... crossval (ClassificationSVM (ones (40,2),randi ([1, 2], 40, 1)), 'KFold', 1) ***** error ... crossval (ClassificationSVM (ones (40,2),randi ([1, 2], 40, 1)), 'KFold', -1) ***** error ... crossval (ClassificationSVM (ones (40,2),randi ([1, 2], 40, 1)), 'KFold', 11.5) ***** error ... crossval (ClassificationSVM (ones (40,2),randi ([1, 2], 40, 1)), 'KFold', [1,2]) ***** error ... crossval (ClassificationSVM (ones (40,2),randi ([1, 2], 40, 1)), 'Holdout', 'a') ***** error ... crossval (ClassificationSVM (ones (40,2),randi ([1, 2], 40, 1)), 'Holdout', 11.5) ***** error ... crossval (ClassificationSVM (ones (40,2),randi ([1, 2], 40, 1)), 'Holdout', -1) ***** error ... crossval (ClassificationSVM (ones (40,2),randi ([1, 2], 40, 1)), 'Holdout', 0) ***** error ... crossval (ClassificationSVM (ones (40,2),randi ([1, 2], 40, 1)), 'Holdout', 1) ***** error ... crossval (ClassificationSVM (ones (40,2),randi ([1, 2], 40, 1)), 'Leaveout', 1) ***** error ... crossval (ClassificationSVM (ones (40,2),randi ([1, 2], 40, 1)), 'CVPartition', 1) ***** error ... crossval (ClassificationSVM (ones (40,2),randi ([1, 2], 40, 1)), 'CVPartition', 'a') ***** error ... crossval (ClassificationSVM (ones (40,2),randi ([1, 2], 40, 1)), 'some', 'some') ***** error ... savemodel (ClassificationSVM ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])) ***** error ... savemodel (ClassificationSVM ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), 1) ***** error ... savemodel (ClassificationSVM ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), ['ab'; 'cd']) ***** test load fisheriris X = meas(1:100,:); Y = grp2idx (species(1:100)); Mdl = fitcsvm (X, Y); assert_equal (Mdl.RowsUsed, []); assert_equal (class (Mdl.RowsUsed), 'double'); assert_equal (Mdl.NumObservations, 100); assert_equal (rows (Mdl.X), 100); assert_equal (rows (Mdl.W), 100); ***** test load fisheriris X = meas(1:100,:); Y = grp2idx (species(1:100)); Y(5) = NaN; Mdl = fitcsvm (X, Y); assert_equal (class (Mdl.RowsUsed), 'logical'); assert_equal (size (Mdl.RowsUsed), [100, 1]); assert_equal (sum (Mdl.RowsUsed), 99); assert_equal (Mdl.RowsUsed(5), false); assert_equal (Mdl.NumObservations, 99); assert_equal (rows (Mdl.X), 99); assert_equal (rows (Mdl.W), 99); ***** test load fisheriris X = meas(1:100,:); X(3,2) = NaN; Y = grp2idx (species(1:100)); Mdl = fitcsvm (X, Y); assert_equal (Mdl.RowsUsed, []); assert_equal (Mdl.NumObservations, 100); assert_equal (rows (Mdl.X), 100); assert_equal (sum (isnan (Mdl.X(:))), 1); ***** test load fisheriris Mdl = fitcsvm (meas(1:100,:), species(1:100)); assert_equal (Mdl.Mu, []); assert_equal (Mdl.Sigma, []); ***** test load fisheriris X = meas(1:100,:); X(3,2) = NaN; X(17,4) = NaN; Mdl = fitcsvm (X, species(1:100), 'Standardize', true); assert_equal (Mdl.Mu, [5.4700833333333314, 3.0964583333333331, ... 2.864374999999999, 0.78487499999999988], 1e-13); assert_equal (Mdl.Sigma, [0.64239212471819018, 0.47709034264660688, ... 1.4464268842305728, 0.56625850081877471], 1e-13); ***** test load fisheriris i2 = [1:50, 51:80]; Mdl = fitcsvm (meas(i2,:), species(i2)); assert_equal (Mdl.Prior, [0.625, 0.375], 1e-14); assert_equal (Mdl.W(1), 0.0125, 1e-14); Mdl = fitcsvm (meas(i2,:), species(i2), 'Prior', 'uniform'); assert_equal (Mdl.W(1), 0.01, 1e-14); assert_equal (Mdl.W(51), 1/60, 1e-14); ***** error ... load fisheriris; ... Mdl = fitcsvm (meas(1:80,:), species(1:80)); ... Mdl.Prior = [0.5, 0.5]; ***** error ... load fisheriris; ... Mdl = fitcsvm (meas(1:80,:), species(1:80)); ... Mdl.Cost = [0, 2; 1, 0]; ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcsvm (meas(inds,:), species(inds)); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2), 'ClassificationSVM'); assert_equal (M2.NumObservations, Mdl.NumObservations); assert_equal (M2.PredictorNames, Mdl.PredictorNames); assert_equal (class (M2.ScoreTransform), class (Mdl.ScoreTransform)); assert_equal (predict (M2, meas(1:5,:)), predict (Mdl, meas(1:5,:))); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); X = meas(inds,:); Y = species(inds); Mdl = fitcsvm (X, Y); assert_equal (edge (Mdl, X, Y), mean (margin (Mdl, X, Y)), 1e-12); assert_equal (resubEdge (Mdl), edge (Mdl, X, Y), 1e-12); assert_equal (resubMargin (Mdl), margin (Mdl, X, Y), 1e-12); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); X = meas(inds,:); Y = species(inds); Mdl = fitcsvm (X, Y); Ypm = ones (100, 1); Ypm(strcmp (Y, Mdl.ClassNames{2})) = -1; assert_equal (margin (Mdl, X, Y), margin (Mdl, X, Ypm), 1e-12); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); X = meas(inds,:); Y = species(inds); Mdl = fitcsvm (X, Y); assert_equal (edge (compact (Mdl), X, Y), edge (Mdl, X, Y), 1e-12); ***** error ... load fisheriris; ... inds = ! strcmp (species, 'virginica'); ... edge (fitcsvm (meas(inds,:), species(inds)), meas(inds,:)) ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcsvm (meas(inds,:), species(inds)); assert_equal (class (Mdl.BinEdges), 'cell'); assert_equal (Mdl.BinEdges, {}); ***** test load fisheriris b = ismember (species, {'setosa', 'versicolor'}); Mdl = fitcsvm (meas(b,:), species(b)); assert_equal (Mdl.KernelParameters, struct ('Function', 'linear', ... 'Scale', 1)); assert_equal (Mdl.BoxConstraints, ones (100, 1), 1e-14); assert_equal (Mdl.OutlierFraction, 0); assert_equal (Mdl.Nu, []); ***** test load fisheriris b = ismember (species, {'setosa', 'versicolor'}); Mdl = fitcsvm (meas(b,:), species(b), 'KernelFunction', 'rbf', ... 'KernelScale', 2.5, 'BoxConstraint', 3); assert_equal (Mdl.KernelParameters.Function, 'gaussian'); assert_equal (Mdl.KernelParameters.Scale, 2.5); n = rows (Mdl.BoxConstraints); assert_equal (Mdl.BoxConstraints, 3 * ones (n, 1), 1e-14); ***** test load fisheriris b = ismember (species, {'setosa', 'versicolor'}); Mdl = fitcsvm (meas(b,:), species(b), 'KernelFunction', 'polynomial', ... 'PolynomialOrder', 3); assert_equal (fieldnames (Mdl.KernelParameters), ... {'Function'; 'Scale'; 'Order'}); assert_equal (Mdl.KernelParameters.Order, 3); ***** test load fisheriris b = ismember (species, {'setosa', 'versicolor'}); Mdl = fitcsvm (meas(b,:), species(b), 'Cost', [0, 4; 1, 0]); assert_equal (Mdl.BoxConstraints(1), 1.6, 1e-12); assert_equal (Mdl.BoxConstraints(51), 0.4, 1e-12); assert_equal (mean (Mdl.BoxConstraints), 1, 1e-12); ***** error ... load fisheriris b = ismember (species, {'setosa', 'versicolor'}); fitcsvm (meas(b,:), species(b), 'OutlierFraction', 0.05); ***** test load fisheriris b = ismember (species, {'setosa', 'versicolor'}); Mdl = fitcsvm (meas(b,:), species(b)); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.KernelParameters, Mdl.KernelParameters); assert_equal (M2.BoxConstraints, Mdl.BoxConstraints); ***** test load fisheriris b = ! strcmp (species, 'virginica'); Mdl = fitcsvm (meas(b,:), species(b)); assert_equal (isempty (Mdl.HyperparameterOptimizationResults), true); ***** test load fisheriris Mdl = fitcsvm (meas, strcmp (species, 'setosa')); assert_equal (fieldnames (Mdl.ModelParameters)', {'SVMtype', ... 'BoxConstraint', 'CacheSize', 'KernelScale', 'KernelOffset', ... 'KernelFunction', 'KernelPolynomialOrder', 'Nu', 'Tolerance', ... 'Shrinking', 'OutlierFraction', 'StandardizeData', 'Version', ... 'Method', 'Type'}); ***** test load fisheriris MP = fitcsvm (meas, strcmp (species, 'setosa')).ModelParameters; assert_equal (MP.OutlierFraction, 0); assert_equal (MP.StandardizeData, false); assert_equal (MP.Version, 1); assert_equal (MP.Method, 'SVM'); assert_equal (MP.Type, 'classification'); ***** test load fisheriris b = strcmp (species, 'setosa'); assert_equal (isempty (fitcsvm (meas, b).ModelParameters. ... KernelPolynomialOrder), true); assert_equal (fitcsvm (meas, b, 'KernelFunction', ... 'polynomial').ModelParameters.KernelPolynomialOrder, 3); ***** test load fisheriris MP = fitcsvm (meas(1:50,:), ones (50, 1), 'Standardize', true, ... 'OutlierFraction', 0.05).ModelParameters; assert_equal (MP.StandardizeData, true); assert_equal (MP.OutlierFraction, 0.05); ***** test load fisheriris b = strcmp (species, 'setosa'); Mdl = fitcsvm (meas, b, 'Cost', [0, 2; 5, 0]); [label, ~, cost] = predict (Mdl, meas([1, 51],:)); assert_equal (label, [true; false]); assert_equal (cost, [5, 0; 0, 2]); ***** test load fisheriris b = strcmp (species, 'setosa'); Mdl = fitcsvm (meas, b); [~, ~, cost] = predict (Mdl, meas([1, 51],:)); assert_equal (cost, [1, 0; 0, 1]); ***** test load fisheriris b = strcmp (species, 'setosa'); Mdl = fitcsvm (meas, b, 'Cost', [0, 2; 5, 0]); [~, ~, cost] = resubPredict (Mdl); assert_equal (size (cost), [150, 2]); assert_equal (cost([1, 51],:), [5, 0; 0, 2]); ***** test load fisheriris Mdl = fitcsvm (meas, strcmp (species, 'setosa')); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); T = {'identity', @(x) x; 'doublelogit', @(x) 1 ./ (1 + exp (-2 * x)); ... 'invlogit', @(x) log (x ./ (1 - x)); ... 'logit', @(x) 1 ./ (1 + exp (-x)); ... 'sign', @(x) sign (x); 'symmetric', @(x) 2 * x - 1; ... 'symmetriclogit', @(x) 2 ./ (1 + exp (-x)) - 1}; for i = 1:rows (T) Mdl.ScoreTransform = T{i,1}; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, T{i,2}(raw), 1e-12); assert_equal (l, label); endfor ## ismax marks the largest score of each observation, ties to the first. [~, k] = max (raw, [], 2); e = zeros (size (raw)); e(sub2ind (size (raw), (1:rows (raw))', k)) = 1; Mdl.ScoreTransform = 'ismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, e); Mdl.ScoreTransform = 'symmetricismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, 2 * e - 1); ***** test load fisheriris Mdl = fitcsvm (meas, strcmp (species, 'setosa')); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); Mdl.ScoreTransform = @(x) x .^ 2; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, raw .^ 2, 1e-12); assert_equal (l, label); ***** shared Xc, Dc, yc, Xq, Dq k = (0:119)'; c1 = mod (k, 3) + 1; x2 = sin (k); c3 = 10 * (mod (floor (k / 2), 2) + 1); Xc = [c1, x2, c3]; Dc = [c1 == 1, c1 == 2, c1 == 3, x2, c3 == 10, c3 == 20]; yr = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 20) + 0.1 * cos (k); yc = yr > 1; Xq = [1, 0, 10; 2, 0.5, 20]; Dq = [1, 0, 0, 0, 1, 0; 0, 1, 0, 0.5, 0, 1]; ***** test # MATLAB parity: a categorical predictor is dummy coded in its place Mdl = ClassificationSVM (Xc, yc, 'CategoricalPredictors', [1, 3]); H = ClassificationSVM (Dc, yc); assert_equal (Mdl.CategoricalPredictors, [1, 3]); assert_equal (Mdl.ExpandedPredictorNames, {'x1 == 1', 'x1 == 2', ... 'x1 == 3', 'x2', 'x3 == 10', 'x3 == 20'}); assert_equal (size (Mdl.X), [120, 3]); assert_equal (columns (Mdl.SupportVectors), 6); assert_equal (Mdl.Beta, H.Beta, 1e-12); [~, s] = predict (Mdl, Xq); [~, sh] = predict (H, Dq); assert_equal (s, sh, 1e-12); ***** test # MATLAB parity: a level the fit did not see has no score Mdl = ClassificationSVM (Xc, yc, 'CategoricalPredictors', [1, 3]); [~, s] = predict (Mdl, [4, 0, 10; 2.5, 0, 20]); assert_equal (all (isnan (s(:))), true); ***** test # MATLAB parity: the coded columns are not standardized Mdl = ClassificationSVM (Xc, yc, 'CategoricalPredictors', [1, 3], ... 'Standardize', true); assert_equal (Mdl.Mu([1:3, 5:6]), zeros (1, 5)); assert_equal (Mdl.Sigma([1:3, 5:6]), ones (1, 5)); ***** test # the coding travels with saved models and cross-validation folds Mdl = ClassificationSVM (Xc, yc, 'CategoricalPredictors', [1, 3]); fname = [tempname(), '.mdl']; savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (predict (M2, Xq), predict (Mdl, Xq)); CV = crossval (Mdl, 'KFold', 3); assert_equal (CV.Trained{1}.CategoricalPredictors, [1, 3]); ***** test # margin and loss score the data on the scale the model was fitted on load fisheriris X = meas(51:150,:) * 10; Y = species(51:150); Mdl = ClassificationSVM (X, Y, 'Standardize', true); [~, s] = predict (Mdl, X); g = 1 + strcmp (Y, 'virginica'); want = s(sub2ind (size (s), (1:100)', g)) ... - s(sub2ind (size (s), (1:100)', 3 - g)); assert_equal (margin (Mdl, X, Y), want, 1e-10); assert_equal (loss (Mdl, X, Y), resubLoss (Mdl)); assert_equal (loss (Mdl, X, Y) < 0.1, true); ***** error ... ClassificationSVM (Xc, yc, 'CategoricalPredictors', 4) ***** test # the class may be built from a table as the fitter builds it load fisheriris inds = ! strcmp (species, 'setosa'); T = table (meas(inds,1), meas(inds,2), 'VariableNames', {'SL', 'SW'}); T.Species = categorical (species(inds)); Mdl = ClassificationSVM (T, 'Species'); assert_equal (Mdl.PredictorNames, {'SL', 'SW'}); assert_equal (Mdl.ResponseName, 'Species'); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(51:150,1:2); y = species(51:150); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcsvm (T, 'Species'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # loss reads one as it reads a cellstr response load fisheriris X = meas(51:150,1:2); y = species(51:150); a = loss (fitcsvm (X, y), X, y); yc = categorical (y); assert_equal (loss (fitcsvm (X, yc), X, yc), a); ys = string (y); assert_equal (loss (fitcsvm (X, ys), X, ys), a); ***** test # margin reads one as it reads a cellstr response load fisheriris X = meas(51:150,1:2); y = species(51:150); a = margin (fitcsvm (X, y), X, y); yc = categorical (y); assert_equal (margin (fitcsvm (X, yc), X, yc), a); ys = string (y); assert_equal (margin (fitcsvm (X, ys), X, ys), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(51:150,1:2); y = categorical (species(51:150)); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcsvm (T, 'Species'); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(51:150,1:2); y = categorical (species(51:150)); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcsvm (T, 'Species'); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** test load fisheriris X = meas(51:150,1:2); Y = species(51:150); A = fitcsvm (X, Y); B = fitcsvm (X, Y, 'Nu', 0.3); assert_equal (B.ModelParameters.SVMtype, 'c_svc'); assert_equal (B.ModelParameters.Nu, 0.3); assert_equal ([B.Bias; B.Alpha], [A.Bias; A.Alpha]); ***** test load fisheriris X = meas(1:50,1:2); Y = ones (50, 1); A = fitcsvm (X, Y, 'Nu', 0.3, 'OutlierFraction', 0.1); B = fitcsvm (X, Y, 'OutlierFraction', 0.1, 'Nu', 0.3); assert_equal (A.ModelParameters.Nu, 0.3); assert_equal (sum (A.Alpha), 15, 1e-10); assert_equal ([A.Bias; A.Alpha], [B.Bias; B.Alpha]); ***** error ... fitcsvm ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', ... int8 ([1; 1; 1; 1])) ***** error ... fitcsvm ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', true (4, 1)) ***** test ## Single weights are stored single, summing to one load fisheriris X = meas(51:end,:); Y = species(51:end); w = 1 + (1:100)' / 7; Mdl = fitcsvm (X, Y, 'Weights', single (w)); assert_equal (class (Mdl.W), 'single'); assert_equal (sum (double (Mdl.W)), 1, 1e-6); ***** test ## Single weights compute as double load fisheriris X = meas(51:end,:); Y = species(51:end); w = 1 + (1:100)' / 7; A = fitcsvm (X, Y, 'Weights', single (w)); B = fitcsvm (X, Y, 'Weights', double (single (w))); assert_equal (nthargout (2, @predict, A, X), nthargout (2, @predict, B, X)); ***** test ## A constant predictor is left unscaled by standardization X = [linspace(0, 1, 20)', ones(20, 1)]; Mdl = ClassificationSVM (X, [ones(10, 1); 2 * ones(10, 1)], 'Standardize', true); assert_equal (Mdl.Sigma(2), 1); 227 tests, 227 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitrsvm.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitrsvm.m ***** demo ## 1. Predict fuel economy from engine power and weight load carsmall X = [Horsepower, Weight]; Mdl = fitrsvm (X, MPG, 'Standardize', true); ## Rows carrying a missing value were dropped, so ask about the ones used used = Mdl.RowsUsed; yFit = predict (Mdl, X(used,:)); plot (MPG(used), yFit, 'o', [5, 45], [5, 45], 'k-'); axis equal; xlabel ('Observed MPG'); ylabel ('Predicted MPG'); title (sprintf ('Linear SVR, RMSE %.2f', sqrt (resubLoss (Mdl)))); ***** demo ## 2. The insensitive tube decides who becomes a support vector ## Errors smaller than Epsilon cost nothing, so a wider tube is fitted by ## fewer observations and a narrower one by almost all of them. load carsmall X = [Horsepower, Weight]; eps_ = [0.1, 0.5, 1, 2, 4, 8]; nsv = zeros (size (eps_)); for k = 1:numel (eps_) m = fitrsvm (X, MPG, 'Standardize', true, 'Epsilon', eps_(k)); nsv(k) = sum (m.IsSupportVector); endfor plot (eps_, nsv, 'o-', 'linewidth', 1.5); xlabel ('Epsilon'); ylabel ('Number of support vectors'); title ('A wider tube needs fewer support vectors'); ***** demo ## 3. A radial kernel fits a curve a linear one cannot rng (42); x = linspace (-3, 3, 120)'; y = sin (x) + randn (120, 1) * 0.1; lin = fitrsvm (x, y); rbf = fitrsvm (x, y, 'KernelFunction', 'rbf', 'BoxConstraint', 10); plot (x, y, 'o', 'markersize', 4); hold on; plot (x, predict (lin, x), 'k--', 'linewidth', 1.5); plot (x, predict (rbf, x), 'r-', 'linewidth', 2); hold off; legend ({'data', 'linear kernel', 'rbf kernel'}); title ('Support vector regression'); ***** demo ## 4. With a linear kernel the model is a plain linear function load carsmall X = [Horsepower, Weight]; Mdl = fitrsvm (X, MPG, 'Standardize', true); used = Mdl.RowsUsed; Xs = (X(used,:) - Mdl.Mu) ./ Mdl.Sigma; printf ('max |X*Beta + Bias - predict| = %g\n', ... max (abs (Xs * Mdl.Beta + Mdl.Bias - resubPredict (Mdl)))); ***** demo ## Fit from a table, and predict on one load fisheriris T = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ## A model formula names the response and the predictors together, and ## holds main effects only Mdl = fitrsvm (T, 'SL ~ PL + Wide'); Mdl.PredictorNames Mdl.ResponseName Mdl.CategoricalPredictors ## predict matches the table's variables by name, so a column the model ## was not fitted on is passed over yFit = predict (Mdl, T(1:5,:)); yFit' ***** test load carsmall X = [Horsepower, Weight]; Mdl = fitrsvm (X, MPG, 'Standardize', true); assert_equal (class (Mdl), 'RegressionSVM'); assert_equal (Mdl.NumPredictors, 2); assert_equal (Mdl.ModelParameters.KernelFunction, 'linear'); assert_equal (Mdl.ModelParameters.SVMtype, 'eps_svr'); assert_equal (Mdl.Epsilon, iqr (MPG(Mdl.RowsUsed)) / 13.49, 1e-12); ***** test X = [linspace(0, 1, 30)', linspace(1, 2, 30)']; Y = 3 * X(:,1) + 1; Mdl = fitrsvm (X, Y, 'KernelFunction', 'rbf', 'BoxConstraint', 5, ... 'Epsilon', 0.05, 'ResponseName', 'speed'); assert_equal (Mdl.ModelParameters.KernelFunction, 'rbf'); assert_equal (Mdl.ModelParameters.BoxConstraint, 5); assert_equal (Mdl.Epsilon, 0.05); assert_equal (Mdl.ResponseName, 'speed'); assert_equal (isempty (Mdl.Beta), true); ***** error fitrsvm () ***** error fitrsvm (ones (4, 1)) ***** error ... fitrsvm (ones (4, 2), ones (4, 1), 'KernelFunction') ***** error ... fitrsvm (ones (4, 2), ones (3, 1)) ***** error ... fitrsvm (ones (4, 2), ones (3, 1), 'Epsilon', 1) ***** shared frsT load fisheriris frsT = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); frsT.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ***** test # the response is named by a column and the rest are predictors Mdl = fitrsvm (frsT, 'SL'); assert_equal (Mdl.PredictorNames, {'SW', 'PL', 'PW', 'Wide'}); assert_equal (Mdl.ResponseName, 'SL'); assert_equal (Mdl.CategoricalPredictors, 4); ***** test # a model formula names the response and the predictors together Mdl = fitrsvm (frsT, 'SL ~ PL + Wide'); assert_equal (Mdl.PredictorNames, {'PL', 'Wide'}); assert_equal (Mdl.CategoricalPredictors, 2); ***** test # the response may be given beside a table of predictors Mdl = fitrsvm (frsT(:,1:3), frsT.SL); assert_equal (Mdl.PredictorNames, {'SW', 'PL', 'PW'}); assert_equal (Mdl.ResponseName, 'Y'); ***** test # predict takes a table, matched by name and not by position Mdl = fitrsvm (frsT, 'SL'); a = predict (Mdl, frsT); assert_equal (numel (a), 150); assert_equal (predict (Mdl, frsT(:, [5, 4, 3, 2, 1])), a); ***** test # the levels travel with the model when it is made compact Mdl = fitrsvm (frsT, 'SL'); CMdl = compact (Mdl); assert_equal (CMdl.PredictorLevels, Mdl.PredictorLevels); assert_equal (predict (CMdl, frsT), predict (Mdl, frsT)); ***** error ... fitrsvm (frsT, 'NoSuch') ***** error ... fitrsvm (frsT, 'SL ~ PL*PW') ***** error ... predict (fitrsvm (frsT, 'SL'), frsT(:, [1, 3, 4, 5])) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Machine_Learning/templateEnsemble.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/templateEnsemble.m ***** test # a template names its method, type, learners and cycles T = templateEnsemble ('AdaBoostM1', 20, 'tree'); assert_equal (class (T), 'struct'); assert_equal (fieldnames (T), ... {'Method'; 'Type'; 'LearnerTemplates'; 'NLearn'}); assert_equal (T.Method, 'AdaBoostM1'); assert_equal (T.Type, 'classification'); assert_equal (T.LearnerTemplates, 'tree'); assert_equal (T.NLearn, 20); ***** test # the method is matched in any letter case T = templateEnsemble ('gentleboost', 10, 'tree'); assert_equal (T.Method, 'GentleBoost'); ***** test # LSBoost grows a regression ensemble T = templateEnsemble ('LSBoost', 10, 'tree'); assert_equal (T.Type, 'regression'); ***** test # Bag takes its type from the 'Type' option T = templateEnsemble ('Bag', 10, 'tree', 'Type', 'regression'); assert_equal (T.Type, 'regression'); assert_equal (isfield (T, 'Type'), true); assert_equal (numfields (T), 4); ***** test # a learner template and the options are stored as they stand S = templateTree ('MaxNumSplits', 1); T = templateEnsemble ('GentleBoost', 5, S, 'LearnRate', 0.5); assert_equal (T.LearnerTemplates, S); assert_equal (T.LearnRate, 0.5); ***** test # a value the ensemble would refuse is not refused here T = templateEnsemble ('AdaBoostM1', 0, 'svm'); assert_equal (T.NLearn, 0); ***** error templateEnsemble ('AdaBoostM1', 10) ***** error ... templateEnsemble (1, 10, 'tree') ***** error ... templateEnsemble ('Foo', 10, 'tree') ***** error ... templateEnsemble ('AdaBoostM1', 10, 'tree', 'LearnRate') ***** error ... templateEnsemble ('Bag', 10, 'tree', 'Type', 'both') ***** error ... templateEnsemble ('LSBoost', 10, 'tree', 'Type', 'classification') 12 tests, 12 passed, 0 known failure, 0 skipped [inst/Machine_Learning/ClassificationDiscriminant.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/ClassificationDiscriminant.m ***** demo ## Create discriminant classifier ## Evaluate some model predictions on new data. load fisheriris x = meas; y = species; xc = [min(x); mean(x); max(x)]; obj = fitcdiscr (x, y); [label, score, cost] = predict (obj, xc); ***** demo load fisheriris model = fitcdiscr (meas, species); X = mean (meas); Y = {'versicolor'}; ## Compute loss for discriminant model L = loss (model, X, Y) ***** demo load fisheriris mdl = fitcdiscr (meas, species); X = mean (meas); Y = {'versicolor'}; ## Margin for discriminant model m = margin (mdl, X, Y) ***** demo load fisheriris x = meas; y = species; obj = fitcdiscr (x, y, 'gamma', 0.4); ## Cross-validation for discriminant model CVMdl = crossval (obj) ***** test load fisheriris x = meas; y = species; PredictorNames = {'Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width'}; Mdl = ClassificationDiscriminant (x, y, 'PredictorNames', PredictorNames); sigma = [0.265008, 0.092721, 0.167514, 0.038401; ... 0.092721, 0.115388, 0.055244, 0.032710; ... 0.167514, 0.055244, 0.185188, 0.042665; ... 0.038401, 0.032710, 0.042665, 0.041882]; mu = [5.0060, 3.4280, 1.4620, 0.2460; ... 5.9360, 2.7700, 4.2600, 1.3260; ... 6.5880, 2.9740, 5.5520, 2.0260]; xCentered = [ 9.4000e-02, 7.2000e-02, -6.2000e-02, -4.6000e-02; ... -1.0600e-01, -4.2800e-01, -6.2000e-02, -4.6000e-02; ... -3.0600e-01, -2.2800e-01, -1.6200e-01, -4.6000e-02]; assert_equal (class (Mdl), "ClassificationDiscriminant"); assert_equal ({Mdl.X, Mdl.Y, Mdl.NumObservations}, {x, y, 150}) assert_equal ({Mdl.DiscrimType, Mdl.ResponseName}, {'linear', 'Y'}) assert_equal ({Mdl.Gamma, Mdl.MinGamma}, {0, 0}, 1e-15) assert_equal (Mdl.ClassNames, unique (species)) assert_equal (Mdl.Sigma, sigma, 1e-6) assert_equal (Mdl.Mu, mu, 1e-14) assert_equal (Mdl.XCentered([1:3],:), xCentered, 1e-14) assert_equal (Mdl.LogDetSigma, -9.9585, 1e-4) assert_equal (Mdl.PredictorNames, PredictorNames) ***** test load fisheriris x = meas; y = species; Mdl = ClassificationDiscriminant (x, y, 'Gamma', 0.5); sigma = [0.265008, 0.046361, 0.083757, 0.019201; ... 0.046361, 0.115388, 0.027622, 0.016355; ... 0.083757, 0.027622, 0.185188, 0.021333; ... 0.019201, 0.016355, 0.021333, 0.041882]; mu = [5.0060, 3.4280, 1.4620, 0.2460; ... 5.9360, 2.7700, 4.2600, 1.3260; ... 6.5880, 2.9740, 5.5520, 2.0260]; xCentered = [ 9.4000e-02, 7.2000e-02, -6.2000e-02, -4.6000e-02; ... -1.0600e-01, -4.2800e-01, -6.2000e-02, -4.6000e-02; ... -3.0600e-01, -2.2800e-01, -1.6200e-01, -4.6000e-02]; assert_equal (class (Mdl), "ClassificationDiscriminant"); assert_equal ({Mdl.X, Mdl.Y, Mdl.NumObservations}, {x, y, 150}) assert_equal ({Mdl.DiscrimType, Mdl.ResponseName}, {'linear', 'Y'}) assert_equal ({Mdl.Gamma, Mdl.MinGamma}, {0.5, 0}) assert_equal (Mdl.ClassNames, unique (species)) assert_equal (Mdl.Sigma, sigma, 1e-6) assert_equal (Mdl.Mu, mu, 1e-14) assert_equal (Mdl.XCentered([1:3],:), xCentered, 1e-14) assert_equal (Mdl.LogDetSigma, -8.6884, 1e-4) ***** test # A categorical 'ClassNames' keeps only the classes it names load fisheriris Mdl = ClassificationDiscriminant (meas, categorical (species), ... 'ClassNames', categorical ({'versicolor'; 'virginica'})); assert_equal (Mdl.NumObservations, 100); assert_equal (class (Mdl.ClassNames), 'categorical'); ***** shared X, Y, MODEL X = rand (10,2); Y = [ones(5,1);2*ones(5,1)]; MODEL = ClassificationDiscriminant (X, Y); ***** test load fisheriris Mdl = fitcdiscr (meas, species); assert_equal (nLinearCoeffs (Mdl), 4); ***** test load fisheriris Mdl = fitcdiscr (meas, species); dps = sort (Mdl.DeltaPredictor); assert_equal (nLinearCoeffs (Mdl, dps), [4; 3; 2; 1]); ***** test load fisheriris Mdl = fitcdiscr (meas, species); assert_equal (nLinearCoeffs (Mdl, [0, 1e6]), [4; 0]); assert_equal (size (nLinearCoeffs (Mdl, [0, 1, 2])), [3, 1]); ***** test load fisheriris Mdl = fitcdiscr (meas, species, "DiscrimType", "quadratic"); assert_equal (nLinearCoeffs (Mdl), 4); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcdiscr (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcdiscr (Xch, Ycell); assert_equal (size (Mc.ClassNames), [2, 10]); assert_equal (cellstr (Mc.ClassNames), Ms.ClassNames); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcdiscr (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcdiscr (Xch, Ycell); pch = predict (Mc, Xch); assert_equal (columns (pch), 10); assert_equal (cellstr (pch), predict (Ms, Xch)); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcdiscr (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcdiscr (Xch, Ycell); assert_equal (loss (Mc, Xch, Ych), loss (Ms, Xch, Ycell), 1e-12); assert_equal (margin (Mc, Xch, Ych), margin (Ms, Xch, Ycell), 1e-12); assert_equal (edge (Mc, Xch, Ych), edge (Ms, Xch, Ycell), 1e-12); ***** test Xpad = [1 2; 3 4; 1.1 2.1; 3.1 4.1; 1.2 2.2; 3.2 4.2]; Ypad = char ({"ab", "abcd", "ab", "abcd", "ab", "abcd"}); rand ("state", 1); randn ("state", 1); Mp = fitcdiscr (Xpad, Ypad); assert_equal (size (Mp.ClassNames), [2, 4]); assert_equal (Mp.ClassNames(1,:), "ab "); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); Xmiss = Xch; Xmiss(3,2) = NaN; rand ("state", 1); randn ("state", 1); Md = fitcdiscr (Xmiss, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcdiscr (Xmiss, Ycell); assert_equal (size (Md.ClassNames), [2, 10]); assert_equal (cellstr (Md.ClassNames), Ms.ClassNames); ***** test load fisheriris rand ("state", 1); randn ("state", 1); Mf = fitcdiscr (meas, char (species), ... "ClassNames", char ({"versicolor", "virginica"})); assert_equal (rows (Mf.ClassNames), 2); assert_equal (cellstr (Mf.ClassNames), {"versicolor"; "virginica"}); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcdiscr (Xch, Ych); fname = tempname (); savemodel (Mc, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.ClassNames, Mc.ClassNames); assert_equal (predict (M2, Xch), predict (Mc, Xch)); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Mc = fitcdiscr (Xch, Ych); rand ("state", 1); randn ("state", 1); Ms = fitcdiscr (Xch, Ycell); rand ("state", 2); cvc = crossval (Mc, "KFold", 3); rand ("state", 2); cvs = crossval (Ms, "KFold", 3); assert_equal (cellstr (kfoldPredict (cvc)), kfoldPredict (cvs)); ***** test load fisheriris Xd = meas(51:150, 1:2); ys = species(51:150); yc = categorical (ys); Mdl = fitcdiscr (Xd, yc); assert_equal (loss (Mdl, Xd, ys), 0.25, 1e-15); assert_equal (loss (Mdl, Xd, yc), 0.25, 1e-15); assert_equal (numel (margin (Mdl, Xd, ys)), 100); ***** error ... load fisheriris nLinearCoeffs (fitcdiscr (meas, species), "a") ***** error ... fitcdiscr ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', 'a') ***** error ... fitcdiscr ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', ones (2, 2)) ***** error ... fitcdiscr ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', [1, 2]) ***** error ... fitcdiscr ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', -ones (4, 1)) ***** error ClassificationDiscriminant () ***** error ... ClassificationDiscriminant (ones (4, 1)) ***** error ... ClassificationDiscriminant (X, Y, 'prior') ***** error ... ClassificationDiscriminant (ones (4,2), ones (1,4)) ***** error ... ClassificationDiscriminant (X, Y, 'PredictorNames', ['A']) ***** error ... ClassificationDiscriminant (X, Y, 'PredictorNames', 'A') ***** error ... ClassificationDiscriminant (X, Y, 'Bogus', 1) ***** error ... ClassificationDiscriminant (X, Y, 'PredictorNames', {'A', 'B', 'C'}) ***** error ... ClassificationDiscriminant (X, Y, 'ResponseName', {'Y'}) ***** error ... ClassificationDiscriminant (X, Y, 'ResponseName', 1) ***** error ... ClassificationDiscriminant (X, Y, 'ClassNames', @(x)x) ***** error ... ClassificationDiscriminant (X, Y, 'ClassNames', {1}) ***** error ... ClassificationDiscriminant (X, ones (10,1), 'ClassNames', [1, 2]) ***** error ... ClassificationDiscriminant ([1;2;3;4;5], ['a';'b';'a';'a';'b'], 'ClassNames', ['a';'c']) ***** error ... ClassificationDiscriminant ([1;2;3;4;5], {'a';'b';'a';'a';'b'}, 'ClassNames', {'a','c'}) ***** error ... ClassificationDiscriminant (X, logical (ones (10,1)), 'ClassNames', [true, false]) ***** error ... ClassificationDiscriminant (X, Y, 'Prior', {'1', '2'}) ***** error ... ClassificationDiscriminant (X, ones (10,1), 'Prior', [1 2]) ***** test ## A single cost is widened to double rather than refused load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Cost = single ([0, 1, 2; 3, 0, 4; 5, 6, 0]); assert_equal (class (Mdl.Cost), 'double'); assert_equal (Mdl.Cost, [0, 1, 2; 3, 0, 4; 5, 6, 0]); ***** test ## A cost need not be symmetric, and is stored as it was given load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Cost = [0, 1, 2; 3, 0, 4; 5, 6, 0]; assert_equal (Mdl.Cost, [0, 1, 2; 3, 0, 4; 5, 6, 0]); ***** test ## Complex means a nonzero imaginary part: a zero one is accepted and ## stored as a double, so the guard is not ! isreal load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Cost = complex ([0, 1, 2; 3, 0, 4; 5, 6, 0], 0); assert_equal (class (Mdl.Cost), 'double'); assert_equal (Mdl.Cost, [0, 1, 2; 3, 0, 4; 5, 6, 0]); ***** test ## A struct names the order its matrix is written in, and the matrix is ## permuted into the model's order entry by entry load fisheriris Mdl = fitcdiscr (meas, species); S = struct ('ClassNames', {{'virginica'; 'setosa'; 'versicolor'}}, ... 'ClassificationCosts', [0, 1, 2; 3, 0, 4; 5, 6, 0]); Mdl.Cost = S; assert_equal (Mdl.Cost, [0, 4, 3; 6, 0, 5; 1, 2, 0]); ***** test ## A struct already in the model's order permutes to itself load fisheriris Mdl = fitcdiscr (meas, species); S = struct ('ClassNames', {{'setosa'; 'versicolor'; 'virginica'}}, ... 'ClassificationCosts', [0, 1, 2; 3, 0, 4; 5, 6, 0]); Mdl.Cost = S; assert_equal (Mdl.Cost, [0, 1, 2; 3, 0, 4; 5, 6, 0]); ***** test ## The constructor takes the struct form too load fisheriris S = struct ('ClassNames', {{'virginica'; 'setosa'; 'versicolor'}}, ... 'ClassificationCosts', [0, 1, 2; 3, 0, 4; 5, 6, 0]); Mdl = fitcdiscr (meas, species, 'Cost', S); assert_equal (Mdl.Cost, [0, 4, 3; 6, 0, 5; 1, 2, 0]); ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Cost = int32 ([0, 1, 2; 3, 0, 4; 5, 6, 0]); ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Cost = ! logical (eye (3)); ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Cost = sparse ([0, 1, 2; 3, 0, 4; 5, 6, 0]); ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Cost = [0, 1, 2; 3, 0, 4i; 5, 6, 0]; ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Cost = [0, -1, 2; 3, 0, 4; 5, 6, 0]; ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Cost = ones (3); ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Cost = [0, 1, 2; 3, 0, NaN; 5, 6, 0]; ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Cost = [0, 1, 2; 3, 0, Inf; 5, 6, 0]; ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Cost = struct ('ClassificationCosts', [0, 1, 2; 3, 0, 4; 5, 6, 0]); ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Cost = struct ('ClassNames', {{'setosa'; 'versicolor'}}, ... 'ClassificationCosts', [0, 1; 2, 0]); ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Cost = struct ('ClassNames', {{'setosa'; 'versicolor'; 'virginica'}}, ... 'ClassificationCosts', [0, 1; 2, 0]); ***** error ... ClassificationDiscriminant (X, Y, 'Cost', [1, 2]) ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Cost = 1:9; ***** error ... ClassificationDiscriminant (X, Y, 'Cost', 'string') ***** error ... ClassificationDiscriminant (X, Y, 'Cost', {eye(2)}) ***** error ... ClassificationDiscriminant (X, Y, 'Cost', ones (3)) ***** error ... ClassificationDiscriminant (ones (5,2), [1; 1; 2; 2; 2]) ***** error ... ClassificationDiscriminant (ones (5,2), [1; 1; 2; 2; 2], 'PredictorNames', {'A', 'B'}) ***** error ... ClassificationDiscriminant ([1,2;2,2;3,2;4,2;5,2], ones (5, 1)) ***** error ... ClassificationDiscriminant ([1,2;2,2;3,2;4,2;5,2], ones (5, 1), 'PredictorNames', {'A', 'B'}) ***** test load fisheriris x = meas; y = species; Mdl = fitcdiscr (meas, species, 'Gamma', 0.5); [label, score, cost] = predict (Mdl, [2, 2, 2, 2]); assert_equal (label, {'versicolor'}) assert_equal (score, [0, 0.9999, 0.0001], 1e-4) assert_equal (cost, [1, 0.0001, 0.9999], 1e-4) [label, score, cost] = predict (Mdl, [2.5, 2.5, 2.5, 2.5]); assert_equal (label, {'versicolor'}) assert_equal (score, [0, 0.6368, 0.3632], 1e-4) assert_equal (cost, [1, 0.3632, 0.6368], 1e-4) ***** test load fisheriris x = meas; y = species; xc = [min(x); mean(x); max(x)]; Mdl = fitcdiscr (x, y); [label, score, cost] = predict (Mdl, xc); l = {'setosa'; 'versicolor'; 'virginica'}; s = [1, 0, 0; 0, 1, 0; 0, 0, 1]; c = [0, 1, 1; 1, 0, 1; 1, 1, 0]; assert_equal (label, l) assert_equal (score, s, 1e-4) assert_equal (cost, c, 1e-4) ***** error ... predict (MODEL) ***** error ... predict (MODEL, []) ***** error ... predict (MODEL, 1) ***** test load fisheriris model = fitcdiscr (meas, species); x = mean (meas); y = {'versicolor'}; L = loss (model, x, y); assert_equal (L, 0) ***** test x = [1, 2; 3, 4; 5, 6]; y = {'A'; 'B'; 'A'}; model = fitcdiscr (x, y, 'Gamma', 0.4); x_test = [1, 6; 3, 3]; y_test = {'A'; 'B'}; L = loss (model, x_test, y_test); assert_equal (L, 0.3333, 1e-4) ***** test x = [1, 2; 3, 4; 5, 6; 7, 8]; y = ['1'; '2'; '3'; '1']; model = fitcdiscr (x, y, 'gamma' , 0.5); x_test = [3, 3]; y_test = ['1']; L = loss (model, x_test, y_test, 'LossFun', 'quadratic'); assert_equal (L, 0.2423, 1e-4) ***** test x = [1, 2; 3, 4; 5, 6; 7, 8]; y = ['1'; '2'; '3'; '1']; model = fitcdiscr (x, y, 'gamma' , 0.5); x_test = [3, 3; 5, 7]; y_test = ['1'; '2']; L = loss (model, x_test, y_test, 'LossFun', 'classifcost'); assert_equal (L, 0.3333, 1e-4) ***** test x = [1, 2; 3, 4; 5, 6; 7, 8]; y = ['1'; '2'; '3'; '1']; model = fitcdiscr (x, y, 'gamma' , 0.5); x_test = [3, 3; 5, 7]; y_test = ['1'; '2']; L = loss (model, x_test, y_test, 'LossFun', 'hinge'); assert_equal (L, 0.5886, 1e-4) ***** test x = [1, 2; 3, 4; 5, 6; 7, 8]; y = ['1'; '2'; '3'; '1']; model = fitcdiscr (x, y, 'gamma' , 0.5); x_test = [3, 3; 5, 7]; y_test = ['1'; '2']; W = [1; 2]; L = loss (model, x_test, y_test, 'LossFun', 'logit', 'Weights', W); assert_equal (L, 0.5107, 1e-4) ***** test x = [1, 2; 3, 4; 5, 6]; y = {'A'; 'B'; 'A'}; model = fitcdiscr (x, y, 'gamma' , 0.5); x_with_nan = [1, 2; NaN, 4]; y_test = {'A'; 'B'}; L = loss (model, x_with_nan, y_test); assert_equal (L, 0.3333, 1e-4) ***** test x = [1, 2; 3, 4; 5, 6]; y = {'A'; 'B'; 'A'}; model = fitcdiscr (x, y); x_with_nan = [1, 2; NaN, 4]; y_test = {'A'; 'B'}; L = loss (model, x_with_nan, y_test, 'LossFun', 'logit'); assert_equal (isnan (L), true) ***** test x = [1, 2; 3, 4; 5, 6]; y = {'A'; 'B'; 'A'}; model = fitcdiscr (x, y); customLossFun = @(C, S, W, Cost) sum (W .* sum (abs (C - S), 2)); L = loss (model, x, y, 'LossFun', customLossFun); assert_equal (L, 0.8889, 1e-4) ***** test x = [1, 2; 3, 4; 5, 6]; y = [1; 2; 1]; model = fitcdiscr (x, y); L = loss (model, x, y, 'LossFun', 'classiferror'); assert_equal (L, 0.3333, 1e-4) ***** error ... loss (MODEL) ***** error ... loss (MODEL, ones (4,2)) ***** error ... loss (MODEL, [], zeros (2)) ***** error ... loss (MODEL, 1, zeros (2)) ***** error ... loss (MODEL, ones (4,2), ones (4,1), 'LossFun') ***** error ... loss (MODEL, ones (4,2), ones (3,1)) ***** error ... loss (MODEL, ones (4,2), ones (4,1), 'LossFun', 'a') ***** error ... loss (MODEL, ones (4,2), ones (4,1), 'Bogus', 1) ***** error ... loss (MODEL, ones (4,2), ones (4,1), 'Weights', 'w') ***** error ... loss (MODEL, ones (4,2), ones (4,1), 'Weights', ones (2, 2)) load fisheriris mdl = fitcdiscr (meas, species); X = mean (meas); Y = {'versicolor'}; m = margin (mdl, X, Y); assert_equal (m, 1, 1e-6) ***** test X = [1, 2; 3, 4; 5, 6]; Y = [1; 2; 1]; mdl = fitcdiscr (X, Y, 'gamma', 0.5); m = margin (mdl, X, Y); assert_equal (m, [0.3333; -0.3333; 0.3333], 1e-4) ***** error ... margin (MODEL) ***** error ... margin (MODEL, ones (4,2)) ***** error ... margin (MODEL, [], zeros (2)) ***** error ... margin (MODEL, 1, zeros (2)) ***** error ... margin (MODEL, ones (4,2), ones (3,1)) ***** shared x, y, obj load fisheriris x = meas; y = species; obj = fitcdiscr (x, y, 'gamma', 0.4); ***** test status = warning; warning ('off'); rand ('seed', 23); CVMdl = crossval (obj); warning (status); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (CVMdl.KFold == 10, true) assert_equal (class (CVMdl.Trained{1}), "CompactClassificationDiscriminant") assert_equal (CVMdl.CrossValidatedModel, "Discriminant") ***** test status = warning; warning ('off'); rand ('seed', 23); CVMdl = crossval (obj, 'KFold', 3); warning (status); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (CVMdl.KFold == 3, true) assert_equal (class (CVMdl.Trained{1}), "CompactClassificationDiscriminant") assert_equal (CVMdl.CrossValidatedModel, "Discriminant") ***** test status = warning; warning ('off'); rand ('seed', 23); CVMdl = crossval (obj, 'HoldOut', 0.2); warning (status); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (class (CVMdl.Trained{1}), "CompactClassificationDiscriminant") assert_equal (CVMdl.CrossValidatedModel, "Discriminant") ***** test status = warning; warning ('off'); rand ('seed', 23); CVMdl = crossval (obj, 'LeaveOut', 'on'); warning (status); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (class (CVMdl.Trained{1}), "CompactClassificationDiscriminant") assert_equal (CVMdl.CrossValidatedModel, "Discriminant") ***** test status = warning; warning ('off'); rand ('seed', 23); partition = cvpartition (y, 'KFold', 3); warning (status); CVMdl = crossval (obj, 'cvPartition', partition); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal (CVMdl.KFold == 3, true) assert_equal (class (CVMdl.Trained{1}), "CompactClassificationDiscriminant") assert_equal (CVMdl.CrossValidatedModel, "Discriminant") ***** error ... crossval (obj, 'kfold') ***** error... crossval (obj, 'kfold', 12, 'holdout', 0.2) ***** error ... crossval (obj, 'kfold', 'a') ***** error ... crossval (obj, 'holdout', 2) ***** error ... crossval (obj, 'leaveout', 1) ***** error ... crossval (obj, 'cvpartition', 1) ***** error ... savemodel (ClassificationDiscriminant ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])) ***** error ... savemodel (ClassificationDiscriminant ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), 1) ***** error ... savemodel (ClassificationDiscriminant ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2]), ['ab'; 'cd']) ***** test load fisheriris Mdl = fitcdiscr (meas, species); Mdl.ScoreTransform = 'symmetric'; assert_equal (class (Mdl.ScoreTransform), 'char'); assert_equal (Mdl.ScoreTransform, 'symmetric'); ***** test load fisheriris X = meas; Y = grp2idx (species); Mdl = fitcdiscr (X, Y); assert_equal (Mdl.RowsUsed, []); assert_equal (class (Mdl.RowsUsed), 'double'); assert_equal (Mdl.NumObservations, 150); assert_equal (rows (Mdl.X), 150); ***** test load fisheriris X = meas; Y = grp2idx (species); Y(5) = NaN; Mdl = fitcdiscr (X, Y); assert_equal (class (Mdl.RowsUsed), 'logical'); assert_equal (size (Mdl.RowsUsed), [150, 1]); assert_equal (sum (Mdl.RowsUsed), 149); assert_equal (Mdl.RowsUsed(5), false); assert_equal (Mdl.NumObservations, 149); assert_equal (rows (Mdl.X), 149); ***** test load fisheriris X = meas; X(3,2) = NaN; Y = grp2idx (species); Mdl = fitcdiscr (X, Y); assert_equal (Mdl.RowsUsed, []); assert_equal (Mdl.NumObservations, 150); assert_equal (rows (Mdl.X), 150); assert_equal (sum (isnan (Mdl.X(:))), 1); ***** test load fisheriris X = meas(1:130,[1, 3]); Y = species(1:130); k = (1:130)'; w = (1 + mod (k, 4)) .* (1 + (k > 50) + 2 * (k > 100)); Mdl = fitcdiscr (X, Y, 'Weights', w); assert_equal (Mdl.Prior, [0.185185185185185, 0.37037037037037, ... 0.444444444444444], 1e-14); assert_equal (Mdl.W([1, 51, 101])', [2, 8, 8] / 675, 1e-15); assert_equal (Mdl.Mu, [4.9832, 1.4472; 5.9456, 4.2536; ... 6.61333333333333, 5.64133333333333], 1e-13); assert_equal (Mdl.Sigma, [0.409670341318635, 0.303326062849595; ... 0.303326062849595, 0.307940102085745], 1e-14); assert_equal (Mdl.BetweenSigma, [0.563597620869565, 1.42708708173913; ... 1.42708708173913, 3.65290384695652], ... 1e-13); [~, s] = predict (Mdl, [6, 4.5; 6.5, 5.2]); assert_equal (s, [2.8720869604692e-15, 0.945382202857469, ... 0.0546177971425277; 4.32813750825658e-20, ... 0.182682233471567, 0.817317766528433], 1e-12); ***** test load fisheriris X = meas(1:130,[1, 3]); Y = species(1:130); k = (1:130)'; w = (1 + mod (k, 4)) .* (1 + (k > 50) + 2 * (k > 100)); Mdl = fitcdiscr (X, Y, 'Weights', w, 'Prior', 'uniform'); assert_equal (Mdl.W([1, 51, 101])', [2, 8, 8] / 675, 1e-15); assert_equal (Mdl.Sigma, [0.409670341318635, 0.303326062849595; ... 0.303326062849595, 0.307940102085745], 1e-14); ***** test load fisheriris X = meas(1:130,[1, 3]); Y = species(1:130); k = (1:130)'; w = (1 + mod (k, 4)) .* (1 + (k > 50) + 2 * (k > 100)); Mdl = fitcdiscr (X, Y, 'Weights', w, 'DiscrimType', 'quadratic'); assert_equal (Mdl.Sigma(:,:,3), [0.619863013698631, 0.507571269900037; ... 0.507571269900037, 0.487067752684191], ... 1e-14); ***** test load fisheriris X = meas(1:130,[1, 3]); Y = species(1:130); k = (1:130)'; w = (1 + mod (k, 4)) .* (1 + (k > 50) + 2 * (k > 100)); w([2, 60]) = 0; Mdl = fitcdiscr (X, Y, 'Weights', w); assert_equal (Mdl.NumObservations, 128); assert_equal (Mdl.RowsUsed([1, 2, 60]), [true; false; false]); ***** test load fisheriris X = meas(1:130,[1, 3]); Y = species(1:130); k = (1:130)'; w = (1 + mod (k, 4)) .* (1 + (k > 50) + 2 * (k > 100)); M1 = fitcdiscr (X, Y, 'Weights', w); M5 = fitcdiscr (X, Y, 'Weights', 5 * w); assert_equal (M5.Sigma, M1.Sigma, 1e-14); assert_equal (M5.W, M1.W, 1e-15); ***** test load fisheriris X = meas(1:130,[1, 3]); Y = species(1:130); k = (1:130)'; w = (1 + mod (k, 4)) .* (1 + (k > 50) + 2 * (k > 100)); Mdl = fitcdiscr (X, Y, 'Weights', w); assert_equal (resubLoss (Mdl), 0.0503703703703704, 1e-14); assert_equal (resubEdge (Mdl), 0.860269668211995, 1e-13); assert_equal (resubLoss (Mdl, 'LossFun', 'binodeviance'), ... 0.153822057071369, 1e-13); assert_equal (loss (Mdl, X, Y), 0.0518518518518519, 1e-14); ***** test load fisheriris i3 = [1:50, 51:80, 101:120]; Mdl = fitcdiscr (meas(i3,:), species(i3)); assert_equal (size (Mdl.Prior), [1, 3]); assert_equal (Mdl.Prior, [0.5, 0.3, 0.2], 1e-14); assert_equal (Mdl.W, ones (100, 1) / 100, 1e-14); ***** test load fisheriris i3 = [1:50, 51:80, 101:120]; Mdl = fitcdiscr (meas(i3,:), species(i3), 'Prior', 'uniform'); assert_equal (Mdl.Prior, [1, 1, 1] / 3, 1e-14); assert_equal (Mdl.W, ones (100, 1) / 100, 1e-14); ***** test load fisheriris i3 = [1:50, 51:80, 101:120]; p = struct ('ClassNames', {{'setosa'; 'virginica'; 'versicolor'}}, ... 'ClassProbs', [0.2, 0.3, 0.5]); Mdl = fitcdiscr (meas(i3,:), species(i3), 'Prior', p); assert_equal (Mdl.Prior, [0.2, 0.5, 0.3], 1e-14); ***** test load fisheriris i3 = [1:50, 51:80, 101:120]; p = struct ('ClassNames', {{'setosa'; 'virginica'; 'versicolor'}}, ... 'ClassProbs', [0.2, 0.3, 0.5]); Mdl = fitcdiscr (meas(i3,:), char (species(i3)), 'Prior', p); assert_equal (Mdl.Prior, [0.2, 0.5, 0.3], 1e-14); ***** test load fisheriris i3 = [1:50, 51:80, 101:120]; p = struct ('ClassNames', {{'setosa'; 'virginica'; 'versicolor'}}, ... 'ClassProbs', [0.2, 0.3, 0.5]); Mdl = fitcdiscr (meas(i3,:), categorical (species(i3)), 'Prior', p); assert_equal (Mdl.Prior, [0.2, 0.5, 0.3], 1e-14); ***** test load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Prior = [2, 3, 5]; assert_equal (Mdl.Prior, [0.2, 0.3, 0.5], 1e-14); Mdl.Cost = [0, 2, 3; 1, 0, 1; 1, 1, 0]; assert_equal (Mdl.Cost, [0, 2, 3; 1, 0, 1; 1, 1, 0]); ***** test load fisheriris Mdl = fitcdiscr (meas, species); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2), 'ClassificationDiscriminant'); assert_equal (M2.NumObservations, Mdl.NumObservations); assert_equal (M2.PredictorNames, Mdl.PredictorNames); assert_equal (class (M2.ScoreTransform), class (Mdl.ScoreTransform)); assert_equal (predict (M2, meas(1:5,:)), predict (Mdl, meas(1:5,:))); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'linear'); assert_equal (Mdl.DiscrimType, 'linear'); assert_equal (size (Mdl.Sigma), [4, 4]); assert_equal (Mdl.LogDetSigma, -9.9585, 1e-4); assert_equal (Mdl.Gamma, 0); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'quadratic'); assert_equal (Mdl.DiscrimType, 'quadratic'); assert_equal (size (Mdl.Sigma), [4, 4, 3]); assert_equal (Mdl.LogDetSigma', [-13.0674, -10.8743, -8.9271], 1e-4); assert_equal (Mdl.Gamma, 0); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'diagLinear'); assert_equal (Mdl.DiscrimType, 'diagLinear'); assert_equal (size (Mdl.Sigma), [1, 4]); assert_equal (Mdl.LogDetSigma, -8.3467, 1e-4); assert_equal (Mdl.Gamma, 1); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'diagQuadratic'); assert_equal (Mdl.DiscrimType, 'diagQuadratic'); assert_equal (size (Mdl.Sigma), [1, 4, 3]); assert_equal (Mdl.LogDetSigma', [-12.0271, -8.3925, -6.9421], 1e-4); assert_equal (Mdl.Gamma, 1); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'pseudoLinear'); assert_equal (Mdl.DiscrimType, 'pseudoLinear'); assert_equal (size (Mdl.Sigma), [4, 4]); assert_equal (Mdl.LogDetSigma, -9.9585, 1e-4); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'pseudoQuadratic'); assert_equal (Mdl.DiscrimType, 'pseudoQuadratic'); assert_equal (size (Mdl.Sigma), [4, 4, 3]); assert_equal (Mdl.LogDetSigma', [-13.0674, -10.8743, -8.9271], 1e-4); ***** test load fisheriris [~, s] = predict (fitcdiscr (meas, species), meas(71,:)); assert_equal (s, [0, 0.2532, 0.7468], 1e-4); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'quadratic'); [~, s] = predict (Mdl, meas(71,:)); assert_equal (s, [0, 0.3359, 0.6641], 1e-4); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'diagLinear'); [~, s] = predict (Mdl, meas(71,:)); assert_equal (s, [0, 0.2646, 0.7354], 1e-4); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'diagQuadratic'); [~, s] = predict (Mdl, meas(71,:)); assert_equal (s, [0, 0.1609, 0.8391], 1e-4); ***** test x = [1, 2; 2, 1; 3, 4; 4, 3; 5, 7; 7, 5; 8, 9; 9, 8]; y = [1; 1; 1; 1; 2; 2; 2; 2]; Mdl = fitcdiscr (x, y, 'DiscrimType', 'linear'); assert_equal (Mdl.Sigma, [2.2917, 1.125; 1.125, 2.2917], 1e-4); assert_equal (Mdl.LogDetSigma, 1.3828, 1e-4); assert_equal (Mdl.Coeffs(1,2).Const, 13.5549, 1e-4); assert_equal (Mdl.Coeffs(1,2).Linear', [-1.3902, -1.3902], 1e-4); ***** test x = [1, 2; 2, 1; 3, 4; 4, 3; 5, 7; 7, 5; 8, 9; 9, 8]; y = [1; 1; 1; 1; 2; 2; 2; 2]; Mdl = fitcdiscr (x, y, 'DiscrimType', 'quadratic'); assert_equal (Mdl.Sigma(:,:,1), [1.6667, 1; 1, 1.6667], 1e-4); assert_equal (Mdl.Coeffs(1,2).Const, 10.9525, 1e-4); assert_equal (Mdl.Coeffs(1,2).Linear', [-0.8025, -0.8025], 1e-4); assert_equal (Mdl.Coeffs(1,2).Quadratic, ... [-0.2587, 0.1912; 0.1912, -0.2587], 1e-4); ***** test x = [1, 2; 2, 1; 3, 4; 4, 3; 5, 7; 7, 5; 8, 9; 9, 8]; y = [1; 1; 1; 1; 2; 2; 2; 2]; Mdl = fitcdiscr (x, y, 'DiscrimType', 'diagQuadratic'); assert_equal (Mdl.Sigma(:,:,1), [1.6667, 1.6667], 1e-4); assert_equal (Mdl.Coeffs(1,2).Const, 14.8310, 1e-4); assert_equal (Mdl.Coeffs(1,2).Quadratic, [-0.1286, -0.1286], 1e-4); ***** test load fisheriris Mdl = fitcdiscr (meas, species); assert_equal (fieldnames (Mdl.Coeffs)', ... {'DiscrimType', 'Const', 'Linear', 'Class1', 'Class2'}); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'quadratic'); assert_equal (fieldnames (Mdl.Coeffs)', {'DiscrimType', 'Const', ... 'Linear', 'Quadratic', 'Class1', 'Class2'}); ***** test load fisheriris Mdl = fitcdiscr (meas, species); Mdl.DiscrimType = 'diagLinear'; assert_equal (size (Mdl.Sigma), [1, 4]); assert_equal (Mdl.Gamma, 1); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'diagLinear'); Mdl.DiscrimType = 'linear'; assert_equal (size (Mdl.Sigma), [4, 4]); assert_equal (Mdl.Gamma, 0); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'quadratic'); Mdl.DiscrimType = 'diagQuadratic'; assert_equal (size (Mdl.Sigma), [1, 4, 3]); ***** test load fisheriris Mdl = fitcdiscr (meas, species); before = Mdl.Coeffs(1,2).Const; Mdl.DiscrimType = 'diagLinear'; assert (abs (Mdl.Coeffs(1,2).Const - before) > 1); ***** test load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Gamma = 1; assert_equal (Mdl.DiscrimType, 'diagLinear'); assert_equal (size (Mdl.Sigma), [1, 4]); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'quadratic'); Mdl.Gamma = 1; assert_equal (Mdl.DiscrimType, 'diagQuadratic'); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'Gamma', 1); assert_equal (Mdl.DiscrimType, 'diagLinear'); ***** test load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Gamma = 0.25; assert_equal (loss (Mdl, meas, species), 0.0267, 1e-4); ***** test load fisheriris Mdl = fitcdiscr ([meas(:,1:3), meas(:,3)], species); assert (Mdl.MinGamma > 0); assert_equal (Mdl.Gamma, Mdl.MinGamma); assert_equal (Mdl.LogDetSigma, -41.3112, 0.1); ***** test load fisheriris Mdl = fitcdiscr ([meas(:,1:3), meas(:,3)], species, ... 'DiscrimType', 'pseudoLinear'); assert_equal (Mdl.LogDetSigma, -7.3470, 1e-4); assert_equal (Mdl.Gamma, 0); ***** test load fisheriris Mdl = fitcdiscr ([meas(:,1:3), meas(:,3)], species, ... 'DiscrimType', 'pseudoQuadratic'); assert_equal (Mdl.LogDetSigma', [-11.2116, -7.2229, -6.4619], 1e-4); ***** test load fisheriris Mdl = fitcdiscr ([meas(:,1:3), ones(150,1)], species, ... 'DiscrimType', 'pseudoLinear'); assert_equal (Mdl.Coeffs(1,2).Linear(4), 0); assert_equal (Mdl.LogDetSigma, -6.3538, 1e-4); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'quadratic'); CMdl = compact (Mdl); assert_equal (predict (CMdl, meas), predict (Mdl, meas)); assert_equal (CMdl.Sigma, Mdl.Sigma); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'quadratic'); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (predict (M2, meas), predict (Mdl, meas)); M2.DiscrimType = 'diagQuadratic'; assert_equal (size (M2.Sigma), [1, 4, 3]); ***** function x = dfix () x = [1, 2; 2, 1; 3, 4; 4, 3; 2, 3; 5, 7; 7, 5; 8, 9; 9, 8; 7, 8]; ***** endfunction ***** test load fisheriris Mdl = fitcdiscr (meas, species); assert_equal (Mdl.DeltaPredictor, ... [3.2508, 4.1236, 7.2926, 4.2506], 1e-4); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'diagLinear'); assert_equal (Mdl.DeltaPredictor, ... [1.6266, 1.0912, 5.3354, 4.6584], 1e-4); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'quadratic'); assert_equal (Mdl.DeltaPredictor, [0, 0, 0, 0]); ***** test load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Delta = 2.25; assert_equal (Mdl.Coeffs(1,2).Linear', ... [6.3148, 12.1393, -16.9464, -20.7701], 1e-4); assert_equal (Mdl.Coeffs(1,2).Const, -14.3792, 1e-4); ***** test load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Delta = 5; assert_equal (Mdl.Coeffs(1,2).Linear', [0, 0, -16.9464, 0], 1e-4); assert_equal (loss (Mdl, meas, species), 0.08, 1e-10); ***** test load fisheriris Mdl = fitcdiscr (meas, species); Mdl.Delta = 8; assert_equal (Mdl.Coeffs(1,2).Linear', [0, 0, 0, 0]); assert_equal (loss (Mdl, meas, species), 2/3, 1e-10); ***** test load fisheriris Mdl = fitcdiscr (meas, species); before = loss (Mdl, meas, species); Mdl.Delta = 5; assert_equal (before, 0.02, 1e-10); assert (loss (Mdl, meas, species) > before); ***** test load fisheriris Mdl = fitcdiscr (meas, species); before = Mdl.DeltaPredictor; Mdl.Delta = 5; assert_equal (Mdl.DeltaPredictor, before); ***** error ... fitcdiscr (ones (10, 2), [1;1;1;1;1;2;2;2;2;2], 'DiscrimType', 'bogus') ***** error ... Mdl = fitcdiscr (dfix (), [1;1;1;1;1;2;2;2;2;2]); ... Mdl.DiscrimType = 'quadratic'; ***** error ... Mdl = fitcdiscr (dfix (), [1;1;1;1;1;2;2;2;2;2], ... 'DiscrimType', 'quadratic'); ... Mdl.DiscrimType = 'linear'; ***** error ... Mdl = fitcdiscr (dfix (), [1;1;1;1;1;2;2;2;2;2]); Mdl.DiscrimType = 'bogus'; ***** error ... Mdl = fitcdiscr (dfix (), [1;1;1;1;1;2;2;2;2;2], ... 'DiscrimType', 'quadratic'); ... Mdl.Gamma = 0.5; ***** error ... fitcdiscr (dfix (), [1;1;1;1;1;2;2;2;2;2], ... 'DiscrimType', 'quadratic', 'Gamma', 0.5) ***** error ... Mdl = fitcdiscr (dfix (), [1;1;1;1;1;2;2;2;2;2]); Mdl.Gamma = 1.5; ***** error ... Mdl = fitcdiscr (dfix (), [1;1;1;1;1;2;2;2;2;2], ... 'DiscrimType', 'quadratic'); ... Mdl.Delta = 0.5; ***** error ... fitcdiscr (dfix (), [1;1;1;1;1;2;2;2;2;2], ... 'DiscrimType', 'quadratic', 'Delta', 0.5) ***** error ... fitcdiscr (dfix (), [1;1;1;1;1;2;2;2;2;2], 'Delta', -1) ***** error ... Mdl = fitcdiscr (dfix (), [1;1;1;1;1;2;2;2;2;2]); Mdl.Delta = [1, 2]; ***** error ... load fisheriris; ... fitcdiscr ([meas(:,1:3), meas(:,3)], species, 'DiscrimType', 'quadratic') ***** error ... load fisheriris; ... fitcdiscr ([meas(:,1:3), ones(150,1)], species, 'DiscrimType', 'quadratic') ***** test load fisheriris Mdl = fitcdiscr ([meas(:,1:3), meas(:,3)], species, ... 'DiscrimType', 'pseudoLinear'); assert (Mdl.MinGamma > 0); assert_equal (Mdl.Gamma, 0); ***** test load fisheriris Mdl = fitcdiscr ([meas(:,1:3), meas(:,3)], species, ... 'DiscrimType', 'diagLinear'); assert (Mdl.MinGamma > 0); assert_equal (Mdl.Gamma, 1); ***** test load fisheriris Mdl = fitcdiscr (meas, species); assert_equal (edge (Mdl, meas, species), 0.9454289377, 1e-9); ***** test load fisheriris Mdl = fitcdiscr (meas, species); m = margin (Mdl, meas, species); assert_equal (edge (Mdl, meas, species), mean (m), 1e-12); ***** test load fisheriris Mdl = fitcdiscr (meas, species); assert_equal (edge (Mdl, meas, species, 'Weights', (1:150)'), ... 0.9438468986, 1e-9); ***** test load fisheriris Mdl = fitcdiscr (meas, species); w = [ones(50,1); 7 * ones(50,1); 0.5 * ones(50,1)]; assert_equal (edge (Mdl, meas, species, 'Weights', w), ... edge (Mdl, meas, species), 1e-12); ***** test load fisheriris Mdl = fitcdiscr (meas, species); assert_equal (resubEdge (Mdl), 0.9454289377, 1e-9); assert_equal (resubLoss (Mdl), 0.02, 1e-12); assert_equal (sum (resubMargin (Mdl)), 141.8143406564, 1e-8); ***** test load fisheriris Mdl = fitcdiscr (meas, species); [label, score, cost] = resubPredict (Mdl); [l2, s2, c2] = predict (Mdl, meas); assert_equal (label, l2); assert_equal (score, s2); assert_equal (cost, c2); assert_equal (numel (label), 150); ***** test load fisheriris Mdl = fitcdiscr (meas, species); assert_equal (edge (compact (Mdl), meas, species), 0.9454289377, 1e-9); ***** error ... load fisheriris; edge (fitcdiscr (meas, species), meas) ***** error ... load fisheriris; ... edge (fitcdiscr (meas, species), meas, species, 'Weights') ***** error ... load fisheriris; ... edge (fitcdiscr (meas, species), meas, species, 'Weights', ones (3, 1)) ***** error ... load fisheriris; ... edge (fitcdiscr (meas, species), meas, species, 'Nope', 1) ***** test load fisheriris Mdl = fitcdiscr (meas, species); assert_equal (class (Mdl.BinEdges), 'cell'); assert_equal (Mdl.BinEdges, {}); ***** test load fisheriris Mdl = fitcdiscr (meas, species); assert_equal (Mdl.CategoricalPredictors, []); assert_equal (size (Mdl.CategoricalPredictors), [0, 0]); assert_equal (Mdl.ExpandedPredictorNames, Mdl.PredictorNames); assert_equal (size (Mdl.ExpandedPredictorNames), [1, 4]); ***** test load fisheriris Mdl = fitcdiscr (meas, species); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.CategoricalPredictors, Mdl.CategoricalPredictors); assert_equal (M2.ExpandedPredictorNames, Mdl.ExpandedPredictorNames); ***** test load fisheriris Mdl = fitcdiscr (meas, species); assert_equal (Mdl.BetweenSigma, ... [0.632121333333333, -0.199526666666667, ... 1.652483999999999, 0.712793333333333; -0.199526666666667, 0.113449333333333, ... -0.572395999999999, -0.229326666666666; 1.652483999999999, -0.572395999999999, ... 4.371027999999996, 1.867739999999998; 0.712793333333333, -0.229326666666666, ... 1.867739999999998, 0.804133333333333], 1e-12); ***** test load fisheriris k = [1:50, 51:80, 101:110]; Mdl = fitcdiscr (meas(k,:), species(k)); assert_equal (Mdl.BetweenSigma, ... [0.651346086956520, -0.299426956521739, ... 1.775435652173911, 0.711567826086955; -0.299426956521739, 0.160084347826087, ... -0.811819130434784, -0.318816086956522; 1.775435652173911, -0.811819130434784, ... 4.840319130434781, 1.941198695652173; 0.711567826086955, -0.318816086956522, ... 1.941198695652173, 0.780424347826086], 1e-12); ***** test load fisheriris X = meas; X(3,2) = NaN; X(77,4) = NaN; Mdl = fitcdiscr (X, species); assert_equal (Mdl.BetweenSigma(1,2), -0.201474748299320, 1e-12); assert_equal (Mdl.BetweenSigma(4,4), 0.803942801055115, 1e-12); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'quadratic'); assert_equal (Mdl.BetweenSigma(1,1), 0.632121333333333, 1e-12); ***** test load fisheriris Mdl = fitcdiscr (meas, species); before = Mdl.BetweenSigma; Mdl.Prior = [0.6, 0.2, 0.2]; assert_equal (Mdl.BetweenSigma, before); ***** test load fisheriris Mdl = fitcdiscr (meas, species); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.BetweenSigma, Mdl.BetweenSigma); ***** test load fisheriris Mdl = fitcdiscr (meas, species); M = mahal (Mdl, meas(1:5,:)); assert_equal (size (M), [5, 3]); assert_equal (M(1,:), [0.2910898404344, 98.8847494279393, ... 191.788642179719], 1e-10); assert_equal (M(5,:), [0.5956300391717, 100.923170228959, ... 193.854037009331], 1e-10); ***** test load fisheriris Mdl = fitcdiscr (meas, species); M = mahal (Mdl, meas(1:5,:), 'ClassLabels', species(1:5)); assert_equal (size (M), [5, 1]); assert_equal (M, [0.291089840434356; 2.031345104042097; ... 0.553281423559203; 2.086697905677364; ... 0.595630039171744], 1e-12); ***** test load fisheriris idx = [1; 51; 101]; D = diag (mahal (fitcdiscr (meas, species), meas(idx,:))); Mdl = fitcdiscr (meas, categorical (species)); assert_equal (mahal (Mdl, meas(idx,:), 'ClassLabels', species(idx)), D); assert_equal (mahal (Mdl, meas(idx,:), 'ClassLabels', ... categorical (species(idx))), D); assert_equal (mahal (Mdl, meas(idx,:), 'ClassLabels', ... string (species(idx))), D); assert_equal (mahal (Mdl, meas(idx,:), 'ClassLabels', ... char (species(idx))), D); ***** test load fisheriris idx = [1; 51; 101]; D = diag (mahal (fitcdiscr (meas, species), meas(idx,:))); Mdl = fitcdiscr (meas, species); assert_equal (mahal (Mdl, meas(idx,:), 'ClassLabels', ... categorical (species(idx))), D); assert_equal (mahal (Mdl, meas(idx,:), 'ClassLabels', ... string (species(idx))), D); ***** test load fisheriris idx = [1; 51; 101]; Mdl = fitcdiscr (meas, grp2idx (species)); D = diag (mahal (Mdl, meas(idx,:))); assert_equal (mahal (Mdl, meas(idx,:), 'ClassLabels', [1; 2; 3]), D); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'quadratic'); M = mahal (Mdl, meas(1:5,:)); assert_equal (M(1,:), [0.4491137892273, 114.804489260461, ... 182.935908699285], 1e-10); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'Gamma', 0.5); M = mahal (Mdl, meas(1:5,:)); assert_equal (M(1,:), [0.1926136709121, 79.4757202663154, ... 163.294484902038], 1e-10); ***** test load fisheriris M1 = mahal (fitcdiscr (meas, species), meas(1:5,:)); Mdl = fitcdiscr (meas, species, 'Prior', [0.6, 0.2, 0.2]); assert_equal (mahal (Mdl, meas(1:5,:)), M1, 1e-12); ***** test load fisheriris Mdl = fitcdiscr (meas, species); lp = logp (Mdl, meas(1:5,:)); assert_equal (size (lp), [5, 1]); assert_equal (lp, [0.059358043320009; -0.810769588483861; ... -0.071737748242414; -0.838445989301495; ... -0.092912056048684], 1e-12); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'quadratic'); lp = logp (Mdl, meas(1:5,:)); assert_equal (lp, [1.534756847193468; 0.718766664165731; ... 1.117146185488189; 0.906210252665867; ... 1.378471050607217], 1e-12); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'Prior', [0.6, 0.2, 0.2]); lp = logp (Mdl, meas(1:5,:)); assert_equal (lp, [0.647144708222129; -0.222982923581741; ... 0.516048916659706; -0.250659324399375; ... 0.494874608853435], 1e-12); ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); mahal (Mdl, []) ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); mahal (Mdl, ones (3, 2)) ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); mahal (Mdl, {1, 2, 3, 4}) ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); mahal (Mdl, meas(1:5,:), 'ClassLabels') ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); mahal (Mdl, meas(1:5,:), 5, 1) ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); mahal (Mdl, meas(1:5,:), 'bogus', 1) ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); mahal (Mdl, meas(1:2,:), 'ClassLabels', {1; 2}) ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); mahal (Mdl, meas(1:5,:), 'ClassLabels', species(1:3)) ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); mahal (Mdl, meas(1:2,:), 'ClassLabels', {'setosa'; 'nosuchspecies'}) ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); logp (Mdl, []) ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); logp (Mdl, ones (3, 2)) ***** error ... load fisheriris Mdl = fitcdiscr (meas, species); logp (Mdl, {1, 2, 3, 4}) ***** test ## DeltaPredictor follows Gamma: regularizing the covariance moves the ## coefficients, and the delta at which a predictor drops out with them. ## Measured against R2024a at four points of the grid. load fisheriris Mdl = fitcdiscr (meas, species); got = zeros (1, 4); g = [0, 1/3, 2/3, 1]; for k = 1:4 m = Mdl; m.Gamma = g(k); got(k) = max (m.DeltaPredictor); endfor assert_equal (got, [7.2926, 5.2537, 4.8816, 5.3354], 1e-4); ***** test ## cvshrink returns a column per output over the default grid of eleven ## Gamma values. load fisheriris Mdl = fitcdiscr (meas, species); [err, gamma, delta, numpred] = cvshrink (Mdl); assert_equal (size (err), [11, 1]); assert_equal (size (gamma), [11, 1]); assert_equal (size (delta), [11, 1]); assert_equal (size (numpred), [11, 1]); assert_equal (gamma, (0:0.1:1)', 1e-12); assert_equal (delta, zeros (11, 1)); assert_equal (numpred, repmat (4, 11, 1)); assert_equal (all (err >= 0 & err <= 1), true); ***** test ## NumGamma sets the number of intervals, so one more value than that. load fisheriris Mdl = fitcdiscr (meas, species); [err, gamma] = cvshrink (Mdl, "NumGamma", 4); assert_equal (size (err), [5, 1]); assert_equal (gamma, [0; 0.25; 0.5; 0.75; 1], 1e-12); ***** test ## The Delta grid runs to the point where the last predictor is gone, and ## that point moves with Gamma. Measured against R2024a. load fisheriris Mdl = fitcdiscr (meas, species); [err, gamma, delta, numpred] = cvshrink (Mdl, "NumGamma", 3, "NumDelta", 2); assert_equal (size (err), [4, 3]); assert_equal (size (delta), [4, 3]); assert_equal (delta, [0, 3.6463, 7.2926; 0, 2.6269, 5.2537; ... 0, 2.4408, 4.8816; 0, 2.6677, 5.3354], 1e-4); ## every predictor is in at Delta of zero, and they leave as it grows assert_equal (numpred(:,1), repmat (4, 4, 1)); assert_equal (all (numpred(:,3) < numpred(:,1)), true); ***** test ## An explicit Gamma is used as given. load fisheriris Mdl = fitcdiscr (meas, species); [err, gamma] = cvshrink (Mdl, "Gamma", [0, 0.5, 1]); assert_equal (size (err), [3, 1]); assert_equal (gamma, [0; 0.5; 1], 1e-12); ***** test ## An explicit Delta vector is used for every Gamma. load fisheriris Mdl = fitcdiscr (meas, species); [err, gamma, delta] = cvshrink (Mdl, "Gamma", [0, 1], "Delta", [0, 2]); assert_equal (size (delta), [2, 2]); assert_equal (delta, [0, 2; 0, 2]); ***** error ... cvshrink (fitcdiscr (ones (6, 2) + [1;2;3;4;5;6], [1;1;1;2;2;2]), "NumGamma") ***** error ... cvshrink (fitcdiscr (ones (6, 2) + [1;2;3;4;5;6], [1;1;1;2;2;2]), "NumGamma", 0) ***** error ... cvshrink (fitcdiscr (ones (6, 2) + [1;2;3;4;5;6], [1;1;1;2;2;2]), "NumDelta", -1) ***** error ... cvshrink (fitcdiscr (ones (6, 2) + [1;2;3;4;5;6], [1;1;1;2;2;2]), "Gamma", 2) ***** error ... cvshrink (fitcdiscr (ones (6, 2) + [1;2;3;4;5;6], [1;1;1;2;2;2]), "bogus", 1) ***** test load fisheriris Mdl = fitcdiscr (meas, species); assert_equal (isempty (Mdl.HyperparameterOptimizationResults), true); ***** test load fisheriris Mdl = fitcdiscr (meas, species); assert_equal (fieldnames (Mdl.ModelParameters)', {'DiscrimType', ... 'Gamma', 'Delta', 'FillCoeffs', 'Version', 'Method', 'Type'}); ***** test load fisheriris MP = fitcdiscr (meas, species).ModelParameters; assert_equal (MP.DiscrimType, 'linear'); assert_equal (MP.Gamma, 0); assert_equal (MP.Delta, 0); assert_equal (MP.FillCoeffs, true); ***** test load fisheriris MP = fitcdiscr (meas, species).ModelParameters; assert_equal (MP.Version, 1); assert_equal (MP.Method, 'Discriminant'); assert_equal (MP.Type, 'classification'); ***** test load fisheriris MP = fitcdiscr (meas, species, 'FillCoeffs', 'off').ModelParameters; assert_equal (MP.FillCoeffs, false); assert_equal (class (MP.FillCoeffs), 'logical'); ***** test load fisheriris MP = fitcdiscr (meas, species, 'DiscrimType', 'pseudoLinear', ... 'Gamma', 0.3, 'Delta', 0.1).ModelParameters; assert_equal (MP.DiscrimType, 'pseudoLinear'); assert_equal (MP.Gamma, 0.3); assert_equal (MP.Delta, 0.1); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'diagLinear', 'Gamma', 0.3); assert_equal (Mdl.ModelParameters.Gamma, 0.3); assert_equal (Mdl.Gamma, 1); ***** test load fisheriris CMdl = compact (fitcdiscr (meas, species)); assert_equal (isprop (CMdl, 'ModelParameters'), false); ***** test load fisheriris Mdl = fitcdiscr (meas, species); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); T = {'identity', @(x) x; 'doublelogit', @(x) 1 ./ (1 + exp (-2 * x)); ... 'invlogit', @(x) log (x ./ (1 - x)); ... 'logit', @(x) 1 ./ (1 + exp (-x)); ... 'sign', @(x) sign (x); 'symmetric', @(x) 2 * x - 1; ... 'symmetriclogit', @(x) 2 ./ (1 + exp (-x)) - 1}; for i = 1:rows (T) Mdl.ScoreTransform = T{i,1}; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, T{i,2}(raw), 1e-12); assert_equal (l, label); endfor ## ismax marks the largest score of each observation, ties to the first. [~, k] = max (raw, [], 2); e = zeros (size (raw)); e(sub2ind (size (raw), (1:rows (raw))', k)) = 1; Mdl.ScoreTransform = 'ismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, e); Mdl.ScoreTransform = 'symmetricismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, 2 * e - 1); ***** test load fisheriris Mdl = fitcdiscr (meas, species); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); Mdl.ScoreTransform = @(x) x .^ 2; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, raw .^ 2, 1e-12); assert_equal (l, label); ***** error ... ClassificationDiscriminant ([1, 2; 2, 1; 3, 2; 4, 1], [1; 1; 2; 2], ... 'CategoricalPredictors', 1) ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcdiscr (T, 'Species'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcdiscr (T, 'Species'); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitcdiscr (T, 'Species'); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** test # a table is matched to the predictors by name load fisheriris T = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = categorical (species); Mdl = fitcdiscr (T, 'Species'); a = mahal (Mdl, meas); assert_equal (mahal (Mdl, T(:,1:4)), a); assert_equal (mahal (Mdl, T(:,[5, 4, 2, 3, 1])), a); ***** test # a table is matched to the predictors by name load fisheriris T = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = categorical (species); Mdl = fitcdiscr (T, 'Species'); a = logp (Mdl, meas); assert_equal (logp (Mdl, T(:,1:4)), a); assert_equal (logp (Mdl, T(:,[5, 4, 2, 3, 1])), a); ***** test load fisheriris w = (1:150)'; Mdl = fitcdiscr (meas, species); assert_equal (resubLoss (Mdl, 'LossFun', 'classiferror', 'Weights', w), ... loss (Mdl, meas, species, 'LossFun', 'classiferror', ... 'Weights', w)); ***** error ... fitcdiscr ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', ... int8 ([1; 1; 1; 1])) ***** error ... fitcdiscr ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', true (4, 1)) ***** test ## Single weights are stored single, summing to one load fisheriris w = 1 + (1:150)' / 7; Mdl = fitcdiscr (meas, species, 'Weights', single (w)); assert_equal (class (Mdl.W), 'single'); assert_equal (sum (double (Mdl.W)), 1, 1e-6); ***** test ## Single weights compute as double load fisheriris w = 1 + (1:150)' / 7; A = fitcdiscr (meas, species, 'Weights', single (w)); B = fitcdiscr (meas, species, 'Weights', double (single (w))); assert_equal (nthargout (2, @predict, A, meas), nthargout (2, @predict, ... B, meas)); 254 tests, 254 passed, 0 known failure, 0 skipped [inst/Machine_Learning/ClassificationPartitionedEnsemble.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/ClassificationPartitionedEnsemble.m ***** shared X2, Y2, S, c, CV load fisheriris X2 = meas(51:150,:); Y2 = species(51:150); S = templateTree ('MaxNumSplits', 1); c = cvpartition (Y2, 'KFold', 5); CV = fitcensemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 4, 'Learners', S, ... 'CVPartition', c); ***** test # MATLAB parity: the properties of a cross-validated ensemble assert_equal (class (CV), 'ClassificationPartitionedEnsemble'); assert_equal (numel (properties (CV)), 19); assert_equal (CV.KFold, 5); assert_equal (CV.NumTrainedPerFold, [4, 4, 4, 4, 4]); assert_equal (CV.CrossValidatedModel, 'AdaBoostM1'); assert_equal (size (CV.Trained), [5, 1]); assert_equal (class (CV.Trained{1}), 'CompactClassificationEnsemble'); assert_equal (class (CV.Trainable{1}), 'ClassificationEnsemble'); assert_equal (CV.ModelParameters.Method, 'PartitionedEnsemble'); assert_equal (CV.ModelParameters.NLearn, 5); ***** test # MATLAB parity: each row is predicted by the fold that held it out S0 = zeros (100, 2); for k = 1:5 te = test (c, k); [~, S0(te,:)] = predict (CV.Trained{k}, X2(te,:)); endfor [label, s] = kfoldPredict (CV); assert_equal (s, S0); [~, j] = max (S0, [], 2); assert_equal (label, CV.ClassNames(j)); ***** test # MATLAB parity: the loss pooled over the folds and fold by fold [~, s] = kfoldPredict (CV); g = 1 + strcmp (Y2, 'virginica'); miss = s(sub2ind (size (s), (1:100)', g)) <= s(sub2ind (size (s), ... (1:100)', 3 - g)); assert_equal (kfoldLoss (CV), mean (miss), 1e-15); Li = kfoldLoss (CV, 'Mode', 'individual'); assert_equal (size (Li), [5, 1]); assert_equal (Li(2), mean (miss(test (c, 2))), 1e-15); assert_equal (kfoldLoss (CV, 'Folds', [1, 3]), ... mean (miss(test (c, 1) | test (c, 3))), 1e-15); ***** test # MATLAB parity: the cumulative loss grows the learners of every fold g = 1 + strcmp (Y2, 'virginica'); Lc = kfoldLoss (CV, 'Mode', 'cumulative'); assert_equal (size (Lc), [4, 1]); s = zeros (100, 2); for k = 1:5 te = test (c, k); [~, s(te,:)] = predict (CV.Trained{k}, X2(te,:), 'Learners', 1:2); endfor miss = s(sub2ind (size (s), (1:100)', g)) <= s(sub2ind (size (s), ... (1:100)', 3 - g)); assert_equal (Lc(2), mean (miss), 1e-15); assert_equal (Lc(4), kfoldLoss (CV), 1e-15); ***** test # MATLAB parity: the losses weigh the held-out rows by W w = [5 * ones(50, 1); ones(50, 1)]; M = fitcensemble (X2, Y2, 'Method', 'AdaBoostM1', 'NumLearningCycles', 4, ... 'Learners', S, 'CVPartition', c, 'Weights', w); [~, s] = kfoldPredict (M); g = 1 + strcmp (Y2, 'virginica'); miss = s(sub2ind (size (s), (1:100)', g)) <= s(sub2ind (size (s), ... (1:100)', 3 - g)); assert_equal (kfoldLoss (M), sum (M.W .* miss) / sum (M.W), 1e-15); ***** test # MATLAB parity: the edge and margins of the out-of-fold scores [~, s] = kfoldPredict (CV); g = 1 + strcmp (Y2, 'virginica'); m = s(sub2ind (size (s), (1:100)', g)) - s(sub2ind (size (s), ... (1:100)', 3 - g)); assert_equal (kfoldMargin (CV), m, 1e-14); assert_equal (kfoldEdge (CV), mean (m), 1e-13); assert_equal (size (kfoldEdge (CV, 'Mode', 'cumulative')), [4, 1]); assert_equal (size (kfoldEdge (CV, 'Mode', 'individual')), [5, 1]); ***** test # MATLAB parity: the score transform is applied once, by the parent M = fitcensemble (X2, Y2, 'Method', 'AdaBoostM1', 'NumLearningCycles', 4, ... 'Learners', S, 'CVPartition', c, ... 'ScoreTransform', 'doublelogit'); assert_equal (M.Trained{1}.ScoreTransform, 'none'); [~, s0] = kfoldPredict (CV); [~, s] = kfoldPredict (M); assert_equal (s, 1 ./ (1 + exp (-2 * s0)), 1e-15); ***** test # MATLAB parity: kfoldfun gets each fold's data and weights f = kfoldfun (CV, @(C, Xtr, Ytr, Wtr, Xte, Yte, Wte) ... [rows(Xtr), sum(Wtr), rows(Xte), sum(Wte), ... isa(C, 'CompactClassificationEnsemble')]); assert_equal (f(1,:), [80, 0.8, 20, 0.2, 1], 1e-15); assert_equal (rows (f), 5); ***** test # MATLAB parity: resuming grows every fold R = resume (CV, 2); assert_equal (R.NumTrainedPerFold, [6, 6, 6, 6, 6]); assert_equal (class (R.Trained{3}), 'CompactClassificationEnsemble'); ***** test # MATLAB parity: a holdout leaves the training rows unscored load fisheriris rng (3); M = fitcensemble (meas, species, 'Method', 'Bag', 'NumLearningCycles', 3, ... 'Holdout', 0.3); assert_equal (class (M), 'ClassificationPartitionedEnsemble'); assert_equal (M.KFold, 1); [~, s] = kfoldPredict (M); assert_equal (sum (any (isnan (s), 2)), sum (training (M.Partition, 1))); ***** error ... ClassificationPartitionedEnsemble (1) ***** error ... ClassificationPartitionedEnsemble (1, c) ***** error ... ClassificationPartitionedEnsemble (CV.Trainable{1}, 1) ***** error ... ClassificationPartitionedEnsemble (CV.Trainable{1}, c) ***** error ... kfoldLoss (CV, 'Mode') ***** error ... kfoldLoss (CV, 'Learners', 1) ***** error ... kfoldLoss (CV, 'Mode', 'ensemble') ***** error ... kfoldLoss (CV, 'Folds', 6) ***** error ... kfoldLoss (CV, 'LossFun', 'mse') ***** error ... kfoldEdge (CV, 'LossFun', 'hinge') ***** error ... kfoldfun (CV) ***** error ... kfoldfun (CV, 1) ***** error ... resume (CV) ***** error ... M = CV; M.ScoreTransform = 1; 24 tests, 24 passed, 0 known failure, 0 skipped [inst/Machine_Learning/RegressionKernel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/RegressionKernel.m ***** demo ## Fit fuel consumption through a randomized Gaussian kernel, which ## bends where a linear model cannot. load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); Mdl = RegressionKernel (X(ok,:), MPG(ok)) yFit = predict (Mdl, X(find (ok, 3),:)) ***** demo ## Standardizing matters more here than for a linear fit, since the ## kernel measures one distance across predictors of every scale. load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); plain = RegressionKernel (X(ok,:), MPG(ok)); scaled = RegressionKernel (X(ok,:), MPG(ok), 'Standardize', true); plainLoss = loss (plain, X(ok,:), MPG(ok)) scaledLoss = loss (scaled, X(ok,:), MPG(ok)) ***** shared X, Y load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); X = X(ok,:); Y = MPG(ok); ***** test ## The model reports the surface MATLAB reports Mdl = RegressionKernel (X, Y); assert_equal (class (Mdl), 'RegressionKernel'); assert_equal (Mdl.Learner, 'svm'); assert_equal (Mdl.FittedLoss, 'epsiloninsensitive'); assert_equal (Mdl.Regularization, 'ridge (L2)'); assert_equal (Mdl.ResponseTransform, 'none'); assert_equal (Mdl.KernelScale, 1); assert_equal (Mdl.BoxConstraint, 1); assert_equal (Mdl.NumExpansionDimensions, 128); assert_equal (Mdl.Mu, []); assert_equal (Mdl.Sigma, []); assert_equal (Mdl.PredictorNames, {'x1', 'x2', 'x3', 'x4'}); ***** test ## The properties are the ones MATLAB lists, in its order Mdl = RegressionKernel (X, Y); assert_equal (sort (properties (Mdl)), ... sort ({'Epsilon'; 'BoxConstraint'; 'ResponseTransform'; ... 'PredictorNames'; 'CategoricalPredictors'; ... 'ResponseName'; 'ExpandedPredictorNames'; ... 'NumExpansionDimensions'; 'FittedLoss'; 'Lambda'; ... 'ModelParameters'; 'Regularization'; 'KernelScale'; ... 'Learner'; 'Mu'; 'Sigma'})); ***** test ## Epsilon defaults to the interquartile range over 13.49, as it does for ## the linear model Mdl = RegressionKernel (X, Y); assert_equal (Mdl.Epsilon, 0.926612305411416, 1e-12); assert_equal (Mdl.Epsilon, iqr (Y) / 13.49, 1e-15); ***** test ## Least squares has no insensitive band at all Mdl = RegressionKernel (X, Y, 'Learner', 'leastsquares'); assert_equal (Mdl.Epsilon, []); assert_equal (Mdl.FittedLoss, 'mse'); ***** test ## Lambda and the box constraint are reciprocal through the number of ## observations, and either one may be the one that is given Mb = RegressionKernel (X, Y, 'BoxConstraint', 4); assert_equal (Mb.Lambda, 1 / (93 * 4), 1e-15); Ml = RegressionKernel (X, Y, 'Lambda', 0.02); assert_equal (Ml.BoxConstraint, 1 / (93 * 0.02), 1e-12); ***** test ## Lambda defaults to the reciprocal of the observations that were used Mdl = RegressionKernel (X, Y); assert_equal (Mdl.Lambda, 1 / 93, 1e-15); ***** test ## The default expansion is MATLAB's, two to the power of five more than ## the base two logarithm of the predictors assert_equal (RegressionKernel (X(:,1:2), Y).NumExpansionDimensions, 64); assert_equal (RegressionKernel (X, Y, ... 'NumExpansionDimensions', 50).NumExpansionDimensions, 50); ***** test ## An odd expansion cannot be paired throughout, and the dimension left ## over still comes back as a dimension Mdl = RegressionKernel (X, Y, 'NumExpansionDimensions', 51); assert_equal (Mdl.NumExpansionDimensions, 51); assert_equal (numel (predict (Mdl, X)), 93); ***** test ## Standardizing records the means and deviations of the predictors Mdl = RegressionKernel (X, Y, 'Standardize', true); assert_equal (Mdl.Mu, mean (X), 1e-12); assert_equal (Mdl.Sigma, std (X), 1e-12); ***** test ## A kernel fit follows the response it was given Mdl = RegressionKernel (X, Y, 'Learner', 'leastsquares', ... 'Standardize', true, 'Lambda', 1e-4); assert_equal (loss (Mdl, X, Y) < var (Y), true); assert_equal (corr (predict (Mdl, X), Y) > 0.5, true); ***** test ## Predicting through the model's own basis gives the same answer every ## time it is asked Mdl = RegressionKernel (X, Y); assert_equal (predict (Mdl, X(1:10,:)), predict (Mdl, X(1:10,:))); ***** test ## resume continues from the coefficients the model already holds, so it ## cannot leave the objective higher than it found it Mdl = RegressionKernel (X, Y, 'IterationLimit', 3); before = Mdl.FitInfo_.ObjectiveValue; Mdl = resume (Mdl, X, Y, 'IterationLimit', 500); assert_equal (class (Mdl), 'RegressionKernel'); assert_equal (Mdl.FitInfo_.ObjectiveValue <= before, true); assert_equal (Mdl.ModelParameters.IterationLimit, 500); ***** test ## The fit information is MATLAB's kernel structure Mdl = RegressionKernel (X, Y); F = Mdl.FitInfo_; assert_equal (fieldnames (F), {'Solver'; 'LossFunction'; 'Lambda'; ... 'BetaTolerance'; 'GradientTolerance'; ... 'ObjectiveValue'; 'GradientMagnitude'; ... 'RelativeChangeInBeta'; 'FitTime'; ... 'History'}); assert_equal (F.Solver, 'LBFGS-fast'); assert_equal (F.LossFunction, 'epsiloninsensitive'); ***** test ## A response transform reaches predict Mdl = RegressionKernel (X, Y, 'Learner', 'leastsquares'); plain = predict (Mdl, X(1:5,:)); Mdl.ResponseTransform = 'exp'; assert_equal (predict (Mdl, X(1:5,:)), exp (plain), 1e-12); ***** test ## A row with a missing predictor or a missing response is dropped Xn = X; Xn(3,2) = NaN; Mdl = RegressionKernel (Xn, Y); assert_equal (Mdl.Lambda, 1 / 92, 1e-15); ***** test ## A saved model reads back as the same model, the random basis included Mdl = RegressionKernel (X, Y); fname = tempname (); savemodel (Mdl, fname); Mnew = loadmodel (fname); delete (fname); assert_equal (class (Mnew), 'RegressionKernel'); assert_equal (predict (Mnew, X(1:5,:)), predict (Mdl, X(1:5,:))); ***** test ## resume keeps no observation weights, because the model keeps no data: ## passing them back restores the weighted fit, and omitting them ## continues against uniform ones Mdl = RegressionKernel (X, Y, 'IterationLimit', 5, 'Weights', (1:93)'); kept = resume (Mdl, X, Y, 'IterationLimit', 400, 'Weights', (1:93)'); lost = resume (Mdl, X, Y, 'IterationLimit', 400); assert_equal (kept.FitInfo_.ObjectiveValue ... != lost.FitInfo_.ObjectiveValue, true); ***** test # A row missing a predictor predicts the lower median of the response X = [(1:10)', mod((1:10)', 3)]; Mdl = RegressionKernel (X, (1:10)'); assert_equal (predict (Mdl, [NaN, 1]), 5); ***** error RegressionKernel (ones (5, 2)) ***** error ... RegressionKernel (ones (10, 2), ones (10, 1), 'Learner') ***** error ... RegressionKernel (ones (10, 2), ones (10, 1), 'Learner', 'logistic') ***** error ... RegressionKernel (ones (10, 2), ones (10, 1), 'Epsilon', -1) ***** error ... RegressionKernel (ones (10, 2), ones (10, 1), 'Learner', 'leastsquares', ... 'Epsilon', 1) ***** error ... RegressionKernel (ones (10, 2), ones (10, 1), 'NumExpansionDimensions', 2.5) ***** error ... RegressionKernel (ones (10, 2), ones (10, 1), 'KernelScale', 0) ***** error ... RegressionKernel (ones (10, 2), ones (10, 1), 'Lambda', Inf) ***** error ... RegressionKernel (ones (10, 2), ones (10, 1), 'BoxConstraint', -2) ***** error ... RegressionKernel (ones (10, 2), ones (10, 1), 'Lambda', 0.1, ... 'BoxConstraint', 2) ***** error ... RegressionKernel (ones (10, 2), ones (10, 1), 'Learner', 'leastsquares', ... 'BoxConstraint', 2) ***** error ... RegressionKernel (ones (10, 2), ones (10, 1), 'Standardize', 'yes') ***** error ... RegressionKernel (ones (10, 2), ones (10, 1), 'Verbose', 2) ***** error ... RegressionKernel (ones (10, 2), ones (10, 1), 'Nonsense', 1) ***** error RegressionKernel ({1, 2; 3, 4}, [1; 2]) ***** error RegressionKernel ([], []) ***** error RegressionKernel (ones (10, 2), {1, 2}) ***** error ... RegressionKernel (ones (10, 2), ones (3, 1)) ***** error ... RegressionKernel (ones (10, 2), ones (10, 1), 'Weights', ones (3, 1)) ***** error ... predict (RegressionKernel (ones (10, 2), ones (10, 1)), []) ***** error ... predict (RegressionKernel (ones (10, 2), ones (10, 1)), ones (3, 5)) ***** error ... loss (RegressionKernel (ones (10, 2), ones (10, 1)), ones (10, 2), ... ones (10, 1), 'LossFun', 'hinge') ***** error ... loss (RegressionKernel (ones (10, 2), ones (10, 1)), ones (10, 2), ... ones (10, 1), 'Bogus', 1) ***** error ... loss (RegressionKernel (ones (10, 2), ones (10, 1), 'Learner', ... 'leastsquares'), ones (10, 2), ones (10, 1), ... 'LossFun', 'epsiloninsensitive') ***** error ... resume (RegressionKernel (ones (10, 2), ones (10, 1)), ones (10, 2)) ***** error ... resume (RegressionKernel (ones (10, 2), ones (10, 1)), ones (10, 5), ... ones (10, 1)) ***** error ... resume (RegressionKernel (ones (10, 2), ones (10, 1)), ones (10, 2), ... ones (10, 1), 'Nonsense', 1) ***** error ... resume (RegressionKernel (ones (10, 2), ones (10, 1)), ones (10, 2), ... ones (10, 1), 'Weights', -1) ***** test load fisheriris Mdl = fitrkernel (meas(:,2:4), meas(:,1)); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); T = {'identity', @(x) x; 'exp', @(x) exp (x); 'log', @(x) log (x)}; for i = 1:rows (T) Mdl.ResponseTransform = T{i,1}; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, T{i,2}(raw), 1e-12); endfor ***** test load fisheriris Mdl = fitrkernel (meas(:,2:4), meas(:,1)); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); Mdl.ResponseTransform = @(x) x .^ 2; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, raw .^ 2, 1e-12); ***** shared Xc, Dc, yc c1 = repmat ([1; 2; 3], 20, 1); x2 = sin ((1:60)'); c3 = repmat ([10; 10; 20; 20], 15, 1); Xc = [c1, x2, c3]; Dc = [c1 == 1, c1 == 2, c1 == 3, x2, c3 == 10, c3 == 20]; yc = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 20) + 0.1 * cos ((1:60)'); ***** test # MATLAB parity: the kernel expands the dummy coded predictors randn ('seed', 9); rand ('seed', 9); Mdl = RegressionKernel (Xc, yc, 'CategoricalPredictors', [1, 3]); randn ('seed', 9); rand ('seed', 9); H = RegressionKernel (Dc, yc); assert_equal (Mdl.CategoricalPredictors, [1, 3]); assert_equal (Mdl.NumExpansionDimensions, 256); assert_equal (predict (Mdl, Xc(1:5,:)), predict (H, Dc(1:5,:)), 1e-12); ***** test # MATLAB parity: the coded columns are not standardized Mdl = RegressionKernel (Xc, yc, 'CategoricalPredictors', [1, 3], ... 'Standardize', true); assert_equal (Mdl.Mu([1:3, 5:6]), zeros (1, 5)); assert_equal (Mdl.Sigma([1:3, 5:6]), ones (1, 5)); assert_equal (Mdl.Sigma(4), std (Xc(:,2)), 1e-12); ***** test # resume codes the data as the fit did Mdl = RegressionKernel (Xc, yc, 'CategoricalPredictors', [1, 3]); Mdl = resume (Mdl, Xc, yc); yhat = predict (Mdl, [4, 0, 10; 2, 0, 20]); ys = sort (yc); assert_equal (yhat(1), ys(ceil (numel (ys) / 2))); assert_equal (isnan (yhat(2)), false); ***** error ... RegressionKernel (Xc, yc, 'CategoricalPredictors', 4) ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,2:3); y = meas(:,1); T = table (X(:,1), X(:,2), 'VariableNames', {'SW', 'PL'}); T.SL = y; Mdl = fitrkernel (T, 'SL'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'SL'), a); assert_equal (loss (Mdl, T), a); ***** test # the response is named or given beside the table load fisheriris X = meas(:,2:3); y = meas(:,1); T = table (X(:,1), X(:,2), 'VariableNames', {'SW', 'PL'}); T.SL = y; Mdl = fitrkernel (T, 'SL', 'IterationLimit', 5); a = predict (resume (Mdl, X, y, 'IterationLimit', 20), X); assert_equal (predict (resume (Mdl, T(:,1:2), y, ... 'IterationLimit', 20), X), a); assert_equal (predict (resume (Mdl, T, 'SL', 'IterationLimit', 20), X), a); assert_equal (predict (resume (Mdl, T(:,[3, 2, 1]), 'SL'), X), ... predict (resume (Mdl, X, y), X)); ***** error ... load fisheriris T = table (meas(:,2), meas(:,3), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'SL'}); resume (fitrkernel (T, 'SL'), T) ***** error ... load fisheriris T = table (meas(:,2), meas(:,3), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'SL'}); resume (fitrkernel (T, 'SL'), T, 'IterationLimit', 5) ***** error ... fitrkernel ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', 'Weights', int8 ([1; 1; 1; 1])) ***** error ... fitrkernel ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', 'Weights', true (4, 1)) ***** error X = [1, 2; 3, 4; 5, 6; 7, 8]; y = (1:4)'; loss (fitrkernel (X, y), X, y, 'Weights', int8 ([1; 1; 1; 1])) ***** error X = [1, 2; 3, 4; 5, 6; 7, 8]; y = (1:4)'; resume (fitrkernel (X, y), X, y, 'Weights', int8 ([1; 1; 1; 1])) ***** test ## Single weights compute as double load fisheriris X = meas(:,2:4); y = meas(:,1); w = 1 + (1:150)' / 7; rand ('seed', 1); randn ('seed', 1); A = fitrkernel (X, y, 'Weights', single (w)); rand ('seed', 1); randn ('seed', 1); B = fitrkernel (X, y, 'Weights', double (single (w))); assert_equal (predict (A, X), predict (B, X)); 61 tests, 61 passed, 0 known failure, 0 skipped [inst/Machine_Learning/plotPartialDependence.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/plotPartialDependence.m ***** demo ## The partial dependence of a fitted tree on one predictor. The line is ## what the tree answers on average as that predictor is varied over its ## range, the others left as the data holds them. load fisheriris Mdl = fitrtree (meas(:,2:4), meas(:,1)); plotPartialDependence (Mdl, 1); ***** demo ## The same tree, with one curve per observation. Each grey curve is what ## the model answers for a single flower as the predictor is varied; the ## red line is their mean and the circles mark where each flower sits. load fisheriris Mdl = fitrtree (meas(:,2:4), meas(:,1)); plotPartialDependence (Mdl, 1, 'Conditional', 'absolute'); ***** demo ## Two predictors give a surface, and a classification model is told which ## class to answer for. load fisheriris Mdl = fitcsvm (meas(51:end,3:4), species(51:end)); plotPartialDependence (Mdl, [1, 2], 'versicolor'); ***** shared ppX, ppYr, ppY3, ppQ, ppLo x1 = repmat ([1;2;3], 4, 1); x2 = reshape (repmat (1:4, 3, 1), 12, 1); ppX = [x1, x2]; ppYr = 10 * x2 + x1; ppY3 = repmat ({'a'; 'b'; 'c'}, 4, 1); ppQ = [1; 2; 3]; lo1 = repmat ([1;2;3], 2, 1); ppLo = [lo1, ones(6, 1)]; ***** test hf = figure ('visible', 'off'); unwind_protect Mdl = fitrsvm (ppX, ppYr); ax = plotPartialDependence (Mdl, 1, 'QueryPoints', ppQ); ch = get (ax, 'children'); assert_equal (numel (ch), 1); assert_equal (get (ch(1), 'ydata'), ... partialDependence (Mdl, 1, 'QueryPoints', ppQ), 1e-12); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # two predictors give one surface, sized by the second then the first hf = figure ('visible', 'off'); unwind_protect Mdl = fitrsvm (ppX, ppYr); ax = plotPartialDependence (Mdl, [1, 2], 'QueryPoints', {ppQ, [2;4]}); ch = get (ax, 'children'); assert_equal (get (ch(1), 'type'), 'surface'); assert_equal (size (get (ch(1), 'zdata')), [2, 3]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a classifier draws one line per class named hf = figure ('visible', 'off'); unwind_protect Mdl = fitctree (ppX, ppY3); ax = plotPartialDependence (Mdl, 1, {'a', 'b'}, 'QueryPoints', ppQ); assert_equal (numel (get (ax, 'children')), 2); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Scores'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # MATLAB parity: one class names the axis after it hf = figure ('visible', 'off'); unwind_protect Mdl = fitctree (ppX, ppY3); ax = plotPartialDependence (Mdl, 1, 'a', 'QueryPoints', ppQ, ... 'Conditional', 'absolute'); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Score of class a'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a conditional plot draws a curve per observation, a marker, a line hf = figure ('visible', 'off'); unwind_protect Mdl = fitrsvm (ppX, ppYr); ax = plotPartialDependence (Mdl, 1, 'QueryPoints', ppQ, ... 'Conditional', 'absolute'); ch = get (ax, 'children'); assert_equal (numel (ch), rows (ppX) + 2); assert_equal (sum (arrayfun (@(h) isprop (h, 'cdata'), ch)), 1); ## Octave's scatter builds an hggroup under the gnuplot toolkit if (! strcmp (graphics_toolkit (), 'gnuplot')) assert_equal (sum (strcmp (get (ch, 'type'), 'scatter')), 1); endif unwind_protect_cleanup close (hf); end_unwind_protect ***** test # MATLAB parity: centering shifts every curve to start at zero hf = figure ('visible', 'off'); unwind_protect Mdl = fitrsvm (ppX, ppYr); ax = plotPartialDependence (Mdl, 1, 'QueryPoints', ppQ, ... 'Conditional', 'centered'); ch = get (ax, 'children'); for k = 1:numel (ch) if (strcmp (get (ch(k), 'type'), 'line')) yd = get (ch(k), 'ydata'); assert_equal (yd(1), 0, 1e-12); endif endfor unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect Mdl = fitrtree (ppX, ppYr); ax = plotPartialDependence (Mdl, 1, ppLo, 'QueryPoints', ppQ, ... 'Conditional', 'absolute'); ch = get (ax, 'children'); red = []; grey = []; for k = 1:numel (ch) if (! strcmp (get (ch(k), 'type'), 'line')) continue; endif if (isequal (get (ch(k), 'color'), [1, 0, 0])) red = get (ch(k), 'ydata'); else grey(end+1,:) = get (ch(k), 'ydata'); endif endfor assert_equal (red, mean (grey, 1), 1e-12); assert_equal (red, [17, 17, 17], 1e-12); assert_equal (partialDependence (Mdl, 1, ppLo, 'QueryPoints', ppQ), ... [27, 27, 27], 1e-12); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # the titles say which plot it is hf = figure ('visible', 'off'); unwind_protect Mdl = fitrsvm (ppX, ppYr); ax = plotPartialDependence (Mdl, 1, 'QueryPoints', ppQ); assert_equal (get (get (ax, 'title'), 'string'), ... 'Partial Dependence Plot'); clf (hf); ax = plotPartialDependence (Mdl, 1, 'QueryPoints', ppQ, ... 'Conditional', 'centered'); assert_equal (get (get (ax, 'title'), 'string'), ... 'Individual Conditional Expectation Plot'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # the horizontal axis is named after the predictor varied hf = figure ('visible', 'off'); unwind_protect Mdl = fitrsvm (ppX, ppYr, 'PredictorNames', {'alpha', 'beta'}); ax = plotPartialDependence (Mdl, 'beta', 'QueryPoints', [2;4]); assert_equal (get (get (ax, 'xlabel'), 'string'), 'beta'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # MATLAB parity: Parent draws into the axes given and returns it hf = figure ('visible', 'off'); unwind_protect a1 = subplot (1, 2, 1); a2 = subplot (1, 2, 2); Mdl = fitrsvm (ppX, ppYr); ax = plotPartialDependence (Mdl, 1, 'QueryPoints', ppQ, 'Parent', a2); assert_equal (ax, a2); assert_equal (isempty (get (a2, 'children')), false); assert_equal (isempty (get (a1, 'children')), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** error ... plotPartialDependence (1) ***** error ... plotPartialDependence (fitrsvm (ppX, ppYr), [1, 2], ... 'Conditional', 'absolute') ***** error ... plotPartialDependence (fitctree (ppX, ppY3), 1, {'a', 'b'}, ... 'Conditional', 'absolute') ***** error ... plotPartialDependence (fitrsvm (ppX, ppYr), 1, 'Conditional', 'sideways') ***** error ... plotPartialDependence (fitrsvm (ppX, ppYr), 1, 'Parent', 42) ***** error ... partialDependence (fitrsvm (ppX, ppYr), 1, 'Conditional', 'absolute') 16 tests, 16 passed, 0 known failure, 0 skipped [inst/Machine_Learning/CompactRegressionNeuralNetwork.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/CompactRegressionNeuralNetwork.m ***** test rand ('seed', 42); randn ('seed', 42); X = [randn(40, 2); randn(40, 2) + 3]; Y = X(:,1) - 2 * X(:,2); Mdl = fitrnet (X, Y, 'IterationLimit', 100); CMdl = compact (Mdl); assert_equal (class (CMdl), 'CompactRegressionNeuralNetwork'); kept = {'NumPredictors', 'PredictorNames', 'ResponseName', ... 'ResponseTransform', 'Sigma', 'Mu', 'LayerSizes', ... 'Activations', 'OutputLayerActivation', 'LayerWeights', ... 'LayerBiases', 'CategoricalPredictors', 'ExpandedPredictorNames'}; assert_equal (all (ismember (kept, properties (CMdl))), true); dropped = {'X', 'Y', 'W', 'NumObservations', 'RowsUsed', 'TrainingHistory'}; assert_equal (any (ismember (dropped, properties (CMdl))), false); ***** test rand ('seed', 42); randn ('seed', 42); X = [randn(50, 2); randn(50, 2) + 2]; Y = 3 * X(:,1) + X(:,2); Mdl = fitrnet (X, Y, 'LayerSizes', [8, 6], 'IterationLimit', 200); CMdl = compact (Mdl); assert_equal (predict (CMdl, X), predict (Mdl, X)); assert_equal (loss (CMdl, X, Y), loss (Mdl, X, Y)); assert_equal (loss (CMdl, X, Y), resubLoss (Mdl), 1e-12); assert_equal (CMdl.LayerWeights, Mdl.LayerWeights); assert_equal (CMdl.LayerBiases, Mdl.LayerBiases); ***** test rand ('seed', 42); randn ('seed', 42); X = [randn(60, 1), randn(60, 1) * 1000]; Y = X(:,1) + X(:,2) / 1000; Mdl = fitrnet (X, Y, 'Standardize', true, 'IterationLimit', 200); CMdl = compact (Mdl); assert_equal (CMdl.Mu, Mdl.Mu); assert_equal (CMdl.Sigma, Mdl.Sigma); assert_equal (predict (CMdl, X), predict (Mdl, X)); ***** test rand ('seed', 42); randn ('seed', 42); X = linspace (0, 1, 30)'; Y = 3 * X + 1; CMdl = compact (fitrnet (X, Y, 'IterationLimit', 100)); yFit = predict (CMdl, X); assert_equal (loss (CMdl, X, Y), mean ((Y - yFit) .^ 2), 1e-12); assert_equal (loss (CMdl, X, Y, 'LossFun', 'mse'), loss (CMdl, X, Y), 1e-12); w = rand (30, 1) + 0.1; assert_equal (loss (CMdl, X, Y, 'Weights', w), ... loss (CMdl, X, Y, 'Weights', 5 * w), 1e-12); f = @(y, yf, ww) sum (ww .* abs (y - yf)); assert_equal (loss (CMdl, X, Y, 'LossFun', f), mean (abs (Y - yFit)), 1e-12); ***** test rand ('seed', 42); X = linspace (0, 1, 20)'; Mdl = fitrnet (X, 2 * X + 1, 'ResponseTransform', 'exp', ... 'IterationLimit', 50); CMdl = compact (Mdl); assert_equal (predict (CMdl, X), predict (Mdl, X)); CMdl.ResponseTransform = 'none'; assert_equal (predict (CMdl, X), log (predict (Mdl, X)), 1e-12); ***** test rand ('seed', 42); randn ('seed', 42); X = linspace (0, 1, 30)'; Y = 4 * X - 1; CMdl = compact (fitrnet (X, Y, 'LayerSizes', [6, 4], ... 'IterationLimit', 60)); fname = tempname (); savemodel (CMdl, fname); C2 = loadmodel (fname); delete (fname); assert_equal (class (C2), 'CompactRegressionNeuralNetwork'); assert_equal (C2.LayerWeights, CMdl.LayerWeights); assert_equal (C2.LayerBiases, CMdl.LayerBiases); assert_equal (C2.NumPredictors, CMdl.NumPredictors); assert_equal (C2.LayerSizes, CMdl.LayerSizes); assert_equal (predict (C2, X), predict (CMdl, X)); ***** test # A row missing a predictor predicts the lower median of the response X = [(1:10)', mod((1:10)', 3)]; Mdl = compact (RegressionNeuralNetwork (X, (1:10)')); assert_equal (predict (Mdl, [NaN, 1]), 5); ***** error ... CompactRegressionNeuralNetwork (1) ***** error ... CompactRegressionNeuralNetwork (fitcnet (ones (4, 2), [1; 1; 2; 2])) ***** shared CRNN rand ('seed', 42); CRNN = compact (fitrnet ([1; 2; 3; 4], [2; 4; 6; 8], 'IterationLimit', 10)); ***** error ... predict (CRNN) ***** error ... predict (CRNN, []) ***** error ... predict (CRNN, ones (2, 3)) ***** error ... loss (CRNN) ***** error ... loss (CRNN, [1; 2], [2; 4], 'Weights') ***** error ... loss (CRNN, [], [2; 4]) ***** error ... loss (CRNN, ones (2, 3), [2; 4]) ***** error ... loss (CRNN, [1; 2], []) ***** error ... loss (CRNN, [1; 2], {'a'; 'b'}) ***** error ... loss (CRNN, [1; 2], [2; 4; 6]) ***** error ... loss (CRNN, [1; 2], [2; 4], 'LossFun', 5) ***** error ... loss (CRNN, [1; 2], [2; 4], 'LossFun', 'mae') ***** error ... loss (CRNN, [1; 2], [2; 4], 'LossFun', @(y, yf, w) [1, 2]) ***** error ... loss (CRNN, [1; 2], [2; 4], 'Weights', {'a'}) ***** error ... loss (CRNN, [1; 2], [2; 4], 'Weights', ones (2, 2)) ***** error ... loss (CRNN, [1; 2], [2; 4], 'Weights', [1; 2; 3]) ***** error ... loss (CRNN, [1; 2], [2; 4], 'Nope', 1) ***** error ... savemodel (CRNN) ***** error ... savemodel (CRNN, 5) ***** error ... CRNN.ResponseTransform = 'nope'; ***** error ... CRNN.ResponseTransform = @(y) [y; y]; ***** test load fisheriris X = meas(:,2:4); Y = meas(:,1); Mdl = compact (fitrnet (X, Y, 'IterationLimit', 20)); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2), 'CompactRegressionNeuralNetwork'); assert_equal (M2.PredictorNames, Mdl.PredictorNames); assert_equal (class (M2.ResponseTransform), class (Mdl.ResponseTransform)); assert_equal (predict (M2, X(1:5,:)), predict (Mdl, X(1:5,:)), 1e-12); ***** test load fisheriris Mdl = compact (fitrnet (meas(:,2:4), meas(:,1))); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); T = {'identity', @(x) x; 'exp', @(x) exp (x); 'log', @(x) log (x)}; for i = 1:rows (T) Mdl.ResponseTransform = T{i,1}; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, T{i,2}(raw), 1e-12); endfor ***** test load fisheriris Mdl = compact (fitrnet (meas(:,2:4), meas(:,1))); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); Mdl.ResponseTransform = @(x) x .^ 2; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, raw .^ 2, 1e-12); ***** shared Xc, Dc, yr, yc, Xq, Dq k = (0:119)'; c1 = mod (k, 3) + 1; x2 = sin (k); c3 = 10 * (mod (floor (k / 2), 2) + 1); Xc = [c1, x2, c3]; Dc = [c1 == 1, c1 == 2, c1 == 3, x2, c3 == 10, c3 == 20]; yr = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 20) + 0.1 * cos (k); yc = yr > 1; Xq = [1, 0, 10; 2, 0.5, 20]; Dq = [1, 0, 0, 0, 1, 0; 0, 1, 0, 0.5, 0, 1]; ***** test # a compact model keeps the coding Full = fitrnet (Xc, yr, 'CategoricalPredictors', [1, 3], 'LayerSizes', 4); Mdl = compact (Full); assert_equal (predict (Mdl, [Xq; 4, 0, 10]), predict (Full, [Xq; 4, 0, 10])); fname = [tempname(), '.mdl']; savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (predict (M2, Xq), predict (Mdl, Xq)); ***** test # the levels a predictor was coded through travel with the model load fisheriris T = table (meas(:,2), meas(:,3), 'VariableNames', {'SW', 'PL'}); T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); T.SL = meas(:,1); CMdl = compact (fitrnet (T, 'SL')); assert_equal (numel (CMdl.PredictorLevels), 3); assert_equal (CMdl.PredictorLevels{3}, {'narrow', 'wide'}); ***** test # predict takes a table, read by name and not by position load fisheriris T = table (meas(:,2), meas(:,3), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'SL'}); CMdl = compact (fitrnet (T, 'SL')); a = predict (CMdl, T); assert_equal (numel (a), 150); assert_equal (predict (CMdl, T(:, [3, 2, 1])), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,2:3); y = meas(:,1); T = table (X(:,1), X(:,2), 'VariableNames', {'SW', 'PL'}); T.SL = y; Mdl = compact (fitrnet (T, 'SL')); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'SL'), a); assert_equal (loss (Mdl, T), a); 37 tests, 37 passed, 0 known failure, 0 skipped [inst/Machine_Learning/templateTree.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/templateTree.m ***** test # the default template names its learner and nothing else T = templateTree (); assert_equal (class (T), 'struct'); assert_equal (T.Method, 'Tree'); assert_equal (T.Type, 'classification'); assert_equal (numfields (T), 2); ***** test # an option given is stored under its own name, as it stands T = templateTree ('MaxNumSplits', 5, 'MinLeafSize', 3); assert_equal (numfields (T), 4); assert_equal (T.MaxNumSplits, 5); assert_equal (T.MinLeafSize, 3); ***** test # a name the learner does not know is not refused here T = templateTree ('NoSuchOption', 42); assert_equal (T.NoSuchOption, 42); ***** error ... templateTree ('KernelScale') ***** error ... templateTree (42, 1) ***** error ... templateTree ('not a name', 1) 6 tests, 6 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitrnet.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitrnet.m ***** demo ## 1. Predict fuel economy from engine power and weight load carsmall X = [Horsepower, Weight]; Mdl = fitrnet (X, MPG, 'Standardize', true, 'IterationLimit', 500); ## Rows carrying a missing value were dropped, so ask about the ones used used = Mdl.RowsUsed; yFit = predict (Mdl, X(used,:)); plot (MPG(used), yFit, 'o', [5, 45], [5, 45], 'k-'); axis equal; xlabel ('Observed MPG'); ylabel ('Predicted MPG'); title (sprintf ('Neural network fit, RMSE %.2f', sqrt (resubLoss (Mdl)))); ***** demo ## 2. Watching the fit converge load carsmall Mdl = fitrnet ([Horsepower, Weight], MPG, 'Standardize', true, ... 'IterationLimit', 400); ## TrainingHistory records the mean squared error at every iteration h = Mdl.TrainingHistory; semilogy (h.Iteration, h.TrainingLoss, 'linewidth', 1.5); xlabel ('Iteration'); ylabel ('Training MSE'); title ('The loss recorded is the network''s own, not a running average'); ***** demo ## 3. Standardizing matters when the predictors differ in scale ## Horsepower runs to a few hundred and Weight to a few thousand, so the ## heavier column dominates the first layer until both are put on one scale. load carsmall X = [Horsepower, Weight]; raw = fitrnet (X, MPG, 'IterationLimit', 400); std_ = fitrnet (X, MPG, 'Standardize', true, 'IterationLimit', 400); printf ('RMSE, raw predictors : %.2f\n', sqrt (resubLoss (raw))); printf ('RMSE, standardized : %.2f\n', sqrt (resubLoss (std_))); ***** demo ## 4. A network recovers a curve a straight line cannot rng (42); x = linspace (-3, 3, 120)'; y = sin (x) + randn (120, 1) * 0.1; Mdl = fitrnet (x, y, 'LayerSizes', [16, 16], 'IterationLimit', 800); plot (x, y, 'o', 'markersize', 4); hold on; plot (x, predict (Mdl, x), 'r-', 'linewidth', 2); plot (x, [ones(120,1), x] * ([ones(120,1), x] \ y), 'k--', 'linewidth', 1.5); hold off; legend ({'data', 'neural network', 'least squares line'}); title ('Two hidden layers of sixteen units'); ***** demo ## Fit from a table, and predict on one load fisheriris T = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ## A model formula names the response and the predictors together, and ## holds main effects only Mdl = fitrnet (T, 'SL ~ PL + Wide'); Mdl.PredictorNames Mdl.ResponseName Mdl.CategoricalPredictors ## predict matches the table's variables by name, so a column the model ## was not fitted on is passed over yFit = predict (Mdl, T(1:5,:)); yFit' ***** test rand ('seed', 42); X = linspace (-1, 1, 40)'; Y = 2 * X + 0.5; Mdl = fitrnet (X, Y, 'IterationLimit', 50); assert_equal (class (Mdl), 'RegressionNeuralNetwork'); assert_equal (numel (Mdl.LayerWeights), 2); assert_equal (size (Mdl.LayerWeights{1}), [10, 1]); assert_equal (size (Mdl.LayerBiases{1}), [10, 1]); assert_equal (size (Mdl.LayerWeights{2}), [1, 10]); assert_equal (size (Mdl.LayerBiases{2}), [1, 1]); ***** test rand ('seed', 42); X = linspace (0, 1, 30)'; Mdl = fitrnet (X, 3 * X, 'LayerSizes', [5, 5], 'Solver', 'sgd', ... 'LearningRate', 0.01, 'IterationLimit', 40, ... 'ResponseName', 'speed'); assert_equal (Mdl.LayerSizes, [5, 5]); assert_equal (Mdl.LearningRate, 0.01); assert_equal (Mdl.IterationLimit, 40); assert_equal (Mdl.ResponseName, 'speed'); ***** test rand ('seed', 42); load carsmall X = [Horsepower, Weight]; Mdl = fitrnet (X, MPG, 'Standardize', true, 'IterationLimit', 200); keep = ! isnan (MPG); assert_equal (Mdl.NumObservations, sum (keep)); assert_equal (Mdl.RowsUsed, keep); assert_equal (numel (resubPredict (Mdl)), sum (keep)); ***** error fitrnet () ***** error fitrnet (ones (4, 1)) ***** error ... fitrnet (ones (4, 2), ones (4, 1), 'LayerSizes') ***** error ... fitrnet (ones (4, 2), ones (3, 1)) ***** error ... fitrnet (ones (4, 2), ones (3, 1), 'LayerSizes', 2) ***** shared frnT load fisheriris frnT = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); frnT.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ***** test # the response is named by a column and the rest are predictors Mdl = fitrnet (frnT, 'SL'); assert_equal (Mdl.PredictorNames, {'SW', 'PL', 'PW', 'Wide'}); assert_equal (Mdl.ResponseName, 'SL'); assert_equal (Mdl.CategoricalPredictors, 4); ***** test # a model formula names the response and the predictors together Mdl = fitrnet (frnT, 'SL ~ PL + Wide'); assert_equal (Mdl.PredictorNames, {'PL', 'Wide'}); assert_equal (Mdl.CategoricalPredictors, 2); ***** test # the response may be given beside a table of predictors Mdl = fitrnet (frnT(:,1:3), frnT.SL); assert_equal (Mdl.PredictorNames, {'SW', 'PL', 'PW'}); assert_equal (Mdl.ResponseName, 'Y'); ***** test # predict takes a table, matched by name and not by position Mdl = fitrnet (frnT, 'SL'); a = predict (Mdl, frnT); assert_equal (numel (a), 150); assert_equal (predict (Mdl, frnT(:, [5, 4, 3, 2, 1])), a); ***** test # the levels travel with the model when it is made compact Mdl = fitrnet (frnT, 'SL'); CMdl = compact (Mdl); assert_equal (CMdl.PredictorLevels, Mdl.PredictorLevels); assert_equal (predict (CMdl, frnT), predict (Mdl, frnT)); ***** error ... fitrnet (frnT, 'NoSuch') ***** error ... fitrnet (frnT, 'SL ~ PL*PW') ***** error ... predict (fitrnet (frnT, 'SL'), frnT(:, [1, 3, 4, 5])) 16 tests, 16 passed, 0 known failure, 0 skipped [inst/Machine_Learning/ClassificationPartitionedECOC.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/ClassificationPartitionedECOC.m ***** test # MATLAB parity: the property surface of a cross-validated model load fisheriris c = cvpartition ('CustomPartition', repmat ((1:5)', 30, 1)); CV = fitcecoc (meas, species, 'Learners', 'tree', 'CVPartition', c); assert_equal (class (CV), 'ClassificationPartitionedECOC'); assert_equal (numel (properties (CV)), 20); assert_equal (CV.CrossValidatedModel, 'ECOC'); assert_equal (CV.KFold, 5); assert_equal (numel (CV.Trained), 5); assert_equal (class (CV.Trained{1}), 'CompactClassificationECOC'); ***** test # MATLAB parity: the out-of-fold answers of a discriminant code ## Measured on R2024a over a partition both engines are given outright. ## The learner is a discriminant and not a tree on purpose: a tree fitted ## on four fifths of this fixture has ties among its best splits, which ## the two engines break differently and which no test can pin. load fisheriris c = cvpartition ('CustomPartition', repmat ((1:5)', 30, 1)); CV = fitcecoc (meas, species, 'Learners', 'discriminant', 'CVPartition', c); assert_equal (kfoldLoss (CV), 0.0333333333333334, 1e-12); assert_equal (kfoldEdge (CV), 0.923697865527129, 1e-12); m = kfoldMargin (CV); assert_equal (m([1, 20, 51, 70, 101, 130])', ... [1, 1, 0.999820708981217, 0.999920781404916, ... 0.999999631930005, -0.0807626827878425], 1e-12); ***** test # MATLAB parity: the labels a tree code gives out of fold load fisheriris c = cvpartition ('CustomPartition', repmat ((1:5)', 30, 1)); CV = fitcecoc (meas, species, 'Learners', 'tree', 'CVPartition', c); [label, NegLoss] = kfoldPredict (CV); assert_equal (size (NegLoss), [150, 3]); assert_equal (sum (! strcmp (label, species)), 11); assert_equal (kfoldLoss (CV), 11/150, 1e-12); ***** test # every observation is answered by the fold that held it out load fisheriris c = cvpartition ('CustomPartition', repmat ((1:5)', 30, 1)); CV = fitcecoc (meas, species, 'Learners', 'discriminant', 'CVPartition', c); [label, NegLoss] = kfoldPredict (CV); assert_equal (any (cellfun (@isempty, label)), false); assert_equal (any (any (isnan (NegLoss))), false); ***** test # a character matrix response gives one out-of-fold label per row load fisheriris c = cvpartition ('CustomPartition', repmat ((1:5)', 30, 1)); CV = fitcecoc (meas, char (species), 'Learners', 'tree', 'CVPartition', c); [label, NegLoss] = kfoldPredict (CV); assert_equal (size (NegLoss), [150, 3]); assert_equal (sum (! strcmp (cellstr (label), species)), 11); ***** test # a holdout partition leaves the rows no fold tested unanswered load fisheriris CV = crossval (ClassificationECOC (meas, species, 'Learners', ... 'discriminant'), 'Holdout', 0.2); [label, NegLoss] = kfoldPredict (CV); assert_equal (sum (cellfun (@isempty, label)), 120); assert_equal (sum (all (isnan (NegLoss), 2)), 120); ***** test # the margin is positive exactly where the out-of-fold label was right load fisheriris c = cvpartition ('CustomPartition', repmat ((1:5)', 30, 1)); CV = fitcecoc (meas, species, 'Learners', 'discriminant', 'CVPartition', c); assert_equal (kfoldMargin (CV) > 0, strcmp (kfoldPredict (CV), species)); ***** test # kfoldfun is called once per fold and its rows are stacked load fisheriris c = cvpartition ('CustomPartition', repmat ((1:5)', 30, 1)); CV = fitcecoc (meas, species, 'Learners', 'discriminant', 'CVPartition', c); v = kfoldfun (CV, @(m, xt, yt, wt, xs, ys, ws) [rows(xt), rows(xs)]); assert_equal (v, [120, 30; 120, 30; 120, 30; 120, 30; 120, 30]); ***** test # crossval and the fit route give the same partitioned class load fisheriris c = cvpartition ('CustomPartition', repmat ((1:5)', 30, 1)); a = fitcecoc (meas, species, 'Learners', 'discriminant', 'CVPartition', c); b = crossval (ClassificationECOC (meas, species, 'Learners', ... 'discriminant'), 'CVPartition', c); assert_equal (kfoldLoss (a), kfoldLoss (b), 1e-12); ***** test # a categorical response gives categorical out-of-fold labels load fisheriris c = cvpartition ('CustomPartition', repmat ((1:5)', 30, 1)); a = fitcecoc (meas, species, 'Learners', 'tree', 'CVPartition', c); b = fitcecoc (meas, categorical (species), 'Learners', 'tree', ... 'CVPartition', c); label = kfoldPredict (b); assert_equal (class (label), 'categorical'); assert_equal (cellstr (label), kfoldPredict (a)); ***** error ... ClassificationPartitionedECOC (1) ***** error ... ClassificationPartitionedECOC (1, cvpartition (10, 'KFold', 2)) ***** error ... Mdl = ClassificationECOC (ones (4, 2), [1; 2; 1; 2]); ... ClassificationPartitionedECOC (Mdl, 1) ***** error ... y = [1; 2; 1; 2; 1; 2; 1; 2]; ... CV = crossval (ClassificationECOC (ones (8, 2), y), 'KFold', 2); ... kfoldLoss (CV, 'LossFun') ***** error ... y = [1; 2; 1; 2; 1; 2; 1; 2]; ... CV = crossval (ClassificationECOC (ones (8, 2), y), 'KFold', 2); ... kfoldLoss (CV, 'Bogus', 1) ***** error ... y = [1; 2; 1; 2; 1; 2; 1; 2]; ... CV = crossval (ClassificationECOC (ones (8, 2), y), 'KFold', 2); ... kfoldfun (CV, 1) 16 tests, 16 passed, 0 known failure, 0 skipped [inst/Machine_Learning/CompactClassificationECOC.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/CompactClassificationECOC.m ***** test # MATLAB parity: the property surface of a compact model load fisheriris CMdl = compact (fitcecoc (meas, species)); assert_equal (class (CMdl), 'CompactClassificationECOC'); assert_equal (numel (properties (CMdl)), 12); assert_equal (CMdl.ClassNames, unique (species)); assert_equal (CMdl.CodingMatrix, [1, 1, 0; -1, 0, 1; 0, -1, -1]); ***** test # MATLAB parity: the three outputs of predict load fisheriris CMdl = compact (fitcecoc (meas, species, 'Learners', 'tree')); [label, NegLoss, PBScore] = predict (CMdl, meas([1, 51, 101], :)); assert_equal (label, {'setosa'; 'versicolor'; 'virginica'}); assert_equal (size (NegLoss), [3, 3]); assert_equal (size (PBScore), [3, 3]); ***** test # MATLAB parity: the decoding of a tree code, both schemes ## Measured on R2024a, whose trees this package reproduces on this ## fixture, so the whole path is compared and not only the labels. load fisheriris CMdl = compact (fitcecoc (meas, species, 'Learners', 'tree')); r = [1, 20, 51, 70, 101, 130]; [~, W] = predict (CMdl, meas(r,:), 'Decoding', 'lossweighted'); assert_equal (W, ... [0, -1, -2; ... 0, -1, -2; ... -2, 0, -1; ... -2, 0, -1; ... -2, -0.956994328922495, -0.000472589792060491; ... -2, -0.444444444444445, -0.111111111111111], 1e-12); [~, B] = predict (CMdl, meas(r,:), 'Decoding', 'lossbased'); assert_equal (B(1,:), [-0.166666666666667, -0.833333333333333, ... -1.5], 1e-12); ***** test # lossweighted is the default decoding load fisheriris CMdl = compact (fitcecoc (meas, species)); [~, a] = predict (CMdl, meas(1:5,:)); [~, b] = predict (CMdl, meas(1:5,:), 'Decoding', 'lossweighted'); assert_equal (a, b); ***** test # MATLAB parity: the edge is the weighted mean of the margins load fisheriris CMdl = compact (fitcecoc (meas, species, 'Learners', 'tree')); m = margin (CMdl, meas, species); assert_equal (edge (CMdl, meas, species), mean (m), 1e-12); ***** test # loss counts the labels it got wrong load fisheriris CMdl = compact (fitcecoc (meas, species, 'Learners', 'tree')); assert_equal (loss (CMdl, meas, species), 0.02, 1e-12); assert_equal (loss (CMdl, meas, species, 'LossFun', 'classiferror'), ... 0.02, 1e-12); ***** test # a binary loss the learners cannot be read with is refused load fisheriris CMdl = compact (fitcecoc (meas, species)); assert_equal (CMdl.BinaryLoss, 'hinge'); CMdl.BinaryLoss = 'logit'; assert_equal (CMdl.BinaryLoss, 'logit'); ***** test # discarding support vectors changes nothing the model answers ## The linear model stands in for the vectors exactly, so the labels and ## the loss are what they were and only the memory is gone. load fisheriris Mdl = compact (fitcecoc (meas, species)); assert_equal (size (Mdl.BinaryLearners{1}.SupportVectors), [3, 4]); D = discardSupportVectors (Mdl); assert_equal (class (D), 'CompactClassificationECOC'); assert_equal (size (D.BinaryLearners{1}.SupportVectors), [0, 0]); assert_equal (isempty (D.BinaryLearners{1}.Alpha), true); assert_equal (predict (D, meas), predict (Mdl, meas)); assert_equal (loss (D, meas, species), 0.0066666666666667, 1e-12); ***** warning ... load fisheriris; ... M = fitcecoc (meas, species, 'Learners', 'tree'); ... discardSupportVectors (compact (M)); ***** test # a code of trees is returned unchanged by discardSupportVectors load fisheriris Mdl = compact (fitcecoc (meas, species, 'Learners', 'tree')); ## The state is saved and put back rather than switched on: 'on' would ## enable warning classes Octave disables by default and leak them into ## every test that runs after this one. w = warning ('off', 'all'); D = discardSupportVectors (Mdl); warning (w); assert_equal (predict (D, meas), predict (Mdl, meas)); ***** test # selectModels narrows every binary learner to the same strengths load fisheriris L = fitcecoc (meas, species, ... 'Learners', templateLinear ('Lambda', [1e-4, 1e-3, 1e-2])); LC = L; assert_equal (LC.BinaryLearners{1}.Lambda, [1e-4, 1e-3, 1e-2], 1e-12); S = selectModels (LC, 2); assert_equal (class (S), 'CompactClassificationECOC'); for j = 1:numel (S.BinaryLearners) assert_equal (S.BinaryLearners{j}.Lambda, 1e-3, 1e-12); endfor ***** test # A row missing a predictor takes the class of largest prior X = [(1:12)', mod((1:12)', 3)]; y = [1; 1; 1; 1; 1; 2; 2; 2; 2; 3; 3; 3]; [label, NegLoss] = predict (compact (fitcecoc (X, y)), [NaN, 1]); assert_equal (label, 1); assert_equal (NegLoss, [NaN, NaN, NaN]); Mdl = compact (fitcecoc (X, y, 'Prior', [0.2, 0.2, 0.6])); assert_equal (predict (Mdl, [NaN, 1]), 3); ***** error ... load fisheriris; ... selectModels (compact (fitcecoc (meas, species))) ***** error ... load fisheriris; ... selectModels (compact (fitcecoc (meas, species, 'Learners', 'tree')), 1) ***** shared CMdl CMdl = compact (fitcecoc (ones (4, 2), [1; 2; 1; 2])); ***** error ... predict (CMdl) ***** error ... predict (CMdl, ones (1, 2), 'Decoding') ***** error ... predict (CMdl, ones (1, 2), 'Decoding', 'nosuch') ***** error ... predict (CMdl, ones (1, 2), 'Bogus', 1) ***** error ... predict (CMdl, ones (1, 2), 'BinaryLoss', 'quadratic') ***** error ... CMdl.BinaryLoss = 'quadratic'; ***** error ... margin (CMdl, ones (1, 2)) ***** error ... loss (CMdl, ones (1, 2)) ***** test # the levels travel with the model, and predict reads a table by name load fisheriris T = table (meas(:,1), meas(:,2), 'VariableNames', {'SL', 'SW'}); T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); T.Species = categorical (species); Mdl = fitcecoc (T, 'Species'); CMdl = compact (Mdl); assert_equal (CMdl.PredictorLevels, Mdl.PredictorLevels); assert_equal (predict (CMdl, T(:, [4, 3, 2, 1])), predict (CMdl, T)); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcecoc (T, 'Species')); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcecoc (T, 'Species')); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcecoc (T, 'Species')); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** error ... loss (compact (fitcecoc ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2])), ... [1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', int8 ([1; 1; 1; 1])) 27 tests, 27 passed, 0 known failure, 0 skipped [inst/Machine_Learning/shapley.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/shapley.m ***** demo ## Explain a model fitted from a table load fisheriris T = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); Mdl = fitrtree (T, 'SL'); ## The observations and the query points may be tables too, read by the ## names the model was fitted on rather than by the order of the columns s = shapley (Mdl, T(:, [1, 2, 3, 5]), 'QueryPoints', T(1, [5, 3, 2, 1]), ... 'NumObservationsToSample', 'all'); s.Shapley ## A column the model was not fitted on is passed over, so the whole ## table, response and all, gives the same explanation t = shapley (Mdl, T, 'QueryPoints', T(1,:), ... 'NumObservationsToSample', 'all'); isequal (t.Shapley.Value, s.Shapley.Value) ***** test X = [1, 10; 2, 20; 3, 30; 4, 45]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2); s = shapley (f, X, 'QueryPoints', [3, 20], ... 'NumObservationsToSample', 'all'); b = [2, -3]; q = [3, 20]; assert_equal (s.Shapley.Value, (b .* (q - mean (X)))', 1e-12); ***** test # the values sum to the deviation of the prediction from the average X = [1, 10; 2, 20; 3, 30; 4, 45]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2); s = shapley (f, X, 'QueryPoints', [3, 20], ... 'NumObservationsToSample', 'all'); assert_equal (sum (s.Shapley.Value), f ([3, 20]) - s.Intercept, 1e-12); ***** test # the intercept is the average prediction over the observations X = [1, 10; 2, 20; 3, 30; 4, 45]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2); s = shapley (f, X, 'QueryPoints', [3, 20], ... 'NumObservationsToSample', 'all'); assert_equal (s.Intercept, mean (f (X)), 1e-12); ***** test # every subset is used, so the count is two to the predictors X = [1, 10; 2, 20; 3, 30; 4, 45]; f = @(Z) Z(:,1); s = shapley (f, X); assert_equal (s.NumSubsets, 4); ***** test # a predictor the function ignores contributes nothing X = [1, 10; 2, 20; 3, 30; 4, 45]; f = @(Z) Z(:,1); s = shapley (f, X, 'QueryPoints', [3, 20], ... 'NumObservationsToSample', 'all'); assert_equal (s.Shapley.Value(2), 0, 1e-12); ***** test # the algorithm is reported X = [1, 10; 2, 20; 3, 30; 4, 45]; s = shapley (@(Z) Z(:,1), X); assert_equal (s.Method, 'interventional-kernel'); ***** test # a handle names its predictors as MATLAB does X = [1, 10; 2, 20; 3, 30; 4, 45]; s = shapley (@(Z) Z(:,1), X, 'QueryPoints', [3, 20]); assert_equal (cellstr (s.Shapley.Predictor), {'x1'; 'x2'}); ***** test # the table names its one value variable as MATLAB R2026a does X = [1, 10; 2, 20; 3, 30; 4, 45]; s = shapley (@(Z) Z(:,1), X, 'QueryPoints', [3, 20]); assert_equal (s.Shapley.Properties.VariableNames, {'Predictor', 'Value'}); ***** test # one column of values per query point X = [1, 10; 2, 20; 3, 30; 4, 45]; s = shapley (@(Z) Z(:,1), X, 'QueryPoints', [3, 20; 2, 30], ... 'NumObservationsToSample', 'all'); assert_equal (size (s.Shapley.Value), [2, 2]); ***** test # with one query point the mean absolute value is the absolute value X = [1, 10; 2, 20; 3, 30; 4, 45]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2); s = shapley (f, X, 'QueryPoints', [3, 20], ... 'NumObservationsToSample', 'all'); assert_equal (s.MeanAbsoluteShapley.Value, abs (s.Shapley.Value), 1e-12); ***** test # fit replaces the query points rather than adding to them X = [1, 10; 2, 20; 3, 30; 4, 45]; s = shapley (@(Z) Z(:,1), X, 'QueryPoints', [3, 20; 2, 30]); s = fit (s, [1, 10]); assert_equal (s.QueryPoints, [1, 10]); assert_equal (size (s.Shapley.Value), [2, 1]); ***** test # 'all' averages over every row, and says which ones X = [1, 10; 2, 20; 3, 30; 4, 45]; s = shapley (@(Z) Z(:,1), X, 'NumObservationsToSample', 'all'); assert_equal (s.SampledObservationIndices, (1:4)'); ***** test # a sample of the observations is drawn without replacement X = (1:200)'; X = [X, 2 * X]; s = shapley (@(Z) Z(:,1), X); assert_equal (numel (s.SampledObservationIndices), 100); assert_equal (numel (unique (s.SampledObservationIndices)), 100); ***** test # a handle answers what it was asked at the query points X = [1, 10; 2, 20; 3, 30; 4, 45]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2); s = shapley (f, X, 'QueryPoints', [3, 20]); assert_equal (s.BlackboxFitted, f ([3, 20]), 1e-12); ***** test # a model supplies the observations it was fitted on load fisheriris Mdl = fitrtree (meas(:,2:4), meas(:,1)); s = shapley (Mdl, 'NumObservationsToSample', 'all'); assert_equal (size (s.X), [150, 3]); ***** test # and its own predictor names load fisheriris Mdl = fitrtree (meas(:,2:4), meas(:,1), ... 'PredictorNames', {'a', 'b', 'c'}); s = shapley (Mdl, 'QueryPoints', meas(1,2:4), ... 'NumObservationsToSample', 'all'); assert_equal (cellstr (s.Shapley.Predictor), {'a'; 'b'; 'c'}); ***** test # a classifier names one variable per class load fisheriris Mdl = fitctree (meas, species); s = shapley (Mdl, 'QueryPoints', meas(1,:), ... 'NumObservationsToSample', 'all'); assert_equal (s.Shapley.Properties.VariableNames, ... {'Predictor', 'setosa', 'versicolor', 'virginica'}); ***** test # the two classes of a binary classifier are exact negatives load fisheriris Mdl = fitctree (meas(51:150,:), species(51:150)); s = shapley (Mdl, 'QueryPoints', meas(51,:), ... 'NumObservationsToSample', 'all'); assert_equal (s.Shapley.versicolor, -s.Shapley.virginica, 1e-12); ***** test # a classifier's values sum to the deviation of its scores load fisheriris Mdl = fitctree (meas, species); s = shapley (Mdl, 'QueryPoints', meas(1,:), ... 'NumObservationsToSample', 'all'); [~, sc] = predict (Mdl, meas(1,:)); v = [s.Shapley.setosa, s.Shapley.versicolor, s.Shapley.virginica]; assert_equal (sum (v, 1), sc - s.Intercept, 1e-12); ***** test load fisheriris Mdl = fitctree (meas, species); s = shapley (Mdl, 'QueryPoints', meas(1,:), ... 'NumObservationsToSample', 'all'); v = [s.Shapley.setosa, s.Shapley.versicolor, s.Shapley.virginica]; assert_equal (v, [0, 0, 0; 0, 0, 0; ... 0.666666666666667, -0.397777777777778, ... -0.268888888888889; ... 0, 0.0644444444444445, -0.0644444444444444], 1e-12); ***** test load fisheriris Mdl = fitcknn (meas, species); s = shapley (Mdl, 'QueryPoints', meas(1,:), ... 'NumObservationsToSample', 'all'); v = [s.Shapley.setosa, s.Shapley.versicolor, s.Shapley.virginica]; assert_equal (v, [0, -0.000555555555555559, 0.000555555555555538; ... 0.00111111111111099, 0.0283333333333334, ... -0.0294444444444444; ... 0.664444444444445, -0.433888888888889, ... -0.230555555555556; ... 0.00111111111111106, 0.0727777777777778, ... -0.0738888888888889], 1e-12); ***** test X = [1, 10; 2, 20; 3, 30; 4, 45]; s = shapley (@(Z) Z(:,1), X, 'MaxNumSubsets', 100); assert_equal (s.NumSubsets, 4); ***** test # a wide model takes MATLAB's default budget X = repmat ((1:20)', 1, 16); s = shapley (@(Z) Z(:,1), X); assert_equal (s.NumSubsets, 1024); ***** test # the weighted least squares reproduces the exact values on a linear # function, which it fits with no residual whatever subsets it is given X = [1, 10, 2; 2, 20, 5; 3, 30, 1; 4, 45, 7]; b = [2, -3, 5]; f = @(Z) Z * b'; q = [3, 20, 4]; s = shapley (f, X, 'QueryPoints', q, 'MaxNumSubsets', 6, ... 'NumObservationsToSample', 'all'); assert_equal (s.Shapley.Value, (b .* (q - mean (X)))', 1e-10); warning: shapley.fit: the values may be unreliable because 'MaxNumSubsets' is too small. warning: called from fit at line 435 column 13 shapley at line 351 column 9 __test__ at line 8 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 4110 column 2 ***** test # and a budget short of every subset still sums to the deviation load fisheriris Mdl = fitcknn (meas, species); s = shapley (Mdl, 'QueryPoints', meas(1,:), 'MaxNumSubsets', 10, ... 'NumObservationsToSample', 'all'); [~, sc] = predict (Mdl, meas(1,:)); v = [s.Shapley.setosa, s.Shapley.versicolor, s.Shapley.virginica]; assert_equal (sum (v, 1), sc - s.Intercept, 1e-10); ***** test # a budget of every subset agrees with the exact enumeration load fisheriris Mdl = fitcknn (meas, species); s = shapley (Mdl, 'QueryPoints', meas(1,:), ... 'NumObservationsToSample', 'all'); assert_equal (s.Shapley.setosa(3), 0.664444444444445, 1e-12); ***** test load fisheriris Mdl = fitcknn (meas, species); s = shapley (Mdl, 'QueryPoints', meas(1,:), 'MaxNumSubsets', 12, ... 'NumObservationsToSample', 'all'); v = [s.Shapley.setosa, s.Shapley.versicolor, s.Shapley.virginica]; assert_equal (v, [0.000555555555556, -0.007777777777778, ... 0.007222222222222; ... 0.000555555555556, 0.035555555555556, ... -0.036111111111111; ... 0.664444444444444, -0.435555555555555, ... -0.228888888888889; ... 0.001111111111111, 0.074444444444445, ... -0.075555555555555], 1e-12); ***** test load fisheriris X5 = [meas, meas(:,1) .* meas(:,4)]; Mdl = fitcknn (X5, species); s = shapley (Mdl, 'QueryPoints', X5(1,:), 'MaxNumSubsets', 24, ... 'NumObservationsToSample', 'all'); assert_equal (s.Shapley.setosa', ... [0.000625, 0.002239583333333, 0.003510416666667, ... 0.002843750000000, 0.657447916666667], 1e-12); ***** test t = (1:101)'; X = [t, mod(t * 37, 101), mod(t * 53, 101)]; s = shapley (@(Z) Z(:,1), X, 'QueryPoints', [10, 50, 90], ... 'Method', 'conditional', 'NumObservationsToSample', 'all'); assert_equal (s.Shapley.Value', [-45.560606060606048, ... 1.621212121212129, 2.939393939393916], 1e-10); ***** test load fisheriris Mdl = fitcknn (meas, species); s = shapley (Mdl, 'QueryPoints', meas(1,:), 'Method', 'conditional', ... 'NumObservationsToSample', 'all'); v = [s.Shapley.setosa, s.Shapley.versicolor, s.Shapley.virginica]; assert_equal (v, [0.15, -0.0666666666666667, -0.0833333333333334; ... 0.172222222222222, -0.0888888888888889, ... -0.0833333333333333; ... 0.172222222222222, -0.0888888888888889, ... -0.0833333333333333; ... 0.172222222222222, -0.0888888888888889, ... -0.0833333333333334], 1e-12); ***** test # conditioning is reported as its own algorithm X = [1, 10; 2, 20; 3, 30; 4, 45]; s = shapley (@(Z) Z(:,1), X, 'Method', 'conditional'); assert_equal (s.Method, 'conditional-kernel'); ***** test # and still sums to the deviation of the prediction from the average t = (1:100)'; X = [t, mod(t * 37, 101), mod(t * 53, 101)]; f = @(Z) Z(:,1); s = shapley (f, X, 'QueryPoints', [10, 50, 90], ... 'Method', 'conditional', 'NumObservationsToSample', 'all'); assert_equal (sum (s.Shapley.Value), f ([10, 50, 90]) - s.Intercept, 1e-10); ***** test # a predictor recorded on a wider scale does not pull the neighbours t = (1:100)'; X = [t, mod(t * 37, 101), mod(t * 53, 101)]; W = X; W(:,2) = W(:,2) * 1000; s = shapley (@(Z) Z(:,1), X, 'QueryPoints', [10, 50, 90], ... 'Method', 'conditional', 'NumObservationsToSample', 'all'); r = shapley (@(Z) Z(:,1), W, 'QueryPoints', [10, 50000, 90], ... 'Method', 'conditional', 'NumObservationsToSample', 'all'); assert_equal (r.Shapley.Value, s.Shapley.Value, 1e-10); ***** test # nothing but the two extremes says nothing about any one predictor X = [1, 10; 2, 20; 3, 30; 4, 45]; s = shapley (@(Z) Z(:,1), X, 'QueryPoints', [3, 20], ... 'MaxNumSubsets', 2, 'NumObservationsToSample', 'all'); assert_equal (s.Shapley.Value, [NaN; NaN]); warning: shapley.fit: the values may be unreliable because 'MaxNumSubsets' is too small. warning: called from fit at line 435 column 13 shapley at line 351 column 9 __test__ at line 4 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 4110 column 2 ***** test # a model predicting a weighted sum is answered from the weights load fisheriris Mdl = fitrlinear (meas(:,2:4), meas(:,1)); s = shapley (Mdl, meas(:,2:4), 'QueryPoints', meas(1,2:4), ... 'NumObservationsToSample', 'all'); assert_equal (s.Method, 'interventional-linear'); ***** test # and gives what the subsets would have given load fisheriris Mdl = fitrlinear (meas(:,2:4), meas(:,1)); s = shapley (Mdl, meas(:,2:4), 'QueryPoints', meas(1,2:4), ... 'NumObservationsToSample', 'all'); k = shapley (Mdl, meas(:,2:4), 'QueryPoints', meas(1,2:4), ... 'MaxNumSubsets', 8, 'NumObservationsToSample', 'all'); assert_equal (s.Shapley.Value, k.Shapley.Value, 1e-10); warning: shapley: 'MaxNumSubsets' is given, so the values are taken over subsets rather than from the structure of the model. warning: called from shapAlgorithm at line 974 column 5 shapley at line 338 column 7 __test__ at line 7 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 4110 column 2 ***** test # which is each weight times the deviation of its predictor load fisheriris Mdl = fitrlinear (meas(:,2:4), meas(:,1)); s = shapley (Mdl, meas(:,2:4), 'QueryPoints', meas(1,2:4), ... 'NumObservationsToSample', 'all'); assert_equal (s.Shapley.Value, ... Mdl.Beta(:) .* (meas(1,2:4) - mean (meas(:,2:4)))', 1e-10); ***** test # a support vector machine on any other kernel keeps no such weights load fisheriris Mdl = fitrsvm (meas(:,2:4), meas(:,1), 'KernelFunction', 'gaussian'); s = shapley (Mdl, meas(:,2:4), 'QueryPoints', meas(1,2:4), ... 'NumObservationsToSample', 'all'); assert_equal (s.Method, 'interventional-kernel'); ***** test load fisheriris Mdl = fitcsvm (meas(51:150,:), species(51:150), ... 'ScoreTransform', 'logit'); s = shapley (Mdl, meas(51:150,:), 'QueryPoints', meas(51,:), ... 'NumObservationsToSample', 'all'); assert_equal (s.Method, 'interventional-kernel'); [~, sc] = predict (Mdl, meas(51,:)); v = [s.Shapley.versicolor, s.Shapley.virginica]; assert_equal (sum (v, 1), sc - s.Intercept, 1e-10); ***** test # asking for a budget of subsets asks for the subsets load fisheriris Mdl = fitrlinear (meas(:,2:4), meas(:,1)); s = shapley (Mdl, meas(:,2:4), 'QueryPoints', meas(1,2:4), ... 'MaxNumSubsets', 8, 'NumObservationsToSample', 'all'); assert_equal (s.Method, 'interventional-kernel'); warning: shapley: 'MaxNumSubsets' is given, so the values are taken over subsets rather than from the structure of the model. warning: called from shapAlgorithm at line 974 column 5 shapley at line 338 column 7 __test__ at line 5 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 4110 column 2 ***** test # a decision tree is answered leaf by leaf load fisheriris Mdl = fitrtree (meas(:,2:4), meas(:,1)); s = shapley (Mdl, 'QueryPoints', meas(1,2:4), ... 'NumObservationsToSample', 'all'); assert_equal (s.Method, 'interventional-tree'); ***** test # and gives what the subsets would have given load fisheriris Mdl = fitrtree (meas(:,2:4), meas(:,1)); s = shapley (Mdl, 'QueryPoints', meas(1,2:4), ... 'NumObservationsToSample', 'all'); k = shapley (Mdl, meas(:,2:4), 'QueryPoints', meas(1,2:4), ... 'MaxNumSubsets', 8, 'NumObservationsToSample', 'all'); assert_equal (s.Shapley.Value, k.Shapley.Value, 1e-10); warning: shapley: 'MaxNumSubsets' is given, so the values are taken over subsets rather than from the structure of the model. warning: called from shapAlgorithm at line 974 column 5 shapley at line 338 column 7 __test__ at line 7 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 4110 column 2 ***** test # for a classifier too, one column of values per class load fisheriris Mdl = fitctree (meas, species); s = shapley (Mdl, 'QueryPoints', meas(1,:), ... 'NumObservationsToSample', 'all'); k = shapley (Mdl, meas, 'QueryPoints', meas(1,:), ... 'MaxNumSubsets', 16, 'NumObservationsToSample', 'all'); assert_equal (s.Shapley.versicolor, k.Shapley.versicolor, 1e-10); warning: shapley: 'MaxNumSubsets' is given, so the values are taken over subsets rather than from the structure of the model. warning: called from shapAlgorithm at line 974 column 5 shapley at line 338 column 7 __test__ at line 7 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 4110 column 2 ***** test # and for a compact one, which keeps the nodes and not the data load fisheriris Mdl = compact (fitctree (meas, species)); s = shapley (Mdl, meas, 'QueryPoints', meas(1,:), ... 'NumObservationsToSample', 'all'); k = shapley (Mdl, meas, 'QueryPoints', meas(1,:), ... 'MaxNumSubsets', 16, 'NumObservationsToSample', 'all'); assert_equal (s.Shapley.setosa, k.Shapley.setosa, 1e-10); warning: shapley: 'MaxNumSubsets' is given, so the values are taken over subsets rather than from the structure of the model. warning: called from shapAlgorithm at line 974 column 5 shapley at line 338 column 7 __test__ at line 7 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 4110 column 2 ***** test # a cut on the levels of a categorical predictor is followed too t = (1:120)'; X = [mod(t, 4), double(t), mod(t * 7, 11)]; y = 3 * (X(:,1) == 1) - 2 * (X(:,1) == 3) + 0.01 * mod (t, 5); Mdl = fitrtree (X, y, 'CategoricalPredictors', 1); s = shapley (Mdl, 'QueryPoints', X(3,:), ... 'NumObservationsToSample', 'all'); k = shapley (Mdl, X, 'QueryPoints', X(3,:), 'MaxNumSubsets', 8, ... 'NumObservationsToSample', 'all'); assert_equal (s.Shapley.Value, k.Shapley.Value, 1e-10); warning: shapley: 'MaxNumSubsets' is given, so the values are taken over subsets rather than from the structure of the model. warning: called from shapAlgorithm at line 974 column 5 shapley at line 338 column 7 __test__ at line 9 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 4110 column 2 ***** test # a tree is exact however many predictors it has, where the subsets # would have stopped at the budget of 1024 rand ('seed', 7); randn ('seed', 7); X = randn (200, 14); y = X(:,1) + 2 * X(:,5) - X(:,9); Mdl = fitrtree (X, y); s = shapley (Mdl, 'QueryPoints', X(1,:), ... 'NumObservationsToSample', 'all'); assert_equal (s.Method, 'interventional-tree'); assert_equal (sum (s.Shapley.Value), ... predict (Mdl, X(1,:)) - s.Intercept, 1e-10); ***** test load fisheriris Mdl = fitctree (meas(51:150,:), species(51:150), ... 'ScoreTransform', 'logit'); s = shapley (Mdl, 'QueryPoints', meas(51,:), ... 'NumObservationsToSample', 'all'); assert_equal (s.Method, 'interventional-tree'); [~, sc] = predict (Mdl, meas(51,:)); v = [s.Shapley.versicolor, s.Shapley.virginica]; assert_equal (sum (v, 1), sc - s.Intercept, 1e-10); ***** test # asking for a budget of subsets asks for the subsets load fisheriris Mdl = fitrtree (meas(:,2:4), meas(:,1)); s = shapley (Mdl, meas(:,2:4), 'QueryPoints', meas(1,2:4), ... 'MaxNumSubsets', 8, 'NumObservationsToSample', 'all'); assert_equal (s.Method, 'interventional-kernel'); warning: shapley: 'MaxNumSubsets' is given, so the values are taken over subsets rather than from the structure of the model. warning: called from shapAlgorithm at line 974 column 5 shapley at line 338 column 7 __test__ at line 5 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 4110 column 2 ***** test # an ensemble of trees is walked leaf by leaf, as one tree is rand ('seed', 11); randn ('seed', 11); X = randn (60, 11); y = X(:,1) + 2 * X(:,2) - X(:,3); Mdl = fitrensemble (X, y, 'Method', 'Bag', 'NumLearningCycles', 4); s = shapley (Mdl, 'QueryPoints', X(1,:), ... 'NumObservationsToSample', 'all'); k = shapley (Mdl, X, 'QueryPoints', X(1,:), 'MaxNumSubsets', 2048, ... 'NumObservationsToSample', 'all'); assert_equal (s.Method, 'interventional-tree'); assert_equal (s.Shapley.Value, k.Shapley.Value, 1e-10); warning: shapley: 'MaxNumSubsets' is given, so the values are taken over subsets rather than from the structure of the model. warning: called from shapAlgorithm at line 974 column 5 shapley at line 338 column 7 __test__ at line 10 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 4110 column 2 ***** test # and a classifier's, where a learner's classes are put where the # ensemble keeps them rand ('seed', 11); randn ('seed', 11); X = randn (60, 11); g = repmat ({'a'; 'b'}, 30, 1); Mdl = fitcensemble (X, g, 'Method', 'Bag', 'NumLearningCycles', 4); s = shapley (Mdl, 'QueryPoints', X(1,:), ... 'NumObservationsToSample', 'all'); k = shapley (Mdl, X, 'QueryPoints', X(1,:), 'MaxNumSubsets', 2048, ... 'NumObservationsToSample', 'all'); assert_equal (s.Method, 'interventional-tree'); assert_equal (s.Shapley.a, k.Shapley.a, 1e-10); warning: shapley: 'MaxNumSubsets' is given, so the values are taken over subsets rather than from the structure of the model. warning: called from shapAlgorithm at line 974 column 5 shapley at line 338 column 7 __test__ at line 11 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 4110 column 2 ***** test # a narrow ensemble is walked too, and agrees with every subset load fisheriris Mdl = fitcensemble (meas, species, 'Method', 'Bag', ... 'NumLearningCycles', 10); s = shapley (Mdl, 'QueryPoints', meas(1,:), ... 'NumObservationsToSample', 'all'); k = shapley (Mdl, meas, 'QueryPoints', meas(1,:), 'MaxNumSubsets', 16, ... 'NumObservationsToSample', 'all'); assert_equal (s.Method, 'interventional-tree'); assert_equal (s.Shapley.setosa, k.Shapley.setosa, 1e-10); warning: shapley: 'MaxNumSubsets' is given, so the values are taken over subsets rather than from the structure of the model. warning: called from shapAlgorithm at line 974 column 5 shapley at line 338 column 7 __test__ at line 8 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 4110 column 2 ***** test # a boosting method reading a learner's label, not its scores, too rand ('seed', 3); randn ('seed', 3); X = randn (60, 11); g = repmat ({'a'; 'b'}, 30, 1); Mdl = fitcensemble (X, g, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 4); s = shapley (Mdl, 'QueryPoints', X(1,:), ... 'NumObservationsToSample', 'all'); assert_equal (s.Method, 'interventional-kernel'); ***** test # a classifier's fitted label keeps the type of the response load fisheriris Mdl = fitctree (meas, species); s = shapley (Mdl, 'QueryPoints', meas(1,:), ... 'NumObservationsToSample', 'all'); assert_equal (s.BlackboxFitted, predict (Mdl, meas(1,:))); ***** error shapley () ***** error shapley (42) ***** error shapley (@(Z) Z(:,1)) ***** error shapley (@(Z) Z(:,1), {1, 2}) ***** error shapley (@(Z) Z(:,1), [1, 2; 3, 4], 'UseParallel', true) ***** error shapley (@(Z) Z(:,1), [1, 2; 3, 4], 'MaxNumSubsets', 1) ***** error shapley (@(Z) Z(:,1), [1, 2; 3, 4], 'MaxNumSubsets', 2.5) ***** error shapley (@(Z) Z(:,1), [1, 2; 3, 4], 'Method', 'marginal') ***** error shapley (@(Z) Z(:,1), [1, 2; 3, 4], 'NumObservationsToSample', 0) ***** error shapley (@(Z) Z(:,1), [1, 2; 3, 4], 'NoSuchThing', 1) ***** error fit (shapley (@(Z) Z(:,1), [1, 2; 3, 4]), 'abc') ***** error fit (shapley (@(Z) Z(:,1), [1, 2; 3, 4]), [1, 2, 3]) ***** test # one query point: one bar per predictor, the least important first X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect b = plot (s); assert_equal (numel (b), 1); assert_equal (get (b, 'horizontal'), 'on'); assert_equal (get (b, 'ydata')', [-2.8333333333333333, -5, 80], 1e-12); assert_equal (get (gca (), 'yticklabel')', {'x3', 'x1', 'x2'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # one query point is titled as an explanation of that point X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect plot (s); ax = gca (); assert_equal (get (get (ax, 'title'), 'string'), 'Shapley Explanation'); assert_equal (get (get (ax, 'xlabel'), 'string'), 'Shapley Value'); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Predictor'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1:4,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect b = plot (s); ax = gca (); assert_equal (get (get (ax, 'title'), 'string'), ... 'Shapley Importance Plot'); assert_equal (get (get (ax, 'xlabel'), 'string'), ... 'Mean of Absolute Shapley Values'); assert_equal (get (b, 'ydata')', [2.5, 2.75, 43.75], 1e-12); assert_equal (get (ax, 'yticklabel')', {'x1', 'x3', 'x2'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1:4,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect b = plot (s, 'NumImportantPredictors', 2); assert_equal (get (b, 'ydata')', [2.5, 2.75, 43.75], 1e-12); assert_equal (get (gca (), 'yticklabel')', ... {'Sum of other 1 predictor(s)', 'x3', 'x2'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # over one query point it is left out rather than summed X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect b = plot (s, 'NumImportantPredictors', 2); assert_equal (get (b, 'ydata')', [-5, 80], 1e-12); assert_equal (get (gca (), 'yticklabel')', {'x1', 'x2'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # naming one query point explains that point rather than summarising X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1:4,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect b = plot (s, 'QueryPointIndices', 2); ax = gca (); assert_equal (get (get (ax, 'title'), 'string'), 'Shapley Explanation'); assert_equal (get (b, 'ydata')', [2.1666666666666667, -3, 50], 1e-12); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # the axes to draw into may be given first, as for any plot X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect a1 = subplot (1, 2, 1); a2 = subplot (1, 2, 2); b = plot (a2, s); assert_equal (get (b, 'parent'), a2); assert_equal (isempty (get (a1, 'children')), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** test load fisheriris Mdl = fitcknn (meas, species); s = shapley (Mdl, 'QueryPoints', meas(1,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect b = plot (s); assert_equal (numel (b), 1); assert_equal (s.BlackboxFitted, {'setosa'}); assert_equal (sort (get (b, 'ydata')'), sort (s.Shapley.setosa'), 1e-12); unwind_protect_cleanup close (hf); end_unwind_protect ***** test load fisheriris Mdl = fitcknn (meas, species); s = shapley (Mdl, 'QueryPoints', meas([1, 60, 120],:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect b = plot (s); assert_equal (numel (b), 3); assert_equal (get (b(1), 'displayname'), 'setosa'); assert_equal (get (b(3), 'displayname'), 'virginica'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # the classes to draw may be named load fisheriris Mdl = fitcknn (meas, species); s = shapley (Mdl, 'QueryPoints', meas([1, 60, 120],:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect b = plot (s, 'ClassNames', {'setosa', 'virginica'}); assert_equal (numel (b), 2); assert_equal (get (b(2), 'displayname'), 'virginica'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # boxchart draws one box per predictor, lying horizontally X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1:4,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect b = boxchart (s); assert_equal (class (b), 'stats.chart.BoxChart'); assert_equal (b.Orientation, 'horizontal'); assert_equal (class (b.XData), 'categorical'); assert_equal (numel (findobj (gca (), 'type', 'patch')), 3); assert_equal (get (gca (), 'yticklabel')', {'x1', 'x3', 'x2'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # boxchart is titled as a summary over the query points X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1:4,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect boxchart (s); ax = gca (); assert_equal (get (get (ax, 'title'), 'string'), 'Shapley Summary Plot'); assert_equal (get (get (ax, 'xlabel'), 'string'), 'Shapley Value'); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Predictor'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1:4,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect boxchart (s, 'NumImportantPredictors', 2); assert_equal (get (gca (), 'yticklabel')', {'x3', 'x2'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test load fisheriris Mdl = fitcknn (meas, species); s = shapley (Mdl, 'QueryPoints', meas([1, 60, 120],:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect boxchart (s, 'ClassName', 'virginica'); [~, ord] = sort (s.MeanAbsoluteShapley.virginica, 'ascend'); assert_equal (get (gca (), 'yticklabel')', ... cellstr (s.Shapley.Predictor(ord))'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # the outlier markers may be spread across the width of the box X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1:4,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect b = boxchart (s, 'JitterOutliers', 'on'); assert_equal (b.JitterOutliers, 'on'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # swarmchart draws one row of points per predictor X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1:4,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect h = swarmchart (s); assert_equal (numel (h), 3); assert_equal (get (h(1), 'xdata')', [-5, -3, -1, 1], 1e-12); assert_equal (get (gca (), 'yticklabel')', {'x1', 'x3', 'x2'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1:4,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect h = swarmchart (s); assert_equal (get (h(1), 'cdata')', [0, 1/3, 2/3, 1], 1e-12); assert_equal (get (gca (), 'clim'), [0, 1]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # the colour map the values are read through may be given X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1:4,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect swarmchart (s, 'ColorMap', [1, 0, 0; 0, 1, 0]); assert_equal (get (gca (), 'colormap'), [1, 0, 0; 0, 1, 0]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # how the points of a row are spread may be chosen X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1:4,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect h = swarmchart (s, 'YJitter', 'none'); assert_equal (get (h(1), 'ydata')', [1, 1, 1, 1]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # plotDependence draws one predictor against its own values X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1:4,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect p = plotDependence (s, 'x1'); assert_equal (get (p, 'xdata')', [1, 2, 3, 4]); assert_equal (get (p, 'ydata')', [-5, -3, -1, 1], 1e-12); ax = gca (); assert_equal (get (get (ax, 'title'), 'string'), ... 'Shapley Dependence Plot'); assert_equal (get (get (ax, 'xlabel'), 'string'), 'x1'); assert_equal (get (get (ax, 'ylabel'), 'string'), ... 'Shapley Values for x1'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a predictor may be indexed rather than named X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1:4,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect p = plotDependence (s, 2); assert_equal (get (p, 'xdata')', [10, 20, 30, 45]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1:4,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect p = plotDependence (s, 1, 'ColorPredictor', 'x2'); assert_equal (get (p, 'cdata')', [10, 20, 30, 45]); assert_equal (get (gca (), 'clim'), [10, 45]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a colour bar is drawn beside a chart whose points are coloured X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.1 * Z(:,3); s = shapley (f, X, 'QueryPoints', X(1:4,:), ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect plotDependence (s, 1); none = numel (findobj (hf, 'tag', 'colorbar')); plotDependence (s, 1, 'ColorPredictor', 'x2'); assert_equal (none, 0); assert_equal (numel (findobj (hf, 'tag', 'colorbar')), 1); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a predictor holding levels is drawn as a box over each level X = [1, 0; 2, 0; 3, 1; 4, 1; 5, 0; 6, 1]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2); s = shapley (f, X, 'QueryPoints', X(1:4,:), ... 'CategoricalPredictors', 2, ... 'NumObservationsToSample', 'all'); hf = figure ('visible', 'off'); unwind_protect p = plotDependence (s, 2); assert_equal (class (p), 'stats.chart.BoxChart'); assert_equal (numel (findobj (gca (), 'type', 'patch')), 2); assert_equal (get (get (gca (), 'title'), 'string'), ... 'Shapley Dependence Plot'); unwind_protect_cleanup close (hf); end_unwind_protect ***** error plot (shapley (@(Z) Z(:,1), [1, 2; 3, 4])) ***** error boxchart (shapley (@(Z) Z(:,1), [1, 2; 3, 4])) ***** error swarmchart (shapley (@(Z) Z(:,1), [1, 2; 3, 4])) ***** error plotDependence (shapley (@(Z) Z(:,1), [1, 2; 3, 4]), 1) ***** error plot (shapley (@(Z) Z(:,1), [1, 2; 3, 4], 'QueryPoints', [1, 2]), ... 'NumImportantPredictors', 0) ***** error plot (shapley (@(Z) Z(:,1), [1, 2; 3, 4], 'QueryPoints', [1, 2]), ... 'QueryPointIndices', 1.5) ***** error plot (shapley (@(Z) Z(:,1), [1, 2; 3, 4], 'QueryPoints', [1, 2]), ... 'QueryPointIndices', 2) ***** error plot (shapley (@(Z) Z(:,1), [1, 2; 3, 4], 'QueryPoints', [1, 2]), ... 'ClassNames', 'setosa') ***** error boxchart (shapley (@(Z) Z(:,1), [1, 2; 3, 4], 'QueryPoints', [1, 2]), ... 'ClassName', 'setosa') ***** error boxchart (shapley (@(Z) Z(:,1), [1, 2; 3, 4], 'QueryPoints', [1, 2]), ... 'JitterOutliers', 'maybe') ***** error swarmchart (shapley (@(Z) Z(:,1), [1, 2; 3, 4], 'QueryPoints', [1, 2]), ... 'YJitter', 'sideways') ***** error swarmchart (shapley (@(Z) Z(:,1), [1, 2; 3, 4], 'QueryPoints', [1, 2]), ... 'ColorMap', 5) ***** error plotDependence (shapley (@(Z) Z(:,1), [1, 2; 3, 4], 'QueryPoints', [1, 2])) ***** error plotDependence (shapley (@(Z) Z(:,1), [1, 2; 3, 4], ... 'QueryPoints', [1, 2]), 'nope') ***** error plot (shapley (@(Z) Z(:,1), [1, 2; 3, 4], 'QueryPoints', [1, 2]), ... 'NoSuchThing', 1) ***** shared stT, stM load fisheriris stT = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); stT.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); stM = fitrtree (stT, 'SL'); ***** test # the observations to average over may be given as a table s = shapley (stM, stT(:,[1, 2, 3, 5]), 'QueryPoints', ... stT(1,[1, 2, 3, 5]), 'NumObservationsToSample', 'all'); assert_equal (size (s.X), [150, 4]); assert_equal (cellstr (s.Shapley.Predictor)', ... {'SW', 'PL', 'PW', 'Wide'}); ***** test a = shapley (stM, stT(:,[1, 2, 3, 5]), 'QueryPoints', ... stT(1,[1, 2, 3, 5]), 'NumObservationsToSample', 'all'); b = shapley (stM, stT(:,[5, 3, 2, 1]), 'QueryPoints', ... stT(1,[5, 3, 2, 1]), 'NumObservationsToSample', 'all'); assert_equal (b.Shapley.Value, a.Shapley.Value); ***** test a = shapley (stM, stT(:,[1, 2, 3, 5]), 'QueryPoints', ... stT(1,[1, 2, 3, 5]), 'NumObservationsToSample', 'all'); b = shapley (stM, stT, 'QueryPoints', stT(1,:), ... 'NumObservationsToSample', 'all'); assert_equal (b.Shapley.Value, a.Shapley.Value); ***** test # fit takes a table too, read the same way a = shapley (stM, stT(:,[1, 2, 3, 5]), 'QueryPoints', ... stT(1,[1, 2, 3, 5]), 'NumObservationsToSample', 'all'); b = shapley (stM, stT(:,[1, 2, 3, 5]), ... 'NumObservationsToSample', 'all'); b = fit (b, stT(1,[5, 3, 2, 1])); assert_equal (b.Shapley.Value, a.Shapley.Value); ***** test # a level carries the code it carried at fitting T = stT(1:60,:); T.Wide = categorical (repmat ({'wide'}, 60, 1), {'narrow', 'wide'}); s = shapley (stM, T(:,[1, 2, 3, 5]), 'QueryPoints', ... T(1,[1, 2, 3, 5]), 'NumObservationsToSample', 'all'); assert_equal (rows (s.Shapley), 4); ***** test f = @(Z) Z(:,1); s = shapley (f, stT(:,1:3), 'QueryPoints', stT(1,1:3), ... 'NumObservationsToSample', 'all'); assert_equal (cellstr (s.Shapley.Predictor)', {'SW', 'PL', 'PW'}); r = shapley (f, stT(:,[3, 2, 1]), 'QueryPoints', stT(1,[3, 2, 1]), ... 'NumObservationsToSample', 'all'); assert_equal (cellstr (r.Shapley.Predictor)', {'PW', 'PL', 'SW'}); ***** error ... shapley (stM, stT(:,[1, 3, 5]), 'QueryPoints', stT(1,[1, 3, 5])) ***** error ... fit (shapley (stM, stT(:,[1, 2, 3, 5]), ... 'NumObservationsToSample', 'all'), stT(1,[1, 3, 5])) 112 tests, 112 passed, 0 known failure, 0 skipped [inst/Machine_Learning/RegressionGAM.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/RegressionGAM.m ***** demo ## Train a RegressionGAM Model for synthetic values rng (42); f1 = @(x) cos (3 * x); f2 = @(x) x .^ 3; x1 = 2 * rand (50, 1) - 1; x2 = 2 * rand (50, 1) - 1; y = f1(x1) + f2(x2); y = y + y .* 0.2 .* rand (50,1); X = [x1, x2]; a = fitrgam (X, y) ***** demo ## Declare two different functions rng (42); f1 = @(x) cos (3 * x); f2 = @(x) x .^ 3; ## Generate 80 samples for f1 and f2 x = [-4*pi:0.1*pi:4*pi-0.1*pi]'; X1 = f1(x); X2 = f2(x); ## Create a synthetic response by adding noise Ytrue = X1 + X2; Y = Ytrue + Ytrue .* 0.2 .* rand (80,1); ## Assemble predictor data X = [X1, X2]; ## Train the GAM and test on the same data ## A standard deviation and a prediction interval come from the spline ## engine, which fits one; the boosted-tree engine reports none. a = fitrgam (X, Y, 'FitMethod', 'splines', 'order', [5, 5]); [ypred, ySDsd, yInt] = predict (a, X); ## Plot the results figure [sortedY, indY] = sort (Ytrue); plot (sortedY, 'r-'); xlim ([0, 80]); hold on plot (ypred(indY), 'g+') plot (yInt(indY,1), 'k:') plot (yInt(indY,2), 'k:') xlabel ('Predictor samples'); ylabel ('Response'); title ('actual vs predicted values for function f1(x) = cos (3x) '); legend ({'Theoretical Response', 'Predicted Response', 'Prediction Intervals'}); ## Use 30% Holdout partitioning for training and testing data C = cvpartition (80, 'HoldOut', 0.3); [ypred, ySDsd, yInt] = predict (a, X(test (C),:)); ## Plot the results figure [sortedY, indY] = sort (Ytrue(test (C))); plot (sortedY, 'r-'); xlim ([0, sum(test(C))]); hold on plot (ypred(indY), 'g+') plot (yInt(indY,1),'k:') plot (yInt(indY,2),'k:') xlabel ('Predictor samples'); ylabel ('Response'); title ('actual vs predicted values for function f1(x) = cos (3x) '); legend ({'Theoretical Response', 'Predicted Response', 'Prediction Intervals'}); ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = [1; 2; 3; 4]; a = RegressionGAM (x, y, 'FitMethod', 'splines'); assert_equal ({a.X, a.Y}, {x, y}) assert_equal ({a.BaseModel.Intercept}, {2.5000}) assert_equal ({a.Knots, a.Order, a.DoF}, {[5, 5, 5], [3, 3, 3], [8, 8, 8]}) assert_equal ({a.NumObservations, a.NumPredictors}, {4, 3}) assert_equal ({a.ResponseName, a.PredictorNames}, {'Y', {'x1', 'x2', 'x3'}}) assert_equal ({a.Formula}, {[]}) ***** test x = [1, 2, 3, 4; 4, 5, 6, 7; 7, 8, 9, 1; 3, 2, 1, 2]; y = [1; 2; 3; 4]; pnames = {'A', 'B', 'C', 'D'}; formula = 'Y ~ A + B + C + D + A:C'; intMat = logical ([1,0,0,0;0,1,0,0;0,0,1,0;0,0,0,1;1,0,1,0]); a = RegressionGAM (x, y, 'FitMethod', 'splines', ... 'predictors', pnames, 'formula', formula); assert_equal (a.IntMatrix, double (intMat)) assert_equal ({a.ResponseName, a.PredictorNames}, {'Y', pnames}) assert_equal (a.Formula, formula) ***** test ## Test that predict() executes correctly when interactions are present X = [1, 2; 3, 4; 5, 6; 7, 8]; Y = [10; 20; 30; 40]; mdl = RegressionGAM (X, Y, 'FitMethod', 'splines', ... 'formula', 'Y ~ x1 + x2 + x1:x2'); ypred = predict (mdl, X); assert_equal (isnumeric (ypred), true); assert_equal (size (ypred), [4, 1]); [ypred2, ySD, yInt] = predict (mdl, X, 'includeinteractions', true); assert_equal (size (ypred2), [4, 1]); assert_equal (size (ySD), [4, 1]); assert_equal (size (yInt), [4, 2]); ## The three terms fit these four points exactly, so the residuals are zero ## and so is ySD. This block asserted the three sizes and nothing else, ## which is why it stayed green while ySD was computed from two of the ## three terms: a size is true whatever the number is. assert_equal (ypred2, [10; 20; 30; 40], 1e-10); assert_equal (ySD, zeros (4, 1), 1e-10); ***** test ## Verify ySD is based on training residual variance X = (1:10)'; Y = [2; 1; 4; 3; 6; 5; 8; 7; 10; 9]; mdl = RegressionGAM (X, Y, 'FitMethod', 'splines'); y_train = predict (mdl, X); rs = Y - y_train; expected_ySD = sqrt (var (rs)); [~, ySD] = predict (mdl, X(1:4,:)); assert_equal (ySD, expected_ySD * ones (4, 1), 1e-10); ***** test ## Verify ySD remains the same for one or more prediction points X = (1:10)'; Y = [2; 1; 4; 3; 6; 5; 8; 7; 10; 9]; mdl = RegressionGAM (X, Y, 'FitMethod', 'splines'); y_train = predict (mdl, X); expected_ySD = sqrt (var (Y - y_train)); [~, ySD_1] = predict (mdl, X(1,:)); [~, ySD_3] = predict (mdl, X(1:3,:)); assert_equal (ySD_1, expected_ySD, 1e-10); assert_equal (ySD_3, expected_ySD * ones (3, 1), 1e-10); ***** test k = (1:60)'; X = [mod(k*7,11)-5, mod(k*3,11)-5, mod(k*5,11)-5]; y = X(:,1) .* X(:,2) + 0.5 * X(:,3); Mdl = fitrgam (X, y, "Interactions", "all"); assert_equal (Mdl.Interactions, [1, 2; 1, 3; 2, 3]); ***** test k = (1:60)'; X = [mod(k*7,11)-5, mod(k*3,11)-5, mod(k*5,11)-5]; Mdl = fitrgam (X, X(:,1) + X(:,3)); assert_equal (size (Mdl.Interactions), [0, 2]); ***** test k = (1:60)'; X = [mod(k*7,11)-5, mod(k*3,11)-5, mod(k*5,11)-5]; y = X(:,1) .* X(:,2) + 0.5 * X(:,3); Mdl = fitrgam (X, y, "FitMethod", "splines", ... "Formula", "Y ~ x1 + x2 + x1:x2"); assert_equal (Mdl.Interactions, [1, 2]); assert_equal (compact (Mdl).Interactions, [1, 2]); ***** test load fisheriris bai = ! strcmp (species, "setosa"); Xai = meas(bai,2:4); Yai = meas(bai,1); Aai = addInteractions (fitrgam (Xai, Yai), "all"); Bai = fitrgam (Xai, Yai, "Interactions", "all"); assert_equal (Aai.Interactions, Bai.Interactions); assert_equal (Aai.ModelwInt, Bai.ModelwInt); assert_equal (predict (Aai, Xai), predict (Bai, Xai)); ***** test load fisheriris bai = ! strcmp (species, "setosa"); Xai = meas(bai,2:4); Yai = meas(bai,1); Cai = fitrgam (Xai, Yai); Aai = addInteractions (Cai, "all"); assert_equal (predict (Aai, Xai, "IncludeInteractions", false), ... predict (Cai, Xai)); ***** test load fisheriris bai = ! strcmp (species, "setosa"); Xai = meas(bai,2:4); Yai = meas(bai,1); Aai = addInteractions (fitrgam (Xai, Yai), 2); assert_equal (size (Aai.Interactions), [2, 2]); assert_equal (sort (Aai.Interactions, 2), Aai.Interactions); Lai = addInteractions (fitrgam (Xai, Yai), logical ([1 1 0; 0 1 1])); assert_equal (Lai.Interactions, [1, 2; 2, 3]); ***** test load fisheriris X = meas; Y = meas(:,1) + 0.3 * meas(:,3); A = fitrgam (X, Y, 'NumTreesPerPredictor', 5); B = resume (A, 10); C = fitrgam (X, Y, 'NumTreesPerPredictor', 15); assert_equal (B.ModelParameters.NumTreesPerPredictor, 15); assert_equal (predict (B, X), predict (C, X), 1e-10); ***** test ## A model carrying interactions gains interaction trees, and its predictor ## shape functions are left where they were. load fisheriris X = meas; Y = meas(:,1) + 0.3 * meas(:,3); A = fitrgam (X, Y, 'NumTreesPerPredictor', 5, 'Interactions', 3, ... 'NumTreesPerInteraction', 4); B = resume (A, 10); assert_equal (B.ModelParameters.NumTreesPerPredictor, 5); assert_equal (B.ModelParameters.NumTreesPerInteraction, 14); assert_equal (B.TreeModel.ShapeValues, A.TreeModel.ShapeValues); C = fitrgam (X, Y, 'NumTreesPerPredictor', 5, 'Interactions', 3, ... 'NumTreesPerInteraction', 14); assert_equal (predict (B, X), predict (C, X), 1e-10); ***** test ## The selected pairs survive, and resuming twice accumulates. load fisheriris X = meas; Y = meas(:,1) + 0.3 * meas(:,3); A = fitrgam (X, Y, 'NumTreesPerPredictor', 5, 'Interactions', 3, ... 'NumTreesPerInteraction', 4); B = resume (resume (A, 10), 6); assert_equal (B.Interactions, A.Interactions); assert_equal (B.ModelParameters.NumTreesPerInteraction, 20); assert_equal (B.ModelParameters.NumTreesPerPredictor, 5); ***** test ## The model handed in is not modified. load fisheriris X = meas; Y = meas(:,1) + 0.3 * meas(:,3); A = fitrgam (X, Y, 'NumTreesPerPredictor', 5); B = resume (A, 10); assert_equal (A.ModelParameters.NumTreesPerPredictor, 5); assert_equal (B.ModelParameters.NumTreesPerPredictor, 15); ***** test # a row missing a predictor is kept, and its spline term has no value x = linspace (0, 1, 30)'; X = [x, cos(4 * x)]; y = sin (3 * x) + X(:,2); Mdl = RegressionGAM (X, y, 'FitMethod', 'splines'); yFit = predict (Mdl, [0.5, 0.2; NaN, 0.2; 0.5, 0.2]); assert_equal (size (yFit), [3, 1]); assert_equal (isnan (yFit)', [false, true, false]); ***** test # MATLAB parity: a missing value adds nothing from its term k = (1:200)'; X = [sin(k), cos(2 * k), mod(k, 5)]; y = 2 * sin (k) + X(:,2) .^ 2 + 0.3 * X(:,3); Q = [0.5, 0.2, 1; NaN, 0.2, 1; 0.5, NaN, 1; NaN, NaN, NaN; 0.1, 0.2, 1; ... NaN, 0.7, 3; NaN, NaN, 1]; Mdl = RegressionGAM (X, y); yFit = predict (Mdl, Q); assert_equal (yFit, [1.4399946345; 0.675842807654; 1.60393628463; ... 1.09800542249; 1.33125338416; 1.62383199199; ... 0.839784457781], 1e-10); assert_equal (yFit(4), Mdl.Intercept); ***** test # MATLAB parity: categorical predictors are split by sets of levels k = (0:119)'; c1 = mod (k, 3) + 1; x2 = sin (k); c3 = 10 * (mod (floor (k / 2), 2) + 1); X = [c1, x2, c3]; y = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 20) + 0.1 * cos (k); Q = [1, 0, 10; 2, 0, 10; 3, 0, 10; 1, 0, 20; 1, 0.5, 10; 4, 0, 10; ... NaN, 0, 10; 2.5, 0, 20]; Mdl = RegressionGAM (X, y, 'CategoricalPredictors', [1, 3], ... 'NumTreesPerPredictor', 5, ... 'MaxNumSplitsPerPredictor', 2); assert_equal (Mdl.CategoricalPredictors, [1, 3]); assert_equal (predict (Mdl, Q), [-0.1559786927; 4.811738827; ... -0.1849962119; -3.091005709; ... 0.2642714677; 1.490254641; ... 1.490254641; -1.444772376], 1e-9); ***** test # MATLAB parity: a categorical predictor reports no bin edges k = (0:119)'; c1 = mod (k, 3) + 1; x2 = sin (k); c3 = 10 * (mod (floor (k / 2), 2) + 1); X = [c1, x2, c3]; y = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 20) + 0.1 * cos (k); Q = [1, 0, 10; 2, 0, 10; 3, 0, 10; 1, 0, 20; 1, 0.5, 10; 4, 0, 10; ... NaN, 0, 10; 2.5, 0, 20]; Mdl = RegressionGAM (X, y, 'CategoricalPredictors', [1, 3], ... 'NumTreesPerPredictor', 1); assert_equal (Mdl.Intercept, 0.1666859425, 1e-10); assert_equal (predict (Mdl, Q(6:8,:)), [1.312029301; 1.312029301; ... -1.640617244], 1e-9); assert_equal (Mdl.BinEdges{1}, []); assert_equal (Mdl.BinEdges{3}, []); assert_equal (numel (Mdl.BinEdges{2}), 119); ***** test # MATLAB parity: pair trees split categorical predictors by level sets k = (0:149)'; c1 = 1 + mod (floor (k * 7 / 11), 4); x2 = sin (k); c3 = 10 * (1 + (mod (k, 7) > 3)) + 10 * (mod (k, 13) == 0); X = [c1, x2, c3]; y = 2 * (c1 == 2) - 1.5 * (c1 == 4) + 0.5 * x2 - 3 * (c3 == 20) ... + (c3 == 30) + (c1 == 3) .* (c3 == 20) + 0.1 * cos (k) ... + 0.05 * sin (3 * k); [A, B] = ndgrid ([1, 2, 3, 4], [10, 20, 30]); Q = [A(:), zeros(12, 1), B(:)]; Mdl = RegressionGAM (X, y, 'CategoricalPredictors', [1, 3], ... 'Interactions', logical ([1, 0, 1]), ... 'NumTreesPerInteraction', 5); d = predict (Mdl, Q) - predict (Mdl, Q, 'IncludeInteractions', false); assert_equal (d, [0.03701741101; 0.06202240762; -0.1556975657; ... 0.08736164669; -0.07100596369; -0.08113441688; ... 0.3496023158; -0.06710888279; 0.06027597832; ... 0.05025393807; -0.06227465812; 0.01256864956], 1e-9); ***** test # MATLAB parity: a pair tree using one predictor alone adds nothing k = (0:149)'; c1 = 1 + mod (floor (k * 7 / 11), 4); x2 = sin (k); c3 = 10 * (1 + (mod (k, 7) > 3)) + 10 * (mod (k, 13) == 0); X = [c1, x2, c3]; y = 2 * (c1 == 2) - 1.5 * (c1 == 4) + 0.5 * x2 - 3 * (c3 == 20) ... + (c3 == 30) + (c1 == 3) .* (c3 == 20) + 0.1 * cos (k) ... + 0.05 * sin (3 * k); g = linspace (-1, 1, 5)'; [A, B, C] = ndgrid ([1, 2, 3, 4, NaN], g, [10, 20, 30, NaN]); Q = [A(:), B(:), C(:)]; Q = Q([1, 7, 13, 19, 28, 34, 45, 52, 59, 67],:); Mdl = RegressionGAM (X, y, 'CategoricalPredictors', [1, 3], ... 'Interactions', 'all', 'NumTreesPerInteraction', 5); assert_equal (Mdl.Interactions, [1, 3; 2, 3; 1, 2]); d = predict (Mdl, Q) - predict (Mdl, Q, 'IncludeInteractions', false); ## Five rounds, not twenty: a fit long enough to compound its rounding ## parts company with a toolchain that contracts multiply-add pairs, and ## then no tolerance holds, one element changing sign. Measured on R2024a, ## 2026-09-16, and agreeing to thirteen digits or better. assert_equal (d, [0.14496260366867; 0.00289829354386018; ... -0.125368787144964; 0.0691339453924824; ... 0.5053322741541; -0.0581889291447562; ... 0.00447142646759335; 0.15228433993982; ... 0.0385020050553703; 0.0838177432700107], 1e-9); ***** test # MATLAB parity: a pair whose trees split one predictor alone is dropped k = (0:119)'; c1 = mod (k, 3) + 1; x2 = sin (k); c3 = 10 * (mod (floor (k / 2), 2) + 1); X = [c1, x2, c3]; y = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 20) + 0.1 * cos (k); warning ('off', 'all', 'local'); Mdl = RegressionGAM (X, y, 'CategoricalPredictors', [1, 3], ... 'Interactions', logical ([0, 1, 1]), ... 'NumTreesPerInteraction', 5); assert_equal (size (Mdl.Interactions), [0, 2]); ***** warning ... k = (0:119)'; RegressionGAM ([mod(k, 3) + 1, sin(k), 10 * (mod (floor (k / 2), 2) + 1)], ... 5 * (mod (k, 3) == 1) + 0.5 * sin (k) ... - 3 * (mod (floor (k / 2), 2) == 1) + 0.1 * cos (k), ... 'CategoricalPredictors', [1, 3], ... 'Interactions', logical ([0, 1, 1]), ... 'NumTreesPerInteraction', 5); ***** test # MATLAB parity: 'CategoricalPredictors', 'all' k = (0:59)'; X = [mod(k, 3) + 1, mod(k, 4)]; y = X(:,1) .^ 2 - X(:,2) + 0.1 * cos (k); Mdl = RegressionGAM (X, y, 'CategoricalPredictors', 'all', ... 'Interactions', 'all', 'NumTreesPerInteraction', 2); assert_equal (Mdl.CategoricalPredictors, [1, 2]); assert_equal (Mdl.BinEdges, {[]; []}); assert_equal (Mdl.PairDetectionBinEdges, {[]; []}); ***** test # MATLAB parity: observation weights enter the fit k = (1:200)'; X = [sin(k), cos(2 * k), mod(k, 5)]; y = 2 * sin (k) + X(:,2) .^ 2 + 0.3 * X(:,3); w = 1 + mod (k, 3); Q = [0.5, 0.2, 1; 0.1, 0.7, 3; -0.4, -0.2, 0]; Mdl = RegressionGAM (X, y, 'Weights', w); assert_equal (Mdl.W, w / sum (w), 1e-15); assert_equal (Mdl.Intercept, 1.09607817728, 1e-10); assert_equal (predict (Mdl, Q), [1.32799066689; 2.22459947488; ... -0.705872562832], 1e-10); M5 = RegressionGAM (X, y, 'Weights', 5 * w); assert_equal (predict (M5, Q), predict (Mdl, Q), 1e-10); ***** test # MATLAB parity: a row missing a predictor is fitted, not dropped k = (1:200)'; X = [sin(k), cos(2 * k), mod(k, 5)]; y = 2 * sin (k) + X(:,2) .^ 2 + 0.3 * X(:,3); X(1:5,1) = NaN; Q = [0.5, 0.2, 1; NaN, 0.2, 1; 0.5, NaN, 1; NaN, NaN, NaN; 0.1, 0.2, 1; ... NaN, 0.7, 3; NaN, NaN, 1]; Mdl = RegressionGAM (X, y); assert_equal (Mdl.NumObservations, 200); assert_equal (Mdl.Intercept, 1.28924934314, 1e-10); assert_equal (predict (Mdl, Q), [1.39295651846; 0.938063487647; ... 1.51847439653; 1.28924934314; ... 1.06837329164; 1.96571223429; ... 1.06358136571], 1e-10); ***** test # MATLAB parity: a pair tree of one split selects no interaction k = (1:200)'; X = [sin(k), cos(2 * k), mod(k, 5)]; y = 2 * sin (k) + X(:,2) .^ 2 + 0.3 * X(:,3); S = warning ('off', 'all'); unwind_protect Mdl = RegressionGAM (X, y, 'Interactions', 1, ... 'MaxNumSplitsPerInteraction', 1); unwind_protect_cleanup warning (S); end_unwind_protect assert_equal (Mdl.Interactions, zeros (0, 2)); assert_equal (Mdl.Intercept, 1.09800542249, 1e-10); ***** test # MATLAB parity: pair trees are fitted to the rows, on their own grid k = (1:200)'; X = [sin(k), cos(2 * k), mod(k, 5)]; y = 2 * sin (k) + X(:,2) .^ 2 + 0.3 * X(:,3); P = [0, -0.99, 0; 0, -0.42, 2; 0, 0.33, 1; 0, 0.78, 4]; Mdl = RegressionGAM (X, y, 'Interactions', 1, ... 'NumTreesPerInteraction', 1, ... 'MaxNumSplitsPerInteraction', 4); assert_equal (Mdl.Interactions, [2, 3]); pc = predict (Mdl, P) - predict (Mdl, P, 'IncludeInteractions', false); assert_equal (pc, [-0.014545869; 0.0020626874; 0.013767507; ... -0.0043992362], 1e-8); ***** test # resuming the interaction phase adds trees a longer run would add k = (1:200)'; X = [sin(k), cos(2 * k), mod(k, 5)]; y = 2 * sin (k) + X(:,2) .^ 2 + 0.3 * X(:,3); P = [0, -0.99, 0; 0, -0.42, 2; 0, 0.33, 1; 0, 0.78, 4]; M1 = RegressionGAM (X, y, 'Interactions', 1, ... 'NumTreesPerInteraction', 1, ... 'MaxNumSplitsPerInteraction', 4); M2 = RegressionGAM (X, y, 'Interactions', 1, ... 'NumTreesPerInteraction', 2, ... 'MaxNumSplitsPerInteraction', 4); assert_equal (predict (resume (M1, 1), P), predict (M2, P), 1e-12); ***** test # MATLAB parity: a missing value stops at the node that splits on it k = (1:200)'; X = [sin(k), cos(2 * k), mod(k, 5)]; y = 2 * sin (k) + X(:,2) .^ 2 + 0.3 * X(:,3); X(1:5,1) = NaN; X(6:10,3) = NaN; P = [-0.99, 0, 0; -0.33, 0, 2; 0.33, 0, 4; 0.99, 0, 1; ... NaN, 0, 0; -0.9, 0, NaN; 0.9, 0, NaN; NaN, 0, NaN]; Mdl = RegressionGAM (X, y, 'Interactions', logical ([1, 0, 1]), ... 'NumTreesPerInteraction', 1, ... 'MaxNumSplitsPerInteraction', 4); assert_equal (Mdl.Interactions, [1, 3]); assert_equal (Mdl.Intercept, 1.27402212251, 1e-10); pc = predict (Mdl, P) - predict (Mdl, P, 'IncludeInteractions', false); assert_equal (pc, [0.004044014047; -0.01436832448; 0.01780996877; ... -0.01436832448; -0.0001224643025; -0.002123518423; ... -0.002123518423; -0.0001224643025], 1e-9); ***** test # resuming keeps what a row missing a pair predictor takes k = (1:200)'; X = [sin(k), cos(2 * k), mod(k, 5)]; y = 2 * sin (k) + X(:,2) .^ 2 + 0.3 * X(:,3); X(1:5,1) = NaN; X(6:10,3) = NaN; P = [-0.99, 0, 0; 0.33, 0, 4; NaN, 0, 0; -0.9, 0, NaN; NaN, 0, NaN]; M1 = RegressionGAM (X, y, 'Interactions', logical ([1, 0, 1]), ... 'NumTreesPerInteraction', 1, ... 'MaxNumSplitsPerInteraction', 4); M2 = RegressionGAM (X, y, 'Interactions', logical ([1, 0, 1]), ... 'NumTreesPerInteraction', 2, ... 'MaxNumSplitsPerInteraction', 4); assert_equal (predict (resume (M1, 1), P), predict (M2, P), 1e-12); ***** test # MATLAB parity: the detection grid, with values missing k = (1:300)'; X = [sin(k), cos(2 * k), mod(k, 5), sin(0.7 * k), cos(0.3 * k)]; y = X(:,1) + X(:,2) .^ 2 + 0.3 * X(:,3) + 0.8 * X(:,1) .* X(:,4) ... + 0.5 * X(:,2) .* X(:,3) + 0.3 * X(:,4) .* X(:,5) + 0.05 * sin (13 * k); X(1:15,1) = NaN; X(16:30,3) = NaN; X(31:45,4) = NaN; Mdl = RegressionGAM (X, y, 'Interactions', 'all', ... 'NumTreesPerInteraction', 1); assert_equal (Mdl.PairDetectionBinEdges{4}(:)', ... [-0.92412955668638763, -0.67185165069256547, ... -0.37673775931105463, 0.064103966449078689, ... 0.43097453606213998, 0.73708146543750352, ... 0.93347437171529057], 1e-15); ***** error ... RegressionGAM (ones (10, 2), (1:10)', 'CategoricalPredictors', 3) ***** error ... RegressionGAM (ones (10, 2), (1:10)', 'CategoricalPredictors', true) ***** error ... RegressionGAM (ones (10, 2), (1:10)', 'CategoricalPredictors', 0.5) ***** error ... RegressionGAM (ones (10, 2), (1:10)', 'FitMethod', 'splines', ... 'CategoricalPredictors', 1) ***** error ... RegressionGAM (ones (10, 2), (1:10)', 'Weights', 'a') ***** error ... RegressionGAM (ones (10, 2), (1:10)', 'Weights', ones (2, 2)) ***** error ... RegressionGAM (ones (10, 2), (1:10)', 'Weights', [1, 2]) ***** error ... RegressionGAM (ones (10, 2), (1:10)', 'Weights', -ones (10, 1)) ***** error ... RegressionGAM ([(1:10)', mod((1:10)', 3)], (1:10)', ... 'Weights', ones (10, 1), 'FitMethod', 'splines') ***** error ... load fisheriris; ... resume (fitrgam (meas, meas(:,1), 'NumTreesPerPredictor', 5)) ***** error ... load fisheriris; ... resume (fitrgam (meas, meas(:,1), 'FitMethod', 'splines'), 5) ***** error ... load fisheriris; ... resume (fitrgam (meas, meas(:,1), 'NumTreesPerPredictor', 5), 0) ***** error ... load fisheriris; ... resume (fitrgam (meas, meas(:,1), 'NumTreesPerPredictor', 5), 2.5) ***** error ... load fisheriris; ... resume (fitrgam (meas, meas(:,1), 'NumTreesPerPredictor', 5), [1, 2]) ***** error ... X = [ones(20,1)*[1, 2]; ones(20,1)*[3, 4]]; ... resume (fitrgam (X, ones (40, 1), 'NumTreesPerPredictor', 5), 5) ***** error ... load fisheriris bai = ! strcmp (species, "setosa"); Mai = fitrgam (meas(bai,2:4), meas(bai,1), "Interactions", 2); addInteractions (Mai, "all") ***** error ... load fisheriris bai = ! strcmp (species, "setosa"); addInteractions (fitrgam (meas(bai,2:4), meas(bai,1), ... "FitMethod", "splines", ... "Formula", "Y ~ x1 + x2 + x1:x2"), "all") ***** error ... load fisheriris bai = ! strcmp (species, "setosa"); addInteractions (fitrgam (meas(bai,2:4), meas(bai,1)), {1}) ***** error RegressionGAM () ***** error RegressionGAM (ones (10,2)) ***** error ... RegressionGAM (ones (10,2), ones (5,1)) ***** error ... RegressionGAM ([1;2;3;'a';4], ones (5,1)) ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'some', 'some') ***** error RegressionGAM (ones (10,2), ones (10,1), 'formula', {'y~x1+x2'}) ***** error RegressionGAM (ones (10,2), ones (10,1), 'formula', [0, 1, 0]) ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'FitMethod', 'splines', ... 'formula', 'something') ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'FitMethod', 'splines', ... 'formula', 'something~') ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'FitMethod', 'splines', ... 'formula', 'something~') ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'FitMethod', 'splines', ... 'formula', 'something~x1:') ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'interactions', 'some') ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'interactions', -1) ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'interactions', [1 2 3 4]) ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'FitMethod', 'splines', ... 'interactions', 3) ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'FitMethod', 'splines', ... 'formula', 'y ~ x1 + x2', 'interactions', 1) ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'FitMethod', 'splines', ... 'interactions', 1, 'formula', 'y ~ x1 + x2') ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'knots', 'a') ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'FitMethod', 'splines', ... 'order', 3, 'dof', 2, 'knots', 5) ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'dof', 'a') ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'FitMethod', 'splines', ... 'knots', 5, 'order', 3, 'dof', 2) ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'order', 'a') ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'FitMethod', 'splines', ... 'knots', 5, 'dof', 2, 'order', 2) ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'tol', -1) ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'responsename', -1) ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'predictors', -1) ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'predictors', ['a','b','c']) ***** error ... RegressionGAM (ones (10,2), ones (10,1), 'predictors', {'a','b','c'}) ***** error ... predict (RegressionGAM (ones (10,1), ones (10,1))) ***** error ... predict (RegressionGAM (ones (10,1), ones (10,1)), []) ***** error ... predict (RegressionGAM (ones (10,2), ones (10,1)), 2) ***** error ... predict (RegressionGAM (ones (10,2), ones (10,1)), ones (10,2), 'some', 'some') ***** error ... predict (RegressionGAM (ones (10,2), ones (10,1)), ones (10,2), 'Alpha') ***** error ... predict (RegressionGAM (ones (10,2), ones (10,1)), ones (10,2), 'includeinteractions', 'some') ***** error ... predict (RegressionGAM (ones (10,2), ones (10,1)), ones (10,2), 'includeinteractions', 5) ***** error ... predict (RegressionGAM (ones (10,2), ones (10,1)), ones (10,2), 'alpha', 5) ***** error ... predict (RegressionGAM (ones (10,2), ones (10,1)), ones (10,2), 'alpha', -1) ***** error ... predict (RegressionGAM (ones (10,2), ones (10,1)), ones (10,2), 'alpha', 'a') ***** error ... savemodel (RegressionGAM ([1, 2; 2, 3; 3, 4; 4, 5], [1; 2; 3; 4])) ***** error ... savemodel (RegressionGAM ([1, 2; 2, 3; 3, 4; 4, 5], [1; 2; 3; 4]), 1) ***** error ... savemodel (RegressionGAM ([1, 2; 2, 3; 3, 4; 4, 5], [1; 2; 3; 4]), ['ab'; 'cd']) ***** test load fisheriris Mdl = fitrgam (meas(:,1:3), meas(:,4), 'FitMethod', 'splines'); assert_equal (Mdl.Intercept, Mdl.BaseModel.Intercept); assert_equal (size (Mdl.W), [Mdl.NumObservations, 1]); assert_equal (sum (Mdl.W), 1, 1e-12); assert_equal (Mdl.CategoricalPredictors, []); assert_equal (Mdl.ExpandedPredictorNames, Mdl.PredictorNames); assert_equal (Mdl.IsStandardDeviationFit, false); ***** test load fisheriris Mdl = fitrgam (meas(:,1:3), meas(:,4), 'FitMethod', 'splines', ... 'Knots', 4); assert_equal (Mdl.Knots, [4, 4, 4]); assert_equal (Mdl.Order, [3, 3, 3]); assert_equal (Mdl.DoF, [7, 7, 7]); ***** error ... RegressionGAM ([1, 2; Inf, 4; 5, 6; 7, 8], [1; 2; 3; 4]) ***** error ... RegressionGAM ([1, 2; 3, 4; 5, 6; 7, 8], [1; 2; Inf; 4]) ***** test load fisheriris Mdl = fitrgam (meas(:,1:3), meas(:,4), 'FitMethod', 'splines', ... 'Interactions', 'all'); assert_equal (Mdl.IntMatrix, logical ([1, 1, 0; 1, 0, 1; 0, 1, 1])); assert_equal (sum (Mdl.IntMatrix(:)), 6); ***** test load fisheriris X = meas(:,1:3); Mdl = fitrgam (X, meas(:,4)); y0 = predict (Mdl, X); Mdl.ResponseTransform = 'exp'; assert_equal (predict (Mdl, X), exp (y0), 1e-12); ***** test load fisheriris X = meas(:,1:3); Y = meas(:,4); Mdl = fitrgam (X, Y); assert_equal (resubPredict (Mdl), predict (Mdl, X)); assert_equal (resubLoss (Mdl), loss (Mdl, X, Y)); ***** test load fisheriris X = meas(:,1:3); Y = meas(:,4); Mdl = fitrgam (X, Y); r = Y - predict (Mdl, X); assert_equal (loss (Mdl, X, Y), mean (r .^ 2), 1e-12); w = [ones(75, 1); 3 * ones(75, 1)]; assert_equal (loss (Mdl, X, Y, 'Weights', w), ... sum (w .* r .^ 2) / sum (w), 1e-12); mae = @(y, yfit, wt) sum (wt .* abs (y - yfit)); assert_equal (loss (Mdl, X, Y, 'LossFun', mae), mean (abs (r)), 1e-12); ***** test load fisheriris X = meas(:,1:3); Mdl = fitrgam (X, meas(:,4), 'Interactions', 'all'); Mdl.ResponseTransform = 'exp'; fname = tempname (); savemodel (Mdl, fname); Mdl2 = loadmodel (fname); delete (fname); assert_equal (class (Mdl2), 'RegressionGAM'); assert_equal (Mdl2.Intercept, Mdl.Intercept); assert_equal (Mdl2.W, Mdl.W); assert_equal (Mdl2.IntMatrix, Mdl.IntMatrix); assert_equal (predict (Mdl2, X), predict (Mdl, X)); ***** shared xr, yr, Mr load fisheriris xr = meas(:,1:3); yr = meas(:,4); Mr = fitrgam (xr, yr); ***** error ... loss (Mr, xr) ***** error ... loss (Mr, xr, yr, 'Weights') ***** error ... loss (Mr, [], yr) ***** error ... loss (Mr, 1, yr) ***** error ... loss (Mr, xr, yr(1:10)) ***** error ... loss (Mr, xr, yr, 'LossFun', 'mad') ***** error ... loss (Mr, xr, yr, 'Bogus', 1) ***** error ... Mr.ResponseTransform = 'nonsense'; ***** test load fisheriris X = meas(:,2:4); Y = meas(:,1); Mdl = fitrgam (X, Y); assert_equal (Mdl.RowsUsed, []); assert_equal (class (Mdl.RowsUsed), 'double'); assert_equal (Mdl.NumObservations, 150); assert_equal (rows (Mdl.X), 150); assert_equal (rows (Mdl.W), 150); ***** test load fisheriris X = meas(:,2:4); Y = meas(:,1); Y(5) = NaN; Mdl = fitrgam (X, Y); assert_equal (class (Mdl.RowsUsed), 'logical'); assert_equal (size (Mdl.RowsUsed), [150, 1]); assert_equal (sum (Mdl.RowsUsed), 149); assert_equal (Mdl.RowsUsed(5), false); assert_equal (Mdl.NumObservations, 149); assert_equal (rows (Mdl.X), 149); assert_equal (rows (Mdl.W), 149); ***** test load fisheriris X = meas(:,2:4); X(3,2) = NaN; Y = meas(:,1); Mdl = fitrgam (X, Y); assert_equal (Mdl.RowsUsed, []); assert_equal (Mdl.NumObservations, 150); assert_equal (rows (Mdl.X), 150); assert_equal (sum (isnan (Mdl.X(:))), 1); ***** test load fisheriris X = meas(:,2:4); Y = meas(:,1); Mdl = fitrgam (X, Y, 'FitMethod', 'splines'); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2), 'RegressionGAM'); assert_equal (M2.NumObservations, Mdl.NumObservations); assert_equal (M2.PredictorNames, Mdl.PredictorNames); assert_equal (class (M2.ResponseTransform), class (Mdl.ResponseTransform)); assert_equal (M2.BaseModel.Parameters(1).coefs, ... Mdl.BaseModel.Parameters(1).coefs); assert_equal (predict (M2, X(1:5,:)), predict (Mdl, X(1:5,:)), 1e-12); ***** test load fisheriris X = meas(:,2:4); Y = meas(:,1); Mdl = fitrgam (X, Y, 'FitMethod', 'boostedtrees'); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.FitMethod, 'boostedtrees'); assert_equal (M2.TreeModel.ShapeValues, Mdl.TreeModel.ShapeValues); assert_equal (M2.BinEdges, Mdl.BinEdges); assert_equal (predict (M2, X(1:5,:)), predict (Mdl, X(1:5,:)), 1e-12); ***** test load fisheriris Mdl = fitrgam (meas(:,1:3), meas(:,4)); CVMdl = crossval (Mdl, 'KFold', 3); assert_equal (class (CVMdl), 'RegressionPartitionedModel'); assert_equal (CVMdl.CrossValidatedModel, 'GAM'); assert_equal (class (CVMdl.Trained{1}), 'CompactRegressionGAM'); assert_equal (CVMdl.KFold, 3); assert_equal (numel (CVMdl.Trained), 3); assert_equal (CVMdl.NumObservations, 150); ***** test load fisheriris CVMdl = crossval (fitrgam (meas(1:20,1:3), meas(1:20,4))); assert_equal (CVMdl.KFold, 10); ***** test load fisheriris CVMdl = crossval (fitrgam (meas(1:20,1:3), meas(1:20,4)), 'Holdout', 0.25); assert_equal (CVMdl.KFold, 1); ***** test load fisheriris CVMdl = crossval (fitrgam (meas(1:12,1:3), meas(1:12,4)), 'Leaveout', 'on'); assert_equal (CVMdl.KFold, 12); ***** test load fisheriris cvp = cvpartition (20, 'KFold', 4); Mdl = fitrgam (meas(1:20,1:3), meas(1:20,4)); assert_equal (crossval (Mdl, 'CVPartition', cvp).KFold, 4); ***** test load fisheriris Mdl = fitrgam (meas(1:20,1:3), meas(1:20,4), 'FitMethod', 'splines', ... 'Knots', 6, 'Order', 3); CVMdl = crossval (Mdl, 'KFold', 3); assert_equal (CVMdl.Trained{1}.FitMethod, 'splines'); assert_equal (isfield (CVMdl.Trained{1}.BaseModel, 'Intercept'), true); ***** test load fisheriris Mdl = fitrgam (meas(:,1:3), meas(:,4)); assert (kfoldLoss (crossval (Mdl, 'KFold', 5)) > resubLoss (Mdl)); ***** shared cvobj x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1; 4, 5, 6]; y = [1; 2; 3; 4; 5]; cvobj = fitrgam (x, y); ***** error ... crossval (cvobj, 'kfold') ***** error ... crossval (cvobj, 'kfold', 3, 'holdout', 0.2) ***** error ... crossval (cvobj, 'kfold', 'a') ***** error ... crossval (cvobj, 'holdout', 2) ***** error ... crossval (cvobj, 'leaveout', 1) ***** error ... crossval (cvobj, 'cvpartition', 1) ***** error ... crossval (cvobj, 'bogus', 1) ***** test load fisheriris Mdl = fitrgam (meas(:,1:3), meas(:,4)); assert_equal (class (Mdl.BinEdges), 'cell'); assert_equal (numel (Mdl.BinEdges), 3); Msp = fitrgam (meas(:,1:3), meas(:,4), 'FitMethod', 'splines'); assert_equal (Msp.BinEdges, {}); ***** test load fisheriris X = meas(:,1:3); Y = meas(:,4); Mdl = fitrgam (X, Y, 'FitMethod', 'splines', 'Interactions', 'all'); [~, ySD] = predict (Mdl, X(1:4,:)); ## Six terms against three stored columns. Truncating to three gave ## 0.9379137529, close to seven times the answer. assert_equal (ySD, 0.136050646147 * ones (4, 1), 1e-9); ***** test load fisheriris X = meas(:,1:3); Y = meas(:,4); Mdl = fitrgam (X, Y, 'FitMethod', 'splines', 'Interactions', 'all'); Xa = X; for i = 1:rows (Mdl.IntMatrix) t = logical (Mdl.IntMatrix(i,:)); Xt = X(:,t); Xi = ones (rows (X), 1); for c = 1:sum (t) Xi = Xi .* Xt(:,c); endfor Xa = [Xa, Xi]; endfor yr = ones (rows (Xa), 1) * Mdl.ModelwInt.Intercept; for j = 1:columns (Xa) yr = yr + ppval (Mdl.ModelwInt.Parameters(j), Xa(:,j)); endfor [~, ySD] = predict (Mdl, X(1:4,:)); assert_equal (ySD, sqrt (var (Y - yr)) * ones (4, 1), 1e-12); ***** test load fisheriris X = meas(:,1:3); Y = meas(:,4); Mdl = fitrgam (X, Y, 'FitMethod', 'splines', 'Formula', 'Y ~ x1 + x2'); assert_equal (numel (Mdl.ModelwInt.Parameters), 2); assert_equal (columns (Mdl.X), 3); [~, ySD, yInt] = predict (Mdl, X(1:4,:)); assert_equal (ySD, 0.348625969903 * ones (4, 1), 1e-9); assert_equal (size (yInt), [4, 2]); ***** test load fisheriris X = meas(:,1:3); Y = meas(:,4); Mdl = fitrgam (X, Y, 'FitMethod', 'splines', 'Interactions', 'all'); yA = predict (Mdl, X(1:3,:)); [yB, ~] = predict (Mdl, X(1:3,:)); assert_equal (yA, yB); assert_equal (yA, [0.255203457138; 0.210404303824; 0.162599243283], 1e-9); ***** test load fisheriris Mdl = fitrgam (meas(:,2:4), meas(:,1), 'FitMethod', 'boostedtrees'); assert_equal (Mdl.FitMethod, 'boostedtrees'); assert_equal (numel (Mdl.BinEdges), 3); assert_equal (numel (fieldnames (Mdl.ModelParameters)), 13); assert_equal (Mdl.ModelParameters.Type, 'regression'); ***** test load fisheriris y = meas(:,1); Mdl = fitrgam (meas(:,2:4), y, 'FitMethod', 'boostedtrees'); assert_equal (Mdl.Intercept, mean (y), 1e-12); ***** test load fisheriris Mdl = fitrgam (meas(:,2:4), meas(:,1), 'FitMethod', 'boostedtrees', ... 'Interactions', 'all'); assert_equal (rows (Mdl.Interactions), 3); assert_equal (numel (Mdl.PairDetectionBinEdges{1}), 7); ***** test load fisheriris X = meas(:,2:4); Mdl = fitrgam (X, meas(:,1), 'FitMethod', 'boostedtrees'); CMdl = compact (Mdl); assert_equal (predict (CMdl, X), predict (Mdl, X)); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (predict (M2, X), predict (Mdl, X)); ***** test load fisheriris Mdl = fitrgam (meas(:,2:4), meas(:,1), 'FitMethod', 'splines'); assert_equal (Mdl.FitMethod, 'splines'); assert_equal (Mdl.BinEdges, {}); assert_equal (Mdl.Knots, [5, 5, 5]); ***** error ... load fisheriris Mdl = fitrgam (meas(:,2:4), meas(:,1), 'FitMethod', 'boostedtrees'); [y, ySD] = predict (Mdl, meas(1:4,2:4)); ***** error ... fitrgam ([1;2;3;4], [1;2;3;4], 'FitMethod', 'nonsense') ***** error ... fitrgam ([1;2;3;4], [1;2;3;4], 'FitMethod', 'boostedtrees', 'Knots', 4) ***** error ... fitrgam ([1;2;3;4], [1;2;3;4], 'FitMethod', 'splines', 'MaxPValue', 0.5) ***** error ... fitrgam ([1;2;3;4], [1;2;3;4], 'FitMethod', 'boostedtrees', ... 'NumTreesPerPredictor', 0) ***** error ... fitrgam ([1;2;3;4], [1;2;3;4], 'FitMethod', 'boostedtrees', ... 'NumTreesPerInteraction', 1.5) ***** error ... fitrgam ([1;2;3;4], [1;2;3;4], 'FitMethod', 'boostedtrees', ... 'MaxNumSplitsPerPredictor', -1) ***** error ... fitrgam ([1;2;3;4], [1;2;3;4], 'FitMethod', 'boostedtrees', ... 'MaxNumSplitsPerInteraction', 'a') ***** error ... fitrgam ([1;2;3;4], [1;2;3;4], 'FitMethod', 'boostedtrees', ... 'InitialLearnRateForPredictors', 0) ***** error ... fitrgam ([1;2;3;4], [1;2;3;4], 'FitMethod', 'boostedtrees', ... 'InitialLearnRateForInteractions', 2) ***** error ... fitrgam ([1;2;3;4], [1;2;3;4], 'FitMethod', 'boostedtrees', 'Verbose', -1) ***** error ... fitrgam ([1;2;3;4], [1;2;3;4], 'FitMethod', 'boostedtrees', 'NumPrint', 0) ***** error ... fitrgam ([1;2;3;4], [1;2;3;4], 'FitMethod', 'boostedtrees', 'MaxPValue', 2) ***** test load fisheriris Mdl = fitrgam (meas(:,1:3), meas(:,4)); assert_equal (isempty (Mdl.HyperparameterOptimizationResults), true); ***** test load fisheriris Mdl = fitrgam (meas(:,2:4), meas(:,1)); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); T = {'identity', @(x) x; 'exp', @(x) exp (x); 'log', @(x) log (x)}; for i = 1:rows (T) Mdl.ResponseTransform = T{i,1}; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, T{i,2}(raw), 1e-12); endfor ***** test load fisheriris Mdl = fitrgam (meas(:,2:4), meas(:,1)); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); Mdl.ResponseTransform = @(x) x .^ 2; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, raw .^ 2, 1e-12); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,2:3); y = meas(:,1); T = table (X(:,1), X(:,2), 'VariableNames', {'SW', 'PL'}); T.SL = y; Mdl = fitrgam (T, 'SL'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'SL'), a); assert_equal (loss (Mdl, T), a); ***** test X = linspace (0, 1, 50)'; Y = sin (6 * X); M = fitrgam (X, Y, 'FitMethod', 'splines', 'Knots', 5, 'DoF', 9); assert_equal ([M.Knots, M.Order, M.DoF], [5, 4, 9]); M = fitrgam (X, Y, 'FitMethod', 'splines', 'DoF', 9, 'Knots', 5); assert_equal ([M.Knots, M.Order, M.DoF], [5, 4, 9]); M = fitrgam (X, Y, 'FitMethod', 'splines', 'Order', 2, 'DoF', 9); assert_equal ([M.Knots, M.Order, M.DoF], [7, 2, 9]); ***** error ... RegressionGAM ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', 'Weights', ... int8 ([1; 1; 1; 1])) ***** error ... RegressionGAM ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', 'Weights', true (4, 1)) ***** error X = [1, 2; 3, 4; 5, 6; 7, 8]; y = (1:4)'; loss (RegressionGAM (X, y), X, y, 'Weights', int8 ([1; 1; 1; 1])) ***** test ## Single weights are stored single, summing to one load fisheriris X = meas(:,2:4); y = meas(:,1); w = 1 + (1:150)' / 7; Mdl = RegressionGAM (X, y, 'Weights', single (w)); assert_equal (class (Mdl.W), 'single'); assert_equal (sum (double (Mdl.W)), 1, 1e-6); ***** test ## Single weights compute as double, to the precision of the stored W load fisheriris X = meas(:,2:4); y = meas(:,1); w = 1 + (1:150)' / 7; A = RegressionGAM (X, y, 'Weights', single (w)); B = RegressionGAM (X, y, 'Weights', double (single (w))); assert_equal (predict (A, X), predict (B, X), 1e-8); 160 tests, 160 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitclinear.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitclinear.m ***** demo ## Fit a linear classifier to the two overlapping iris species and read ## what the optimization did. load fisheriris X = meas(51:end,:); Y = species(51:end); [Mdl, FitInfo] = fitclinear (X, Y, 'Learner', 'logistic') ***** demo ## Fit from a table, and predict on one load fisheriris inds = ! strcmp (species, 'setosa'); X = meas(inds,:); T = table (X(:,1), X(:,2), X(:,3), X(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = species(inds); ## The response is named by its column, and everything else is a predictor Mdl = fitclinear (T, 'Species'); Mdl.PredictorNames Mdl.ResponseName ## predict reads a table by the names the model was fitted on, so the ## columns may come in any order label = predict (Mdl, T(1:5, [5, 4, 3, 2, 1])); label' ***** test ## The driver returns what the class constructor returns load fisheriris X = meas(51:end,:); Y = species(51:end); M1 = fitclinear (X, Y); M2 = ClassificationLinear (X, Y); assert_equal (class (M1), 'ClassificationLinear'); assert_equal (M1.Beta, M2.Beta); assert_equal (M1.Bias, M2.Bias); ***** test ## The options reach the model load fisheriris Mdl = fitclinear (meas(51:end,:), species(51:end), ... 'Learner', 'logistic', 'Lambda', 0.05, ... 'ResponseName', 'species'); assert_equal (Mdl.Learner, 'logistic'); assert_equal (Mdl.Lambda, 0.05); assert_equal (Mdl.ResponseName, 'species'); ***** test ## The second output describes the optimization load fisheriris [~, FitInfo] = fitclinear (meas(51:end,:), species(51:end)); assert_equal (FitInfo.Lambda, 0.01); assert_equal (FitInfo.Solver, {'bfgs'}); assert_equal (FitInfo.BetaTolerance, 1e-4); assert_equal (FitInfo.GradientTolerance, 1e-6); assert_equal (isfield (FitInfo, 'TerminationStatus'), true); ***** test ## A dual fit reports the passes it took and the dual variables it left load fisheriris [~, FitInfo] = fitclinear (meas(51:end,:), species(51:end), ... 'Solver', 'dual', 'PassLimit', 20); assert_equal (isfield (FitInfo, 'Alpha'), true); assert_equal (isfield (FitInfo, 'NumPasses'), true); assert_equal (isfield (FitInfo, 'IterationLimit'), false); assert_equal (FitInfo.GradientTolerance, 0); assert_equal (isnan (FitInfo.GradientNorm), true); ***** test ## A mini-batch fit reports the batch it stopped on and the rate it used load fisheriris [~, FitInfo] = fitclinear (meas(51:end,:), species(51:end), ... 'Solver', 'sgd', 'PassLimit', 5); assert_equal (isfield (FitInfo, 'BatchIndex'), true); assert_equal (isfield (FitInfo, 'OptimalLearnRate'), true); ***** test ## A cross-validation option returns a partitioned model instead load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = fitclinear (X, Y, 'KFold', 5); assert_equal (class (CVMdl), 'ClassificationPartitionedLinear'); assert_equal (CVMdl.KFold, 5); assert_equal (numel (CVMdl.Trained), 5); ***** test ## 'CrossVal' on gives the ten folds it defaults to, and 'off' the model ## itself load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = fitclinear (X, Y, 'CrossVal', 'on'); assert_equal (CVMdl.KFold, 10); assert_equal (class (fitclinear (X, Y, 'CrossVal', 'off')), ... 'ClassificationLinear'); ***** error ... [Mdl, FitInfo] = fitclinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'KFold', 3); ***** error fitclinear (ones (5, 2)) ***** error ... fitclinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Learner') ***** error ... fitclinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Learner', 'tree') ***** test # MATLAB parity: classes given as text are sorted load fisheriris k = [101:150, 51:100]; Mdl = fitclinear (meas(k,:), species(k)); assert_equal (Mdl.ClassNames, {'versicolor'; 'virginica'}); ***** test # MATLAB parity: a given ClassNames order is kept load fisheriris Mdl = fitclinear (meas(51:150,:), species(51:150), ... 'ClassNames', {'virginica'; 'versicolor'}); assert_equal (Mdl.ClassNames, {'virginica'; 'versicolor'}); ***** error ... load fisheriris fitclinear (meas(51:150,:), species(51:150), 'ClassNames', [3, 2]) ***** error ... load fisheriris fitclinear (meas(51:150,:), species(51:150), ... 'ClassNames', {'virginica'; 'rose'}) ***** shared fclT load fisheriris fclI = ! strcmp (species, 'setosa'); fclX = meas(fclI,:); fclT = table (fclX(:,1), fclX(:,2), fclX(:,3), fclX(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); fclT.Species = species(fclI); ***** test # the response is named by a column and the rest are predictors Mdl = fitclinear (fclT, 'Species'); assert_equal (Mdl.PredictorNames, {'SL', 'SW', 'PL', 'PW'}); assert_equal (Mdl.ResponseName, 'Species'); ***** test # a model formula names the response and the predictors together Mdl = fitclinear (fclT, 'Species ~ PW + SL'); assert_equal (Mdl.PredictorNames, {'PW', 'SL'}); ***** test # predict takes a table, matched by name and not by position Mdl = fitclinear (fclT, 'Species'); a = predict (Mdl, fclT); assert_equal (predict (Mdl, fclT(:, [5, 4, 3, 2, 1])), a); ***** test # a cross-validated fit takes a table too Mdl = fitclinear (fclT, 'Species', 'KFold', 3); assert_equal (class (Mdl), 'ClassificationPartitionedLinear'); assert_equal (Mdl.KFold, 3); ***** error ... fitclinear (fclT, 'NoSuch') ***** error ... fitclinear (fclT, 'Species ~ SL*PW') 21 tests, 21 passed, 0 known failure, 0 skipped [inst/Machine_Learning/ClassificationPartitionedModel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/ClassificationPartitionedModel.m ***** demo load fisheriris x = meas; y = species; ## Create a KNN classifier model obj = fitcknn (x, y, 'NumNeighbors', 5, 'Standardize', 1); ## Create a partition for 5-fold cross-validation partition = cvpartition (y, 'KFold', 5); ## Create the ClassificationPartitionedModel object cvModel = crossval (obj, 'cvPartition', partition) ***** demo load fisheriris x = meas; y = species; ## Create a KNN classifier model obj = fitcknn (x, y, 'NumNeighbors', 5, 'Standardize', 1); ## Create the ClassificationPartitionedModel object cvModel = crossval (obj); ## Predict the class labels for the observations not used for training [label, score, cost] = kfoldPredict (cvModel); fprintf ("Cross-validated accuracy = %1.2f%% (%d/%d)\n", ... sum (strcmp (label, y)) / numel (y) *100, ... sum (strcmp (label, y)), numel (y)) ***** test load fisheriris a = fitcdiscr (meas, species, 'gamma', 0.3); cvModel = crossval (a, 'KFold', 5); assert_equal (class (cvModel), "ClassificationPartitionedModel"); assert_equal (cvModel.NumObservations, 150); assert_equal (numel (cvModel.Trained), 5); assert_equal (class (cvModel.Trained{1}), "CompactClassificationDiscriminant"); assert_equal (cvModel.CrossValidatedModel, "Discriminant"); assert_equal (cvModel.KFold, 5); ***** test load fisheriris a = fitcdiscr (meas, species, 'gamma', 0.5, 'fillcoeffs', 'off'); cvModel = crossval (a, 'HoldOut', 0.3); assert_equal (class (cvModel), "ClassificationPartitionedModel"); assert_equal ({cvModel.X, cvModel.Y}, {meas, species}); assert_equal (cvModel.NumObservations, 150); assert_equal (numel (cvModel.Trained), 1); assert_equal (class (cvModel.Trained{1}), "CompactClassificationDiscriminant"); assert_equal (cvModel.CrossValidatedModel, "Discriminant"); ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = fitcgam (x, y, 'Interactions', 'all'); cvModel = crossval (a, 'KFold', 2); assert_equal (class (cvModel), "ClassificationPartitionedModel"); assert_equal (cvModel.NumObservations, 4); assert_equal (numel (cvModel.Trained), 2); assert_equal (class (cvModel.Trained{1}), "CompactClassificationGAM"); assert_equal (cvModel.CrossValidatedModel, "GAM"); assert_equal (cvModel.KFold, 2); warning: ClassificationGAM: model does not include interaction terms because all interaction terms have p-values greater than the 'MaxPValue' value, or the software was unable to improve the model fit. warning: called from fitBoosted at line 2583 column 11 ClassificationGAM at line 1308 column 9 fitcgam at line 226 column 3 __test__ at line 5 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 4134 column 2 ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = fitcgam (x, y); cvModel = crossval (a, 'LeaveOut', 'on'); assert_equal (class (cvModel), "ClassificationPartitionedModel"); assert_equal ({cvModel.X, cvModel.Y}, {x, y}); assert_equal (cvModel.NumObservations, 4); assert_equal (numel (cvModel.Trained), 4); assert_equal (class (cvModel.Trained{1}), "CompactClassificationGAM"); assert_equal (cvModel.CrossValidatedModel, "GAM"); ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = fitcknn (x, y); partition = cvpartition (y, 'KFold', 2); cvModel = ClassificationPartitionedModel (a, partition); assert_equal (class (cvModel), "ClassificationPartitionedModel"); assert_equal (class (cvModel.Trained{1}), "ClassificationKNN"); assert_equal (cvModel.NumObservations, 4); assert_equal (cvModel.ModelParameters.NumNeighbors, 1); assert_equal (cvModel.ModelParameters.NSMethod, "kdtree"); assert_equal (cvModel.ModelParameters.Distance, "euclidean"); assert_equal (isempty (cvModel.Trained{1}.Mu), true); ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = fitcknn (x, y, 'NSMethod', 'exhaustive'); partition = cvpartition (y, 'HoldOut', 0.2); cvModel = ClassificationPartitionedModel (a, partition); assert_equal (class (cvModel), "ClassificationPartitionedModel"); assert_equal (class (cvModel.Trained{1}), "ClassificationKNN"); assert_equal ({cvModel.X, cvModel.Y}, {x, y}); assert_equal (cvModel.NumObservations, 4); assert_equal (cvModel.ModelParameters.NumNeighbors, 1); assert_equal (cvModel.ModelParameters.NSMethod, "exhaustive"); assert_equal (cvModel.ModelParameters.Distance, "euclidean"); assert_equal (isempty (cvModel.Trained{1}.Mu), true); ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; k = 2; a = fitcknn (x, y, 'NumNeighbors' ,k); partition = cvpartition (numel (y), 'LeaveOut'); cvModel = ClassificationPartitionedModel (a, partition); assert_equal (class (cvModel), "ClassificationPartitionedModel"); assert_equal (class (cvModel.Trained{1}), "ClassificationKNN"); assert_equal ({cvModel.X, cvModel.Y}, {x, y}); assert_equal (cvModel.NumObservations, 4); assert_equal (cvModel.ModelParameters.NumNeighbors, k); assert_equal (cvModel.ModelParameters.NSMethod, "kdtree"); assert_equal (cvModel.ModelParameters.Distance, "euclidean"); assert_equal (isempty (cvModel.Trained{1}.Mu), true); ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = {'a'; 'a'; 'b'; 'b'}; a = fitcnet (x, y, 'IterationLimit', 50); cvModel = crossval (a, 'KFold', 2); assert_equal (class (cvModel), "ClassificationPartitionedModel"); assert_equal (cvModel.NumObservations, 4); assert_equal (numel (cvModel.Trained), 2); assert_equal (class (cvModel.Trained{1}), "CompactClassificationNeuralNetwork"); assert_equal (cvModel.CrossValidatedModel, "NeuralNetwork"); assert_equal (cvModel.KFold, 2); ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = {'a'; 'a'; 'b'; 'b'}; a = fitcnet (x, y, 'LayerSizes', [5, 3]); cvModel = crossval (a, 'LeaveOut', 'on'); assert_equal (class (cvModel), "ClassificationPartitionedModel"); assert_equal ({cvModel.X, cvModel.Y}, {x, y}); assert_equal (cvModel.NumObservations, 4); assert_equal (numel (cvModel.Trained), 4); assert_equal (class (cvModel.Trained{1}), "CompactClassificationNeuralNetwork"); assert_equal (cvModel.CrossValidatedModel, "NeuralNetwork"); ***** test load fisheriris inds = ! strcmp (species, 'setosa'); x = meas(inds, 3:4); y = grp2idx (species(inds)); SVMModel = fitcsvm (x,y); CVMdl = crossval (SVMModel, 'KFold', 5); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (CVMdl.KFold == 5, true) assert_equal (class (CVMdl.Trained{1}), "CompactClassificationSVM") assert_equal (CVMdl.CrossValidatedModel, "SVM"); ***** test load fisheriris inds = ! strcmp (species, 'setosa'); x = meas(inds, 3:4); y = grp2idx (species(inds)); obj = fitcsvm (x, y); CVMdl = crossval (obj, 'HoldOut', 0.2); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (class (CVMdl.Trained{1}), "CompactClassificationSVM") assert_equal (CVMdl.CrossValidatedModel, "SVM"); ***** test load fisheriris inds = ! strcmp (species, 'setosa'); x = meas(inds, 3:4); y = grp2idx (species(inds)); obj = fitcsvm (x, y); CVMdl = crossval (obj, 'LeaveOut', 'on'); assert_equal (class (CVMdl), "ClassificationPartitionedModel") assert_equal ({CVMdl.X, CVMdl.Y}, {x, y}) assert_equal (class (CVMdl.Trained{1}), "CompactClassificationSVM") assert_equal (CVMdl.CrossValidatedModel, "SVM"); ***** test load fisheriris CVMdl = crossval (fitcknn (meas, species), 'KFold', 5); assert_equal (CVMdl.CrossValidatedModel, "KNN"); ***** test # MATLAB parity: a cross-validated tree, over compact folds load fisheriris a = fitctree (meas, species); cvModel = crossval (a, 'KFold', 5); assert_equal (class (cvModel), "ClassificationPartitionedModel"); assert_equal (cvModel.CrossValidatedModel, "Tree"); assert_equal (class (cvModel.Trained{1}), "CompactClassificationTree"); assert_equal (cvModel.KFold, 5); assert_equal (cvModel.NumObservations, 150); assert_equal (cvModel.Prior, [1/3, 1/3, 1/3], 1e-15); assert_equal (cvModel.Cost, [0, 1, 1; 1, 0, 1; 1, 1, 0]); ***** test # A tree fold is grown with the parameters the parent was grown with load fisheriris a = fitctree (meas, species, 'SplitCriterion', 'deviance', ... 'MinLeafSize', 5, 'MaxNumSplits', 4); cvModel = crossval (a, 'KFold', 3); assert_equal (cvModel.ModelParameters.SplitCriterion, 'deviance'); assert_equal (cvModel.ModelParameters.MinLeaf, 5); assert_equal (cvModel.ModelParameters.MaxSplits, 4); assert_equal (sum (cvModel.Trained{1}.IsBranchNode) <= 4, true); ***** test # A tree fold carries the parent's classes, prior and cost load fisheriris a = fitctree (meas, species, 'Weights', (1:150)', ... 'Cost', [0, 1, 10; 1, 0, 1; 10, 1, 0]); cvModel = crossval (a, 'KFold', 3); assert_equal (cvModel.Trained{1}.Prior, a.Prior, 1e-15); assert_equal (cvModel.Trained{1}.Cost, a.Cost); assert_equal (cvModel.Trained{1}.ClassNames, a.ClassNames); ***** test # MATLAB parity: kfoldPredict costs a tree from its score load fisheriris cvModel = crossval (fitctree (meas, species), 'KFold', 5); [label, score, cost] = kfoldPredict (cvModel); assert_equal (size (label), [150, 1]); assert_equal (cost, score * cvModel.Cost, 1e-14); assert_equal (sum (score, 2), ones (150, 1), 1e-14); assert_equal (kfoldLoss (cvModel) < 0.2, true); assert_equal (size (kfoldMargin (cvModel)), [150, 1]); ***** test # kfoldPredict gives categorical labels for a categorical response load fisheriris c = cvpartition ('CustomPartition', repmat ((1:5)', 30, 1)); a = crossval (fitctree (meas, species), 'CVPartition', c); b = crossval (fitctree (meas, categorical (species)), 'CVPartition', c); label = kfoldPredict (b); assert_equal (class (label), 'categorical'); assert_equal (cellstr (label), kfoldPredict (a)); ***** test # kfoldPredict gives string labels for a string response load fisheriris c = cvpartition ('CustomPartition', repmat ((1:5)', 30, 1)); a = crossval (fitctree (meas, species), 'CVPartition', c); b = crossval (fitctree (meas, string (species)), 'CVPartition', c); label = kfoldPredict (b); assert_equal (class (label), 'string'); assert_equal (cellstr (label), kfoldPredict (a)); ***** test # a holdout leaves the rows no fold tested load fisheriris b = crossval (fitctree (meas, categorical (species)), 'Holdout', 0.2); assert_equal (sum (isundefined (kfoldPredict (b))), 120); ***** test k = (1:60)'; X = [mod(k*7,11)-5, mod(k*3,11)-5, mod(k*5,11)-5]; y = double (X(:,1).*X(:,2) > 0) + 1; Mdl = fitcgam (X, y, "Interactions", "all"); rand ("state", 1); cv = crossval (Mdl, "KFold", 3); assert_equal (numel (cv.Trained), 3); assert_equal (cv.Trained{1}.Interactions, [1, 2; 1, 3; 2, 3]); assert_equal (cv.Trained{3}.Interactions, Mdl.Interactions); ***** test load fisheriris b = ! strcmp (species, "setosa"); X = meas(b,:); Ys = species(b); Yc = char (Ys); rand ("state", 1); Mc = fitcdiscr (X, Yc); rand ("state", 1); Ms = fitcdiscr (X, Ys); rand ("state", 2); cvc = crossval (Mc, "KFold", 3); rand ("state", 2); cvs = crossval (Ms, "KFold", 3); p = kfoldPredict (cvc); assert_equal (columns (p), 10); assert_equal (cellstr (p), kfoldPredict (cvs)); ***** test # a GAM fold is fitted with the weights of the rows it holds k = (1:60)'; X = [sin(k), cos(2 * k)]; y = 2 * sin (k) + X(:,2) .^ 2 > 1; w = 1 + mod (k, 3); CVMdl = crossval (ClassificationGAM (X, y, 'Weights', w), 'KFold', 3); idx = training (CVMdl.Partition, 1); F = fitcgam (X(idx,:), y(idx), 'Weights', w(idx)); assert_equal (CVMdl.Trained{1}.Prior, F.Prior, 1e-12); assert_equal (CVMdl.Trained{1}.Intercept, F.Intercept, 1e-10); ***** error ... ClassificationPartitionedModel () ***** error ... ClassificationPartitionedModel (ClassificationKNN (ones (4,2), ones (4,1))) ***** error ... ClassificationPartitionedModel (RegressionGAM (ones (40,2), ... randi ([1, 2], 40, 1)), cvpartition (randi ([1, 2], 40, 1), 'Holdout', 0.3)) ***** error ... ClassificationPartitionedModel (ClassificationKNN (ones (4,2), ... ones (4,1)), 'Holdout') ***** test load fisheriris a = fitcdiscr (meas, species, 'gamma', 0.5, 'fillcoeffs', 'off'); cvModel = crossval (a, 'Kfold', 4); [label, score, cost] = kfoldPredict (cvModel); assert_equal (class (cvModel), "ClassificationPartitionedModel"); assert_equal ({cvModel.X, cvModel.Y}, {meas, species}); assert_equal (cvModel.NumObservations, 150); ***** # assert_equal (label, {"b"; "b"; "a"; "a"}); ***** # assert_equal (score, [4.5380e-01, 5.4620e-01; 2.4404e-01, 7.5596e-01; ... ***** # 9.9392e-01, 6.0844e-03; 9.9820e-01, 1.8000e-03], 1e-4); ***** # assert_equal (cost, [5.4620e-01, 4.5380e-01; 7.5596e-01, 2.4404e-01; ... ***** # 6.0844e-03, 9.9392e-01; 1.8000e-03, 9.9820e-01], 1e-4); ***** test x = ones (4, 11); y = {'a'; 'a'; 'b'; 'b'}; k = 3; a = fitcknn (x, y, 'NumNeighbors', k); partition = cvpartition (numel (y), 'LeaveOut'); cvModel = ClassificationPartitionedModel (a, partition); [label, score, cost] = kfoldPredict (cvModel); assert_equal (class (cvModel), "ClassificationPartitionedModel"); assert_equal ({cvModel.X, cvModel.Y}, {x, y}); assert_equal (cvModel.NumObservations, 4); assert_equal (cvModel.ModelParameters.NumNeighbors, k); assert_equal (cvModel.ModelParameters.NSMethod, "exhaustive"); assert_equal (cvModel.ModelParameters.Distance, "euclidean"); assert_equal (isempty (cvModel.Trained{1}.Mu), true); ## Each fold keeps the parent's prior, so a fold holding one 'a' and two ## 'b' rows gives the classes equal votes; values from R2024a. assert_equal (label, {'a'; 'a'; 'a'; 'a'}); assert_equal (score, 0.5 * ones (4, 2), 1e-15); assert_equal (cost, 0.5 * ones (4, 2), 1e-15); ***** test randn ('seed', 42); lab = double (randn (40, 1) > 0) + 1; X = [randn(40, 2); NaN, 1; 2, NaN]; Y = [lab; 1; 2]; Mdl = fitcsvm (X, Y); assert_equal (Mdl.NumObservations, 42); assert_equal (Mdl.RowsUsed, []); CVMdl = crossval (Mdl, 'KFold', 4); assert_equal (CVMdl.NumObservations, 42); assert_equal (rows (CVMdl.X), 42); assert_equal (rows (CVMdl.Y), 42); assert_equal (CVMdl.Partition.NumObservations, 42); assert_equal (numel (kfoldPredict (CVMdl)), 42); ***** test randn ('seed', 7); X = randn (60, 2); Y = [ones(20, 1); 2 * ones(40, 1)]; CVMdl = crossval (fitcsvm (X, Y), 'KFold', 4); for k = 1:4 idx = test (CVMdl.Partition, k); assert_equal (sum (CVMdl.Y(idx) == 1) >= 4, true); assert_equal (sum (CVMdl.Y(idx) == 2) >= 8, true); endfor ***** test load fisheriris X = meas(51:150,:); Y = species(51:150); rand ('seed', 42); cvp = cvpartition (Y, 'KFold', 5); for f = {'fitcsvm', 'fitcnet', 'fitcknn', 'fitcdiscr', 'fitcgam'} CVMdl = crossval (feval (f{1}, X, Y), 'CVPartition', cvp); assert_equal (kfoldLoss (CVMdl), ... mean (! strcmp (kfoldPredict (CVMdl), CVMdl.Y)), 1e-12); endfor ***** test load fisheriris idx = [51:75, 101:125]; CVMdl = crossval (fitcdiscr (meas(idx,:), species(idx)), 'Leaveout', 'on'); assert_equal (CVMdl.KFold, 50); assert_equal (kfoldLoss (CVMdl), 0.02, 1e-12); assert_equal (kfoldLoss (CVMdl, 'LossFun', 'classifcost'), 0.02, 1e-12); assert_equal (kfoldLoss (CVMdl, 'LossFun', 'mincost'), 0.02, 1e-12); ***** test load fisheriris X = meas(51:150,:); Y = species(51:150); rand ('seed', 42); cvp = cvpartition (Y, 'KFold', 5); CVMdl = crossval (fitcsvm (X, Y), 'CVPartition', cvp); L = kfoldLoss (CVMdl, 'Mode', 'individual'); assert_equal (size (L), [5, 1]); lab = kfoldPredict (CVMdl); k2 = test (cvp, 2); assert_equal (L(2), mean (! strcmp (lab(k2), CVMdl.Y(k2))), 1e-12); sel = test (cvp, 1) | test (cvp, 3); assert_equal (kfoldLoss (CVMdl, 'Folds', [1, 3]), ... mean (! strcmp (lab(sel), CVMdl.Y(sel))), 1e-12); assert_equal (numel (kfoldLoss (CVMdl, 'Folds', [2, 4], ... 'Mode', 'individual')), 2); assert_equal (kfoldLoss (CVMdl, 'LossFun', @(C, S, W, Cost) sum (W)), ... 1, 1e-12); ***** test load fisheriris X = meas(51:150,:); Y = species(51:150); rand ('seed', 42); CVMdl = crossval (fitcsvm (X, Y, 'Cost', [0, 4; 1, 0]), 'KFold', 5); assert_equal (CVMdl.Cost, [0, 4; 1, 0]); assert_equal (kfoldLoss (CVMdl, 'LossFun', 'classifcost') >= ... kfoldLoss (CVMdl, 'LossFun', 'classiferror'), true); ***** shared CVK load fisheriris rand ('seed', 42); CVK = crossval (fitcsvm (meas(51:150,:), species(51:150)), 'KFold', 4); ***** error ... kfoldLoss (CVK, 'Mode') ***** error ... kfoldLoss (CVK, 5, 1) ***** error ... kfoldLoss (CVK, 'LossFun', 5) ***** error ... kfoldLoss (CVK, 'LossFun', 'hinge') ***** error ... kfoldLoss (CVK, 'LossFun', @(C, S, W, Cost) [1, 2]) ***** error ... kfoldLoss (CVK, 'Mode', 'nope') ***** error ... kfoldLoss (CVK, 'Folds', 0) ***** error ... kfoldLoss (CVK, 'Nope', 1) ***** test load fisheriris X = meas(:,1:3); X(:,1) = X(:,1) * 1000; CVMdl = crossval (fitcknn (X, species, 'Standardize', true), 'KFold', 5); assert_equal (isempty (CVMdl.Trained{1}.Mu), false); ***** test load fisheriris X = meas(:,1:3); X(:,1) = X(:,1) * 1000; cvp = cvpartition (species, 'KFold', 5); CVMdl = crossval (fitcknn (X, species, 'Standardize', true), ... 'CVPartition', cvp); hit = 0; for k = 1:5 tr = training (cvp, k); te = test (cvp, k); Mdl = fitcknn (X(tr,:), species(tr), 'Standardize', true); hit += sum (strcmp (predict (Mdl, X(te,:)), species(te))); endfor assert_equal (sum (strcmp (kfoldPredict (CVMdl), species)), hit); ***** test load fisheriris Mdl = fitcknn (meas, species); CVMdl = crossval (Mdl, 'KFold', 3); assert_equal (CVMdl.W, Mdl.W); assert_equal (size (CVMdl.W), [150, 1]); ***** test load fisheriris CVMdl = crossval (fitcknn (meas, species), 'KFold', 3); assert_equal (class (CVMdl.BinEdges), 'cell'); assert_equal (CVMdl.BinEdges, {}); ***** test load fisheriris CVMdl = crossval (fitcdiscr (meas, species), 'KFold', 3); C = double (! eye (3)); C(1,2) = 4; CVMdl.Cost = C; assert_equal (CVMdl.Trained{1}.Cost, C); assert_equal (CVMdl.Trained{3}.Cost, C); ***** test load fisheriris CVMdl = crossval (fitcknn (meas, species), 'KFold', 3); C = double (! eye (3)); C(1,2) = 4; CVMdl.Cost = C; assert_equal (CVMdl.Trained{2}.Cost, C); ***** test load fisheriris CVMdl = crossval (fitcdiscr (meas, species), 'KFold', 3); CVMdl.Prior = [0.6, 0.2, 0.2]; assert_equal (CVMdl.Prior, [0.6, 0.2, 0.2], 1e-15); assert_equal (CVMdl.Trained{1}.Prior, [0.6, 0.2, 0.2], 1e-15); ***** test load fisheriris CVMdl = crossval (fitcnb (meas, species), 'KFold', 3); CVMdl.Prior = [0.6, 0.2, 0.2]; assert_equal (CVMdl.Prior, [0.6, 0.2, 0.2], 1e-15); assert_equal (CVMdl.Trained{1}.Prior, [0.6, 0.2, 0.2], 1e-15); ***** test load fisheriris X = meas(51:150,1:2); Y = species(51:150); CVMdl = crossval (fitcnb (X, Y), 'KFold', 5); before = kfoldPredict (CVMdl); CVMdl.Prior = [0.9, 0.1]; after = kfoldPredict (CVMdl); assert_equal (sum (! strcmp (before, after)) > 0, true); ***** test load fisheriris CVMdl = crossval (fitcdiscr (meas, species), 'KFold', 3); CVMdl.Prior = [3, 1, 1]; assert_equal (CVMdl.Prior, [0.6, 0.2, 0.2], 1e-15); ***** test load fisheriris CVMdl = crossval (fitcdiscr (meas, species), 'KFold', 3); CVMdl.Prior = 'uniform'; assert_equal (CVMdl.Prior, [1, 1, 1] / 3, 1e-15); ***** error ... load fisheriris; ... b = ismember (species, {'setosa', 'versicolor'}); ... CVMdl = crossval (fitcsvm (meas(b,:), species(b)), 'KFold', 3); ... CVMdl.Cost = [0, 4; 1, 0]; ***** error ... load fisheriris; ... CVMdl = crossval (fitcknn (meas, species), 'KFold', 3); ... CVMdl.Prior = [0.6, 0.2, 0.2]; ***** error ... load fisheriris; ... CVMdl = crossval (fitcnet (meas, species), 'KFold', 3); ... CVMdl.Prior = [0.6, 0.2, 0.2]; ***** error ... load fisheriris; ... CVMdl = crossval (fitcdiscr (meas, species), 'KFold', 3); ... CVMdl.Prior = [0.5, 0.5]; ***** test load fisheriris inds = ! strcmp (species, 'virginica'); CVMdl = crossval (fitcgam (meas(inds,:), species(inds)), 'KFold', 3); assert_equal (CVMdl.ScoreTransform, 'logit'); assert_equal (CVMdl.Trained{1}.ScoreTransform, 'none'); [~, s] = kfoldPredict (CVMdl); assert_equal (sum (s, 2), ones (rows (s), 1), 1e-12); ***** test load fisheriris CVMdl = crossval (fitcdiscr (meas, species), 'KFold', 3); [~, s0] = kfoldPredict (CVMdl); CVMdl.ScoreTransform = 'doublelogit'; [~, s1] = kfoldPredict (CVMdl); assert_equal (CVMdl.Trained{1}.ScoreTransform, 'none'); assert_equal (s1, 1 ./ (1 + exp (-2 * s0)), 1e-12); ***** test load fisheriris CVMdl = crossval (fitcdiscr (meas, species), 'KFold', 3); f = @(C, S, W, Cost) sum (S(:)); [~, s0] = kfoldPredict (CVMdl); assert_equal (kfoldLoss (CVMdl, 'LossFun', f), 150, 1e-12); CVMdl.ScoreTransform = 'doublelogit'; assert_equal (kfoldLoss (CVMdl, 'LossFun', f), ... sum (sum (1 ./ (1 + exp (-2 * s0)))), 1e-12); ***** test load fisheriris CVMdl = crossval (fitcknn (meas, species), 'KFold', 3); [~, s0] = kfoldPredict (CVMdl); CVMdl.ScoreTransform = 'none'; [~, s1] = kfoldPredict (CVMdl); assert_equal (s1, s0); ***** test load fisheriris CVMdl = crossval (fitcknn (meas, species, ... 'ScoreTransform', 'doublelogit'), 'KFold', 3); assert_equal (CVMdl.ScoreTransform, 'doublelogit'); assert_equal (CVMdl.Trained{1}.ScoreTransform, 'none'); ***** test load fisheriris CVMdl = crossval (fitcnet (meas, species, ... 'ScoreTransform', 'doublelogit'), 'KFold', 3); assert_equal (CVMdl.ScoreTransform, 'doublelogit'); assert_equal (CVMdl.Trained{1}.ScoreTransform, 'none'); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); CVMdl = crossval (fitcsvm (meas(inds,:), species(inds), ... 'ScoreTransform', 'doublelogit'), 'KFold', 3); assert_equal (CVMdl.ScoreTransform, 'doublelogit'); assert_equal (CVMdl.Trained{1}.ScoreTransform, 'none'); ***** test load fisheriris c = cvpartition (species, 'KFold', 3); CV0 = crossval (fitcknn (meas, species), 'CVPartition', c); CV1 = crossval (fitcknn (meas, species, ... 'ScoreTransform', 'doublelogit'), 'CVPartition', c); [~, s0] = kfoldPredict (CV0); [~, s1] = kfoldPredict (CV1); assert_equal (s1, 1 ./ (1 + exp (-2 * s0)), 1e-12); ***** test load fisheriris CVMdl = crossval (fitcnet (meas, species, ... 'ScoreTransform', 'doublelogit'), 'KFold', 3); [~, s1] = kfoldPredict (CVMdl); CVMdl.ScoreTransform = 'none'; [~, s0] = kfoldPredict (CVMdl); assert_equal (s1, 1 ./ (1 + exp (-2 * s0)), 1e-12); ***** error ... load fisheriris CVMdl = crossval (fitcdiscr (meas, species), 'KFold', 3); CVMdl.Cost = 1:9; ***** test assert_equal (any (strcmp (methods ("ClassificationPartitionedModel"), ... "foldLoss_")), false); ***** test load fisheriris CVMdl = crossval (fitcknn (meas, species), 'Leaveout', 'on'); m = kfoldMargin (CVMdl); assert_equal (size (m), [150, 1]); assert_equal (all (m >= -1 & m <= 1), true); ***** test load fisheriris CVMdl = crossval (fitcknn (meas, species), 'Leaveout', 'on'); assert_equal (kfoldEdge (CVMdl), 0.92, 1e-14); assert_equal (kfoldEdge (CVMdl), mean (kfoldMargin (CVMdl)), 1e-14); ***** test load fisheriris CVMdl = crossval (fitcdiscr (meas, species), 'KFold', 5); assert_equal (size (kfoldEdge (CVMdl, 'Mode', 'individual')), [5, 1]); assert_equal (isscalar (kfoldEdge (CVMdl, 'Mode', 'average')), true); ***** test load fisheriris CVMdl = crossval (fitcdiscr (meas, species), 'KFold', 5); m = kfoldMargin (CVMdl); idx = test (CVMdl.Partition, 2); assert_equal (kfoldEdge (CVMdl, 'Folds', 2), mean (m(idx)), 1e-12); assert_equal (kfoldEdge (CVMdl, 'Folds', 1:5), kfoldEdge (CVMdl), 1e-12); ***** error ... load fisheriris kfoldEdge (crossval (fitcdiscr (meas, species), 'KFold', 3), 'Mode') ***** error ... load fisheriris kfoldEdge (crossval (fitcdiscr (meas, species), 'KFold', 3), 5, 'average') ***** error ... load fisheriris CVMdl = crossval (fitcdiscr (meas, species), 'KFold', 3); kfoldEdge (CVMdl, 'Mode', 'cumulative') ***** error ... load fisheriris kfoldEdge (crossval (fitcdiscr (meas, species), 'KFold', 3), 'Folds', 7) ***** error ... load fisheriris kfoldEdge (crossval (fitcdiscr (meas, species), 'KFold', 3), 'bogus', 1) ***** test load fisheriris CVMdl = crossval (fitcdiscr (meas, species), 'Holdout', 0.2); idx = test (CVMdl.Partition, 1); [label, Score] = kfoldPredict (CVMdl); assert_equal (iscellstr (label), true); assert_equal (all (strcmp (label(! idx), '')), true); assert_equal (any (strcmp (label(idx), '')), false); assert_equal (all (all (isnan (Score(! idx, :)))), true); assert_equal (any (any (isnan (Score(idx, :)))), false); ***** test load fisheriris CVMdl = crossval (fitcdiscr (meas, species), 'Holdout', 0.2); idx = test (CVMdl.Partition, 1); label = kfoldPredict (CVMdl); assert_equal (label(idx), predict (CVMdl.Trained{1}, meas(idx,:))); assert_equal (mean (strcmp (label(idx), species(idx))) > 0.9, true); ***** test load fisheriris y = grp2idx (species); CVMdl = crossval (fitcdiscr (meas, y), 'Holdout', 0.2); idx = test (CVMdl.Partition, 1); label = kfoldPredict (CVMdl); assert_equal (all (isnan (label(! idx))), true); assert_equal (any (isnan (label(idx))), false); ***** test load fisheriris CVMdl = crossval (fitcdiscr (meas, species), 'Holdout', 0.2); idx = test (CVMdl.Partition, 1); label = kfoldPredict (CVMdl); assert_equal (kfoldLoss (CVMdl), ... mean (! strcmp (label(idx), species(idx))), 1e-12); m = kfoldMargin (CVMdl); assert_equal (all (isnan (m(! idx))), true); assert_equal (kfoldEdge (CVMdl), mean (m(idx)), 1e-12); ***** test load fisheriris Mdl = crossval (fitcdiscr (meas, species), 'KFold', 3); S = struct ('ClassNames', {{'virginica'; 'setosa'; 'versicolor'}}, ... 'ClassificationCosts', [0, 1, 2; 3, 0, 4; 5, 6, 0]); Mdl.Cost = S; assert_equal (Mdl.Cost, [0, 4, 3; 6, 0, 5; 1, 2, 0]); ***** error ... load fisheriris Mdl = crossval (fitcdiscr (meas, species), 'KFold', 3); Mdl.Cost = ones (3); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcgam (meas(inds,:), species(inds), 'FitMethod', 'boostedtrees'); CVMdl = crossval (Mdl, 'KFold', 3); assert_equal (class (CVMdl), 'ClassificationPartitionedModel'); assert_equal (numel (CVMdl.Trained), 3); assert_equal (CVMdl.Trained{1}.FitMethod, 'boostedtrees'); assert_equal (isempty (CVMdl.Trained{1}.TreeModel), false); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcgam (meas(inds,:), species(inds), 'FitMethod', 'boostedtrees'); CVMdl = crossval (Mdl, 'KFold', 3); assert_equal (CVMdl.ScoreTransform, 'logit'); assert_equal (CVMdl.Trained{1}.ScoreTransform, 'none'); [~, s] = kfoldPredict (CVMdl); assert_equal (sum (s, 2), ones (rows (s), 1), 1e-12); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcgam (meas(inds,:), species(inds), 'FitMethod', 'boostedtrees', ... 'Interactions', 2); CVMdl = crossval (Mdl, 'KFold', 3); assert_equal (rows (Mdl.Interactions), 2); assert_equal (rows (CVMdl.Trained{1}.Interactions), 2); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcgam (meas(inds,:), species(inds), 'FitMethod', 'splines', ... 'Knots', 4); CVMdl = crossval (Mdl, 'KFold', 3); assert_equal (CVMdl.Trained{1}.FitMethod, 'splines'); assert_equal (isfield (CVMdl.Trained{1}.BaseModel, 'Intercept'), true); ***** test ## kfoldfun hands the fold's model, its training data and its held-out ## data to the function, seven arguments in that order. load fisheriris CV = crossval (fitcknn (meas, species), "KFold", 3); seen = kfoldfun (CV, @(M, Xtr, Ytr, Wtr, Xte, Yte, Wte) ... [rows(Xtr), rows(Ytr), rows(Wtr), ... rows(Xte), rows(Yte), rows(Wte)]); assert_equal (size (seen), [3, 6]); ## the three training counts agree with each other, as do the three test ## counts, and each row accounts for every observation assert_equal (seen(:,1), seen(:,2)); assert_equal (seen(:,1), seen(:,3)); assert_equal (seen(:,4), seen(:,5)); assert_equal (seen(:,4), seen(:,6)); assert_equal (seen(:,1) + seen(:,4), repmat (150, 3, 1)); ***** test ## The result is one row per fold, whatever the width. load fisheriris CV = crossval (fitcknn (meas, species), "KFold", 4); assert_equal (size (kfoldfun (CV, @(varargin) 1)), [4, 1]); assert_equal (size (kfoldfun (CV, @(varargin) [1, 2, 3])), [4, 3]); ***** test ## The use it exists for: a count of errors on each held-out fold. load fisheriris CV = crossval (fitcknn (meas, species), "KFold", 3); f = @(M, Xtr, Ytr, Wtr, Xte, Yte, Wte) sum (! strcmp (predict (M, Xte), Yte)); n = kfoldfun (CV, f); assert_equal (size (n), [3, 1]); assert_equal (all (n >= 0 & n <= 150), true); ***** test ## The model handed over is the one the fold was fitted with. load fisheriris CV = crossval (fitcknn (meas, species), "KFold", 3); same = kfoldfun (CV, @(M, varargin) isequal (M, CV.Trained{1})); assert_equal (same(1), 1); ***** error ... kfoldfun (crossval (fitcknn (ones (6, 2), [1;1;1;2;2;2]), "KFold", 2)) ***** error ... kfoldfun (crossval (fitcknn (ones (6, 2), [1;1;1;2;2;2]), "KFold", 2), 42) ***** error ... kfoldfun (crossval (fitcknn (ones (6, 2), [1;1;1;2;2;2]), "KFold", 2), ... @(varargin) "x") ***** test load fisheriris CV = crossval (fitcknn (meas, species), "KFold", 3); g = @(M, Xtr, varargin) ones (1, rows (Xtr)); fail ("kfoldfun (CV, g)", ... "must return the same number of values for every fold"); ***** test ## The property order is MATLAB's, measured on R2024a. It is one list per ## class there and does not vary with the backing, so one fixture pins it. load fisheriris CVMdl = crossval (fitcknn (meas, species), "KFold", 3); assert_equal (sort (properties (CVMdl)), ... sort ({'ClassNames'; 'Cost'; 'Prior'; 'ScoreTransform'; ... 'CrossValidatedModel'; 'PredictorNames'; ... 'CategoricalPredictors'; 'ResponseName'; ... 'NumObservations'; 'X'; 'Y'; 'W'; ... 'ModelParameters'; 'Trained'; 'KFold'; 'Partition'; ... 'BinEdges'; 'NumTrainedPerFold'})); ***** test ## NumTrainedPerFold reports what each fold actually fitted, which the ## budget in ModelParameters does not: boosting stops early and the folds ## need not stop together. Structure and semantics follow R2024a; the ## counts do not and are not expected to, the engine being this package's. load fisheriris b = strcmp (species, "setosa"); CVMdl = crossval (fitcgam (meas(:,2:4), b), "KFold", 3); n = CVMdl.NumTrainedPerFold; assert_equal (isstruct (n), true); assert_equal (sort (fieldnames (n)), {"InteractionTrees"; "PredictorTrees"}); assert_equal (size (n.PredictorTrees), [1, 3]); assert_equal (size (n.InteractionTrees), [1, 3]); ## early stopping, so under the budget rather than at it assert_equal (all (n.PredictorTrees < CVMdl.ModelParameters.NumTreesPerPredictor), true); ## no interactions were asked for, so none were fitted assert_equal (n.InteractionTrees, [0, 0, 0]); ***** test ## A backing that fits no trees reports nothing rather than zero of them. load fisheriris CVMdl = crossval (fitcknn (meas, species), "KFold", 3); assert_equal (isempty (CVMdl.NumTrainedPerFold), true); ***** test ## Nor does a GAM fitted by splines, which counts no trees either. load fisheriris b = strcmp (species, "setosa"); Mdl = fitcgam (meas(1:30,2:4), b(1:30), "FitMethod", "splines"); CVMdl = crossval (Mdl, "KFold", 3); assert_equal (isempty (CVMdl.NumTrainedPerFold), true); ***** test load fisheriris Mdl = fitcsvm (meas, strcmp (species, 'setosa'), ... 'KernelFunction', 'polynomial', 'PolynomialOrder', 2); CVMdl = crossval (Mdl, 'KFold', 3); assert_equal (CVMdl.ModelParameters.KernelPolynomialOrder, 2); assert_equal (numel (CVMdl.Trained), 3); ***** test load fisheriris CVMdl = crossval (fitcsvm (meas, strcmp (species, 'setosa')), 'KFold', 3); MP = CVMdl.ModelParameters; assert_equal (MP.Method, 'PartitionedModel'); assert_equal (MP.Type, 'classification'); assert_equal (MP.Version, 1); assert_equal (MP.NLearn, 3); assert_equal (MP.SVMtype, 'c_svc'); ***** test load fisheriris CVMdl = crossval (fitcdiscr (meas, species, 'FillCoeffs', 'off'), ... 'KFold', 3); MP = CVMdl.ModelParameters; assert_equal (MP.FillCoeffs, false); assert_equal (MP.DiscrimType, 'linear'); assert_equal (MP.Method, 'PartitionedModel'); ***** test load fisheriris MP = crossval (fitcknn (meas, species, 'Distance', 'minkowski'), ... 'KFold', 3).ModelParameters; assert_equal (MP.Exponent, 2); assert_equal (MP.Method, 'PartitionedModel'); ***** test load fisheriris CVMdl = crossval (fitcnet (meas, strcmp (species, 'setosa'), ... 'Cost', [0, 2; 5, 0]), 'KFold', 3); [label, score, cost] = kfoldPredict (CVMdl); assert_equal (size (cost), [150, 2]); assert_equal (cost, score * [0, 2; 5, 0], 1e-12); ***** test load fisheriris CVMdl = crossval (fitcnet (meas, species), 'KFold', 3); [~, score, cost] = kfoldPredict (CVMdl); assert_equal (cost, 1 - score, 1e-12); ***** error ... load fisheriris; ... [l, s, c] = kfoldPredict (crossval (fitcgam (meas, strcmp (species, 'setosa')), 'KFold', 3)) ***** test load fisheriris CVMdl = crossval (fitcsvm (meas, strcmp (species, 'setosa'), ... 'Cost', [0, 2; 5, 0]), 'KFold', 3); [~, ~, cost] = kfoldPredict (CVMdl); assert_equal (size (cost), [150, 2]); assert_equal (unique (cost, 'rows'), [0, 2; 5, 0]); ***** test load fisheriris Mdl = crossval (fitcknn (meas, species), 'KFold', 3); Mdl.ScoreTransform = 'none'; [label, raw] = kfoldPredict (Mdl); T = {'identity', @(x) x; 'doublelogit', @(x) 1 ./ (1 + exp (-2 * x)); ... 'invlogit', @(x) log (x ./ (1 - x)); ... 'logit', @(x) 1 ./ (1 + exp (-x)); ... 'sign', @(x) sign (x); 'symmetric', @(x) 2 * x - 1; ... 'symmetriclogit', @(x) 2 ./ (1 + exp (-x)) - 1}; for i = 1:rows (T) Mdl.ScoreTransform = T{i,1}; [l, s] = kfoldPredict (Mdl); assert_equal (s, T{i,2}(raw), 1e-12); assert_equal (l, label); endfor ## ismax marks the largest score of each observation, ties to the first. [~, k] = max (raw, [], 2); e = zeros (size (raw)); e(sub2ind (size (raw), (1:rows (raw))', k)) = 1; Mdl.ScoreTransform = 'ismax'; [~, s] = kfoldPredict (Mdl); assert_equal (s, e); Mdl.ScoreTransform = 'symmetricismax'; [~, s] = kfoldPredict (Mdl); assert_equal (s, 2 * e - 1); ***** test load fisheriris Mdl = crossval (fitcknn (meas, species), 'KFold', 3); Mdl.ScoreTransform = 'none'; [label, raw] = kfoldPredict (Mdl); Mdl.ScoreTransform = @(x) x .^ 2; [l, s] = kfoldPredict (Mdl); assert_equal (s, raw .^ 2, 1e-12); assert_equal (l, label); ***** test load fisheriris b = strcmp (species, 'setosa'); CVMdl = crossval (fitcgam (meas, b, 'Prior', [0.3, 0.7]), 'KFold', 3); for k = 1:3 tr = training (CVMdl.Partition, k); n = [sum(b(tr) == 0), sum(b(tr) == 1)]; w = [0.3, 0.7] .* (n ./ [100, 50]); assert_equal (CVMdl.Trained{k}.Prior, w ./ sum (w), 1e-12); endfor ***** test load fisheriris b = strcmp (species, 'setosa'); CVMdl = crossval (fitcgam (meas, b), 'KFold', 3); for k = 1:3 tr = training (CVMdl.Partition, k); n = [sum(b(tr) == 0), sum(b(tr) == 1)]; assert_equal (CVMdl.Trained{k}.Prior, n ./ sum (n), 1e-12); endfor ***** error load fisheriris CVMdl = crossval (fitctree (meas, species), 'KFold', 3); CVMdl.Cost = [0, 2, 8; 3, 0, 1; 5, 4, 0]; ***** test ## A naive Bayes fold is fitted with its rows' weights load fisheriris w = 1 + (1:150)' / 7; CVMdl = crossval (fitcnb (meas, species, 'Weights', w), 'KFold', 3); idx = training (CVMdl.Partition, 1); Mdl = fitcnb (meas(idx,:), species(idx), 'Weights', w(idx)); assert_equal (CVMdl.Trained{1}.DistributionParameters, ... Mdl.DistributionParameters, 1e-12); ***** test ## A neural network fold is fitted with its rows' weights load fisheriris w = 1 + (1:150)' / 7; Mdl = fitcnet (meas, species, 'LayerSizes', 3, 'Weights', w); rand ('seed', 7); CVMdl = crossval (Mdl, 'KFold', 3); idx = training (CVMdl.Partition, 1); rand ('seed', 7); cvpartition (150, 'KFold', 3); F = fitcnet (meas(idx,:), species(idx), 'LayerSizes', 3, ... 'Weights', Mdl.W(idx), 'Prior', Mdl.Prior); assert_equal (nthargout (2, @predict, CVMdl.Trained{1}, meas), ... nthargout (2, @predict, F, meas), 1e-10); 115 tests, 115 passed, 0 known failure, 0 skipped [inst/Machine_Learning/TreeBagger.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/TreeBagger.m ***** demo ## Grow a random forest on the iris data, estimate its error from the ## observations each tree left out, and classify a new flower. load fisheriris rng (42); B = TreeBagger (50, meas, species, 'OOBPrediction', 'on'); err = oobError (B); err(end) label = predict (B, [5.8, 2.8, 4.5, 1.4]) ***** demo ## A regression forest predicting sepal length from the other three ## measurements, with the spread of its trees around each prediction. load fisheriris rng (42); B = TreeBagger (50, meas(:,2:4), meas(:,1), 'Method', 'regression'); [yfit, sd] = predict (B, meas([1, 51, 101], 2:4)) ***** demo ## A 90% prediction interval for sepal length from the other three ## measurements, read off the quantiles of a regression forest. load fisheriris rng (42); B = TreeBagger (100, meas(:,2:4), meas(:,1), 'Method', 'regression'); q = quantilePredict (B, meas([1, 51, 101], 2:4), ... 'Quantile', [0.05, 0.5, 0.95]) ***** demo ## Which measurements a forest relies on: permuting a petal measurement ## among each tree's out-of-bag flowers raises the error the most. load fisheriris rng (42); B = TreeBagger (50, meas, species, 'OOBPredictorImportance', 'on'); bar (B.OOBPermutedPredictorDeltaError); set (gca, 'xticklabel', {'SL', 'SW', 'PL', 'PW'}); ylabel ('Rise in out-of-bag error'); ***** demo ## Scale the proximities of a random forest to two dimensions and draw ## the flowers one color per species. load fisheriris rng (42); B = fillprox (TreeBagger (50, meas, species)); mdsprox (B, 'Colors', 'rgb'); ***** test # MATLAB parity: the defaults of a classification ensemble load fisheriris rng (1); B = TreeBagger (5, meas, species); assert_equal (B.NumTrees, 5); assert_equal (B.Method, 'classification'); assert_equal (B.NumPredictorsToSample, 2); assert_equal (B.MinLeafSize, 1); assert_equal (B.InBagFraction, 1); assert_equal (B.SampleWithReplacement, true); assert_equal (B.ComputeOOBPrediction, false); assert_equal (B.MergeLeaves, false); assert_equal (B.Prune, false); assert_equal (B.TreeArguments, {}); assert_equal (class (B.Trees{1}), 'CompactClassificationTree'); ***** test # MATLAB parity: the number of predictors sampled by default rng (1); X5 = rand (30, 5); X7 = rand (30, 7); y = [ones(15, 1); 2 * ones(15, 1)]; assert_equal (TreeBagger (1, X5, y).NumPredictorsToSample, 3); assert_equal (TreeBagger (1, X7, y).NumPredictorsToSample, 3); r = rand (30, 1); assert_equal (TreeBagger (1, X5, r, 'Method', ... 'regression').NumPredictorsToSample, 2); assert_equal (TreeBagger (1, X7, r, 'Method', ... 'regression').NumPredictorsToSample, 3); ***** test # MATLAB parity: a regression leaf holds five observations by default rng (1); B = TreeBagger (1, rand (30, 3), rand (30, 1), 'Method', 'regression'); assert_equal (B.MinLeafSize, 5); assert_equal (class (B.Trees{1}), 'CompactRegressionTree'); ***** test # MATLAB parity: without sampling a tree is the single tree load fisheriris B = TreeBagger (2, meas, species, 'SampleWithReplacement', 'off', ... 'InBagFraction', 1, 'NumPredictorsToSample', 'all'); T = ClassificationTree (meas, species, 'Prune', 'off', ... 'MergeLeaves', 'off', 'MinParentSize', 2); assert_equal (B.Trees{2}.NumNodes, 17); assert_equal (B.Trees{2}.CutPredictorIndex, T.CutPredictorIndex); assert_equal (isequaln (B.Trees{2}.CutPoint, T.CutPoint), true); ***** test # MATLAB parity: without sampling a regression tree is the single tree load fisheriris B = TreeBagger (1, meas(:,2:4), meas(:,1), 'Method', 'regression', ... 'SampleWithReplacement', 'off', 'InBagFraction', 1, ... 'NumPredictorsToSample', 'all'); T = RegressionTree (meas(:,2:4), meas(:,1), 'Prune', 'off', ... 'MergeLeaves', 'off', 'MinLeafSize', 5); assert_equal (B.Trees{1}.NumNodes, 47); assert_equal (isequaln (B.Trees{1}.CutPoint, T.CutPoint), true); ***** test # MATLAB parity: scores average the trees and deviations divide by N load fisheriris rng (1); B = TreeBagger (10, meas, species, 'MinLeafSize', 5); [~, s, sd] = predict (B, meas); S = zeros (150, 3, 10); for t = 1:10 [~, st] = predict (B.Trees{t}, meas); S(:, B.TreeClassIdx{t}, t) = st; endfor assert_equal (s, mean (S, 3), 1e-14); assert_equal (sd, std (S, 1, 3), 1e-12); ***** test # MATLAB parity: a regression forest averages its trees load fisheriris rng (1); B = TreeBagger (10, meas(:,2:4), meas(:,1), 'Method', 'regression'); [yfit, sd] = predict (B, meas(:,2:4)); R = zeros (150, 10); for t = 1:10 R(:,t) = predict (B.Trees{t}, meas(:,2:4)); endfor assert_equal (yfit, mean (R, 2), 1e-12); assert_equal (sd, std (R, 1, 2), 1e-12); ***** test # MATLAB parity: the label is the class of highest score under a cost load fisheriris rng (1); B = TreeBagger (10, meas, species, 'MinLeafSize', 15, ... 'Cost', [0, 1, 1; 20, 0, 1; 1, 1, 0]); [label, s] = predict (B, meas); [~, k] = max (s, [], 2); assert_equal (label, B.ClassNames(k)); ***** test # labels take the type of the response, where MATLAB gives cellstr load fisheriris rng (1); B = TreeBagger (3, meas, categorical (species)); assert_equal (class (predict (B, meas(1,:))), 'categorical'); assert_equal (class (B.ClassNames), 'categorical'); assert_equal (class (B.DefaultYfit), 'categorical'); ***** test # MATLAB parity: a sample holds ceil (InBagFraction * N) observations load fisheriris rng (1); B = TreeBagger (1, meas, species, 'InBagFraction', 0.334); assert_equal (B.Trees{1}.NodeSize(1), 51); ***** test # MATLAB parity: the default class is the class of most weight load fisheriris w = [20 * ones(20, 1); ones(100, 1)]; B = TreeBagger (1, meas([1:20, 51:150],:), species([1:20, 51:150]), ... 'Weights', w); assert_equal (B.DefaultYfit, {'setosa'}); assert_equal (sum (B.W), 1, 1e-15); ***** test # MATLAB parity: the regression default is the weighted mean load fisheriris w = [5 * ones(50, 1); ones(100, 1)]; B = TreeBagger (1, meas(:,2:4), meas(:,1), 'Method', 'regression', ... 'Weights', w); assert_equal (B.DefaultYfit, sum (w .* meas(:,1)) / sum (w), 1e-12); ***** test # MATLAB parity: a missing response drops its row, a missing X does not load fisheriris y = meas(:,1); y([3, 7]) = NaN; X = meas(:,2:4); X(5, 1) = NaN; B = TreeBagger (1, X, y, 'Method', 'regression', 'OOBPrediction', 'on'); assert_equal (size (B.X), [148, 3]); assert_equal (size (B.OOBIndices), [148, 1]); ***** test # MATLAB parity: 'ClassNames' keeps its order and drops other classes load fisheriris B = TreeBagger (1, meas, species, 'ClassNames', {'virginica'; 'setosa'}); assert_equal (B.ClassNames, {'virginica'; 'setosa'}); assert_equal (rows (B.X), 100); ***** test # MATLAB parity: the out-of-bag error in its three modes load fisheriris rng (1); B = TreeBagger (8, meas, species, 'OOBPrediction', 'on', 'MinLeafSize', 5); e = oobError (B); assert_equal (size (e), [8, 1]); assert_equal (size (oobError (B, 'Mode', 'individual')), [8, 1]); assert_equal (e(end), oobError (B, 'Mode', 'ensemble'), 1e-15); assert_equal (B.OOBInstanceWeight, sum (B.OOBIndices, 2)); ***** test # MATLAB parity: a tree judged alone gives its sample the default load fisheriris rng (1); B = TreeBagger (4, meas, species, 'OOBPrediction', 'on', 'MinLeafSize', 5); l = predict (B.Trees{3}, meas); l(! B.OOBIndices(:,3)) = B.DefaultYfit; e = oobError (B, 'Mode', 'individual'); assert_equal (e(3), sum (B.W .* ! strcmp (l, species)), 1e-14); ***** test # MATLAB parity: an observation in every sample takes the default load fisheriris rng (5); B = TreeBagger (1, meas, species, 'OOBPrediction', 'on', 'MinLeafSize', 15); r = find (! B.OOBIndices, 1); [label, s] = oobPredict (B); assert_equal (label(r), B.DefaultYfit); assert_equal (s(r,:), B.Prior, 1e-15); ***** test # MATLAB parity: margins by tree and their means load fisheriris rng (1); B = TreeBagger (6, meas, species, 'OOBPrediction', 'on'); assert_equal (size (margin (B, meas, species)), [150, 6]); assert_equal (size (meanMargin (B, meas, species)), [1, 6]); assert_equal (size (oobMargin (B)), [150, 6]); assert_equal (size (oobMeanMargin (B, 'Mode', 'ensemble')), [1, 1]); ***** test # MATLAB parity: weights make the error a weighted share load fisheriris rng (1); B = TreeBagger (6, meas, species, 'MinLeafSize', 15); w = [5 * ones(50, 1); ones(100, 1)]; miss = ! strcmp (predict (B, meas), species); e = error (B, meas, species, 'Mode', 'ensemble', 'Weights', w); assert_equal (e, sum (w .* miss) / sum (w), 1e-15); ***** test # MATLAB parity: an observation no tree may use takes the default load fisheriris rng (1); B = TreeBagger (4, meas, species); U = true (2, 4); U(1,:) = false; [label, s, sd] = predict (B, meas(1:2,:), 'UseInstanceForTree', U); assert_equal (label(1), B.DefaultYfit); assert_equal (s(1,:), B.Prior, 1e-15); assert_equal (sd(1,:), NaN (1, 3)); ***** test # tree weights give a weighted average of the trees chosen load fisheriris rng (1); B = TreeBagger (6, meas, species, 'MinLeafSize', 15); [~, s] = predict (B, meas(1:5,:), 'Trees', [2, 5], 'TreeWeights', [3, 1]); [~, a] = predict (B.Trees{2}, meas(1:5,:)); [~, b] = predict (B.Trees{5}, meas(1:5,:)); A = zeros (5, 3); A(:, B.TreeClassIdx{2}) = a; Bs = zeros (5, 3); Bs(:, B.TreeClassIdx{5}) = b; assert_equal (s, (3 * A + Bs) / 4, 1e-15); ***** test # the state of the generator reproduces an ensemble load fisheriris rng (3); A = TreeBagger (3, meas, species, 'OOBPrediction', 'on'); rng (3); B = TreeBagger (3, meas, species, 'OOBPrediction', 'on'); assert_equal (A.OOBIndices, B.OOBIndices); assert_equal (A.Trees{3}.CutPredictorIndex, B.Trees{3}.CutPredictorIndex); ***** test # MATLAB parity: growing and appending extend the out-of-bag matrix load fisheriris rng (1); B = TreeBagger (3, meas, species, 'OOBPrediction', 'on'); B = growTrees (B, 2); assert_equal (B.NumTrees, 5); assert_equal (size (B.OOBIndices), [150, 5]); B = append (B, TreeBagger (2, meas, species, 'OOBPrediction', 'on')); assert_equal (B.NumTrees, 7); assert_equal (size (B.OOBIndices), [150, 7]); ***** test # MATLAB parity: the tree options given are kept as given load fisheriris B = TreeBagger (1, meas, species, 'MinLeafSize', 3, 'MaxNumSplits', 7); assert_equal (B.TreeArguments, {'MinLeafSize', 3, 'MaxNumSplits', 7}); ***** test # MATLAB parity: progress is printed after every NumPrint trees load fisheriris out = evalc ("TreeBagger (2, meas, species, 'NumPrint', 1);"); assert_equal (out, sprintf ("Tree 1 done.\nTree 2 done.\n")); ***** warning ... TreeBagger (1, [1; 2; 3; 4], [1; 1; 2; 2], 'MergeLeaves', 'on'); ***** test # MATLAB parity: the split statistics of a regression ensemble load fisheriris B = TreeBagger (2, meas(:,2:4), meas(:,1), 'Method', 'regression', ... 'SampleWithReplacement', 'off', 'InBagFraction', 1, ... 'NumPredictorsToSample', 'all'); assert_equal (B.DeltaCriterionDecisionSplit, ... [0.001540487516843, 0.025160029558674, ... 0.000497162933685], 1e-14); assert_equal (B.NumPredictorSplit, ... [0.521739130434783, 1.043478260869565, ... 0.434782608695652], 1e-14); assert_equal (B.SurrogateAssociation, eye (3)); ***** test # MATLAB parity: the split statistics of a classification ensemble load fisheriris B = TreeBagger (2, meas, species, 'SampleWithReplacement', 'off', ... 'InBagFraction', 1, 'NumPredictorsToSample', 'all', ... 'MinLeafSize', 5); assert_equal (B.DeltaCriterionDecisionSplit, ... [0.000477777777778, 0, 0.072985238862050, ... 0.051959205582394], 1e-14); assert_equal (B.NumPredictorSplit, [0.4, 0, 1.2, 0.4], 1e-14); ***** test # MATLAB parity: split statistics are per-tree shares and means load fisheriris rng (1); B = growTrees (TreeBagger (3, meas, species), 2); n = zeros (1, 4); d = zeros (1, 4); for t = 1:5 tr = B.Trees{t}; br = find (tr.Children(:,1) > 0); n += accumarray (tr.CutPredictorIndex(br), 1, [4, 1])' / numel (br); d += predictorImportance (tr) / 5; endfor assert_equal (B.NumPredictorSplit, n, 1e-14); assert_equal (B.DeltaCriterionDecisionSplit, d, 1e-14); ***** test # MATLAB parity: a tree without splits adds nothing to the statistics load fisheriris B = TreeBagger (3, meas, species, 'MinLeafSize', 100); assert_equal (B.NumPredictorSplit, zeros (1, 4)); assert_equal (B.DeltaCriterionDecisionSplit, zeros (1, 4)); ***** test # MATLAB parity: the quantiles of a regression ensemble load fisheriris B = TreeBagger (2, meas(:,2:4), meas(:,1), 'Method', 'regression', ... 'SampleWithReplacement', 'off', 'InBagFraction', 1, ... 'NumPredictorsToSample', 'all'); q = quantilePredict (B, meas([1, 51, 101, 150], 2:4), ... 'Quantile', [0, 0.05, 0.25, 0.5, 0.75, 0.95, 1]); assert_equal (q, [4.6, 4.6, 4.9, 5.0, 5.1, 5.5, 5.5; ... 6.4, 6.4, 6.625, 6.7, 6.925, 7.0, 7.0; ... 6.3, 6.3, 6.45, 6.7, 6.825, 6.9, 6.9; ... 5.9, 5.9, 5.975, 6.1, 6.225, 6.3, 6.3], 1e-14); ***** test # MATLAB parity: observation weights enter only through the sample load fisheriris w = [10 * ones(50, 1); ones(100, 1)]; B = TreeBagger (1, meas(:,2:4), meas(:,1), 'Method', 'regression', ... 'SampleWithReplacement', 'off', 'InBagFraction', 1, ... 'NumPredictorsToSample', 'all', 'Weights', w); q = quantilePredict (B, meas([1, 51, 101], 2:4), ... 'Quantile', [0.25, 0.5, 0.75]); assert_equal (q, [4.9, 5.0, 5.1; 6.625, 6.7, 6.925; ... 6.45, 6.7, 6.825], 1e-14); ***** test # response weights are sample counts over leaf sizes, averaged load fisheriris rng (1); B = TreeBagger (4, meas(:,2:4), meas(:,1), 'Method', 'regression'); [~, YW] = quantilePredict (B, meas(1:3,2:4)); W = zeros (150, 3); for t = 1:4 [~, ntr] = predict (B.Trees{t}, B.X); [~, nq] = predict (B.Trees{t}, meas(1:3,2:4)); for k = 1:3 in = (ntr == nq(k)) .* full (B.InBag(:,t)); W(:,k) += in / B.Trees{t}.NodeSize(nq(k)) / 4; endfor endfor assert_equal (issparse (YW), true); assert_equal (full (YW), W, 1e-15); ***** test # quantiles interpolate sorted responses at mid cumulative weights load fisheriris rng (1); B = TreeBagger (5, meas(:,2:4), meas(:,1), 'Method', 'regression'); tau = [0.001, 0.3, 0.62, 0.999]; [q, YW] = quantilePredict (B, meas(7,2:4), 'Quantile', tau); [i, ~, w] = find (YW); [ys, o] = sort (B.Y(i)); w = w(o); F = cumsum (w) - w / 2; e = interp1 (F, ys, tau); e(tau <= F(1)) = ys(1); e(tau >= F(end)) = ys(end); assert_equal (q, e, 1e-14); ***** test # MATLAB parity: a row no tree may answer for takes the sample quantile load fisheriris rng (1); B = TreeBagger (3, meas(:,2:4), meas(:,1), 'Method', 'regression'); U = true (2, 3); U(1,:) = false; [q, YW] = quantilePredict (B, meas(1:2,2:4), ... 'Quantile', [0.1, 0.5, 0.9], ... 'UseInstanceForTree', U); assert_equal (q(1,:), [4.8, 5.8, 6.9], 1e-14); assert_equal (full (YW(:,1)), ones (150, 1) / 150, 1e-15); ***** test # MATLAB parity: an observation in every bag takes the sample quantile load fisheriris rng (22); B = TreeBagger (1, meas(:,2:4), meas(:,1), 'Method', 'regression', ... 'OOBPrediction', 'on'); r = find (! B.OOBIndices, 1); q = oobQuantilePredict (B, 'Quantile', [0.1, 0.5, 0.9]); assert_equal (q(r,:), [4.8, 5.8, 6.9], 1e-14); ***** test # out-of-bag quantiles use only the trees that left a row out load fisheriris rng (1); B = TreeBagger (6, meas(:,2:4), meas(:,1), 'Method', 'regression', ... 'OOBPrediction', 'on'); tau = [0.2, 0.8]; [qo, Wo] = oobQuantilePredict (B, 'Quantile', tau); [q, W] = quantilePredict (B, B.X, 'Quantile', tau, ... 'UseInstanceForTree', B.OOBIndices); assert_equal (qo, q); assert_equal (Wo, W); ***** test # MATLAB parity: the quantile loss is the mean pinball loss load fisheriris B = TreeBagger (2, meas(:,2:4), meas(:,1), 'Method', 'regression', ... 'SampleWithReplacement', 'off', 'InBagFraction', 1, ... 'NumPredictorsToSample', 'all'); e = quantileError (B, meas(:,2:4), meas(:,1), 'Quantile', [0.25, 0.5, 0.9]); assert_equal (e, [0.069916666666667, 0.088666666666667, ... 0.035026666666667], 1e-14); ***** test # MATLAB parity: the quantile loss weighs the observations load fisheriris B = TreeBagger (2, meas(:,2:4), meas(:,1), 'Method', 'regression', ... 'SampleWithReplacement', 'off', 'InBagFraction', 1, ... 'NumPredictorsToSample', 'all'); w = [5 * ones(50, 1); ones(100, 1)]; e = quantileError (B, meas(:,2:4), meas(:,1), 'Quantile', [0.25, 0.9], ... 'Weights', w); assert_equal (e, [0.064821428571429, 0.036268571428571], 1e-14); ***** test # MATLAB parity: the three modes of the quantile loss load fisheriris rng (1); B = TreeBagger (4, meas(:,2:4), meas(:,1), 'Method', 'regression'); X = meas(:,2:4); y = meas(:,1); tau = [0.25, 0.75]; e = quantileError (B, X, y, 'Quantile', tau); c = quantileError (B, X, y, 'Quantile', tau, 'Mode', 'cumulative'); i = quantileError (B, X, y, 'Quantile', tau, 'Mode', 'individual'); assert_equal (size (e), [1, 2]); assert_equal (size (c), [4, 2]); assert_equal (c(end,:), e, 1e-15); assert_equal (i(3,:), quantileError (B, X, y, 'Quantile', tau, ... 'Trees', 3), 1e-15); ***** test # MATLAB parity: the out-of-bag quantile loss in ensemble mode load fisheriris rng (1); B = TreeBagger (6, meas(:,2:4), meas(:,1), 'Method', 'regression', ... 'OOBPrediction', 'on'); tau = [0.1, 0.5, 0.9]; d = B.Y - oobQuantilePredict (B, 'Quantile', tau); L = mean (max (tau .* d, (tau - 1) .* d)); assert_equal (oobQuantileError (B, 'Quantile', tau), L, 1e-15); assert_equal (size (oobQuantileError (B, 'Mode', 'cumulative')), [6, 1]); ***** test # each tree's out-of-bag quantile loss is on its own out-of-bag rows load fisheriris rng (1); B = TreeBagger (3, meas(:,2:4), meas(:,1), 'Method', 'regression', ... 'OOBPrediction', 'on'); e = oobQuantileError (B, 'Mode', 'individual'); r = B.OOBIndices(:,2); d = B.Y(r) - quantilePredict (B, B.X(r,:), 'Trees', 2); assert_equal (size (e), [3, 1]); assert_equal (e(2), mean (abs (d)) / 2, 1e-15); ***** test # MATLAB parity: out-of-bag importance turns out-of-bag prediction on load fisheriris rng (1); B = TreeBagger (3, meas, species, 'OOBPredictorImportance', 'on'); assert_equal (B.ComputeOOBPrediction, true); assert_equal (B.ComputeOOBPredictorImportance, true); assert_equal (size (B.OOBPermutedPredictorDeltaError), [1, 4]); assert_equal (size (B.OOBPermutedPredictorDeltaMeanMargin), [1, 4]); assert_equal (size (B.OOBPermutedPredictorCountRaiseMargin), [1, 4]); ***** test # MATLAB parity: a regression ensemble has no margin importances load fisheriris rng (1); B = TreeBagger (3, meas(:,2:4), meas(:,1), 'Method', 'regression', ... 'OOBPredictorImportance', 'on'); assert_equal (size (B.OOBPermutedPredictorDeltaError), [1, 3]); assert_equal (B.OOBPermutedPredictorDeltaMeanMargin, zeros (1, 0)); assert_equal (B.OOBPermutedPredictorCountRaiseMargin, zeros (1, 0)); ***** test # MATLAB parity: importance is the mean change over its deviation load fisheriris rng (1); B = TreeBagger (5, meas, species, 'OOBPredictorImportance', 'on'); D = B.PermDelta; assert_equal (B.OOBPermutedPredictorDeltaError, ... mean (D(:,:,1)) ./ std (D(:,:,1)), 1e-14); assert_equal (B.OOBPermutedPredictorDeltaMeanMargin, ... mean (D(:,:,2)) ./ std (D(:,:,2)), 1e-14); assert_equal (B.OOBPermutedPredictorCountRaiseMargin, ... mean (D(:,:,3)) ./ std (D(:,:,3)), 1e-14); ***** test # MATLAB parity: a predictor no tree splits on has zero importance load fisheriris rng (1); B = TreeBagger (10, [meas, ones(150, 1)], species, ... 'OOBPredictorImportance', 'on'); assert_equal (B.NumPredictorSplit(5), 0); assert_equal (B.OOBPermutedPredictorDeltaError(5), 0); assert_equal (B.OOBPermutedPredictorDeltaMeanMargin(5), 0); assert_equal (B.OOBPermutedPredictorCountRaiseMargin(5), 0); ***** test # MATLAB parity: the importance of a single tree is zero or infinite load fisheriris rng (9); B = TreeBagger (1, meas, species, 'OOBPredictorImportance', 'on'); imp = B.OOBPermutedPredictorDeltaError; assert_equal (all (imp == 0 | isinf (imp)), true); ***** test # MATLAB parity: permuting a petal measurement matters most load fisheriris rng (1); B = TreeBagger (30, meas, species, 'OOBPredictorImportance', 'on'); imp = B.OOBPermutedPredictorDeltaError; assert_equal (min (imp(3:4)) > max (imp(1:2)), true); assert_equal (all (B.OOBPermutedPredictorCountRaiseMargin(3:4) > 0), true); ***** test # growing and appending extend the importances load fisheriris rng (1); B = TreeBagger (3, meas, species, 'OOBPredictorImportance', 'on'); B = growTrees (B, 2); assert_equal (size (B.PermDelta), [5, 4, 3]); B = append (B, TreeBagger (2, meas, species, ... 'OOBPredictorImportance', 'on')); assert_equal (size (B.PermDelta), [7, 4, 3]); D = B.PermDelta(:,:,1); assert_equal (B.OOBPermutedPredictorDeltaError, mean (D) ./ std (D), 1e-14); ***** test # MATLAB parity: the proximity of the training observations load fisheriris B = TreeBagger (2, meas, species, 'SampleWithReplacement', 'off', ... 'InBagFraction', 1, 'NumPredictorsToSample', 'all', ... 'MinLeafSize', 5); B = fillprox (B); k = [1, 51, 101, 150]; assert_equal (B.Proximity(k,k), [1, 0, 0, 0; 0, 1, 0, 0; ... 0, 0, 1, 1; 0, 0, 1, 1]); ***** test # MATLAB parity: fillprox over chosen trees load fisheriris rng (1); B = fillprox (TreeBagger (6, meas, species, 'MinLeafSize', 5), ... 'Trees', [2, 5]); P = zeros (150); for t = [2, 5] [~, ~, nd] = predict (B.Trees{t}, meas); P += nd == nd'; endfor assert_equal (B.Proximity, P / 2); ***** test # the filled matrices agree with the compact ensemble's methods load fisheriris rng (1); B = fillprox (TreeBagger (4, meas, species, 'MinLeafSize', 5)); C = compact (B); assert_equal (B.Proximity, proximity (C, meas)); assert_equal (B.OutlierMeasure, outlierMeasure (C, meas, 'Labels', species)); ***** test # MATLAB parity: a regression outlier measure is over every row load fisheriris rng (1); B = fillprox (TreeBagger (4, meas(:,2:4), meas(:,1), ... 'Method', 'regression')); assert_equal (B.OutlierMeasure, outlierMeasure (compact (B), meas(:,2:4))); ***** test # MATLAB parity: fillprox prints its progress load fisheriris B = TreeBagger (3, meas, species); out = evalc ("fillprox (B, 'NumPrint', 1);"); assert_equal (out, sprintf ("Tree 1 done.\nTree 2 done.\nTree 3 done.\n")); ***** test # MATLAB parity: the scaling of the proximity matrix load fisheriris B = TreeBagger (2, meas, species, 'SampleWithReplacement', 'off', ... 'InBagFraction', 1, 'NumPredictorsToSample', 'all', ... 'MinLeafSize', 5); [S, E] = mdsprox (fillprox (B)); assert_equal (size (S), [150, 5]); assert_equal (E(1:5)', [23.511509991334723, 20.652625175036377, ... 5.054560979007729, 3, 2.627970521287837], 1e-12); assert_equal (abs (S([1, 51, 101], 1:2)), ... [0.539357634260452, 0.083561333480090; ... 0.399117306477463, 0.428703363387418; ... 0.228627699102420, 0.556632583919985], 1e-12); ***** test # MATLAB parity: 'Keep' scales the chosen observations alone load fisheriris rng (1); B = fillprox (TreeBagger (10, meas, species, 'MinLeafSize', 5)); k = 1:3:150; [S, E] = mdsprox (B, 'Keep', k); [S0, E0] = cmdscale (1 - B.Proximity(k,k)); assert_equal (S, S0); assert_equal (E, E0); assert_equal (mdsprox (B, 'Keep', mod (1:150, 3) == 1), S0); ***** test # the scaled coordinates are drawn one class per color load fisheriris rng (1); B = fillprox (TreeBagger (5, meas, species, 'MinLeafSize', 5)); h = figure ('visible', 'off'); unwind_protect mdsprox (B, 'Colors', 'rgb'); assert_equal (numel (get (gca, 'children')), 3); unwind_protect_cleanup close (h); end_unwind_protect ***** test # a regression ensemble is drawn in the first color load fisheriris rng (1); B = fillprox (TreeBagger (5, meas(:,2:4), meas(:,1), ... 'Method', 'regression')); h = figure ('visible', 'off'); unwind_protect mdsprox (B, 'Colors', 'rgb'); kids = get (gca, 'children'); assert_equal (numel (kids), 1); assert_equal (get (kids, 'color'), [1, 0, 0]); unwind_protect_cleanup close (h); end_unwind_protect ***** error ... load fisheriris B = growTrees (fillprox (TreeBagger (2, meas, species)), 1); B.Proximity ***** shared x, y, B, C, R, Q load fisheriris x = meas; y = species; B = TreeBagger (3, x, y, 'OOBPrediction', 'on'); C = compact (B); R = TreeBagger (2, x(:,2:4), x(:,1), 'Method', 'regression'); Q = TreeBagger (2, x(:,2:4), x(:,1), 'Method', 'regression', ... 'OOBPrediction', 'on'); ***** error TreeBagger (1, x) ***** error TreeBagger (0, x, y) ***** error ... TreeBagger (1, {1}, y) ***** error ... TreeBagger (1, x, y(1:10)) ***** error ... TreeBagger (1, x, y, 'Method') ***** error ... TreeBagger (1, x, y, 1, 2) ***** error ... TreeBagger (1, x, y, 'Foo', 2) ***** error ... TreeBagger (1, x, y, 'Method', 'cluster') ***** error ... TreeBagger (1, x, y, 'NumPredictorsToSample', 0) ***** error ... TreeBagger (1, x, y, 'MinLeafSize', 0) ***** error ... TreeBagger (1, x, y, 'InBagFraction', 1.5) ***** error ... TreeBagger (1, x, y, 'SampleWithReplacement', 1) ***** error ... TreeBagger (1, x, y, 'OOBPrediction', true) ***** error ... TreeBagger (1, x, y, 'OOBPredictorImportance', 1) ***** error ... TreeBagger (1, x, y, 'PredictorNames', {'a'}) ***** error ... TreeBagger (1, x, y, 'NumPrint', -1) ***** error ... TreeBagger (1, x, y, 'Surrogate', 'on') ***** error ... TreeBagger (1, x, y, 'Options', struct ()) ***** error ... TreeBagger (1, x, y, 'QuadraticErrorTolerance', 1e-3) ***** error ... TreeBagger (1, x(:,2:4), x(:,1), 'Method', 'regression', ... 'Cost', [0, 1; 1, 0]) ***** error ... TreeBagger (1, x, y, 'SampleWithReplacement', 'off', 'OOBPrediction', 'on') ***** error ... TreeBagger (1, x, y, 'Weights', -ones (150, 1)) ***** error ... TreeBagger (1, x, y, 'ClassNames', {1}) ***** error ... TreeBagger (1, x, y, 'ClassNames', {'rose'}) ***** error ... TreeBagger (1, x(1:3,:), NaN (3, 1)) ***** error ... TreeBagger (1, x, y, 'Weights', zeros (150, 1)) ***** error ... TreeBagger (1, x, y, 'Cost', [0, 1; 1, 0]) ***** error ... TreeBagger (1, x, y, 'Prior', [1, 2]) ***** error ... TreeBagger (1, x, y, 'Prior', struct ('a', 1)) ***** error ... TreeBagger (1, x, y, 'Method', 'regression') ***** error ... TreeBagger (1, x(1:3,:), NaN (3, 1), 'Method', 'regression') ***** error ... oobError (TreeBagger (1, x, y)) ***** error ... oobPredict (TreeBagger (1, x, y)) ***** error ... oobMargin (TreeBagger (1, x, y)) ***** error ... oobMeanMargin (TreeBagger (1, x, y)) ***** error predict (B) ***** error predict (B, {1}) ***** error ... predict (B, ones (2, 3)) ***** error ... predict (B, x, 'Trees') ***** error ... predict (B, x, 'Mode', 'ensemble') ***** error ... predict (B, x, 'Trees', 4) ***** error ... predict (B, x, 'TreeWeights', [1, 1]) ***** error ... predict (B, x, 'UseInstanceForTree', true (2, 3)) ***** error ... oobPredict (B, 'UseInstanceForTree', true (150, 3)) ***** error margin (B, x) ***** error ... margin (B, x, y, 'Weights', ones (150, 1)) ***** error meanMargin (B, x) ***** error ... margin (R, x(:,2:4), x(:,1)) ***** error error (B, x) ***** error error (B, x, y(1:3)) ***** error<'Weights' must be a nonnegative numeric vector with one element per observation, not all zero.> ... error (B, x, y, 'Weights', ones (3, 1)) ***** error<'Mode' must be 'cumulative', 'individual' or 'ensemble'.> ... error (B, x, y, 'Mode', 'all') ***** error<'TreeWeights' cannot be used in 'individual' mode.> ... error (B, x, y, 'Mode', 'individual', 'TreeWeights', [1, 1, 1]) ***** error ... error (B, x(1:2,:), {'rose'; 'setosa'}) ***** error error (R, x(1:2,2:4), {'a'; 'b'}) ***** error growTrees (B) ***** error ... growTrees (B, 0) ***** error ... growTrees (B, 1, 'NumPrint') ***** error ... growTrees (B, 1, 'NumPrint', -1) ***** error ... growTrees (B, 1, 'Options', 1) ***** error ... growTrees (B, 1, 'Foo', 1) ***** error append (B) ***** error append (B, C) ***** error ... append (B, TreeBagger (1, x, x(:,1), 'Method', 'regression')) ***** error ... append (B, TreeBagger (1, x(1:100,:), y(1:100), 'OOBPrediction', 'on')) ***** error ... append (B, TreeBagger (1, x, y, 'OOBPrediction', 'on', ... 'Prior', 'uniform', ... 'ClassNames', {'virginica'; 'versicolor'; 'setosa'})) ***** error ... append (B, TreeBagger (1, x, y)) ***** error ... append (B, TreeBagger (1, x, y, 'OOBPredictorImportance', 'on')) ***** error ... B.OOBPermutedPredictorDeltaError ***** error ... B.OOBPermutedPredictorDeltaMeanMargin ***** error ... B.OOBPermutedPredictorCountRaiseMargin ***** error ... B.Proximity ***** error ... B.OutlierMeasure ***** error ... quantilePredict (R) ***** error ... quantilePredict (B, x) ***** error ... quantilePredict (R, {1}) ***** error ... quantilePredict (R, x) ***** error ... quantilePredict (R, x(:,2:4), 'Quantile', 2) ***** error ... quantilePredict (R, x(:,2:4), 'Trees') ***** error ... quantilePredict (R, x(:,2:4), 'Mode', 'ensemble') ***** error ... oobQuantilePredict (R) ***** error ... oobQuantilePredict (Q, 'UseInstanceForTree', true (150, 2)) ***** error ... quantileError (R, x) ***** error ... quantileError (R, x(:,2:4), y) ***** error ... quantileError (R, x(:,2:4), x(:,1), 'Mode', 'all') ***** error ... quantileError (R, x(:,2:4), x(:,1), 'Mode', 'individual', ... 'TreeWeights', [1, 1]) ***** error ... oobQuantileError (R) ***** error ... oobQuantileError (B) ***** error ... oobQuantileError (Q, 'Weights', ones (150, 1)) ***** error ... fillprox (B, 'NumPrint', -1) ***** error ... fillprox (B, 'Trees') ***** error ... fillprox (B, 'Trees', 9) ***** error ... fillprox (B, 'Keep', 1) ***** error ... mdsprox (B) ***** error ... mdsprox (fillprox (B), 'Keep') ***** error ... mdsprox (fillprox (B), 'Data', 'proximity') ***** error ... mdsprox (fillprox (B), 'Keep', 0) ***** error ... mdsprox (fillprox (B), 'Colors', 1) ***** error ... mdsprox (fillprox (B), 'MDSCoordinates', [1, 2, 3, 4]) ***** error ... mdsprox (fillprox (B), 'MDSCoordinates', [1, 500]) ***** error ... load fisheriris TreeBagger (2, meas, species, 'ClassNames', [3, 1, 2]) ***** test # classes named as text for numeric labels keep the labels' type load fisheriris Y = [ones(50, 1); 2 * ones(50, 1); 3 * ones(50, 1)]; B = TreeBagger (2, meas, Y, 'ClassNames', {'3', '1', '2'}); assert_equal (B.ClassNames, [3; 1; 2]); ***** shared X, yb, yr k = (0:119)'; c = mod (k, 4) + 1; j = floor (k / 4); x2 = mod (k * 7, 10); X = [c, x2]; yb = (c == 1) | (c == 2 & mod (j, 4) != 0) | (c == 3 & mod (j, 4) == 0) ... | (x2 > 7); yr = [3; 1; 4; 1.5]; yr = yr(c) + 0.1 * sin (k) + 0.2 * x2; Xq = [1, 0; 3, 5; 5, 0; NaN, 2; 2.5, 9]; ***** test # every bagged tree takes the categorical predictors and options B = TreeBagger (3, X, yb, 'CategoricalPredictors', 1, ... 'MaxNumCategories', 3, 'AlgorithmForCategorical', 'pca'); assert_equal (B.Trees{1}.CategoricalPredictors, 1); assert_equal (any (strcmpi (B.TreeArguments, 'MaxNumCategories')), true); assert_equal (any (strcmpi (B.TreeArguments, 'AlgorithmForCategorical')), ... true); Br = TreeBagger (3, X, yr, 'Method', 'regression', ... 'CategoricalPredictors', 1); assert_equal (Br.Trees{1}.CategoricalPredictors, 1); ***** test # the property records the resolved indices, empty when none is named B = TreeBagger (3, X, yb); assert_equal (B.CategoricalPredictors, []); B = TreeBagger (3, X, yb, 'CategoricalPredictors', 1); assert_equal (B.CategoricalPredictors, 1); ***** test # a logical vector and 'all' are resolved to indices B = TreeBagger (3, X, yb, 'CategoricalPredictors', [true, false]); assert_equal (B.CategoricalPredictors, 1); B = TreeBagger (3, X, yb, 'CategoricalPredictors', 'all'); assert_equal (B.CategoricalPredictors, [1, 2]); ***** test # a categorical predictor may be named rather than indexed B = TreeBagger (3, X, yb, 'PredictorNames', {'grp', 'val'}, ... 'CategoricalPredictors', {'grp'}); assert_equal (B.CategoricalPredictors, 1); assert_equal (B.Trees{1}.CategoricalPredictors, 1); ***** error ... TreeBagger (3, X, yb, 'CategoricalPredictors', 3) ***** error ... append (TreeBagger (3, X, yb, 'CategoricalPredictors', 1), ... TreeBagger (3, X, yb)) ***** test # the predictors and the response come from a table load fisheriris T = table (meas(:,1), meas(:,2), 'VariableNames', {'SL', 'SW'}); T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); T.Species = categorical (species); B = TreeBagger (20, T, 'Species'); assert_equal (B.PredictorNames, {'SL', 'SW', 'Wide'}); assert_equal (B.CategoricalPredictors, 3); ***** test # a model formula names the response and the predictors together load fisheriris T = table (meas(:,1), meas(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = categorical (species); B = TreeBagger (20, T, 'Species ~ SW + SL'); assert_equal (B.PredictorNames, {'SW', 'SL'}); ***** test # predict takes a table, matched by name and not by position load fisheriris T = table (meas(:,1), meas(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = categorical (species); B = TreeBagger (20, T, 'Species'); a = predict (B, T); assert_equal (predict (B, T(:, [3, 2, 1])), a); ***** error ... TreeBagger (10, table (rand (6, 1), rand (6, 1)), 'NoSuch') ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = TreeBagger (20, T, 'Species'); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = TreeBagger (20, T, 'Species'); a = error (Mdl, X, y); assert_equal (error (Mdl, T(:,1:2), y), a); assert_equal (error (Mdl, T, 'Species'), a); assert_equal (error (Mdl, T), a); assert_equal (error (Mdl, T, 'Mode', 'ensemble'), a(end)); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = TreeBagger (20, T, 'Species'); a = meanMargin (Mdl, X, y); assert_equal (meanMargin (Mdl, T(:,1:2), y), a); assert_equal (meanMargin (Mdl, T, 'Species'), a); assert_equal (meanMargin (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,2:4); y = meas(:,1); T = table (X(:,1), X(:,2), X(:,3), y, ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); Mdl = TreeBagger (20, T, 'SL', 'Method', 'regression'); a = quantileError (Mdl, X, y); assert_equal (quantileError (Mdl, T(:,1:3), y), a); assert_equal (quantileError (Mdl, T, 'SL'), a); assert_equal (quantileError (Mdl, T), a); assert_equal (quantileError (Mdl, T(:,[3, 1, 2, 4])), a); ***** test # a table is matched to the predictors by name load fisheriris T = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); Mdl = TreeBagger (20, T, 'SL', 'Method', 'regression'); a = quantilePredict (Mdl, meas(:,2:4), 'Quantile', [0.25, 0.75]); assert_equal (quantilePredict (Mdl, T(:,1:3), 'Quantile', [0.25, 0.75]), a); assert_equal (quantilePredict (Mdl, T(:,[4, 3, 1, 2]), ... 'Quantile', [0.25, 0.75]), a); ***** error ... TreeBagger (3, [1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], ... 'Weights', int8 ([1; 1; 1; 1])) ***** error ... TreeBagger (3, [1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], ... 'Weights', true (4, 1)) ***** error <'Weights' must be a real vector of class single or double.> ... error (TreeBagger (3, [1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2]), ... [1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', ... int8 ([1; 1; 1; 1])) ***** test ## Single weights are stored single, summing to one load fisheriris w = 1 + (1:150)' / 7; Mdl = TreeBagger (5, meas, species, 'Weights', single (w)); assert_equal (class (Mdl.W), 'single'); assert_equal (sum (double (Mdl.W)), 1, 1e-6); 180 tests, 180 passed, 0 known failure, 0 skipped [inst/Machine_Learning/CompactClassificationTree.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/CompactClassificationTree.m ***** test # MATLAB parity: the surface a compact tree reports load fisheriris CMdl = compact (ClassificationTree (meas, species)); assert_equal (class (CMdl), 'CompactClassificationTree'); assert_equal (numel (properties (CMdl)), 33); assert_equal (CMdl.NumNodes, 9); assert_equal (CMdl.ClassNames, unique (species)); assert_equal (CMdl.Prior, [1/3, 1/3, 1/3], 1e-15); assert_equal (CMdl.Cost, [0, 1, 1; 1, 0, 1; 1, 1, 0]); assert_equal (CMdl.ResponseName, 'Y'); assert_equal (CMdl.PredictorNames, {'x1', 'x2', 'x3', 'x4'}); assert_equal (CMdl.ScoreTransform, 'none'); ***** test # The compact tree carries the node table the model it came from has load fisheriris Mdl = ClassificationTree (meas, species); CMdl = compact (Mdl); assert_equal (CMdl.Children, Mdl.Children); assert_equal (CMdl.Parent, Mdl.Parent); assert_equal (CMdl.NodeSize, Mdl.NodeSize); assert_equal (CMdl.ClassCount, Mdl.ClassCount); assert_equal (CMdl.NodeRisk, Mdl.NodeRisk, 1e-15); assert_equal (CMdl.NodeError, Mdl.NodeError, 1e-15); assert_equal (CMdl.NodeProbability, Mdl.NodeProbability, 1e-15); assert_equal (CMdl.ClassProbability, Mdl.ClassProbability, 1e-15); assert_equal (CMdl.NodeClass, Mdl.NodeClass); assert_equal (CMdl.PruneList, Mdl.PruneList); assert_equal (CMdl.PruneAlpha, Mdl.PruneAlpha, 1e-15); assert_equal (CMdl.CutPredictor, Mdl.CutPredictor); assert_equal (CMdl.CutType, Mdl.CutType); ***** test # MATLAB parity: what a tree with no categories and no surrogates holds load fisheriris CMdl = compact (ClassificationTree (meas, species)); assert_equal (size (CMdl.CutCategories), [9, 2]); assert_equal (size (CMdl.CategoricalSplit), [0, 0]); assert_equal (size (CMdl.SurrogateCutPredictor), [0, 1]); assert_equal (size (CMdl.SurrogateCutPoint), [0, 0]); assert_equal (size (CMdl.SurrogatePredictorAssociation), [0, 0]); ***** test # MATLAB parity: predict answers exactly as the full model does load fisheriris Mdl = ClassificationTree (meas, species); CMdl = compact (Mdl); [l1, s1, n1, c1] = predict (Mdl, meas); [l2, s2, n2, c2] = predict (CMdl, meas); assert_equal ({l1, s1, n1, c1}, {l2, s2, n2, c2}); assert_equal (predict (CMdl, meas([1, 60, 120], :)), ... {'setosa'; 'versicolor'; 'virginica'}); ***** test # MATLAB parity: loss, margin and edge on a compact tree load fisheriris CMdl = compact (ClassificationTree (meas, species)); assert_equal (loss (CMdl, meas, species), 0.02, 1e-14); assert_equal (edge (CMdl, meas, species), 0.938357487922706, 1e-14); m = margin (CMdl, meas([1, 60, 120], :), species([1, 60, 120])); assert_equal (m', [1, 1, 1/3], 1e-14); assert_equal (loss (CMdl, meas, species, 'LossFun', 'hinge'), ... 0.0308212560386473, 1e-14); ***** test # MATLAB parity: edge on a set missing a class load fisheriris CMdl = compact (ClassificationTree (meas, species)); r = 51:150; assert_equal (edge (CMdl, meas(r,:), species(r)), 0.9075362319, 1e-10); ***** test # MATLAB parity: predictorImportance and nodeVariableRange load fisheriris CMdl = compact (ClassificationTree (meas, species)); assert_equal (predictorImportance (CMdl), ... [0, 0, 0.0907484567901233, 0.0682128958668813], 1e-14); r = nodeVariableRange (CMdl, 8); assert_equal (r.x3, [2.45, 4.95], 1e-14); assert_equal (r.x4, [-Inf, 1.65], 1e-14); assert_equal (fieldnames (nodeVariableRange (CMdl, 1)), cell (0, 1)); ***** test # MATLAB parity: the text form of a compact tree load fisheriris CMdl = compact (ClassificationTree (meas, species)); lines = strsplit (strtrim (evalc ('view (CMdl)')), "\n"); assert_equal (numel (lines), 10); assert_equal (lines{2}, ... '1 if x3<2.45 then node 2 elseif x3>=2.45 then node 3 else setosa'); assert_equal (lines{10}, '9 class = virginica'); ***** test # The risk follows the criterion the tree it came from was grown under load fisheriris Mdl = ClassificationTree (meas, species, 'SplitCriterion', 'deviance'); CMdl = compact (Mdl); assert_equal (CMdl.NodeRisk, Mdl.NodeRisk, 1e-15); assert_equal (CMdl.NodeRisk(1), 0.792481250360577, 1e-14); ***** test # Reassigning Cost re-derives the node statistics, not the tree load fisheriris CMdl = compact (ClassificationTree (meas, species)); shape = {CMdl.Children, CMdl.NodeSize, CMdl.ClassCount}; CMdl.Cost = [0, 2, 8; 3, 0, 1; 5, 4, 0]; assert_equal ({CMdl.Children, CMdl.NodeSize, CMdl.ClassCount}, shape); assert_equal (CMdl.NodeClass{1}, 'versicolor'); assert_equal (CMdl.NodeError(1), 2, 1e-14); ***** test # Reassigning Prior re-derives the node statistics load fisheriris CMdl = compact (ClassificationTree (meas, species)); CMdl.Prior = [0.5, 0.25, 0.25]; assert_equal (CMdl.Prior, [0.5, 0.25, 0.25], 1e-14); assert_equal (CMdl.ClassProbability(1,:), [0.5, 0.25, 0.25], 1e-14); assert_equal (CMdl.NodeProbability(2), 0.5, 1e-14); assert_equal (CMdl.NodeRisk(1), 0.625, 1e-14); ***** test # The score transform travels with the compact model load fisheriris CMdl = compact (ClassificationTree (meas, species, ... 'ScoreTransform', 'logit')); assert_equal (CMdl.ScoreTransform, 'logit'); [~, score] = predict (CMdl, meas(1, :)); assert_equal (score, [0.731058578630005, 0.5, 0.5], 1e-14); ***** test # A compact model saved and loaded answers exactly as it did load fisheriris CMdl = compact (ClassificationTree (meas, species)); fname = tempname (); unwind_protect savemodel (CMdl, fname); New = loadmodel (fname); assert_equal (class (New), 'CompactClassificationTree'); assert_equal (New.NumNodes, CMdl.NumNodes); assert_equal (New.NodeRisk, CMdl.NodeRisk, 1e-15); assert_equal (New.CutPredictor, CMdl.CutPredictor); assert_equal (predict (New, meas), predict (CMdl, meas)); unwind_protect_cleanup delete (fname); end_unwind_protect ***** error CompactClassificationTree () ***** error CompactClassificationTree (5) ***** error predict (compact (ClassificationTree (ones (4, 2), [1; 1; 2; 2]))) ***** error predict (compact (ClassificationTree (ones (4, 2), [1; 1; 2; 2])), []) ***** error predict (compact (ClassificationTree (ones (4, 2), [1; 1; 2; 2])), 'a') ***** error predict (compact (ClassificationTree (ones (4, 2), [1; 1; 2; 2])), ... ones (2, 3)) ***** error margin (compact (ClassificationTree (ones (4, 2), [1; 1; 2; 2])), ... ones (4, 2)) ***** error edge (compact (ClassificationTree (ones (4, 2), [1; 1; 2; 2])), ones (4, 2)) ***** error loss (compact (ClassificationTree (ones (4, 2), [1; 1; 2; 2])), ones (4, 2)) ***** error loss (compact (ClassificationTree (ones (4, 2), [1; 1; 2; 2])), ... ones (4, 2), [1; 1; 2; 2], 'LossFun', 'x') ***** error ... loss (compact (ClassificationTree (ones (4, 2), [1; 1; 2; 2])), ... ones (4, 2), [1; 1; 2; 2], 'Bogus', 1) ***** error nodeVariableRange (compact (ClassificationTree (ones (4, 2), ... [1; 1; 2; 2])), 99) ***** error savemodel (compact (ClassificationTree (ones (4, 2), [1; 1; 2; 2]))) ***** error savemodel (compact (ClassificationTree (ones (4, 2), [1; 1; 2; 2])), 5) ***** error CMdl = compact (ClassificationTree (ones (4, 2), [1; 1; 2; 2])); CMdl.Prior = [0.2, 0.3, 0.5]; ***** test # a compact tree keeps and uses the level sets of its cuts k = (0:79)'; c = mod (k, 4) + 1; j = floor (k / 4); X = [c, mod(k * 7, 10)]; y = (c == 1) | (c == 2 & mod (j, 4) != 0) | (c == 3 & mod (j, 4) == 0); Mdl = compact (fitctree (X, y, 'CategoricalPredictors', 1)); assert_equal (Mdl.CategoricalPredictors, 1); assert_equal (Mdl.CategoricalSplit, {[1, 2], [3, 4]}); [~, ~, nd] = predict (Mdl, [1, 0; 3, 0; 5, 0]); assert_equal (nd', [2, 3, 1]); fname = [tempname(), '.mdl']; savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.CutCategories, Mdl.CutCategories); ***** shared cctT, cctM load fisheriris cctT = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); cctT.Species = categorical (species); cctT.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); cctM = compact (fitctree (cctT, 'Species')); ***** test # the levels a predictor was coded through travel with the model assert_equal (numel (cctM.PredictorLevels), 5); assert_equal (cctM.PredictorLevels{5}, {'narrow', 'wide'}); ***** test # predict takes a table, read by name and not by position a = predict (cctM, cctT); assert_equal (class (a), 'categorical'); assert_equal (predict (cctM, cctT(:, [6, 5, 4, 3, 2, 1])), a); ***** test # a matrix is still taken load fisheriris CMdl = compact (fitctree (meas, species)); assert_equal (numel (predict (CMdl, meas)), 150); ***** error ... predict (cctM, cctT(:, [1, 3, 4, 5, 6])) ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitctree (T, 'Species')); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitctree (T, 'Species')); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitctree (T, 'Species')); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** error ... loss (compact (fitctree (ones (4, 2), [1; 1; 2; 2])), ones (4, 2), ... [1; 1; 2; 2], ... 'Weights', int8 ([1; 1; 1; 1])) 37 tests, 37 passed, 0 known failure, 0 skipped [inst/Machine_Learning/templateNaiveBayes.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/templateNaiveBayes.m ***** test # the default template names its learner and nothing else T = templateNaiveBayes (); assert_equal (class (T), 'struct'); assert_equal (T.Method, 'NaiveBayes'); assert_equal (T.Type, 'classification'); assert_equal (numfields (T), 2); ***** test # an option given is stored under its own name, as it stands T = templateNaiveBayes ('DistributionNames', 'kernel'); assert_equal (numfields (T), 3); assert_equal (T.DistributionNames, 'kernel'); ***** test # a name the learner does not know is not refused here T = templateNaiveBayes ('NoSuchOption', 42); assert_equal (T.NoSuchOption, 42); ***** error ... templateNaiveBayes ('KernelScale') ***** error ... templateNaiveBayes (42, 1) ***** error ... templateNaiveBayes ('not a name', 1) 6 tests, 6 passed, 0 known failure, 0 skipped [inst/Machine_Learning/lime.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/lime.m ***** demo ## Explain a model fitted from a table load fisheriris T = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); Mdl = fitrtree (T, 'SL'); ## The observations and the query point may be tables too, read by the ## names the model was fitted on rather than by the order of the columns ex = lime (Mdl, T(:, [1, 2, 3, 5]), 'NumSyntheticData', 2000, ... 'QueryPoint', T(1, [5, 3, 2, 1]), 'NumImportantPredictors', 2); ex.ImportantPredictors' ex.SimpleModel.Beta' ## A column the model was not fitted on is passed over, so the whole ## table, response and all, may be handed over as it stands ex2 = fit (ex, T(1,:), 2); ex2.ImportantPredictors' ***** test # the observations are drawn when the explainer is built X = [1, 10; 2, 20; 3, 30; 4, 45; 5, 50; 6, 65]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2); L = lime (f, X, 'Type', 'regression', 'NumSyntheticData', 200); assert_equal (size (L.SyntheticData), [200, 2]); assert_equal (size (L.Fitted), [200, 1]); assert_equal (isempty (L.SimpleModel), true); assert_equal (isempty (L.QueryPoint), true); ***** test # the drawn observations follow the observations they were fitted to rand ('seed', 42); randn ('seed', 42); X = [randn(400,1) * 2 + 5, randn(400,1) * 0.5 - 1]; f = @(Z) Z(:,1); L = lime (f, X, 'Type', 'regression', 'NumSyntheticData', 4000); assert_equal (mean (L.SyntheticData), mean (X), 0.4); assert_equal (std (L.SyntheticData), std (X), 0.4); ***** test X = [0, 0, 0; 1, 0, 0; 2, 0, 0; 3, 0, 0; 4, 0, 0; 5, 0, 0; 0, 1, 0; ... 0, 2, 0; 0, 3, 0; 0, 0, 1; 0, 0, 2; 0, 0, 3; 1, 1, 1; 2, 2, 2; ... 3, 3, 3; 4, 4, 4; 5, 5, 5; 1, 2, 3; 3, 2, 1; 2, 3, 1]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.5 * Z(:,3) .^ 2; L = lime (f, X, 'Type', 'regression', 'CustomSyntheticData', X); a = fit (L, [0, 0, 0], 3, 'KernelWidth', 0.1, 'BetaTolerance', 1e-12); assert_equal (a.SimpleModel.Beta', ... [1.992780427426674, -3.006957351974981, ... 0.691563828807785], 1e-5); assert_equal (a.SimpleModel.Bias, -0.022034064280291, 1e-5); b = fit (L, [0, 0, 0], 3, 'KernelWidth', 1, 'BetaTolerance', 1e-12); assert_equal (b.SimpleModel.Beta', ... [2.211849727686012, -2.799187539649991, ... 1.725666244878087], 1e-5); assert_equal (b.SimpleModel.Bias, -0.941458529287273, 1e-5); ***** test X = [0, 0, 0; 1, 0, 0; 2, 0, 0; 3, 0, 0; 4, 0, 0; 5, 0, 0; 0, 1, 0; ... 0, 2, 0; 0, 3, 0; 0, 0, 1; 0, 0, 2; 0, 0, 3; 1, 1, 1; 2, 2, 2; ... 3, 3, 3; 4, 4, 4; 5, 5, 5; 1, 2, 3; 3, 2, 1; 2, 3, 1]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.5 * Z(:,3) .^ 2; L = lime (f, X, 'Type', 'regression', 'CustomSyntheticData', X); a = fit (L, [0.5, 0.5, 0.5], 3, 'BetaTolerance', 1e-12); assert_equal (a.SimpleModel.Beta', ... [2.197589328509646, -2.816490786994012, ... 1.701570881013631], 1e-5); assert_equal (a.SimpleModel.Bias, -0.887925297450557, 1e-5); ***** test X = [0, 0, 0; 1, 0, 0; 2, 0, 0; 3, 0, 0; 4, 0, 0; 5, 0, 0; 0, 1, 0; ... 0, 2, 0; 0, 3, 0; 0, 0, 1; 0, 0, 2; 0, 0, 3; 1, 1, 1; 2, 2, 2; ... 3, 3, 3; 4, 4, 4; 5, 5, 5; 1, 2, 3; 3, 2, 1; 2, 3, 1]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.5 * Z(:,3) .^ 2; L = lime (f, X, 'Type', 'regression', 'CustomSyntheticData', X); a = fit (L, [0, 0, 0], 1, 'BetaTolerance', 1e-12); assert_equal (a.ImportantPredictors, 1); assert_equal (a.SimpleModel.Beta, 1.849047756469483, 1e-5); b = fit (L, [0, 0, 0], 2, 'BetaTolerance', 1e-12); assert_equal (b.ImportantPredictors', [1, 2]); assert_equal (b.SimpleModel.Beta', ... [2.280838361112699, -1.990784316697158], 1e-5); ***** test # the simple model is fitted on the important predictors alone X = [1, 10, 100; 2, 20, 150; 3, 30, 120; 4, 45, 180; 5, 50, 90; ... 6, 65, 130]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2); L = lime (f, X, 'Type', 'regression', 'CustomSyntheticData', X); a = fit (L, [3, 30, 120], 2); assert_equal (numel (a.SimpleModel.Beta), 2); assert_equal (a.NumImportantPredictors, 2); ***** test # a linear model is explained by its own weights X = [1, 10; 2, 20; 3, 28; 4, 45; 5, 50; 6, 65; 2.5, 25; 3.5, 35]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 7; L = lime (f, X, 'Type', 'regression', 'CustomSyntheticData', X); a = fit (L, [3, 28], 2, 'BetaTolerance', 1e-12); assert_equal (a.SimpleModel.Beta', [2, -3], 1e-6); assert_equal (a.SimpleModel.Bias, 7, 1e-5); assert_equal (a.SimpleModelFitted, a.BlackboxFitted, 1e-5); ***** test # a classifier is separated from every other class at once load fisheriris Mdl = fitcknn (meas, species); S = [meas(1:6,:); meas(51:56,:); meas(101:106,:)]; L = lime (Mdl, 'CustomSyntheticData', S); assert_equal (L.Type, 'classification'); a = fit (L, meas(1,:), 2); assert_equal (class (a.SimpleModel), 'ClassificationLinear'); assert_equal (a.SimpleModel.ClassNames', [-1, 1]); assert_equal (a.BlackboxFitted, {'setosa'}); ***** test # a tree may stand in for the weighted sum X = [1, 10; 2, 20; 3, 28; 4, 45; 5, 50; 6, 65; 2.5, 25; 3.5, 35]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2); L = lime (f, X, 'Type', 'regression', 'CustomSyntheticData', X); a = fit (L, [3, 28], 2, 'SimpleModelType', 'tree'); assert_equal (class (a.SimpleModel), 'RegressionTree'); ***** test # the draw may be taken around the query point rather than over all load fisheriris X = meas(:,2:4); f = @(Z) Z(:,1); L = lime (f, X, 'Type', 'regression', 'DataLocality', 'local', ... 'NumNeighbors', 20, 'NumSyntheticData', 500, ... 'QueryPoint', X(1,:)); assert_equal (L.DataLocality, 'local'); assert_equal (size (L.SyntheticData), [500, 3]); idx = knnsearch (X, X(1,:), 'K', 20); assert_equal (mean (L.SyntheticData), mean (X(idx,:)), 0.35); ***** test # observations may be given outright rather than drawn X = [1, 10; 2, 20; 3, 28; 4, 45]; S = [1.5, 15; 2.5, 25; 3.5, 35]; f = @(Z) Z(:,1); L = lime (f, X, 'Type', 'regression', 'CustomSyntheticData', S); assert_equal (L.SyntheticData, S); assert_equal (L.NumSyntheticData, 3); assert_equal (L.Fitted, S(:,1)); ***** test # a predictor holding levels becomes one column per level but one C = [1, 1; 1, 2; 2, 1; 2, 2; 3, 1; 3, 2; 1, 1; 2, 2]; f = @(Z) 5 * (Z(:,1) == 3) + Z(:,2); L = lime (f, C, 'Type', 'regression', 'CategoricalPredictors', [1, 2], ... 'CustomSyntheticData', C); a = fit (L, [1, 1], 1); assert_equal (numel (a.SimpleModel.Beta), 2); ***** test # the two measures for levels answer differently C = [1, 1, 1; 1, 1, 2; 1, 1, 3; 1, 2, 1; 1, 2, 2; 2, 1, 1; 2, 1, 2; ... 2, 2, 3; 3, 1, 1; 3, 2, 2; 1, 1, 1; 1, 1, 2; 1, 2, 3; 2, 1, 1; ... 1, 1, 1; 1, 1, 1; 3, 2, 3; 2, 2, 1]; f = @(Z) 5 * ((Z(:,2) == 1) & (Z(:,3) == 1)) + 0.5 * Z(:,1); L = lime (f, C, 'Type', 'regression', ... 'CategoricalPredictors', [1, 2, 3], 'CustomSyntheticData', C); a = fit (L, [1, 1, 1], 3, 'Distance', 'goodall3'); b = fit (L, [1, 1, 1], 3, 'Distance', 'ofd'); assert_equal (isequal (a.SimpleModel.Beta, b.SimpleModel.Beta), false); c = fit (L, [1, 1, 1], 3); assert_equal (c.SimpleModel.Beta, a.SimpleModel.Beta); ***** test # a distance given as a function handle is ours, not MATLAB's X = [1, 10; 2, 20; 3, 28; 4, 45; 5, 50; 6, 65]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2); L = lime (f, X, 'Type', 'regression', 'CustomSyntheticData', X); a = fit (L, [3, 28], 2, 'Distance', @(q, Z) sum (abs (Z - q), 2)); b = fit (L, [3, 28], 2, 'Distance', 'cityblock'); assert_equal (a.SimpleModel.Beta, b.SimpleModel.Beta, 1e-8); ***** test # plot draws a bar per column of the model and gives the figure X = [1, 10; 2, 20; 3, 28; 4, 45; 5, 50; 6, 65]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2); L = lime (f, X, 'Type', 'regression', 'CustomSyntheticData', X); a = fit (L, [3, 28], 2); ## plot opens a figure of its own, kept off screen through the default vis = get (0, 'DefaultFigureVisible'); set (0, 'DefaultFigureVisible', 'off'); h = []; unwind_protect h = plot (a); assert_equal (strcmp (get (h, 'type'), 'figure'), true); ax = findobj (h, 'type', 'axes'); assert_equal (get (get (ax, 'title'), 'string'), ... 'LIME with Linear Model'); assert_equal (get (get (ax, 'xlabel'), 'string'), 'Coefficient'); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Predictor'); unwind_protect_cleanup close (h); set (0, 'DefaultFigureVisible', vis); end_unwind_protect ***** test # a tree is titled after what it is, over its predictor importance X = [1, 10; 2, 20; 3, 28; 4, 45; 5, 50; 6, 65]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2); L = lime (f, X, 'Type', 'regression', 'CustomSyntheticData', X); a = fit (L, [3, 28], 2, 'SimpleModelType', 'tree'); ## plot opens a figure of its own, kept off screen through the default vis = get (0, 'DefaultFigureVisible'); set (0, 'DefaultFigureVisible', 'off'); h = []; unwind_protect h = plot (a); ax = findobj (h, 'type', 'axes'); assert_equal (get (get (ax, 'title'), 'string'), ... 'LIME with Decision Tree Model'); assert_equal (get (get (ax, 'xlabel'), 'string'), 'Predictor Importance'); unwind_protect_cleanup close (h); set (0, 'DefaultFigureVisible', vis); end_unwind_protect ***** test # 'P' reaches the distance that takes it X = [1, 10; 2, 20; 3, 28; 4, 45; 5, 50; 6, 65; 2.5, 25; 3.5, 35]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.01 * Z(:,2) .^ 2; L = lime (f, X, 'Type', 'regression', 'CustomSyntheticData', X); a = fit (L, [3, 28], 2, 'Distance', 'minkowski', 'P', 3); same = @(q, Z) sum (abs (Z - q) .^ 3, 2) .^ (1/3); b = fit (L, [3, 28], 2, 'Distance', same); assert_equal (a.SimpleModel.Beta, b.SimpleModel.Beta, 1e-8); c = fit (L, [3, 28], 2, 'Distance', 'minkowski', 'P', 1); assert_equal (isequal (a.SimpleModel.Beta, c.SimpleModel.Beta), false); ***** test # 'Scale' reaches the distance that takes it X = [1, 10; 2, 20; 3, 28; 4, 45; 5, 50; 6, 65; 2.5, 25; 3.5, 35]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.01 * Z(:,2) .^ 2; L = lime (f, X, 'Type', 'regression', 'CustomSyntheticData', X); sc = [2, 20]; a = fit (L, [3, 28], 2, 'Distance', 'seuclidean', 'Scale', sc); same = @(q, Z) sqrt (sum (((Z - q) ./ sc) .^ 2, 2)); b = fit (L, [3, 28], 2, 'Distance', same); assert_equal (a.SimpleModel.Beta, b.SimpleModel.Beta, 1e-8); c = fit (L, [3, 28], 2, 'Distance', 'seuclidean'); assert_equal (isequal (a.SimpleModel.Beta, c.SimpleModel.Beta), false); ***** test # 'Cov' reaches the distance that takes it X = [1, 10; 2, 20; 3, 28; 4, 45; 5, 50; 6, 65; 2.5, 25; 3.5, 35]; f = @(Z) 2 * Z(:,1) - 3 * Z(:,2) + 0.01 * Z(:,2) .^ 2; L = lime (f, X, 'Type', 'regression', 'CustomSyntheticData', X); CV = [4, 1; 1, 400]; a = fit (L, [3, 28], 2, 'Distance', 'mahalanobis', 'Cov', CV); same = @(q, Z) sqrt (sum (((Z - q) / CV) .* (Z - q), 2)); b = fit (L, [3, 28], 2, 'Distance', same); assert_equal (a.SimpleModel.Beta, b.SimpleModel.Beta, 1e-8); c = fit (L, [3, 28], 2, 'Distance', 'mahalanobis'); assert_equal (isequal (a.SimpleModel.Beta, c.SimpleModel.Beta), false); ***** test X = [1, 9, 0; 2, 3, 0; 3, 7, 0; 4, 1, 0; 5, 8, 0; 6, 2, 0; 7, 5, 0; ... 8, 4, 0]; f = @(Z) Z(:,1) .^ 2 - 0.5 * Z(:,2); L = lime (f, X, 'Type', 'regression', 'CustomSyntheticData', X); a = fit (L, [3, 7, 0], 3); assert_equal (a.NumImportantPredictors, 3); assert_equal (a.ImportantPredictors', [1, 2]); assert_equal (numel (a.SimpleModel.Beta), 2); ***** test # the pursuit stops where there is nothing left to explain X = [1, 9, 0; 2, 3, 0; 3, 7, 0; 4, 1, 0; 5, 8, 0; 6, 2, 0]; f = @(Z) 3 * Z(:,1); L = lime (f, X, 'Type', 'regression', 'CustomSyntheticData', X); a = fit (L, [3, 7, 0], 3); assert_equal (a.ImportantPredictors, 1); ***** test # a classifier is drawn as its simple model, one bar per column load fisheriris Mdl = fitcknn (meas, species); S = [meas(1:8,:); meas(51:58,:); meas(101:108,:)]; a = fit (lime (Mdl, 'CustomSyntheticData', S), meas(1,:), 2); ## plot opens a figure of its own, kept off screen through the default vis = get (0, 'DefaultFigureVisible'); set (0, 'DefaultFigureVisible', 'off'); h = []; unwind_protect h = plot (a); ax = findobj (h, 'type', 'axes'); assert_equal (get (get (ax, 'title'), 'string'), ... 'LIME with Linear Model'); assert_equal (numel (get (ax, 'yticklabel')), ... numel (a.SimpleModel.Beta)); unwind_protect_cleanup close (h); set (0, 'DefaultFigureVisible', vis); end_unwind_protect ***** error lime () ***** error ... lime (42) ***** error ... lime (@(Z) Z(:,1)) ***** error ... lime (@(Z) Z(:,1), [1, 2; 3, 4]) ***** error ... lime (@(Z) Z(:,1), {1, 2}, 'Type', 'regression') ***** error ... lime (@(Z) Z(:,1), [1, 2; 3, 4], 'Type', 'regression', 'UseParallel', true) ***** error ... lime (@(Z) Z(:,1), [1, 2; 3, 4], 'Type', 'regression', ... 'DataLocality', 'nearby') ***** error ... lime (@(Z) Z(:,1), [1, 2; 3, 4], 'Type', 'regression', ... 'NumSyntheticData', 0) ***** error ... lime (@(Z) Z(:,1), [1, 2; 3, 4], 'Type', 'regression', 'KernelWidth', 2) ***** error ... lime (@(Z) Z(:,1), [1, 2; 3, 4], 'Type', 'regression', ... 'SimpleModelType', 'forest') ***** error ... lime (@(Z) Z(:,1), [1, 2; 3, 4], 'Type', 'regression', ... 'CustomSyntheticData', [1, 2, 3]) ***** error ... lime (@(Z) Z(:,1), [1, 2; 3, 4], 'Type', 'regression', 'NoSuchThing', 1) ***** error ... lime (@(Z) Z(:,1), [1, 2; 3, 4], 'Type', 'regression', ... 'Distance', 'goodall3') ***** error ... lime (@(Z) Z(:,1), [1, 2; 3, 4], 'Type', 'regression', ... 'Distance', @(a) a) ***** error lime (@(Z) Z(:,1), [1, 2; 3, 4; 5, 6], 'Type', 'regression', ... 'Distance', @(a, B) 5) ***** error ... fit (lime (@(Z) Z(:,1), [1, 2; 3, 4], 'Type', 'regression'), [1, 2]) ***** error ... fit (lime (@(Z) Z(:,1), [1, 2; 3, 4], 'Type', 'regression'), [1, 2], 0) ***** error ... fit (lime (@(Z) Z(:,1), [1, 2; 3, 4], 'Type', 'regression'), [1, 2], 5) ***** error ... fit (lime (@(Z) Z(:,1), [1, 2; 3, 4], 'Type', 'regression'), [1, 2, 3], 1) ***** error ... plot (lime (@(Z) Z(:,1), [1, 2; 3, 4], 'Type', 'regression')) ***** shared ltT, ltM load fisheriris ltT = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); ltT.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ltM = fitrtree (ltT, 'SL'); ***** test # the observations the draw is fitted to may be a table L = lime (ltM, ltT(:,[1, 2, 3, 5]), 'NumSyntheticData', 200); assert_equal (size (L.X), [150, 4]); assert_equal (size (L.SyntheticData), [200, 4]); ***** test # the drawn observations may be given outright as a table L = lime (ltM, ltT(:,[1, 2, 3, 5]), ... 'CustomSyntheticData', ltT(1:30,[1, 2, 3, 5])); assert_equal (size (L.SyntheticData), [30, 4]); ***** test L = lime (ltM, ltT(:,[1, 2, 3, 5]), ... 'CustomSyntheticData', ltT(1:30,[1, 2, 3, 5])); a = fit (L, ltT(1,[1, 2, 3, 5]), 2); b = fit (L, ltT(1,[5, 3, 2, 1]), 2); assert_equal (b.ImportantPredictors, a.ImportantPredictors); assert_equal (b.SimpleModel.Beta, a.SimpleModel.Beta, 1e-12); ***** test L = lime (ltM, ltT(:,[1, 2, 3, 5]), ... 'CustomSyntheticData', ltT(1:30,[1, 2, 3, 5])); a = fit (L, ltT(1,[1, 2, 3, 5]), 2); b = fit (L, ltT(1,:), 2); assert_equal (b.SimpleModel.Beta, a.SimpleModel.Beta, 1e-12); ***** test # a query point given at building is read the same way L = lime (ltM, ltT(:,[1, 2, 3, 5]), ... 'CustomSyntheticData', ltT(1:30,[1, 2, 3, 5]), ... 'QueryPoint', ltT(1,[5, 3, 2, 1]), ... 'NumImportantPredictors', 2); assert_equal (numel (L.ImportantPredictors), 2); assert_equal (size (L.QueryPoint), [1, 4]); ***** test f = @(Z) Z(:,1); L = lime (f, ltT(:,1:3), 'Type', 'regression', ... 'CustomSyntheticData', ltT(1:30,1:3), ... 'QueryPoint', ltT(1,1:3), 'NumImportantPredictors', 1); assert_equal (L.SimpleModel.PredictorNames, {'SW'}); ***** error ... lime (ltM, ltT(:,[1, 3, 5])) ***** error ... fit (lime (ltM, ltT(:,[1, 2, 3, 5]), 'NumSyntheticData', 50), ... ltT(1,[1, 3, 5]), 2) ***** shared lgX, lgS, lgf lgX = [1, 1, 1; 1, 3, 2; 1, 2, 2; 1, 2, 1; 2, 2, 3; 1, 2, 3; 1, 2, 3; ... 2, 2, 1; 1, 1, 3; 1, 2, 1; 1, 3, 1; 1, 3, 3; 2, 2, 1; 1, 3, 3; ... 1, 2, 1; 1, 2, 3; 1, 3, 1; 1, 1, 3; 2, 3, 1; 2, 2, 1; 3, 2, 3; ... 1, 2, 3; 1, 3, 3; 1, 2, 3; 1, 2, 3; 1, 2, 1; 3, 2, 3; 1, 3, 3; ... 3, 2, 3; 1, 3, 1; 1, 2, 1; 1, 3, 1; 2, 2, 1; 1, 2, 3; 1, 2, 1; ... 2, 3, 1; 1, 2, 1; 3, 1, 3; 3, 3, 3; 1, 2, 3]; lgS = [2, 3, 2; 2, 1, 2; 1, 1, 2; 1, 3, 3; 2, 1, 1; 1, 1, 1; 3, 2, 2; ... 3, 3, 1; 3, 3, 2; 3, 3, 2; 3, 1, 1; 3, 2, 3; 3, 1, 1; 3, 3, 1; ... 1, 1, 2; 2, 3, 2; 1, 1, 2; 2, 1, 2; 2, 1, 3; 1, 3, 2; 2, 1, 2; ... 2, 1, 2; 1, 3, 1; 2, 1, 1; 2, 1, 2; 1, 3, 2; 1, 1, 2; 1, 1, 2; ... 1, 1, 2; 1, 2, 3; 2, 2, 3; 3, 1, 2; 3, 3, 1; 2, 1, 3; 2, 1, 2; ... 3, 1, 1; 3, 3, 2; 1, 2, 2; 1, 3, 2; 2, 1, 2; 1, 3, 3; 1, 3, 2; ... 3, 1, 3; 2, 1, 2; 2, 1, 1; 2, 1, 2; 3, 3, 2; 2, 1, 2; 1, 3, 2; ... 2, 1, 2; 2, 1, 2; 2, 3, 2; 3, 2, 1; 1, 3, 2; 3, 1, 3; 3, 1, 3; ... 1, 3, 2; 3, 2, 3; 3, 2, 2; 3, 3, 1]; lgf = @(Z) 3 * (Z(:,1) == 1) .* (Z(:,2) == 2) + (Z(:,3) == 3) ... + 0.5 * Z(:,1) .* (Z(:,3) == 1); ***** test L = lime (lgf, lgX, 'Type', 'regression', 'CategoricalPredictors', ... [1, 2, 3], 'CustomSyntheticData', lgS); a = fit (L, [3, 1, 2], 3, 'Distance', 'goodall3', 'KernelWidth', 0.25); assert_equal (a.SimpleModel.Beta', [0.121118041142843, ... -0.000600506617868, 0.398788365579973, 0.021938631288382, ... 1.340450289008853, 1.006911791276333], 1e-4); ***** test L = lime (lgf, lgX, 'Type', 'regression', 'CategoricalPredictors', ... [1, 2, 3], 'CustomSyntheticData', lgS); a = fit (L, [3, 1, 2], 3, 'KernelWidth', 0.75); assert_equal (a.SimpleModel.Beta', [0.228175170664997, ... 0.013506333846389, 0.753704128127034, -0.009766750012839, ... 1.230617170587539, 0.995575992275549], 1e-4); ***** test ## Ours; MATLAB's undocumented rule gives [0.177564664766370, ## 0.005664618556746, 0.676928812402028, 0.004396374156961, ## 1.246265361445370, 0.993126581893467] L = lime (lgf, lgX, 'Type', 'regression', 'CategoricalPredictors', ... [1, 2, 3], 'CustomSyntheticData', lgS); a = fit (L, [3, 1, 2], 3, 'Distance', 'ofd', 'KernelWidth', 0.25); assert_equal (a.SimpleModel.Beta', [0.174628345510863, ... 0.00526956351961691, 0.671359079482785, ... 0.0052078819336837, 1.24767221788603, ... 0.993112744621723], 1e-6); ***** test # each coefficient is read against the query point's level C = [1, 1; 2, 1; 3, 1; 1, 2; 2, 2; 3, 2; 3, 1; 1, 2]; f = @(Z) 5 * (Z(:,1) == 3); L = lime (f, C, 'Type', 'regression', 'CategoricalPredictors', [1, 2], ... 'CustomSyntheticData', C); a = fit (L, [3, 1], 1); assert_equal (a.ImportantPredictors, 1); assert_equal (a.SimpleModel.Beta', [-5, -5], 1e-3); ***** test # a predictor held at the query point's level throughout is not taken C = [2, 1; 2, 2; 2, 3; 2, 1; 2, 2; 2, 3]; f = @(Z) Z(:,2); L = lime (f, C, 'Type', 'regression', 'CategoricalPredictors', [1, 2], ... 'CustomSyntheticData', C); a = fit (L, [2, 1], 2); assert_equal (a.ImportantPredictors, 2); ***** error ... fit (lime (@(Z) Z(:,1), [1, 1; 1, 1], 'Type', 'regression', ... 'CategoricalPredictors', [1, 2]), [1, 1], 1) 56 tests, 56 passed, 0 known failure, 0 skipped [inst/Machine_Learning/templateSVM.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/templateSVM.m ***** test # the default template names its learner and nothing else T = templateSVM (); assert_equal (class (T), 'struct'); assert_equal (T.Method, 'SVM'); assert_equal (T.Type, 'classification'); assert_equal (numfields (T), 2); ***** test # an option given is stored under its own name, as it stands T = templateSVM ('KernelFunction', 'rbf', 'BoxConstraint', 2); assert_equal (numfields (T), 4); assert_equal (T.KernelFunction, 'rbf'); assert_equal (T.BoxConstraint, 2); ***** test # a name the learner does not know is not refused here T = templateSVM ('NoSuchOption', 42); assert_equal (T.NoSuchOption, 42); ***** error ... templateSVM ('KernelScale') ***** error ... templateSVM (42, 1) ***** error ... templateSVM ('not a name', 1) 6 tests, 6 passed, 0 known failure, 0 skipped [inst/Machine_Learning/ClassificationPartitionedKernel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/ClassificationPartitionedKernel.m ***** demo ## Cross-validate a Gaussian kernel classifier on the two overlapping ## iris species and read the out-of-sample error rate. load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedKernel (X, Y, 'KFold', 5) outOfSample = kfoldLoss (CVMdl) ***** test ## The model reports the surface MATLAB reports load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedKernel (X, Y, 'KFold', 5); assert_equal (class (CVMdl), 'ClassificationPartitionedKernel'); assert_equal (CVMdl.CrossValidatedModel, 'Kernel'); assert_equal (CVMdl.KFold, 5); assert_equal (CVMdl.NumObservations, 100); assert_equal (CVMdl.ClassNames, {'versicolor'; 'virginica'}); assert_equal (CVMdl.Prior, [0.5, 0.5]); assert_equal (class (CVMdl.Trained{1}), 'ClassificationKernel'); assert_equal (CVMdl.ModelParameters.Method, 'PartitionedKernel'); assert_equal (CVMdl.ModelParameters.LearnerTemplates, 'Kernel'); assert_equal (CVMdl.ModelParameters.NLearn, 5); ***** test ## The properties are the ones MATLAB lists, in its order load fisheriris CVMdl = ClassificationPartitionedKernel (meas(51:end,:), species(51:end)); assert_equal (sort (properties (CVMdl)), ... sort ({'ClassNames'; 'Cost'; 'Prior'; 'ScoreTransform'; ... 'CrossValidatedModel'; 'NumObservations'; 'Y'; 'W'; ... 'PredictorNames'; 'CategoricalPredictors'; ... 'ResponseName'; 'Trained'; 'KFold'; 'Partition'; ... 'ModelParameters'})); ***** test ## Each fold resolves 'Lambda' against its own training rows, which is ## one eightieth of five folds over a hundred observations. R2024a's ## number. load fisheriris CVMdl = ClassificationPartitionedKernel (meas(51:end,:), ... species(51:end), 'KFold', 5); assert_equal (CVMdl.Trained{1}.Lambda, 1 / 80, 1e-15); assert_equal (CVMdl.Trained{1}.NumExpansionDimensions, 128); assert_equal (CVMdl.Trained{1}.KernelScale, 1); ***** test ## Every fold draws its own basis, so two folds hold different ## expansions of the same kernel load fisheriris CVMdl = ClassificationPartitionedKernel (meas(51:end,:), ... species(51:end), 'KFold', 5); X = meas(51:53,:); [~, s1] = predict (CVMdl.Trained{1}, X); [~, s2] = predict (CVMdl.Trained{2}, X); assert_equal (isequal (s1, s2), false); ***** test ## kfoldPredict classifies each observation with the fold that held it ## out, and doing the same partition by hand agrees load fisheriris X = meas(51:end,:); Y = species(51:end); part = cvpartition (Y, 'KFold', 4); CVMdl = ClassificationPartitionedKernel (X, Y, 'CVPartition', part); label = kfoldPredict (CVMdl); byhand = cell (100, 1); for k = 1:4 te = test (part, k); byhand(te) = predict (CVMdl.Trained{k}, X(te,:)); endfor assert_equal (label, byhand); ***** test ## The fit separates the two species out of sample load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedKernel (X, Y, 'KFold', 5); assert_equal (kfoldLoss (CVMdl) < 0.2, true); assert_equal (kfoldEdge (CVMdl) > 0, true); assert_equal (numel (kfoldMargin (CVMdl)), 100); ***** test ## 'Mode', 'individual' gives one row per fold, and averaging pools the ## observations rather than the fold values load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedKernel (X, Y, 'KFold', 5); assert_equal (size (kfoldLoss (CVMdl, 'Mode', 'individual')), [5, 1]); label = kfoldPredict (CVMdl); assert_equal (kfoldLoss (CVMdl), mean (! strcmp (label, Y)), 1e-12); ***** test ## A logistic fit reports posteriors, and the transform stays with the ## fold models as it does in MATLAB load fisheriris CVMdl = ClassificationPartitionedKernel (meas(51:end,:), ... species(51:end), 'KFold', 5, ... 'Learner', 'logistic'); assert_equal (CVMdl.ScoreTransform, 'none'); assert_equal (CVMdl.Trained{1}.ScoreTransform, 'logit'); [~, score] = kfoldPredict (CVMdl); assert_equal (sum (score, 2), ones (100, 1), 1e-12); ***** test ## An observation that no fold held out is not classified load fisheriris CVMdl = ClassificationPartitionedKernel (meas(51:end,:), ... species(51:end), 'Holdout', 0.3); assert_equal (CVMdl.KFold, 1); [label, score] = kfoldPredict (CVMdl); assert_equal (sum (cellfun (@isempty, label)), 70); assert_equal (sum (isnan (score(:,1))), 70); ***** test ## A character matrix response carries through cross-validation load fisheriris X = meas(51:end,:); Yc = species(51:end); part = cvpartition (Yc, 'KFold', 4); CVm = ClassificationPartitionedKernel (X, char (Yc), 'CVPartition', part); assert_equal (size (CVm.ClassNames), [2, 10]); assert_equal (cellstr (CVm.ClassNames), {'versicolor'; 'virginica'}); assert_equal (size (kfoldPredict (CVm)), [100, 10]); assert_equal (isfinite (kfoldLoss (CVm)), true); assert_equal (isfinite (kfoldEdge (CVm)), true); ***** test ## A transform asked for by name goes to the parent and not to the folds, ## and is applied once to the assembled scores. R2024a's arrangement. ## The baseline is read from the same object with the transform switched ## off, a second fit being no baseline at all here: the random feature ## expansion differs between two fits of the same data. load fisheriris CVMdl = ClassificationPartitionedKernel (meas(51:end,:), species(51:end), ... 'KFold', 5, ... 'ScoreTransform', 'doublelogit'); assert_equal (CVMdl.ScoreTransform, 'doublelogit'); assert_equal (CVMdl.Trained{1}.ScoreTransform, 'none'); [~, s1] = kfoldPredict (CVMdl); CVMdl.ScoreTransform = 'none'; [~, s0] = kfoldPredict (CVMdl); assert_equal (s1, 1 ./ (1 + exp (-2 * s0)), 1e-12); ***** test ## It can be assigned after the model is built, and reaches kfoldPredict ## without being carried into the folds load fisheriris CVMdl = ClassificationPartitionedKernel (meas(51:end,:), species(51:end), ... 'KFold', 5); [~, s0] = kfoldPredict (CVMdl); CVMdl.ScoreTransform = 'doublelogit'; [~, s1] = kfoldPredict (CVMdl); assert_equal (CVMdl.Trained{1}.ScoreTransform, 'none'); assert_equal (s1, 1 ./ (1 + exp (-2 * s0)), 1e-12); ***** test ## A transform the learner implies stays with the folds, and an assigned ## one is applied on top of it rather than replacing it. Measured on ## R2024a, where the folds keep 'logit' and the parent's transform ## composes. load fisheriris CVMdl = ClassificationPartitionedKernel (meas(51:end,:), species(51:end), ... 'KFold', 5, ... 'Learner', 'logistic'); [~, s0] = kfoldPredict (CVMdl); CVMdl.ScoreTransform = 'doublelogit'; [~, s1] = kfoldPredict (CVMdl); assert_equal (CVMdl.Trained{1}.ScoreTransform, 'logit'); assert_equal (s1, 1 ./ (1 + exp (-2 * s0)), 1e-12); ***** test ## 'none' is the identity, so assigning it transforms nothing load fisheriris CVMdl = ClassificationPartitionedKernel (meas(51:end,:), species(51:end), ... 'KFold', 5); [~, s0] = kfoldPredict (CVMdl); CVMdl.ScoreTransform = 'none'; [~, s1] = kfoldPredict (CVMdl); assert_equal (s1, s0); ***** error ... load fisheriris CVMdl = ClassificationPartitionedKernel (meas(51:end,:), species(51:end), ... 'KFold', 5); CVMdl.ScoreTransform = 'nosuchtransform'; ***** error ... ClassificationPartitionedKernel (ones (10, 2)) ***** error ... ClassificationPartitionedKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'KFold') ***** error ... ClassificationPartitionedKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'KFold', 0) ***** error ... ClassificationPartitionedKernel (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'KFold', 2, 'Leaveout', 'on') ***** error ... kfoldLoss (ClassificationPartitionedKernel (ones (10, 2), ... [ones(5,1); 2*ones(5,1)], 'KFold', 2), 'LossFun', 'mse') ***** error ... kfoldEdge (ClassificationPartitionedKernel (ones (10, 2), ... [ones(5,1); 2*ones(5,1)], 'KFold', 2), 'Folds', 0) ***** test load fisheriris CVMdl = fitckernel (meas, strcmp (species, 'setosa'), 'KFold', 3); MP = CVMdl.ModelParameters; assert_equal (MP.Method, 'PartitionedKernel'); assert_equal (MP.LearnerTemplates, 'Kernel'); assert_equal (MP.NLearn, 3); assert_equal (MP.Learner, 'svm'); assert_equal (MP.BlockSize, 4000); ***** test load fisheriris Mdl = fitckernel (meas, strcmp (species, 'setosa'), 'KFold', 3); Mdl.ScoreTransform = 'none'; [label, raw] = kfoldPredict (Mdl); T = {'identity', @(x) x; 'doublelogit', @(x) 1 ./ (1 + exp (-2 * x)); ... 'invlogit', @(x) log (x ./ (1 - x)); ... 'logit', @(x) 1 ./ (1 + exp (-x)); ... 'sign', @(x) sign (x); 'symmetric', @(x) 2 * x - 1; ... 'symmetriclogit', @(x) 2 ./ (1 + exp (-x)) - 1}; for i = 1:rows (T) Mdl.ScoreTransform = T{i,1}; [l, s] = kfoldPredict (Mdl); assert_equal (s, T{i,2}(raw), 1e-12); assert_equal (l, label); endfor ## ismax marks the largest score of each observation, ties to the first. [~, k] = max (raw, [], 2); e = zeros (size (raw)); e(sub2ind (size (raw), (1:rows (raw))', k)) = 1; Mdl.ScoreTransform = 'ismax'; [~, s] = kfoldPredict (Mdl); assert_equal (s, e); Mdl.ScoreTransform = 'symmetricismax'; [~, s] = kfoldPredict (Mdl); assert_equal (s, 2 * e - 1); ***** test load fisheriris Mdl = fitckernel (meas, strcmp (species, 'setosa'), 'KFold', 3); Mdl.ScoreTransform = 'none'; [label, raw] = kfoldPredict (Mdl); Mdl.ScoreTransform = @(x) x .^ 2; [l, s] = kfoldPredict (Mdl); assert_equal (s, raw .^ 2, 1e-12); assert_equal (l, label); ***** test # the predictors and the response may come from a table load fisheriris inds = ! strcmp (species, 'setosa'); T = table (meas(inds,1), meas(inds,2), 'VariableNames', {'SL', 'SW'}); T.Species = categorical (species(inds)); CVMdl = ClassificationPartitionedKernel (T, 'Species', 'KFold', 3); assert_equal (class (CVMdl), 'ClassificationPartitionedKernel'); assert_equal (CVMdl.KFold, 3); 25 tests, 25 passed, 0 known failure, 0 skipped [inst/Machine_Learning/partialDependence.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/partialDependence.m ***** shared pdX, pdYr, pdYc, pdY3, pdQ, pdLo, pdHi x1 = repmat ([1;2;3], 8, 1); x2 = reshape (repmat (1:8, 3, 1), 24, 1); pdX = [x1, x2]; pdYr = 10 * x2 + x1; pdYc = (x2 > 4) + 1; pdY3 = repmat ({'a'; 'b'; 'c'}, 8, 1); pdQ = [1; 2; 3]; lo1 = repmat ([1;2;3], 4, 1); one = ones (12, 1); pdLo = [lo1, one]; pdHi = [lo1, 8 * one]; ***** test Mdl = fitlm (pdX, pdYr); assert_equal (partialDependence (Mdl, 1, 'QueryPoints', pdQ), ... [46, 47, 48], 1e-10); ***** test # and over the observations it is handed rather than its own Mdl = fitlm (pdX, pdYr); assert_equal (partialDependence (Mdl, 1, pdLo, 'QueryPoints', pdQ), ... [11, 12, 13], 1e-10); ***** test # MATLAB parity: two variables give one row per point of the second Mdl = fitlm (pdX, pdYr); [pd, x, y] = partialDependence (Mdl, [1, 2], 'QueryPoints', {pdQ, [2;5]}); assert_equal (pd, [21, 22, 23; 51, 52, 53], 1e-10); assert_equal (size (pd), [2, 3]); assert_equal (x', [1, 2, 3]); assert_equal (y', [2, 5]); ***** test Mdl = fitrtree (pdX, pdYr); assert_equal (partialDependence (Mdl, 1, 'QueryPoints', pdQ), ... [47, 47, 47], 1e-10); ***** test # and does not move when the observations it is handed are replaced Mdl = fitrtree (pdX, pdYr); lo = partialDependence (Mdl, 1, pdLo, 'QueryPoints', pdQ); hi = partialDependence (Mdl, 1, pdHi, 'QueryPoints', pdQ); assert_equal (lo, hi); assert_equal (lo, [47, 47, 47], 1e-10); ***** test # a compact tree keeps no observations and answers just the same Mdl = compact (fitrtree (pdX, pdYr)); assert_equal (partialDependence (Mdl, 1, pdLo, 'QueryPoints', pdQ), ... [47, 47, 47], 1e-10); ***** test # the traversal equals averaging the tree over its training data Mdl = fitrtree (pdX, pdYr); pd = partialDependence (Mdl, 1, 'QueryPoints', pdQ); avg = zeros (1, 3); for k = 1:3 Z = pdX; Z(:,1) = pdQ(k); avg(k) = mean (predict (Mdl, Z)); endfor assert_equal (pd, avg, 1e-10); ***** test xc = repmat ([1;2;3;4], 6, 1); x2 = reshape (repmat (1:8, 3, 1), 24, 1); y = 10 * (xc == 1) + 20 * (xc == 2) + 30 * (xc == 3) + 40 * (xc == 4) + x2; Mdl = fitrtree ([xc, x2], y, 'CategoricalPredictors', 1); [pd, x] = partialDependence (Mdl, 1); assert_equal (x', [1, 2, 3, 4]); assert_equal (pd, [14, 73/3, 104/3, 45], 1e-10); ***** test # and takes its levels whatever query points are asked for xc = repmat ([1;2;3;4], 6, 1); x2 = reshape (repmat (1:8, 3, 1), 24, 1); y = 10 * (xc == 1) + 20 * (xc == 2) + 30 * (xc == 3) + 40 * (xc == 4) + x2; Mdl = fitrtree ([xc, x2], y, 'CategoricalPredictors', 1); [a, ax] = partialDependence (Mdl, 1); [b, bx] = partialDependence (Mdl, 1, 'QueryPoints', [1; 2]); assert_equal (a, b); assert_equal (ax, bx); ***** test Mdl = fitrgam (pdX, pdYr); lo = partialDependence (Mdl, 1, pdLo, 'QueryPoints', pdQ); hi = partialDependence (Mdl, 1, pdHi, 'QueryPoints', pdQ); assert_equal (lo, hi); assert_equal (lo, [46, 47, 48], 1e-6); ***** test # excluding the intercept takes it off the result Mdl = fitrgam (pdX, pdYr); with = partialDependence (Mdl, 1, 'QueryPoints', pdQ); without = partialDependence (Mdl, 1, 'QueryPoints', pdQ, ... 'IncludeIntercept', false); assert_equal (with - Mdl.Intercept, without, 1e-10); ***** test Mdl = fitrensemble (pdX, pdYr, 'Method', 'Bag', 'NumLearningCycles', 5); lo = partialDependence (Mdl, 1, pdLo, 'QueryPoints', pdQ); hi = partialDependence (Mdl, 1, pdHi, 'QueryPoints', pdQ); assert_equal (lo, hi); ***** test # a compacted bagged ensemble carries no Method and is still bagged Mdl = compact (fitrensemble (pdX, pdYr, 'Method', 'Bag', ... 'NumLearningCycles', 5)); lo = partialDependence (Mdl, 1, pdLo, 'QueryPoints', pdQ); hi = partialDependence (Mdl, 1, pdHi, 'QueryPoints', pdQ); assert_equal (lo, hi); ***** test # a boosted ensemble moves with the observations it is handed Mdl = fitrensemble (pdX, pdYr, 'Method', 'LSBoost', 'NumLearningCycles', 5); lo = partialDependence (Mdl, 1, pdLo, 'QueryPoints', pdQ); hi = partialDependence (Mdl, 1, pdHi, 'QueryPoints', pdQ); assert_equal (isequal (lo, hi), false); ***** test # a regression model varying one predictor gives a row Mdl = fitrsvm (pdX, pdYr); assert_equal (size (partialDependence (Mdl, 1, 'QueryPoints', pdQ)), [1, 3]); ***** test # a classifier gives one row per class named Mdl = fitctree (pdX, pdY3); pd3 = partialDependence (Mdl, 1, {'a', 'b', 'c'}, 'QueryPoints', pdQ); pd1 = partialDependence (Mdl, 1, 'b', 'QueryPoints', pdQ); assert_equal (size (pd3), [3, 3]); assert_equal (size (pd1), [1, 3]); ***** test # and two predictors add a dimension between them Mdl = fitctree (pdX, pdY3); pd = partialDependence (Mdl, [1, 2], {'a', 'b'}, ... 'QueryPoints', {pdQ, [2; 5]}); assert_equal (size (pd), [2, 2, 3]); ***** test # MATLAB parity: the rows follow the order the classes were named in Mdl = fitctree (pdX, pdY3); abc = partialDependence (Mdl, 1, {'a', 'b', 'c'}, 'QueryPoints', pdQ); ca = partialDependence (Mdl, 1, {'c', 'a'}, 'QueryPoints', pdQ); assert_equal (ca(1,:), abc(3,:)); assert_equal (ca(2,:), abc(1,:)); ***** test # MATLAB parity: a hundred points spanning what the observations hold Mdl = fitrsvm (pdX, pdYr); [~, x] = partialDependence (Mdl, 1); assert_equal (numel (x), 100); assert_equal ([min(x), max(x)], [1, 3]); ***** test # the query points come from the observations handed over Mdl = fitrtree (pdX, pdYr); wide = [repmat([10;15;20], 4, 1), 4 * ones(12, 1)]; [~, x] = partialDependence (Mdl, 1, wide); assert_equal ([min(x), max(x)], [10, 20]); ***** test # a second output is empty where only one predictor was named Mdl = fitrsvm (pdX, pdYr); [~, ~, y] = partialDependence (Mdl, 1, 'QueryPoints', pdQ); assert_equal (isempty (y), true); ***** test # sampling draws from the observations and the answer stays finite Mdl = fitrsvm (pdX, pdYr); pd = partialDependence (Mdl, 1, 'QueryPoints', pdQ, ... 'NumObservationsToSample', 6); assert_equal (size (pd), [1, 3]); assert_equal (all (isfinite (pd)), true); ***** test # asking for more observations than there are takes all of them Mdl = fitrsvm (pdX, pdYr); a = partialDependence (Mdl, 1, 'QueryPoints', pdQ); b = partialDependence (Mdl, 1, 'QueryPoints', pdQ, ... 'NumObservationsToSample', 500); assert_equal (a, b); ***** test # a predictor may be named rather than indexed Mdl = fitrsvm (pdX, pdYr, 'PredictorNames', {'a', 'b'}); assert_equal (partialDependence (Mdl, 'a', 'QueryPoints', pdQ), ... partialDependence (Mdl, 1, 'QueryPoints', pdQ)); ***** test # and two may be, in a cellstr Mdl = fitrsvm (pdX, pdYr, 'PredictorNames', {'a', 'b'}); byname = partialDependence (Mdl, {'a', 'b'}, 'QueryPoints', {pdQ, [2;5]}); byidx = partialDependence (Mdl, [1, 2], 'QueryPoints', {pdQ, [2;5]}); assert_equal (byname, byidx); ***** test f = @(Z) 2 * Z(:,1) + Z(:,2); assert_equal (partialDependence (f, 1, pdX, 'QueryPoints', pdQ), ... [2 + 4.5, 4 + 4.5, 6 + 4.5], 1e-10); ***** test # and its columns may be picked f = @(Z) [Z(:,1), 2 * Z(:,1)]; pd = partialDependence (f, 1, pdX, 'QueryPoints', pdQ, ... 'OutputColumns', 2); assert_equal (pd, [2, 4, 6], 1e-10); ***** test Mdl = fitrsvm (pdX, pdYr); [a, ax, ay] = partialDependence (Mdl, 1, 'QueryPoints', pdQ); [b, bx, by] = Mdl.partialDependence (1, 'QueryPoints', pdQ); assert_equal (a, b); assert_equal (ax, bx); assert_equal (ay, by); ***** error ... partialDependence (1) ***** error ... partialDependence (42, 1) ***** error ... partialDependence (fitctree (pdX, pdYc), 1) ***** error ... partialDependence (fitrsvm (pdX, pdYr), 1, {'a'}) ***** error ... partialDependence (fitctree (pdX, pdY3), 1, {'z'}, 'QueryPoints', pdQ) ***** error ... partialDependence (compact (fitrsvm (pdX, pdYr)), 1) ***** error ... partialDependence (compact (fitrgam (pdX, pdYr)), 1) ***** error ... partialDependence (fitctree (pdX, pdYc), 1, 1, {1, 2}) ***** error ... partialDependence (fitrsvm (pdX, pdYr), 5) ***** error ... partialDependence (fitrsvm (pdX, pdYr), 'z') ***** error ... partialDependence (fitrsvm (pdX, pdYr), [1, 1]) ***** error ... partialDependence (fitrsvm (pdX, pdYr), [1, 2, 1]) ***** error ... partialDependence (fitrsvm (pdX, pdYr), 1, 'UseParallel', true) ***** error ... partialDependence (fitrsvm (pdX, pdYr), 1, 'PredictionForMissingValue', 0) ***** error ... partialDependence (fitrsvm (pdX, pdYr), 1, 'IncludeInteractions', true) ***** error ... partialDependence (fitrsvm (pdX, pdYr), 1, 'IncludeIntercept', false) ***** error ... partialDependence (fitrsvm (pdX, pdYr), 1, 'CategoricalPredictors', 1) ***** error ... partialDependence (fitrsvm (pdX, pdYr), 1, 'OutputColumns', 1) ***** error ... partialDependence (fitrsvm (pdX, pdYr), 1, 'QueryPoints', ones (3, 3)) ***** error ... partialDependence (fitrsvm (pdX, pdYr), [1, 2], 'QueryPoints', ones (3, 3)) ***** error ... partialDependence (fitrsvm (pdX, pdYr), 1, 'NumObservationsToSample', 2.5) ***** error ... partialDependence (@(Z) Z(:,1), 1) 50 tests, 50 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitcnb.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitcnb.m ***** demo ## Fit a naive Bayes classifier to Fisher's iris data and see how often it ## classifies a training observation into its own species. load fisheriris Mdl = fitcnb (meas, species) printf ("resubstitution loss: %g\n", resubLoss (Mdl)); ***** demo ## The petal measurements separate the species far better than the sepal ## ones, and a kernel density follows a skewed predictor where a normal ## one cannot. load fisheriris normalMdl = fitcnb (meas, species); kernelMdl = fitcnb (meas, species, 'DistributionNames', 'kernel'); printf ("normal : %g\n", resubLoss (normalMdl)); printf ("kernel : %g\n", resubLoss (kernelMdl)); ***** demo ## Fit from a table, and predict on one load fisheriris T = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = categorical (species); ## A column holding levels is a categorical predictor without being named ## one T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ## The response is named by its column, and everything else is a predictor Mdl = fitcnb (T, 'Species'); Mdl.PredictorNames Mdl.CategoricalPredictors ## A model formula names them instead, holding main effects only Mdl2 = fitcnb (T, 'Species ~ PL + PW'); Mdl2.PredictorNames ## predict reads a table by the names the model was fitted on, so the ## columns may come in any order label = predict (Mdl, T(1:5, [6, 5, 4, 3, 2, 1])); label' ***** test # the driver returns what the constructor returns load fisheriris Mdl = fitcnb (meas, species); assert_equal (class (Mdl), 'ClassificationNaiveBayes'); assert_equal (Mdl.NumObservations, 150); assert_equal (Mdl.ClassNames, unique (species)); ***** test # MATLAB parity: the fitted parameters and the resubstitution loss load fisheriris Mdl = fitcnb (meas, species); assert_equal (Mdl.DistributionParameters{1,1}, ... [5.005999999999998; 0.352489687213451], 1e-13); assert_equal (resubLoss (Mdl), 0.04, 1e-14); ***** test # name-value arguments reach the constructor load fisheriris Mdl = fitcnb (meas, species, 'Prior', 'uniform', 'ResponseName', 'flower'); assert_equal (Mdl.Prior, [1/3, 1/3, 1/3], 1e-15); assert_equal (Mdl.ResponseName, 'flower'); ***** error fitcnb () ***** error fitcnb (ones (4, 1)) ***** error ... fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], ones (4, 1), 'Prior') ***** error ... fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], ones (3, 1)) ***** error ... fitcnb ([1, 2; 2, 3; 3, 4; 4, 5], ones (3, 1), 'Prior', 'uniform') ***** error ... fitcnb ([1, 2; 2, 3; 3, 4; 10, 20], [1; 1; 1; 2]) ***** error ... load fisheriris fitcnb (meas, species, 'ClassNames', [3, 1, 2]) ***** test # classes named as text for numeric labels keep the labels' type load fisheriris Y = [ones(50, 1); 2 * ones(50, 1); 3 * ones(50, 1)]; Mdl = fitcnb (meas, Y, 'ClassNames', {'3', '1', '2'}); assert_equal (Mdl.ClassNames, [3; 1; 2]); ***** shared fnbT load fisheriris fnbT = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); fnbT.Species = categorical (species); fnbT.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ***** test # the response is named by a column and the rest are predictors Mdl = fitcnb (fnbT, 'Species'); assert_equal (Mdl.PredictorNames, {'SL', 'SW', 'PL', 'PW', 'Wide'}); assert_equal (Mdl.ResponseName, 'Species'); assert_equal (Mdl.CategoricalPredictors, 5); ***** test # a model formula names the response and the predictors together Mdl = fitcnb (fnbT, 'Species ~ PW + SL'); assert_equal (Mdl.PredictorNames, {'PW', 'SL'}); assert_equal (isempty (Mdl.CategoricalPredictors), true); ***** test # the response may be given beside a table of predictors Mdl = fitcnb (fnbT(:,1:4), fnbT.Species); assert_equal (Mdl.PredictorNames, {'SL', 'SW', 'PL', 'PW'}); assert_equal (Mdl.ResponseName, 'Y'); ***** test # predict takes a table, matched by name and not by position Mdl = fitcnb (fnbT, 'Species'); a = predict (Mdl, fnbT); assert_equal (class (a), 'categorical'); assert_equal (predict (Mdl, fnbT(:, [6, 5, 4, 3, 2, 1])), a); ***** test # the levels travel with the model when it is made compact Mdl = fitcnb (fnbT, 'Species'); CMdl = compact (Mdl); assert_equal (CMdl.PredictorLevels, Mdl.PredictorLevels); assert_equal (predict (CMdl, fnbT), predict (Mdl, fnbT)); ***** error ... fitcnb (fnbT, 'NoSuch') ***** error ... fitcnb (fnbT, 'Species ~ SL*PW') ***** error ... predict (fitcnb (fnbT, 'Species'), fnbT(:, [1, 3, 4, 5, 6])) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitctree.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitctree.m ***** demo ## Grow a classification tree on Fisher's iris data and look at it load fisheriris Mdl = fitctree (meas, species); ## The tree as text: a branch names its cut, a leaf names its class view (Mdl); ## How much each predictor contributed predictorImportance (Mdl) ## The resubstitution error of the whole tree and of its subtrees resubLoss (Mdl) ***** demo ## Prune a tree back and watch the error rise as it gets smaller load fisheriris Mdl = fitctree (meas, species); levels = 0:numel (Mdl.PruneAlpha) - 1; leaves = zeros (size (levels)); err = zeros (size (levels)); for ii = 1:numel (levels) sub = prune (Mdl, 'Level', levels(ii)); leaves(ii) = sum (! sub.IsBranchNode); err(ii) = resubLoss (sub); endfor [leaves(:), err(:)] ***** demo ## Fit from a table, and predict on one load fisheriris T = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... categorical (species), 'VariableNames', ... {'SL', 'SW', 'PL', 'PW', 'Species'}); ## A column holding levels is a categorical predictor without being named ## one, so the width of the sepal is split into two and comes back as the ## fifth predictor rather than as a number T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ## The response is named by its column, and everything else is a predictor Mdl = fitctree (T, 'Species'); Mdl.PredictorNames Mdl.CategoricalPredictors ## A model formula names them instead, holding main effects only Mdl2 = fitctree (T, 'Species ~ PL + Wide'); Mdl2.PredictorNames ## predict reads a table by the names the model was fitted on, so the ## columns may come in any order and may carry more than the model needs label = predict (Mdl, T(1:5, [6, 4, 3, 2, 1, 5])); label' ***** test # MATLAB parity: the tree a default fit grows on fisheriris load fisheriris Mdl = fitctree (meas, species); assert_equal (class (Mdl), 'ClassificationTree'); assert_equal (Mdl.NumNodes, 9); assert_equal (Mdl.NodeSize', [150, 50, 100, 54, 46, 48, 6, 47, 1]); assert_equal (Mdl.Parent', [0, 1, 1, 3, 3, 4, 4, 6, 6]); assert_equal (Mdl.CutPredictorIndex', [3, 0, 4, 3, 0, 4, 0, 0, 0]); ***** test # MATLAB parity: the cut points and the predictors they name load fisheriris Mdl = fitctree (meas, species); assert_equal (Mdl.CutPoint([1, 3, 4, 6])', [2.45, 1.75, 4.95, 1.65]); assert_equal (isnan (Mdl.CutPoint([2, 5, 7, 8, 9]))', true (1, 5)); assert_equal (Mdl.CutPredictor', {'x3', '', 'x4', 'x3', '', 'x4', ... '', '', ''}); assert_equal (Mdl.CutType', {'continuous', '', 'continuous', ... 'continuous', '', 'continuous', '', '', ''}); ***** test # MATLAB parity: the class the fit reports for every node load fisheriris Mdl = fitctree (meas, species); assert_equal (Mdl.NodeClass', {'setosa', 'setosa', 'versicolor', ... 'versicolor', 'virginica', 'versicolor', ... 'virginica', 'versicolor', 'virginica'}); assert_equal (Mdl.ClassCount, [50, 50, 50; 50, 0, 0; 0, 50, 50; ... 0, 49, 5; 0, 1, 45; 0, 47, 1; ... 0, 2, 4; 0, 47, 0; 0, 0, 1]); ***** test # MATLAB parity: predict, its four outputs and its scores load fisheriris Mdl = fitctree (meas, species); [label, score, node, cnum] = predict (Mdl, meas([1, 60, 120], :)); assert_equal (label, {'setosa'; 'versicolor'; 'virginica'}); assert_equal (node', [2, 8, 7]); assert_equal (cnum', [1, 2, 3]); assert_equal (score, [1, 0, 0; 0, 1, 0; 0, 1/3, 2/3], 1e-14); ***** test # MATLAB parity: the losses on the training data load fisheriris Mdl = fitctree (meas, species); assert_equal (resubLoss (Mdl), 0.02, 1e-14); assert_equal (loss (Mdl, meas, species), 0.02, 1e-14); assert_equal (resubEdge (Mdl), 0.9384, 1e-4); ***** test # MATLAB parity: a fit that keeps every split it made load fisheriris Mdl = fitctree (meas, species, 'MergeLeaves', 'off'); assert_equal (Mdl.NumNodes, 11); assert_equal (isempty (Mdl.PruneList), false); ***** test # MATLAB parity: turning both reductions off leaves no sequence load fisheriris Mdl = fitctree (meas, species, 'MergeLeaves', 'off', 'Prune', 'off'); assert_equal (Mdl.NumNodes, 11); assert_equal (isempty (Mdl.PruneList), true); assert_equal (isempty (Mdl.PruneAlpha), true); ***** test # MATLAB parity: a merged tree carries a sequence with Prune off load fisheriris Mdl = fitctree (meas, species, 'Prune', 'off'); assert_equal (Mdl.PruneList', [4, 0, 3, 2, 0, 1, 0, 0, 0]); assert_equal (Mdl.PruneAlpha', [0, 1/150, 2/150, 44/150, 50/150], 1e-14); ***** test # MATLAB parity: MinParentSize is raised to two leaves load fisheriris Mdl = fitctree (meas, species, 'MinParentSize', 3, 'MinLeafSize', 2); assert_equal (Mdl.ModelParameters.MinParent, 4); assert_equal (Mdl.NodeSize', [150, 50, 100, 54, 46, 48, 6, 3, 3]); ***** test # MATLAB parity: a leaf size that stops the tree early load fisheriris Mdl = fitctree (meas, species, 'MinLeafSize', 20); assert_equal (Mdl.NumNodes, 5); assert_equal (Mdl.NodeSize', [150, 50, 100, 54, 46]); ***** test # MATLAB parity: a budget of two splits load fisheriris Mdl = fitctree (meas, species, 'MaxNumSplits', 2); assert_equal (Mdl.NumNodes, 5); assert_equal (Mdl.NodeSize', [150, 50, 100, 54, 46]); ***** test # MATLAB parity: the deviance criterion and the risk it reports load fisheriris Mdl = fitctree (meas, species, 'SplitCriterion', 'deviance'); assert_equal (Mdl.NumNodes, 9); assert_equal (Mdl.CutPoint([1, 3, 4, 6])', [2.45, 1.75, 4.95, 1.65]); assert_equal (Mdl.NodeRisk(1), 0.792481250360578, 1e-12); assert_equal (Mdl.NodeRisk(4), 0.0801, 1e-4); ***** test # MATLAB parity: the prior a weighted fit reports load fisheriris Mdl = fitctree (meas, species, 'Weights', (1:150)'); assert_equal (Mdl.Prior, [1275, 3775, 6275] / 11325, 1e-14); assert_equal (sum (Mdl.W), 1, 1e-14); assert_equal (Mdl.NumNodes, 7); assert_equal (Mdl.NodeSize', [150, 95, 55, 50, 45, 44, 1]); ***** test # MATLAB parity: a uniform prior over an unbalanced sample ## The shape of this tree is not asserted. A uniform prior over 50, 20 ## and 10 observations makes the split that isolates setosa and the one ## that isolates virginica exactly equal, at a gain of 1/3 each, and the ## two engines keep opposite sides of the tie. load fisheriris inds = [1:50, 51:70, 101:110]; Mdl = fitctree (meas(inds, :), species(inds), 'Prior', 'uniform'); assert_equal (Mdl.Prior, [1/3, 1/3, 1/3], 1e-14); assert_equal (Mdl.W([1, 51, 71])', [1/150, 1/60, 1/30], 1e-14); assert_equal (sum (Mdl.W), 1, 1e-14); assert_equal (Mdl.NodeSize(1), 80); assert_equal (resubLoss (Mdl), 0, 1e-14); ***** test # MATLAB parity: a cost matrix reshapes the tree load fisheriris Mdl = fitctree (meas, species, 'Cost', [0, 1, 10; 1, 0, 1; 10, 1, 0]); assert_equal (Mdl.NumNodes, 9); assert_equal (Mdl.NodeSize', [150, 50, 100, 45, 55, 44, 1, 9, 46]); assert_equal (Mdl.CutPoint([1, 3, 4, 5])', [2.45, 4.75, 1.65, 1.75]); assert_equal (Mdl.NodeClass{1}, 'versicolor'); assert_equal (Mdl.NodeRisk(1), 0.572916666666667, 1e-12); assert_equal (Mdl.PruneAlpha', [0, 1/150, 43/150, 50/150], 1e-12); ***** test # MATLAB parity: the label type is the response's own load fisheriris y = strcmp (species, 'setosa'); Mdl = fitctree (meas, y); assert_equal (class (Mdl.ClassNames), 'logical'); assert_equal (class (predict (Mdl, meas(1, :))), 'logical'); Mdl = fitctree (meas, grp2idx (species)); assert_equal (Mdl.ClassNames, [1; 2; 3]); assert_equal (Mdl.NodeClass{1}, '1'); ***** test # MATLAB parity: a categorical response gives categorical labels load fisheriris Mdl = fitctree (meas, categorical (species)); label = predict (Mdl, meas([1, 60, 120], :)); assert_equal (label, categorical ({'setosa'; 'versicolor'; 'virginica'})); assert_equal (Mdl.NodeClass{1}, 'setosa'); ***** test # A string response gives string labels, where MATLAB gives cellstr load fisheriris Mdl = fitctree (meas, string (species)); label = predict (Mdl, meas([1, 60, 120], :)); assert_equal (label, string ({'setosa'; 'versicolor'; 'virginica'})); assert_equal (Mdl.NodeClass{1}, 'setosa'); ***** test # MATLAB parity: a missing response drops its row, a missing X does not load fisheriris x = meas; x(1:10, 4) = NaN; Mdl = fitctree (x, species); assert_equal (Mdl.NumObservations, 150); assert_equal (Mdl.RowsUsed, []); y = species; y(1:10) = {''}; Mdl = fitctree (meas, y); assert_equal (Mdl.NumObservations, 140); assert_equal (sum (Mdl.RowsUsed), 140); ***** test # MATLAB parity: ClassNames keeps only the classes it names load fisheriris Mdl = fitctree (meas, species, 'ClassNames', {'setosa', 'versicolor'}); assert_equal (Mdl.ClassNames, {'setosa'; 'versicolor'}); assert_equal (Mdl.NumObservations, 100); assert_equal (Mdl.NodeSize', [100, 50, 50]); assert_equal (Mdl.Prior, [0.5, 0.5], 1e-14); ***** test # MATLAB parity: a number below the predictor count is kept load fisheriris Mdl = fitctree (meas, species, 'NumVariablesToSample', 2); assert_equal (Mdl.ModelParameters.NVarToSample, 2); ***** test # MATLAB parity: a number covering every predictor is reported 'all' load fisheriris Mdl = fitctree (meas, species, 'NumVariablesToSample', 5); assert_equal (Mdl.ModelParameters.NVarToSample, 'all'); ***** test # the generator's state reproduces a sampled tree load fisheriris rng (1); A = fitctree (meas, species, 'NumVariablesToSample', 1); rng (1); B = fitctree (meas, species, 'NumVariablesToSample', 1); assert_equal (A.CutPredictorIndex, B.CutPredictorIndex); assert_equal (isequaln (A.CutPoint, B.CutPoint), true); ***** test # MATLAB parity: a split budget spent inside a layer keeps the best load fisheriris T = fitctree (meas(:,1:2), species, 'MaxNumSplits', 7); assert_equal (T.CutPredictorIndex', [1, 2, 1, 0, 0, 2, 1, 0, 0, 2, 0, 0, 0]); assert_equal (T.NodeSize', [150, 52, 98, 7, 45, 43, 55, 38, 5, 43, 12, ... 2, 41]); assert_equal (T.CutPoint([1, 2, 3, 6, 7, 10])', ... [5.45, 2.8, 6.15, 3.45, 7.05, 2.4], 1e-12); ***** test # MATLAB parity: the budget ranks weighted splits by their gain load fisheriris w = [5 * ones(50, 1); (1:100)' / 20]; T = fitctree (meas(:,1:2), species, 'MaxNumSplits', 6, 'Weights', w); assert_equal (T.CutPredictorIndex', [1, 2, 1, 1, 0, 2, 2, 0, 0, 0, 0, ... 0, 0]); assert_equal (T.NodeSize', [150, 59, 91, 12, 47, 36, 55, 3, 9, 33, 3, ... 2, 53]); assert_equal (T.CutPoint([1, 2, 3, 4, 6, 7])', ... [5.55, 2.8, 6.15, 4.95, 3.6, 2.4], 1e-12); ***** test # MATLAB parity: the budget ranks deviance splits by their gain load fisheriris T = fitctree (meas, species, 'MaxNumSplits', 4, ... 'SplitCriterion', 'deviance', 'MinParentSize', 2); assert_equal (T.CutPredictorIndex', [3, 0, 4, 3, 0, 0, 0]); assert_equal (T.NodeSize', [150, 50, 100, 54, 46, 48, 6]); assert_equal (T.CutPoint([1, 3, 4])', [2.45, 1.75, 4.95], 1e-12); ***** error fitctree () ***** error fitctree (ones (4, 1)) ***** error fitctree (ones (4, 2), ones (4, 1), 'K') ***** error fitctree (ones (4, 2), ones (3, 1)) ***** error fitctree (ones (4, 2), ones (3, 1), 'K', 2) ***** test # MATLAB parity: classes given as text are sorted load fisheriris k = [101:150, 51:100]; Mdl = fitctree (meas(k,:), species(k)); assert_equal (Mdl.ClassNames, {'versicolor'; 'virginica'}); ***** test # MATLAB parity: a given ClassNames order is kept load fisheriris Mdl = fitctree (meas(51:150,:), species(51:150), ... 'ClassNames', {'virginica'; 'versicolor'}); assert_equal (Mdl.ClassNames, {'virginica'; 'versicolor'}); ***** test # the score columns follow a given ClassNames order load fisheriris Mdl = fitctree (meas(51:150,:), species(51:150), ... 'ClassNames', {'virginica'; 'versicolor'}); [label, s] = predict (Mdl, meas(51,:)); assert_equal (label, {'versicolor'}); assert_equal (s(2) > s(1), true); ***** test # classes named as text for numeric labels keep the given order load fisheriris Y = [ones(50, 1); 2 * ones(50, 1); 3 * ones(50, 1)]; Mdl = fitctree (meas, Y, 'ClassNames', {'3', '1', '2'}); assert_equal (Mdl.ClassNames, [3; 1; 2]); ***** error ... load fisheriris fitctree (meas, species, 'ClassNames', [3, 1, 2]) ***** test # classes named 'true' and 'false' for logical labels load fisheriris Y = [false(50, 1); true(50, 1)]; Mdl = fitctree (meas(51:150,:), Y, 'ClassNames', {'true'; 'false'}); assert_equal (Mdl.ClassNames, [true; false]); ***** error ... load fisheriris fitctree (meas(51:150,:), [false(50, 1); true(50, 1)], ... 'ClassNames', {'1'; '0'}) ***** test # MATLAB parity: 'all' and a logical vector name categorical predictors k = (0:79)'; c = mod (k, 4) + 1; j = floor (k / 4); y = (c == 1) | (c == 2 & mod (j, 4) != 0) | (c == 3 & mod (j, 4) == 0); Mdl = fitctree ([c, mod(k * 7, 10)], y, 'CategoricalPredictors', 'all'); assert_equal (Mdl.CategoricalPredictors, [1, 2]); Mdl = fitctree ([c, mod(k * 7, 10)], y, 'CategoricalPredictors', ... logical ([1, 0])); assert_equal (Mdl.CategoricalPredictors, 1); assert_equal (Mdl.CutCategories(1,:), {[1, 2], [3, 4]}); ***** test # MATLAB parity: levels need not be integers k = (0:79)'; c = mod (k, 4) + 1; j = floor (k / 4); y = (c == 1) | (c == 2 & mod (j, 4) != 0) | (c == 3 & mod (j, 4) == 0); Mdl = fitctree ([c + 0.5, mod(k * 7, 10)], y, 'CategoricalPredictors', 1); assert_equal (Mdl.CutCategories(1,:), {[1.5, 2.5], [3.5, 4.5]}); ***** shared ftT load fisheriris ftT = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); ftT.Species = categorical (species); ftT.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ftT.Flag = meas(:,1) > 5.8; ***** test # the response is named by a column and the rest are predictors Mdl = fitctree (ftT, 'Species'); assert_equal (Mdl.PredictorNames, {'SL', 'SW', 'PL', 'PW', 'Wide', 'Flag'}); assert_equal (Mdl.ResponseName, 'Species'); assert_equal (class (Mdl), 'ClassificationTree'); ***** test Mdl = fitctree (ftT, 'Species'); assert_equal (Mdl.CategoricalPredictors, [5, 6]); ***** test # 'CategoricalPredictors' adds to what the table says, not replaces it Mdl = fitctree (ftT, 'Species', 'CategoricalPredictors', 1); assert_equal (Mdl.CategoricalPredictors, [1, 5, 6]); ***** test # a model formula names the response and the predictors together Mdl = fitctree (ftT, 'Species ~ SL + Wide'); assert_equal (Mdl.PredictorNames, {'SL', 'Wide'}); assert_equal (Mdl.ResponseName, 'Species'); assert_equal (Mdl.CategoricalPredictors, 2); ***** test # the predictors keep the order the formula wrote them in Mdl = fitctree (ftT, 'Species ~ PW + SL'); assert_equal (Mdl.PredictorNames, {'PW', 'SL'}); ***** test # the response may be given beside a table of predictors Mdl = fitctree (ftT(:,1:4), categorical (ftT.Species)); assert_equal (Mdl.PredictorNames, {'SL', 'SW', 'PL', 'PW'}); assert_equal (Mdl.ResponseName, 'Y'); assert_equal (isempty (Mdl.CategoricalPredictors), true); ***** test # 'PredictorNames' takes a subset of the table's variables Mdl = fitctree (ftT, 'Species', 'PredictorNames', {'SL', 'PW'}); assert_equal (Mdl.PredictorNames, {'SL', 'PW'}); ***** test # a column of text is a categorical predictor as a categorical is T = table (ftT.SL, 'VariableNames', {'SL'}); T.g = repmat ({'x'; 'y'; 'z'}, 50, 1); T.y = ftT.Species; Mdl = fitctree (T, 'y'); assert_equal (Mdl.PredictorNames, {'SL', 'g'}); assert_equal (Mdl.CategoricalPredictors, 2); ***** test # a matrix is taken as it always was load fisheriris Mdl = fitctree (meas, species); assert_equal (columns (Mdl.X), 4); assert_equal (isempty (Mdl.PredictorLevels), true); ***** error ... fitctree (ftT, 'NoSuch') ***** error ... fitctree (ftT(:,5), 'Species') ***** error ... fitctree (ftT, 'Species ~ SL*PW') ***** error ... fitctree (ftT, 'Species ~ SL + SL^2') ***** error ... fitctree (ftT, 'Species ~ nope') ***** error ... fitctree (ftT, 'SL + PW') ***** error ... fitctree (ftT, 'Species', 'PredictorNames', {'nope'}) ***** error ... fitctree (ftT, 'Species ~ SL', 'PredictorNames', {'SL'}) 57 tests, 57 passed, 0 known failure, 0 skipped [inst/Machine_Learning/ClassificationTree.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/ClassificationTree.m ***** test # MATLAB parity: the surface a default fit reports load fisheriris Mdl = ClassificationTree (meas, species); assert_equal (class (Mdl), 'ClassificationTree'); assert_equal (Mdl.NumObservations, 150); assert_equal (Mdl.ClassNames, unique (species)); assert_equal (Mdl.Prior, [1/3, 1/3, 1/3], 1e-15); assert_equal (Mdl.Cost, [0, 1, 1; 1, 0, 1; 1, 1, 0]); assert_equal (Mdl.ResponseName, 'Y'); assert_equal (Mdl.PredictorNames, {'x1', 'x2', 'x3', 'x4'}); assert_equal (Mdl.ExpandedPredictorNames, {'x1', 'x2', 'x3', 'x4'}); assert_equal (Mdl.ScoreTransform, 'none'); assert_equal (Mdl.CategoricalPredictors, []); assert_equal (Mdl.RowsUsed, []); assert_equal (Mdl.W, ones (150, 1) / 150, 1e-15); ***** test # MATLAB parity: what a tree with no categories and no surrogates holds load fisheriris Mdl = ClassificationTree (meas, species); assert_equal (size (Mdl.CutCategories), [9, 2]); assert_equal (all (cellfun (@isempty, Mdl.CutCategories(:))), true); assert_equal (size (Mdl.CategoricalSplit), [0, 0]); assert_equal (size (Mdl.SurrogateCutPredictor), [0, 1]); assert_equal (size (Mdl.SurrogateCutPoint), [0, 0]); assert_equal (size (Mdl.SurrogatePredictorAssociation), [0, 0]); assert_equal (Mdl.BinEdges, {}); assert_equal (Mdl.HyperparameterOptimizationResults, []); ***** test # MATLAB parity: the parameters a default fit reports load fisheriris Mdl = ClassificationTree (meas, species); MP = Mdl.ModelParameters; assert_equal (MP.SplitCriterion, 'gdi'); assert_equal ({MP.MinParent, MP.MinLeaf, MP.MaxSplits}, {10, 1, 149}); assert_equal ({MP.MergeLeaves, MP.Prune}, {'on', 'on'}); assert_equal ({MP.PruneCriterion, MP.NVarToSample}, {'error', 'all'}); assert_equal ({MP.NSurrogate, MP.MaxCat, MP.AlgCat}, {0, 10, 'auto'}); assert_equal (MP.PredictorSelection, 'allsplits'); assert_equal ({MP.Method, MP.Type}, {'Tree', 'classification'}); ***** test # MATLAB parity: the node statistics of the iris tree load fisheriris Mdl = ClassificationTree (meas, species); assert_equal (Mdl.NodeProbability', [150, 50, 100, 54, 46, 48, 6, 47, 1] ... / 150, 1e-14); assert_equal (Mdl.NodeError', [2/3, 0, 1/2, 5/54, 1/46, 1/48, 1/3, 0, 0], ... 1e-14); assert_equal (Mdl.NodeRisk(1), 2/3, 1e-14); assert_equal (Mdl.NodeRisk(3), 1/3, 1e-14); assert_equal (Mdl.ClassProbability(1,:), [1/3, 1/3, 1/3], 1e-14); assert_equal (Mdl.ClassProbability(7,:), [0, 1/3, 2/3], 1e-14); ***** test # NodeRisk is the impurity weighted by the node probability load fisheriris Mdl = ClassificationTree (meas, species); gdi = 1 - sum (Mdl.ClassProbability .^ 2, 2); assert_equal (Mdl.NodeRisk, Mdl.NodeProbability .* gdi, 1e-14); ***** test # MATLAB parity: prune takes a subtree out of the sequence load fisheriris Mdl = ClassificationTree (meas, species); sub = prune (Mdl, 'Level', 1); assert_equal (sub.NumNodes, 7); assert_equal (sub.NodeSize', [150, 50, 100, 54, 46, 48, 6]); assert_equal (sub.PruneList', [3, 0, 2, 1, 0, 0, 0]); assert_equal (sub.Children, [2, 3; 0, 0; 4, 5; 6, 7; 0, 0; 0, 0; 0, 0]); assert_equal (sub.Parent', [0, 1, 1, 3, 3, 4, 4]); ***** test # MATLAB parity: a level of two, and level zero changing nothing load fisheriris Mdl = ClassificationTree (meas, species); assert_equal (prune (Mdl, 'Level', 2).NodeSize', [150, 50, 100, 54, 46]); assert_equal (prune (Mdl, 'Level', 0).NumNodes, 9); assert_equal (prune (Mdl).NumNodes, 9); ***** test # MATLAB parity: a cost complexity parameter picks its own level load fisheriris Mdl = ClassificationTree (meas, species); assert_equal (prune (Mdl, 'Alpha', 0.1).NumNodes, 5); assert_equal (prune (Mdl, 'Alpha', 0).NumNodes, 9); assert_equal (prune (Mdl, 'Alpha', 1).NumNodes, 1); ***** test # Pruning named nodes turns just those into leaves load fisheriris Mdl = ClassificationTree (meas, species); sub = prune (Mdl, 'Nodes', 3); assert_equal (sub.NumNodes, 3); assert_equal (sub.NodeSize', [150, 50, 100]); assert_equal (sub.IsBranchNode', [true, false, false]); ***** test # The pruned tree re-derives its own sequence, and it is the shifted one load fisheriris Mdl = ClassificationTree (meas, species); sub = prune (Mdl, 'Level', 1); assert_equal (sub.PruneAlpha', [0, 2/150, 44/150, 50/150], 1e-14); ***** warning load fisheriris Mdl = ClassificationTree (meas, species); sub = prune (Mdl, 'Level', 9); ***** test # MATLAB parity: the four outputs of predict, and a missing predictor load fisheriris Mdl = ClassificationTree (meas, species); x = meas([1, 60, 120], :); x(1, 3) = NaN; [label, score, node, cnum] = predict (Mdl, x); assert_equal (node', [1, 8, 7]); assert_equal (label, {'setosa'; 'versicolor'; 'virginica'}); assert_equal (cnum', [1, 2, 3]); assert_equal (score(1,:), [1/3, 1/3, 1/3], 1e-14); ***** test # MATLAB parity: a row missing every predictor stops at the root load fisheriris Mdl = ClassificationTree (meas, species); [label, score, node] = predict (Mdl, NaN (1, 4)); assert_equal (node, 1); assert_equal (label, {'setosa'}); assert_equal (score, [1/3, 1/3, 1/3], 1e-14); ***** test # MATLAB parity: the score transform is applied to the probabilities load fisheriris Mdl = ClassificationTree (meas, species, 'ScoreTransform', 'logit'); [~, score] = predict (Mdl, meas([1, 60, 120], :)); assert_equal (Mdl.ScoreTransform, 'logit'); assert_equal (score(1,:), [0.731058578630005, 0.5, 0.5], 1e-14); ***** test # MATLAB parity: predictorImportance divides by the branch node count load fisheriris Mdl = ClassificationTree (meas, species); imp = predictorImportance (Mdl); assert_equal (size (imp), [1, 4]); assert_equal (imp(1:2), [0, 0]); assert_equal (imp(3:4), [0.0907, 0.0682], 1e-4); ***** test # MATLAB parity: the range of each predictor on the path to a node load fisheriris Mdl = ClassificationTree (meas, species); assert_equal (fieldnames (nodeVariableRange (Mdl, 1)), cell (0, 1)); r = nodeVariableRange (Mdl, 8); assert_equal (r.x3, [2.45, 4.95], 1e-14); assert_equal (r.x4, [-Inf, 1.65], 1e-14); ***** test # MATLAB parity: the text form of the tree load fisheriris Mdl = ClassificationTree (meas, species); txt = evalc ('view (Mdl)'); lines = strsplit (strtrim (txt), "\n"); assert_equal (numel (lines), 10); assert_equal (lines{1}, 'Decision tree for classification'); assert_equal (lines{2}, ... '1 if x3<2.45 then node 2 elseif x3>=2.45 then node 3 else setosa'); assert_equal (lines{3}, '2 class = setosa'); ***** test # MATLAB parity: the seven classification losses on the training data load fisheriris Mdl = ClassificationTree (meas, species); assert_equal (resubLoss (Mdl, 'LossFun', 'binodeviance'), 0.1388, 1e-4); assert_equal (resubLoss (Mdl, 'LossFun', 'classiferror'), 0.02, 1e-14); assert_equal (resubLoss (Mdl, 'LossFun', 'exponential'), 0.3829, 1e-4); assert_equal (resubLoss (Mdl, 'LossFun', 'hinge'), 0.0308, 1e-4); assert_equal (resubLoss (Mdl, 'LossFun', 'logit'), 0.3232, 1e-4); assert_equal (resubLoss (Mdl, 'LossFun', 'mincost'), 0.02, 1e-14); assert_equal (resubLoss (Mdl, 'LossFun', 'quadratic'), 0.0154, 1e-4); ***** test # MATLAB parity: margin and edge load fisheriris Mdl = ClassificationTree (meas, species); m = margin (Mdl, meas([1, 60, 120], :), species([1, 60, 120])); assert_equal (m', [1, 1, 1/3], 1e-14); assert_equal (size (resubMargin (Mdl)), [150, 1]); assert_equal (resubEdge (Mdl), 0.9384, 1e-4); assert_equal (edge (Mdl, meas, species), resubEdge (Mdl), 1e-14); ***** test # resubPredict answers exactly as predict on the training data load fisheriris Mdl = ClassificationTree (meas, species); [l1, s1, n1, c1] = resubPredict (Mdl); [l2, s2, n2, c2] = predict (Mdl, meas); assert_equal ({l1, s1, n1, c1}, {l2, s2, n2, c2}); ***** test # MATLAB parity: a cost matrix reaches the label and the risk load fisheriris Mdl = ClassificationTree (meas, species, ... 'Cost', [0, 2, 8; 3, 0, 1; 5, 4, 0]); assert_equal (Mdl.NodeSize', [150, 50, 100, 45, 55, 44, 1]); assert_equal (Mdl.NodeClass{1}, 'versicolor'); assert_equal (Mdl.NodeError(1), 2, 1e-14); assert_equal (Mdl.NodeRisk(1), 0.6276, 1e-4); assert_equal (Mdl.PruneAlpha', [0, 0.0267, 0.2667, 1.6667], 1e-4); ***** test # Reassigning Cost re-derives the node statistics, not the tree load fisheriris Mdl = ClassificationTree (meas, species); shape = {Mdl.Children, Mdl.NodeSize, Mdl.ClassCount}; Mdl.Cost = [0, 2, 8; 3, 0, 1; 5, 4, 0]; assert_equal ({Mdl.Children, Mdl.NodeSize, Mdl.ClassCount}, shape); assert_equal (Mdl.NodeClass{1}, 'versicolor'); assert_equal (Mdl.NodeError(1), 2, 1e-14); ***** test # Reassigning Prior re-derives the weights and the node statistics load fisheriris Mdl = ClassificationTree (meas, species); Mdl.Prior = [0.5, 0.25, 0.25]; assert_equal (Mdl.Prior, [0.5, 0.25, 0.25], 1e-14); assert_equal (Mdl.W([1, 51, 101])', [0.01, 0.005, 0.005], 1e-14); assert_equal (Mdl.ClassProbability(1,:), [0.5, 0.25, 0.25], 1e-14); assert_equal (Mdl.NodeProbability(2), 0.5, 1e-14); assert_equal (Mdl.NodeRisk(1), 0.625, 1e-14); ***** test # A prior given as a structure names its own class order load fisheriris p.ClassNames = {'virginica'; 'versicolor'; 'setosa'}; p.ClassProbs = [0.25, 0.25, 0.5]; Mdl = ClassificationTree (meas, species, 'Prior', p); assert_equal (Mdl.Prior, [0.5, 0.25, 0.25], 1e-14); ***** test # A structure prior may name its classes in a character matrix load fisheriris p.ClassNames = char ({'virginica'; 'versicolor'; 'setosa'}); p.ClassProbs = [0.25, 0.25, 0.5]; Mdl = ClassificationTree (meas, char (species), 'Prior', p); assert_equal (Mdl.Prior, [0.5, 0.25, 0.25], 1e-14); ***** test # A cost given as a structure names its own class order load fisheriris c.ClassNames = {'virginica'; 'versicolor'; 'setosa'}; c.ClassificationCosts = [0, 1, 10; 1, 0, 1; 10, 1, 0]; Mdl = ClassificationTree (meas, species, 'Cost', c); assert_equal (Mdl.Cost, [0, 1, 10; 1, 0, 1; 10, 1, 0]); assert_equal (Mdl.NodeSize', [150, 50, 100, 45, 55, 44, 1, 9, 46]); ***** test # A response of one class alone gives a tree of one node load fisheriris Mdl = ClassificationTree (meas(1:5, :), species(1:5)); assert_equal (Mdl.NumNodes, 1); assert_equal (Mdl.NodeClass, {'setosa'}); assert_equal (Mdl.ClassProbability, 1); assert_equal (predict (Mdl, meas(1, :)), {'setosa'}); ***** test # A model saved and loaded answers exactly as it did load fisheriris Mdl = ClassificationTree (meas, species); fname = tempname (); unwind_protect savemodel (Mdl, fname); New = loadmodel (fname); assert_equal (class (New), 'ClassificationTree'); assert_equal (New.NumNodes, Mdl.NumNodes); assert_equal (New.NodeRisk, Mdl.NodeRisk, 1e-15); assert_equal (New.CutPredictor, Mdl.CutPredictor); assert_equal (predict (New, meas), predict (Mdl, meas)); unwind_protect_cleanup delete (fname); end_unwind_protect ***** test # MATLAB parity: an unmerged tree records no level for a free subtree ## With MergeLeaves off, the pair of leaves that merging would have ## removed survives, and giving it up costs nothing. MATLAB records ## neither a level nor an alpha for such a subtree, so the sequence is ## the merged tree's, over eleven nodes instead of nine. load fisheriris Mdl = ClassificationTree (meas, species, 'MergeLeaves', 'off'); assert_equal (Mdl.NumNodes, 11); assert_equal (Mdl.PruneList', [4, 0, 3, 2, 0, 1, 0, 0, 0, 0, 0]); assert_equal (Mdl.PruneAlpha', [0, 1/150, 2/150, 44/150, 50/150], 1e-14); ***** test # MATLAB parity: a deeper tree, every branch pruned at its own level load fisheriris Mdl = ClassificationTree (meas, species, 'MinParentSize', 2); assert_equal (Mdl.NumNodes, 17); assert_equal (Mdl.PruneList', [5, 0, 4, 3, 1, 2, 2, 1, 0, 0, 0, 0, 2, ... 0, 0, 0, 0]); assert_equal (Mdl.PruneAlpha', [0, 0.5, 1, 2, 44, 50] / 150, 1e-14); assert_equal (predictorImportance (Mdl), ... [0.00222222222222222, 0, 0.0458935520665593, ... 0.0352175590445518], 1e-14); ***** test # MATLAB parity: the resubstitution methods weigh as the fit weighed load fisheriris Mdl = ClassificationTree (meas, species, 'Weights', (1:150)'); assert_equal (resubLoss (Mdl), 0.0384988962472406, 1e-14); assert_equal (resubEdge (Mdl), 0.856171294940654, 1e-14); ## loss and edge over the same data weigh it uniformly unless told not to assert_equal (loss (Mdl, meas, species), 0.04, 1e-14); assert_equal (edge (Mdl, meas, species), 0.853582991377224, 1e-14); assert_equal (loss (Mdl, meas, species, 'Weights', (1:150)'), ... 0.0384988962472406, 1e-14); ***** test # MATLAB parity: edge on a set missing a class load fisheriris Mdl = ClassificationTree (meas, species); r = 51:150; assert_equal (edge (Mdl, meas(r,:), species(r)), 0.9075362319, 1e-10); assert_equal (edge (Mdl, meas(r,:), species(r), 'Weights', (1:100)'), ... 0.9037275415, 1e-10); ***** test # MATLAB parity: the tree a weighted fit grows load fisheriris Mdl = ClassificationTree (meas, species, 'Weights', (1:150)'); assert_equal (Mdl.NodeSize', [150, 95, 55, 50, 45, 44, 1]); assert_equal (Mdl.NodeProbability', [1, 0.416865342163355, ... 0.583134657836645, ... 0.112582781456954, ... 0.304282560706402, ... 0.294834437086093, ... 0.00944812362030905], 1e-14); assert_equal (Mdl.NodeRisk(1), 0.569205054359214, 1e-14); assert_equal (Mdl.PruneAlpha', [0, 0.00944812362030906, ... 0.112582781456954, 0.285386313465784], ... 1e-14); ***** test # MATLAB parity: the resubstitution edge under a cost matrix load fisheriris Mdl = ClassificationTree (meas, species, ... 'Cost', [0, 1, 10; 1, 0, 1; 10, 1, 0]); assert_equal (resubLoss (Mdl), 1/30, 1e-14); assert_equal (resubEdge (Mdl), 0.914653784219002, 1e-14); ***** test # MATLAB parity: compact drops the data and answers identically load fisheriris Mdl = ClassificationTree (meas, species); CMdl = compact (Mdl); assert_equal (class (CMdl), 'CompactClassificationTree'); assert_equal (numel (properties (CMdl)), 33); assert_equal (predict (CMdl, meas), predict (Mdl, meas)); assert_equal (CMdl.NodeRisk, Mdl.NodeRisk, 1e-15); ***** test # MATLAB parity: crossval returns a partitioned model over compacts load fisheriris Mdl = ClassificationTree (meas, species); CVMdl = crossval (Mdl); assert_equal (class (CVMdl), 'ClassificationPartitionedModel'); assert_equal (CVMdl.CrossValidatedModel, 'Tree'); assert_equal (class (CVMdl.Trained{1}), 'CompactClassificationTree'); assert_equal (CVMdl.KFold, 10); assert_equal (CVMdl.NumObservations, 150); assert_equal (CVMdl.Prior, Mdl.Prior, 1e-15); assert_equal (CVMdl.Cost, Mdl.Cost); ***** test # Each way of asking for a partition gives the folds it names load fisheriris Mdl = ClassificationTree (meas, species); assert_equal (crossval (Mdl, 'KFold', 5).KFold, 5); assert_equal (crossval (Mdl, 'Holdout', 0.3).KFold, 1); assert_equal (crossval (Mdl, 'Leaveout', 'on').KFold, 150); assert_equal (crossval (Mdl, 'CVPartition', ... cvpartition (species, 'KFold', 4)).KFold, 4); ***** test # A fold is grown with the parent's prior, cost and weights load fisheriris Mdl = ClassificationTree (meas, species, 'Weights', (1:150)', ... 'Cost', [0, 1, 10; 1, 0, 1; 10, 1, 0]); CVMdl = crossval (Mdl, 'KFold', 3); assert_equal (CVMdl.Trained{1}.Prior, Mdl.Prior, 1e-15); assert_equal (CVMdl.Trained{1}.Cost, Mdl.Cost); assert_equal (CVMdl.Trained{1}.ClassNames, Mdl.ClassNames); ***** test # A fold is grown with the parameters the parent was grown with load fisheriris Mdl = ClassificationTree (meas, species, 'SplitCriterion', 'deviance', ... 'MinLeafSize', 7, 'MergeLeaves', 'off'); CVMdl = crossval (Mdl, 'KFold', 3); assert_equal (CVMdl.ModelParameters.SplitCriterion, 'deviance'); assert_equal (CVMdl.ModelParameters.MinLeaf, 7); assert_equal (CVMdl.ModelParameters.MergeLeaves, 'off'); ***** test # kfoldPredict scores every observation and costs them from the score load fisheriris CVMdl = crossval (ClassificationTree (meas, species), 'KFold', 5); [label, score, cost] = kfoldPredict (CVMdl); assert_equal (size (label), [150, 1]); assert_equal (size (score), [150, 3]); assert_equal (cost, score * CVMdl.Cost, 1e-14); assert_equal (sum (score, 2), ones (150, 1), 1e-14); assert_equal (kfoldLoss (CVMdl) < 0.2, true); assert_equal (size (kfoldMargin (CVMdl)), [150, 1]); ***** test # cvloss over a fixture whose folds all answer alike ## The two classes are separated by a gap no fold can straddle, so every ## fold grows the same tree and every quantity below is the same whatever ## partition is drawn. x = [(1:20)'; (101:120)']; y = [repmat({'a'}, 20, 1); repmat({'b'}, 20, 1)]; Mdl = ClassificationTree (x, y); assert_equal (Mdl.NumNodes, 3); [E, SE, Nleaf, BestLevel] = cvloss (Mdl, 'SubTrees', 'all'); assert_equal (E', [0, 0.5], 1e-14); assert_equal (SE', [0, 0], 1e-14); assert_equal (Nleaf', [2, 1]); assert_equal (BestLevel, 0); ***** test # MATLAB parity: the leaf counts and the stable loss of the iris tree ## Only the last level's loss is asserted. Its parameter is infinite, so ## every fold's tree goes back to its root whatever the partition, and a ## root under a uniform prior answers the first class, which two thirds ## of the data are not. The levels below it are not fixed: a fold's tree ## is matched to a subtree of the whole by a complexity parameter, and ## which of its own levels that picks out depends on the rows it saw. load fisheriris Mdl = ClassificationTree (meas, species); [E, SE, Nleaf, BestLevel] = cvloss (Mdl, 'SubTrees', 'all'); assert_equal (size (E), [5, 1]); assert_equal (Nleaf', [5, 4, 3, 2, 1]); assert_equal (E(5), 2/3, 1e-14); assert_equal (SE(5), 0, 1e-12); assert_equal (BestLevel >= 0 && BestLevel <= 4, true); ***** test # cvloss defaults to the unpruned tree alone load fisheriris Mdl = ClassificationTree (meas, species); [E, SE, Nleaf, BestLevel] = cvloss (Mdl); assert_equal (size (E), [1, 1]); assert_equal (Nleaf, 5); assert_equal (BestLevel, 0); assert_equal (E > 0 && E < 0.2, true); ***** test # A subset of the levels is answered in the order it was asked for load fisheriris Mdl = ClassificationTree (meas, species); [E, SE, Nleaf, BestLevel] = cvloss (Mdl, 'SubTrees', [0, 2, 4]); assert_equal (Nleaf', [5, 3, 1]); assert_equal (E(3), 2/3, 1e-14); assert_equal (any (BestLevel == [0, 2, 4]), true); ***** test # TreeSize picks the smallest tree the rule allows ## 'min' takes the smallest tree of least loss and 'se' the smallest whose ## loss is within one standard error of it, so 'se' never names a larger ## tree than 'min' does. load fisheriris Mdl = ClassificationTree (meas, species); [E, SE] = cvloss (Mdl, 'SubTrees', 'all'); [~, ~, ~, bmin] = cvloss (Mdl, 'SubTrees', 'all', 'TreeSize', 'min'); [~, ~, ~, bse] = cvloss (Mdl, 'SubTrees', 'all', 'TreeSize', 'se'); assert_equal (bmin >= 0 && bmin <= 4, true); assert_equal (bse >= 0 && bse <= 4, true); ***** test # The number of folds is the number asked for load fisheriris Mdl = ClassificationTree (meas, species); [E, SE, Nleaf] = cvloss (Mdl, 'KFold', 5); assert_equal (size (E), [1, 1]); assert_equal (Nleaf, 5); assert_equal (E > 0 && E < 0.2, true); ***** test # cvloss weighs the loss as the fit weighed it ## A weighted fit whose folds all answer alike. The three to one weights ## make the prior 0.25 and 0.75, so every fold's root answers the heavier ## class and the twenty rows of the lighter one are wrong. Their weight ## is 0.25, where their share of the rows is 0.5. x = [(1:20)'; (101:120)']; y = [repmat({'a'}, 20, 1); repmat({'b'}, 20, 1)]; Mdl = ClassificationTree (x, y, 'Weights', [ones(20, 1); 3 * ones(20, 1)]); assert_equal (Mdl.Prior, [0.25, 0.75], 1e-14); E = cvloss (Mdl, 'SubTrees', 'all'); assert_equal (E(1), 0, 1e-14); assert_equal (E(2), 0.25, 1e-14); ***** test # More folds than observations are reduced to one fold each ## The reduction warns, and so does cvpartition about a fold that cannot ## hold every class, so the message is not what is asserted here; the ## answer is, and it is the one leaving each observation out in turn. x = [(1:20)'; (101:120)']; y = [repmat({'a'}, 20, 1); repmat({'b'}, 20, 1)]; Mdl = ClassificationTree (x, y); ws = warning ('off', 'all'); unwind_protect E = cvloss (Mdl, 'KFold', 500, 'SubTrees', 'all'); unwind_protect_cleanup warning (ws); end_unwind_protect assert_equal (E', [0, 0.5], 1e-14); ***** test # MATLAB parity: a node that holds rows back pays for them ## Twenty rows have no fourth predictor, and the node that cuts on it ## sends them to neither child. They are in no child's risk, so a ## subtree's risk is its children's plus what the node holds back, and ## leaving that out would overstate every link above it. load fisheriris x = meas; x(51:70, 4) = NaN; Mdl = ClassificationTree (x, species); assert_equal (Mdl.NumNodes, 9); assert_equal (Mdl.NodeSize', [150, 50, 100, 45, 55, 25, 1, 8, 46]); assert_equal (Mdl.NodeSize(4) - sum (Mdl.NodeSize(Mdl.Children(4,:))), 19); assert_equal (Mdl.PruneList', [4, 0, 3, 1, 2, 0, 0, 0, 0]); assert_equal (Mdl.PruneAlpha', [0, 0.00385185185185185, ... 0.00593939393939394, 0.286666666666666, ... 0.333333333333333], 1e-14); assert_equal (predictorImportance (Mdl), ... [0, 0, 0.145589225589225, 0.00944980621616545], 1e-14); assert_equal (resubLoss (Mdl), 0.04, 1e-14); ***** test # MATLAB parity: held-back rows under a cost matrix ## The weight a node holds back is a different fraction of it on the two ## scales a classification tree is measured by, so the pruning sequence ## and the predictor importances discount different amounts. load fisheriris x = meas; x(51:80, 3) = NaN; Mdl = ClassificationTree (x, species, ... 'Cost', [0, 1, 10; 1, 0, 1; 10, 1, 0]); assert_equal (Mdl.NumNodes, 7); assert_equal (Mdl.NodeSize', [150, 50, 70, 15, 55, 5, 50]); assert_equal (Mdl.NodeSize(1) - sum (Mdl.NodeSize(Mdl.Children(1,:))), 30); assert_equal (Mdl.PruneList', [3, 0, 2, 0, 1, 0, 0]); assert_equal (Mdl.PruneAlpha', [0, 0.02, 0.1, 0.4], 1e-14); assert_equal (predictorImportance (Mdl), ... [0, 0, 0.17774350820443, 0], 1e-14); ***** test # MATLAB parity: held-back rows with the leaves left unmerged load fisheriris x = meas; x(51:70, 4) = NaN; Mdl = ClassificationTree (x, species, 'MergeLeaves', 'off'); assert_equal (Mdl.NumNodes, 11); assert_equal (Mdl.NodeSize', [150, 50, 100, 45, 55, 25, 1, 8, 46, 3, 43]); assert_equal (Mdl.PruneList', [4, 0, 3, 1, 2, 0, 0, 0, 0, 0, 0]); assert_equal (Mdl.PruneAlpha', [0, 0.00385185185185185, ... 0.00593939393939394, 0.286666666666666, ... 0.333333333333333], 1e-14); ***** test # A categorical 'ClassNames' keeps only the classes it names load fisheriris Mdl = ClassificationTree (meas, categorical (species), 'ClassNames', ... categorical ({'versicolor'; 'virginica'})); assert_equal (Mdl.NumObservations, 100); assert_equal (class (Mdl.ClassNames), 'categorical'); ***** test load fisheriris Mdl = fitctree (meas(51:150,:), categorical (species(51:150))); assert_equal (categories (Mdl.ClassNames), {'versicolor'; 'virginica'}); assert_equal (categories (predict (Mdl, meas(51,:))), ... {'versicolor'; 'virginica'}); ***** error ClassificationTree () ***** error ClassificationTree (ones (4, 2)) ***** error ClassificationTree (ones (4, 2), ones (4, 1), 'K') ***** error ClassificationTree ('a', ones (4, 1)) ***** error ClassificationTree (ones (4, 2), ones (3, 1)) ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'PredictorNames', 'a') ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'PredictorNames', {'a'}) ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'ResponseName', 5) ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'ClassNames', {1}) ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'ClassNames', 5) ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'Prior', {1}) ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'Prior', 'bogus') ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'Cost', ones (2, 3)) ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'Weights', 'a') ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'Weights', ones (2, 2)) ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'Weights', [1, 2, 3]) ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'Weights', -ones (4, 1)) ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'MaxNumSplits', -1) ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'MinLeafSize', 0) ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'MinParentSize', 0) ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'MergeLeaves', 'x') ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'Prune', 'x') ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'PruneCriterion', 'x') ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'PruneCriterion', 'impurity') ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'SplitCriterion', 'x') ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'SplitCriterion', 'twoing') ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'Surrogate', 'on') ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'KFold', 5) ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'Bogus', 1) ***** error predict (ClassificationTree (ones (4, 2), [1; 1; 2; 2])) ***** error predict (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), []) ***** error predict (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), 'a') ***** error predict (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), ones (2, 3)) ***** error margin (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), ones (4, 2)) ***** error margin (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), ones (4, 2), ... [1; 1; 2; 9]) ***** error margin (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), ones (3, 2), ... [1; 1; 2; 2]) ***** error edge (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), ones (4, 2)) ***** error ... edge (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), ones (4, 2), ... [1; 1; 2; 2], 'Weights') ***** error ... edge (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), ones (4, 2), ... [1; 1; 2; 2], 'Bogus', 1) ***** error loss (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), ones (4, 2)) ***** error loss (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), ones (4, 2), ... [1; 1; 2; 2], 'LossFun') ***** error loss (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), ones (4, 2), ... [1; 1; 2; 2], 'LossFun', 'x') ***** error loss (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), ones (4, 2), ... [1; 1; 2; 2], 'Weights', 'a') ***** error loss (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), ones (4, 2), ... [1; 1; 2; 2], 'Weights', ones (2, 2)) ***** error loss (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), ones (4, 2), ... [1; 1; 2; 2], 'Bogus', 1) ***** error prune (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), 'Level') ***** error prune (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), 'Level', 1, ... 'Alpha', 1) ***** error prune (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), 'Level', -1) ***** error prune (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), 'Alpha', -1) ***** error prune (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), 'Nodes', 99) ***** error prune (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), 'Bogus', 1) ***** error nodeVariableRange (ClassificationTree (ones (4, 2), [1; 1; 2; 2])) ***** error nodeVariableRange (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), 99) ***** error savemodel (ClassificationTree (ones (4, 2), [1; 1; 2; 2])) ***** error savemodel (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), 5) ***** error cvloss (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), 'SubTrees') ***** error load fisheriris cvloss (ClassificationTree (meas, species), 'SubTrees', -1) ***** error load fisheriris cvloss (ClassificationTree (meas, species), 'SubTrees', [2, 1]) ***** error load fisheriris cvloss (ClassificationTree (meas, species), 'SubTrees', 'most') ***** error load fisheriris cvloss (ClassificationTree (meas, species), 'SubTrees', 99) ***** error load fisheriris cvloss (ClassificationTree (meas, species), 'TreeSize', 'x') ***** error load fisheriris cvloss (ClassificationTree (meas, species), 'KFold', 1) ***** error load fisheriris cvloss (ClassificationTree (meas, species), 'Bogus', 1) ***** error load fisheriris cvloss (ClassificationTree (meas, species, 'Prune', 'off', ... 'MergeLeaves', 'off')) ***** error crossval (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), 'KFold') ***** error crossval (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), 'KFold', 2, ... 'Holdout', 0.3) ***** error crossval (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), 'KFold', 1) ***** error crossval (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), 'Holdout', 2) ***** error crossval (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), 'Leaveout', 'x') ***** error crossval (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), 'CVPartition', 5) ***** error crossval (ClassificationTree (ones (4, 2), [1; 1; 2; 2]), 'Bogus', 1) ***** error Mdl = ClassificationTree (ones (4, 2), [1; 1; 2; 2]); Mdl.Prior = [0.2, 0.3, 0.5]; ***** error Mdl = ClassificationTree (ones (4, 2), [1; 1; 2; 2]); Mdl.Prior = 'bogus'; ***** error Mdl = ClassificationTree (ones (4, 2), [1; 1; 2; 2]); Mdl.Prior = [0, 0]; ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'NumVariablesToSample', 0) ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'NumVariablesToSample', 1.5) ***** error ClassificationTree (ones (4, 2), [1; 1; 2; 2], ... 'NumVariablesToSample', 'some') ***** shared Xb, yb, X3, y3 k = (0:79)'; c = mod (k, 4) + 1; j = floor (k / 4); Xb = [c, mod(k * 7, 10)]; yb = (c == 1) | (c == 2 & mod (j, 4) != 0) | (c == 3 & mod (j, 4) == 0); k = (0:119)'; c = mod (k, 6) + 1; base = [1, 2, 3, 1, 2, 3]; alt = [1, 2, 3, 2, 3, 1]; y3 = base(c)'; odd = mod (floor (k / 6), 2) == 1 & c >= 4; y3(odd) = alt(c(odd)); X3 = [c, mod(k * 5, 7)]; ***** test # MATLAB parity: a categorical predictor splits into sets of levels Mdl = ClassificationTree (Xb, yb, 'CategoricalPredictors', 1); assert_equal (Mdl.NumNodes, 3); assert_equal (Mdl.CategoricalPredictors, 1); assert_equal (Mdl.CutType, {'categorical'; ''; ''}); assert_equal (Mdl.CutCategories(1,:), {[1, 2], [3, 4]}); assert_equal (Mdl.CategoricalSplit, {[1, 2], [3, 4]}); assert_equal (isnan (Mdl.CutPoint(1)), true); assert_equal (predictorImportance (Mdl), [0.28125, 0], 1e-12); ***** test # a categorical predictor may be named in any of the three containers pn = {'grp', 'val'}; M1 = ClassificationTree (Xb, yb, 'PredictorNames', pn, ... 'CategoricalPredictors', {'grp'}); M2 = ClassificationTree (Xb, yb, 'PredictorNames', pn, ... 'CategoricalPredictors', string ({'grp'})); M3 = ClassificationTree (Xb, yb, 'PredictorNames', pn, ... 'CategoricalPredictors', 'grp'); assert_equal (M1.CategoricalPredictors, 1); assert_equal (M2.CategoricalPredictors, 1); assert_equal (M3.CategoricalPredictors, 1); ***** test # a character matrix names one predictor per row, its padding stripped M = ClassificationTree (Xb, yb, 'PredictorNames', {'g', 'val'}, ... 'CategoricalPredictors', ['g '; 'val']); assert_equal (M.CategoricalPredictors, [1, 2]); ***** test # 'all' is every predictor even where a predictor is named 'all' M = ClassificationTree (Xb, yb, 'PredictorNames', {'all', 'val'}, ... 'CategoricalPredictors', 'all'); assert_equal (M.CategoricalPredictors, [1, 2]); ***** test # a repeated name gives one index, where MATLAB repeats it M = ClassificationTree (Xb, yb, 'PredictorNames', {'grp', 'val'}, ... 'CategoricalPredictors', {'grp', 'grp'}); assert_equal (M.CategoricalPredictors, 1); ***** error ... ClassificationTree (Xb, yb, 'PredictorNames', {'grp', 'val'}, ... 'CategoricalPredictors', {'GRP'}) ***** error ... ClassificationTree (Xb, yb, 'PredictorNames', {'grp', 'val'}, ... 'CategoricalPredictors', {'grp', 2}) ***** test # MATLAB parity: a level a node did not see stops the row there Mdl = ClassificationTree (Xb, yb, 'CategoricalPredictors', 1); [~, s, nd] = predict (Mdl, [1, 0; 3, 0; 5, 0; NaN, 0; 2.5, 0]); assert_equal (nd', [2, 3, 1, 1, 1]); assert_equal (s(3,:), [0.5, 0.5], 1e-12); assert_equal (s(1,:), [0.125, 0.875], 1e-12); ***** test # MATLAB parity: three classes search every partition of the levels Mdl = ClassificationTree (X3, y3, 'CategoricalPredictors', 1); assert_equal (Mdl.NumNodes, 25); assert_equal (Mdl.CutCategories(1,:), {[1, 4, 6], [2, 3, 5]}); assert_equal (size (Mdl.CategoricalSplit), [5, 2]); assert_equal (nodeVariableRange (Mdl, 2), struct ('x1', [1, 4, 6])); assert_equal (Mdl.ModelParameters.MaxCat, 10); assert_equal (Mdl.ModelParameters.AlgCat, 'auto'); ***** test # MATLAB parity: view prints a categorical cut as sets of levels Mdl = ClassificationTree (X3, y3, 'CategoricalPredictors', 1); txt = evalc ('view (Mdl)'); assert_equal (! isempty (strfind (txt, [' 1 if x1 in {1 4 6} then node', ... ' 2 elseif x1 in {2 3 5} then node 3 else 1'])), true); ***** test # MATLAB parity: the categorical options are recorded as given Mdl = ClassificationTree (X3, y3, 'CategoricalPredictors', 1, ... 'MaxNumCategories', 4, ... 'AlgorithmForCategorical', 'PCA'); assert_equal (Mdl.ModelParameters.MaxCat, 4); assert_equal (Mdl.ModelParameters.AlgCat, 'PCA'); ***** test # MATLAB parity: pruning keeps the categorical splits that remain Mdl = ClassificationTree (X3, y3, 'CategoricalPredictors', 1); P = prune (Mdl, 'Level', 1); assert_equal (P.NumNodes, 13); assert_equal (rows (P.CategoricalSplit), 3); ***** test # the level sets travel with a saved and a compact tree Mdl = ClassificationTree (X3, y3, 'CategoricalPredictors', 1); fname = [tempname(), '.mdl']; savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.CutCategories, Mdl.CutCategories); assert_equal (predict (compact (Mdl), X3), predict (Mdl, X3)); ***** test # cross-validation grows every fold with the categorical predictors Mdl = ClassificationTree (X3, y3, 'CategoricalPredictors', 1); CV = crossval (Mdl, 'KFold', 3); assert_equal (CV.Trained{1}.CategoricalPredictors, 1); ***** error ... ClassificationTree (Xb, yb, 'CategoricalPredictors', 3) ***** error ... ClassificationTree (Xb, yb, 'MaxNumCategories', -1) ***** error ... ClassificationTree (Xb, yb, 'AlgorithmForCategorical', 'bogus') ***** shared ctT, ctM load fisheriris ctT = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); ctT.Species = categorical (species); ctT.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ctM = fitctree (ctT, 'Species'); ***** test # the class may be built from a table as the fitter builds it Mdl = ClassificationTree (ctT, 'Species'); assert_equal (Mdl.PredictorNames, ctM.PredictorNames); assert_equal (Mdl.CategoricalPredictors, ctM.CategoricalPredictors); ***** test # predict takes a table and answers in the type the labels came in label = predict (ctM, ctT); assert_equal (class (label), 'categorical'); assert_equal (numel (label), 150); ***** test a = predict (ctM, ctT); b = predict (ctM, ctT(:, [6, 5, 4, 3, 2, 1])); assert_equal (a, b); T = ctT; T.Extra = (1:150)'; assert_equal (predict (ctM, T), a); ***** test # a level carries at prediction the code it carried at fitting T = ctT(1:60,:); T.Wide = categorical (repmat ({'wide'}, 60, 1), {'narrow', 'wide'}); assert_equal (numel (predict (ctM, T)), 60); ***** test # a matrix is still taken, as the model was fitted from one before load fisheriris Mdl = fitctree (meas, species); assert_equal (numel (predict (Mdl, meas)), 150); ***** test # the levels travel with the model when it is made compact CMdl = compact (ctM); assert_equal (CMdl.PredictorLevels, ctM.PredictorLevels); assert_equal (predict (CMdl, ctT), predict (ctM, ctT)); ***** error ... predict (ctM, ctT(:, [1, 3, 4, 5, 6])) ***** error ... predict (ctM, setfield (ctT, 'SL', categorical (ctT.SL > 5.8))) ***** shared lctT, lctM load fisheriris lctT = table (meas(:,1), meas(:,2), 'VariableNames', {'SL', 'SW'}); lctT.Species = categorical (species); lctM = fitctree (lctT, 'Species'); ***** test # the response is named, left out, or given beside the table a = loss (lctM, [lctT.SL, lctT.SW], lctT.Species); assert_equal (loss (lctM, lctT(:,1:2), lctT.Species), a); assert_equal (loss (lctM, lctT, 'Species'), a); assert_equal (loss (lctM, lctT), a); ***** test # an even number of arguments after the table is all name-value a = loss (lctM, lctT, 'LossFun', 'classiferror'); assert_equal (loss (lctM, lctT, 'Species', 'LossFun', 'classiferror'), a); ***** test # a table is read by name, so the order of its columns does not matter assert_equal (loss (lctM, lctT(:, [3, 2, 1])), loss (lctM, lctT)); ***** error ... loss (lctM, lctT, 'NoSuch') ***** error ... loss (lctM, lctT(:,1:2)) ***** test # the response is named, left out, or given beside the table a = edge (lctM, [lctT.SL, lctT.SW], lctT.Species); assert_equal (edge (lctM, lctT(:,1:2), lctT.Species), a); assert_equal (edge (lctM, lctT, 'Species'), a); assert_equal (edge (lctM, lctT), a); ***** test # an even number of arguments after the table is all name-value w = ones (150, 1); a = edge (lctM, lctT, 'Weights', w); assert_equal (edge (lctM, lctT, 'Species', 'Weights', w), a); ***** test # a table is read by name, so the order of its columns does not matter assert_equal (edge (lctM, lctT(:, [3, 2, 1])), edge (lctM, lctT)); ***** error ... edge (lctM, lctT, 'NoSuch') ***** error ... edge (lctM, lctT(:,1:2)) ***** test # the response is named, left out, or given beside the table a = margin (lctM, [lctT.SL, lctT.SW], lctT.Species); assert_equal (margin (lctM, lctT(:,1:2), lctT.Species), a); assert_equal (margin (lctM, lctT, 'Species'), a); assert_equal (margin (lctM, lctT), a); ***** test # a table is read by name, so the order of its columns does not matter assert_equal (margin (lctM, lctT(:, [3, 2, 1])), margin (lctM, lctT)); ***** error ... margin (lctM, lctT, 'NoSuch') ***** error ... margin (lctM, lctT(:,1:2)) ***** error ... ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'Weights', ... int8 ([1; 1; 1; 1])) ***** error ... ClassificationTree (ones (4, 2), [1; 1; 2; 2], 'Weights', true (4, 1)) ***** test ## Single weights are stored single, summing to one load fisheriris w = 1 + (1:150)' / 7; Mdl = ClassificationTree (meas, species, 'Weights', single (w)); assert_equal (class (Mdl.W), 'single'); assert_equal (sum (double (Mdl.W)), 1, 1e-6); ***** test ## Single weights compute as double load fisheriris w = 1 + (1:150)' / 7; A = ClassificationTree (meas, species, 'Weights', single (w)); B = ClassificationTree (meas, species, 'Weights', double (single (w))); assert_equal (nthargout (2, @predict, A, meas), nthargout (2, @predict, ... B, meas)); 173 tests, 173 passed, 0 known failure, 0 skipped [inst/Machine_Learning/CompactClassificationNeuralNetwork.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/CompactClassificationNeuralNetwork.m ***** demo ## Train a neural network classifier and take its compact version, which ## drops the training data but predicts identically. load fisheriris X = meas; Y = species; Mdl = fitcnet (X, Y, 'IterationLimit', 100) CMdl = compact (Mdl) ## The compact model keeps no training data isprop (Mdl, 'X') isprop (CMdl, 'X') ## and predicts the same labels isequal (predict (Mdl, X), predict (CMdl, X)) ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Cc = compact (fitcnet (Xch, Ych)); rand ("state", 1); randn ("state", 1); Cs = compact (fitcnet (Xch, Ycell)); assert_equal (cellstr (Cc.ClassNames), Cs.ClassNames); assert_equal (cellstr (predict (Cc, Xch)), predict (Cs, Xch)); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Cc = compact (fitcnet (Xch, Ych)); rand ("state", 1); randn ("state", 1); Cs = compact (fitcnet (Xch, Ycell)); assert_equal (loss (Cc, Xch, Ych), loss (Cs, Xch, Ycell), 1e-12); ***** test # A row missing a predictor takes the class of largest prior X = [(1:10)', mod((1:10)', 3)]; y = [1; 1; 1; 1; 1; 1; 2; 2; 2; 2]; Mdl = compact (ClassificationNeuralNetwork (X, y)); [label, score] = predict (Mdl, [NaN, 1]); assert_equal (label, 1); assert_equal (score, [NaN, NaN]); Mdl = compact (ClassificationNeuralNetwork (X, y, 'Prior', [0.3, 0.7])); assert_equal (predict (Mdl, [NaN, 1]), 2); ***** error ... CompactClassificationNeuralNetwork (1) ***** shared x, y, CMdl load fisheriris x = meas; y = grp2idx (species); Mdl = fitcnet (x, y, 'IterationLimit', 100); CMdl = compact (Mdl); ***** error ... predict (CMdl) ***** error ... predict (CMdl, []) ***** error ... predict (CMdl, 1) ***** error ... CMdl.ScoreTransform = 'a'; ***** test Mdl = fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], ... 'LayerSizes', [3, 2], 'IterationLimit', 20); CMdl = compact (Mdl); assert_equal (CMdl.LayerWeights, Mdl.LayerWeights); assert_equal (CMdl.LayerBiases, Mdl.LayerBiases); assert_equal (CMdl.Cost, Mdl.Cost); assert_equal (CMdl.Prior, Mdl.Prior); assert_equal (CMdl.CategoricalPredictors, Mdl.CategoricalPredictors); assert_equal (CMdl.ExpandedPredictorNames, Mdl.ExpandedPredictorNames); ***** test load fisheriris Mdl = fitcnet (meas, species, 'IterationLimit', 20); CMdl = compact (Mdl); assert_equal (margin (CMdl, meas, species), margin (Mdl, meas, species)); assert_equal (edge (CMdl, meas, species), edge (Mdl, meas, species)); assert_equal (loss (CMdl, meas, species), loss (Mdl, meas, species)); ***** test load fisheriris Mdl = fitcnet (meas, species, 'IterationLimit', 20); CMdl = compact (Mdl); names = {'binodeviance', 'classifcost', 'classiferror', 'crossentropy', ... 'exponential', 'hinge', 'logit', 'mincost', 'quadratic'}; for k = 1:numel (names) assert_equal (loss (CMdl, meas, species, 'LossFun', names{k}), ... loss (Mdl, meas, species, 'LossFun', names{k})); endfor ***** test load fisheriris CMdl = compact (fitcnet (meas, species, 'IterationLimit', 20)); ## The weights are normalized within each class to that class's prior, ## not divided by their total. A weight constant within a class therefore ## leaves the edge exactly where the unweighted one is. w = [ones(50, 1); 2 * ones(50, 1); 3 * ones(50, 1)]; m = margin (CMdl, meas, species); assert_equal (edge (CMdl, meas, species, 'Weights', w), ... edge (CMdl, meas, species), 1e-12); ***** error ... margin (CMdl) ***** error ... margin (CMdl, x) ***** error ... margin (CMdl, [], y) ***** error ... margin (CMdl, 1, y) ***** error ... margin (CMdl, x, []) ***** error ... margin (CMdl, x, y(1:10)) ***** error ... edge (CMdl, x) ***** error ... edge (CMdl, x, y, 'Weights') ***** error ... edge (CMdl, x, y, 'LossFun', 'hinge') ***** error ... edge (CMdl, x, y, 'Weights', 'a') ***** error ... edge (CMdl, x, y, 'Weights', ones (2, 2)) ***** error ... edge (CMdl, x, y, 'Weights', [1, 2, 3]) ***** error ... loss (CMdl, x) ***** error ... loss (CMdl, x, y, 'LossFun') ***** error ... loss (CMdl, x, y, 'LossFun', 1) ***** error ... loss (CMdl, x, y, 'LossFun', 'nonsense') ***** error ... loss (CMdl, x, y, 'Bogus', 1) ***** test Mdl = fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], ... 'LayerSizes', [3, 2], 'IterationLimit', 20); CMdl = compact (Mdl); fname = tempname (); savemodel (CMdl, fname); CMdl2 = loadmodel (fname); delete (fname); assert_equal (CMdl2.LayerWeights, CMdl.LayerWeights); assert_equal (CMdl2.LayerBiases, CMdl.LayerBiases); assert_equal (CMdl2.LayerSizes, CMdl.LayerSizes); assert_equal (CMdl2.ClassNames, CMdl.ClassNames); ***** test load fisheriris Mdl = fitcnet (meas, species, 'IterationLimit', 20); fname = tempname (); savemodel (compact (Mdl), fname); CMdl2 = loadmodel (fname); delete (fname); [label, score] = predict (Mdl, meas); [label2, score2] = predict (CMdl2, meas); assert_equal (label2, label); assert_equal (score2, score); ***** test Mdl = fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2], 'IterationLimit', 20); Mdl.ScoreTransform = 'symmetric'; fname = tempname (); savemodel (compact (Mdl), fname); CMdl2 = loadmodel (fname); delete (fname); assert_equal (CMdl2.ScoreTransform, 'symmetric'); [~, s1] = predict (CMdl2, [1, 2; 4, 5]); [~, s2] = predict (compact (Mdl), [1, 2; 4, 5]); assert_equal (s1, s2); ***** error ... savemodel (CompactClassificationNeuralNetwork ()) ***** error ... savemodel (CompactClassificationNeuralNetwork (), 1) ***** error ... savemodel (CompactClassificationNeuralNetwork (), ['ab'; 'cd']) ***** test load fisheriris Mdl = compact (fitcnet (meas, species, 'IterationLimit', 20)); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2), 'CompactClassificationNeuralNetwork'); assert_equal (M2.PredictorNames, Mdl.PredictorNames); assert_equal (class (M2.ScoreTransform), class (Mdl.ScoreTransform)); assert_equal (predict (M2, meas(1:5,:)), predict (Mdl, meas(1:5,:))); ***** error ... CMdl = compact (fitcnet ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])); CMdl.Cost = 1:4; ***** test load fisheriris Mdl = compact (fitcnet (meas, species)); S = struct ('ClassNames', {{'virginica'; 'setosa'; 'versicolor'}}, ... 'ClassificationCosts', [0, 1, 2; 3, 0, 4; 5, 6, 0]); Mdl.Cost = S; assert_equal (Mdl.Cost, [0, 4, 3; 6, 0, 5; 1, 2, 0]); ***** error ... load fisheriris Mdl = compact (fitcnet (meas, species)); Mdl.Cost = ones (3); ***** test load fisheriris Mdl = compact (fitcnet (meas, species)); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); T = {'identity', @(x) x; 'doublelogit', @(x) 1 ./ (1 + exp (-2 * x)); ... 'invlogit', @(x) log (x ./ (1 - x)); ... 'logit', @(x) 1 ./ (1 + exp (-x)); ... 'sign', @(x) sign (x); 'symmetric', @(x) 2 * x - 1; ... 'symmetriclogit', @(x) 2 ./ (1 + exp (-x)) - 1}; for i = 1:rows (T) Mdl.ScoreTransform = T{i,1}; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, T{i,2}(raw), 1e-12); assert_equal (l, label); endfor ## ismax marks the largest score of each observation, ties to the first. [~, k] = max (raw, [], 2); e = zeros (size (raw)); e(sub2ind (size (raw), (1:rows (raw))', k)) = 1; Mdl.ScoreTransform = 'ismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, e); Mdl.ScoreTransform = 'symmetricismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, 2 * e - 1); ***** test load fisheriris Mdl = compact (fitcnet (meas, species)); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); Mdl.ScoreTransform = @(x) x .^ 2; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, raw .^ 2, 1e-12); assert_equal (l, label); ***** shared Xc, Dc, yr, yc, Xq, Dq k = (0:119)'; c1 = mod (k, 3) + 1; x2 = sin (k); c3 = 10 * (mod (floor (k / 2), 2) + 1); Xc = [c1, x2, c3]; Dc = [c1 == 1, c1 == 2, c1 == 3, x2, c3 == 10, c3 == 20]; yr = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 20) + 0.1 * cos (k); yc = yr > 1; Xq = [1, 0, 10; 2, 0.5, 20]; Dq = [1, 0, 0, 0, 1, 0; 0, 1, 0, 0.5, 0, 1]; ***** test # a compact model keeps the coding Full = fitcnet (Xc, yc, 'CategoricalPredictors', [1, 3], 'LayerSizes', 4); Mdl = compact (Full); [~, s] = predict (Mdl, [Xq; 4, 0, 10]); [~, sf] = predict (Full, [Xq; 4, 0, 10]); assert_equal (s, sf); assert_equal (isnan (s(3,1)), true); fname = [tempname(), '.mdl']; savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); [~, s2] = predict (M2, Xq); assert_equal (s2, s(1:2,:)); ***** test # the levels a predictor was coded through travel with the model load fisheriris T = table (meas(:,1), meas(:,2), 'VariableNames', {'SL', 'SW'}); T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); T.Species = categorical (species); CMdl = compact (fitcnet (T, 'Species')); assert_equal (numel (CMdl.PredictorLevels), 3); assert_equal (CMdl.PredictorLevels{3}, {'narrow', 'wide'}); ***** test # predict takes a table, read by name and not by position load fisheriris T = table (meas(:,1), meas(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = categorical (species); CMdl = compact (fitcnet (T, 'Species')); a = predict (CMdl, T); assert_equal (class (a), 'categorical'); assert_equal (predict (CMdl, T(:, [3, 2, 1])), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcnet (T, 'Species')); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcnet (T, 'Species')); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcnet (T, 'Species')); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** error ... loss (compact (fitcnet ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2])), ... [1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', int8 ([1; 1; 1; 1])) 48 tests, 48 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitcknn.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitcknn.m ***** demo ## Train a k-nearest neighbor classifier for k = 10 ## and plot the decision boundaries. load fisheriris idx = ! strcmp (species, 'setosa'); X = meas(idx,3:4); Y = cast (strcmpi (species(idx), 'virginica'), 'double'); obj = fitcknn (X, Y, 'Standardize', 1, 'NumNeighbors', 10, 'NSMethod', 'exhaustive') x1 = [min(X(:,1)):0.03:max(X(:,1))]; x2 = [min(X(:,2)):0.02:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; pred = predict (obj, XGrid); gidx = logical (pred); figure scatter (XGrid(gidx,1), XGrid(gidx,2), 'markerfacecolor', 'magenta'); hold on scatter (XGrid(! gidx,1), XGrid(! gidx,2), 'markerfacecolor', 'red'); plot (X(Y == 0, 1), X(Y == 0, 2), 'ko', X(Y == 1, 1), X(Y == 1, 2), 'kx'); xlabel ('Petal length (cm)'); ylabel ('Petal width (cm)'); title ('5-Nearest Neighbor Classifier Decision Boundary'); legend ({'Versicolor Region', 'Virginica Region', ... 'Sampled Versicolor', 'Sampled Virginica'}, ... 'location', 'northwest') axis tight hold off ***** demo ## Fit from a table, and predict on one load fisheriris T = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = categorical (species); ## The response is named by its column, and everything else is a predictor Mdl = fitcknn (T, 'Species'); Mdl.PredictorNames Mdl.ResponseName ## predict reads a table by the names the model was fitted on, so the ## columns may come in any order label = predict (Mdl, T(1:5, [5, 4, 3, 2, 1])); label' ## This learner takes every predictor as holding levels or none of them, ## so a table whose columns all hold levels is measured by the Hamming ## distance instead C = table (categorical (meas(:,1) > 5.8, [false true], {'short', 'long'}), ... categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}), ... 'VariableNames', {'Long', 'Wide'}); C.Species = categorical (species); CMdl = fitcknn (C, 'Species'); CMdl.Distance ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = fitcknn (x, y); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.X, a.Y, a.NumNeighbors}, {x, y, 1}) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = fitcknn (x, y, 'NSMethod', 'exhaustive'); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.X, a.Y, a.NumNeighbors}, {x, y, 1}) assert_equal ({a.NSMethod, a.Distance}, {'exhaustive', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; k = 10; a = fitcknn (x, y, 'NumNeighbors' ,k); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.X, a.Y, a.NumNeighbors}, {x, y, 4}) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = ones (4, 11); y = ['a'; 'a'; 'b'; 'b']; k = 10; a = fitcknn (x, y, 'NumNeighbors' ,k); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.X, a.Y, a.NumNeighbors}, {x, y, 4}) assert_equal ({a.NSMethod, a.Distance}, {'exhaustive', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; k = 10; a = fitcknn (x, y, 'NumNeighbors' ,k, 'NSMethod', 'exhaustive'); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.X, a.Y, a.NumNeighbors}, {x, y, 4}) assert_equal ({a.NSMethod, a.Distance}, {'exhaustive', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; k = 10; a = fitcknn (x, y, 'NumNeighbors' ,k, 'Distance', 'hamming'); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.X, a.Y, a.NumNeighbors}, {x, y, 4}) assert_equal ({a.NSMethod, a.Distance}, {'exhaustive', 'hamming'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; weights = ones (4,1); a = fitcknn (x, y, 'Standardize', 1); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.X, a.Y, a.NumNeighbors}, {x, y, 1}) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) assert_equal ({a.Sigma}, {std(x, [], 1)}) assert_equal ({a.Mu}, {[3.75, 4.25, 4.75]}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; weights = ones (4,1); a = fitcknn (x, y, 'Standardize', false); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.X, a.Y, a.NumNeighbors}, {x, y, 1}) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) assert_equal ({a.Sigma}, {[]}) assert_equal ({a.Mu}, {[]}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; s = ones (1, 3); a = fitcknn (x, y, 'Scale' , s, 'Distance', 'seuclidean'); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.DistParameter}, {s}) assert_equal ({a.NSMethod, a.Distance}, {'exhaustive', 'seuclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = fitcknn (x, y, 'Exponent' , 5, 'Distance', 'minkowski'); assert_equal (class (a), "ClassificationKNN"); assert_equal (a.DistParameter, 5) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'minkowski'}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = fitcknn (x, y, 'Exponent' , 5, 'Distance', 'minkowski', ... 'NSMethod', 'exhaustive'); assert_equal (class (a), "ClassificationKNN"); assert_equal (a.DistParameter, 5) assert_equal ({a.NSMethod, a.Distance}, {'exhaustive', 'minkowski'}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = fitcknn (x, y, 'BucketSize' , 20, 'distance', 'mahalanobis'); assert_equal (class (a), "ClassificationKNN"); assert_equal ({a.NSMethod, a.Distance}, {'exhaustive', 'mahalanobis'}) assert_equal ({a.BucketSize}, {20}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = fitcknn (x, y, 'IncludeTies', true); assert_equal (class (a), "ClassificationKNN"); assert_equal (a.IncludeTies, true); assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = fitcknn (x, y); assert_equal (class (a), "ClassificationKNN"); assert_equal (a.IncludeTies, false); assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; a = fitcknn (x, y); assert_equal (class (a), "ClassificationKNN") assert_equal (a.Prior, [0.5, 0.5]) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; prior = [0.5, 0.5]; a = fitcknn (x, y, 'Prior', 'empirical'); assert_equal (class (a), "ClassificationKNN") assert_equal (a.Prior, prior) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'a'; 'b']; prior = [0.75, 0.25]; a = fitcknn (x, y, 'Prior', 'empirical'); assert_equal (class (a), "ClassificationKNN") assert_equal (a.Prior, prior) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'a'; 'b']; prior = [0.5, 0.5]; a = fitcknn (x, y, 'Prior', 'uniform'); assert_equal (class (a), "ClassificationKNN") assert_equal (a.Prior, prior) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; cost = [0, 1; 1, 0]; a = fitcknn (x, y, 'Cost', cost); assert_equal (class (a), "ClassificationKNN") assert_equal (a.Cost, [0, 1; 1, 0]) assert_equal ({a.NSMethod, a.Distance}, {'kdtree', 'euclidean'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; cost = [0, 1; 1, 0]; a = fitcknn (x, y, 'Cost', cost, 'Distance', 'hamming' ); assert_equal (class (a), "ClassificationKNN") assert_equal (a.Cost, [0, 1; 1, 0]) assert_equal ({a.NSMethod, a.Distance}, {'exhaustive', 'hamming'}) assert_equal ({a.BucketSize}, {50}) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = ['a'; 'a'; 'b'; 'b']; status = warning; warning ('off'); rand ('seed', 23); a = fitcknn (x, y, 'NSMethod', 'exhaustive', 'CrossVal', 'on'); warning (status); assert_equal (class (a), "ClassificationPartitionedModel"); assert_equal ({a.X, a.Y, a.Trained{1}.NumNeighbors}, {x, y, 1}) assert_equal (a.ModelParameters.NSMethod, "exhaustive") assert_equal (a.ModelParameters.Distance, "euclidean") assert_equal ({a.Trained{1}.BucketSize}, {50}) ***** error fitcknn () ***** error fitcknn (ones (4,1)) ***** error fitcknn (ones (4,2), ones (4, 1), 'K') ***** error fitcknn (ones (4,2), ones (3, 1)) ***** error fitcknn (ones (4,2), ones (3, 1), 'K', 2) ***** error fitcknn (ones (4,2), ones (4, 1), 'CrossVal', 2) ***** error fitcknn (ones (4,2), ones (4, 1), 'CrossVal', 'a') ***** error ... fitcknn (ones (4,2), ones (4, 1), 'KFold', 10, 'Holdout', 0.3) ***** test # 'Leaveout' leaves one observation out of each fold load fisheriris CVMdl = fitcknn (meas, species, 'Leaveout', 'on'); assert_equal (CVMdl.KFold, 150); ***** test # MATLAB parity: classes given as text are sorted load fisheriris k = [101:150, 1:50, 51:100]; Mdl = fitcknn (meas(k,:), species(k)); assert_equal (Mdl.ClassNames, {'setosa'; 'versicolor'; 'virginica'}); ***** test # MATLAB parity: a given ClassNames order is kept load fisheriris Mdl = fitcknn (meas(1:150,:), species(1:150), ... 'ClassNames', {'virginica'; 'setosa'; 'versicolor'}); assert_equal (Mdl.ClassNames, {'virginica'; 'setosa'; 'versicolor'}); ***** error ... load fisheriris fitcknn (meas, species, 'ClassNames', [3, 1, 2]) ***** shared fknT load fisheriris fknT = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); fknT.Species = categorical (species); ***** test # the response is named by a column and the rest are predictors Mdl = fitcknn (fknT, 'Species'); assert_equal (Mdl.PredictorNames, {'SL', 'SW', 'PL', 'PW'}); assert_equal (Mdl.ResponseName, 'Species'); ***** test # a model formula names the response and the predictors together Mdl = fitcknn (fknT, 'Species ~ PW + SL'); assert_equal (Mdl.PredictorNames, {'PW', 'SL'}); ***** test # predict takes a table, matched by name and not by position Mdl = fitcknn (fknT, 'Species'); a = predict (Mdl, fknT); assert_equal (class (a), 'categorical'); assert_equal (predict (Mdl, fknT(:, [5, 4, 3, 2, 1])), a); ***** test load fisheriris C = table (categorical (meas(:,1) > 5.8, [false true], ... {'short', 'long'}), ... categorical (meas(:,2) > 3, [false true], ... {'narrow', 'wide'}), ... 'VariableNames', {'Long', 'Wide'}); C.Species = categorical (species); Mdl = fitcknn (C, 'Species'); assert_equal (Mdl.CategoricalPredictors, [1, 2]); assert_equal (Mdl.Distance, 'hamming'); ***** error load fisheriris M = table (meas(:,1), 'VariableNames', {'SL'}); M.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); M.Species = categorical (species); fitcknn (M, 'Species'); ***** error ... fitcknn (fknT, 'NoSuch') ***** error ... fitcknn (fknT, 'Species ~ SL*PW') ***** error ... predict (fitcknn (fknT, 'Species'), fknT(:, [1, 3, 4, 5])) 41 tests, 41 passed, 0 known failure, 0 skipped [inst/Machine_Learning/RegressionPartitionedKernel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/RegressionPartitionedKernel.m ***** demo ## Cross-validate a Gaussian kernel regression of fuel consumption and ## read the out-of-sample mean squared error. load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedKernel (X(ok,:), MPG(ok), 'KFold', 5) outOfSample = kfoldLoss (CVMdl) ***** shared X, Y load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); X = X(ok,:); Y = MPG(ok); ***** test ## The model reports the surface MATLAB reports CVMdl = RegressionPartitionedKernel (X, Y, 'KFold', 4); assert_equal (class (CVMdl), 'RegressionPartitionedKernel'); assert_equal (CVMdl.CrossValidatedModel, 'Kernel'); assert_equal (CVMdl.KFold, 4); assert_equal (CVMdl.NumObservations, 93); assert_equal (CVMdl.ResponseTransform, 'none'); assert_equal (class (CVMdl.Trained{1}), 'RegressionKernel'); assert_equal (CVMdl.ModelParameters.Method, 'PartitionedKernel'); assert_equal (CVMdl.ModelParameters.LearnerTemplates, 'Kernel'); ***** test ## The properties are the ones MATLAB lists, in its order CVMdl = RegressionPartitionedKernel (X, Y); assert_equal (sort (properties (CVMdl)), ... sort ({'ResponseTransform'; 'CrossValidatedModel'; ... 'NumObservations'; 'Y'; 'W'; 'PredictorNames'; ... 'CategoricalPredictors'; 'ResponseName'; 'Trained'; ... 'KFold'; 'Partition'; 'ModelParameters'})); ***** test ## Each fold resolves its own strength and its own band from its own ## training rows CVMdl = RegressionPartitionedKernel (X, Y, 'KFold', 4); n1 = sum (training (CVMdl.Partition, 1)); assert_equal (CVMdl.Trained{1}.Lambda, 1 / n1, 1e-15); assert_equal (CVMdl.Trained{1}.NumExpansionDimensions, 128); ***** test ## kfoldPredict predicts each observation with the fold that held it out part = cvpartition (93, 'KFold', 4); CVMdl = RegressionPartitionedKernel (X, Y, 'CVPartition', part); yFit = kfoldPredict (CVMdl); byhand = nan (93, 1); for k = 1:4 te = test (part, k); byhand(te) = predict (CVMdl.Trained{k}, X(te,:)); endfor assert_equal (yFit, byhand); ***** test ## Averaging pools the observations rather than the per-fold values CVMdl = RegressionPartitionedKernel (X, Y, 'KFold', 4, ... 'Learner', 'leastsquares'); yFit = kfoldPredict (CVMdl); assert_equal (kfoldLoss (CVMdl), mean ((Y - yFit) .^ 2), 1e-10); assert_equal (size (kfoldLoss (CVMdl, 'Mode', 'individual')), [4, 1]); ***** test ## The epsilon-insensitive loss is offered by a support vector machine ## alone, and judges each residual against the band of its own fold CVMdl = RegressionPartitionedKernel (X, Y, 'KFold', 4); assert_equal (isfinite (kfoldLoss (CVMdl, 'LossFun', ... 'epsiloninsensitive')), true); ***** test ## Every fold draws its own basis, so two folds hold different ## expansions of the same kernel CVMdl = RegressionPartitionedKernel (X, Y, 'KFold', 4); p1 = predict (CVMdl.Trained{1}, X(1:3,:)); p2 = predict (CVMdl.Trained{2}, X(1:3,:)); assert_equal (isequal (p1, p2), false); ***** test ## An observation that no fold held out comes back NaN CVMdl = RegressionPartitionedKernel (X, Y, 'Holdout', 0.3); assert_equal (CVMdl.KFold, 1); assert_equal (sum (isnan (kfoldPredict (CVMdl))), 65); assert_equal (isfinite (kfoldLoss (CVMdl)), true); ***** test ## Standardizing reaches every fold CVMdl = RegressionPartitionedKernel (X, Y, 'KFold', 4, ... 'Standardize', true); assert_equal (isempty (CVMdl.Trained{1}.Mu), false); assert_equal (isempty (CVMdl.Trained{4}.Sigma), false); ***** test ## It can be assigned after the model is built, and reaches kfoldPredict ## without being carried into the folds CVMdl = RegressionPartitionedKernel (X, Y, 'KFold', 4); y0 = kfoldPredict (CVMdl); CVMdl.ResponseTransform = @(y) y + 100; y1 = kfoldPredict (CVMdl); assert_equal (CVMdl.Trained{1}.ResponseTransform, 'none'); assert_equal (y1, y0 + 100, 1e-10); ***** test ## And it reaches kfoldLoss, which is computed from those predictions CVMdl = RegressionPartitionedKernel (X, Y, 'KFold', 4); before = kfoldLoss (CVMdl); CVMdl.ResponseTransform = @(y) y + 100; assert (kfoldLoss (CVMdl) > before); ***** test ## 'none' is the identity, so assigning it transforms nothing CVMdl = RegressionPartitionedKernel (X, Y, 'KFold', 4); y0 = kfoldPredict (CVMdl); CVMdl.ResponseTransform = 'none'; assert_equal (kfoldPredict (CVMdl), y0); ***** error ... CVMdl = RegressionPartitionedKernel (X, Y, 'KFold', 4); CVMdl.ResponseTransform = 'nosuchtransform'; ***** error ... RegressionPartitionedKernel (ones (10, 2)) ***** error ... RegressionPartitionedKernel (ones (10, 2), ones (10, 1), 'KFold') ***** error ... RegressionPartitionedKernel (ones (10, 2), ones (10, 1), 'KFold', 1) ***** error ... RegressionPartitionedKernel (ones (10, 2), ones (10, 1), 'KFold', 2, ... 'Leaveout', 'on') ***** error ... kfoldLoss (RegressionPartitionedKernel (ones (10, 2), ones (10, 1), ... 'KFold', 2), 'LossFun', 'hinge') ***** error ... kfoldLoss (RegressionPartitionedKernel (ones (10, 2), ones (10, 1), ... 'KFold', 2, 'Learner', 'leastsquares'), 'LossFun', ... 'epsiloninsensitive') ***** test load fisheriris CVMdl = fitrkernel (meas(:,2:4), meas(:,1), 'KFold', 3); MP = CVMdl.ModelParameters; assert_equal (MP.Method, 'PartitionedKernel'); assert_equal (MP.LearnerTemplates, 'Kernel'); assert_equal (MP.NLearn, 3); assert_equal (MP.Learner, 'svm'); assert_equal (MP.BlockSize, 4000); ***** test load fisheriris Mdl = fitrkernel (meas(:,2:4), meas(:,1), 'KFold', 3); Mdl.ResponseTransform = 'none'; raw = kfoldPredict (Mdl); T = {'identity', @(x) x; 'exp', @(x) exp (x); 'log', @(x) log (x)}; for i = 1:rows (T) Mdl.ResponseTransform = T{i,1}; yhat = kfoldPredict (Mdl); assert_equal (yhat, T{i,2}(raw), 1e-12); endfor ***** test load fisheriris Mdl = fitrkernel (meas(:,2:4), meas(:,1), 'KFold', 3); Mdl.ResponseTransform = 'none'; raw = kfoldPredict (Mdl); Mdl.ResponseTransform = @(x) x .^ 2; yhat = kfoldPredict (Mdl); assert_equal (yhat, raw .^ 2, 1e-12); ***** test # the predictors and the response may come from a table load fisheriris T = table (meas(:,2), meas(:,3), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'SL'}); CVMdl = RegressionPartitionedKernel (T, 'SL', 'KFold', 3); assert_equal (class (CVMdl), 'RegressionPartitionedKernel'); assert_equal (CVMdl.KFold, 3); 23 tests, 23 passed, 0 known failure, 0 skipped [inst/Machine_Learning/RegressionPartitionedLinear.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/RegressionPartitionedLinear.m ***** demo ## Cross-validate a linear regression of fuel consumption and read the ## out-of-sample mean squared error. load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedLinear (X(ok,:), MPG(ok), 'KFold', 5) outOfSample = kfoldLoss (CVMdl) ***** shared X, Y load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); X = X(ok,:); Y = MPG(ok); ***** test ## The model reports the surface MATLAB reports CVMdl = RegressionPartitionedLinear (X, Y, 'KFold', 4); assert_equal (class (CVMdl), 'RegressionPartitionedLinear'); assert_equal (CVMdl.CrossValidatedModel, 'Linear'); assert_equal (CVMdl.KFold, 4); assert_equal (CVMdl.NumObservations, 93); assert_equal (CVMdl.ResponseTransform, 'none'); assert_equal (CVMdl.ResponseName, 'Y'); assert_equal (CVMdl.PredictorNames, {'x1', 'x2', 'x3', 'x4'}); assert_equal (size (CVMdl.Trained), [4, 1]); assert_equal (class (CVMdl.Trained{1}), 'RegressionLinear'); assert_equal (sum (CVMdl.W), 1, 1e-12); assert_equal (CVMdl.ModelParameters.Method, 'PartitionedLinear'); ***** test ## The properties are the ones MATLAB lists, in its order CVMdl = RegressionPartitionedLinear (X, Y); assert_equal (sort (properties (CVMdl)), ... sort ({'ResponseTransform'; 'CrossValidatedModel'; ... 'NumObservations'; 'Y'; 'W'; 'PredictorNames'; ... 'CategoricalPredictors'; 'ResponseName'; 'Trained'; ... 'KFold'; 'Partition'; 'ModelParameters'})); ***** test ## The default is ten folds CVMdl = RegressionPartitionedLinear (X, Y); assert_equal (CVMdl.KFold, 10); assert_equal (numel (CVMdl.Trained), 10); ***** test ## Each fold resolves its own 'Lambda' and its own 'Epsilon' from its own ## training rows, which is why two folds report different bands CVMdl = RegressionPartitionedLinear (X, Y, 'KFold', 4); n1 = sum (training (CVMdl.Partition, 1)); assert_equal (CVMdl.Trained{1}.Lambda, 1 / n1, 1e-15); assert_equal (isequal (CVMdl.Trained{1}.Epsilon, ... CVMdl.Trained{4}.Epsilon), false); ***** test ## kfoldPredict predicts each observation with the fold that held it out, ## and doing the same partition by hand gives the same numbers part = cvpartition (93, 'KFold', 4); CVMdl = RegressionPartitionedLinear (X, Y, 'CVPartition', part, ... 'Learner', 'leastsquares'); yFit = kfoldPredict (CVMdl); byhand = nan (93, 1); for k = 1:4 tr = training (part, k); te = test (part, k); m = RegressionLinear (X(tr,:), Y(tr), 'Learner', 'leastsquares'); byhand(te) = predict (m, X(te,:)); endfor assert_equal (yFit, byhand, 1e-10); ***** test ## Averaging pools the observations rather than the per-fold values, and ## the two differ once the folds differ in size. The pooled reading is ## the one R2024a returns. part = cvpartition (93, 'KFold', 4); CVMdl = RegressionPartitionedLinear (X, Y, 'CVPartition', part, ... 'Learner', 'leastsquares'); yFit = kfoldPredict (CVMdl); assert_equal (kfoldLoss (CVMdl), mean ((Y - yFit) .^ 2), 1e-10); each = kfoldLoss (CVMdl, 'Mode', 'individual'); assert_equal (size (each), [4, 1]); assert_equal (isequal (kfoldLoss (CVMdl), mean (each)), false); ***** test ## 'Folds' reports over the observations of the folds it names CVMdl = RegressionPartitionedLinear (X, Y, 'KFold', 4, ... 'Learner', 'leastsquares'); yFit = kfoldPredict (CVMdl); idx = test (CVMdl.Partition, 1) | test (CVMdl.Partition, 3); assert_equal (kfoldLoss (CVMdl, 'Folds', [1, 3]), ... mean ((Y(idx) - yFit(idx)) .^ 2), 1e-10); ***** test ## The epsilon-insensitive loss judges each residual against the band of ## the fold that produced it, and is offered by a support vector machine ## alone CVMdl = RegressionPartitionedLinear (X, Y, 'KFold', 4); assert_equal (isfinite (kfoldLoss (CVMdl, 'LossFun', ... 'epsiloninsensitive')), true); assert_equal (kfoldLoss (CVMdl, 'LossFun', 'epsiloninsensitive') ... < kfoldLoss (CVMdl), true); ***** test ## A whole regularization path gives one column per strength CVMdl = RegressionPartitionedLinear (X, Y, 'KFold', 4, ... 'Lambda', [0.001, 0.01, 0.1]); assert_equal (size (kfoldPredict (CVMdl)), [93, 3]); assert_equal (size (kfoldLoss (CVMdl)), [1, 3]); assert_equal (size (kfoldLoss (CVMdl, 'Mode', 'individual')), [4, 3]); ***** test ## An observation that no fold held out comes back NaN rather than ## predicted CVMdl = RegressionPartitionedLinear (X, Y, 'Holdout', 0.3); assert_equal (CVMdl.KFold, 1); yFit = kfoldPredict (CVMdl); assert_equal (sum (isnan (yFit)), 65); assert_equal (isfinite (kfoldLoss (CVMdl)), true); ***** test ## A response transform reaches the assembled predictions once, the fold ## models carrying none part = cvpartition (93, 'KFold', 4); plain = RegressionPartitionedLinear (X, Y, 'CVPartition', part, ... 'Learner', 'leastsquares'); CVexp = RegressionPartitionedLinear (X, Y, 'CVPartition', part, ... 'Learner', 'leastsquares', ... 'ResponseTransform', 'exp'); assert_equal (CVexp.ResponseTransform, 'exp'); assert_equal (CVexp.Trained{1}.ResponseTransform, 'none'); assert_equal (kfoldPredict (CVexp), exp (kfoldPredict (plain)), 1e-10); ***** test ## A row with a missing value is dropped before the partition Xn = X; Xn(3,2) = NaN; CVMdl = RegressionPartitionedLinear (Xn, Y, 'KFold', 4); assert_equal (CVMdl.NumObservations, 92); assert_equal (CVMdl.Partition.NumObservations, 92); ***** test ## It can be assigned after the model is built, and reaches kfoldPredict ## without being carried into the folds CVMdl = RegressionPartitionedLinear (X, Y, 'KFold', 4); y0 = kfoldPredict (CVMdl); CVMdl.ResponseTransform = @(y) y + 100; y1 = kfoldPredict (CVMdl); assert_equal (CVMdl.Trained{1}.ResponseTransform, 'none'); assert_equal (y1, y0 + 100, 1e-10); ***** test ## And it reaches kfoldLoss, which is computed from those predictions CVMdl = RegressionPartitionedLinear (X, Y, 'KFold', 4); before = kfoldLoss (CVMdl); CVMdl.ResponseTransform = @(y) y + 100; assert (kfoldLoss (CVMdl) > before); ***** test ## 'none' is the identity, so assigning it transforms nothing CVMdl = RegressionPartitionedLinear (X, Y, 'KFold', 4); y0 = kfoldPredict (CVMdl); CVMdl.ResponseTransform = 'none'; assert_equal (kfoldPredict (CVMdl), y0); ***** error ... CVMdl = RegressionPartitionedLinear (X, Y, 'KFold', 4); CVMdl.ResponseTransform = 'nosuchtransform'; ***** error ... RegressionPartitionedLinear (ones (10, 2)) ***** error ... RegressionPartitionedLinear (ones (10, 2), ones (10, 1), 'KFold') ***** error ... RegressionPartitionedLinear (ones (10, 2), ones (10, 1), 'KFold', 1) ***** error ... RegressionPartitionedLinear (ones (10, 2), ones (10, 1), 'KFold', 2, ... 'Holdout', 0.2) ***** error ... RegressionPartitionedLinear (ones (10, 2), {1, 2}) ***** error ... kfoldLoss (RegressionPartitionedLinear (ones (10, 2), ones (10, 1), ... 'KFold', 2), 'LossFun', 'hinge') ***** error ... kfoldLoss (RegressionPartitionedLinear (ones (10, 2), ones (10, 1), ... 'KFold', 2, 'Learner', 'leastsquares'), 'LossFun', ... 'epsiloninsensitive') ***** error ... kfoldLoss (RegressionPartitionedLinear (ones (10, 2), ones (10, 1), ... 'KFold', 2), 'Mode', 'each') ***** test load fisheriris Mdl = fitrlinear (meas(:,2:4), meas(:,1), 'KFold', 3); Mdl.ResponseTransform = 'none'; raw = kfoldPredict (Mdl); T = {'identity', @(x) x; 'exp', @(x) exp (x); 'log', @(x) log (x)}; for i = 1:rows (T) Mdl.ResponseTransform = T{i,1}; yhat = kfoldPredict (Mdl); assert_equal (yhat, T{i,2}(raw), 1e-12); endfor ***** test load fisheriris Mdl = fitrlinear (meas(:,2:4), meas(:,1), 'KFold', 3); Mdl.ResponseTransform = 'none'; raw = kfoldPredict (Mdl); Mdl.ResponseTransform = @(x) x .^ 2; yhat = kfoldPredict (Mdl); assert_equal (yhat, raw .^ 2, 1e-12); ***** test # the predictors and the response may come from a table load fisheriris T = table (meas(:,2), meas(:,3), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'SL'}); CVMdl = RegressionPartitionedLinear (T, 'SL', 'KFold', 3); assert_equal (class (CVMdl), 'RegressionPartitionedLinear'); assert_equal (CVMdl.KFold, 3); 27 tests, 27 passed, 0 known failure, 0 skipped [inst/Machine_Learning/CompactClassificationGAM.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/CompactClassificationGAM.m ***** demo ## Create a generalized additive model classifier and its compact version # and compare their size load fisheriris X = meas; Y = species; Mdl = fitcdiscr (X, Y, 'ClassNames', unique (species)) CMdl = crossval (Mdl) ***** test Mdl = CompactClassificationGAM (); assert_equal (class (Mdl), "CompactClassificationGAM") ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = [0; 0; 1; 1]; PredictorNames = {'Feature1', 'Feature2', 'Feature3'}; Mdl = fitcgam (x, y, 'FitMethod', 'splines', ... 'PredictorNames', PredictorNames); CMdl = compact (Mdl); assert_equal (class (CMdl), "CompactClassificationGAM"); assert_equal ({CMdl.NumPredictors, CMdl.ResponseName}, {3, 'Y'}) assert_equal (CMdl.ClassNames, [0; 1]) assert_equal (CMdl.PredictorNames, PredictorNames) assert_equal (CMdl.BaseModel.Intercept, 0) ***** test load fisheriris inds = strcmp (species,'versicolor') | strcmp (species,'virginica'); X = meas(inds, :); Y = species(inds, :)'; Y = strcmp (Y, 'virginica')'; Mdl = fitcgam (X, Y, 'FitMethod', 'splines', ... 'Formula', 'Y ~ x1 + x2 + x3 + x4 + x1:x2 + x2:x3'); CMdl = compact (Mdl); assert_equal (class (CMdl), "CompactClassificationGAM"); assert_equal ({CMdl.NumPredictors, CMdl.ResponseName}, {4, 'Y'}) assert_equal (CMdl.ClassNames, logical ([0; 1])) assert_equal (CMdl.Formula, 'Y ~ x1 + x2 + x3 + x4 + x1:x2 + x2:x3') assert_equal (CMdl.PredictorNames, {'x1', 'x2', 'x3', 'x4'}) assert_equal (CMdl.ModelwInt.Intercept, 0) ***** test X = [2, 3, 5; 4, 6, 8; 1, 2, 3; 7, 8, 9; 5, 4, 3]; Y = [0; 1; 0; 1; 1]; Mdl = fitcgam (X, Y, 'FitMethod', 'splines', ... 'Knots', [4, 4, 4], 'Order', [3, 3, 3]); CMdl = compact (Mdl); assert_equal (class (CMdl), "CompactClassificationGAM"); assert_equal ({CMdl.NumPredictors, CMdl.ResponseName}, {3, 'Y'}) assert_equal (CMdl.ClassNames, [0; 1]) assert_equal (CMdl.PredictorNames, {'x1', 'x2', 'x3'}) assert_equal (CMdl.BaseModel.Intercept, 0.4055, 1e-1) ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Cc = compact (fitcgam (Xch, Ych)); rand ("state", 1); randn ("state", 1); Cs = compact (fitcgam (Xch, Ycell)); assert_equal (cellstr (Cc.ClassNames), Cs.ClassNames); assert_equal (cellstr (predict (Cc, Xch)), predict (Cs, Xch)); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Cc = compact (fitcgam (Xch, Ych)); rand ("state", 1); randn ("state", 1); Cs = compact (fitcgam (Xch, Ycell)); assert_equal (loss (Cc, Xch, Ych), loss (Cs, Xch, Ycell), 1e-12); ***** test # a row missing a predictor is kept, and without a spline score it ## takes the class of largest prior x = linspace (0, 1, 30)'; X = [x, cos(4 * x)]; y = [ones(18, 1); 2 * ones(12, 1)]; Mdl = compact (ClassificationGAM (X, y, 'FitMethod', 'splines')); [label, score] = predict (Mdl, [0.5, 0.2; NaN, 0.2]); assert_equal (size (label), [2, 1]); assert_equal (label(2), 1); assert_equal (score(2,:), [NaN, NaN]); ***** test # a row missing every predictor is scored from the intercept k = (1:200)'; X = [sin(k), cos(2 * k), mod(k, 5)]; y = 2 * sin (k) + X(:,2) .^ 2 + 0.3 * X(:,3); Q = [0.5, 0.2, 1; NaN, 0.2, 1; 0.5, NaN, 1; NaN, NaN, NaN; 0.1, 0.2, 1; ... NaN, 0.7, 3; NaN, NaN, 1]; Mdl = compact (ClassificationGAM (X, y > median (y))); [label, score] = predict (Mdl, Q); assert_equal (size (label), [7, 1]); assert_equal (score(4,2), 1 / (1 + exp (-Mdl.Intercept)), 1e-14); ***** error ... CompactClassificationGAM (1) ***** test x = [1, 2; 3, 4; 5, 6; 7, 8; 9, 10]; y = [1; 0; 1; 0; 1]; Mdl = fitcgam (x, y, 'FitMethod', 'splines', 'interactions', 'all'); CMdl = compact (Mdl); l = [1; 0; 1; 0; 1]; s = [0.0334, 0.9666; 0.9648, 0.0352; 0.0334, 0.9666; ... 0.9648, 0.0352; 0.0334, 0.9666]; [labels, scores] = predict (CMdl, x); assert_equal (class (CMdl), "CompactClassificationGAM"); assert_equal ({CMdl.NumPredictors, CMdl.ResponseName}, {2, 'Y'}) assert_equal (CMdl.ClassNames, [0; 1]) assert_equal (CMdl.PredictorNames, {'x1', 'x2'}) assert_equal (CMdl.ModelwInt.Intercept, 0.4055, 1e-1) assert_equal (labels, l) assert_equal (scores, s, 1e-1) ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = [0; 0; 1; 1]; interactions = [false, true, false; true, false, true; false, true, false]; Mdl = fitcgam (x, y, 'FitMethod', 'splines', ... 'learningrate', 0.2, 'interactions', interactions); CMdl = compact (Mdl); [label, score] = predict (CMdl, x, 'includeinteractions', true); l = [0; 0; 1; 1]; s = [0.9725, 0.0275; 0.9895, 0.0105; 0.0070, 0.9930; 0.0238, 0.9762]; assert_equal (class (CMdl), "CompactClassificationGAM"); assert_equal ({CMdl.NumPredictors, CMdl.ResponseName}, {3, 'Y'}) assert_equal (CMdl.ClassNames, [0; 1]) assert_equal (CMdl.PredictorNames, {'x1', 'x2', 'x3'}) assert_equal (CMdl.ModelwInt.Intercept, 0) assert_equal (label, l) assert_equal (score, s, 1e-1) ***** shared CMdl Mdl = fitcgam (ones (4,2), ones (4,1)); CMdl = compact (Mdl); ***** error ... predict (CMdl) ***** error ... predict (CMdl, []) ***** error ... predict (CMdl, 1) ***** error ... predict (CMdl, ones (4,2), 'Bogus', 1) ***** error ... savemodel (CompactClassificationGAM ()) ***** error ... savemodel (CompactClassificationGAM (), 1) ***** error ... savemodel (CompactClassificationGAM (), ['ab'; 'cd']) ***** test load fisheriris inds = ! strcmp (species, 'virginica'); CMdl = compact (fitcgam (meas(inds,:), species(inds))); assert_equal (CMdl.ScoreTransform, 'logit'); [~, scores] = predict (CMdl, meas(1:6,:)); assert_equal (sum (scores, 2), ones (6, 1), 1e-12); ***** test CMdl = compact (fitcgam ([1, 2; 2, 3; 3, 4; 4, 5], [1; 1; 2; 2])); CMdl.ScoreTransform = 'symmetric'; assert_equal (class (CMdl.ScoreTransform), 'char'); assert_equal (CMdl.ScoreTransform, 'symmetric'); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = fitcgam (meas(inds,:), species(inds)); CMdl = compact (Mdl); assert_equal (CMdl.Intercept, Mdl.Intercept); assert_equal (CMdl.CategoricalPredictors, Mdl.CategoricalPredictors); assert_equal (CMdl.ExpandedPredictorNames, Mdl.ExpandedPredictorNames); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); X = meas(inds,:); Y = species(inds); Mdl = fitcgam (X, Y); CMdl = compact (Mdl); assert_equal (margin (CMdl, X, Y), margin (Mdl, X, Y)); assert_equal (edge (CMdl, X, Y), edge (Mdl, X, Y)); assert_equal (loss (CMdl, X, Y), loss (Mdl, X, Y)); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); CMdl = compact (fitcgam (meas(inds,:), species(inds), ... 'FitMethod', 'splines')); fname = tempname (); savemodel (CMdl, fname); CMdl2 = loadmodel (fname); delete (fname); assert_equal (CMdl2.Intercept, CMdl.Intercept); assert_equal (CMdl2.ClassNames, CMdl.ClassNames); assert_equal (CMdl2.BaseModel.Parameters(1).coefs, ... CMdl.BaseModel.Parameters(1).coefs); assert_equal (predict (CMdl2, meas(inds,:)), predict (CMdl, meas(inds,:))); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); CMdl = compact (fitcgam (meas(inds,:), species(inds), ... 'FitMethod', 'boostedtrees')); fname = tempname (); savemodel (CMdl, fname); CMdl2 = loadmodel (fname); delete (fname); assert_equal (CMdl2.Intercept, CMdl.Intercept); assert_equal (CMdl2.TreeModel.ShapeValues, CMdl.TreeModel.ShapeValues); assert_equal (CMdl2.BinEdges, CMdl.BinEdges); assert_equal (predict (CMdl2, meas(inds,:)), predict (CMdl, meas(inds,:))); ***** shared x2, y2, CM load fisheriris inds = ! strcmp (species, 'virginica'); x2 = meas(inds,:); y2 = species(inds); CM = compact (fitcgam (x2, y2)); ***** error ... margin (CM, x2) ***** error ... margin (CM, [], y2) ***** error ... edge (CM, x2, y2, 'Weights') ***** error ... loss (CM, x2, y2, 'LossFun', 'nonsense') ***** error ... loss (CM, x2, y2, 'Bogus', 1) ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = compact (fitcgam (meas(inds,:), species(inds))); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2), 'CompactClassificationGAM'); assert_equal (M2.PredictorNames, Mdl.PredictorNames); assert_equal (class (M2.ScoreTransform), class (Mdl.ScoreTransform)); assert_equal (predict (M2, meas(1:5,:)), predict (Mdl, meas(1:5,:))); ***** error ... Mdl = fitcgam ([1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1], [0; 0; 1; 1]); CMdl = compact (Mdl); CMdl.Cost = 1:4; ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = compact (fitcgam (meas(inds,:), species(inds))); S = struct ('ClassNames', {{'versicolor'; 'setosa'}}, ... 'ClassificationCosts', [0, 1; 2, 0]); Mdl.Cost = S; assert_equal (Mdl.Cost, [0, 2; 1, 0]); ***** error ... load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = compact (fitcgam (meas(inds,:), species(inds))); Mdl.Cost = ones (2); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); X = meas(inds,:); Mdl = fitcgam (X, species(inds), 'FitMethod', 'boostedtrees'); CMdl = compact (Mdl); assert_equal (CMdl.FitMethod, 'boostedtrees'); assert_equal (CMdl.TreeModel.ShapeValues, Mdl.TreeModel.ShapeValues); assert_equal (predict (CMdl, X), predict (Mdl, X)); fname = tempname (); savemodel (CMdl, fname); C2 = loadmodel (fname); delete (fname); assert_equal (predict (C2, X), predict (CMdl, X)); ***** test load fisheriris Mdl = compact (fitcgam (meas, strcmp (species, 'setosa'))); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); T = {'identity', @(x) x; 'doublelogit', @(x) 1 ./ (1 + exp (-2 * x)); ... 'invlogit', @(x) log (x ./ (1 - x)); ... 'logit', @(x) 1 ./ (1 + exp (-x)); ... 'sign', @(x) sign (x); 'symmetric', @(x) 2 * x - 1; ... 'symmetriclogit', @(x) 2 ./ (1 + exp (-x)) - 1}; for i = 1:rows (T) Mdl.ScoreTransform = T{i,1}; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, T{i,2}(raw), 1e-12); assert_equal (l, label); endfor ## ismax marks the largest score of each observation, ties to the first. [~, k] = max (raw, [], 2); e = zeros (size (raw)); e(sub2ind (size (raw), (1:rows (raw))', k)) = 1; Mdl.ScoreTransform = 'ismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, e); Mdl.ScoreTransform = 'symmetricismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, 2 * e - 1); ***** test load fisheriris Mdl = compact (fitcgam (meas, strcmp (species, 'setosa'))); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); Mdl.ScoreTransform = @(x) x .^ 2; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, raw .^ 2, 1e-12); assert_equal (l, label); ***** test # the levels a predictor was coded through travel with the model load fisheriris inds = ! strcmp (species, 'setosa'); X = meas(inds,:); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Wide = categorical (X(:,2) > 2.9, [false true], {'narrow', 'wide'}); T.Species = categorical (species(inds)); CMdl = compact (fitcgam (T, 'Species')); assert_equal (numel (CMdl.PredictorLevels), 3); assert_equal (CMdl.PredictorLevels{3}, {'narrow', 'wide'}); ***** test # predict takes a table, read by name and not by position load fisheriris inds = ! strcmp (species, 'setosa'); X = meas(inds,:); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = categorical (species(inds)); CMdl = compact (fitcgam (T, 'Species')); a = predict (CMdl, T); assert_equal (class (a), 'categorical'); assert_equal (predict (CMdl, T(:, [3, 2, 1])), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(51:150,1:2); y = categorical (species(51:150)); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcgam (T, 'Species')); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(51:150,1:2); y = categorical (species(51:150)); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcgam (T, 'Species')); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(51:150,1:2); y = categorical (species(51:150)); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcgam (T, 'Species')); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** error ... loss (compact (fitcgam ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2])), ... [1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', int8 ([1; 1; 1; 1])) 42 tests, 42 passed, 0 known failure, 0 skipped [inst/Machine_Learning/RegressionPartitionedEnsemble.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/RegressionPartitionedEnsemble.m ***** shared X, y, S, c, CV load fisheriris X = meas(:,2:4); y = meas(:,1); S = templateTree ('MaxNumSplits', 1); c = cvpartition (150, 'KFold', 5); CV = fitrensemble (X, y, 'NumLearningCycles', 3, 'Learners', S, ... 'CVPartition', c); ***** test # MATLAB parity: the properties of a cross-validated ensemble assert_equal (class (CV), 'RegressionPartitionedEnsemble'); assert_equal (numel (properties (CV)), 16); assert_equal (CV.KFold, 5); assert_equal (CV.NumTrainedPerFold, [3, 3, 3, 3, 3]); assert_equal (CV.CrossValidatedModel, 'LSBoost'); assert_equal (class (CV.Trained{1}), 'CompactRegressionEnsemble'); assert_equal (class (CV.Trainable{1}), 'RegressionEnsemble'); ***** test # MATLAB parity: each row is predicted by the fold that held it out yf = zeros (150, 1); for k = 1:5 te = test (c, k); yf(te) = predict (CV.Trained{k}, X(te,:)); endfor assert_equal (kfoldPredict (CV), yf); assert_equal (kfoldLoss (CV), mean ((yf - y) .^ 2), 1e-14); Li = kfoldLoss (CV, 'Mode', 'individual'); assert_equal (Li(4), mean ((yf(test (c, 4)) - y(test (c, 4))) .^ 2), 1e-14); ***** test # MATLAB parity: the cumulative loss grows the trees of every fold Lc = kfoldLoss (CV, 'Mode', 'cumulative'); assert_equal (size (Lc), [3, 1]); yf = zeros (150, 1); for k = 1:5 te = test (c, k); yf(te) = predict (CV.Trained{k}, X(te,:), 'Learners', 1:2); endfor assert_equal (Lc(2), mean ((yf - y) .^ 2), 1e-14); assert_equal (Lc(3), kfoldLoss (CV), 1e-14); ***** test # the response transform is applied once, where MATLAB applies it twice M = fitrensemble (X, y, 'NumLearningCycles', 3, 'Learners', S, ... 'CVPartition', c, 'ResponseTransform', @(z) 2 * z); assert_equal (M.Trained{1}.ResponseTransform, 'none'); assert_equal (kfoldPredict (M), 2 * kfoldPredict (CV), 1e-14); ***** test # MATLAB parity: kfoldfun and resume f = kfoldfun (CV, @(C, Xtr, Ytr, Wtr, Xte, Yte, Wte) [rows(Xtr), rows(Xte)]); assert_equal (f(1,:), [120, 30]); R = resume (CV, 1); assert_equal (R.NumTrainedPerFold, [4, 4, 4, 4, 4]); ***** test # MATLAB parity: the losses weigh the held-out rows by W w = [5 * ones(50, 1); ones(100, 1)]; M = fitrensemble (X, y, 'NumLearningCycles', 3, 'Learners', S, ... 'CVPartition', c, 'Weights', w); yf = kfoldPredict (M); assert_equal (kfoldLoss (M), sum (M.W .* (yf - y) .^ 2) / sum (M.W), 1e-14); ***** error ... RegressionPartitionedEnsemble (1) ***** error ... RegressionPartitionedEnsemble (1, c) ***** error ... RegressionPartitionedEnsemble (CV.Trainable{1}, 1) ***** error ... kfoldLoss (CV, 'Mode') ***** error ... kfoldLoss (CV, 'Learners', 1) ***** error ... kfoldLoss (CV, 'Mode', 'ensemble') ***** error ... kfoldLoss (CV, 'Folds', 0) ***** error ... kfoldLoss (CV, 'LossFun', 'mae') ***** error ... kfoldfun (CV, 1) ***** error ... resume (CV) 16 tests, 16 passed, 0 known failure, 0 skipped [inst/Machine_Learning/templateKNN.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/templateKNN.m ***** test # the default template names its learner and nothing else T = templateKNN (); assert_equal (class (T), 'struct'); assert_equal (T.Method, 'KNN'); assert_equal (T.Type, 'classification'); assert_equal (numfields (T), 2); ***** test # an option given is stored under its own name, as it stands T = templateKNN ('NumNeighbors', 5, 'Distance', 'cityblock'); assert_equal (numfields (T), 4); assert_equal (T.NumNeighbors, 5); assert_equal (T.Distance, 'cityblock'); ***** test # a name the learner does not know is not refused here T = templateKNN ('NoSuchOption', 42); assert_equal (T.NoSuchOption, 42); ***** error ... templateKNN ('KernelScale') ***** error ... templateKNN (42, 1) ***** error ... templateKNN ('not a name', 1) 6 tests, 6 passed, 0 known failure, 0 skipped [inst/Machine_Learning/ClassificationPartitionedLinear.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/ClassificationPartitionedLinear.m ***** demo ## Cross-validate a linear classifier on the two overlapping iris ## species and read the out-of-sample error rate. load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5) outOfSample = kfoldLoss (CVMdl) ***** test ## The model reports the surface MATLAB reports load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5); assert_equal (class (CVMdl), 'ClassificationPartitionedLinear'); assert_equal (CVMdl.CrossValidatedModel, 'Linear'); assert_equal (CVMdl.KFold, 5); assert_equal (CVMdl.NumObservations, 100); assert_equal (CVMdl.ClassNames, {'versicolor'; 'virginica'}); assert_equal (CVMdl.Prior, [0.5, 0.5]); assert_equal (CVMdl.Cost, [0, 1; 1, 0]); assert_equal (CVMdl.ScoreTransform, 'none'); assert_equal (CVMdl.ResponseName, 'Y'); assert_equal (CVMdl.PredictorNames, {'x1', 'x2', 'x3', 'x4'}); assert_equal (size (CVMdl.Trained), [5, 1]); assert_equal (class (CVMdl.Trained{1}), 'ClassificationLinear'); assert_equal (sum (CVMdl.W), 1, 1e-12); ***** test ## The properties are the ones MATLAB lists, in its order load fisheriris CVMdl = ClassificationPartitionedLinear (meas(51:end,:), species(51:end)); assert_equal (sort (properties (CVMdl)), ... sort ({'ClassNames'; 'Cost'; 'Prior'; 'ScoreTransform'; ... 'CrossValidatedModel'; 'NumObservations'; 'Y'; 'W'; ... 'PredictorNames'; 'CategoricalPredictors'; ... 'ResponseName'; 'Trained'; 'KFold'; 'Partition'; ... 'ModelParameters'})); ***** test ## The default is ten stratified folds load fisheriris CVMdl = ClassificationPartitionedLinear (meas(51:end,:), species(51:end)); assert_equal (CVMdl.KFold, 10); assert_equal (numel (CVMdl.Trained), 10); ***** test ## Each fold resolves 'Lambda' against its own training rows, not the ## parent's count: eighty of a hundred observations train each fold of ## five, so the strength is one eightieth. This is R2024a's number. load fisheriris CVMdl = ClassificationPartitionedLinear (meas(51:end,:), ... species(51:end), 'KFold', 5); assert_equal (CVMdl.Trained{1}.Lambda, 1 / 80, 1e-15); assert_equal (CVMdl.Trained{3}.Lambda, 1 / 80, 1e-15); ***** test ## The class names, the prior and the cost are the parent's and are ## handed to every fold, so an unbalanced problem does not give each fold ## a prior of its own. Also R2024a's behaviour. load fisheriris X = meas([51:100, 101:120],:); Y = species([51:100, 101:120]); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5); assert_equal (CVMdl.Prior, [50/70, 20/70], 1e-12); assert_equal (CVMdl.Trained{1}.Prior, CVMdl.Prior); assert_equal (CVMdl.Trained{4}.Prior, CVMdl.Prior); assert_equal (CVMdl.Trained{1}.ClassNames, CVMdl.ClassNames); ***** test ## kfoldPredict predicts each observation with the fold that held it out. ## Doing the same partition by hand must give the same answers, which is ## what pins the assembly rather than the fit. load fisheriris X = meas(51:end,:); Y = species(51:end); part = cvpartition (Y, 'KFold', 4); CVMdl = ClassificationPartitionedLinear (X, Y, 'CVPartition', part); [label, score] = kfoldPredict (CVMdl); byhand = cell (100, 1); for k = 1:4 tr = training (part, k); te = test (part, k); m = ClassificationLinear (X(tr,:), Y(tr), 'ClassNames', ... CVMdl.ClassNames, 'Prior', CVMdl.Prior, ... 'Cost', CVMdl.Cost); byhand(te) = predict (m, X(te,:)); endfor assert_equal (label, byhand); assert_equal (size (score), [100, 2]); ***** test ## The margin is the out-of-fold score of the true class less the other, ## and the edge its weighted mean load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5); [~, score] = kfoldPredict (CVMdl); m = kfoldMargin (CVMdl); virg = strcmp (Y, 'virginica'); expect = score(:,1) - score(:,2); expect(virg) = score(virg,2) - score(virg,1); assert_equal (m, expect, 1e-12); assert_equal (mean (m > 0), 1 - kfoldLoss (CVMdl), 1e-12); ***** test ## 'Mode', 'individual' gives one row per fold load fisheriris CVMdl = ClassificationPartitionedLinear (meas(51:end,:), ... species(51:end), 'KFold', 5); assert_equal (size (kfoldLoss (CVMdl, 'Mode', 'individual')), [5, 1]); assert_equal (size (kfoldEdge (CVMdl, 'Mode', 'individual')), [5, 1]); ***** test ## Averaging pools the observations rather than averaging the per-fold ## values, which is not the same thing once the folds differ in size. ## The pooled reading is the one R2024a returns. load fisheriris X = meas([51:100, 101:143],:); Y = species([51:100, 101:143]); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 4); [~, score] = kfoldPredict (CVMdl); gY = 1 + strcmp (Y, 'virginica'); wrong = mean (score(sub2ind (size (score), (1:93)', gY)) ... <= score(sub2ind (size (score), (1:93)', 3 - gY))); assert_equal (kfoldLoss (CVMdl), wrong, 1e-12); ***** test ## 'Folds' reports over the observations of the folds it names load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5); two = kfoldLoss (CVMdl, 'Folds', [1, 2]); idx = test (CVMdl.Partition, 1) | test (CVMdl.Partition, 2); [label, ~] = kfoldPredict (CVMdl); assert_equal (two, mean (! strcmp (label(idx), Y(idx))), 1e-12); ***** test ## Every classification loss is offered, and each reads the out-of-fold ## score of the true class load fisheriris CVMdl = ClassificationPartitionedLinear (meas(51:end,:), ... species(51:end), 'KFold', 5); for f = {'binodeviance', 'classifcost', 'classiferror', 'exponential', ... 'hinge', 'logit', 'mincost', 'quadratic'} assert_equal (isfinite (kfoldLoss (CVMdl, 'LossFun', f{1})), true); endfor ***** test ## A logistic fit reports posteriors, and the transform that produces ## them stays with the fold models: the cross-validated model reports ## none of its own, which is R2024a's arrangement and not the reverse load fisheriris CVMdl = ClassificationPartitionedLinear (meas(51:end,:), ... species(51:end), 'KFold', 5, ... 'Learner', 'logistic'); assert_equal (CVMdl.ScoreTransform, 'none'); assert_equal (CVMdl.Trained{1}.ScoreTransform, 'logit'); [~, score] = kfoldPredict (CVMdl); assert_equal (sum (score, 2), ones (100, 1), 1e-12); ***** test ## A whole regularization path gives one column per strength everywhere load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5, ... 'Lambda', [0.001, 0.01, 0.1]); [label, score] = kfoldPredict (CVMdl); assert_equal (size (label), [100, 3]); assert_equal (size (score), [100, 2, 3]); assert_equal (size (kfoldMargin (CVMdl)), [100, 3]); assert_equal (size (kfoldLoss (CVMdl)), [1, 3]); assert_equal (size (kfoldEdge (CVMdl)), [1, 3]); assert_equal (size (kfoldLoss (CVMdl, 'Mode', 'individual')), [5, 3]); ***** test ## An observation that no fold held out is not classified: under a ## holdout partition that is the training rows, and they come back ## missing rather than carrying a class load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'Holdout', 0.3); assert_equal (CVMdl.KFold, 1); [label, score] = kfoldPredict (CVMdl); assert_equal (sum (cellfun (@isempty, label)), 70); assert_equal (sum (isnan (score(:,1))), 70); assert_equal (isfinite (kfoldLoss (CVMdl)), true); ***** test ## Leave-one-out gives as many folds as there are observations load fisheriris X = meas([51:70, 101:120],:); Y = species([51:70, 101:120]); CVMdl = ClassificationPartitionedLinear (X, Y, 'Leaveout', 'on'); assert_equal (CVMdl.KFold, 40); assert_equal (numel (kfoldPredict (CVMdl)), 40); ***** test ## A row with a missing predictor is dropped before the partition, so ## every index below refers to the same set of observations load fisheriris X = meas(51:end,:); Y = species(51:end); X(3,2) = NaN; CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5); assert_equal (CVMdl.NumObservations, 99); assert_equal (numel (CVMdl.Y), 99); assert_equal (CVMdl.Partition.NumObservations, 99); ***** test ## Observation weights reach both the folds and the reported prior load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5, ... 'Weights', (1:100)'); assert_equal (CVMdl.Prior, [0.252475247524752, 0.747524752475248], 1e-12); assert_equal (CVMdl.Trained{1}.Prior, CVMdl.Prior); assert_equal (sum (CVMdl.W), 1, 1e-12); ***** test ## A character matrix response carries through cross-validation: the ## class names, the fold models, the assembled labels and every kfold ## method answer as they do for the equivalent cell array load fisheriris X = meas(51:end,:); Yc = species(51:end); Ym = char (Yc); part = cvpartition (Yc, 'KFold', 4); CVc = ClassificationPartitionedLinear (X, Yc, 'CVPartition', part); CVm = ClassificationPartitionedLinear (X, Ym, 'CVPartition', part); assert_equal (cellstr (CVm.ClassNames), CVc.ClassNames); assert_equal (size (CVm.ClassNames), [2, 10]); assert_equal (cellstr (CVm.Trained{1}.ClassNames), CVc.ClassNames); assert_equal (cellstr (kfoldPredict (CVm)), kfoldPredict (CVc)); assert_equal (kfoldMargin (CVm), kfoldMargin (CVc)); assert_equal (kfoldEdge (CVm), kfoldEdge (CVc)); assert_equal (kfoldLoss (CVm), kfoldLoss (CVc)); assert_equal (kfoldLoss (CVm, 'LossFun', 'hinge'), ... kfoldLoss (CVc, 'LossFun', 'hinge')); ***** test ## Names of unequal length are padded by the character matrix and the ## padding is not part of the name, through the cross-validated path too load fisheriris X = meas(51:end,:); Y = [repmat({'ab'}, 50, 1); repmat({'abcd'}, 50, 1)]; part = cvpartition (Y, 'KFold', 4); CVc = ClassificationPartitionedLinear (X, Y, 'CVPartition', part); CVm = ClassificationPartitionedLinear (X, char (Y), 'CVPartition', part); assert_equal (cellstr (CVm.ClassNames), CVc.ClassNames); assert_equal (cellstr (kfoldPredict (CVm)), kfoldPredict (CVc)); ***** test ## A row dropped for a missing predictor is dropped before the partition, ## through the character path, which is the case that exercises the row ## indexing rather than the label comparison load fisheriris X = meas(51:end,:); X(7,3) = NaN; CVMdl = ClassificationPartitionedLinear (X, char (species(51:end)), ... 'KFold', 4); assert_equal (CVMdl.NumObservations, 99); assert_equal (size (CVMdl.Y), [99, 10]); assert_equal (numel (kfoldPredict (CVMdl)) / 10, 99); ***** test ## A transform asked for by name goes to the parent and not to the folds, ## and is applied once to the assembled scores. R2024a's arrangement. load fisheriris part = cvpartition (species(51:end), 'KFold', 5); plain = ClassificationPartitionedLinear (meas(51:end,:), species(51:end), ... 'CVPartition', part); CVMdl = ClassificationPartitionedLinear (meas(51:end,:), species(51:end), ... 'CVPartition', part, ... 'ScoreTransform', 'doublelogit'); assert_equal (CVMdl.ScoreTransform, 'doublelogit'); assert_equal (CVMdl.Trained{1}.ScoreTransform, 'none'); [~, s0] = kfoldPredict (plain); [~, s1] = kfoldPredict (CVMdl); assert_equal (s1, 1 ./ (1 + exp (-2 * s0)), 1e-12); ***** test ## It can be assigned after the model is built, and reaches kfoldPredict ## without being carried into the folds load fisheriris CVMdl = ClassificationPartitionedLinear (meas(51:end,:), species(51:end), ... 'KFold', 5); [~, s0] = kfoldPredict (CVMdl); CVMdl.ScoreTransform = 'doublelogit'; [~, s1] = kfoldPredict (CVMdl); assert_equal (CVMdl.Trained{1}.ScoreTransform, 'none'); assert_equal (s1, 1 ./ (1 + exp (-2 * s0)), 1e-12); ***** test ## A transform the learner implies stays with the folds, and an assigned ## one is applied on top of it rather than replacing it. Measured on ## R2024a, where the folds keep 'logit' and the parent's transform ## composes. load fisheriris CVMdl = ClassificationPartitionedLinear (meas(51:end,:), species(51:end), ... 'KFold', 5, ... 'Learner', 'logistic'); [~, s0] = kfoldPredict (CVMdl); CVMdl.ScoreTransform = 'doublelogit'; [~, s1] = kfoldPredict (CVMdl); assert_equal (CVMdl.Trained{1}.ScoreTransform, 'logit'); assert_equal (s1, 1 ./ (1 + exp (-2 * s0)), 1e-12); ***** test ## 'none' is the identity, so assigning it transforms nothing load fisheriris CVMdl = ClassificationPartitionedLinear (meas(51:end,:), species(51:end), ... 'KFold', 5); [~, s0] = kfoldPredict (CVMdl); CVMdl.ScoreTransform = 'none'; [~, s1] = kfoldPredict (CVMdl); assert_equal (s1, s0); ***** error ... load fisheriris CVMdl = ClassificationPartitionedLinear (meas(51:end,:), species(51:end), ... 'KFold', 5); CVMdl.ScoreTransform = 'nosuchtransform'; ***** error ... ClassificationPartitionedLinear (ones (10, 2)) ***** error ... ClassificationPartitionedLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'KFold') ***** error ... ClassificationPartitionedLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'KFold', 1) ***** error ... ClassificationPartitionedLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'Holdout', 1.5) ***** error ... ClassificationPartitionedLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'Leaveout', 1) ***** error ... ClassificationPartitionedLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'CVPartition', 3) ***** error ... ClassificationPartitionedLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'KFold', 2, 'Holdout', 0.2) ***** error ... ClassificationPartitionedLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'CVPartition', cvpartition (20, 'KFold', 2)) ***** error ... ClassificationPartitionedLinear (ones (9, 2), ... [1; 1; 1; 2; 2; 2; 3; 3; 3], 'KFold', 3) ***** error ... kfoldLoss (ClassificationPartitionedLinear (ones (10, 2), ... [ones(5,1); 2*ones(5,1)], 'KFold', 2), 'Mode', 'each') ***** error ... kfoldLoss (ClassificationPartitionedLinear (ones (10, 2), ... [ones(5,1); 2*ones(5,1)], 'KFold', 2), 'Folds', 7) ***** error ... kfoldLoss (ClassificationPartitionedLinear (ones (10, 2), ... [ones(5,1); 2*ones(5,1)], 'KFold', 2), 'LossFun', 'mse') ***** error ... kfoldEdge (ClassificationPartitionedLinear (ones (10, 2), ... [ones(5,1); 2*ones(5,1)], 'KFold', 2), 'LossFun', ... 'hinge') ***** test load fisheriris Mdl = fitclinear (meas, strcmp (species, 'setosa'), 'KFold', 3); Mdl.ScoreTransform = 'none'; [label, raw] = kfoldPredict (Mdl); T = {'identity', @(x) x; 'doublelogit', @(x) 1 ./ (1 + exp (-2 * x)); ... 'invlogit', @(x) log (x ./ (1 - x)); ... 'logit', @(x) 1 ./ (1 + exp (-x)); ... 'sign', @(x) sign (x); 'symmetric', @(x) 2 * x - 1; ... 'symmetriclogit', @(x) 2 ./ (1 + exp (-x)) - 1}; for i = 1:rows (T) Mdl.ScoreTransform = T{i,1}; [l, s] = kfoldPredict (Mdl); assert_equal (s, T{i,2}(raw), 1e-12); assert_equal (l, label); endfor ## ismax marks the largest score of each observation, ties to the first. [~, k] = max (raw, [], 2); e = zeros (size (raw)); e(sub2ind (size (raw), (1:rows (raw))', k)) = 1; Mdl.ScoreTransform = 'ismax'; [~, s] = kfoldPredict (Mdl); assert_equal (s, e); Mdl.ScoreTransform = 'symmetricismax'; [~, s] = kfoldPredict (Mdl); assert_equal (s, 2 * e - 1); ***** test load fisheriris Mdl = fitclinear (meas, strcmp (species, 'setosa'), 'KFold', 3); Mdl.ScoreTransform = 'none'; [label, raw] = kfoldPredict (Mdl); Mdl.ScoreTransform = @(x) x .^ 2; [l, s] = kfoldPredict (Mdl); assert_equal (s, raw .^ 2, 1e-12); assert_equal (l, label); ***** test # the predictors and the response may come from a table load fisheriris inds = ! strcmp (species, 'setosa'); T = table (meas(inds,1), meas(inds,2), 'VariableNames', {'SL', 'SW'}); T.Species = species(inds); CVMdl = ClassificationPartitionedLinear (T, 'Species', 'KFold', 3); assert_equal (class (CVMdl), 'ClassificationPartitionedLinear'); assert_equal (CVMdl.KFold, 3); 41 tests, 41 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitcgam.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitcgam.m ***** demo ## Train a GAM classifier for binary classification ## using specific data and plot the decision boundaries. ## Define specific data X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ... 6, 7; 7, 8; 8, 8; 9, 9; 10, 10]; Y = [0; 0; 0; 0; 0; ... 1; 1; 1; 1; 1]; ## Train the GAM model obj = fitcgam (X, Y, 'Interactions', 'all'); ## Create a grid of values for prediction x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; pred = predict (obj, XGrid); ## Plot decision boundaries and data points predNumeric = str2double (pred); gidx = predNumeric > 0.5; figure scatter (XGrid(gidx,1), XGrid(gidx,2), 'markerfacecolor', 'magenta'); hold on scatter (XGrid(! gidx,1), XGrid(! gidx,2), 'markerfacecolor', 'red'); plot (X(Y == 0, 1), X(Y == 0, 2), 'ko', X(Y == 1, 1), X(Y == 1, 2), 'kx'); xlabel ('Feature 1'); ylabel ('Feature 2'); title ('Generalized Additive Model (GAM) Decision Boundary'); legend ({'Class 1 Region', 'Class 0 Region', ... 'Class 1 Samples', 'Class 0 Samples'}, ... 'location', 'northwest') axis tight hold off ***** demo ## Fit from a table, and predict on one load fisheriris inds = ! strcmp (species, 'setosa'); X = meas(inds,:); T = table (X(:,1), X(:,2), X(:,3), X(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = categorical (species(inds)); ## A column holding levels is a categorical predictor without being named ## one T.Wide = categorical (X(:,2) > 2.9, [false true], {'narrow', 'wide'}); ## The response is named by its column, and everything else is a predictor Mdl = fitcgam (T, 'Species'); Mdl.PredictorNames Mdl.CategoricalPredictors ## predict reads a table by the names the model was fitted on, so the ## columns may come in any order label = predict (Mdl, T(1:5, [6, 5, 4, 3, 2, 1])); label' ***** test x = [1, 2, 3; 4, 5, 6; 7, 8, 9; 3, 2, 1]; y = [0; 0; 1; 1]; PredictorNames = {'Feature1', 'Feature2', 'Feature3'}; a = fitcgam (x, y, 'FitMethod', 'splines', ... 'PredictorNames', PredictorNames); assert_equal (class (a), "ClassificationGAM"); assert_equal ({a.X, a.Y, a.NumObservations}, {x, y, 4}) assert_equal ({a.NumPredictors, a.ResponseName}, {3, 'Y'}) assert_equal (a.ClassNames, [0; 1]) assert_equal (a.PredictorNames, PredictorNames) assert_equal (a.BaseModel.Intercept, 0) ***** test x = [1, 2; 3, 4; 5, 6; 7, 8; 9, 10]; y = [1; 0; 1; 0; 1]; a = fitcgam (x, y, 'FitMethod', 'splines', 'interactions', 'all'); assert_equal (class (a), "ClassificationGAM"); assert_equal ({a.X, a.Y, a.NumObservations}, {x, y, 5}) assert_equal ({a.NumPredictors, a.ResponseName}, {2, 'Y'}) assert_equal (a.ClassNames, [0; 1]) assert_equal (a.PredictorNames, {'x1', 'x2'}) assert_equal (a.ModelwInt.Intercept, 0.4055, 1e-1) ***** test load fisheriris inds = strcmp (species,'versicolor') | strcmp (species,'virginica'); X = meas(inds, :); Y = species(inds, :)'; Y = strcmp (Y, 'virginica')'; a = fitcgam (X, Y, 'FitMethod', 'splines', ... 'Formula', 'Y ~ x1 + x2 + x3 + x4 + x1:x2 + x2:x3'); assert_equal (class (a), "ClassificationGAM"); assert_equal ({a.X, a.Y, a.NumObservations}, {X, Y, 100}) assert_equal ({a.NumPredictors, a.ResponseName}, {4, 'Y'}) assert_equal (a.ClassNames, logical ([0; 1])) assert_equal (a.Formula, 'Y ~ x1 + x2 + x3 + x4 + x1:x2 + x2:x3') assert_equal (a.PredictorNames, {'x1', 'x2', 'x3', 'x4'}) assert_equal (a.ModelwInt.Intercept, 0) ***** error fitcgam () ***** error fitcgam (ones (4,1)) ***** error fitcgam (ones (4,2), ones (4, 1), 'K') ***** error fitcgam (ones (4,2), ones (3, 1)) ***** error fitcgam (ones (4,2), ones (3, 1), 'K', 2) ***** test # MATLAB parity: classes given as text are sorted load fisheriris k = [101:150, 51:100]; Mdl = fitcgam (meas(k,:), species(k)); assert_equal (Mdl.ClassNames, {'versicolor'; 'virginica'}); ***** test # MATLAB parity: a given ClassNames order is kept load fisheriris Mdl = fitcgam (meas(51:150,:), species(51:150), ... 'ClassNames', {'virginica'; 'versicolor'}); assert_equal (Mdl.ClassNames, {'virginica'; 'versicolor'}); ***** error ... load fisheriris fitcgam (meas(51:150,:), species(51:150), 'ClassNames', [3, 2]) ***** shared fcgT load fisheriris inds = ! strcmp (species, 'setosa'); fcgX = meas(inds,:); fcgT = table (fcgX(:,1), fcgX(:,2), fcgX(:,3), fcgX(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); fcgT.Species = categorical (species(inds)); fcgT.Wide = categorical (fcgX(:,2) > 2.9, [false true], ... {'narrow', 'wide'}); ***** test # the response is named by a column and the rest are predictors Mdl = fitcgam (fcgT, 'Species'); assert_equal (Mdl.PredictorNames, {'SL', 'SW', 'PL', 'PW', 'Wide'}); assert_equal (Mdl.ResponseName, 'Species'); ***** test # a column holding levels is a categorical predictor of its own accord Mdl = fitcgam (fcgT, 'Species'); assert_equal (Mdl.CategoricalPredictors, 5); ***** test # a model formula names the response and the predictors together Mdl = fitcgam (fcgT, 'Species ~ SL + Wide'); assert_equal (Mdl.PredictorNames, {'SL', 'Wide'}); assert_equal (Mdl.CategoricalPredictors, 2); ***** test # the response may be given beside a table of predictors Mdl = fitcgam (fcgT(:,1:4), fcgT.Species); assert_equal (Mdl.PredictorNames, {'SL', 'SW', 'PL', 'PW'}); assert_equal (Mdl.ResponseName, 'Y'); ***** test # predict takes a table, matched by name and not by position Mdl = fitcgam (fcgT, 'Species'); a = predict (Mdl, fcgT); assert_equal (class (a), 'categorical'); assert_equal (predict (Mdl, fcgT(:, [6, 5, 4, 3, 2, 1])), a); ***** test # the levels travel with the model when it is made compact Mdl = fitcgam (fcgT, 'Species'); CMdl = compact (Mdl); assert_equal (CMdl.PredictorLevels, Mdl.PredictorLevels); assert_equal (predict (CMdl, fcgT), predict (Mdl, fcgT)); ***** error ... fitcgam (fcgT, 'NoSuch') ***** error ... fitcgam (fcgT, 'Species ~ SL*PW') ***** error ... predict (fitcgam (fcgT, 'Species'), fcgT(:, [1, 3, 4, 5, 6])) 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Machine_Learning/CompactClassificationDiscriminant.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/CompactClassificationDiscriminant.m ***** demo ## Create a discriminant analysis classifier and its compact version # and compare their size load fisheriris X = meas; Y = species; Mdl = fitcdiscr (X, Y, 'ClassNames', unique (species)) CMdl = crossval (Mdl) ***** test load fisheriris x = meas; y = species; PredictorNames = {'Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width'}; Mdl = fitcdiscr (x, y, 'PredictorNames', PredictorNames); CMdl = compact (Mdl); sigma = [0.265008, 0.092721, 0.167514, 0.038401; ... 0.092721, 0.115388, 0.055244, 0.032710; ... 0.167514, 0.055244, 0.185188, 0.042665; ... 0.038401, 0.032710, 0.042665, 0.041882]; mu = [5.0060, 3.4280, 1.4620, 0.2460; ... 5.9360, 2.7700, 4.2600, 1.3260; ... 6.5880, 2.9740, 5.5520, 2.0260]; xCentered = [ 9.4000e-02, 7.2000e-02, -6.2000e-02, -4.6000e-02; ... -1.0600e-01, -4.2800e-01, -6.2000e-02, -4.6000e-02; ... -3.0600e-01, -2.2800e-01, -1.6200e-01, -4.6000e-02]; assert_equal (class (CMdl), "CompactClassificationDiscriminant"); assert_equal ({CMdl.DiscrimType, CMdl.ResponseName}, {'linear', 'Y'}) assert_equal ({CMdl.Gamma, CMdl.MinGamma}, {0, 0}, 1e-15) assert_equal (CMdl.ClassNames, unique (species)) assert_equal (CMdl.Sigma, sigma, 1e-6) assert_equal (CMdl.Mu, mu, 1e-14) assert_equal (CMdl.LogDetSigma, -9.9585, 1e-4) assert_equal (CMdl.PredictorNames, PredictorNames) ***** test load fisheriris x = meas; y = species; Mdl = fitcdiscr (x, y, 'Gamma', 0.5); CMdl = compact (Mdl); sigma = [0.265008, 0.046361, 0.083757, 0.019201; ... 0.046361, 0.115388, 0.027622, 0.016355; ... 0.083757, 0.027622, 0.185188, 0.021333; ... 0.019201, 0.016355, 0.021333, 0.041882]; mu = [5.0060, 3.4280, 1.4620, 0.2460; ... 5.9360, 2.7700, 4.2600, 1.3260; ... 6.5880, 2.9740, 5.5520, 2.0260]; xCentered = [ 9.4000e-02, 7.2000e-02, -6.2000e-02, -4.6000e-02; ... -1.0600e-01, -4.2800e-01, -6.2000e-02, -4.6000e-02; ... -3.0600e-01, -2.2800e-01, -1.6200e-01, -4.6000e-02]; assert_equal (class (CMdl), "CompactClassificationDiscriminant"); assert_equal ({CMdl.DiscrimType, CMdl.ResponseName}, {'linear', 'Y'}) assert_equal ({CMdl.Gamma, CMdl.MinGamma}, {0.5, 0}) assert_equal (CMdl.ClassNames, unique (species)) assert_equal (CMdl.Sigma, sigma, 1e-6) assert_equal (CMdl.Mu, mu, 1e-14) assert_equal (CMdl.LogDetSigma, -8.6884, 1e-4) ***** test load fisheriris Mdl = compact (fitcdiscr (meas, species)); assert_equal (nLinearCoeffs (Mdl), 4); ***** test load fisheriris Mdl = compact (fitcdiscr (meas, species)); dps = sort (Mdl.DeltaPredictor); assert_equal (nLinearCoeffs (Mdl, dps), [4; 3; 2; 1]); ***** test load fisheriris Mdl = compact (fitcdiscr (meas, species)); assert_equal (nLinearCoeffs (Mdl, [0, 1e6]), [4; 0]); assert_equal (size (nLinearCoeffs (Mdl, [0, 1, 2])), [3, 1]); ***** test load fisheriris Mdl = compact (fitcdiscr (meas, species, "DiscrimType", "quadratic")); assert_equal (nLinearCoeffs (Mdl), 4); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Cc = compact (fitcdiscr (Xch, Ych)); rand ("state", 1); randn ("state", 1); Cs = compact (fitcdiscr (Xch, Ycell)); assert_equal (cellstr (Cc.ClassNames), Cs.ClassNames); assert_equal (cellstr (predict (Cc, Xch)), predict (Cs, Xch)); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Cc = compact (fitcdiscr (Xch, Ych)); rand ("state", 1); randn ("state", 1); Cs = compact (fitcdiscr (Xch, Ycell)); assert_equal (loss (Cc, Xch, Ych), loss (Cs, Xch, Ycell), 1e-12); ***** test load fisheriris X = meas(51:150, 1:2); ys = species(51:150); yc = categorical (ys); C = compact (fitcdiscr (X, yc)); assert_equal (loss (C, X, ys), 0.25, 1e-15); assert_equal (loss (C, X, yc), 0.25, 1e-15); L = loss (C, X, string (ys), 'LossFun', 'classiferror'); assert_equal (L, 0.25, 1e-15); assert_equal (margin (C, X, yc), margin (C, X, ys), 1e-15); ***** error ... load fisheriris nLinearCoeffs (compact (fitcdiscr (meas, species)), "a") ***** error ... CompactClassificationDiscriminant (1) ***** test load fisheriris x = meas; y = species; Mdl = fitcdiscr (meas, species, 'Gamma', 0.5); CMdl = compact (Mdl); [label, score, cost] = predict (CMdl, [2, 2, 2, 2]); assert_equal (label, {'versicolor'}) assert_equal (score, [0, 0.9999, 0.0001], 1e-4) assert_equal (cost, [1, 0.0001, 0.9999], 1e-4) [label, score, cost] = predict (CMdl, [2.5, 2.5, 2.5, 2.5]); assert_equal (label, {'versicolor'}) assert_equal (score, [0, 0.6368, 0.3632], 1e-4) assert_equal (cost, [1, 0.3632, 0.6368], 1e-4) ***** test load fisheriris x = meas; y = species; xc = [min(x); mean(x); max(x)]; Mdl = fitcdiscr (x, y); CMdl = compact (Mdl); [label, score, cost] = predict (CMdl, xc); l = {'setosa'; 'versicolor'; 'virginica'}; s = [1, 0, 0; 0, 1, 0; 0, 0, 1]; c = [0, 1, 1; 1, 0, 1; 1, 1, 0]; assert_equal (label, l) assert_equal (score, s, 1e-4) assert_equal (cost, c, 1e-4) ***** shared MODEL X = rand (10,2); Y = [ones(5,1);2*ones(5,1)]; MODEL = compact (ClassificationDiscriminant (X, Y)); ***** error ... predict (MODEL) ***** error ... predict (MODEL, []) ***** error ... predict (MODEL, 1) ***** test load fisheriris model = fitcdiscr (meas, species); x = mean (meas); y = {'versicolor'}; L = loss (model, x, y); assert_equal (L, 0) ***** test x = [1, 2; 3, 4; 5, 6]; y = {'A'; 'B'; 'A'}; model = fitcdiscr (x, y, 'Gamma', 0.4); x_test = [1, 6; 3, 3]; y_test = {'A'; 'B'}; L = loss (model, x_test, y_test); assert_equal (L, 0.3333, 1e-4) ***** test x = [1, 2; 3, 4; 5, 6; 7, 8]; y = ['1'; '2'; '3'; '1']; model = fitcdiscr (x, y, 'gamma' , 0.5); x_test = [3, 3]; y_test = ['1']; L = loss (model, x_test, y_test, 'LossFun', 'quadratic'); assert_equal (L, 0.2423, 1e-4) ***** test x = [1, 2; 3, 4; 5, 6; 7, 8]; y = ['1'; '2'; '3'; '1']; model = fitcdiscr (x, y, 'gamma' , 0.5); x_test = [3, 3; 5, 7]; y_test = ['1'; '2']; L = loss (model, x_test, y_test, 'LossFun', 'classifcost'); assert_equal (L, 0.3333, 1e-4) ***** test x = [1, 2; 3, 4; 5, 6; 7, 8]; y = ['1'; '2'; '3'; '1']; model = fitcdiscr (x, y, 'gamma' , 0.5); x_test = [3, 3; 5, 7]; y_test = ['1'; '2']; L = loss (model, x_test, y_test, 'LossFun', 'hinge'); assert_equal (L, 0.5886, 1e-4) ***** test x = [1, 2; 3, 4; 5, 6; 7, 8]; y = ['1'; '2'; '3'; '1']; model = fitcdiscr (x, y, 'gamma' , 0.5); x_test = [3, 3; 5, 7]; y_test = ['1'; '2']; W = [1; 2]; L = loss (model, x_test, y_test, 'LossFun', 'logit', 'Weights', W); assert_equal (L, 0.5107, 1e-4) ***** test x = [1, 2; 3, 4; 5, 6]; y = {'A'; 'B'; 'A'}; model = fitcdiscr (x, y, 'gamma' , 0.5); x_with_nan = [1, 2; NaN, 4]; y_test = {'A'; 'B'}; L = loss (model, x_with_nan, y_test); assert_equal (L, 0.3333, 1e-4) ***** test x = [1, 2; 3, 4; 5, 6]; y = {'A'; 'B'; 'A'}; model = fitcdiscr (x, y); x_with_nan = [1, 2; NaN, 4]; y_test = {'A'; 'B'}; L = loss (model, x_with_nan, y_test, 'LossFun', 'logit'); assert_equal (isnan (L), true) ***** test x = [1, 2; 3, 4; 5, 6]; y = {'A'; 'B'; 'A'}; model = fitcdiscr (x, y); customLossFun = @(C, S, W, Cost) sum (W .* sum (abs (C - S), 2)); L = loss (model, x, y, 'LossFun', customLossFun); assert_equal (L, 0.8889, 1e-4) ***** test x = [1, 2; 3, 4; 5, 6]; y = [1; 2; 1]; model = fitcdiscr (x, y); L = loss (model, x, y, 'LossFun', 'classiferror'); assert_equal (L, 0.3333, 1e-4) ***** error ... loss (MODEL) ***** error ... loss (MODEL, ones (4,2)) ***** error ... loss (MODEL, ones (4,2), ones (4,1), 'LossFun') ***** error ... loss (MODEL, ones (4,2), ones (4,1), 'Bogus', 1) ***** error ... loss (MODEL, ones (4,2), ones (3,1)) ***** error ... loss (MODEL, ones (4,2), ones (4,1), 'LossFun', 'a') ***** error ... loss (MODEL, ones (4,2), ones (4,1), 'Weights', 'w') ***** error ... loss (MODEL, ones (4,2), ones (4,1), 'Weights', ones (2, 2)) load fisheriris mdl = fitcdiscr (meas, species); X = mean (meas); Y = {'versicolor'}; m = margin (mdl, X, Y); assert_equal (m, 1, 1e-6) ***** test X = [1, 2; 3, 4; 5, 6]; Y = [1; 2; 1]; mdl = fitcdiscr (X, Y, 'gamma', 0.5); m = margin (mdl, X, Y); assert_equal (m, [0.3333; -0.3333; 0.3333], 1e-4) ***** error ... margin (MODEL) ***** error ... margin (MODEL, ones (4,2)) ***** error ... margin (MODEL, ones (4,2), ones (3,1)) ***** error ... savemodel (CompactClassificationDiscriminant ()) ***** error ... savemodel (CompactClassificationDiscriminant (), 1) ***** error ... savemodel (CompactClassificationDiscriminant (), ['ab'; 'cd']) ***** test load fisheriris CMdl = compact (fitcdiscr (meas, species)); CMdl.ScoreTransform = 'symmetric'; assert_equal (class (CMdl.ScoreTransform), 'char'); assert_equal (CMdl.ScoreTransform, 'symmetric'); ***** test load fisheriris CMdl = compact (fitcdiscr (meas, species)); CMdl.Prior = [2, 3, 5]; assert_equal (CMdl.Prior, [0.2, 0.3, 0.5], 1e-14); CMdl.Cost = [0, 2, 3; 1, 0, 1; 1, 1, 0]; assert_equal (CMdl.Cost, [0, 2, 3; 1, 0, 1; 1, 1, 0]); ***** test load fisheriris Mdl = compact (fitcdiscr (meas, species)); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2), 'CompactClassificationDiscriminant'); assert_equal (M2.PredictorNames, Mdl.PredictorNames); assert_equal (class (M2.ScoreTransform), class (Mdl.ScoreTransform)); assert_equal (predict (M2, meas(1:5,:)), predict (Mdl, meas(1:5,:))); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'quadratic'); CMdl = compact (Mdl); assert_equal (CMdl.DiscrimType, 'quadratic'); assert_equal (size (CMdl.Sigma), [4, 4, 3]); assert_equal (predict (CMdl, meas), predict (Mdl, meas)); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'diagQuadratic'); CMdl = compact (Mdl); assert_equal (size (CMdl.Sigma), [1, 4, 3]); assert_equal (predict (CMdl, meas), predict (Mdl, meas)); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'pseudoLinear'); CMdl = compact (Mdl); assert_equal (CMdl.LogDetSigma, -9.9585, 1e-4); assert_equal (predict (CMdl, meas), predict (Mdl, meas)); ***** test load fisheriris CMdl = compact (fitcdiscr (meas, species, 'DiscrimType', 'quadratic')); CMdl.DiscrimType = 'diagQuadratic'; assert_equal (size (CMdl.Sigma), [1, 4, 3]); assert_equal (CMdl.Gamma, 1); ***** test load fisheriris CMdl = compact (fitcdiscr (meas, species)); CMdl.Gamma = 1; assert_equal (CMdl.DiscrimType, 'diagLinear'); assert_equal (size (CMdl.Sigma), [1, 4]); ***** test load fisheriris Mdl = fitcdiscr (meas, species, 'DiscrimType', 'diagQuadratic'); CMdl = compact (Mdl); fname = tempname (); savemodel (CMdl, fname); C2 = loadmodel (fname); delete (fname); assert_equal (predict (C2, meas), predict (CMdl, meas)); C2.DiscrimType = 'quadratic'; assert_equal (size (C2.Sigma), [4, 4, 3]); ***** error ... load fisheriris; ... CMdl = compact (fitcdiscr (meas, species, 'DiscrimType', 'quadratic')); ... CMdl.DiscrimType = 'linear'; ***** error ... load fisheriris; ... CMdl = compact (fitcdiscr (meas, species, 'DiscrimType', 'quadratic')); ... CMdl.Gamma = 0.5; ***** error ... load fisheriris; ... CMdl = compact (fitcdiscr (meas, species, 'DiscrimType', 'quadratic')); ... CMdl.Delta = 0.5; ***** error ... load fisheriris; ... CMdl = compact (fitcdiscr (meas, species)); CMdl.Delta = -1; ***** test load fisheriris CMdl = compact (fitcdiscr (meas, species)); assert_equal (edge (CMdl, meas, species), 0.9454289377, 1e-9); assert_equal (edge (CMdl, meas, species), ... mean (margin (CMdl, meas, species)), 1e-12); ***** test load fisheriris CMdl = compact (fitcdiscr (meas, species)); assert_equal (edge (CMdl, meas, species, 'Weights', (1:150)'), ... 0.9438468986, 1e-9); ***** error ... load fisheriris; edge (compact (fitcdiscr (meas, species)), meas) ***** test load fisheriris CMdl = compact (fitcdiscr (meas, species)); assert_equal (CMdl.CategoricalPredictors, []); assert_equal (CMdl.ExpandedPredictorNames, CMdl.PredictorNames); assert_equal (size (CMdl.ExpandedPredictorNames), [1, 4]); ***** test load fisheriris CMdl = compact (fitcdiscr (meas, species)); fname = tempname (); savemodel (CMdl, fname); C2 = loadmodel (fname); delete (fname); assert_equal (C2.CategoricalPredictors, CMdl.CategoricalPredictors); assert_equal (C2.ExpandedPredictorNames, CMdl.ExpandedPredictorNames); ***** test load fisheriris Mdl = fitcdiscr (meas, species); CMdl = compact (Mdl); assert_equal (CMdl.BetweenSigma, Mdl.BetweenSigma); assert_equal (CMdl.BetweenSigma(1,1), 0.632121333333333, 1e-12); ***** test load fisheriris CMdl = compact (fitcdiscr (meas, species)); fname = tempname (); savemodel (CMdl, fname); C2 = loadmodel (fname); delete (fname); assert_equal (C2.BetweenSigma, CMdl.BetweenSigma); ***** error ... load fisheriris CMdl = compact (fitcdiscr (meas, species)); CMdl.Cost = 1:9; ***** test load fisheriris Mdl = compact (fitcdiscr (meas, species)); M = mahal (Mdl, meas(1:5,:)); assert_equal (size (M), [5, 3]); assert_equal (M(1,:), [0.2910898404344, 98.8847494279393, ... 191.788642179719], 1e-10); assert_equal (M(5,:), [0.5956300391717, 100.923170228959, ... 193.854037009331], 1e-10); ***** test load fisheriris Mdl = compact (fitcdiscr (meas, species)); M = mahal (Mdl, meas(1:5,:), 'ClassLabels', species(1:5)); assert_equal (size (M), [5, 1]); assert_equal (M, [0.291089840434356; 2.031345104042097; ... 0.553281423559203; 2.086697905677364; ... 0.595630039171744], 1e-12); ***** test load fisheriris idx = [1; 51; 101]; D = diag (mahal (compact (fitcdiscr (meas, species)), meas(idx,:))); Mdl = compact (fitcdiscr (meas, categorical (species))); assert_equal (mahal (Mdl, meas(idx,:), 'ClassLabels', species(idx)), D); assert_equal (mahal (Mdl, meas(idx,:), 'ClassLabels', ... categorical (species(idx))), D); assert_equal (mahal (Mdl, meas(idx,:), 'ClassLabels', ... string (species(idx))), D); assert_equal (mahal (Mdl, meas(idx,:), 'ClassLabels', ... char (species(idx))), D); ***** test load fisheriris idx = [1; 51; 101]; D = diag (mahal (compact (fitcdiscr (meas, species)), meas(idx,:))); Mdl = compact (fitcdiscr (meas, species)); assert_equal (mahal (Mdl, meas(idx,:), 'ClassLabels', ... categorical (species(idx))), D); assert_equal (mahal (Mdl, meas(idx,:), 'ClassLabels', ... string (species(idx))), D); ***** test load fisheriris idx = [1; 51; 101]; Mdl = compact (fitcdiscr (meas, grp2idx (species))); D = diag (mahal (Mdl, meas(idx,:))); assert_equal (mahal (Mdl, meas(idx,:), 'ClassLabels', [1; 2; 3]), D); ***** test load fisheriris Mdl = compact (fitcdiscr (meas, species, 'DiscrimType', 'quadratic')); M = mahal (Mdl, meas(1:5,:)); assert_equal (M(1,:), [0.4491137892273, 114.804489260461, ... 182.935908699285], 1e-10); ***** test load fisheriris Mdl = compact (fitcdiscr (meas, species, 'Gamma', 0.5)); M = mahal (Mdl, meas(1:5,:)); assert_equal (M(1,:), [0.1926136709121, 79.4757202663154, ... 163.294484902038], 1e-10); ***** test load fisheriris M1 = mahal (compact (fitcdiscr (meas, species)), meas(1:5,:)); Mdl = compact (fitcdiscr (meas, species, 'Prior', [0.6, 0.2, 0.2])); assert_equal (mahal (Mdl, meas(1:5,:)), M1, 1e-12); ***** test load fisheriris Mdl = compact (fitcdiscr (meas, species)); lp = logp (Mdl, meas(1:5,:)); assert_equal (size (lp), [5, 1]); assert_equal (lp, [0.059358043320009; -0.810769588483861; ... -0.071737748242414; -0.838445989301495; ... -0.092912056048684], 1e-12); ***** test load fisheriris Mdl = compact (fitcdiscr (meas, species, 'DiscrimType', 'quadratic')); lp = logp (Mdl, meas(1:5,:)); assert_equal (lp, [1.534756847193468; 0.718766664165731; ... 1.117146185488189; 0.906210252665867; ... 1.378471050607217], 1e-12); ***** test load fisheriris Mdl = compact (fitcdiscr (meas, species, 'Prior', [0.6, 0.2, 0.2])); lp = logp (Mdl, meas(1:5,:)); assert_equal (lp, [0.647144708222129; -0.222982923581741; ... 0.516048916659706; -0.250659324399375; ... 0.494874608853435], 1e-12); ***** error ... load fisheriris Mdl = compact (fitcdiscr (meas, species)); mahal (Mdl, []) ***** error ... load fisheriris Mdl = compact (fitcdiscr (meas, species)); mahal (Mdl, ones (3, 2)) ***** error ... load fisheriris Mdl = compact (fitcdiscr (meas, species)); mahal (Mdl, {1, 2, 3, 4}) ***** error ... load fisheriris Mdl = compact (fitcdiscr (meas, species)); mahal (Mdl, meas(1:5,:), 'ClassLabels') ***** error ... load fisheriris Mdl = compact (fitcdiscr (meas, species)); mahal (Mdl, meas(1:5,:), 5, 1) ***** error ... load fisheriris Mdl = compact (fitcdiscr (meas, species)); mahal (Mdl, meas(1:5,:), 'bogus', 1) ***** error ... load fisheriris Mdl = compact (fitcdiscr (meas, species)); mahal (Mdl, meas(1:2,:), 'ClassLabels', {1; 2}) ***** error ... load fisheriris Mdl = compact (fitcdiscr (meas, species)); mahal (Mdl, meas(1:5,:), 'ClassLabels', species(1:3)) ***** error ... load fisheriris Mdl = compact (fitcdiscr (meas, species)); mahal (Mdl, meas(1:2,:), 'ClassLabels', {'setosa'; 'nosuchspecies'}) ***** error ... load fisheriris Mdl = compact (fitcdiscr (meas, species)); logp (Mdl, []) ***** error ... load fisheriris Mdl = compact (fitcdiscr (meas, species)); logp (Mdl, ones (3, 2)) ***** error ... load fisheriris Mdl = compact (fitcdiscr (meas, species)); logp (Mdl, {1, 2, 3, 4}) ***** test load fisheriris Mdl = compact (fitcdiscr (meas, species)); S = struct ('ClassNames', {{'virginica'; 'setosa'; 'versicolor'}}, ... 'ClassificationCosts', [0, 1, 2; 3, 0, 4; 5, 6, 0]); Mdl.Cost = S; assert_equal (Mdl.Cost, [0, 4, 3; 6, 0, 5; 1, 2, 0]); ***** error ... load fisheriris Mdl = compact (fitcdiscr (meas, species)); Mdl.Cost = ones (3); ***** test load fisheriris Mdl = compact (fitcdiscr (meas, species)); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); T = {'identity', @(x) x; 'doublelogit', @(x) 1 ./ (1 + exp (-2 * x)); ... 'invlogit', @(x) log (x ./ (1 - x)); ... 'logit', @(x) 1 ./ (1 + exp (-x)); ... 'sign', @(x) sign (x); 'symmetric', @(x) 2 * x - 1; ... 'symmetriclogit', @(x) 2 ./ (1 + exp (-x)) - 1}; for i = 1:rows (T) Mdl.ScoreTransform = T{i,1}; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, T{i,2}(raw), 1e-12); assert_equal (l, label); endfor ## ismax marks the largest score of each observation, ties to the first. [~, k] = max (raw, [], 2); e = zeros (size (raw)); e(sub2ind (size (raw), (1:rows (raw))', k)) = 1; Mdl.ScoreTransform = 'ismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, e); Mdl.ScoreTransform = 'symmetricismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, 2 * e - 1); ***** test load fisheriris Mdl = compact (fitcdiscr (meas, species)); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); Mdl.ScoreTransform = @(x) x .^ 2; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, raw .^ 2, 1e-12); assert_equal (l, label); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcdiscr (T, 'Species')); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcdiscr (T, 'Species')); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcdiscr (T, 'Species')); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** test # a table is matched to the predictors by name load fisheriris T = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = categorical (species); Mdl = compact (fitcdiscr (T, 'Species')); a = mahal (Mdl, meas); assert_equal (mahal (Mdl, T(:,1:4)), a); assert_equal (mahal (Mdl, T(:,[5, 4, 2, 3, 1])), a); ***** test # a table is matched to the predictors by name load fisheriris T = table (meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'SL', 'SW', 'PL', 'PW'}); T.Species = categorical (species); Mdl = compact (fitcdiscr (T, 'Species')); a = logp (Mdl, meas); assert_equal (logp (Mdl, T(:,1:4)), a); assert_equal (logp (Mdl, T(:,[5, 4, 2, 3, 1])), a); 94 tests, 94 passed, 0 known failure, 0 skipped [inst/Machine_Learning/ClassificationLinear.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/ClassificationLinear.m ***** demo ## Separate the two overlapping iris species with a linear classifier and ## read the posterior probability it gives each observation. load fisheriris X = meas(51:end,:); Y = species(51:end); Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic') [label, score] = predict (Mdl, X([1, 51],:)) ***** demo ## One object can hold a whole regularization path. A stronger penalty ## shrinks the coefficients, and every method reports one column per ## strength. load fisheriris X = meas(51:end,:); Y = species(51:end); Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]); Mdl.Beta loss (Mdl, X, Y) ***** test ## The model reports the surface MATLAB reports load fisheriris X = meas(51:end,:); Y = species(51:end); Mdl = ClassificationLinear (X, Y); assert_equal (class (Mdl), 'ClassificationLinear'); assert_equal (Mdl.ClassNames, {'versicolor'; 'virginica'}); assert_equal (Mdl.Learner, 'svm'); assert_equal (Mdl.FittedLoss, 'hinge'); assert_equal (Mdl.Regularization, 'ridge (L2)'); assert_equal (Mdl.ScoreTransform, 'none'); assert_equal (Mdl.ResponseName, 'Y'); assert_equal (Mdl.PredictorNames, {'x1', 'x2', 'x3', 'x4'}); assert_equal (Mdl.ExpandedPredictorNames, {'x1', 'x2', 'x3', 'x4'}); assert_equal (Mdl.CategoricalPredictors, []); assert_equal (Mdl.Prior, [0.5, 0.5]); assert_equal (Mdl.Cost, [0, 1; 1, 0]); assert_equal (Mdl.Lambda, 0.01); assert_equal (size (Mdl.Beta), [4, 1]); ***** test ## The properties are the ones MATLAB lists, in its order load fisheriris Mdl = ClassificationLinear (meas(51:end,:), species(51:end)); assert_equal (sort (properties (Mdl)), ... sort ({'ClassNames'; 'Prior'; 'Cost'; 'ScoreTransform'; ... 'PredictorNames'; 'CategoricalPredictors'; ... 'ResponseName'; 'ExpandedPredictorNames'; ... 'Learner'; 'Beta'; 'Bias'; 'FittedLoss'; 'Lambda'; ... 'ModelParameters'; 'Regularization'})); ***** test ## A logistic ridge fit reproduces R2024a's coefficients load fisheriris Mdl = ClassificationLinear (meas(51:end,:), species(51:end), ... 'Learner', 'logistic', 'Solver', 'lbfgs', ... 'BetaTolerance', 0, 'GradientTolerance', ... 1e-12, ... 'IterationLimit', 20000); assert_equal (Mdl.Beta, [-0.394433478724131; -0.513277404049627; ... 2.9307513837558; 2.41703218835114], 1e-7); assert_equal (Mdl.Bias, -14.4307581801051, 1e-7); assert_equal (Mdl.FittedLoss, 'logit'); assert_equal (Mdl.ScoreTransform, 'logit'); ***** test ## The default score transform follows the learner, and only the logistic ## one turns the scores into posterior probabilities load fisheriris X = meas(51:end,:); Ml = ClassificationLinear (X, species(51:end), 'Learner', 'logistic'); Ms = ClassificationLinear (X, species(51:end), 'Learner', 'svm'); assert_equal (Ml.ScoreTransform, 'logit'); assert_equal (Ms.ScoreTransform, 'none'); [~, sl] = predict (Ml, X(1:5,:)); [~, ss] = predict (Ms, X(1:5,:)); assert_equal (sum (sl, 2), ones (5, 1), 1e-12); assert_equal (ss(:,1), -ss(:,2), 1e-12); ***** test ## The scores of a logistic fit are R2024a's posteriors load fisheriris X = meas(51:end,:); Mdl = ClassificationLinear (X, species(51:end), 'Learner', 'logistic', ... 'Solver', 'lbfgs', 'BetaTolerance', 0, ... 'GradientTolerance', 1e-12, ... 'IterationLimit', 20000); [label, score] = predict (Mdl, X(1:2,:)); assert_equal (label, {'versicolor'; 'versicolor'}); assert_equal (score, [0.842361345526662, 0.157638654473338; ... 0.856151985655854, 0.143848014344146], 1e-7); ***** test ## margin is the true class score less the other, and edge their weighted ## mean. Both halves are asserted: the values against R2024a, and the ## relationship against the scores this model actually reports. The ## values alone would not catch a margin computed consistently wrongly, ## since a wrong-but-stable margin agrees with its own past output ## forever; the relationship alone would not catch our agreeing with ## ourselves about the wrong quantity. load fisheriris X = meas(51:end,:); Y = species(51:end); Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic', ... 'Solver', 'lbfgs', 'BetaTolerance', 0, ... 'GradientTolerance', 1e-12, ... 'IterationLimit', 20000); assert_equal (margin (Mdl, X(1,:), Y(1)), 0.684722691053324, 1e-7); assert_equal (edge (Mdl, X, Y), 0.726067240395032, 1e-7); ## the invariant, independent of any solver output [~, score] = predict (Mdl, X); virg = strcmp (Y, 'virginica'); strue = score(:,1); strue(virg) = score(virg,2); sother = score(:,2); sother(virg) = score(virg,1); assert_equal (margin (Mdl, X, Y), strue - sother, 1e-15); assert_equal (edge (Mdl, X, Y), mean (margin (Mdl, X, Y)), 1e-15); ***** test # MATLAB parity: edge on a set holding one class load fisheriris X = meas(51:end,:); Y = species(51:end); Mdl = ClassificationLinear (X, Y); assert_equal (edge (Mdl, X(1:50,:), Y(1:50)), 3.3451311639, 1e-10); ***** test ## Every loss reproduces R2024a, and each is a function of the score the ## model gives the true class rather than of the margin load fisheriris X = meas(51:end,:); Y = species(51:end); Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic', ... 'Solver', 'lbfgs', 'BetaTolerance', 0, ... 'GradientTolerance', 1e-12, ... 'IterationLimit', 20000); assert_equal (loss (Mdl, X, Y), 0.04, 1e-12); assert_equal (loss (Mdl, X, Y, 'LossFun', 'hinge'), ... 0.136966379802484, 1e-7); assert_equal (loss (Mdl, X, Y, 'LossFun', 'logit'), ... 0.354333320227268, 1e-7); assert_equal (loss (Mdl, X, Y, 'LossFun', 'binodeviance'), ... 0.170050306584128, 1e-7); assert_equal (loss (Mdl, X, Y, 'LossFun', 'exponential'), ... 0.426899191073676, 1e-7); assert_equal (loss (Mdl, X, Y, 'LossFun', 'quadratic'), ... 0.040701761220091, 1e-7); ***** test ## Under the default cost both cost based losses reduce to the error ## rate: the class of least expected cost is then the class of largest ## score, which is what predict returns load fisheriris X = meas(51:end,:); Y = species(51:end); Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic'); assert_equal (loss (Mdl, X, Y, 'LossFun', 'classifcost'), ... loss (Mdl, X, Y), 1e-12); assert_equal (loss (Mdl, X, Y, 'LossFun', 'mincost'), ... loss (Mdl, X, Y), 1e-12); ***** test ## A cost that is not symmetric moves the least cost assignment away from ## the largest score, so the two cost based losses part company load fisheriris X = meas(51:end,:); Y = species(51:end); Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic', ... 'Cost', [0, 2; 3, 0]); assert_equal (loss (Mdl, X, Y, 'LossFun', 'classifcost') > 0, true); assert_equal (loss (Mdl, X, Y, 'LossFun', 'mincost') > 0, true); ***** test ## A cost matrix reaches the fit through the prior, which is what MATLAB ## does: a fit costing four times as much to miss the first class equals ## one given the prior that scaling implies load fisheriris X = meas(51:end,:); Y = species(51:end); Mc = ClassificationLinear (X, Y, 'Cost', [0, 4; 1, 0]); Mp = ClassificationLinear (X, Y, 'Prior', [0.8, 0.2]); assert_equal (Mc.Beta, Mp.Beta, 1e-12); assert_equal (Mc.Bias, Mp.Bias, 1e-12); assert_equal (Mc.Prior, [0.5, 0.5]); ***** test ## Lambda defaults to the reciprocal of the observations that were used load fisheriris Mdl = ClassificationLinear (meas(51:end,:), species(51:end)); assert_equal (Mdl.Lambda, 1 / 100, 1e-15); ***** test ## A vector of strengths fits one model per value, sorted ascending, and ## every method reports one column per value load fisheriris X = meas(51:end,:); Y = species(51:end); Mdl = ClassificationLinear (X, Y, 'Lambda', [0.1, 0.001, 0.01]); assert_equal (Mdl.Lambda, [0.001, 0.01, 0.1]); assert_equal (size (Mdl.Beta), [4, 3]); assert_equal (size (Mdl.Bias), [1, 3]); [label, score] = predict (Mdl, X(1:4,:)); assert_equal (size (label), [4, 3]); assert_equal (size (score), [4, 2, 3]); assert_equal (size (margin (Mdl, X, Y)), [100, 3]); assert_equal (size (edge (Mdl, X, Y)), [1, 3]); assert_equal (size (loss (Mdl, X, Y)), [1, 3]); ***** test ## A stronger penalty shrinks the coefficients load fisheriris Mdl = ClassificationLinear (meas(51:end,:), species(51:end), ... 'Learner', 'logistic', 'Lambda', [0.001, 1]); assert_equal (norm (Mdl.Beta(:,1)) > norm (Mdl.Beta(:,2)), true); ***** test ## selectModels keeps the strengths it is given and drops the rest load fisheriris Mdl = ClassificationLinear (meas(51:end,:), species(51:end), ... 'Lambda', [0.001, 0.01, 0.1]); sub = selectModels (Mdl, [1, 3]); assert_equal (sub.Lambda, [0.001, 0.1]); assert_equal (size (sub.Beta), [4, 2]); assert_equal (sub.Beta, Mdl.Beta(:,[1, 3])); sub = selectModels (Mdl, logical ([0, 1, 0])); assert_equal (sub.Lambda, 0.01); ***** test ## A lasso penalty drives coefficients to exactly zero, which a ridge ## penalty never does load fisheriris X = meas(51:end,:); Y = species(51:end); Ml = ClassificationLinear (X, Y, 'Learner', 'logistic', ... 'Regularization', 'lasso', 'Lambda', 0.05); Mr = ClassificationLinear (X, Y, 'Learner', 'logistic', ... 'Regularization', 'ridge', 'Lambda', 0.05); assert_equal (Ml.Regularization, 'lasso (L1)'); assert_equal (sum (Ml.Beta == 0) > 0, true); assert_equal (any (Mr.Beta == 0), false); ***** test ## The default solver follows the penalty and the width of the data load fisheriris X = meas(51:end,:); Y = species(51:end); [~, F] = fitclinear (X, Y); assert_equal (F.Solver, {'bfgs'}); [~, F] = fitclinear (X, Y, 'Regularization', 'lasso'); assert_equal (F.Solver, {'sparsa'}); ***** test ## FitBias false leaves the intercept at zero load fisheriris Mdl = ClassificationLinear (meas(51:end,:), species(51:end), ... 'FitBias', false); assert_equal (Mdl.Bias, 0); ***** test ## Observations may be given down the columns instead load fisheriris X = meas(51:end,:); Y = species(51:end); Mr = ClassificationLinear (X, Y, 'Learner', 'logistic'); Mc = ClassificationLinear (X', Y, 'Learner', 'logistic', ... 'ObservationsIn', 'columns'); assert_equal (Mr.Beta, Mc.Beta, 1e-12); ***** test ## A row with a missing predictor or a missing response is dropped, and ## Lambda follows the count that survived load fisheriris X = meas(51:end,:); Y = species(51:end); X(3,2) = NaN; Mdl = ClassificationLinear (X, Y); assert_equal (Mdl.Lambda, 1 / 99, 1e-15); ***** test ## ScoreTransform is settable and reaches predict load fisheriris X = meas(51:end,:); Mdl = ClassificationLinear (X, species(51:end)); Mdl.ScoreTransform = 'logit'; assert_equal (Mdl.ScoreTransform, 'logit'); [~, score] = predict (Mdl, X(1:3,:)); assert_equal (sum (score, 2), ones (3, 1), 1e-12); ***** test ## A saved model reads back as the same model load fisheriris X = meas(51:end,:); Mdl = ClassificationLinear (X, species(51:end), 'Learner', 'logistic'); fname = tempname (); savemodel (Mdl, fname); Mnew = loadmodel (fname); delete (fname); assert_equal (class (Mnew), 'ClassificationLinear'); assert_equal (Mnew.Beta, Mdl.Beta); assert_equal (Mnew.Bias, Mdl.Bias); assert_equal (predict (Mnew, X(1:5,:)), predict (Mdl, X(1:5,:))); ***** test ## The labels come back in the type the response was given in, a ## character matrix included: its rows name the classes, and indexing it ## by element rather than by row would flatten it into single characters load fisheriris X = meas(51:end,:); Y = species(51:end); Mcell = ClassificationLinear (X, Y); assert_equal (class (predict (Mcell, X(1:3,:))), 'cell'); Mchar = ClassificationLinear (X, char (Y)); assert_equal (size (Mchar.ClassNames), [2, 10]); assert_equal (size (predict (Mchar, X(1:3,:))), [3, 10]); assert_equal (loss (Mchar, X, char (Y)), loss (Mcell, X, Y), 1e-12); Ynum = double (strcmp (Y, 'virginica')); Mnum = ClassificationLinear (X, Ynum); assert_equal (class (predict (Mnum, X(1:3,:))), 'double'); assert_equal (Mnum.ClassNames, [0; 1]); Mlog = ClassificationLinear (X, logical (Ynum)); assert_equal (class (predict (Mlog, X(1:3,:))), 'logical'); ***** test ## Observation weights reach the fit, and the prior follows them. Both ## numbers are R2024a's for the weights 1 to 100. load fisheriris X = meas(51:end,:); Y = species(51:end); Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic', ... 'Solver', 'lbfgs', 'Weights', (1:100)', ... 'BetaTolerance', 0, ... 'GradientTolerance', 1e-12, ... 'IterationLimit', 20000); assert_equal (Mdl.Prior, [0.252475247524752, 0.747524752475248], 1e-12); assert_equal (Mdl.Beta, [-0.0907861095243143; -0.344147850956068; ... 2.73449884653132; 2.20876095012392], 1e-7); assert_equal (Mdl.Bias, -14.6291356484861, 1e-6); assert_equal (Mdl.FitInfo_.Objective, 0.208158687811647, 1e-10); ***** test ## A character matrix response names one class per row, and a model ## fitted from one is the model fitted from the equivalent cell array. ## The check is worth its length: a linear index into a character matrix ## flattens the names into single characters, and so does an ismember ## between two character matrices, and neither shows up at the property ## that is usually looked at. load fisheriris X = meas(51:end,:); Yc = species(51:end); Ym = char (Yc); Mc = ClassificationLinear (X, Yc, 'Learner', 'logistic'); Mm = ClassificationLinear (X, Ym, 'Learner', 'logistic'); assert_equal (cellstr (Mm.ClassNames), Mc.ClassNames); assert_equal (Mm.Prior, Mc.Prior); assert_equal (Mm.Beta, Mc.Beta); assert_equal (Mm.Bias, Mc.Bias); ***** test ## Every method answers the same through a character matrix response as ## through the cell array it came from load fisheriris X = meas(51:end,:); Yc = species(51:end); Ym = char (Yc); Mc = ClassificationLinear (X, Yc, 'Learner', 'logistic'); Mm = ClassificationLinear (X, Ym, 'Learner', 'logistic'); assert_equal (cellstr (predict (Mm, X)), predict (Mc, X)); assert_equal (margin (Mm, X, Ym), margin (Mc, X, Yc)); assert_equal (edge (Mm, X, Ym), edge (Mc, X, Yc)); assert_equal (edge (Mm, X, Ym, 'Weights', (1:100)'), ... edge (Mc, X, Yc, 'Weights', (1:100)')); assert_equal (loss (Mm, X, Ym), loss (Mc, X, Yc)); assert_equal (loss (Mm, X, Ym, 'LossFun', 'hinge'), ... loss (Mc, X, Yc, 'LossFun', 'hinge')); assert_equal (loss (Mm, X, Ym, 'LossFun', 'mincost'), ... loss (Mc, X, Yc, 'LossFun', 'mincost')); ***** test ## 'ClassNames' selects a subset when it is given as a character matrix ## too, which needs both sides of the comparison turned into names load fisheriris Mcell = ClassificationLinear (meas, species, ... 'ClassNames', {'versicolor', 'virginica'}); Mchar = ClassificationLinear (meas, char (species), 'ClassNames', ... char ({'versicolor', 'virginica'})); assert_equal (cellstr (Mchar.ClassNames), Mcell.ClassNames); assert_equal (Mchar.Beta, Mcell.Beta); assert_equal (Mchar.Lambda, Mcell.Lambda); ***** test ## Names of unequal length are padded by the character matrix and the ## padding is not part of the name load fisheriris X = meas(51:end,:); Y = [repmat({'ab'}, 50, 1); repmat({'abcd'}, 50, 1)]; Mcell = ClassificationLinear (X, Y); Mchar = ClassificationLinear (X, char (Y)); assert_equal (cellstr (Mchar.ClassNames), Mcell.ClassNames); assert_equal (cellstr (predict (Mchar, X)), predict (Mcell, X)); ***** test # MATLAB parity: 'bfgs' keeps the full inverse Hessian load fisheriris [Mdl, FI] = fitclinear (meas(51:end,:), species(51:end), ... 'Learner', 'logistic', 'Lambda', 1e-10, ... 'Solver', 'bfgs'); assert_equal (FI.NumIterations, 71); assert_equal (FI.TerminationCode, 1); assert_equal (Mdl.Beta', [-2.465354655400692, -6.680676306572678, ... 9.429341643431608, 18.2859364726242], 1e-9); assert_equal (Mdl.Bias, -42.6370704726009, 1e-9); ***** test # MATLAB parity: 'lbfgs' keeps fifteen curvature pairs load fisheriris [Mdl, FI] = fitclinear (meas(51:end,:), species(51:end), ... 'Learner', 'logistic', 'Lambda', 1e-10, ... 'Solver', 'lbfgs'); assert_equal (FI.NumIterations, 40); assert_equal (FI.TerminationCode, 1); assert_equal (Mdl.Beta', [-2.465511460111347, -6.67942802197831, ... 9.429867603796366, 18.28403561808411], 1e-9); assert_equal (Mdl.Bias, -42.6390545166892, 1e-9); ***** test # MATLAB parity: the first step of 'bfgs' starts from a unit one load fisheriris [Mdl, FI] = fitclinear (100 * meas(51:end,:), species(51:end), ... 'Learner', 'logistic', 'Lambda', 1e-10, ... 'Solver', 'bfgs'); assert_equal (FI.NumIterations, 46); assert_equal (Mdl.Beta', [-0.06327372376455137, -0.06618088890242214, ... 0.0843323334344509, 0.1028323453382017], 1e-12); ***** test # MATLAB parity: 'sparsa' stops on the gradient with BetaTolerance 0 load fisheriris [~, FI] = fitclinear (meas(51:end,:), species(51:end), ... 'Learner', 'logistic', 'Lambda', 1e-10, ... 'Regularization', 'lasso', 'Solver', 'sparsa', ... 'BetaTolerance', 0); assert_equal (FI.TerminationCode, 2); assert_equal (FI.TerminationStatus, {'Tolerance on gradient satisfied.'}); assert_equal (FI.RelativeChangeInBeta, NaN); ***** test ## MATLAB parity: with both tolerances at zero neither tolerance test can ## fire, so the fit ends either by the line search failing to improve or by ## the iteration limit, whichever the platform's arithmetic reaches first. ## R2024a reports the first; that is not reproducible across toolchains, so ## only the tolerance codes are ruled out here. load fisheriris [~, FI] = fitclinear (meas(51:end,:), species(51:end), ... 'Learner', 'logistic', 'Lambda', 1e-10, ... 'Regularization', 'lasso', 'Solver', 'sparsa', ... 'BetaTolerance', 0, 'GradientTolerance', 0); assert_equal (any (FI.TerminationCode == [-11, 0]), true); ***** test ## The default fit stops on the coefficients, as MATLAB's does, which is ## only true once the engine offers BetaTolerance. Before it did, this ## fit ran on to the gradient tolerance and reported NaN here. load fisheriris Mdl = ClassificationLinear (meas(51:end,:), species(51:end), ... 'Learner', 'logistic'); assert_equal (Mdl.FitInfo_.BetaTolerance, 1e-4); assert_equal (Mdl.FitInfo_.TerminationCode, 1); assert_equal (Mdl.FitInfo_.TerminationStatus, ... {'Tolerance on coefficients satisfied.'}); assert_equal (isfinite (Mdl.FitInfo_.RelativeChangeInBeta), true); ***** test ## A line search that cannot improve the objective says so, rather than ## reporting the iteration limit it never reached. Code and wording ## measured on R2024a. Where the search gives up varies by platform, so ## the count is only asserted to be short of the limit. load fisheriris Mdl = ClassificationLinear (meas(51:end,:), species(51:end), ... 'Learner', 'logistic', 'Lambda', 1e-10, ... 'BetaTolerance', 0, 'GradientTolerance', 0); assert_equal (Mdl.FitInfo_.TerminationCode, -11); assert_equal (Mdl.FitInfo_.TerminationStatus, ... {'Unable to find a step decreasing the objective.'}); S = Mdl.fitInfo_ (); assert_equal (S.NumIterations < S.IterationLimit, true); ***** test ## A tolerance of exactly zero switches its test off and the quantity it ## governs comes back NaN, which is what MATLAB reports. Not "never ## satisfied": not computed. load fisheriris Mdl = ClassificationLinear (meas(51:end,:), species(51:end), ... 'BetaTolerance', 0, 'GradientTolerance', 1e-8); assert_equal (isnan (Mdl.FitInfo_.RelativeChangeInBeta), true); Mdl = ClassificationLinear (meas(51:end,:), species(51:end), ... 'GradientTolerance', 0); assert_equal (isnan (Mdl.FitInfo_.GradientNorm), true); assert_equal (Mdl.FitInfo_.GradientTolerance, 0); ***** test ## A character matrix response survives a round trip through savemodel ## and loadmodel, names and all load fisheriris X = meas(51:end,:); Ym = char (species(51:end)); Mdl = ClassificationLinear (X, Ym, 'Learner', 'logistic'); fname = tempname (); savemodel (Mdl, fname); Mnew = loadmodel (fname); delete (fname); assert_equal (Mnew.ClassNames, Mdl.ClassNames); assert_equal (size (Mnew.ClassNames), [2, 10]); assert_equal (predict (Mnew, X(1:5,:)), predict (Mdl, X(1:5,:))); assert_equal (loss (Mnew, X, Ym), loss (Mdl, X, Ym), 1e-12); ***** test ## ModelParameters reports every option but gives a value only to the ## ones the chosen solver can act on, which is MATLAB's behaviour and was ## measured one fit per solver on R2024a. Two of these are easy to get ## wrong: HessianHistorySize is empty for 'bfgs' and 15 for 'lbfgs', a ## full quasi-Newton method having no limited memory to size, and the two ## solvers that run no gradient test report a tolerance of zero. load fisheriris X = meas(51:end,:); Y = species(51:end); b = ClassificationLinear (X, Y, 'Solver', 'bfgs').ModelParameters; assert_equal (numel (fieldnames (b)), 28); assert_equal (b.HessianHistorySize, []); assert_equal (b.BatchSize, []); assert_equal (b.PassLimit, []); assert_equal (b.IterationLimit, 1000); assert_equal (b.LineSearch, 'weakwolfe'); l = ClassificationLinear (X, Y, 'Solver', 'lbfgs').ModelParameters; assert_equal (l.HessianHistorySize, 15); g = ClassificationLinear (X, Y, 'Solver', 'sgd').ModelParameters; assert_equal (g.BatchSize, 10); assert_equal (g.IterationLimit, []); assert_equal (g.GradientTolerance, 0); assert_equal (g.LineSearch, []); d = ClassificationLinear (X, Y, 'Solver', 'dual').ModelParameters; assert_equal (isempty (d.DeltaGradientTolerance), false); assert_equal (d.PassLimit, 10); assert_equal (d.HessianHistorySize, []); assert_equal (d.GradientTolerance, 0); ***** test ## The default learning rate is MATLAB's own formula, the reciprocal root ## of one plus the largest squared observation norm. R2024a reports ## 0.0896365435911655 on this fixture. load fisheriris X = meas(51:end,:); Mdl = ClassificationLinear (X, species(51:end), 'Solver', 'sgd'); assert_equal (Mdl.ModelParameters.LearnRate, ... 1 / sqrt (1 + max (sum (X .^ 2, 2))), 1e-15); assert_equal (Mdl.ModelParameters.LearnRate, 0.0896365435911655, 1e-12); ***** test ## The dual solver's two defaults, measured on R2024a and confirmed on ## R2026a through MATLAB Online. Both differ from what MathWorks ## documents, and the first differs between the two learners: the ## complementarity tolerance is 1 for a hinge loss and 0.1 for an ## epsilon-insensitive one, which is the 0.1 the documentation quotes. load fisheriris Mdl = ClassificationLinear (meas(51:end,:), species(51:end), ... 'Solver', 'dual'); assert_equal (Mdl.ModelParameters.DeltaGradientTolerance, 1); assert_equal (Mdl.ModelParameters.NumCheckConvergence, 2); assert_equal (Mdl.ModelParameters.PassLimit, 10); ***** test # An unused category of a categorical response is not a class load fisheriris y = categorical (species); Mdl = ClassificationLinear (meas(51:150,:), y(51:150)); assert_equal (cellstr (Mdl.ClassNames), {'versicolor'; 'virginica'}); ***** test # A row missing a predictor takes the class of largest prior X = [(1:10)', mod((1:10)', 3)]; y = [1; 1; 1; 1; 1; 1; 2; 2; 2; 2]; Mdl = ClassificationLinear (X, y); [label, score] = predict (Mdl, [NaN, 1]); assert_equal (label, 1); assert_equal (score, [NaN, NaN]); Mdl = ClassificationLinear (X, y, 'Prior', [0.3, 0.7]); assert_equal (predict (Mdl, [NaN, 1]), 2); ***** error ... ClassificationLinear (ones (5, 2)) ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Learner') ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Learner', ... 'tree') ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'Regularization', 'elastic') ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Lambda', -1) ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Solver', ... 'newton') ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'FitBias', ... 'yes') ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'ObservationsIn', 'pages') ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'BetaTolerance', -1) ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'IterationLimit', 2.5) ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Verbose', 3) ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Nonsense', 1) ***** error ... ClassificationLinear ({1, 2; 3, 4}, [1; 2]) ***** error ClassificationLinear ([], []) ***** error ... ClassificationLinear (ones (10, 2), [1; 2]) ***** error ... ClassificationLinear (ones (9, 2), [1; 1; 1; 2; 2; 2; 3; 3; 3]) ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Prior', ... [0.2, 0.3, 0.5]) ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Cost', ... ones (3)) ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'Regularization', 'ridge', 'Solver', 'sparsa') ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'Regularization', 'lasso', 'Solver', 'lbfgs') ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Learner', ... 'logistic', 'Solver', 'dual') ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], ... 'PredictorNames', {'a', 'b', 'c'}) ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Beta', ... ones (3, 1)) ***** error ... ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Bias', [1, 2]) ***** error ... predict (ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)])) ***** error ... predict (ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)]), []) ***** error ... predict (ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)]), ... ones (3, 5)) ***** error ... margin (ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)]), ... ones (3, 2)) ***** error ... loss (ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)]), ... ones (10, 2), [ones(5,1); 2*ones(5,1)], 'LossFun', 'mse') ***** error ... loss (ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)]), ... ones (10, 2), [ones(5,1); 2*ones(5,1)], 'Nonsense', 1) ***** error ... loss (ClassificationLinear (ones (10, 2), [ones(5,1); 2*ones(5,1)]), ... ones (10, 2), 3*ones (10, 1)) ***** error ... selectModels (ClassificationLinear (ones (10, 2), ... [ones(5,1); 2*ones(5,1)], 'Lambda', [0.1, 0.2, 0.3]), 5) ***** error ... selectModels (ClassificationLinear (ones (10, 2), ... [ones(5,1); 2*ones(5,1)], 'Lambda', [0.1, 0.2, ... 0.3]), logical ([1, 0])) ***** error ... predict (ClassificationLinear (ones (10, 2), ... ['a';'a';'a';'a';'a';'b';'b';'b';'b';'b'], 'Lambda', ... [0.1, 0.2]), ones (3, 2)) ***** test load fisheriris Mdl = fitclinear (meas, strcmp (species, 'setosa')); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); T = {'identity', @(x) x; 'doublelogit', @(x) 1 ./ (1 + exp (-2 * x)); ... 'invlogit', @(x) log (x ./ (1 - x)); ... 'logit', @(x) 1 ./ (1 + exp (-x)); ... 'sign', @(x) sign (x); 'symmetric', @(x) 2 * x - 1; ... 'symmetriclogit', @(x) 2 ./ (1 + exp (-x)) - 1}; for i = 1:rows (T) Mdl.ScoreTransform = T{i,1}; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, T{i,2}(raw), 1e-12); assert_equal (l, label); endfor ## ismax marks the largest score of each observation, ties to the first. [~, k] = max (raw, [], 2); e = zeros (size (raw)); e(sub2ind (size (raw), (1:rows (raw))', k)) = 1; Mdl.ScoreTransform = 'ismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, e); Mdl.ScoreTransform = 'symmetricismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, 2 * e - 1); ***** test load fisheriris Mdl = fitclinear (meas, strcmp (species, 'setosa')); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); Mdl.ScoreTransform = @(x) x .^ 2; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, raw .^ 2, 1e-12); assert_equal (l, label); ***** shared Xc, Dc, yc c1 = repmat ([1; 2; 3], 20, 1); x2 = sin ((1:60)'); c3 = repmat ([10; 10; 20; 20], 15, 1); Xc = [c1, x2, c3]; Dc = [c1 == 1, c1 == 2, c1 == 3, x2, c3 == 10, c3 == 20]; yc = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 20) + 0.1 * cos ((1:60)') > 1; ***** test # MATLAB parity: a categorical predictor is dummy coded in its place Mdl = ClassificationLinear (Xc, yc, 'CategoricalPredictors', [1, 3]); assert_equal (Mdl.CategoricalPredictors, [1, 3]); assert_equal (Mdl.ExpandedPredictorNames, {'x1 == 1', 'x1 == 2', ... 'x1 == 3', 'x2', 'x3 == 10', 'x3 == 20'}); assert_equal (size (Mdl.Beta), [6, 1]); H = ClassificationLinear (Dc, yc); assert_equal (Mdl.Beta, H.Beta, 1e-12); [~, s] = predict (Mdl, Xc(1:5,:)); [~, sh] = predict (H, Dc(1:5,:)); assert_equal (s, sh, 1e-12); ***** test # a logical vector names the categorical predictors too Mdl = ClassificationLinear (Xc, yc, 'CategoricalPredictors', ... logical ([1, 0, 1])); assert_equal (Mdl.CategoricalPredictors, [1, 3]); ***** test # a level the training data did not hold is scored NaN Mdl = ClassificationLinear (Xc, yc, 'CategoricalPredictors', [1, 3]); [~, s] = predict (Mdl, [4, 0, 10; 2.5, 0, 20; NaN, 0, 10; 2, 0, 20]); assert_equal (isnan (s(:,1))', [true, true, true, false]); ***** error ... ClassificationLinear (Xc, yc, 'CategoricalPredictors', 4) ***** error ... ClassificationLinear (Xc, yc, 'CategoricalPredictors', logical ([1, 0])) ***** error ... ClassificationLinear (Xc, yc, 'CategoricalPredictors', 0) ***** test # the classes may be named as a categorical, as the other learners take load fisheriris inds = ! strcmp (species, 'setosa'); Mdl = ClassificationLinear (meas(inds,:), categorical (species(inds)), ... 'ClassNames', ... categorical ({'versicolor', 'virginica'})); assert_equal (class (Mdl.ClassNames), 'categorical'); ***** test # or as a string array load fisheriris inds = ! strcmp (species, 'setosa'); Mdl = ClassificationLinear (meas(inds,:), string (species(inds)), ... 'ClassNames', ... string ({'versicolor', 'virginica'})); assert_equal (numel (Mdl.ClassNames), 2); ***** test load fisheriris inds = ! strcmp (species, 'setosa'); CVMdl = fitclinear (meas(inds,:), categorical (species(inds)), ... 'KFold', 3); assert_equal (class (CVMdl), 'ClassificationPartitionedLinear'); assert_equal (CVMdl.KFold, 3); ***** error ... ClassificationLinear ([1, 2; 3, 4], [1; 2], 'ClassNames', {1, 2}) ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(51:150,1:2); y = categorical (species(51:150)); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitclinear (T, 'Species'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(51:150,1:2); y = categorical (species(51:150)); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitclinear (T, 'Species'); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(51:150,1:2); y = categorical (species(51:150)); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = fitclinear (T, 'Species'); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** error ... fitclinear ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', ... int8 ([1; 1; 1; 1])) ***** error ... fitclinear ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', true (4, 1)) ***** error X = [1, 2; 3, 4; 5, 6; 7, 8]; Y = [1; 1; 2; 2]; loss (fitclinear (X, Y), X, Y, 'Weights', int8 ([1; 1; 1; 1])) ***** test ## Single weights compute as double load fisheriris X = meas(51:end,:); Y = species(51:end); w = 1 + (1:100)' / 7; A = fitclinear (X, Y, 'Weights', single (w)); B = fitclinear (X, Y, 'Weights', double (single (w))); assert_equal (nthargout (2, @predict, A, X), nthargout (2, @predict, B, X)); 95 tests, 95 passed, 0 known failure, 0 skipped [inst/Machine_Learning/PredictiveModel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/PredictiveModel.m ***** test # the class is abstract and cannot be instantiated fail ('PredictiveModel ()', 'abstract'); ***** test # a model that predicts derives from it, a cross-validated one does not load fisheriris Mdl = fitctree (meas, species); assert_equal (isa (Mdl, 'PredictiveModel'), true); assert_equal (isa (compact (Mdl), 'PredictiveModel'), true); assert_equal (isa (crossval (Mdl, 'KFold', 2), 'PredictiveModel'), false); ***** test # a model fitted by fitlm derives from it too, across directories X = [1, 2; 2, 3; 3, 4; 1, 5; 2, 6; 3, 7]; y = [2.5; 3.1; 4.8; 2.2; 3.9; 5.1]; assert_equal (isa (fitlm (X, y), 'PredictiveModel'), true); ***** test # no subclass may sit in a directory sorting before this class's own base = fileparts (which ('PredictiveModel')); root = fileparts (base); here = base(numel (root) + 2:end); d = dir (root); subs = {d([d.isdir]).name}; subs = subs(! ismember (subs, {'.', '..', here})); for k = 1:numel (subs) f = dir (fullfile (root, subs{k}, '*.m')); for j = 1:numel (f) src = fileread (fullfile (root, subs{k}, f(j).name)); pat = '^classdef[^\n]*<[^\n]*PredictiveModel'; if (! isempty (regexp (src, pat, 'once', 'lineanchors'))) order = sort ({here, subs{k}}); assert_equal (order{1}, here); endif endfor endfor 4 tests, 4 passed, 0 known failure, 0 skipped [inst/Machine_Learning/RegressionSVM.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/RegressionSVM.m ***** test X = [linspace(0, 1, 40)', linspace(2, 3, 40)']; Y = 2 * X(:,1) + 0.5; Mdl = RegressionSVM (X, Y); assert_equal (class (Mdl), 'RegressionSVM'); assert_equal (Mdl.ModelParameters.KernelFunction, 'linear'); assert_equal (Mdl.ModelParameters.SVMtype, 'eps_svr'); assert_equal (Mdl.ModelParameters.BoxConstraint, 1); assert_equal (Mdl.ModelParameters.KernelScale, 1); assert_equal (isempty (Mdl.ModelParameters.KernelPolynomialOrder), true); assert_equal (isempty (Mdl.Mu), true); assert_equal (Mdl.NumObservations, 40); assert_equal (Mdl.NumPredictors, 2); assert_equal (Mdl.ResponseName, 'Y'); assert_equal (Mdl.PredictorNames, {'x1', 'x2'}); ***** test randn ('seed', 42); X = randn (60, 2); Y = X(:,1) * 3 + randn (60, 1); Mdl = RegressionSVM (X, Y); assert_equal (Mdl.Epsilon, iqr (Y) / 13.49, 1e-12); M2 = RegressionSVM (X, Y, 'Epsilon', 0.25); assert_equal (M2.Epsilon, 0.25); ***** test X = [linspace(0, 1, 20)', linspace(1, 2, 20)']; Mdl = RegressionSVM (X, ones (20, 1)); assert_equal (Mdl.Epsilon, 0.1); ***** test randn ('seed', 42); X = randn (50, 3); Y = X * [2; -1; 0.5] + 1; Mdl = RegressionSVM (X, Y); assert_equal (size (Mdl.Beta), [3, 1]); assert_equal (isscalar (Mdl.Bias), true); assert_equal (X * Mdl.Beta + Mdl.Bias, resubPredict (Mdl), 1e-8); assert_equal (Mdl.Beta, Mdl.SupportVectors' * Mdl.Alpha, 1e-12); ***** test randn ('seed', 42); X = randn (40, 2); Y = sum (X .^ 2, 2); Mdl = RegressionSVM (X, Y, 'KernelFunction', 'rbf'); assert_equal (isempty (Mdl.Beta), true); assert_equal (numel (resubPredict (Mdl)), 40); ***** test randn ('seed', 42); X = randn (60, 2); Y = X(:,1) - X(:,2) + randn (60, 1) * 0.5; Mdl = RegressionSVM (X, Y); nsv = rows (Mdl.SupportVectors); assert_equal (size (Mdl.Alpha), [nsv, 1]); assert_equal (any (Mdl.Alpha < 0), true); assert_equal (class (Mdl.IsSupportVector), 'logical'); assert_equal (numel (Mdl.IsSupportVector), 60); assert_equal (sum (Mdl.IsSupportVector), nsv); ***** test randn ('seed', 42); X = randn (60, 2); Y = X(:,1) * 2 + randn (60, 1); narrow = RegressionSVM (X, Y, 'Epsilon', 0.05); wide = RegressionSVM (X, Y, 'Epsilon', 3); assert_equal (sum (wide.IsSupportVector) < ... sum (narrow.IsSupportVector), true); ***** test randn ('seed', 42); X = [randn(60, 1), randn(60, 1) * 1000]; Y = X(:,1) + X(:,2) / 1000; Mdl = RegressionSVM (X, Y, 'Standardize', true, 'Epsilon', 0.01); assert_equal (size (Mdl.Mu), [1, 2]); assert_equal (size (Mdl.Sigma), [1, 2]); assert_equal (predict (Mdl, X), resubPredict (Mdl)); assert_equal (sqrt (resubLoss (Mdl)) < std (Y), true); ***** test X = [linspace(0, 1, 20)', ones(20, 1)]; Mdl = RegressionSVM (X, X(:,1), 'Standardize', true); assert_equal (Mdl.Sigma(2), 1); assert_equal (all (isfinite (resubPredict (Mdl))), true); ***** test X = [linspace(0, 1, 12)', linspace(1, 2, 12)'; NaN, 1; 0.5, 1]; Y = [2 * linspace(0, 1, 12)'; 1; NaN]; Mdl = RegressionSVM (X, Y); assert_equal (Mdl.NumObservations, 13); assert_equal (sum (Mdl.RowsUsed), 13); assert_equal (Mdl.RowsUsed(13:14), [true; false]); assert_equal (numel (resubPredict (Mdl)), 13); ***** test randn ('seed', 42); X = randn (40, 2); Y = X(:,1) + 2 * X(:,2); Mdl = RegressionSVM (X, Y); assert_equal (predict (Mdl, X), resubPredict (Mdl)); ***** test randn ('seed', 42); X = randn (30, 2); Y = X(:,1) * 3 + 1; Mdl = RegressionSVM (X, Y); yFit = predict (Mdl, X); assert_equal (loss (Mdl, X, Y), mean ((Y - yFit) .^ 2), 1e-12); assert_equal (loss (Mdl, X, Y, 'LossFun', 'mse'), loss (Mdl, X, Y), 1e-12); w = rand (30, 1) + 0.1; assert_equal (loss (Mdl, X, Y, 'Weights', w), ... loss (Mdl, X, Y, 'Weights', 7 * w), 1e-12); assert_equal (loss (Mdl, X, Y, 'Weights', w), ... sum ((w / sum (w)) .* (Y - yFit) .^ 2), 1e-12); ***** test randn ('seed', 42); X = randn (30, 2); Y = X(:,1) * 3 + 1; Mdl = RegressionSVM (X, Y, 'Epsilon', 0.5); yFit = predict (Mdl, X); L = loss (Mdl, X, Y, 'LossFun', 'epsiloninsensitive'); assert_equal (L, mean (max (0, abs (Y - yFit) - 0.5)), 1e-12); assert_equal (L <= loss (Mdl, X, Y, 'LossFun', 'mse') + 1, true); assert_equal (L >= 0, true); ***** test randn ('seed', 42); X = randn (20, 2); Y = X(:,1) + 1; Mdl = RegressionSVM (X, Y); f = @(y, yf, w) sum (w .* abs (y - yf)); assert_equal (loss (Mdl, X, Y, 'LossFun', f), ... mean (abs (Y - predict (Mdl, X))), 1e-12); ***** test randn ('seed', 42); X = randn (21, 2); Y = [randn(20, 1); NaN]; Mdl = RegressionSVM (X, Y); Xu = X(Mdl.RowsUsed, :); Yu = Y(Mdl.RowsUsed); assert_equal (resubLoss (Mdl), loss (Mdl, Xu, Yu), 1e-12); assert_equal (resubLoss (Mdl, 'LossFun', 'epsiloninsensitive'), ... loss (Mdl, Xu, Yu, 'LossFun', 'epsiloninsensitive'), 1e-12); ***** test X = [linspace(0, 1, 20)', linspace(1, 2, 20)']; Y = 2 * X(:,1) + 1; Mdl = RegressionSVM (X, Y); raw = predict (Mdl, X); Mdl.ResponseTransform = 'exp'; assert_equal (predict (Mdl, X), exp (raw), 1e-12); Mdl.ResponseTransform = @(y) 2 * y; assert_equal (predict (Mdl, X), 2 * raw, 1e-12); Mdl.ResponseTransform = 'none'; assert_equal (predict (Mdl, X), raw, 1e-12); ***** test randn ('seed', 42); X = randn (50, 2); Y = X(:,1) - X(:,2); Mdl = RegressionSVM (X, Y, 'SVMtype', 'nu_svr', 'Nu', 0.3); assert_equal (Mdl.ModelParameters.SVMtype, 'nu_svr'); assert_equal (Mdl.ModelParameters.Nu, 0.3); assert_equal (Mdl.Model.Parameters(1), 4); assert_equal (all (isfinite (resubPredict (Mdl))), true); ***** test randn ('seed', 42); X = randn (40, 2); Y = X(:,1) + X(:,2); names = {'linear', 'rbf', 'gaussian', 'polynomial', 'sigmoid'}; for k = 1:numel (names) Mdl = RegressionSVM (X, Y, 'KernelFunction', names{k}); assert_equal (all (isfinite (resubPredict (Mdl))), true); endfor ***** test randn ('seed', 42); X = randn (30, 2); Y = X(:,1) * 4 - 1; Mdl = RegressionSVM (X, Y, 'Standardize', true); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2), 'RegressionSVM'); assert_equal (M2.Alpha, Mdl.Alpha); assert_equal (M2.Beta, Mdl.Beta); assert_equal (M2.Bias, Mdl.Bias); assert_equal (M2.Epsilon, Mdl.Epsilon); assert_equal (M2.SupportVectors, Mdl.SupportVectors); assert_equal (M2.NumObservations, Mdl.NumObservations); assert_equal (predict (M2, X), predict (Mdl, X)); ***** test randn ('seed', 42); X = randn (40, 2); Y = X(:,1) - X(:,2); Mdl = RegressionSVM (X, Y); CMdl = compact (Mdl); assert_equal (class (CMdl), 'CompactRegressionSVM'); assert_equal (predict (CMdl, X), predict (Mdl, X)); assert_equal (loss (CMdl, X, Y), loss (Mdl, X, Y)); ***** test rand ('seed', 42); randn ('seed', 42); X = randn (30, 2); Y = X(:,1) - X(:,2); Mdl = fitrsvm (X, Y); CVMdl = crossval (Mdl, 'KFold', 3); assert_equal (class (CVMdl), 'RegressionPartitionedModel'); assert_equal (CVMdl.KFold, 3); assert_equal (CVMdl.CrossValidatedModel, 'SVM'); assert_equal (numel (kfoldPredict (CVMdl)), 30); assert_equal (isfinite (kfoldLoss (CVMdl)), true); ***** test load fisheriris keep = ! strcmp (species, "setosa"); X = meas(keep,2:4); y = meas(keep,1); Mdl = fitrsvm (X, y, "KernelFunction", "linear"); D = discardSupportVectors (Mdl); assert_equal (class (D), "RegressionSVM"); assert_equal (isempty (D.Alpha), true); assert_equal (isempty (D.SupportVectors), true); assert_equal (D.Beta, Mdl.Beta); assert_equal (D.Bias, Mdl.Bias); assert_equal (D.IsSupportVector, Mdl.IsSupportVector); ***** test load fisheriris keep = ! strcmp (species, "setosa"); X = meas(keep,2:4); y = meas(keep,1); Mdl = fitrsvm (X, y, "KernelFunction", "linear"); D = discardSupportVectors (Mdl); assert_equal (predict (D, X), predict (Mdl, X), 1e-10); ***** test load fisheriris keep = ! strcmp (species, "setosa"); X = meas(keep,2:4); y = meas(keep,1); Mdl = fitrsvm (X, y, "KernelFunction", "linear"); D = discardSupportVectors (Mdl); assert_equal (rows (Mdl.Model.SVs) > 1, true); assert_equal (rows (D.Model.SVs), 1); assert_equal (predict (discardSupportVectors (D), X), predict (D, X)); ***** test # A row missing a predictor predicts the lower median of the response X = [(1:10)', mod((1:10)', 3)]; Mdl = RegressionSVM (X, (1:10)'); assert_equal (predict (Mdl, [NaN, 1]), 5); ***** warning ... RegressionSVM ((1:20)' * 1000, (1:20)' * 10, 'KernelFunction', 'polynomial'); ***** error ... load fisheriris keep = ! strcmp (species, "setosa"); X = meas(keep,2:4); y = meas(keep,1); discardSupportVectors (fitrsvm (X, y, "KernelFunction", "rbf")) ***** error ... crossval (fitrsvm (randn (12, 2), randn (12, 1)), 'KFold') ***** error ... crossval (fitrsvm (randn (12, 2), randn (12, 1)), ... 'KFold', 3, 'Leaveout', 'on') ***** error ... crossval (fitrsvm (randn (12, 2), randn (12, 1)), 'KFold', 1) ***** error ... crossval (fitrsvm (randn (12, 2), randn (12, 1)), 'Holdout', 1) ***** error ... crossval (fitrsvm (randn (12, 2), randn (12, 1)), 'Leaveout', 1) ***** error ... crossval (fitrsvm (randn (12, 2), randn (12, 1)), 'CVPartition', 1) ***** error ... crossval (fitrsvm (randn (12, 2), randn (12, 1)), 'Nope', 1) ***** error ... RegressionSVM () ***** error ... RegressionSVM (ones (10, 2)) ***** error ... RegressionSVM (ones (10, 2), ones (5, 1)) ***** error ... RegressionSVM (ones (5, 2), {'a'; 'b'; 'c'; 'd'; 'e'}) ***** error ... RegressionSVM (ones (5, 2), ones (5, 3)) ***** error ... RegressionSVM ([1, 1; Inf, 1; 3, 1], [1; 2; 3]) ***** error ... RegressionSVM ([1, 1; 2, 1; 3, 1], [1; Inf; 3]) ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'Standardize', 'yes') ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'PredictorNames', 'a') ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'PredictorNames', {'a'}) ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'ResponseName', 5) ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'ResponseTransform', 5) ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'ResponseTransform', 'nope') ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'SVMtype', 5) ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'SVMtype', 'c_svc') ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'Epsilon', -1) ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'KernelFunction', 5) ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'KernelFunction', 'nope') ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'PolynomialOrder', 2.5) ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'KernelScale', 0) ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'KernelOffset', -1) ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'BoxConstraint', 0) ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'Nu', 0) ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'CacheSize', 0) ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'Tolerance', -1) ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'Shrinking', 2) ***** error ... RegressionSVM (ones (5, 2), ones (5, 1), 'Prior', 1) ***** shared RSVM RSVM = RegressionSVM ([1, 1; 2, 1; 3, 2; 4, 2], [2; 4; 6; 8]); ***** error ... predict (RSVM) ***** error ... predict (RSVM, []) ***** error ... predict (RSVM, ones (2, 3)) ***** error ... loss (RSVM) ***** error ... loss (RSVM, [1, 1; 2, 1], [2; 4], 'Weights') ***** error ... loss (RSVM, [], [2; 4]) ***** error ... loss (RSVM, ones (2, 3), [2; 4]) ***** error ... loss (RSVM, [1, 1; 2, 1], []) ***** error ... loss (RSVM, [1, 1; 2, 1], {'a'; 'b'}) ***** error ... loss (RSVM, [1, 1; 2, 1], [2; 4; 6]) ***** error ... loss (RSVM, [1, 1; 2, 1], [2; 4], 'LossFun', 5) ***** error ... loss (RSVM, [1, 1; 2, 1], [2; 4], 'LossFun', 'mae') ***** error ... loss (RSVM, [1, 1; 2, 1], [2; 4], 'LossFun', @(y, yf, w) [1, 2]) ***** error ... loss (RSVM, [1, 1; 2, 1], [2; 4], 'Weights', {'a'}) ***** error ... loss (RSVM, [1, 1; 2, 1], [2; 4], 'Weights', ones (2, 2)) ***** error ... loss (RSVM, [1, 1; 2, 1], [2; 4], 'Weights', [1; 2; 3]) ***** error ... loss (RSVM, [1, 1; 2, 1], [2; 4], 'Nope', 1) ***** error ... savemodel (RSVM) ***** error ... savemodel (RSVM, 5) ***** error ... RSVM.ResponseTransform = 'nope'; ***** test load fisheriris X = meas(:,2:4); Y = meas(:,1); Mdl = fitrsvm (X, Y); assert_equal (Mdl.RowsUsed, []); assert_equal (class (Mdl.RowsUsed), 'double'); assert_equal (Mdl.NumObservations, 150); assert_equal (rows (Mdl.X), 150); assert_equal (rows (Mdl.W), 150); ***** test load fisheriris X = meas(:,2:4); Y = meas(:,1); Y(5) = NaN; Mdl = fitrsvm (X, Y); assert_equal (class (Mdl.RowsUsed), 'logical'); assert_equal (size (Mdl.RowsUsed), [150, 1]); assert_equal (sum (Mdl.RowsUsed), 149); assert_equal (Mdl.RowsUsed(5), false); assert_equal (Mdl.NumObservations, 149); assert_equal (rows (Mdl.X), 149); assert_equal (rows (Mdl.W), 149); ***** test load fisheriris X = meas(:,2:4); X(3,2) = NaN; Y = meas(:,1); Mdl = fitrsvm (X, Y); assert_equal (Mdl.RowsUsed, []); assert_equal (Mdl.NumObservations, 150); assert_equal (rows (Mdl.X), 150); assert_equal (sum (isnan (Mdl.X(:))), 1); ***** test load fisheriris X = meas(:,2:4); X(7,2) = NaN; X(120,3) = NaN; Mdl = fitrsvm (X, meas(:,1), 'Standardize', true); assert_equal (Mdl.Mu, [3.0608108108108096, 3.7655405405405395, ... 1.203378378378378], 1e-13); assert_equal (Mdl.Sigma, [0.43214937187299296, 1.7636045663278643, ... 0.76339873235638711], 1e-13); ***** test load fisheriris X = meas(:,2:4); Y = meas(:,1); Mdl = fitrsvm (X, Y); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2), 'RegressionSVM'); assert_equal (M2.NumObservations, Mdl.NumObservations); assert_equal (M2.PredictorNames, Mdl.PredictorNames); assert_equal (class (M2.ResponseTransform), class (Mdl.ResponseTransform)); assert_equal (predict (M2, X(1:5,:)), predict (Mdl, X(1:5,:)), 1e-12); ***** test load fisheriris Mdl = fitrsvm (meas(:,1:3), meas(:,4)); assert_equal (class (Mdl.BinEdges), 'cell'); assert_equal (Mdl.BinEdges, {}); ***** test load fisheriris Mdl = fitrsvm (meas(:,1:3), meas(:,4)); assert_equal (Mdl.KernelParameters, struct ('Function', 'linear', ... 'Scale', 1)); assert_equal (Mdl.BoxConstraints, ones (150, 1)); ***** test load fisheriris Mdl = fitrsvm (meas(:,1:3), meas(:,4), 'KernelFunction', 'rbf', ... 'BoxConstraint', 2); assert_equal (Mdl.KernelParameters.Function, 'gaussian'); assert_equal (unique (Mdl.BoxConstraints), 2); ***** test load carsmall X = [Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); Mdl = fitrsvm (X(ok,:), MPG(ok), 'KernelFunction', 'gaussian'); assert_equal (Mdl.ModelParameters.BoxConstraint, 9.266123054, 1e-9); assert_equal (Mdl.BoxConstraints(2), 9.266123054, 1e-9); ***** test load carsmall X = [Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); Mdl = fitrsvm (X(ok,:), MPG(ok), 'KernelFunction', 'rbf'); assert_equal (Mdl.ModelParameters.BoxConstraint, 9.266123054, 1e-9); ***** test load carsmall X = [Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); w = (1:sum (ok))'; Mdl = fitrsvm (X(ok,:), MPG(ok), 'KernelFunction', 'gaussian', ... 'Weights', w); assert_equal (Mdl.ModelParameters.BoxConstraint, 9.266123054, 1e-9); assert_equal (Mdl.BoxConstraints(2), 0.3943031087, 1e-9); ***** test load carsmall X = [Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); Y = MPG(ok); Y(1) = 100; w = [0; (2:numel(Y))']; Mdl = fitrsvm (X(ok,:), Y, 'KernelFunction', 'gaussian', 'Weights', w); assert_equal (Mdl.ModelParameters.BoxConstraint, 9.266123054, 1e-9); ***** test load carsmall X = [Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); Mdl = fitrsvm (X(ok,:), 5 * ones (sum (ok), 1), ... 'KernelFunction', 'gaussian'); assert_equal (Mdl.ModelParameters.BoxConstraint, 1); ***** test load carsmall X = [Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); Mdl = fitrsvm (X(ok,:), MPG(ok), 'KernelFunction', 'polynomial', ... 'Standardize', true); assert_equal (Mdl.ModelParameters.BoxConstraint, 1); ***** test load fisheriris Mdl = fitrsvm (meas(:,1:3), meas(:,4), 'KernelScale', 2); assert_equal (predict (Mdl, meas([1, 75, 150], 1:3)), ... [0.222015641544; 1.35505851032; 1.83323561521], 2e-3); ***** test load fisheriris Mdl = fitrsvm (meas(:,1:3), meas(:,4), 'KernelFunction', 'gaussian', ... 'KernelScale', 2); assert_equal (predict (Mdl, meas([1, 75, 150], 1:3)), ... [0.220070671683; 1.2611886798; 1.9057640742], 3e-3); ***** test load fisheriris Mdl = fitrsvm (meas(:,1:3), meas(:,4), 'KernelScale', 2); Q = meas([1, 75, 150], 1:3); assert_equal (predict (Mdl, Q), (Q / 2) * Mdl.Beta + Mdl.Bias, 1e-12); ***** test load fisheriris Mdl = fitrsvm (meas(:,1:3), meas(:,4), 'KernelFunction', 'gaussian', ... 'KernelScale', 2); assert_equal (Mdl.SupportVectors, meas(Mdl.IsSupportVector, 1:3)); ***** test load fisheriris Mdl = fitrsvm (meas(:,1:3), meas(:,4)); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.KernelParameters, Mdl.KernelParameters); assert_equal (M2.BoxConstraints, Mdl.BoxConstraints); ***** test load fisheriris Mdl = fitrsvm (meas(:,1:3), meas(:,4)); assert_equal (isempty (Mdl.HyperparameterOptimizationResults), true); ***** test load fisheriris Mdl = fitrsvm (meas(:,2:4), meas(:,1)); assert_equal (fieldnames (Mdl.ModelParameters)', {'SVMtype', ... 'BoxConstraint', 'CacheSize', 'KernelScale', 'KernelOffset', ... 'KernelFunction', 'KernelPolynomialOrder', 'Epsilon', 'Nu', ... 'Tolerance', 'Shrinking', 'StandardizeData', 'Version', 'Method', ... 'Type'}); ***** test load fisheriris MP = fitrsvm (meas(:,2:4), meas(:,1), 'Standardize', true).ModelParameters; assert_equal (MP.StandardizeData, true); assert_equal (MP.Version, 1); assert_equal (MP.Method, 'SVM'); assert_equal (MP.Type, 'regression'); ***** test load fisheriris MP = fitrsvm (meas(:,2:4), meas(:,1)).ModelParameters; assert_equal (MP.Epsilon, 0.0963676797627873, 1e-15); assert_equal (MP.Nu, 0.5); ***** test load fisheriris Mdl = fitrsvm (meas(:,2:4), meas(:,1)); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); T = {'identity', @(x) x; 'exp', @(x) exp (x); 'log', @(x) log (x)}; for i = 1:rows (T) Mdl.ResponseTransform = T{i,1}; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, T{i,2}(raw), 1e-12); endfor ***** test load fisheriris Mdl = fitrsvm (meas(:,2:4), meas(:,1)); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); Mdl.ResponseTransform = @(x) x .^ 2; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, raw .^ 2, 1e-12); ***** shared Xc, Dc, yr, Xq, Dq k = (0:119)'; c1 = mod (k, 3) + 1; x2 = sin (k); c3 = 10 * (mod (floor (k / 2), 2) + 1); Xc = [c1, x2, c3]; Dc = [c1 == 1, c1 == 2, c1 == 3, x2, c3 == 10, c3 == 20]; yr = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 20) + 0.1 * cos (k); yc = yr > 1; Xq = [1, 0, 10; 2, 0.5, 20]; Dq = [1, 0, 0, 0, 1, 0; 0, 1, 0, 0.5, 0, 1]; ***** test # MATLAB parity: a categorical predictor is dummy coded in its place Mdl = RegressionSVM (Xc, yr, 'CategoricalPredictors', [1, 3]); H = RegressionSVM (Dc, yr); assert_equal (Mdl.CategoricalPredictors, [1, 3]); assert_equal (Mdl.ExpandedPredictorNames, {'x1 == 1', 'x1 == 2', ... 'x1 == 3', 'x2', 'x3 == 10', 'x3 == 20'}); assert_equal (Mdl.Beta, H.Beta, 1e-12); assert_equal (predict (Mdl, Xq), predict (H, Dq), 1e-12); ys = sort (yr); assert_equal (predict (Mdl, [4, 0, 10]), ys(ceil (numel (ys) / 2))); ***** test # MATLAB parity: the coded columns are not standardized Mdl = RegressionSVM (Xc, yr, 'CategoricalPredictors', [1, 3], ... 'Standardize', true); assert_equal (Mdl.Mu([1:3, 5:6]), zeros (1, 5)); assert_equal (Mdl.Sigma([1:3, 5:6]), ones (1, 5)); ***** test # the coding travels with saved models and cross-validation folds Mdl = RegressionSVM (Xc, yr, 'CategoricalPredictors', [1, 3]); fname = [tempname(), '.mdl']; savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (predict (M2, Xq), predict (Mdl, Xq)); CV = crossval (Mdl, 'KFold', 3); assert_equal (CV.Trained{1}.CategoricalPredictors, [1, 3]); ***** error ... RegressionSVM (Xc, yr, 'CategoricalPredictors', 4) ***** test # the class may be built from a table as the fitter builds it load fisheriris T = table (meas(:,2), meas(:,3), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'SL'}); Mdl = RegressionSVM (T, 'SL'); assert_equal (Mdl.PredictorNames, {'SW', 'PL'}); assert_equal (Mdl.ResponseName, 'SL'); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,2:3); y = meas(:,1); T = table (X(:,1), X(:,2), 'VariableNames', {'SW', 'PL'}); T.SL = y; Mdl = fitrsvm (T, 'SL'); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'SL'), a); assert_equal (loss (Mdl, T), a); ***** error ... RegressionSVM ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', 'Weights', int8 ([1; 1; 1; 1])) ***** error ... RegressionSVM ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', 'Weights', true (4, 1)) ***** error ... RegressionSVM ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', 'Weights', [1; 1]) ***** error ... RegressionSVM ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', 'Weights', [1; -1; 1; 1]) ***** error ... RegressionSVM ([1, 2; 3, 4; 5, 6; 7, 8], (1:4)', 'Weights', zeros (4, 1)) ***** test ## Box constraints are n * C * W, as R2024a sets them load fisheriris Mdl = RegressionSVM (meas(:,2:4), meas(:,1), 'Weights', 1 + (1:150)' / 7); assert_equal (sum (Mdl.W), 1, 1e-15); assert_equal (Mdl.BoxConstraints([1, 150]), ... [0.09696969696969696; 1.903030303030303], 1e-15); ***** test ## Single weights are stored single, summing to one load fisheriris Mdl = RegressionSVM (meas(:,2:4), meas(:,1), ... 'Weights', single (1 + (1:150)' / 7)); assert_equal (class (Mdl.W), 'single'); assert_equal (class (Mdl.BoxConstraints), 'double'); assert_equal (sum (double (Mdl.W)), 1, 1e-6); ***** test ## Rows of zero weight are left out, as R2024a leaves them load fisheriris w = 1 + (1:150)' / 7; w(5) = 0; Mdl = RegressionSVM (meas(:,2:4), meas(:,1), 'Weights', w); assert_equal (Mdl.NumObservations, 149); assert_equal (Mdl.RowsUsed(5), false); ***** test ## Standardization weighs the observations, as R2024a does load fisheriris Mdl = RegressionSVM (meas(:,2:4), meas(:,1), 'Standardize', true, ... 'Weights', 1 + (1:150)' / 7); assert_equal (Mdl.Mu, [2.965608080808081, 4.573050505050505, ... 1.55819797979798], 1e-14); assert_equal (Mdl.Sigma, [0.3809861139391035, 1.433169957562235, ... 0.6470320013330532], 1e-14); ***** test ## A row missing a predictor is predicted as the weighted lower median load fisheriris X = meas(:,2:4); X(7,2) = NaN; Mdl = RegressionSVM (X, meas(:,1), 'Weights', 1 + (1:150)' / 7); assert_equal (predict (Mdl, [NaN, 1, 1]), 6.2); assert_equal (isnan (Mdl.BoxConstraints(7)), true); assert_equal (Mdl.IsSupportVector(7), false); assert_equal (sum (Mdl.IsSupportVector), rows (Mdl.SupportVectors)); ***** test ## resubLoss weighs the observations by W unless given weights load fisheriris w = 1 + (1:150)' / 7; Mdl = RegressionSVM (meas(:,2:4), meas(:,1), 'Weights', w); assert_equal (resubLoss (Mdl), ... loss (Mdl, meas(:,2:4), meas(:,1), 'Weights', w), 1e-15); 123 tests, 123 passed, 0 known failure, 0 skipped [inst/Machine_Learning/CompactRegressionSVM.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/CompactRegressionSVM.m ***** test randn ('seed', 42); X = randn (50, 2); Y = X(:,1) - 2 * X(:,2); CMdl = compact (RegressionSVM (X, Y)); assert_equal (class (CMdl), 'CompactRegressionSVM'); kept = {'NumPredictors', 'PredictorNames', 'ResponseName', ... 'ResponseTransform', 'Epsilon', 'Sigma', 'Mu', ... 'Alpha', 'Beta', 'Bias', 'SupportVectors', ... 'CategoricalPredictors', 'ExpandedPredictorNames'}; assert_equal (all (ismember (kept, properties (CMdl))), true); dropped = {'X', 'Y', 'W', 'NumObservations', 'RowsUsed', ... 'IsSupportVector'}; assert_equal (any (ismember (dropped, properties (CMdl))), false); ***** test randn ('seed', 42); X = randn (60, 3); Y = X * [1; -2; 0.5] + 3; Mdl = RegressionSVM (X, Y); CMdl = compact (Mdl); assert_equal (predict (CMdl, X), predict (Mdl, X)); assert_equal (loss (CMdl, X, Y), loss (Mdl, X, Y)); assert_equal (loss (CMdl, X, Y), resubLoss (Mdl), 1e-12); assert_equal (CMdl.Alpha, Mdl.Alpha); assert_equal (CMdl.Beta, Mdl.Beta); assert_equal (CMdl.Bias, Mdl.Bias); assert_equal (CMdl.SupportVectors, Mdl.SupportVectors); assert_equal (CMdl.Epsilon, Mdl.Epsilon); ***** test randn ('seed', 42); X = randn (40, 2); Y = X * [3; -1] + 2; CMdl = compact (RegressionSVM (X, Y)); assert_equal (X * CMdl.Beta + CMdl.Bias, predict (CMdl, X), 1e-8); assert_equal (CMdl.Beta, CMdl.SupportVectors' * CMdl.Alpha, 1e-12); ***** test randn ('seed', 42); X = [randn(60, 1), randn(60, 1) * 1000]; Y = X(:,1) + X(:,2) / 1000; Mdl = RegressionSVM (X, Y, 'Standardize', true, 'Epsilon', 0.01); CMdl = compact (Mdl); assert_equal (CMdl.Mu, Mdl.Mu); assert_equal (CMdl.Sigma, Mdl.Sigma); assert_equal (predict (CMdl, X), predict (Mdl, X)); ***** test randn ('seed', 42); X = randn (40, 2); Y = sum (X .^ 2, 2); Mdl = RegressionSVM (X, Y, 'KernelFunction', 'rbf'); CMdl = compact (Mdl); assert_equal (isempty (CMdl.Beta), true); assert_equal (predict (CMdl, X), predict (Mdl, X)); ***** test randn ('seed', 42); X = randn (30, 2); Y = X(:,1) * 3 + 1; Mdl = RegressionSVM (X, Y, 'Epsilon', 0.5); CMdl = compact (Mdl); yFit = predict (CMdl, X); assert_equal (loss (CMdl, X, Y), mean ((Y - yFit) .^ 2), 1e-12); assert_equal (loss (CMdl, X, Y, 'LossFun', 'epsiloninsensitive'), ... mean (max (0, abs (Y - yFit) - 0.5)), 1e-12); w = rand (30, 1) + 0.1; assert_equal (loss (CMdl, X, Y, 'Weights', w), ... loss (CMdl, X, Y, 'Weights', 4 * w), 1e-12); f = @(y, yf, ww) sum (ww .* abs (y - yf)); assert_equal (loss (CMdl, X, Y, 'LossFun', f), ... mean (abs (Y - yFit)), 1e-12); ***** test X = [linspace(0, 1, 20)', linspace(1, 2, 20)']; Mdl = RegressionSVM (X, 2 * X(:,1) + 1, 'ResponseTransform', 'exp'); CMdl = compact (Mdl); assert_equal (predict (CMdl, X), predict (Mdl, X)); CMdl.ResponseTransform = 'none'; assert_equal (predict (CMdl, X), log (predict (Mdl, X)), 1e-12); ***** test randn ('seed', 42); X = randn (30, 2); Y = X(:,1) * 4 - 1; CMdl = compact (RegressionSVM (X, Y, 'Standardize', true)); fname = tempname (); savemodel (CMdl, fname); C2 = loadmodel (fname); delete (fname); assert_equal (class (C2), 'CompactRegressionSVM'); assert_equal (C2.Alpha, CMdl.Alpha); assert_equal (C2.Bias, CMdl.Bias); assert_equal (C2.Epsilon, CMdl.Epsilon); assert_equal (C2.SupportVectors, CMdl.SupportVectors); assert_equal (predict (C2, X), predict (CMdl, X)); ***** test load fisheriris keep = ! strcmp (species, "setosa"); X = meas(keep,2:4); y = meas(keep,1); Mdl = compact (fitrsvm (X, y, "KernelFunction", "linear")); D = discardSupportVectors (Mdl); assert_equal (class (D), "CompactRegressionSVM"); assert_equal (isempty (D.Alpha), true); assert_equal (isempty (D.SupportVectors), true); assert_equal (D.Beta, Mdl.Beta); assert_equal (D.Bias, Mdl.Bias); ***** test load fisheriris keep = ! strcmp (species, "setosa"); X = meas(keep,2:4); y = meas(keep,1); Mdl = compact (fitrsvm (X, y, "KernelFunction", "linear")); D = discardSupportVectors (Mdl); assert_equal (predict (D, X), predict (Mdl, X), 1e-10); ***** test load fisheriris keep = ! strcmp (species, "setosa"); X = meas(keep,2:4); y = meas(keep,1); Mdl = compact (fitrsvm (X, y, "KernelFunction", "linear")); D = discardSupportVectors (Mdl); assert_equal (rows (Mdl.Model.SVs) > 1, true); assert_equal (rows (D.Model.SVs), 1); assert_equal (predict (discardSupportVectors (D), X), predict (D, X)); ***** test # A row missing a predictor predicts the lower median of the response X = [(1:10)', mod((1:10)', 3)]; Mdl = compact (RegressionSVM (X, (1:10)')); assert_equal (predict (Mdl, [NaN, 1]), 5); ***** error ... load fisheriris keep = ! strcmp (species, "setosa"); X = meas(keep,2:4); y = meas(keep,1); discardSupportVectors (compact (fitrsvm (X, y, "KernelFunction", "rbf"))) ***** error ... CompactRegressionSVM (1) ***** error ... CompactRegressionSVM (fitcsvm (ones (4, 2), [1; 1; 2; 2])) ***** shared CRSVM CRSVM = compact (RegressionSVM ([1, 1; 2, 1; 3, 2; 4, 2], [2; 4; 6; 8])); ***** error ... predict (CRSVM) ***** error ... predict (CRSVM, []) ***** error ... predict (CRSVM, ones (2, 3)) ***** error ... loss (CRSVM) ***** error ... loss (CRSVM, [1, 1; 2, 1], [2; 4], 'Weights') ***** error ... loss (CRSVM, [], [2; 4]) ***** error ... loss (CRSVM, ones (2, 3), [2; 4]) ***** error ... loss (CRSVM, [1, 1; 2, 1], []) ***** error ... loss (CRSVM, [1, 1; 2, 1], {'a'; 'b'}) ***** error ... loss (CRSVM, [1, 1; 2, 1], [2; 4; 6]) ***** error ... loss (CRSVM, [1, 1; 2, 1], [2; 4], 'LossFun', 5) ***** error ... loss (CRSVM, [1, 1; 2, 1], [2; 4], 'LossFun', 'mae') ***** error ... loss (CRSVM, [1, 1; 2, 1], [2; 4], 'LossFun', @(y, yf, w) [1, 2]) ***** error ... loss (CRSVM, [1, 1; 2, 1], [2; 4], 'Weights', {'a'}) ***** error ... loss (CRSVM, [1, 1; 2, 1], [2; 4], 'Weights', ones (2, 2)) ***** error ... loss (CRSVM, [1, 1; 2, 1], [2; 4], 'Weights', [1; 2; 3]) ***** error ... loss (CRSVM, [1, 1; 2, 1], [2; 4], 'Nope', 1) ***** error ... savemodel (CRSVM) ***** error ... savemodel (CRSVM, 5) ***** error ... CRSVM.ResponseTransform = 'nope'; ***** test load fisheriris X = meas(:,2:4); Y = meas(:,1); Mdl = compact (fitrsvm (X, Y)); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2), 'CompactRegressionSVM'); assert_equal (M2.PredictorNames, Mdl.PredictorNames); assert_equal (class (M2.ResponseTransform), class (Mdl.ResponseTransform)); assert_equal (predict (M2, X(1:5,:)), predict (Mdl, X(1:5,:)), 1e-12); ***** test load fisheriris Mdl = fitrsvm (meas(:,1:3), meas(:,4)); CMdl = compact (Mdl); assert_equal (CMdl.KernelParameters, Mdl.KernelParameters); assert_equal (CMdl.KernelParameters.Function, 'linear'); ***** test load fisheriris Mdl = compact (fitrsvm (meas(:,2:4), meas(:,1))); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); T = {'identity', @(x) x; 'exp', @(x) exp (x); 'log', @(x) log (x)}; for i = 1:rows (T) Mdl.ResponseTransform = T{i,1}; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, T{i,2}(raw), 1e-12); endfor ***** test load fisheriris Mdl = compact (fitrsvm (meas(:,2:4), meas(:,1))); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); Mdl.ResponseTransform = @(x) x .^ 2; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, raw .^ 2, 1e-12); ***** shared Xc, Dc, yr, yc, Xq, Dq k = (0:119)'; c1 = mod (k, 3) + 1; x2 = sin (k); c3 = 10 * (mod (floor (k / 2), 2) + 1); Xc = [c1, x2, c3]; Dc = [c1 == 1, c1 == 2, c1 == 3, x2, c3 == 10, c3 == 20]; yr = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 20) + 0.1 * cos (k); yc = yr > 1; Xq = [1, 0, 10; 2, 0.5, 20]; Dq = [1, 0, 0, 0, 1, 0; 0, 1, 0, 0.5, 0, 1]; ***** test # a compact model keeps the coding Full = fitrsvm (Xc, yr, 'CategoricalPredictors', [1, 3]); Mdl = compact (Full); assert_equal (Mdl.ExpandedPredictorNames, Full.ExpandedPredictorNames); assert_equal (predict (Mdl, Xq), predict (Full, Xq)); fname = [tempname(), '.mdl']; savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (predict (M2, Xq), predict (Mdl, Xq)); ***** test # the levels a predictor was coded through travel with the model load fisheriris T = table (meas(:,2), meas(:,3), 'VariableNames', {'SW', 'PL'}); T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); T.SL = meas(:,1); CMdl = compact (fitrsvm (T, 'SL')); assert_equal (numel (CMdl.PredictorLevels), 3); assert_equal (CMdl.PredictorLevels{3}, {'narrow', 'wide'}); ***** test # predict takes a table, read by name and not by position load fisheriris T = table (meas(:,2), meas(:,3), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'SL'}); CMdl = compact (fitrsvm (T, 'SL')); a = predict (CMdl, T); assert_equal (numel (a), 150); assert_equal (predict (CMdl, T(:, [3, 2, 1])), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,2:3); y = meas(:,1); T = table (X(:,1), X(:,2), 'VariableNames', {'SW', 'PL'}); T.SL = y; Mdl = compact (fitrsvm (T, 'SL')); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'SL'), a); assert_equal (loss (Mdl, T), a); 43 tests, 43 passed, 0 known failure, 0 skipped [inst/Machine_Learning/CompactClassificationSVM.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/CompactClassificationSVM.m ***** demo ## Create a support vectors machine classifier and its compact version rng (42); # and compare their size load fisheriris X = meas; Y = species; selected_classes = unique (Y)(randperm (3, 2)); selected_indices = ismember (Y, selected_classes); X_selected = X(selected_indices, :); Y_selected = Y(selected_indices); Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes); CMdl = crossval (Mdl) ***** test load fisheriris keep = ! strcmp (species, "setosa"); X = meas(keep,:); y = species(keep); Mdl = compact (fitcsvm (X, y, "KernelFunction", "linear")); D = discardSupportVectors (Mdl); assert_equal (class (D), "CompactClassificationSVM"); assert_equal (isempty (D.Alpha), true); assert_equal (isempty (D.SupportVectors), true); assert_equal (isempty (D.SupportVectorLabels), true); assert_equal (D.Beta, Mdl.Beta); assert_equal (D.Bias, Mdl.Bias); ***** test load fisheriris keep = ! strcmp (species, "setosa"); X = meas(keep,:); y = species(keep); Mdl = compact (fitcsvm (X, y, "KernelFunction", "linear")); D = discardSupportVectors (Mdl); assert_equal (predict (D, X), predict (Mdl, X), 1e-10); ***** test load fisheriris keep = ! strcmp (species, "setosa"); X = meas(keep,:); y = species(keep); Mdl = compact (fitcsvm (X, y, "KernelFunction", "linear")); D = discardSupportVectors (Mdl); assert_equal (rows (Mdl.Model.SVs) > 1, true); assert_equal (rows (D.Model.SVs), 1); assert_equal (predict (discardSupportVectors (D), X), predict (D, X)); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Cc = compact (fitcsvm (Xch, Ych)); rand ("state", 1); randn ("state", 1); Cs = compact (fitcsvm (Xch, Ycell)); assert_equal (cellstr (Cc.ClassNames), Cs.ClassNames); assert_equal (cellstr (predict (Cc, Xch)), predict (Cs, Xch)); ***** test load fisheriris bch = ! strcmp (species, "setosa"); Xch = meas(bch,:); Ycell = species(bch); Ych = char (Ycell); rand ("state", 1); randn ("state", 1); Cc = compact (fitcsvm (Xch, Ych)); rand ("state", 1); randn ("state", 1); Cs = compact (fitcsvm (Xch, Ycell)); assert_equal (loss (Cc, Xch, Ych), loss (Cs, Xch, Ycell), 1e-12); ***** test # A row missing a predictor takes the class of largest prior X = [(1:10)', mod((1:10)', 3)]; y = [1; 1; 1; 1; 1; 1; 2; 2; 2; 2]; Mdl = compact (ClassificationSVM (X, y)); [label, score, cost] = predict (Mdl, [NaN, 1]); assert_equal (label, 1); assert_equal (score, [NaN, NaN]); assert_equal (cost, [NaN, NaN]); Mdl = compact (ClassificationSVM (X, y, 'Prior', [0.3, 0.7])); assert_equal (predict (Mdl, [NaN, 1]), 2); ***** test load fisheriris C = compact (fitcsvm (meas(51:100,[1, 3]), ones (50, 1))); [lab, s] = predict (C, [6, 4.3; 5, 3.5; 7, 4.7; 5.5, 5]); assert_equal (lab, ones (4, 1)); assert_equal (size (s), [4, 1]); assert_equal (loss (C, meas(51:100,[1, 3]), ones (50, 1)), 0); ***** error ... load fisheriris keep = ! strcmp (species, "setosa"); X = meas(keep,:); y = species(keep); discardSupportVectors (compact (fitcsvm (X, y, "KernelFunction", "rbf"))) ***** error ... CompactClassificationSVM (1) ***** shared x, y, CMdl load fisheriris inds = ! strcmp (species, 'setosa'); x = meas(inds, 3:4); y = grp2idx (species(inds)); ***** test xc = [min(x); mean(x); max(x)]; Mdl = fitcsvm (x, y, 'KernelFunction', 'rbf', 'Tolerance', 1e-7); CMdl = compact (Mdl); assert_equal (isempty (CMdl.Beta), true) assert_equal (rows (CMdl.SupportVectors), numel (CMdl.Alpha)) [label, score] = predict (CMdl, xc); assert_equal (label, [1; 2; 2]); ## R2024a's scores. assert_equal (score(:,1), [0.9813697204; -0.1752955874; ... -0.9410361822], 5e-4); assert_equal (score(:,1), -score(:,2), eps) ***** test Mdl = fitcsvm (x, y); CMdl = compact (Mdl); assert_equal (CMdl.Beta, [2.182926829268275; 2.253658536585344], 1e-5) assert_equal (rows (CMdl.SupportVectors), numel (CMdl.Alpha)) assert_equal (numel (CMdl.Alpha), 24) assert_equal (CMdl.Bias, -14.415, 1e-3) xc = [min(x); mean(x); max(x)]; label = predict (CMdl, xc); assert_equal (label, [1; 2; 2]); ***** error ... predict (CMdl) ***** error ... predict (CMdl, []) ***** error ... predict (CMdl, 1) ***** error ... CMdl.ScoreTransform = 'a'; ***** test load fisheriris Yb = strcmp (species, 'setosa'); CMdl2 = compact (fitcsvm (meas, Yb)); assert_equal (CMdl2.KernelParameters.Function, 'linear'); CMdl2.ScoreTransform = 'logit'; [~, s1] = predict (CMdl2, meas(1:3,:)); CMdl2.ScoreTransform = @(x) 1 ./ (1 + exp (-x)); [~, s2] = predict (CMdl2, meas(1:3,:)); assert_equal (s1, s2); CMdl2.ScoreTransform = 'logit'; fname = tempname (); savemodel (CMdl2, fname); M2 = loadmodel (fname); delete (fname); [~, s3] = predict (M2, meas(1:3,:)); assert_equal (s3, s1); ***** test rand ('seed', 1); C = cvpartition (y, 'HoldOut', 0.15); Mdl = fitcsvm (x(training (C),:), y(training (C)), ... 'KernelFunction', 'rbf', 'Tolerance', 1e-7); CMdl = compact (Mdl); testInds = test (C); ## R2024a's margins, fitted on the same training rows. Every one of the ## fifteen is classified correctly, so every margin is positive. expected_margin = [2.183612293; 0.998032770; 1.999658371; 3.068544065; ... 2.967820747; 2.189865834; 3.256968349; 2.318380120; ... 3.188442076; 3.154586323; 1.701435679; 3.218617427; ... 1.028076370; 3.029995574; 2.811141675]; computed_margin = margin (CMdl, x(testInds,:), y(testInds,:)); assert_equal (computed_margin, expected_margin, 2e-3); assert (all (computed_margin > 0)); ***** error ... margin (CMdl) ***** error ... margin (CMdl, zeros (2)) ***** error ... margin (CMdl, [], 1) ***** error ... margin (CMdl, 1, 1) ***** error ... margin (CMdl, [1, 2], []) ***** error ... margin (CMdl, [1, 2], [1; 2]) ***** test rand ('seed', 1); C = cvpartition (y, 'HoldOut', 0.15); Mdl = fitcsvm (x(training (C),:), y(training (C)), ... 'KernelFunction', 'rbf', 'Tolerance', 1e-7); CMdl = compact (Mdl); testInds = test (C); L1 = loss (CMdl, x(testInds,:), y(testInds,:), 'LossFun', 'binodeviance'); L2 = loss (CMdl, x(testInds,:), y(testInds,:), 'LossFun', 'classiferror'); L3 = loss (CMdl, x(testInds,:), y(testInds,:), 'LossFun', 'exponential'); L4 = loss (CMdl, x(testInds,:), y(testInds,:), 'LossFun', 'hinge'); L5 = loss (CMdl, x(testInds,:), y(testInds,:), 'LossFun', 'logit'); L6 = loss (CMdl, x(testInds,:), y(testInds,:), 'LossFun', 'quadratic'); ## R2024a's losses, fitted on the same training rows. assert_equal (L1, 0.1059272872, 5e-4); assert_equal (L2, 0, 5e-4); assert_equal (L3, 0.3141243253, 5e-4); assert_equal (L4, 0.07545354045, 5e-4); assert_equal (L5, 0.2684014524, 5e-4); assert_equal (L6, 0.194889185, 5e-4); ***** error ... loss (CMdl) ***** error ... loss (CMdl, zeros (2)) ***** error ... loss (CMdl, [1, 2], 1, 'LossFun') ***** error ... loss (CMdl, [], zeros (2)) ***** error ... loss (CMdl, 1, zeros (2)) ***** error ... loss (CMdl, [1, 2], []) ***** error ... loss (CMdl, [1, 2], [1; 2]) ***** error ... loss (CMdl, [1, 2], 1, 'LossFun', 1) ***** error ... loss (CMdl, [1, 2], 1, 'LossFun', 'some') ***** error ... loss (CMdl, [1, 2], 1, 'Weights', ['a', 'b']) ***** error ... loss (CMdl, [1, 2], 1, 'Weights', ones (2, 2)) ***** error ... loss (CMdl, [1, 2], 1, 'Weights', 'a') ***** error ... loss (CMdl, [1, 2], 1, 'Weights', [1, 2]) ***** error ... loss (CMdl, [1, 2], 1, 'some', 'some') ***** error ... savemodel (CompactClassificationSVM ()) ***** error ... savemodel (CompactClassificationSVM (), 1) ***** error ... savemodel (CompactClassificationSVM (), ['ab'; 'cd']) ***** test load fisheriris inds = ! strcmp (species, 'virginica'); Mdl = compact (fitcsvm (meas(inds,:), species(inds))); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2), 'CompactClassificationSVM'); assert_equal (M2.PredictorNames, Mdl.PredictorNames); assert_equal (class (M2.ScoreTransform), class (Mdl.ScoreTransform)); assert_equal (predict (M2, meas(1:5,:)), predict (Mdl, meas(1:5,:))); ***** test load fisheriris inds = ! strcmp (species, 'virginica'); X = meas(inds,:); Y = species(inds); Mdl = fitcsvm (X, Y); CMdl = compact (Mdl); assert_equal (edge (CMdl, X, Y), mean (margin (CMdl, X, Y)), 1e-12); assert_equal (edge (CMdl, X, Y), edge (Mdl, X, Y), 1e-12); ***** error ... load fisheriris; ... inds = ! strcmp (species, 'virginica'); ... edge (compact (fitcsvm (meas(inds,:), species(inds))), meas(inds,:)) ***** test load fisheriris b = ismember (species, {'setosa', 'versicolor'}); CMdl = compact (fitcsvm (meas(b,:), species(b))); assert_equal (CMdl.CategoricalPredictors, []); assert_equal (CMdl.ExpandedPredictorNames, CMdl.PredictorNames); assert_equal (size (CMdl.ExpandedPredictorNames), [1, 4]); ***** test load fisheriris b = ismember (species, {'setosa', 'versicolor'}); CMdl = compact (fitcsvm (meas(b,:), species(b))); fname = tempname (); savemodel (CMdl, fname); C2 = loadmodel (fname); delete (fname); assert_equal (C2.CategoricalPredictors, CMdl.CategoricalPredictors); assert_equal (C2.ExpandedPredictorNames, CMdl.ExpandedPredictorNames); ***** test load fisheriris b = ismember (species, {'setosa', 'versicolor'}); Mdl = fitcsvm (meas(b,:), species(b), 'KernelFunction', 'rbf'); CMdl = compact (Mdl); assert_equal (CMdl.KernelParameters, Mdl.KernelParameters); assert_equal (CMdl.KernelParameters.Function, 'gaussian'); ***** test load fisheriris b = strcmp (species, 'setosa'); Mdl = fitcsvm (meas, b, 'Cost', [0, 2; 5, 0]); [~, ~, cost] = predict (compact (Mdl), meas([1, 51],:)); assert_equal (cost, [5, 0; 0, 2]); ***** test load fisheriris Mdl = compact (fitcsvm (meas, strcmp (species, 'setosa'))); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); T = {'identity', @(x) x; 'doublelogit', @(x) 1 ./ (1 + exp (-2 * x)); ... 'invlogit', @(x) log (x ./ (1 - x)); ... 'logit', @(x) 1 ./ (1 + exp (-x)); ... 'sign', @(x) sign (x); 'symmetric', @(x) 2 * x - 1; ... 'symmetriclogit', @(x) 2 ./ (1 + exp (-x)) - 1}; for i = 1:rows (T) Mdl.ScoreTransform = T{i,1}; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, T{i,2}(raw), 1e-12); assert_equal (l, label); endfor ## ismax marks the largest score of each observation, ties to the first. [~, k] = max (raw, [], 2); e = zeros (size (raw)); e(sub2ind (size (raw), (1:rows (raw))', k)) = 1; Mdl.ScoreTransform = 'ismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, e); Mdl.ScoreTransform = 'symmetricismax'; [~, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, 2 * e - 1); ***** test load fisheriris Mdl = compact (fitcsvm (meas, strcmp (species, 'setosa'))); Mdl.ScoreTransform = 'none'; [label, raw] = predict (Mdl, meas([1, 60, 120],:)); Mdl.ScoreTransform = @(x) x .^ 2; [l, s] = predict (Mdl, meas([1, 60, 120],:)); assert_equal (s, raw .^ 2, 1e-12); assert_equal (l, label); ***** shared Xc, Dc, yr, yc, Xq, Dq k = (0:119)'; c1 = mod (k, 3) + 1; x2 = sin (k); c3 = 10 * (mod (floor (k / 2), 2) + 1); Xc = [c1, x2, c3]; Dc = [c1 == 1, c1 == 2, c1 == 3, x2, c3 == 10, c3 == 20]; yr = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 20) + 0.1 * cos (k); yc = yr > 1; Xq = [1, 0, 10; 2, 0.5, 20]; Dq = [1, 0, 0, 0, 1, 0; 0, 1, 0, 0.5, 0, 1]; ***** test # a compact model keeps the coding, margin and loss included Full = fitcsvm (Xc, yc, 'CategoricalPredictors', [1, 3], ... 'Standardize', true); Mdl = compact (Full); assert_equal (Mdl.CategoricalPredictors, [1, 3]); assert_equal (predict (Mdl, Xq), predict (Full, Xq)); assert_equal (margin (Mdl, Xc, yc), margin (Full, Xc, yc), 1e-12); assert_equal (loss (Mdl, Xc, yc), resubLoss (Full)); fname = [tempname(), '.mdl']; savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (predict (M2, Xq), predict (Mdl, Xq)); ***** test # the levels a predictor was coded through travel with the model load fisheriris inds = ! strcmp (species, 'setosa'); T = table (meas(inds,1), meas(inds,2), 'VariableNames', {'SL', 'SW'}); T.Wide = categorical (meas(inds,2) > 2.9, [false true], ... {'narrow', 'wide'}); T.Species = categorical (species(inds)); CMdl = compact (fitcsvm (T, 'Species')); assert_equal (numel (CMdl.PredictorLevels), 3); assert_equal (CMdl.PredictorLevels{3}, {'narrow', 'wide'}); ***** test # predict takes a table, read by name and not by position load fisheriris inds = ! strcmp (species, 'setosa'); T = table (meas(inds,1), meas(inds,2), 'VariableNames', {'SL', 'SW'}); T.Species = categorical (species(inds)); CMdl = compact (fitcsvm (T, 'Species')); a = predict (CMdl, T); assert_equal (class (a), 'categorical'); assert_equal (predict (CMdl, T(:, [3, 2, 1])), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(51:150,1:2); y = species(51:150); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcsvm (T, 'Species')); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # loss reads one as it reads a cellstr response load fisheriris X = meas(51:150,1:2); y = species(51:150); a = loss (compact (fitcsvm (X, y)), X, y); yc = categorical (y); assert_equal (loss (compact (fitcsvm (X, yc)), X, yc), a); ys = string (y); assert_equal (loss (compact (fitcsvm (X, ys)), X, ys), a); ***** test # margin reads one as it reads a cellstr response load fisheriris X = meas(51:150,1:2); y = species(51:150); a = margin (compact (fitcsvm (X, y)), X, y); yc = categorical (y); assert_equal (margin (compact (fitcsvm (X, yc)), X, yc), a); ys = string (y); assert_equal (margin (compact (fitcsvm (X, ys)), X, ys), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(51:150,1:2); y = categorical (species(51:150)); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcsvm (T, 'Species')); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(51:150,1:2); y = categorical (species(51:150)); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcsvm (T, 'Species')); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); 58 tests, 58 passed, 0 known failure, 0 skipped [inst/Machine_Learning/CompactRegressionGAM.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/CompactRegressionGAM.m ***** demo ## Take the compact version of a fitted model and predict with it load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y) cmdl = compact (mdl) ***** test # a row missing a predictor is kept, and its spline term has no value x = linspace (0, 1, 30)'; X = [x, cos(4 * x)]; y = sin (3 * x) + X(:,2); Mdl = compact (RegressionGAM (X, y, 'FitMethod', 'splines')); yFit = predict (Mdl, [0.5, 0.2; NaN, 0.2; 0.5, 0.2]); assert_equal (size (yFit), [3, 1]); assert_equal (isnan (yFit)', [false, true, false]); ***** test # a row missing every predictor predicts the intercept k = (1:200)'; X = [sin(k), cos(2 * k), mod(k, 5)]; y = 2 * sin (k) + X(:,2) .^ 2 + 0.3 * X(:,3); Q = [0.5, 0.2, 1; NaN, 0.2, 1; 0.5, NaN, 1; NaN, NaN, NaN; 0.1, 0.2, 1; ... NaN, 0.7, 3; NaN, NaN, 1]; Mdl = compact (RegressionGAM (X, y)); yFit = predict (Mdl, Q); assert_equal (size (yFit), [7, 1]); assert_equal (yFit(4), Mdl.Intercept); ***** error ... CompactRegressionGAM (1) ***** test load fisheriris Mdl = fitrgam (meas(:,1:3), meas(:,4)); CMdl = compact (Mdl); assert_equal (class (CMdl), 'CompactRegressionGAM'); assert_equal (CMdl.Intercept, Mdl.Intercept); assert_equal (CMdl.CategoricalPredictors, Mdl.CategoricalPredictors); assert_equal (CMdl.ExpandedPredictorNames, Mdl.ExpandedPredictorNames); assert_equal (CMdl.IsStandardDeviationFit, false); assert_equal (isprop (CMdl, 'X'), false); ***** test load fisheriris X = meas(:,1:3); Y = meas(:,4); Mdl = fitrgam (X, Y, 'Interactions', 'all'); CMdl = compact (Mdl); assert_equal (predict (CMdl, X), predict (Mdl, X)); assert_equal (loss (CMdl, X, Y), loss (Mdl, X, Y)); ***** test load fisheriris X = meas(:,1:3); CMdl = compact (fitrgam (X, meas(:,4))); fname = tempname (); savemodel (CMdl, fname); CMdl2 = loadmodel (fname); delete (fname); assert_equal (class (CMdl2), 'CompactRegressionGAM'); assert_equal (CMdl2.Intercept, CMdl.Intercept); assert_equal (predict (CMdl2, X), predict (CMdl, X)); ***** test load fisheriris X = meas(:,1:3); CMdl = compact (fitrgam (X, meas(:,4))); y0 = predict (CMdl, X); CMdl.ResponseTransform = 'log'; assert_equal (predict (CMdl, X), log (y0), 1e-12); ***** shared xc, yc, CMr load fisheriris xc = meas(:,1:3); yc = meas(:,4); CMr = compact (fitrgam (xc, yc)); ***** error ... predict (CMr) ***** error ... predict (CMr, []) ***** error ... predict (CMr, xc, 'Bogus', 1) ***** error ... loss (CMr, xc) ***** error ... loss (CMr, xc, yc, 'LossFun', 'mad') ***** error ... loss (CMr, xc, yc, 'Bogus', 1) ***** error ... savemodel (CompactRegressionGAM ()) ***** error ... savemodel (CompactRegressionGAM (), 1) ***** test load fisheriris X = meas(:,2:4); Y = meas(:,1); Mdl = compact (fitrgam (X, Y, 'FitMethod', 'splines')); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (class (M2), 'CompactRegressionGAM'); assert_equal (M2.PredictorNames, Mdl.PredictorNames); assert_equal (class (M2.ResponseTransform), class (Mdl.ResponseTransform)); assert_equal (M2.BaseModel.Parameters(1).coefs, ... Mdl.BaseModel.Parameters(1).coefs); assert_equal (predict (M2, X(1:5,:)), predict (Mdl, X(1:5,:)), 1e-12); ***** test load fisheriris X = meas(:,2:4); Y = meas(:,1); Mdl = compact (fitrgam (X, Y, 'FitMethod', 'boostedtrees')); fname = tempname (); savemodel (Mdl, fname); M2 = loadmodel (fname); delete (fname); assert_equal (M2.FitMethod, 'boostedtrees'); assert_equal (M2.TreeModel.ShapeValues, Mdl.TreeModel.ShapeValues); assert_equal (predict (M2, X(1:5,:)), predict (Mdl, X(1:5,:)), 1e-12); ***** test load fisheriris X = meas(:,2:4); CMdl = compact (fitrgam (X, meas(:,1), 'FitMethod', 'boostedtrees')); assert_equal (CMdl.FitMethod, 'boostedtrees'); assert_equal (numel (CMdl.BinEdges), 3); assert_equal (numel (predict (CMdl, X)), rows (X)); ***** test load fisheriris Mdl = compact (fitrgam (meas(:,2:4), meas(:,1))); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); T = {'identity', @(x) x; 'exp', @(x) exp (x); 'log', @(x) log (x)}; for i = 1:rows (T) Mdl.ResponseTransform = T{i,1}; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, T{i,2}(raw), 1e-12); endfor ***** test load fisheriris Mdl = compact (fitrgam (meas(:,2:4), meas(:,1))); Mdl.ResponseTransform = 'none'; raw = predict (Mdl, meas([1, 60, 120],2:4)); Mdl.ResponseTransform = @(x) x .^ 2; yhat = predict (Mdl, meas([1, 60, 120],2:4)); assert_equal (yhat, raw .^ 2, 1e-12); ***** test # the levels a predictor was coded through travel with the model load fisheriris T = table (meas(:,2), meas(:,3), 'VariableNames', {'SW', 'PL'}); T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); T.SL = meas(:,1); CMdl = compact (fitrgam (T, 'SL')); assert_equal (numel (CMdl.PredictorLevels), 3); assert_equal (CMdl.PredictorLevels{3}, {'narrow', 'wide'}); ***** test # predict takes a table, read by name and not by position load fisheriris T = table (meas(:,2), meas(:,3), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'SL'}); CMdl = compact (fitrgam (T, 'SL')); a = predict (CMdl, T); assert_equal (numel (a), 150); assert_equal (predict (CMdl, T(:, [3, 2, 1])), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,2:3); y = meas(:,1); T = table (X(:,1), X(:,2), 'VariableNames', {'SW', 'PL'}); T.SL = y; Mdl = compact (fitrgam (T, 'SL')); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'SL'), a); assert_equal (loss (Mdl, T), a); ***** error X = [1, 2; 3, 4; 5, 6; 7, 8]; y = (1:4)'; loss (compact (fitrgam (X, y)), X, y, 'Weights', int8 ([1; 1; 1; 1])) 24 tests, 24 passed, 0 known failure, 0 skipped [inst/Machine_Learning/CompactClassificationEnsemble.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/CompactClassificationEnsemble.m ***** shared X2, Y2, C load fisheriris X2 = meas(51:150,:); Y2 = species(51:150); C = compact (fitcensemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 5, ... 'Learners', templateTree ('MaxNumSplits', 1))); ***** test # MATLAB parity: the properties of a compact ensemble assert_equal (numel (properties (C)), 13); assert_equal (C.NumTrained, 5); assert_equal (C.CombineWeights, 'WeightedSum'); assert_equal (isprop (C, 'X'), false); ***** test # MATLAB parity: scores over a subset of the learners [~, s] = predict (C, X2([1, 51],:), 'Learners', [2, 4]); assert_equal (s(:,1), [1.547898302883168; -0.439169918665653], 1e-13); ***** test # MATLAB parity: a row no learner may score has NaN scores U = true (2, 5); U(1,:) = false; U(2,[1, 3]) = false; [label, s] = predict (C, X2(1:2,:), 'UseObsForLearner', U); assert_equal (isnan (s(1,:)), [true, true]); assert_equal (label{1}, 'versicolor'); assert_equal (s(2,1), 1.279703855451121, 1e-13); ***** test # MATLAB parity: such a row takes the class of greatest prior load fisheriris Y = species(41:150); Y(1:10) = {'virginica'}; M = compact (fitcensemble (meas(41:150,:), Y, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 3, ... 'Learners', templateTree ('MaxNumSplits', 1))); label = predict (M, meas(1,:), 'UseObsForLearner', false (1, 3)); assert_equal (label, {'virginica'}); ***** test # MATLAB parity: the loss in its three modes assert_equal (loss (C, X2, Y2), 0.04, 1e-15); assert_equal (loss (C, X2, Y2, 'Mode', 'cumulative'), ... [0.06; 0.06; 0.04; 0.06; 0.04], 1e-15); assert_equal (loss (C, X2, Y2, 'Mode', 'individual'), ... [0.06; 0.08; 0.21; 0.5; 0.5], 1e-14); assert_equal (loss (C, X2, Y2, 'Learners', [1, 3]), 0.06, 1e-15); ***** test # MATLAB parity: every built-in loss function f = {'binodeviance', 'exponential', 'hinge', 'logit', 'quadratic', ... 'mincost', 'classifcost'}; L = cellfun (@(n) loss (C, X2, Y2, 'LossFun', n), f); assert_equal (L, [0.088288301419851, 0.182079166822146, ... 0.093152538904937, 0.136695159561291, ... 3.600631106449406, 0.04, 0.04], 1e-12); ***** test # a loss function given as a handle f = @(Cl, Sc, W, Cost) sum (W .* (Sc(Cl) < 0)); assert_equal (loss (C, X2, Y2, 'LossFun', f), 0.04, 1e-15); ***** test # MATLAB parity: the edge and its cumulative mode assert_equal (edge (C, X2, Y2), 5.115272254726563, 1e-12); assert_equal (edge (C, X2, Y2, 'Mode', 'cumulative'), ... [2.421351075476915; 4.090488381577923; ... 5.115272254726563; 5.115272254726564; ... 5.115272254726563], 1e-12); ***** test # MATLAB parity: margins are twice the score of the true class [~, s] = predict (C, X2([1, 21],:)); m = margin (C, X2([1, 21],:), Y2([1, 21])); assert_equal (m, [3.544074277136197; -1.958996348947703], 1e-12); assert_equal (m, 2 * s(:,1), 1e-14); ***** test # MATLAB parity: losses read the transformed scores D = C; D.ScoreTransform = 'doublelogit'; assert_equal (loss (D, X2, Y2, 'LossFun', 'quadratic'), ... 0.028390700687515, 1e-13); ***** test # a score transform given as a function handle survives compacting load fisheriris Mdl = fitcensemble (X2, Y2, 'Method', 'AdaBoostM1', ... 'NumLearningCycles', 2, ... 'Learners', templateTree ('MaxNumSplits', 1), ... 'ScoreTransform', @(s) 2 * s); [~, s] = predict (Mdl, X2(1,:)); [~, s0] = predict (C, X2(1,:), 'Learners', [1, 2]); assert_equal (s, 2 * s0, 1e-14); ***** test # MATLAB parity: removing learners D = removeLearners (C, [2, 4]); assert_equal (D.NumTrained, 3); assert_equal (D.TrainedWeights, [1.375767656520975; ... 0.883434373403998; 0.268194447432047], 1e-13); ***** error ... CompactClassificationEnsemble (1) ***** error ... predict (C) ***** error ... predict (C, {1}) ***** error ... predict (C, ones (2, 3)) ***** error ... predict (C, X2, 'Learners') ***** error ... predict (C, X2, 'Mode', 'ensemble') ***** error ... predict (C, X2, 'Learners', 6) ***** error ... predict (C, X2, 'UseObsForLearner', true (2, 5)) ***** error ... loss (C, X2) ***** error ... loss (C, X2, Y2, 'Mode', 'all') ***** error ... loss (C, X2, Y2, 'Weights', ones (3, 1)) ***** error ... loss (C, X2, Y2, 'LossFun', 'mse') ***** error ... loss (C, X2, Y2(1:3)) ***** error ... loss (C, X2(1:2,:), {'rose'; 'versicolor'}) ***** error ... edge (C, X2) ***** error ... edge (C, X2, Y2, 'LossFun', 'hinge') ***** error ... margin (C, X2) ***** error ... margin (C, X2, Y2, 'Mode', 'cumulative') ***** error ... removeLearners (C) ***** error ... removeLearners (C, 0) ***** error ... D = C; D.ScoreTransform = 1; ***** test # MATLAB parity: importance is the weighted average over the learners [imp, ma] = predictorImportance (C); assert_equal (imp, [0.020544313498471, 0, 0.094343052487178, ... 0.131555749375574], 1e-13); assert_equal (ma, []); ***** test # MATLAB parity: the importance of AdaBoostM2 stumps load fisheriris M = fitcensemble (meas, species, 'Method', 'AdaBoostM2', ... 'NumLearningCycles', 4, ... 'Learners', templateTree ('MaxNumSplits', 1)); assert_equal (predictorImportance (compact (M)), ... [0, 0, 0.230674233368758, 0.072325623666526], 1e-13); ***** test # MATLAB parity: boosted regression trees give their importance M = fitcensemble (X2, Y2, 'Method', 'LogitBoost', 'NumLearningCycles', 3, ... 'Learners', templateTree ('MaxNumSplits', 1), ... 'LearnRate', 0.5); assert_equal (predictorImportance (M), ... [0, 0, 0.698823105603178, 1.563129005828868], 1e-13); ***** test # MATLAB parity: a row no learner may score is left out of the loss U = true (100, 5); U(1,:) = false; miss = ! strcmp (predict (C, X2(2:end,:)), Y2(2:end)); assert_equal (loss (C, X2, Y2, 'UseObsForLearner', U), mean (miss), 1e-15); m = margin (C, X2(2:end,:), Y2(2:end)); assert_equal (edge (C, X2, Y2, 'UseObsForLearner', U), mean (m), 1e-13); ***** test # the levels travel with the model, and predict reads a table by name load fisheriris T = table (meas(:,1), meas(:,2), 'VariableNames', {'SL', 'SW'}); T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); T.Species = categorical (species); Mdl = fitcensemble (T, 'Species'); CMdl = compact (Mdl); assert_equal (CMdl.PredictorLevels, Mdl.PredictorLevels); a = predict (CMdl, T); assert_equal (predict (CMdl, T(:, [4, 3, 2, 1])), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcensemble (T, 'Species')); a = loss (Mdl, X, y); assert_equal (loss (Mdl, T(:,1:2), y), a); assert_equal (loss (Mdl, T, 'Species'), a); assert_equal (loss (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcensemble (T, 'Species')); a = edge (Mdl, X, y); assert_equal (edge (Mdl, T(:,1:2), y), a); assert_equal (edge (Mdl, T, 'Species'), a); assert_equal (edge (Mdl, T), a); ***** test # the response is named, left out, or given beside the table load fisheriris X = meas(:,1:2); y = categorical (species); T = table (X(:,1), X(:,2), 'VariableNames', {'SL', 'SW'}); T.Species = y; Mdl = compact (fitcensemble (T, 'Species')); a = margin (Mdl, X, y); assert_equal (margin (Mdl, T(:,1:2), y), a); assert_equal (margin (Mdl, T, 'Species'), a); assert_equal (margin (Mdl, T), a); ***** error ... loss (compact (fitcensemble ([1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], ... 'NumLearningCycles', 3)), ... [1, 2; 3, 4; 5, 6; 7, 8], [1; 1; 2; 2], 'Weights', int8 ([1; 1; 1; 1])) 42 tests, 42 passed, 0 known failure, 0 skipped [inst/Machine_Learning/fitrgp.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Machine_Learning/fitrgp.m ***** demo ## Fit a Gaussian process to a noisy sine and predict on a fine grid. x = linspace (0, 2*pi, 30)'; y = sin (x) + 0.1 * cos (7*x); Mdl = fitrgp (x, y) xq = linspace (0, 2*pi, 5)'; [yq, ysd] = predict (Mdl, xq) ***** demo ## Fit from a table, and predict on one load fisheriris T = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); ## A column holding levels is a categorical predictor without being named ## one T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ## The response is named by its column, and everything else is a predictor Mdl = fitrgp (T, 'SL'); Mdl.PredictorNames Mdl.ResponseName Mdl.CategoricalPredictors ## A model formula names them instead, holding main effects only Mdl2 = fitrgp (T, 'SL ~ PL + Wide'); Mdl2.PredictorNames ## predict reads a table by the names the model was fitted on, so the ## columns may come in any order yFit = predict (Mdl, T(1:5, [5, 4, 3, 2, 1])); yFit' ***** test ## fitrgp returns the model the class constructor returns x = linspace (0, 1, 15)'; y = cos (3*x) + 0.1 * sin (11*x); M1 = fitrgp (x, y); M2 = RegressionGP (x, y); assert_equal (class (M1), 'RegressionGP'); assert_equal (M1.Beta, M2.Beta); assert_equal (M1.Sigma, M2.Sigma); assert_equal (predict (M1, x), predict (M2, x), 1e-14); ***** test ## The options reach the model x = linspace (0, 1, 15)'; y = cos (3*x) + 0.1 * sin (11*x); Mdl = fitrgp (x, y, 'KernelFunction', 'matern52', ... 'BasisFunction', 'linear', 'ResponseName', 'temp'); assert_equal (Mdl.KernelFunction, 'Matern52'); assert_equal (Mdl.BasisFunction, 'Linear'); assert_equal (Mdl.ResponseName, 'temp'); assert_equal (numel (Mdl.Beta), 2); ***** test ## A cross validation option returns a partitioned model instead x = linspace (0, 1, 20)'; y = cos (3*x) + 0.1 * sin (11*x); CVMdl = fitrgp (x, y, 'KFold', 4); assert_equal (class (CVMdl), 'RegressionPartitionedModel'); assert_equal (CVMdl.KFold, 4); assert_equal (CVMdl.CrossValidatedModel, 'GP'); ***** test ## 'CrossVal' on gives the ten folds it defaults to x = linspace (0, 1, 20)'; y = cos (3*x) + 0.1 * sin (11*x); CVMdl = fitrgp (x, y, 'CrossVal', 'on'); assert_equal (class (CVMdl), 'RegressionPartitionedModel'); assert_equal (CVMdl.KFold, 10); ***** test ## 'CrossVal' off is the model itself x = linspace (0, 1, 15)'; y = cos (3*x); assert_equal (class (fitrgp (x, y, 'CrossVal', 'off')), 'RegressionGP'); ***** error fitrgp (ones (5, 2)) ***** error ... fitrgp (ones (5, 2), ones (5, 1), 'Standardize') ***** error ... fitrgp (ones (5, 2), ones (5, 1), 'CrossVal', 5) ***** error ... fitrgp (ones (20, 2), ones (20, 1), 'KFold', 3, 'Holdout', 0.2) ***** shared fgpT load fisheriris fgpT = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ... 'VariableNames', {'SW', 'PL', 'PW', 'SL'}); fgpT.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'}); ***** test # the response is named by a column and the rest are predictors Mdl = fitrgp (fgpT, 'SL'); assert_equal (Mdl.PredictorNames, {'SW', 'PL', 'PW', 'Wide'}); assert_equal (Mdl.ResponseName, 'SL'); assert_equal (Mdl.CategoricalPredictors, 4); ***** test # a model formula names the response and the predictors together Mdl = fitrgp (fgpT, 'SL ~ PL + Wide'); assert_equal (Mdl.PredictorNames, {'PL', 'Wide'}); assert_equal (Mdl.CategoricalPredictors, 2); ***** test # the response may be given beside a table of predictors Mdl = fitrgp (fgpT(:,1:3), fgpT.SL); assert_equal (Mdl.PredictorNames, {'SW', 'PL', 'PW'}); assert_equal (Mdl.ResponseName, 'Y'); ***** test # predict takes a table, matched by name and not by position Mdl = fitrgp (fgpT, 'SL'); a = predict (Mdl, fgpT); assert_equal (numel (a), 150); assert_equal (predict (Mdl, fgpT(:, [5, 4, 3, 2, 1])), a); ***** test # the levels travel with the model when it is made compact Mdl = fitrgp (fgpT, 'SL'); CMdl = compact (Mdl); assert_equal (CMdl.PredictorLevels, Mdl.PredictorLevels); assert_equal (predict (CMdl, fgpT), predict (Mdl, fgpT)); ***** error ... fitrgp (fgpT, 'NoSuch') ***** error ... fitrgp (fgpT, 'SL ~ PL*PW') ***** error ... predict (fitrgp (fgpT, 'SL'), fgpT(:, [1, 3, 4, 5])) 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Model_Evaluation/confusionmat.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Model_Evaluation/confusionmat.m ***** test Yt = [8 5 6 8 5 3 1 6 4 2 5 3 1 4]'; Yp = [8 5 6 8 5 2 3 4 4 5 5 7 2 6]'; C = [0 1 1 0 0 0 0 0; 0 0 0 0 1 0 0 0; 0 1 0 0 0 0 1 0; 0 0 0 1 0 1 0 0; ... 0 0 0 0 3 0 0 0; 0 0 0 1 0 1 0 0; 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 2]; assert_equal (confusionmat (Yt, Yp), C) ***** test g = [1; 2; 3; 1]; gh = [1; 2; 2; 1]; [C, order] = confusionmat (g, gh); assert_equal (C, [2 0 0; 0 1 0; 0 1 0]); assert_equal (order, [1; 2; 3]); ***** test g = [true; false; true; false]; gh = [true; true; false; false]; [C, order] = confusionmat (g, gh); assert_equal (C, [1 1; 1 1]); assert_equal (order, [false; true]); ***** test g = [1.1; 2.2; 1.1]; gh = [1.1; 2.2; 2.2]; [C, order] = confusionmat (g, gh); assert_equal (C, [1 1; 0 1]); assert_equal (order, [1.1; 2.2]); ***** test g = [1; 2; NaN; 3]; gh = [1; 1; 2; 3]; [C, order] = confusionmat (g, gh); assert_equal (C, [1 0 0; 1 0 0; 0 0 1]); assert_equal (order, [1; 2; 3]); ***** error confusionmat ([], []) ***** test [C, order] = confusionmat (1, 1); assert_equal (C, 1); assert_equal (order, 1); ***** test g = {'A'; ''; 'B'}; gh = {'A'; 'B'; 'B'}; [C, order] = confusionmat (g, gh); assert_equal (C, [1 0; 0 1]); assert_equal (order, {'A'; 'B'}); ***** test g = ['AA'; 'BB'; 'AA'; 'CC']; gh = ['AA'; 'BB'; 'BB'; 'CC']; [C, order] = confusionmat (g, gh); assert_equal (C, [1 1 0; 0 1 0; 0 0 1]); assert_equal (order, ['AA'; 'BB'; 'CC']); ***** test g = char ('A', 'B', 'A'); gh = char ('A', 'A', 'B'); [C, order] = confusionmat (g, gh); assert_equal (C, [1 1; 1 0]); assert_equal (order, char ('A', 'B')); ***** test g = {'Cat'; 'Dog'; 'Cat'; 'Bird'}; gh = {'Cat'; 'Cat'; 'Bird'; 'Bird'}; [C, order] = confusionmat (g, gh); assert_equal (C, [1 0 1; 1 0 0; 0 0 1]); assert_equal (order, {'Cat'; 'Dog'; 'Bird'}); ***** test g = ['Apple'; 'Banana'; 'Apple']; gh = ['Apple'; 'Apple'; 'Cherry']; [C, order] = confusionmat (g, gh); assert_equal (C, [1 0 1; 1 0 0; 0 0 0]); assert_equal (order, ['Apple'; 'Banana'; 'Cherry']); ***** test g = string ({'A'; 'B'; 'B'}); g(2) = missing; gh = string (['A'; 'B'; 'B']); [C, order] = confusionmat (g, gh); assert_equal (C, [1 0; 0 1]); assert_equal (isequal (order, string (['A'; 'B'])), true); ***** test g = categorical ({'Small', 'Medium', 'Large'}); gh = categorical ({'Small', 'Large', 'Large'}); [C, order] = confusionmat (g, gh); assert_equal (C, [1 0 0; 1 0 0; 0 0 1]); assert_equal (cellstr (char (order)), {'Large'; 'Medium'; 'Small'}); ***** test g = categorical ({'Red', 'Blue', 'Red'}); g(2) = missing; gh = categorical ({'Red', 'Blue', 'Red'}); [C, order] = confusionmat (g, gh); assert_equal (C, [0 0; 0 2]); assert_equal (cellstr (char (order)), {'Blue'; 'Red'}); ***** test vals = {'A', 'B', 'A'}; cats = {'A', 'B', 'C'}; g = categorical (vals, cats); gh = categorical (vals, cats); [C, order] = confusionmat (g, gh); assert_equal (size (C), [3 3]); assert_equal (C(3,3), 0); assert_equal (cellstr (char (order)), {'A'; 'B'; 'C'}); ***** test g = categorical ({'A'}, {'A', 'B'}); gh = categorical ({'A'}, {'A', 'C'}); [C, order] = confusionmat (g, gh); assert_equal (size (C), [3 3]); assert_equal (cellstr (char (order)), {'A'; 'B'; 'C'}); ***** test g = [1, 2, 3]; gh = [1; 2; 3]; [C, order] = confusionmat (g, gh); assert_equal (C, eye (3)); assert_equal (order, [1; 2; 3]); ***** test g = [1; 2; 3]; gh = [1; 2; 3]; myOrder = [3; 2; 1]; [C, order] = confusionmat (g, gh, 'Order', myOrder); assert_equal (C, [1 0 0; 0 1 0; 0 0 1]); assert_equal (order, [3; 2; 1]); ***** test g = {'A'; 'B'}; gh = {'A'; 'B'}; [C, order] = confusionmat (g, gh, 'Order', {'B'; 'A'}); assert_equal (C, [1 0; 0 1]); assert_equal (order, {'B'; 'A'}); ***** test g = [1; 2; 3]; gh = [1; 2; 3]; [C, order] = confusionmat (g, gh, 'Order', [1; 2]); assert_equal (C, eye (2)); assert_equal (order, [1; 2]); ***** test g = [1; 2]; gh = [1; 2]; [C, order] = confusionmat (g, gh, 'Order', [1; 2; 4]); assert_equal (C, [1 0 0; 0 1 0; 0 0 0]); assert_equal (order, [1; 2; 4]); ***** test g = [1; 1; 1]; gh = [2; 2; 2]; [C, order] = confusionmat (g, gh); assert_equal (C, [0 3; 0 0]); assert_equal (order, [1; 2]); ***** test g = [1; 1; 1]; gh = [1; 1; 1]; [C, order] = confusionmat (g, gh); assert_equal (C, 3); assert_equal (order, 1); ***** error confusionmat ([1; 2], {'A'; 'B'}) ***** error confusionmat ('A', [1]) ***** error confusionmat ([1; 2; 3], [1; 2]) ***** error confusionmat ([1; 2], [1; 2], 'Order', {'A'; 'B'}) ***** error confusionmat ({'A'}, {'A'}, 'Order', [1]) ***** error confusionmat (eye (2), eye (2)) ***** error confusionmat ({1; 2}, {1; 2}) 31 tests, 31 passed, 0 known failure, 0 skipped [inst/Model_Evaluation/rocmetrics.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Model_Evaluation/rocmetrics.m ***** demo ## One-versus-all ROC curves for a three-class problem labels = [1 1 2 2 3 3]'; scores = [0.9 0.05 0.05; 0.6 0.3 0.1; 0.2 0.7 0.1; ... 0.1 0.6 0.3; 0.2 0.2 0.6; 0.1 0.3 0.6]; rocObj = rocmetrics (labels, scores, [1 2 3]); disp (rocObj.AUC) plot (rocObj); ***** demo ## Binary ROC metrics with additional performance metrics labels = [1 1 1 1 0 0]'; p = [0.9 0.7 0.4 0.3 0.8 0.2]'; scores = [1-p p]; rocObj = rocmetrics (labels, scores, [0 1], ... "AdditionalMetrics", {"Accuracy", "ExpectedCost"}); head = rocObj.Metrics(1:4,:); disp (head); ***** shared labels, scores, cn labels = [1 1 2 2 3 3]'; scores = [0.9 0.05 0.05; 0.6 0.3 0.1; 0.2 0.7 0.1; ... 0.1 0.6 0.3; 0.2 0.2 0.6; 0.1 0.3 0.6]; cn = [1 2 3]; ***** test # MATLAB parity: default Metrics columns, thresholds, FPR/TPR, AUC r = rocmetrics (labels, scores, cn); assert_equal (r.Metrics.Properties.VariableNames, ... {'ClassName', 'Threshold', 'FalsePositiveRate', 'TruePositiveRate'}); assert_equal (double (r.Metrics.ClassName)', ... [1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 3], 0); assert_equal (r.Metrics.Threshold, ... [0.85;0.85;0.3;-0.4;-0.5;0.5;0.5;0.3;-0.3;-0.4;-0.85; ... 0.4;0.4;0.3;-0.3;-0.5;-0.6;-0.85], 1e-12); assert_equal (r.Metrics.TruePositiveRate, ... [0;0.5;1;1;1;0;0.5;1;1;1;1;0;0.5;1;1;1;1;1], 1e-12); assert_equal (r.AUC, [1 1 1], 1e-12); assert_equal (r.Prior, [1 1 1]/3, 1e-12); ***** test # MATLAB parity: one-versus-all margin score sets the thresholds r = rocmetrics (labels, scores, cn); m1 = r.Metrics(double (r.Metrics.ClassName) == 1, :); assert_equal (m1.Threshold, [0.85;0.85;0.3;-0.4;-0.5], 1e-12); assert_equal (m1.FalsePositiveRate, [0;0;0;0.25;1], 1e-12); ***** test # MATLAB parity: additional count and rate metrics (imbalanced binary) y = [1 1 1 1 0 0]'; p = [0.9 0.7 0.4 0.3 0.8 0.2]'; s = [1-p p]; mets = {"TruePositives","FalsePositives","TrueNegatives","FalseNegatives"}; r = rocmetrics (y, s, [0 1], "AdditionalMetrics", mets); m0 = r.Metrics(double (r.Metrics.ClassName) == 0, :); assert_equal (m0.TruePositives, [0;0.5;0.5;0.5;0.5;1;1], 1e-12); assert_equal (m0.FalsePositives, [0;0;0.5;1;1.5;1.5;2], 1e-12); assert_equal (m0.TrueNegatives, [2;2;1.5;1;0.5;0.5;0], 1e-12); assert_equal (m0.FalseNegatives, [1;0.5;0.5;0.5;0.5;0;0], 1e-12); assert_equal (r.AUC, [0.625 0.625], 1e-12); ***** test # MATLAB parity: ExpectedCost with default and custom cost y = [1 1 1 1 0 0]'; p = [0.9 0.7 0.4 0.3 0.8 0.2]'; s = [1-p p]; r = rocmetrics (y, s, [0 1], "AdditionalMetrics", "ExpectedCost"); ec0 = r.Metrics.ExpectedCost(double (r.Metrics.ClassName) == 0); assert_equal (ec0(1), 2/27, 1e-12); assert_equal (ec0(5), 4/27, 1e-12); rc = rocmetrics (y, s, [0 1], "Cost", [0 2; 1 0], ... "AdditionalMetrics", "ExpectedCost"); ecc = rc.Metrics.ExpectedCost(double (rc.Metrics.ClassName) == 0); assert_equal (ecc(1), 4/27, 1e-12); assert_equal (ecc(5), 5/27, 1e-12); ***** test # MATLAB parity: uniform prior reweights the counts y = [1 1 1 1 0 0]'; p = [0.9 0.7 0.4 0.3 0.8 0.2]'; s = [1-p p]; r = rocmetrics (y, s, [0 1], "Prior", "uniform", ... "AdditionalMetrics", "TruePositives"); assert_equal (r.Prior, [0.5 0.5], 1e-12); tp0 = r.Metrics.TruePositives(double (r.Metrics.ClassName) == 0); assert_equal (max (tp0), 4/3, 1e-12); ***** test # explicit weights renormalise the effective counts y = [1 1 1 1 0 0]'; p = [0.9 0.7 0.4 0.3 0.8 0.2]'; s = [1-p p]; w = [1 1 1 1 2 2]'; r = rocmetrics (y, s, [0 1], "Weights", w, ... "AdditionalMetrics", "TruePositives"); assert_equal (r.Prior, [0.5 0.5], 1e-12); tp0 = r.Metrics.TruePositives(double (r.Metrics.ClassName) == 0); assert_equal (max (tp0), 2, 1e-12); ***** test # addMetrics appends without recomputing the curve r = rocmetrics (labels, scores, cn); r = addMetrics (r, "Accuracy"); assert_equal (any (strcmp ("Accuracy", ... r.Metrics.Properties.VariableNames)), true); acc1 = r.Metrics.Accuracy(1); assert_equal (acc1, 2/3, 1e-12); ***** test # PPV is NaN at the origin, NPV is NaN at the all-positive end r = rocmetrics (labels, scores, cn, "AdditionalMetrics", ... {"PositivePredictiveValue","NegativePredictiveValue"}); m1 = r.Metrics(double (r.Metrics.ClassName) == 1, :); assert_equal (isnan (m1.PositivePredictiveValue(1)), true); assert_equal (isnan (m1.NegativePredictiveValue(end)), true); ***** test # cell-array string labels and names y = {"a","a","b","b","c","c"}; r = rocmetrics (y, scores, {"a","b","c"}); assert_equal (r.AUC, [1 1 1], 1e-12); assert_equal (iscellstr (r.Metrics.ClassName), true); ***** test # FixedMetricValues selects nearest thresholds r = rocmetrics (labels, scores, cn, "FixedMetricValues", [Inf 0.4 -0.5]); m1 = r.Metrics(double (r.Metrics.ClassName) == 1, :); assert_equal (numel (m1.Threshold), 3); assert_equal (m1.Threshold(1), 0.85, 1e-12); ***** test # average returns a valid curve for each averaging type r = rocmetrics (labels, scores, cn); [fpr, tpr, thr, auc] = average (r, "macro"); assert_equal (fpr(1), 0, 1e-12); assert_equal (tpr(end), 1, 1e-12); assert_equal (auc >= 0 && auc <= 1, true); [~, ~, ~, aucmi] = average (r, "micro"); assert_equal (aucmi >= 0 && aucmi <= 1, true); ***** error rocmetrics ([1 0], [0.4 0.6]) ***** error ... rocmetrics ([1 0], {1, 2}, [0 1]) ***** error ... rocmetrics ([1 0 1], [0.4 0.6; 0.5 0.5], [0 1]) ***** error ... rocmetrics ([1 0], [0.4 0.6; 0.5 0.5], [0 1 2]) ***** error ... rocmetrics ([1 0], [0.4 0.6; 0.5 0.5], [0 1], "AdditionalMetrics", "foo") ***** error ... rocmetrics ([1 0], [0.4 0.6; 0.5 0.5], [0 1], "Prior", "bogus") ***** error ... rocmetrics ([1 0], [0.4 0.6; 0.5 0.5], [0 1], "NumBootstraps", 100) ***** error ... rocmetrics ([1 0], [0.4 0.6; 0.5 0.5], [0 1], "Zzz", 1) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Model_Evaluation/confusionchart.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Model_Evaluation/confusionchart.m ***** demo close all ## Setting the chart properties Yt = [8 5 6 8 5 3 1 6 4 2 5 3 1 4]'; Yp = [8 5 6 8 5 2 3 4 4 5 5 7 2 6]'; confusionchart (Yt, Yp, 'Title', ... 'Demonstration with summaries','Normalization',... 'absolute','ColumnSummary', 'column-normalized','RowSummary',... 'row-normalized') ***** demo close all ## Cellstr as inputs Yt = {'Positive', 'Positive', 'Positive', 'Negative', 'Negative'}; Yp = {'Positive', 'Positive', 'Negative', 'Negative', 'Negative'}; m = confusionmat (Yt, Yp); confusionchart (m, {'Positive', 'Negative'}); hold off ***** demo close all ## Editing the object properties Yt = {'Positive', 'Positive', 'Positive', 'Negative', 'Negative'}; Yp = {'Positive', 'Positive', 'Negative', 'Negative', 'Negative'}; cm = confusionchart (Yt, Yp); cm.Title = 'This is an example with a green diagonal'; cm.DiagonalColor = [0.4660, 0.6740, 0.1880]; hold off ***** demo close all ## Confusion chart in a uipanel h = uipanel (); Yt = {'Positive', 'Positive', 'Positive', 'Negative', 'Negative'}; Yp = {'Positive', 'Positive', 'Negative', 'Negative', 'Negative'}; cm = confusionchart (h, Yt, Yp); hold off ***** demo close all ## Sorting classes Yt = [8 5 6 8 5 3 1 6 4 2 5 3 1 4]'; Yp = [8 5 6 8 5 2 3 4 4 5 5 7 2 6]'; cm = confusionchart (Yt, Yp, 'Title', ... 'Classes are sorted in ascending order'); cm = confusionchart (Yt, Yp, 'Title', ... 'Classes are sorted according to clusters'); sortClasses (cm, 'cluster'); ***** shared visibility_setting visibility_setting = get (0, 'DefaultFigureVisible'); ***** test set (0, 'DefaultFigureVisible', 'off'); fail ('confusionchart ()', 'Invalid call'); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); fail ('confusionchart ([1 1; 2 2; 3 3])', 'invalid argument'); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); fail ('confusionchart ([1 2], [0 1], ''xxx'', 1)', 'invalid property'); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); fail ('confusionchart ([1 2], [0 1], ''XLabel'', 1)', 'XLabel .* string'); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); fail ('confusionchart ([1 2], [0 1], ''YLabel'', [1 0])', ... '.* YLabel .* string'); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); fail ('confusionchart ([1 2], [0 1], ''Title'', .5)', '.* Title .* string'); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); fail ('confusionchart ([1 2], [0 1], ''FontName'', [])', ... '.* FontName .* string'); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); fail ('confusionchart ([1 2], [0 1], ''FontSize'', ''b'')', ... '.* FontSize .* numeric'); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); fail ('confusionchart ([1 2], [0 1], ''DiagonalColor'', ''h'')', ... '.* DiagonalColor .* color'); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); fail ('confusionchart ([1 2], [0 1], ''OffDiagonalColor'', [])', ... '.* OffDiagonalColor .* color'); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); fail ('confusionchart ([1 2], [0 1], ''Normalization'', '''')', ... '.* invalid .* Normalization'); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); fail ('confusionchart ([1 2], [0 1], ''ColumnSummary'', [])', ... '.* invalid .* ColumnSummary'); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); fail ('confusionchart ([1 2], [0 1], ''RowSummary'', 1)', ... '.* invalid .* RowSummary'); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); fail ('confusionchart ([1 2], [0 1], ''GridVisible'', .1)', ... '.* invalid .* GridVisible'); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); fail ('confusionchart ([1 2], [0 1], ''HandleVisibility'', .1)', ... '.* invalid .* HandleVisibility'); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); fail ('confusionchart ([1 2], [0 1], ''OuterPosition'', .1)', ... '.* invalid .* OuterPosition'); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); fail ('confusionchart ([1 2], [0 1], ''Position'', .1)', ... '.* invalid .* Position'); set (0, 'DefaultFigureVisible', visibility_setting); ***** test set (0, 'DefaultFigureVisible', 'off'); fail ('confusionchart ([1 2], [0 1], ''Units'', .1)', '.* invalid .* Units'); set (0, 'DefaultFigureVisible', visibility_setting); 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Model_Evaluation/cvpartition.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Model_Evaluation/cvpartition.m ***** test custom = [1, 1, 1, 2, 2, 2, 1, 2, 3, 2, 3, 3, 2, 1, 3]'; cv = cvpartition ('CustomPartition', custom); assert_equal (cv.Type, 'kfold'); assert_equal (cv.NumObservations, 15); assert_equal (cv.NumTestSets, 3); assert_equal (cv.TrainSize, [10, 9, 11]); assert_equal (cv.TestSize, [5, 6, 4]); assert_equal (cv.IsCustom, true); assert_equal (cv.IsGrouped, false); assert_equal (cv.IsStratified, false); idx = training (cv, 1); assert_equal (idx, custom != 1); idx = test (cv, 1); assert_equal (idx, custom == 1); idx = training (cv, 2); assert_equal (idx, custom != 2); idx = test (cv, 2); assert_equal (idx, custom == 2); idx = training (cv, 3); assert_equal (idx, custom != 3); idx = test (cv, 3); assert_equal (idx, custom == 3); idx1 = training (cv, 'all'); idx2 = test (cv, 'all'); assert_equal (idx1, ! idx2); ***** test custom = logical ([1, 1, 1, 0, 0, 0, 1, 0, 1, 1])'; cv = cvpartition ('CustomPartition', custom); assert_equal (cv.Type, 'holdout'); assert_equal (cv.NumObservations, 10); assert_equal (cv.NumTestSets, 1); assert_equal (cv.TrainSize, 4); assert_equal (cv.TestSize, 6); assert_equal (cv.IsCustom, true); assert_equal (cv.IsGrouped, false); assert_equal (cv.IsStratified, false); idx = training (cv, 1); assert_equal (idx, custom != 1); assert_equal (idx, training (cv, 'all')); idx = test (cv, 1); assert_equal (idx, custom == 1); assert_equal (idx, test (cv, 'all')); ***** test custom = logical ([1, 0, 0; 0, 1, 0; 1, 0, 0; 0, 0, 1]); cv = cvpartition ('CustomPartition', custom); assert_equal (cv.Type, 'kfold'); assert_equal (cv.NumObservations, 4); assert_equal (cv.NumTestSets, 3); assert_equal (cv.TrainSize, [2, 3, 3]); assert_equal (cv.TestSize, [2, 1, 1]); assert_equal (cv.IsCustom, true); assert_equal (cv.IsGrouped, false); assert_equal (cv.IsStratified, false); idx = training (cv, 1); assert_equal (idx, custom(:,1) == false); idx = test (cv, 1); assert_equal (idx, custom(:,1) == true); idx = training (cv, 2); assert_equal (idx, custom(:,2) == false); idx = test (cv, 2); assert_equal (idx, custom(:,2) == true); assert_equal (! custom, training (cv, 'all')); assert_equal (custom, test (cv, 'all')); ***** test cv = cvpartition ('CustomPartition', [1:8]); assert_equal (cv.Type, 'leaveout'); assert_equal (cv.NumObservations, 8); assert_equal (cv.NumTestSets, 8); assert_equal (cv.TrainSize, [7, 7, 7, 7, 7, 7, 7, 7]); assert_equal (cv.TestSize, [1, 1, 1, 1, 1, 1, 1, 1]); assert_equal (cv.IsCustom, true); assert_equal (cv.IsGrouped, false); assert_equal (cv.IsStratified, false); assert_equal (class (training (cv, 1)), 'logical'); assert_equal (sum (training (cv, 1)), 7); assert_equal (sum (training (cv, 'all')), cv.TrainSize); assert_equal (class (test (cv, 1)), 'logical'); assert_equal (sum (test (cv, 1)), 1); assert_equal (sum (test (cv, 'all')), cv.TestSize); assert_equal (! training (cv, 'all'), test (cv, 'all')); ***** test cv = cvpartition ('CustomPartition', logical (eye (8))); assert_equal (cv.Type, 'leaveout'); assert_equal (cv.NumObservations, 8); assert_equal (cv.NumTestSets, 8); assert_equal (cv.TrainSize, [7, 7, 7, 7, 7, 7, 7, 7]); assert_equal (cv.TestSize, [1, 1, 1, 1, 1, 1, 1, 1]); assert_equal (cv.IsCustom, true); assert_equal (cv.IsGrouped, false); assert_equal (cv.IsStratified, false); assert_equal (class (training (cv, 1)), 'logical'); assert_equal (sum (training (cv, 1)), 7); assert_equal (sum (training (cv, 'all')), cv.TrainSize); assert_equal (class (test (cv, 1)), 'logical'); assert_equal (sum (test (cv, 1)), 1); assert_equal (sum (test (cv, 'all')), cv.TestSize); assert_equal (! training (cv, 'all'), test (cv, 'all')); ***** test cv = cvpartition (10, 'resubstitution'); assert_equal (cv.Type, 'resubstitution'); assert_equal (cv.NumObservations, 10); assert_equal (cv.NumTestSets, 1); assert_equal (cv.TrainSize, 10); assert_equal (cv.TestSize, 10); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, false); assert_equal (cv.IsStratified, false); assert_equal (class (training (cv, 1)), 'logical'); assert_equal (sum (training (cv, 1)), 10); assert_equal (training (cv, 'all'), logical (ones (10, 1))); assert_equal (class (test (cv, 1)), 'logical'); assert_equal (sum (test (cv, 1)), 10); assert_equal (test (cv, 'all'), logical (ones (10, 1))); assert_equal (test (cv), training (cv)); ***** test cv = cvpartition (10, 'leaveout'); assert_equal (cv.Type, 'leaveout'); assert_equal (cv.NumObservations, 10); assert_equal (cv.NumTestSets, 10); assert_equal (cv.TrainSize, ones (1, 10) * 9); assert_equal (cv.TestSize, ones (1, 10)); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, false); assert_equal (cv.IsStratified, false); assert_equal (class (training (cv, 1)), 'logical'); assert_equal (sum (training (cv, 1)), 9); assert_equal (training (cv, 'all'), ! logical (eye (10))); assert_equal (class (test (cv, 1)), 'logical'); assert_equal (sum (test (cv, 1)), 1); assert_equal (test (cv, 'all'), logical (eye (10))); assert_equal (test (cv), ! training (cv)); assert_equal (test (cv, 'all'), ! training (cv, 'all')); ***** test rand ('seed', 5); # for reproducibility cv = cvpartition (10, 'holdout', 0.3); assert_equal (cv.Type, 'holdout'); assert_equal (cv.NumObservations, 10); assert_equal (cv.NumTestSets, 1); assert_equal (cv.TrainSize, 7); assert_equal (cv.TestSize, 3); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, false); assert_equal (cv.IsStratified, false); assert_equal (class (training (cv, 1)), 'logical'); assert_equal (sum (training (cv, 1)), 7); assert_equal (training (cv, 'all'), logical ([1, 0, 1, 1, 0, 1, 1, 1, 0, 1])'); assert_equal (class (test (cv, 1)), 'logical'); assert_equal (sum (test (cv, 1)), 3); assert_equal (test (cv, 'all'), logical ([0, 1, 0, 0, 1, 0, 0, 0, 1, 0])'); assert_equal (test (cv), ! training (cv)); assert_equal (test (cv, 'all'), ! training (cv, 'all')); ***** test cv = cvpartition (10, 'holdout', 4); assert_equal (cv.Type, 'holdout'); assert_equal (cv.NumObservations, 10); assert_equal (cv.NumTestSets, 1); assert_equal (cv.TrainSize, 6); assert_equal (cv.TestSize, 4); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, false); assert_equal (cv.IsStratified, false); assert_equal (class (training (cv, 1)), 'logical'); assert_equal (sum (training (cv, 1)), 6); assert_equal (class (test (cv, 1)), 'logical'); assert_equal (sum (test (cv, 1)), 4); assert_equal (test (cv), ! training (cv)); assert_equal (test (cv, 'all'), ! training (cv, 'all')); ***** test cv = cvpartition (5, 'holdout', 4); assert_equal (cv.Type, 'holdout'); assert_equal (cv.NumObservations, 5); assert_equal (cv.NumTestSets, 1); assert_equal (cv.TrainSize, 1); assert_equal (cv.TestSize, 4); assert_equal (sum (test (cv, 1)), 4); ***** test cv = cvpartition (5, 'holdout', 1); assert_equal (cv.Type, 'holdout'); assert_equal (cv.NumObservations, 5); assert_equal (cv.NumTestSets, 1); assert_equal (cv.TrainSize, 4); assert_equal (cv.TestSize, 1); assert_equal (sum (test (cv, 1)), 1); ***** test cv = cvpartition (5, 'kfold'); assert_equal (cv.Type, 'kfold'); assert_equal (cv.NumObservations, 5); assert_equal (cv.NumTestSets, 5); ***** test cv = cvpartition (20, 'kfold'); assert_equal (cv.Type, 'kfold'); assert_equal (cv.NumObservations, 20); assert_equal (cv.NumTestSets, 10); ***** test cv = cvpartition (10, 'kfold', 5); assert_equal (cv.Type, 'kfold'); assert_equal (cv.NumObservations, 10); assert_equal (cv.NumTestSets, 5); assert_equal (cv.TrainSize, [8, 8, 8, 8, 8]); assert_equal (cv.TestSize, [2, 2, 2, 2, 2]); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, false); assert_equal (cv.IsStratified, false); assert_equal (test (cv, 1), ! training (cv, 1)); assert_equal (test (cv, 'all'), ! training (cv, 'all')); assert_equal (size (test (cv, 'all')), [10, 5]); ***** test grpvar = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 5]; rand ('seed', 5); cv = cvpartition (12, 'kfold', 5, 'GroupingVariables', grpvar); assert_equal (cv.Type, 'kfold'); assert_equal (cv.NumObservations, 12); assert_equal (cv.NumTestSets, 5); assert_equal (cv.TrainSize, [10, 10, 10, 8, 10]); assert_equal (cv.TestSize, [2, 2, 2, 4, 2]); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, true); assert_equal (cv.IsStratified, false); assert_equal (test (cv, 1), ! training (cv, 1)); assert_equal (test (cv, 'all'), ! training (cv, 'all')); assert_equal (size (test (cv, 'all')), [12, 5]); assert_equal (sum (test (cv, 'all')), [2, 2, 2, 4, 2]); assert_equal (sum (training (cv, 'all')), [10, 10, 10, 8, 10]); ***** test grpvar = [1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3]; rand ('seed', 5); cv = cvpartition (12, 'kfold', 3, 'GroupingVariables', grpvar); assert_equal (cv.Type, 'kfold'); assert_equal (cv.NumObservations, 12); assert_equal (cv.NumTestSets, 3); assert_equal (cv.TrainSize, [9, 10, 5]); assert_equal (cv.TestSize, [3, 2, 7]); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, true); assert_equal (cv.IsStratified, false); assert_equal (test (cv, 1), ! training (cv, 1)); assert_equal (test (cv, 'all'), ! training (cv, 'all')); assert_equal (size (test (cv, 'all')), [12, 3]); assert_equal (sum (test (cv, 'all')), [3, 2, 7]); assert_equal (sum (training (cv, 'all')), [9, 10, 5]); ***** test grpvar = [1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3]; rand ('seed', 5); cv = cvpartition (12, 'kfold', 2, 'GroupingVariables', grpvar); assert_equal (cv.Type, 'kfold'); assert_equal (cv.NumObservations, 12); assert_equal (cv.NumTestSets, 2); assert_equal (cv.TrainSize, [6, 6]); assert_equal (cv.TestSize, [6, 6]); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, true); assert_equal (cv.IsStratified, false); assert_equal (test (cv, 1), ! training (cv, 1)); assert_equal (test (cv, 'all'), ! training (cv, 'all')); assert_equal (size (test (cv, 'all')), [12, 2]); assert_equal (sum (test (cv, 'all')), [6, 6]); assert_equal (sum (training (cv, 'all')), [6, 6]); ***** test grpvar = [1, 1, 1, 2, 2, 2, 2, NaN, 2, 3, 3, 3]; rand ('seed', 5); cv = cvpartition (12, 'kfold', 2, 'GroupingVariables', grpvar); assert_equal (cv.Type, 'kfold'); assert_equal (cv.NumObservations, 12); assert_equal (cv.NumTestSets, 2); assert_equal (cv.TrainSize, [6, 5]); assert_equal (cv.TestSize, [5, 6]); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, true); assert_equal (cv.IsStratified, false); idx = ! isnan (grpvar); assert_equal (test (cv, 1)(idx), ! training (cv, 1)(idx)); assert_equal (test (cv, 'all')(idx, :), ! training (cv, 'all')(idx, :)); assert_equal (size (test (cv, 'all')), [12, 2]); assert_equal (sum (test (cv, 'all')), [5, 6]); assert_equal (sum (training (cv, 'all')), [6, 5]); ***** test grpvar = [1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3]; rand ('seed', 5); cv = cvpartition (12, 'kfold', 2, 'GroupingVariables', grpvar); assert_equal (cv.Type, 'kfold'); assert_equal (cv.NumObservations, 12); assert_equal (cv.NumTestSets, 2); assert_equal (cv.TrainSize, [5, 7]); assert_equal (cv.TestSize, [7, 5]); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, true); assert_equal (cv.IsStratified, false); assert_equal (test (cv, 1), ! training (cv, 1)); assert_equal (test (cv, 'all'), ! training (cv, 'all')); assert_equal (size (test (cv, 'all')), [12, 2]); assert_equal (sum (test (cv, 'all')), [7, 5]); assert_equal (sum (training (cv, 'all')), [5, 7]); assert_equal (test (cv, 1)', grpvar == 2); assert_equal (test (cv, 2)', grpvar != 2); ***** test grpvar = [1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3]; rand ('seed', 5); cv = cvpartition (12, 'kfold', 2, 'GroupingVariables', grpvar); assert_equal (cv.Type, 'kfold'); assert_equal (cv.NumObservations, 12); assert_equal (cv.NumTestSets, 2); assert_equal (cv.TrainSize, [7, 5]); assert_equal (cv.TestSize, [5, 7]); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, true); assert_equal (cv.IsStratified, false); assert_equal (test (cv, 1), ! training (cv, 1)); assert_equal (test (cv, 'all'), ! training (cv, 'all')); assert_equal (size (test (cv, 'all')), [12, 2]); assert_equal (sum (test (cv, 'all')), [5, 7]); assert_equal (sum (training (cv, 'all')), [7, 5]); assert_equal (test (cv, 1)', grpvar == 2); assert_equal (test (cv, 2)', grpvar != 2); ***** test grpvar = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3]; rand ('seed', 5); cv = cvpartition (12, 'kfold', 2, 'GroupingVariables', grpvar); assert_equal (cv.Type, 'kfold'); assert_equal (cv.NumObservations, 12); assert_equal (cv.NumTestSets, 2); assert_equal (cv.TrainSize, [7, 5]); assert_equal (cv.TestSize, [5, 7]); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, true); assert_equal (cv.IsStratified, false); assert_equal (test (cv, 1), ! training (cv, 1)); assert_equal (test (cv, 'all'), ! training (cv, 'all')); assert_equal (size (test (cv, 'all')), [12, 2]); assert_equal (sum (test (cv, 'all')), [5, 7]); assert_equal (sum (training (cv, 'all')), [7, 5]); assert_equal (test (cv, 1)', grpvar == 3); assert_equal (test (cv, 2)', grpvar != 3); ***** test status = warning; warning ('off'); cv = cvpartition (5, 'kfold', 5, 'GroupingVariables', {'a';'a';'b';'b';''}); warning (status); assert_equal (cv.Type, 'kfold'); assert_equal (cv.NumObservations, 5); assert_equal (cv.NumTestSets, 2); assert_equal (cv.TrainSize, [2, 2]); assert_equal (cv.TestSize, [2, 2]); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, true); assert_equal (cv.IsStratified, false); idx = ! ismissing ({'a';'a';'b';'b';''}); assert_equal (test (cv, 1)(idx), ! training (cv, 1)(idx)); assert_equal (test (cv, 'all')(idx,:), ! training (cv, 'all')(idx,:)); assert_equal (size (test (cv, 'all')), [5, 2]); assert_equal (sum (test (cv, 'all')), [2, 2]); assert_equal (sum (test (cv, 'all'), 2), [1; 1; 1; 1; 0]); ***** test rand ('seed', 5); cv = cvpartition ([1, 1, 1, 1, 1, 2, 2, 2, 2, 2], 'holdout', 3); assert_equal (cv.Type, 'holdout'); assert_equal (cv.NumObservations, 10); assert_equal (cv.NumTestSets, 1); assert_equal (cv.TrainSize, 7); assert_equal (cv.TestSize, 3); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, false); assert_equal (cv.IsStratified, true); assert_equal (test (cv, 1), ! training (cv, 1)); assert_equal (test (cv), logical ([0, 0, 0, 0, 1, 0, 1, 0, 0, 1])'); ***** test cv = cvpartition ([1, 1, 1, 1, 1, 2, 2, 2, 2, 2], 'holdout', 4); assert_equal (cv.Type, 'holdout'); assert_equal (cv.NumObservations, 10); assert_equal (cv.NumTestSets, 1); assert_equal (cv.TrainSize, 6); assert_equal (cv.TestSize, 4); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, false); assert_equal (cv.IsStratified, true); assert_equal (test (cv, 1), ! training (cv, 1)); assert_equal (sum (test (cv)(1:5)), 2); assert_equal (sum (test (cv)(6:10)), 2); ***** test grpvar = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2]; rand ('seed', 5); cv = cvpartition (grpvar, 'holdout', 4, 'Stratify', false); assert_equal (cv.Type, 'holdout'); assert_equal (cv.NumObservations, 10); assert_equal (cv.NumTestSets, 1); assert_equal (cv.TrainSize, 6); assert_equal (cv.TestSize, 4); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, false); assert_equal (cv.IsStratified, false); assert_equal (test (cv, 1), ! training (cv, 1)); assert_equal (sum (test (cv)(1:5)), 3); assert_equal (sum (test (cv)(6:10)), 1); ***** test cv = cvpartition ([1 1 1 1 1 2 2 2 2 1], 'kfold', 2); assert_equal (cv.Type, 'kfold'); assert_equal (cv.NumObservations, 10); assert_equal (cv.NumTestSets, 2); assert_equal (cv.TrainSize, [5, 5]); assert_equal (cv.TestSize, [5, 5]); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, false); assert_equal (cv.IsStratified, true); assert_equal (test (cv, 1), ! training (cv, 1)); assert_equal (test (cv, 'all'), ! training (cv, 'all')); assert_equal (sum (test (cv, 1)(1:5)), 3); assert_equal (sum (test (cv, 2)(1:5)), 2); assert_equal (sum (test (cv, 1)(6:10)), 2); assert_equal (sum (test (cv, 2)(6:10)), 3); ***** test grpvar = [1 1 1 1 1 2 2 2 2 1]; rand ('seed', 5); cv = cvpartition (grpvar, 'kfold', 2, 'Stratify', false); assert_equal (cv.Type, 'kfold'); assert_equal (cv.NumObservations, 10); assert_equal (cv.NumTestSets, 2); assert_equal (cv.TrainSize, [5, 5]); assert_equal (cv.TestSize, [5, 5]); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, false); assert_equal (cv.IsStratified, false); assert_equal (test (cv, 1), ! training (cv, 1)); assert_equal (test (cv, 'all'), ! training (cv, 'all')); assert_equal (sum (test (cv, 1)(1:5)), 4); assert_equal (sum (test (cv, 2)(1:5)), 1); assert_equal (sum (test (cv, 1)(6:10)), 1); assert_equal (sum (test (cv, 2)(6:10)), 4); ***** test status = warning; warning ('off'); cv = cvpartition ({'a','a','b','b',''}, 'kfold'); warning (status); assert_equal (cv.Type, 'kfold'); assert_equal (cv.NumObservations, 5); assert_equal (cv.NumTestSets, 4); assert_equal (cv.TrainSize, [3, 3, 3, 3]); assert_equal (cv.TestSize, [1, 1, 1, 1]); assert_equal (cv.IsCustom, false); assert_equal (cv.IsGrouped, false); assert_equal (cv.IsStratified, true); idx = ! ismissing ({'a','a','b','b',''}); assert_equal (test (cv, 1)(idx), ! training (cv, 1)(idx)); assert_equal (test (cv, 'all')(idx,:), ! training (cv, 'all')(idx,:)); assert_equal (sum (test (cv, 'all'), 2), [1; 1; 1; 1; 0]); ***** test ## A vector of set indices returns one column per set, not every set. ## The k-fold loop used the whole index vector instead of the loop ## variable, so the comparison broadcast and each pass added a column ## per requested set. c = cvpartition (60, 'KFold', 4); t = test (c, [1, 2]); assert_equal (size (t), [60, 2]); assert_equal (t(:,1), test (c, 1)); assert_equal (t(:,2), test (c, 2)); assert_equal (any (t(:,1) & t(:,2)), false); assert_equal (size (test (c, [1, 3, 4])), [60, 3]); ***** test ## training indexes the same way, and stays the complement of test c = cvpartition (60, 'KFold', 4); r = training (c, [1, 2]); assert_equal (size (r), [60, 2]); assert_equal (r(:,1), training (c, 1)); assert_equal (r, ! test (c, [1, 2])); ***** test ## 'GroupingVariables' with 'HoldOut' holds out whole groups, as ## scikit-learn's GroupShuffleSplit does: no group is split between the ## training and test sets. g = [1 1 1 1 2 2 2 2 3 3 3 3]'; c = cvpartition (12, 'HoldOut', 0.25, 'GroupingVariables', g); assert_equal (c.IsGrouped, true); te = test (c); tr = training (c); assert_equal (any (ismember (unique (g(te)), unique (g(tr)))), false); assert_equal (tr, ! te); ***** test ## 'GroupingVariables' with 'LeaveOut' leaves one whole group out at a ## time, as scikit-learn's LeaveOneGroupOut does. g = [1 1 1 1 2 2 2 2 3 3 3 3]'; c = cvpartition (12, 'LeaveOut', 'GroupingVariables', g); assert_equal (c.IsGrouped, true); assert_equal (c.NumTestSets, 3); assert_equal (c.TestSize, [4, 4, 4]); for s = 1:3 te = test (c, s); assert_equal (numel (unique (g(te))), 1); assert_equal (training (c, s), ! te); endfor assert_equal (size (test (c, 'all')), [12, 3]); ***** test ## the ungrouped forms are untouched c = cvpartition (12, 'LeaveOut'); assert_equal (c.NumTestSets, 12); assert_equal (c.IsGrouped, false); c = cvpartition (12, 'HoldOut', 0.25); assert_equal (c.IsGrouped, false); ***** test ## 'Stratify' and 'GroupingVariables' together keep each group whole ## while spreading the classes across the folds, as scikit-learn's ## StratifiedGroupKFold does. Six single-class groups, two classes. g = [1 1 2 2 3 3 4 4 5 5 6 6]'; y = [1 1 1 1 1 1 2 2 2 2 2 2]'; c = cvpartition (y, 'KFold', 3, 'Stratify', true, ... 'GroupingVariables', g); assert_equal (c.IsStratified, true); assert_equal (c.IsGrouped, true); assert_equal (c.NumTestSets, 3); assert_equal (c.TestSize, [4, 4, 4]); for s = 1:3 te = test (c, s); ## no group is split between training and test assert_equal (any (ismember (unique (g(te)), ... unique (g(training (c, s))))), false); ## and the fold still sees both classes assert_equal (numel (unique (y(te))), 2); endfor ***** test ## 'GroupingVariables' with 'Stratify', false groups without stratifying: ## the stratification variable is simply not used, as asked. g = [1 1 2 2 3 3 4 4]'; y = [1 1 1 1 2 2 2 2]'; c = cvpartition (y, 'KFold', 2, 'Stratify', false, 'GroupingVariables', g); assert_equal (c.IsGrouped, true); assert_equal (c.IsStratified, false); for s = 1:c.NumTestSets te = test (c, s); assert_equal (any (ismember (unique (g(te)), ... unique (g(training (c, s))))), false); endfor ***** test load fisheriris c1 = cvpartition (char (species), "KFold", 3); c2 = cvpartition (species, "KFold", 3); assert_equal (c1.TestSize, c2.TestSize); assert_equal (c1.NumObservations, 150); ***** test c = cvpartition ("aabbcc", "KFold", 3); assert_equal (c.NumObservations, 6); warning: One or more of the unique class values in the stratification variable is not present in one or more folds. warning: called from cvpartition at line 911 column 19 __test__ at line 3 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 4390 column 2 ***** error ... cvpartition (12, 'Resubstitution', 'GroupingVariables', ... [1 1 2 2 3 3 1 1 2 2 3 3]) ***** error cvpartition (2) ***** error ... cvpartition (1, 2, 3, 4, 5, 6, 7, 8) ***** error ... cvpartition ('CustomPartition', 'a') ***** error ... cvpartition ('CustomPartition', [2, 3; 2, 3]) ***** error ... cvpartition ('CustomPartition', false (3, 3, 3)) ***** error ... cvpartition ('CustomPartition', [false, true; true, true; true, false]) ***** error ... cvpartition ('CustomPartition', false (3, 5)) ***** error ... cvpartition (-20, 'LeaveOut') ***** error ... cvpartition (20.5, 'LeaveOut') ***** error ... cvpartition (20, 'HoldOut', [0.2, 0.3]) ***** error ... cvpartition (20, 'HoldOut', 'a') ***** error ... cvpartition (20, 'HoldOut', 0) ***** error ... cvpartition (20, 'HoldOut', -0.1) ***** error ... cvpartition (20, 'HoldOut', 21) ***** error ... cvpartition (20, 'kfold', [2, 3]) ***** error ... cvpartition (20, 'kfold', 'a') ***** error ... cvpartition (20, 'kfold', 2.5) ***** error ... cvpartition (20, 'kfold', 21) ***** error ... cvpartition (10, 'kfold', 3, 'Group') ***** error ... cvpartition (10, 'kfold', 3, 'GroupingVariables') ***** error ... cvpartition (10, 'kfold', 3, 'GroupingVariables', ones (3, 3, 3)) ***** error ... cvpartition (10, 'kfold', 3, 'GroupingVariables', {'a', 'a', 'a', 'b', 'b'}) ***** warning ... cvpartition (5, 'kfold', 3, 'GroupingVariables', {'a', 'a', 'a', 'b', 'b'}); ***** error ... cvpartition (20, 'some') ***** error ... cvpartition ([1, 1, 1, 2, 2], 'kfold', 2, 'strat') ***** error ... cvpartition ([1, 1, 1, 2, 2], 'kfold', 2, 'stratify') ***** error ... cvpartition ([1, 1, 1, 2, 2], 'kfold', 2, 'stratify', [true, true]) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'kfold', 2, 'stratify', 'no') ***** error ... cvpartition ([1, 1, 1, 2, 2], 'holdout', 'a') ***** error ... cvpartition ([1, 1, 1, 2, 2], 'holdout', 'a', 'stratify', true) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'holdout', [0.2, 0.3]) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'holdout', [0.2, 0.3], 'stratify', true) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'holdout', 0) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'holdout', 0, 'stratify', true) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'holdout', -0.1) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'holdout', -0.1, 'stratify', true) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'holdout', 1.2) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'holdout', 1.2, 'stratify', false) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'holdout', 6) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'holdout', 6, 'stratify', false) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'kfold', 'a') ***** error ... cvpartition ([1, 1, 1, 2, 2], 'kfold', 'a', 'stratify', true) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'kfold', [2, 3]) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'kfold', [2, 3], 'stratify', false) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'kfold', 0) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'kfold', 0, 'stratify', true) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'kfold', 1.5) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'kfold', 1.5, 'stratify', true) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'kfold', 6) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'kfold', 6, 'stratify', true) ***** error ... cvpartition ([1, 1, 1, 2, 2], 'leaveout') ***** error ... cvpartition ([1, 1, 1, 2, 2], 'resubstitution') ***** error ... cvpartition ([1, 1, 1, 2, 2], 'some') ***** error ... cvpartition ({1, 1; 2, 2}, 'kfold') ***** test c = cvpartition (60, 'KFold', 5); assert_equal (test (repartition (c, 42), 1), test (repartition (c, 42), 1)); assert_equal (isequal (test (repartition (c, 42), 1), ... test (repartition (c, 43), 1)), false); ***** test c = cvpartition (60, 'KFold', 5); assert_equal (test (repartition (c, [1 2 3]), 1), ... test (repartition (c, [1 2 3]), 1)); ***** test c = cvpartition (60, 'KFold', 5); rand ('twister', 5); expect = rand (1, 4); rand ('twister', 5); repartition (c, 42); assert_equal (rand (1, 4), expect); rand ('twister', 5); repartition (c, [1 2 3]); assert_equal (rand (1, 4), expect); ***** test c = cvpartition (60, 'KFold', 5); rand ('twister', 5); a = test (repartition (c, 42), 1); rand ('twister', 777); assert_equal (test (repartition (c, 42), 1), a); ***** test c = cvpartition (60, 'KFold', 5); rand ('twister', 5); untouched = rand (1, 4); rand ('twister', 5); repartition (c); assert_equal (isequal (rand (1, 4), untouched), false); ***** error ... repartition (cvpartition ('CustomPartition', [1,1,2,2,3,3])) ***** error ... repartition (cvpartition ([1 1 1 1 1 2 2 2 2 1], 'kfold', 2, 'Stratify', true), 'legacy') ***** error ... repartition (cvpartition (20, 'Leaveout', 0.2), 'legacy') ***** error ... repartition (cvpartition (20, 'Leaveout', 0.2), 'asd') ***** error ... repartition (cvpartition (20, 'Leaveout', 0.2), 2+i) ***** error ... repartition (cvpartition (20, 'KFold', 5), [34, 56; 2, 3]) ***** error ... test (cvpartition (20, 'kfold'), 2, 3) ***** error ... test (cvpartition (20, 'kfold'), 0) ***** error ... test (cvpartition (20, 'kfold'), 1.5) ***** error ... test (cvpartition (20, 'kfold'), [1, 1.5]) ***** error ... test (cvpartition (20, 'kfold'), [2, 3; 2, 3]) ***** error ... test (cvpartition (20, 'kfold'), 21) ***** error ... test (cvpartition (20, 'kfold'), [18, 21]) ***** error ... training (cvpartition (20, 'kfold'), 2, 3) ***** error ... training (cvpartition (20, 'kfold'), 0) ***** error ... training (cvpartition (20, 'kfold'), 1.5) ***** error ... training (cvpartition (20, 'kfold'), [1, 1.5]) ***** error ... training (cvpartition (20, 'kfold'), [2, 3; 2, 3]) ***** error ... training (cvpartition (20, 'kfold'), 21) ***** error ... training (cvpartition (20, 'kfold'), [18, 21]) ***** test ## 1. Stratified K-Fold: Basic Text Labels species = [repmat({'Setosa'}, 10, 1); repmat({'Versicolor'}, 10, 1)]; rand ('state', 42); c = cvpartition (species, 'KFold', 2); T = summary (c); assert_equal (height (T), 10); assert_equal (all (ismember ({'Set', 'SetSize', 'StratificationLabel', ... 'StratificationCount', 'PercentInSet'}, ... T.Properties.VariableNames)), true); ## Check Output Type (String Array) and Counts if (exist ('string', 'class')) assert_equal (isa (T.Set, 'string'), true); assert_equal (isa (T.StratificationLabel, 'string'), true); mask = (T.Set == 'all') & (T.StratificationLabel == 'Setosa'); else ## Fallback for older environments mask = strcmp (T.Set, 'all') & strcmp (T.StratificationLabel, 'Setosa'); endif assert_equal (T.StratificationCount(mask), 10); ***** test ## 2. Grouped K-Fold: Basic Numeric Labels groups = [1; 1; 1; 2; 2; 3; 3; 3; 3; 3]; rand ('state', 100); c = cvpartition (numel (groups), 'KFold', 2, 'GroupingVariables', groups); T = summary (c); assert_equal (any (strcmp ('GroupLabel', T.Properties.VariableNames)), true); ## Verify Group Integrity if (iscell (T.GroupLabel)) vals = cell2mat (T.GroupLabel); else vals = T.GroupLabel; endif mask_g3 = (vals == 3); if (exist ('string', 'class')) mask_t1 = (T.Set == 'test1'); else mask_t1 = strcmp (T.Set, 'test1'); endif count_g3 = T.GroupCount(mask_g3 & mask_t1); assert_equal (count_g3 == 5 || count_g3 == 0, true); ***** test ## 3. Grouped K-Fold: Matrix Grouping g1 = [1; 1; 1; 2; 2; 2]; g2 = [1; 1; 2; 1; 2; 2]; groups = [g1, g2]; c = cvpartition (6, 'KFold', 2, 'GroupingVariables', groups); T = summary (c); ## 4 unique groups * 5 sets (all + 2 train + 2 test) assert_equal (height (T), 20); ***** test ## 4. Stratified Holdout: Basic species = [repmat({'A'}, 10, 1); repmat({'B'}, 10, 1)]; c = cvpartition (species, 'Holdout', 0.5); T = summary (c); sets = unique (T.Set); assert_equal (numel (sets), 3); ## all, train1, test1 ***** test ## 5. Mathematical Consistency: Percentages classes = [1; 1; 2; 2; 3; 3]; c = cvpartition (classes, 'KFold', 2); T = summary (c); if (exist ('string', 'class')) mask_all = (T.Set == 'all'); mask_tr1 = (T.Set == 'train1'); else mask_all = strcmp (T.Set, 'all'); mask_tr1 = strcmp (T.Set, 'train1'); endif assert_equal (sum (T.PercentInSet(mask_all)), 100, 1e-10); assert_equal (sum (T.PercentInSet(mask_tr1)), 100, 1e-10); ***** test ## 6. Mathematical Consistency: Set Sizes N = 20; c = cvpartition (ones (N, 1), 'KFold', 4); T = summary (c); if (exist ('string', 'class')) mask_tr1 = (T.Set == 'train1'); mask_ts1 = (T.Set == 'test1'); else mask_tr1 = strcmp (T.Set, 'train1'); mask_ts1 = strcmp (T.Set, 'test1'); endif size_tr1 = T.SetSize(find (mask_tr1, 1)); size_ts1 = T.SetSize(find (mask_ts1, 1)); assert_equal (size_tr1 + size_ts1, N); ***** test ## 7. Logical Grouping Variables groups = [true; true; true; false; false]; c = cvpartition (5, 'KFold', 2, 'GroupingVariables', groups); T = summary (c); assert_equal (height (T), 2 * 5); if (iscell (T.GroupLabel)) u_labels = unique (cell2mat (T.GroupLabel)); else u_labels = unique (T.GroupLabel); endif assert_equal (numel (u_labels), 2); ***** test ## 8. Char Array Grouping Variables groups = ['A'; 'A'; 'B'; 'B'; 'C']; c = cvpartition (5, 'KFold', 2, 'GroupingVariables', groups); T = summary (c); assert_equal (height (T), 3 * 5); assert_equal (any (strcmp ('GroupLabel', T.Properties.VariableNames)), true); ***** test ## 9. Floating Point Grouping Variables groups = [1.1; 1.1; 2.2; 2.2]; c = cvpartition (4, 'KFold', 2, 'GroupingVariables', groups); T = summary (c); if (iscell (T.GroupLabel)) vals = cell2mat (T.GroupLabel); else vals = T.GroupLabel; endif assert_equal (any (abs (vals - 1.1) < 1e-10), true); assert_equal (any (abs (vals - 2.2) < 1e-10), true); ***** test ## 10. Negative Numeric Grouping groups = [-5; -5; -10; -10]; c = cvpartition (4, 'KFold', 2, 'GroupingVariables', groups); T = summary (c); assert_equal (height (T), 2 * 5); ***** test ## 11. Missing Values in Stratification (NaN) classes = [1; 1; 2; 2; NaN; NaN]; c = cvpartition (classes, 'KFold', 2); T = summary (c); if (exist ('string', 'class')) mask_all = (T.Set == 'all'); else mask_all = strcmp (T.Set, 'all'); endif total_obs = T.SetSize(find (mask_all, 1)); assert_equal (total_obs, 4); ***** test ## 12. Missing Values in Grouping (NaN) groups = [1; 1; 2; 2; NaN]; c = cvpartition (5, 'KFold', 2, 'GroupingVariables', groups); T = summary (c); if (exist ('string', 'class')) mask_all = (T.Set == 'all'); else mask_all = strcmp (T.Set, 'all'); endif assert_equal (T.SetSize(find (mask_all, 1)), 4); ***** test ## 13. Unbalanced Stratification species = [repmat({'C1'}, 90, 1); repmat({'C2'}, 10, 1)]; c = cvpartition (species, 'KFold', 2); T = summary (c); if (exist ('string', 'class')) mask_ts1 = (T.Set == 'test1'); subT = T(mask_ts1, :); c1_count = subT.StratificationCount(subT.StratificationLabel == 'C1'); c2_count = subT.StratificationCount(subT.StratificationLabel == 'C2'); else mask_ts1 = strcmp (T.Set, 'test1'); subT = T(mask_ts1, :); c1_count = subT.StratificationCount(strcmp (subT.StratificationLabel, 'C1')); c2_count = subT.StratificationCount(strcmp (subT.StratificationLabel, 'C2')); endif assert_equal (c1_count == 45, true); assert_equal (c2_count == 5, true); ***** test ## 14. Single Observation per Group (Edge Case) groups = [1; 2; 3; 4]; c = cvpartition (4, 'KFold', 2, 'GroupingVariables', groups); T = summary (c); if (exist ('string', 'class')) mask_ts1 = (T.Set == 'test1'); else mask_ts1 = strcmp (T.Set, 'test1'); endif counts = T.GroupCount(mask_ts1); assert_equal (sum (counts == 1), 2); assert_equal (sum (counts == 0), 2); ***** test ## 15. Set Name Generation Verification species = [1; 1; 2; 2]; c = cvpartition (species, 'KFold', 2); T = summary (c); set_names = unique (T.Set); expected = {'all'; 'train1'; 'test1'; 'train2'; 'test2'}; if (exist ('string', 'class')) ## Convert string array to cell for sort comparison assert_equal (sort (cellstr (set_names)), sort (expected)); else assert_equal (sort (set_names), sort (expected)); endif ***** test ## 16. Label Column Consistency groups = ['A'; 'B']; c = cvpartition (2, 'KFold', 2, 'GroupingVariables', groups); T = summary (c); if (exist ('string', 'class')) assert_equal (isa (T.GroupLabel, 'string'), true); else assert_equal (iscellstr (T.GroupLabel), true); endif ***** test ## 17. Valid "Blank" Labels (Space) - FIX APPLIED species = {'A'; 'A'; ' '; ' '}; c = cvpartition (species, 'KFold', 2); T = summary (c); if (exist ('string', 'class')) labels = cellstr (T.StratificationLabel); sets = cellstr (T.Set); assert_equal (any (strcmp (labels, ' ')), true); mask_space = strcmp (labels, ' '); mask_all = strcmp (sets, 'all'); else assert_equal (any (strcmp (T.StratificationLabel, ' ')), true); mask_space = strcmp (T.StratificationLabel, ' '); mask_all = strcmp (T.Set, 'all'); endif assert_equal (sum (T.StratificationCount(mask_space & mask_all)), 2); ***** test ## 18. Large K (Leave-One-Out Simulation) - FIX APPLIED species = [1; 1; 2; 2]; warn_state = warning ("off", 'all'); c = cvpartition (species, 'KFold', 4); warning (warn_state); T = summary (c); assert_equal (height (T), 18); if (exist ('string', 'class')) mask_test = startsWith (cellstr(T.Set), 'test'); else mask_test = strncmp (T.Set, 'test', 4); endif assert_equal (all (T.SetSize(mask_test) == 1), true); ***** test ## 19. Repeated Holdout Integrity species = [1; 1; 2; 2]; rand ('state', 42); c = cvpartition (species, 'Holdout', 0.5); T = summary (c); if (exist ('string', 'class')) mask_ts1 = (T.Set == 'test1'); else mask_ts1 = strcmp (T.Set, 'test1'); endif size_ts1 = T.SetSize(find (mask_ts1, 1)); assert_equal (size_ts1, 2); ***** test ## 20. Empty String Handling (Missing Data) species = {'A'; 'A'; ''; ''}; c = cvpartition (species, 'KFold', 2); T = summary (c); if (exist ('string', 'class')) assert_equal (! any (T.StratificationLabel == ''), true); mask_all = (T.Set == 'all'); else assert_equal (! any (strcmp (T.StratificationLabel, '')), true); mask_all = strcmp (T.Set, 'all'); endif total_rows = T.SetSize(find (mask_all, 1)); assert_equal (total_rows, 2); ***** test ## 21. Basic Unstacking (Stratified K-Fold) species = [repmat({'Alpha'}, 10, 1); repmat({'Beta'}, 10, 1)]; c = cvpartition (species, 'KFold', 2); T = summary (c); T_wide = unstack (T(:, 1:4), 'StratificationCount', 'StratificationLabel'); ## Check dimensions: 3 sets (all, train1, test1, etc) x (Set+SetSize + 2 Labels) assert_equal (height (T_wide), 5); assert_equal (width (T_wide), 4); assert_equal (all (ismember ({'Alpha', 'Beta'}, T_wide.Properties.VariableNames)), true); ***** test ## 22. Data Integrity Check (Row Sums) species = [repmat({'Control'}, 20, 1); repmat({'Treatment'}, 80, 1)]; c = cvpartition (species, 'Holdout', 0.25); T = summary (c); T_wide = unstack (T(:, 1:4), 'StratificationCount', 'StratificationLabel'); row_sums = T_wide.Control + T_wide.Treatment; assert_equal (all (row_sums == T_wide.SetSize), true); ***** test ## 23. Unstacking Grouped Data (Numeric Labels) groups = [1; 1; 2; 2; 2]; c = cvpartition (5, 'KFold', 2, 'GroupingVariables', groups); T = summary (c); T_wide = unstack (T(:, 1:4), 'GroupCount', 'GroupLabel'); ## Check if numeric columns were created successfully col_names = T_wide.Properties.VariableNames; assert_equal (any (cellfun (@(x) ! isempty (strfind (x, '1')), col_names)), true); assert_equal (any (cellfun (@(x) ! isempty (strfind (x, '2')), col_names)), true); ***** test ## 24. Unstacking with Missing/NaN Groups groups = [1; 1; 2; 2; NaN]; c = cvpartition (5, 'KFold', 2, 'GroupingVariables', groups); T = summary (c); T_wide = unstack (T(:, 1:4), 'GroupCount', 'GroupLabel'); ## Should only have columns for 1 and 2, not NaN or 'undefined' assert_equal (width (T_wide), 4); ## Set, SetSize, x1, x2 ***** test ## 25. Unstacking String Array Inputs species = {'Red'; 'Blue'; 'Red'; 'Blue'}; c = cvpartition (species, 'KFold', 2); T = summary (c); ## Verify input is actually string before unstacking checks if (exist ('string', 'class')) assert_equal (isa (T.Set, 'string'), true); endif T_wide = unstack (T(:, 1:4), 'StratificationCount', 'StratificationLabel'); ## Check the 'all' row count for Red assert_equal (T_wide.Red(strcmp(cellstr(T_wide.Set), 'all')) == 2, true); ***** test ## 26. Large K Unstacking (Many Rows) species = [repmat({'High'}, 10, 1); repmat({'Low'}, 10, 1)]; c = cvpartition (species, 'KFold', 10); T = summary (c); T_wide = unstack (T(:, 1:4), 'StratificationCount', 'StratificationLabel'); ## 10 folds * 2 (train/test) + 1 (all) = 21 rows assert_equal (height (T_wide), 21); ***** test ## 27. Unstacking with Special Characters in Labels species = {'Type A'; 'Type A'; 'Type-B'; 'Type-B'}; c = cvpartition (species, 'KFold', 2); T = summary (c); T_wide = unstack (T(:, 1:4), 'StratificationCount', 'StratificationLabel'); vnames = T_wide.Properties.VariableNames; ## Check if spaces/dashes were handled/preserved in some valid form assert_equal (numel (vnames), 4); ***** test ## 28. Verification of 'all' row logic after Unstacking species = [repmat({'Yes'}, 50, 1); repmat({'No'}, 50, 1)]; c = cvpartition (species, 'Holdout', 0.2); T = summary (c); T_wide = unstack (T(:, 1:4), 'StratificationCount', 'StratificationLabel'); mask = strcmp (cellstr (T_wide.Set), 'all'); assert_equal (T_wide.Yes(mask) == 50, true); assert_equal (T_wide.No(mask) == 50, true); ***** test ## 29. Robustness against re-ordering species = {'Left'; 'Left'; 'Right'; 'Right'}; c = cvpartition (species, 'Holdout', 0.5); T = summary (c); T_shuffled = T([3, 1, 2], :); T_wide = unstack (T_shuffled(:, 1:4), 'StratificationCount', 'StratificationLabel'); mask = strcmp (cellstr (T_wide.Set), 'all'); assert_equal (T_wide.Left(mask) == 2, true); ***** error c = cvpartition (20, 'KFold', 5); summary (c); ***** error c = cvpartition (10, 'LeaveOut'); summary (c); 148 tests, 148 passed, 0 known failure, 0 skipped [inst/Model_Evaluation/crossval.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Model_Evaluation/crossval.m ***** demo ## Determine the optimal number of clusters using cross-validation ## Declare a function to compute the sum of squared distances ## between data points and a varying number of clusters. function D = dist2clusters (X, Y, k) [Z, Zmu, Zstd] = zscore (X); [~, C] = kmeans (Z, k); ZY = (Y - Zmu) ./ Zstd; d = pdist2 (C, ZY, 'euclidean', 'Smallest', 1); D = sum (d .^ 2); endfunction load fisheriris for k = 1:8 fcn = @(X, Y) dist2clusters (X, Y, k); distances = crossval (fcn, meas); cvdist(k) = sum (distances); endfor plot (cvdist) xlabel ('Number of Clusters') ylabel ('CV Sum of Squared Distances') xlim ([1,8]); ***** test function yfit = regf (Xtrain, ytrain, Xtest) b = regress (ytrain, Xtrain); yfit = Xtest * b; endfunction load carsmall data = [Acceleration Horsepower Weight MPG]; data(any (isnan (data),2),:) = []; y = data(:,4); X = [ones(length(y),1) data(:,1:3)]; rand ('seed', 3); cvMSE = crossval ('mse',X,y,'Predfun',@regf); assert_equal (cvMSE, 18.720, 1e-3); ***** test ## With a response variable the handle is called over both, as ## f (Xtrain, Ytrain, Xtest, Ytest); Y used to be dropped and the handle ## called with two arguments, so any supervised handle was refused. X = [1, 2; 2, 3; 3, 4; 4, 5; 5, 6; 6, 7; 7, 8; 8, 9; 9, 10; 10, 11]; Y = (1:10)'; f = @(xtr, ytr, xte, yte) size (xtr, 1) + size (xte, 1) + numel (ytr) + numel (yte); r = crossval (f, X, Y, 'KFold', 5); assert_equal (size (r), [1, 5]); assert_equal (unique (r), 20); ***** error ... crossval ('fe', rand (10, 1), rand (10, 1), 1); ***** error ... crossval ('mse', rand (10, 1), rand (10, 1), 1); ***** error ... crossval ('mse', rand (10, 1), 'Predfun', @(x,y) x + y); ***** error ... crossval ('mse', rand (10, 3), rand (10, 1), 'Predfun', @(x,y) sum (x + y)); ***** error ... crossval ('mse', rand (10, 3), rand (10, 1), 'Predfun', @(x,y,z) sum (x + y)); ***** error crossval (@(x) x); ***** error ... crossval (@(x) x, rand (10, 3), rand (10, 1)); ***** error ... crossval (@(xtr, ytr, xte, yte) [xte, yte], rand (10, 3), rand (10, 1)); ***** error crossval ({1}, 1, 1); ***** error ... crossval (@(x,y) sum ([x; y]), rand (10, 3), 'Holdout', 0.1, 'Leaveout', true) ***** error ... crossval (@(x,y) sum ([x; y]), rand (10, 3), 'Partition', cvpartition (10, 'Leaveout'), 'Stratify', true) 13 tests, 13 passed, 0 known failure, 0 skipped [inst/Model_Evaluation/perfcurve.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Model_Evaluation/perfcurve.m ***** demo ## ROC curve for scores with a known positive class scores = [0.9 0.8 0.7 0.6 0.55 0.5 0.4 0.3 0.2 0.1]; labels = [1 1 0 1 0 1 0 0 1 0]; [X, Y, T, AUC] = perfcurve (labels, scores, 1); plot (X, Y, "b-o"); xlabel ("FPR"); ylabel ("TPR"); title (sprintf ("ROC curve (AUC = %.2f)", AUC)); ***** shared labels, scores labels = [1 1 0 1 0 1 0 0 1 0]; scores = [0.95 0.9 0.85 0.7 0.7 0.6 0.55 0.4 0.35 0.2]; ***** test # MATLAB parity: default ROC curve, thresholds, AUC and OPTROCPT [X, Y, T, AUC, OPT] = perfcurve (labels, scores, 1); assert_equal (X, [0 0 0 0.2 0.4 0.4 0.6 0.8 0.8 1]', 1e-12); assert_equal (Y, [0 0.2 0.4 0.4 0.6 0.8 0.8 0.8 1 1]', 1e-12); assert_equal (T, [0.95 0.95 0.9 0.85 0.7 0.6 0.55 0.4 0.35 0.2]', 1e-12); assert_equal (AUC, 0.7, 1e-12); assert_equal (OPT, [0 0.4], 1e-12); ***** test # MATLAB parity: precision-recall and its NaN at the origin [Xr, Yr] = perfcurve (labels, scores, 1, "XCrit", "reca", "YCrit", "prec"); assert_equal (Xr, [0 0.2 0.4 0.4 0.6 0.8 0.8 0.8 1 1]', 1e-12); assert_equal (Yr(2:end), [1 1 2/3 0.6 2/3 4/7 0.5 5/9 0.5]', 1e-12); assert_equal (isnan (Yr(1)), true); ***** test # MATLAB parity: accuracy and specificity/sensitivity criteria [~, Ya] = perfcurve (labels, scores, 1, "YCrit", "accu"); assert_equal (Ya, [0.5 0.6 0.7 0.6 0.6 0.7 0.6 0.5 0.6 0.5]', 1e-12); [Xs, Ys] = perfcurve (labels, scores, 1, "XCrit", "spec", "YCrit", "sens"); assert_equal (Xs, [1 1 1 0.8 0.6 0.6 0.4 0.2 0.2 0]', 1e-12); assert_equal (Ys, [0 0.2 0.4 0.4 0.6 0.8 0.8 0.8 1 1]', 1e-12); ***** test # MATLAB parity: weighted curve, AUC and OPTROCPT w = [2 1 1 1 1 1 1 1 1 2]; [Xw, Yw, Tw, AUCw, OPTw] = perfcurve (labels, scores, 1, "Weights", w); assert_equal (Xw, [0 0 0 1 2 2 3 4 4 6]'/6, 1e-12); assert_equal (Yw, [0 2 3 3 4 5 5 5 6 6]'/6, 1e-12); assert_equal (AUCw, 0.791666666666667, 1e-12); assert_equal (OPTw, [0 0.5], 1e-12); ***** test # MATLAB parity: OPTROCPT shifts with a non-default cost matrix [~, ~, ~, ~, OPTc] = perfcurve (labels, scores, 1, "Cost", [0 1; 2 0]); assert_equal (OPTc, [0 0.4], 1e-12); ***** test # MATLAB parity: TVals selects nearest thresholds [Xt, Yt, Tt] = perfcurve (labels, scores, 1, "TVals", [Inf 0.8 0.6 0.4 0.2]); assert_equal (Xt, [0 0.2 0.4 0.8 1]', 1e-12); assert_equal (Yt, [0 0.4 0.8 0.8 1]', 1e-12); assert_equal (Tt, [0.95 0.85 0.6 0.4 0.2]', 1e-12); ***** test # MATLAB parity: XVals selects floor points plus the origin [Xv, Yv, Tv] = perfcurve (labels, scores, 1, "XVals", [0 0.25 0.5 0.75 1]); assert_equal (Xv, [0 0 0.2 0.4 0.6 1]', 1e-12); assert_equal (Yv, [0 0.4 0.4 0.8 0.8 1]', 1e-12); assert_equal (Tv, [0.95 0.9 0.85 0.6 0.55 0.2]', 1e-12); ***** test # MATLAB parity: cell-array string labels labels2 = {"g","g","b","g","b","g","b","b","g","b"}; [X, Y, T, AUC] = perfcurve (labels2, scores, "g"); assert_equal (AUC, 0.7, 1e-12); assert_equal (X, [0 0 0 0.2 0.4 0.4 0.6 0.8 0.8 1]', 1e-12); ***** test # AUC of a perfectly separable problem is 1 sc = [0.9 0.8 0.7 0.6 0.3 0.2 0.1 0.05]; lb = [1 1 1 1 0 0 0 0]; [~, ~, ~, auc] = perfcurve (lb, sc, 1); assert_equal (auc, 1, 1e-12); ***** test # bootstrap: shapes, point estimate preserved, bounds bracket it (BCa) rand ("seed", 42); randn ("seed", 42); [X, Y, T, AUC, OPT, SUBY, SUBYN] = ... perfcurve (labels, scores, 1, "NBoot", 200); assert_equal (columns (Y), 3); assert_equal (size (AUC), [1, 3]); assert_equal (Y(:,1), [0 0.2 0.4 0.4 0.6 0.8 0.8 0.8 1 1]', 1e-12); assert_equal (all (Y(:,2) <= Y(:,1) + 1e-9), true); # lower <= est assert_equal (all (Y(:,3) >= Y(:,1) - 1e-9), true); # upper >= est assert_equal (AUC(2) <= AUC(1) && AUC(1) <= AUC(3), true); assert_equal (isequal (SUBY, Y), true); ***** test # bootstrap: percentile bounds also run and bracket the AUC estimate rand ("seed", 7); randn ("seed", 7); [~, Y, ~, AUC] = perfcurve (labels, scores, 1, "NBoot", 200, ... "BootType", "percentile"); assert_equal (columns (Y), 3); assert_equal (AUC(2) <= AUC(1) && AUC(1) <= AUC(3), true); ***** error perfcurve (1, 2) ***** test ## Logical labels are accepted, as MATLAB does, and give the same curve as ## the equivalent numeric labels. s = [0.9; 0.8; 0.7; 0.6; 0.5; 0.4; 0.3; 0.2]; l = [1; 1; 1; 0; 1; 0; 0; 0]; [xn, yn, tn, an] = perfcurve (l, s, 1); [xg, yg, tg, ag] = perfcurve (logical (l), s, true); assert_equal (xg, xn); assert_equal (yg, yn); assert_equal (tg, tn); assert_equal (ag, an); ## and the curve is MATLAB's, not merely self-consistent assert_equal (xg(:)', [0, 0, 0, 0, 0.25, 0.25, 0.5, 0.75, 1], 1e-12); ***** error ... perfcurve ([1 0], ones (2, 2), 1) ***** error ... perfcurve ([1 0 1], [0.5 0.4], 1) ***** error ... perfcurve (struct ('a', 1), [0.5 0.4], 1) ***** error ... perfcurve ({1, 2}, [0.5 0.4], 1) ***** error ... perfcurve ([1 1 1], [0.5 0.4 0.3], 1) ***** error ... perfcurve ([1 0], [0.5 0.4], 1, "YCrit", "foo") ***** error ... perfcurve ([1 0], [0.5 0.4], 1, "Cost", [0 1 0]) ***** error ... perfcurve ([1 0], [0.5 0.4], 1, "NBoot", -5) ***** error ... perfcurve ([1 0], [0.5 0.4], 1, "Alpha", 1.5) 22 tests, 22 passed, 0 known failure, 0 skipped [inst/Model_Evaluation/ConfusionMatrixChart.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Model_Evaluation/ConfusionMatrixChart.m ***** demo ## Create a simple ConfusionMatrixChart Object cm = ConfusionMatrixChart (gca, [1 2; 1 2], {'A','B'}, {'XLabel','LABEL A'}) NormalizedValues = cm.NormalizedValues ClassLabels = cm.ClassLabels ***** test hf = figure ('visible', 'off'); unwind_protect cm = ConfusionMatrixChart (gca, [1 2; 1 2], {'A','B'}, {'XLabel','LABEL A'}); assert_equal (isa (cm, 'ConfusionMatrixChart'), true); unwind_protect_cleanup close (hf); end_unwind_protect 1 test, 1 passed, 0 known failure, 0 skipped [inst/Plotting/parallelcoords.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/parallelcoords.m ***** demo ## Parallel coordinates plot of Fisher's iris data, grouped by species. load fisheriris; parallelcoords (meas, "Group", species, "Labels", ... {"SL", "SW", "PL", "PW"}); ***** demo ## The same data with median and quartile lines per species. load fisheriris; parallelcoords (meas, "Group", species, "Quantile", 0.25, ... "Standardize", "on"); ***** test hf = figure ("visible", "off"); unwind_protect X = [1 2 3; 4 5 6; 7 8 9; 2 1 5]; h = parallelcoords (X); assert_equal (numel (h), 4); assert_equal (get (h(1), "xdata"), [1 2 3]); assert_equal (get (h(1), "ydata"), [1 2 3]); assert_equal (get (h(2), "ydata"), [4 5 6]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # Standardize "on" (z-score each column) hf = figure ("visible", "off"); unwind_protect X = [1 2 3; 4 5 6; 7 8 9; 2 1 5]; h = parallelcoords (X, "Standardize", "on"); assert_equal (get (h(1), "ydata"), [-0.94491, -0.63246, -1.1], 1e-4); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # Standardize "pca" hf = figure ("visible", "off"); unwind_protect X = [1 2 3; 4 5 6; 7 8 9; 2 1 5]; h = parallelcoords (X, "Standardize", "pca"); assert_equal (get (h(1), "ydata")(1:2), [-4.1082, 0.9670], 1e-4); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # Quantile mode: median, alpha, 1-alpha lines hf = figure ("visible", "off"); unwind_protect X = [1 2 3; 4 5 6; 7 8 9; 2 1 5]; h = parallelcoords (X, "Quantile", 0.25); assert_equal (numel (h), 3); assert_equal (get (h(1), "ydata"), [3, 3.5, 5.5], 1e-12); assert_equal (get (h(2), "ydata"), [1.5, 1.5, 4], 1e-12); assert_equal (get (h(3), "ydata"), [5.5, 6.5, 7.5], 1e-12); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # coordinate tick labels hf = figure ("visible", "off"); unwind_protect h = parallelcoords ([1 2 3; 4 5 6], "Labels", {"a", "b", "c"}); assert_equal (get (gca, "xtick"), [1 2 3]); assert_equal (get (gca, "xticklabel"), {"a"; "b"; "c"}); unwind_protect_cleanup close (hf); end_unwind_protect ***** error parallelcoords () ***** error parallelcoords ({1}) ***** error ... parallelcoords (ones (3, 2), "Group") ***** error ... parallelcoords (ones (3, 2), "bogus", 1) ***** error ... parallelcoords (ones (3, 2), "Standardize", "xxx") ***** error ... parallelcoords (ones (3, 2), "Group", [1 2]) ***** error ... parallelcoords (ones (3, 2), "Quantile", 0) ***** test nfig = numel (get (0, "children")); fail ('parallelcoords (ones (3, 2), "Quantile", 0)', ... 'parallelcoords: Quantile ALPHA must be a scalar in .0,1..'); assert_equal (numel (get (0, "children")), nfig); 13 tests, 13 passed, 0 known failure, 0 skipped [inst/Plotting/ppplot.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/ppplot.m ***** test hf = figure ('visible', 'off'); unwind_protect ppplot ([2 3 3 4 4 5 6 5 6 7 8 9 8 7 8 9 0 8 7 6 5 4 6 13 8 15 9 9]); unwind_protect_cleanup close (hf); end_unwind_protect ***** error ppplot () ***** error ppplot (ones (2,2)) ***** error ppplot (1, 2) ***** error ppplot ([1 2 3 4], 2) 5 tests, 5 passed, 0 known failure, 0 skipped [inst/Plotting/parallelplot.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/parallelplot.m ***** demo ## The four measurements of each iris flower, joined across four rulers. load fisheriris parallelplot (meas); ***** demo ## Grouped by species, with the columns named, as z-scores on one scale. load fisheriris parallelplot (meas, 'GroupData', species, 'CoordinateTickLabels', ... {'Sepal length', 'Sepal width', 'Petal length', ... 'Petal width'}, 'DataNormalization', 'zscore'); ***** demo ## From a table, with a variable of categories as a coordinate. load carsmall t = table (MPG, Horsepower, Weight, categorical (cellstr (Origin)), ... 'VariableNames', {'MPG', 'Horsepower', 'Weight', 'Origin'}); parallelplot (t, 'GroupVariable', 'Origin', 'CoordinateVariables', ... {'MPG', 'Horsepower', 'Weight'}); ***** test hf = figure ('visible', 'off'); unwind_protect parallelplot (magic (4)); tag = 'stats.chart.ParallelCoordinatesPlot'; ax = findall (hf, 'type', 'axes', 'tag', tag); assert_equal (numel (ax), 1); assert_equal (gca (), ax); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect plot (1:3); pax = gca (); h = parallelplot (magic (4)); assert_equal (ishghandle (pax), false); plot (1:3); assert_equal (isempty (h.Parent), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** error parallelplot () ***** error ... parallelplot ('abc') ***** error ... parallelplot (ones (2, 2, 2)) ***** error ... parallelplot (magic (3), 'Title') ***** error ... parallelplot (magic (3), 'Foo', 1) ***** error ... parallelplot (magic (3), 'CoordinateVariables', {'A'}) ***** error ... parallelplot (magic (3), 'GroupVariable', 'G') ***** error ... parallelplot (table ([1; 2]), 'CoordinateData', 1) ***** error ... hf = figure ('visible', 'off'); unwind_protect parallelplot (axes (hf), magic (3)); unwind_protect_cleanup close (hf); end_unwind_protect ***** error ... hf = figure ('visible', 'off'); unwind_protect plot (1:3); hold on; parallelplot (magic (3)); unwind_protect_cleanup close (hf); end_unwind_protect 12 tests, 12 passed, 0 known failure, 0 skipped [inst/Plotting/glyphplot.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/glyphplot.m ***** demo ## Star plot of the first few cars in the carsmall data set. load carsmall; X = [Acceleration, Cylinders, Displacement, Horsepower, Weight]; glyphplot (X(1:9,:), "ObsLabels", cellstr (num2str ((1:9)'))); ***** test hf = figure ("visible", "off"); unwind_protect X = [1 4 2; 3 2 5; 5 5 1; 2 1 4]; g = glyphplot (X); assert_equal (size (g), [4, 3]); ## star perimeter of observation 1 (column standardize, radius 0.4) assert_equal (get (g(1,1), "xdata"), [1.04 0.845 0.935 1.04], 1e-4); assert_equal (get (g(1,1), "ydata"), [2 2.2685 1.8874 2], 1e-4); assert_equal (get (g(1,1), "userdata"), [1 2 1], 1e-12); ## observation 2 assert_equal (get (g(2,1), "xdata"), [2.22 1.935 1.8 2.22], 1e-4); assert_equal (get (g(2,1), "ydata"), [2 2.1126 1.6536 2], 1e-4); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # Radius option scales the glyph hf = figure ("visible", "off"); unwind_protect X = [1 4 2; 3 2 5; 5 5 1; 2 1 4]; g = glyphplot (X, "Radius", 0.8); ## perimeter x of obs 1 spoke 1: cx + 0.8*(0.1+0.9*0) = 1 + 0.08 assert_equal (get (g(1,1), "xdata")(1), 1.08, 1e-12); unwind_protect_cleanup close (hf); end_unwind_protect ***** error glyphplot () ***** error glyphplot ({1}) ***** error ... glyphplot (ones (3, 3), "Glyph", "face") ***** error ... glyphplot (ones (3, 3), "Radius") ***** error ... glyphplot (ones (3, 3), "bogus", 1) ***** error ... glyphplot (ones (3, 3), "Standardize", "xxx") ***** error ... glyphplot (ones (3, 3), "Centers", [1 2]) 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Plotting/gscatter.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/gscatter.m ***** demo load fisheriris; X = meas(:,3:4); cidcs = kmeans (X, 3, 'Replicates', 5); gscatter (X(:,1), X(:,2), cidcs, [.75 .75 0; 0 .75 .75; .75 0 .75], 'os^'); title ('Fisher''s iris data'); ***** shared visibility_setting visibility_setting = get (0, 'DefaultFigureVisible'); ***** test hf = figure ('visible', 'off'); unwind_protect load fisheriris; X = meas(:,3:4); cidcs = kmeans (X, 3, 'Replicates', 5); gscatter (X(:,1), X(:,2), cidcs, [.75 .75 0; 0 .75 .75; .75 0 .75], 'os^'); title ('Fisher''s iris data'); unwind_protect_cleanup close (hf); end_unwind_protect warning: legend: 'best' not yet implemented for location specifier, using 'northeast' instead ***** error gscatter (); ***** error gscatter ([1]); ***** error gscatter ([1], [2]); ***** error gscatter ('abc', [1 2 3], [1]); ***** error gscatter ([1 2 3], [1 2], [1]); ***** error gscatter ([1 2 3], 'abc', [1]); ***** error gscatter ([1 2], [1 2], [1]); ***** error gscatter ([1 2], [1 2], [1 2], 'rb', 'so', 12, 'xxx'); 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Plotting/normplot.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/normplot.m ***** demo h = normplot ([1:20]); ***** demo h = normplot ([1:20;5:2:44]'); ***** demo ax = newplot (); h = normplot (ax, [1:20]); ax = gca; h = normplot (ax, [-10:10]); set (ax, 'xlim', [-11, 21]); ***** error normplot (); ***** error normplot (23); ***** error normplot (23, [1:20]); ***** error normplot (ones (3,4,5)); ***** test hf = figure ('visible', 'off'); unwind_protect ax = newplot (hf); h = normplot (ax, [1:20]); ax = gca; h = normplot (ax, [-10:10]); set (ax, 'xlim', [-11, 21]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = normplot ([1:20;5:2:44]'); unwind_protect_cleanup close (hf); end_unwind_protect 6 tests, 6 passed, 0 known failure, 0 skipped [inst/Plotting/dendrogram.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/dendrogram.m ***** demo ## simple dendrogram y = [4, 5; 2, 6; 3, 7; 8, 9; 1, 10]; y(:,3) = 1:5; dendrogram (y); title ('simple dendrogram'); ***** demo ## another simple dendrogram rng (42); v = 2 * rand (30, 1) - 1; d = abs (bsxfun (@minus, v(:, 1), v(:, 1)')); y = linkage (squareform (d, 'tovector')); dendrogram (y); title ('another simple dendrogram'); ***** demo ## collapsed tree, find all the leaves of node 5 rng (42); X = randn (60, 2); D = pdist (X); y = linkage (D, 'average'); subplot (2, 1, 1); title ('original tree'); dendrogram (y, 0); subplot (2, 1, 2); title ('collapsed tree'); [~, t] = dendrogram (y, 20); find (t == 5) ***** demo ## optimal leaf order rng (42); X = randn (30, 2); D = pdist (X); y = linkage (D, 'average'); order = optimalleaforder (y, D); subplot (2, 1, 1); title ('original leaf order'); dendrogram (y); subplot (2, 1, 2); title ('optimal leaf order'); dendrogram (y, 'Reorder', order); ***** demo ## horizontal orientation and labels rng (42); X = randn (8, 2); D = pdist (X); L = ['Snow White'; 'Doc'; 'Grumpy'; 'Happy'; 'Sleepy'; 'Bashful'; ... 'Sneezy'; 'Dopey']; y = linkage (D, 'average'); dendrogram (y, 'Orientation', 'left', 'Labels', L); title ('horizontal orientation and labels'); ***** shared visibility_setting visibility_setting = get (0, 'DefaultFigureVisible'); ***** test hf = figure ('visible', 'off'); unwind_protect y = [4, 5; 2, 6; 3, 7; 8, 9; 1, 10]; y(:,3) = 1:5; dendrogram (y); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect y = [4, 5; 2, 6; 3, 7; 8, 9; 1, 10]; y(:,3) = 1:5; dendrogram (y); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect v = 2 * rand (30, 1) - 1; d = abs (bsxfun (@minus, v(:, 1), v(:, 1)')); y = linkage (squareform (d, 'tovector')); dendrogram (y); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect X = randn (30, 2); D = pdist (X); y = linkage (D, 'average'); order = optimalleaforder (y, D); subplot (2, 1, 1); title ('original leaf order'); dendrogram (y); subplot (2, 1, 2); title ('optimal leaf order'); dendrogram (y, 'Reorder', order); unwind_protect_cleanup close (hf); end_unwind_protect ***** error dendrogram (); ***** error dendrogram (ones (2, 2), 1); ***** error dendrogram ([1 2 1], 1, 'xxx', 'xxx'); ***** error dendrogram ([1 2 1], 'Reorder', 'xxx'); ***** error dendrogram ([1 2 1], 'Reorder', [1 2 3 4]); fail ('dendrogram ([1 2 1], "Orientation", "north")', 'invalid orientation .*') 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Plotting/probplot.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/probplot.m ***** demo probplot ([1:20]); ***** demo probplot ("weibull", [1 2 3 4 5 6 7 8 9 10 15 20]); ***** shared y, c, f y = [2.1 3.4 1.8 5.2 2.9 4.1 3.3 2.7 6.0 3.8 4.5 2.2]; c = logical ([0 0 0 1 0 0 0 0 1 0 1 0]); f = [1 2 1 1 3 1 1 2 1 1 1 2]; ***** test hf = figure ("visible", "off"); unwind_protect h = probplot (y); assert_equal (numel (h), 2); xd = get (h(1), "xdata"); yd = get (h(1), "ydata"); assert_equal (xd(:)', sort (y), 1e-12); ymatlab = [-1.7317 -1.1503 -0.8122 -0.5485 -0.3186 -0.1046 ... 0.1046 0.3186 0.5485 0.8122 1.1503 1.7317]; assert_equal (yd(:)', ymatlab, 1e-4); rl = get (h(2), "ydata"); rx = get (h(2), "xdata"); ## reference line slope matches MATLAB robust quartile fit slope = (rl(end) - rl(1)) / (rx(end) - rx(1)); assert_equal (slope, 0.72923, 1e-4); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ("visible", "off"); unwind_protect ax = axes (hf); h = probplot (ax, "weibull", y); assert_equal (get (ax, "xscale"), "log"); yd = get (h(1), "ydata"); ymatlab = [-3.1568 -2.0134 -1.4541 -1.0647 -0.7550 -0.4892 ... -0.2483 -0.0194 0.2088 0.4502 0.7321 1.1563]; assert_equal (yd(:)', ymatlab, 1e-4); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ("visible", "off"); unwind_protect dists = {"exponential", "lognormal", "rayleigh", "logistic", ... "loglogistic", "extreme value"}; gold = {[0.0426 0.1335 0.2336 0.3448 0.4700 0.6131 0.7802 0.9808 ... 1.2321 1.5686 2.0794 3.1781], ... [-1.7317 -1.1503 -0.8122 -0.5485 -0.3186 -0.1046 0.1046 ... 0.3186 0.5485 0.8122 1.1503 1.7317], ... [0.2918 0.5168 0.6835 0.8305 0.9695 1.1073 1.2491 1.4006 ... 1.5698 1.7712 2.0393 2.5211], ... [-3.1355 -1.9459 -1.3350 -0.8873 -0.5108 -0.1671 0.1671 ... 0.5108 0.8873 1.3350 1.9459 3.1355], ... [-3.1355 -1.9459 -1.3350 -0.8873 -0.5108 -0.1671 0.1671 ... 0.5108 0.8873 1.3350 1.9459 3.1355], ... [-3.1568 -2.0134 -1.4541 -1.0647 -0.7550 -0.4892 -0.2483 ... -0.0194 0.2088 0.4502 0.7321 1.1563]}; logx = {false, true, false, false, true, false}; for k = 1:numel (dists) ax = axes (hf); h = probplot (ax, dists{k}, y); assert_equal (get (h(1), "ydata")(:)', gold{k}, 1e-4); if (logx{k}) assert_equal (get (ax, "xscale"), "log"); else assert_equal (get (ax, "xscale"), "linear"); endif delete (ax); endfor unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ("visible", "off"); unwind_protect h = probplot (y, "noref"); assert_equal (numel (h), 1); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ("visible", "off"); unwind_protect h = probplot ("normal", y, c); xd = get (h(1), "xdata"); yd = get (h(1), "ydata"); assert_equal (xd(:)', [1.8 2.1 2.2 2.7 2.9 3.3 3.4 3.8 4.1], 1e-12); ymatlab = [-1.7317 -1.1503 -0.8122 -0.5485 -0.3186 -0.1046 ... 0.1046 0.3186 0.5485]; assert_equal (yd(:)', ymatlab, 1e-4); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ("visible", "off"); unwind_protect cm = logical ([0 0 0 0 0 1 1 1 0 0 0 0]); h = probplot ("normal", y, cm); yd = get (h(1), "ydata"); ymatlab = [-1.7317 -1.1503 -0.8122 -0.5334 -0.2574 0.0196 ... 0.3462 0.7764 1.4544]; assert_equal (yd(:)', ymatlab, 1e-4); rl = get (h(2), "ydata"); rx = get (h(2), "xdata"); slope = (rl(end) - rl(1)) / (rx(end) - rx(1)); assert_equal (slope, 0.53519, 1e-4); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ("visible", "off"); unwind_protect h = probplot ("normal", y, [], f); xd = get (h(1), "xdata"); assert_equal (numel (xd), sum (f)); unwind_protect_cleanup close (hf); end_unwind_protect ***** error probplot () ***** error probplot ("foo", [1 2 3 4]) ***** error probplot ([1 2 3 4], "bar") 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Plotting/+stats/+chart/BoxChart.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/+stats/+chart/BoxChart.m ***** shared bxY, bxG, bxS, bxR bxY = [1; 2; 3; 4; 5; 6; 7; 8; 9; 100]; bxG = [2; 2; 2; 2; 2; 5; 5; 5; 5; 5]; bxS = struct ('XData', [], 'YData', bxY, 'SourceTable', [], ... 'XVariable', [], 'YVariable', [], ... 'XDataMode', 'auto', 'YDataMode', 'manual'); bxR = struct ('XData', [], 'YData', [], ... 'SourceTable', table (bxG, bxY, ... 'VariableNames', {'grp', 'val'}), ... 'XVariable', 'grp', 'YVariable', 'val', ... 'XDataMode', 'auto', 'YDataMode', 'auto'); ***** test # the class is built from an axes and a data specification hf = figure ('visible', 'off'); unwind_protect b = stats.chart.BoxChart (gca (), bxS); assert_equal (class (b), 'stats.chart.BoxChart'); assert_equal (b.Parent, gca ()); assert_equal (b.YData, bxY); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # an empty axes is the current one, and the pairs are set before drawing hf = figure ('visible', 'off'); unwind_protect b = stats.chart.BoxChart ([], bxS, {'Notch', 'on', 'BoxWidth', 0.8}); assert_equal (b.Parent, gca ()); assert_equal (b.Notch, 'on'); assert_equal (b.BoxWidth, 0.8); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a rejected value leaves no figure, the axes being resolved last n = numel (findall (0, 'type', 'figure')); msg = ''; try stats.chart.BoxChart ([], bxS, {'BoxWidth', -1}); catch err msg = err.message; end_try_catch assert_equal (isempty (msg), false); assert_equal (numel (findall (0, 'type', 'figure')), n); ***** test # the colours every part is drawn in default to the same triplet hf = figure ('visible', 'off'); unwind_protect b = stats.chart.BoxChart (gca (), bxS); assert_equal (b.BoxFaceColor, [0, 0.447, 0.741]); assert_equal (b.BoxEdgeColor, [0, 0.447, 0.741]); assert_equal (b.BoxMedianLineColor, [0, 0.447, 0.741]); assert_equal (b.WhiskerLineColor, [0, 0.447, 0.741]); assert_equal (b.MarkerColor, [0, 0.447, 0.741]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # nothing was chosen, so every mode reads 'auto' hf = figure ('visible', 'off'); unwind_protect b = stats.chart.BoxChart (gca (), bxS); assert_equal (b.BoxFaceColorMode, 'auto'); assert_equal (b.BoxEdgeColorMode, 'auto'); assert_equal (b.BoxMedianLineColorMode, 'auto'); assert_equal (b.MarkerColorMode, 'auto'); assert_equal (b.CapWidthMode, 'auto'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # setting one of them records that it was chosen hf = figure ('visible', 'off'); unwind_protect b = stats.chart.BoxChart (gca (), bxS); b.BoxEdgeColor = [1, 0, 0]; assert_equal (b.BoxEdgeColorMode, 'manual'); b.BoxMedianLineColor = [1, 0, 0]; assert_equal (b.BoxMedianLineColorMode, 'manual'); b.MarkerColor = [1, 0, 0]; assert_equal (b.MarkerColorMode, 'manual'); b.CapWidth = 0.4; assert_equal (b.CapWidthMode, 'manual'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a colour name is kept as the triplet it stands for hf = figure ('visible', 'off'); unwind_protect b = stats.chart.BoxChart (gca (), bxS); b.BoxFaceColor = 'r'; assert_equal (b.BoxFaceColor, [1, 0, 0]); b.WhiskerLineColor = 'black'; assert_equal (b.WhiskerLineColor, [0, 0, 0]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a word is taken whatever its case and kept in the documented spelling hf = figure ('visible', 'off'); unwind_protect b = stats.chart.BoxChart (gca (), bxS); b.Notch = 'ON'; assert_equal (b.Notch, 'on'); b.Orientation = 'HORIZONTAL'; assert_equal (b.Orientation, 'horizontal'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test m = meta.class.fromName ('stats.chart.BoxChart'); nm = cellfun (@(p) p.Name, m.PropertyList, 'UniformOutput', false); i = find (strcmp (nm, 'XDataMode'), 1); assert_equal (m.PropertyList{i}.SetAccess, 'private'); assert_equal (m.PropertyList{i}.GetAccess, 'public'); i = find (strcmp (nm, 'Parent'), 1); assert_equal (m.PropertyList{i}.SetAccess, 'private'); ***** test # the box spans the quartiles and the median lies across it hf = figure ('visible', 'off'); unwind_protect stats.chart.BoxChart (gca (), bxS); k = flipud (get (gca (), 'children')); assert_equal (get (k(1), 'xdata'), [0.75; 1.25; 1.25; 0.75]); assert_equal (get (k(1), 'ydata'), [3; 3; 8; 8]); assert_equal (get (k(2), 'ydata'), [5.5, 5.5]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect stats.chart.BoxChart (gca (), bxS); k = flipud (get (gca (), 'children')); assert_equal (get (k(3), 'ydata'), [8, 9]); assert_equal (get (k(4), 'ydata'), [3, 1]); assert_equal (get (k(5), 'xdata'), [0.875, 1.125]); assert_equal (get (k(6), 'xdata'), [0.875, 1.125]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # whatever the whiskers do not reach is drawn as a marker hf = figure ('visible', 'off'); unwind_protect b = stats.chart.BoxChart (gca (), bxS); k = flipud (get (gca (), 'children')); assert_equal (numel (k), 7); assert_equal (get (k(7), 'ydata'), 100); assert_equal (get (k(7), 'marker'), 'o'); b.MarkerStyle = 'none'; assert_equal (numel (get (gca (), 'children')), 6); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a jittered marker is spread across the width of the box hf = figure ('visible', 'off'); unwind_protect b = stats.chart.BoxChart (gca (), bxS); k = flipud (get (gca (), 'children')); assert_equal (get (k(7), 'xdata'), 1); b.JitterOutliers = 'on'; k = flipud (get (gca (), 'children')); assert_equal (abs (get (k(7), 'xdata') - 1) <= 0.25, true); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a horizontal chart is the same drawing with the axes exchanged hf = figure ('visible', 'off'); unwind_protect b = stats.chart.BoxChart (gca (), bxS, {'Orientation', 'horizontal'}); k = flipud (get (gca (), 'children')); assert_equal (get (k(1), 'xdata'), [3; 3; 8; 8]); assert_equal (get (k(1), 'ydata'), [0.75; 1.25; 1.25; 0.75]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect stats.chart.BoxChart (gca (), bxS, {'Notch', 'on'}); k = flipud (get (gca (), 'children')); by = get (k(1), 'ydata'); d = 1.57 * (8 - 3) / sqrt (10); assert_equal (numel (by), 10); assert_equal (by(3), 5.5 - d, eps); assert_equal (by(5), 5.5 + d, eps); assert_equal (by(4), 5.5); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a numeric grouping puts each box at the value it was given hf = figure ('visible', 'off'); unwind_protect s = bxS; s.XData = bxG; s.XDataMode = 'manual'; stats.chart.BoxChart (gca (), s); p = findobj (gca (), 'type', 'patch'); x1 = get (p(1), 'xdata'); x2 = get (p(2), 'xdata'); assert_equal (sort ([x1(1), x2(1)]), [1.75, 4.75]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a categorical grouping draws one box per level hf = figure ('visible', 'off'); unwind_protect s = bxS; s.XData = categorical ({'a'; 'a'; 'a'; 'b'; 'b'; 'b'; 'c'; 'c'; 'c'; 'c'}); s.XDataMode = 'manual'; stats.chart.BoxChart (gca (), s); assert_equal (numel (findobj (gca (), 'type', 'patch')), 3); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # no observations, nothing drawn, and the data may be given afterwards hf = figure ('visible', 'off'); unwind_protect s = bxS; s.YData = []; b = stats.chart.BoxChart (gca (), s); assert_equal (isempty (get (gca (), 'children')), true); b.YData = bxY; assert_equal (numel (get (gca (), 'children')), 7); assert_equal (b.YDataMode, 'manual'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a row of observations is kept as a column hf = figure ('visible', 'off'); unwind_protect s = bxS; s.YData = bxY'; b = stats.chart.BoxChart (gca (), s); assert_equal (b.YData, bxY); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # the chart is a handle, so two names are one chart hf = figure ('visible', 'off'); unwind_protect b = stats.chart.BoxChart (gca (), bxS); c = b; c.BoxWidth = 0.9; assert_equal (b.BoxWidth, 0.9); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a table fills both sides and puts both modes at 'auto' hf = figure ('visible', 'off'); unwind_protect b = stats.chart.BoxChart (gca (), bxR); assert_equal (b.YData, bxY); assert_equal (b.XDataMode, 'auto'); assert_equal (b.YDataMode, 'auto'); assert_equal (numel (findobj (gca (), 'type', 'patch')), 2); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # clearing a variable name is allowed where naming one would not be hf = figure ('visible', 'off'); unwind_protect b = stats.chart.BoxChart (gca (), bxR); b.XVariable = []; assert_equal (isempty (b.XVariable), true); assert_equal (b.YData, bxY); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # disp heads with the short name and says what was drawn hf = figure ('visible', 'off'); unwind_protect b = stats.chart.BoxChart (gca (), bxS); s = evalc ('disp (b)'); assert_equal (isempty (strfind (s, 'BoxChart with properties:')), false); assert_equal (isempty (strfind (s, 'observations: 10')), false); assert_equal (isempty (strfind (s, 'boxes: 1')), false); assert_equal (isempty (strfind (s, 'Orientation: vertical')), false); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a chart drawn from a table also names the column it was drawn from hf = figure ('visible', 'off'); unwind_protect b = stats.chart.BoxChart (gca (), bxR); s = evalc ('disp (b)'); assert_equal (isempty (strfind (s, 'boxes: 2')), false); assert_equal (isempty (strfind (s, 'YVariable: val')), false); unwind_protect_cleanup close (hf); end_unwind_protect ***** error ... stats.chart.BoxChart () ***** error ... stats.chart.BoxChart ([], setfield (bxS, 'YData', {1, 2})) ***** error ... stats.chart.BoxChart ([], setfield (bxS, 'SourceTable', 5)) ***** error ... stats.chart.BoxChart ([], setfield (bxR, 'XVariable', 5)) ***** error ... stats.chart.BoxChart ([], setfield (bxR, 'YVariable', 'nope')) ***** error ... stats.chart.BoxChart ([], setfield (bxR, 'XVariable', 'nope')) ***** error ... stats.chart.BoxChart ([], bxS, {'BoxWidth', 0}) ***** error ... stats.chart.BoxChart ([], bxS, {'CapWidth', [1, 2]}) ***** error ... stats.chart.BoxChart ([], bxS, {'LineWidth', -1}) ***** error ... stats.chart.BoxChart ([], bxS, {'MarkerSize', 'big'}) ***** error ... stats.chart.BoxChart ([], bxS, {'BoxFaceAlpha', 1.5}) ***** error ... stats.chart.BoxChart ([], bxS, {'BoxFaceColor', [2, 0, 0]}) ***** error ... stats.chart.BoxChart ([], bxS, {'WhiskerLineColor', 'puce'}) ***** error ... stats.chart.BoxChart ([], bxS, {'WhiskerLineStyle', 'wavy'}) ***** error ... stats.chart.BoxChart ([], bxS, {'MarkerStyle', 'q'}) ***** error ... stats.chart.BoxChart ([], bxS, {'Notch', 'maybe'}) ***** error ... stats.chart.BoxChart ([], bxS, {'JitterOutliers', 'yes'}) ***** error ... stats.chart.BoxChart ([], bxS, {'Orientation', 'sideways'}) ***** error hf = figure ('visible', 'off'); b = stats.chart.BoxChart (gca (), bxR); close (hf); b.YData = bxY; ***** error hf = figure ('visible', 'off'); b = stats.chart.BoxChart (gca (), bxR); close (hf); b.XData = bxG; ***** error hf = figure ('visible', 'off'); b = stats.chart.BoxChart (gca (), bxS); close (hf); b.YVariable = 'val'; ***** error hf = figure ('visible', 'off'); s = bxS; s.XData = bxG; s.XDataMode = 'manual'; b = stats.chart.BoxChart (gca (), s); close (hf); b.XVariable = 'grp'; 46 tests, 46 passed, 0 known failure, 0 skipped [inst/Plotting/+stats/+chart/ScatterHistogramChart.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/+stats/+chart/ScatterHistogramChart.m ***** shared x, y, g x = [2.1; 3.4; 1.9; 5.6; 4.4; 3.8; 2.7; 6.1; 3.3; 4.9; 1.2; 2.8]; y = [1.2; 2.8; 0.9; 2.2; 3.1; 1.7; 2.5; 0.4; 1.9; 3.6; 2.0; 1.1]; g = categorical ({'a';'b';'a';'b';'a';'b';'a';'b';'a';'c';'c';'c'}); ***** test hf = figure ('visible', 'off'); unwind_protect h = scatterhistogram (x, y); assert_equal (class (h), 'stats.chart.ScatterHistogramChart'); assert_equal (h.XData, x); assert_equal (h.YData, y); assert_equal (h.GroupData, []); assert_equal (h.NumBins, [4; 4]); assert_equal (h.BinWidths, [2; 1]); assert_equal (h.XLimits, [1.2, 6.1]); assert_equal (h.YLimits, [0.4, 3.6]); assert_equal (h.Color, [0, 0.447, 0.741]); assert_equal (h.HistogramDisplayStyle, 'stairs'); assert_equal (h.ScatterPlotLocation, 'SouthWest'); assert_equal (h.ScatterPlotProportion, 0.75); assert_equal (h.XHistogramDirection, 'up'); assert_equal (h.YHistogramDirection, 'right'); assert_equal (h.LineStyle, '-'); assert_equal (h.LineWidth, 0.5); assert_equal (h.MarkerStyle, 'o'); assert_equal (h.MarkerSize, 36); assert_equal (h.MarkerFilled, 'on'); assert_equal (h.MarkerAlpha, 1); assert_equal (h.LegendVisible, 'off'); assert_equal (h.OuterPosition, [0, 0, 1, 1]); assert_equal (h.Parent, hf); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = scatterhistogram (x, y, 'GroupData', g); assert_equal (h.LegendVisible, 'on'); assert_equal (h.Color, [0, 0.447, 0.741; 0.85, 0.325, 0.098; ... 0.929, 0.694, 0.125]); assert_equal (h.LineStyle, {'-', ':', '-.'}); assert_equal (h.NumBins, [3, 2, 1; 2, 2, 2]); assert_equal (h.BinWidths, [2, 3, 5; 2, 2, 3]); tag = 'stats.chart.ScatterHistogramChart'; lg = findall (hf, 'type', 'axes', 'tag', 'legend'); s = get (lg, 'string'); # a row under gnuplot, a column otherwise assert_equal (s(:), {'a'; 'b'; 'c'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = scatterhistogram (x, y, 'GroupData', {'q';'p';'q';'p';'q';'p'; ... 'q';'p';'q';'p';'q';'p'}); assert_equal (rows (h.Color), 2); lg = findall (hf, 'type', 'axes', 'tag', 'legend'); s = get (lg, 'string'); # a row under gnuplot, a column otherwise assert_equal (s(:), {'q'; 'p'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = scatterhistogram (x, y, 'NumBins', 4); assert_equal (h.NumBins, [4; 4]); assert_equal (h.BinWidths, [1.3; 0.9], -1e-12); h.NumBins = [3; 5]; assert_equal (h.NumBins, [3; 5]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = scatterhistogram (x, y, 'NumBins', 4, 'BinWidths', 1); assert_equal (h.NumBins, [6; 4]); assert_equal (h.BinWidths, [1; 1]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = scatterhistogram (x, y, 'HistogramDisplayStyle', 'smooth'); assert_equal (h.NumBins, []); assert_equal (h.BinWidths, []); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## Each histogram is a density: the area under it is one hf = figure ('visible', 'off'); unwind_protect h = scatterhistogram (x, y); tag = 'stats.chart.ScatterHistogramChart'; ax = findall (hf, 'type', 'axes', 'tag', tag); ln = [findall(ax, 'type', 'line'); findall(ax, 'type', 'patch')]; for k = 1:numel (ln) px = get (ln(k), 'xdata'); py = get (ln(k), 'ydata'); if (numel (px) > 2) area = max (abs (trapz (px(:), py(:))), abs (trapz (py(:), px(:)))); assert_equal (area, 1, -1e-12); endif endfor unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = scatterhistogram (x, y); h.XLimits = [0, 10]; assert_equal (h.XLimits, [0, 10]); assert_equal (xlim (h), [0, 10]); ylim (h, [-1, 5]); assert_equal (h.YLimits, [-1, 5]); h.XData = x + 100; assert_equal (h.XLimits, [0, 10]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = scatterhistogram ([x; NaN], [y; 2]); assert_equal (numel (h.XData), 13); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## The histograms line the sides away from the scatter plot's corner hf = figure ('visible', 'off'); unwind_protect h = scatterhistogram (x, y); tag = 'stats.chart.ScatterHistogramChart'; ax = findall (hf, 'type', 'axes', 'tag', tag); ps = h.Position; p = cell2mat (get (ax, 'position')); top = p(:,2) > ps(2) + ps(4) - 1e-9; right = p(:,1) > ps(1) + ps(3) - 1e-9; assert_equal ([sum(top), sum(right)], [1, 1]); h.ScatterPlotLocation = 'northeast'; assert_equal (h.ScatterPlotLocation, 'NorthEast'); ps = h.Position; p = cell2mat (get (ax, 'position')); below = p(:,2) + p(:,4) < ps(2) + 1e-9; left = p(:,1) + p(:,3) < ps(1) + 1e-9; assert_equal ([sum(below), sum(left)], [1, 1]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = scatterhistogram (x, y, 'XHistogramDirection', 'down', ... 'YHistogramDirection', 'left', ... 'MarkerFilled', 'off', 'MarkerAlpha', 0.5, ... 'Title', 'T', 'XLabel', 'XL', 'YLabel', 'YL'); assert_equal (h.XHistogramDirection, 'down'); assert_equal (h.YHistogramDirection, 'left'); assert_equal (h.MarkerFilled, 'off'); assert_equal (h.MarkerAlpha, 0.5); assert_equal (h.Title, 'T'); assert_equal (get (get (gca (), 'xlabel'), 'string'), 'XL'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = scatterhistogram (x, y, 'GroupData', g, 'Color', ... [1, 0, 0; 0, 1, 0; 0, 0, 1], 'LineStyle', ... {'-', '--', ':'}, 'MarkerStyle', {'o', 'x', 's'}, ... 'MarkerSize', [4, 6, 8], 'LineWidth', [1, 2, 3]); assert_equal (h.Color, [1, 0, 0; 0, 1, 0; 0, 0, 1]); assert_equal (h.LineStyle, {'-', '--', ':'}); assert_equal (h.MarkerStyle, {'o', 'x', 's'}); assert_equal (h.MarkerSize, [4, 6, 8]); assert_equal (h.LineWidth, [1, 2, 3]); h.GroupData = g(end:-1:1); assert_equal (h.Color, [1, 0, 0; 0, 1, 0; 0, 0, 1]); unwind_protect_cleanup close (hf); end_unwind_protect ***** shared shS shS = struct ('XData', [1; 2; 3], 'YData', [4; 5; 6], 'GroupData', [], ... 'SourceTable', [], 'XVariable', '', 'YVariable', '', ... 'GroupVariable', ''); ***** error ... stats.chart.ScatterHistogramChart ([]) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'XData', {1, 2}}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'YData', [1; 2]}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'GroupData', [1; 2]}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'GroupData', ones(2, 2)}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'SourceTable', 5}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, ... {'HistogramDisplayStyle', 'area'}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'NumBins', 0}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'NumBins', [3, 5]}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'BinWidths', [1, 0.5]}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, ... {'ScatterPlotLocation', 'Middle'}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'ScatterPlotProportion', 1.2}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'XHistogramDirection', 'left'}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'YHistogramDirection', 'up'}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'XLimits', [2, 1]}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'Color', 'r'}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'LineStyle', '*'}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'LineWidth', 0}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'MarkerStyle', 'q'}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'MarkerFilled', 1}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'MarkerAlpha', 2}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'LegendVisible', 'yes'}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'Title', 5}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'FontSize', -1}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'Position', [0, 0, 1]}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, {'Visible', 'maybe'}) ***** error ... stats.chart.ScatterHistogramChart ([], shS, ... {'SourceTable', table([1; 2], 'VariableNames', {'X'}), ... 'XVariable', 'X', 'YVariable', 'Q'}) 39 tests, 39 passed, 0 known failure, 0 skipped [inst/Plotting/+stats/+chart/ParallelCoordinatesPlot.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/+stats/+chart/ParallelCoordinatesPlot.m ***** shared X, g, T X = [2.1, 1.2, 10; 3.4, 2.8, 12; 1.9, 0.9, 11; 5.6, 2.2, 15; ... 4.4, 3.1, 9; 3.8, 1.7, 13]; g = categorical ({'a'; 'b'; 'a'; 'b'; 'c'; 'a'}); T = table (X(:,1), X(:,2), X(:,3), g, 'VariableNames', {'A', 'B', 'C', 'G'}); ***** test hf = figure ('visible', 'off'); unwind_protect h = parallelplot (X); assert_equal (class (h), 'stats.chart.ParallelCoordinatesPlot'); assert_equal (h.Data, X); assert_equal (h.CoordinateData, [1, 2, 3]); assert_equal (h.GroupData, []); assert_equal (h.CoordinateTickLabels, {'1'; '2'; '3'}); assert_equal (h.DataNormalization, 'range'); assert_equal (h.Color, [0, 0.447, 0.741]); assert_equal (h.LineWidth, 1); assert_equal (h.LineStyle, '-'); assert_equal (h.LineAlpha, 0.7); assert_equal (h.MarkerStyle, 'none'); assert_equal (h.MarkerSize, 6); assert_equal (h.Jitter, 0.1); assert_equal (h.LegendVisible, 'off'); assert_equal (h.FontSize, 10); assert_equal (h.OuterPosition, [0, 0, 1, 1]); assert_equal (h.Parent, hf); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = parallelplot (X, 'GroupData', g); assert_equal (h.Color, [0, 0.447, 0.741; 0.85, 0.325, 0.098; ... 0.929, 0.694, 0.125]); assert_equal (h.LineStyle, {'-', '-', '-'}); assert_equal (h.LineWidth, [1, 1, 1]); assert_equal (h.LineAlpha, [0.7, 0.7, 0.7]); assert_equal (h.MarkerStyle, {'none', 'none', 'none'}); assert_equal (h.MarkerSize, [6, 6, 6]); assert_equal (h.LegendVisible, 'on'); assert_equal (h.LegendTitle, ''); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = parallelplot (X, 'GroupData', {'p'; 'q'; 'p'; 'q'; 'p'; 'q'}); assert_equal (rows (h.Color), 2); assert_equal (h.LegendVisible, 'on'); lg = findall (hf, 'type', 'axes', 'tag', 'legend'); s = get (lg, 'string'); # a row under gnuplot, a column otherwise assert_equal (s(:), {'p'; 'q'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = parallelplot (T); assert_equal (h.CoordinateVariables, {'A', 'B', 'C', 'G'}); assert_equal (h.CoordinateTickLabels, {'A'; 'B'; 'C'; 'G'}); assert_equal (h.GroupVariable, ''); assert_equal (h.LegendTitle, ''); assert_equal (h.LegendVisible, 'off'); assert_equal (h.Data, []); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = parallelplot (T, 'GroupVariable', 'G'); assert_equal (h.LegendTitle, 'G'); assert_equal (h.LegendVisible, 'on'); assert_equal (rows (h.Color), 3); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = parallelplot (T, 'CoordinateVariables', {'C', 'A'}); assert_equal (h.CoordinateVariables, {'C', 'A'}); assert_equal (h.CoordinateTickLabels, {'C'; 'A'}); h.CoordinateVariables = [3, 1]; assert_equal (h.CoordinateVariables, [3, 1]); h.CoordinateVariables = [true, false, true, false]; assert_equal (h.CoordinateVariables, [true, false, true, false]); assert_equal (h.CoordinateTickLabels, {'A'; 'C'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = parallelplot (X, 'CoordinateTickLabels', {'x', 'y', 'z'}, ... 'Jitter', 0.3, 'DataNormalization', 'zscore'); assert_equal (h.CoordinateTickLabels, {'x'; 'y'; 'z'}); assert_equal (h.Jitter, 0.3); assert_equal (h.DataNormalization, 'zscore'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = parallelplot (T, 'GroupVariable', 'G', 'Color', ... [1, 0, 0; 0, 1, 0; 0, 0, 1], 'LineStyle', ... {'-', '--', ':'}, 'LineWidth', [1, 2, 3], ... 'MarkerStyle', {'o', 'x', 's'}, 'MarkerSize', ... [4, 6, 8], 'LineAlpha', 0.3); assert_equal (h.Color, [1, 0, 0; 0, 1, 0; 0, 0, 1]); assert_equal (h.LineStyle, {'-', '--', ':'}); assert_equal (h.LineWidth, [1, 2, 3]); assert_equal (h.MarkerStyle, {'o', 'x', 's'}); assert_equal (h.MarkerSize, [4, 6, 8]); assert_equal (h.LineAlpha, 0.3); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = parallelplot ([X; NaN, 1, 1]); assert_equal (size (h.Data), [7, 3]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## Values on rulers of their own run from 0 at the smallest to 1 at the ## largest, and a missing value breaks its line hf = figure ('visible', 'off'); unwind_protect h = parallelplot ([1, 10; 3, 20; 2, NaN]); tag = 'stats.chart.ParallelCoordinatesPlot'; ax = findall (hf, 'type', 'axes', 'tag', tag); ln = findobj (ax, 'type', 'line', '-and', '-not', 'linestyle', 'none'); yd = get (ln(end), 'ydata'); assert_equal (yd(:)', [0, 0, NaN, 1, 1, NaN, 0.5, NaN, NaN], -1e-15); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = parallelplot ([1, 10; 3, 20; 2, 30], 'DataNormalization', 'zscore'); tag = 'stats.chart.ParallelCoordinatesPlot'; ax = findall (hf, 'type', 'axes', 'tag', tag); ln = findobj (ax, 'type', 'line'); yd = get (ln(end), 'ydata'); assert_equal (yd(:)', [-1, -1, NaN, 1, 0, NaN, 0, 1, NaN], -1e-15); h.DataNormalization = 'center'; ln = findobj (ax, 'type', 'line'); yd = get (ln(end), 'ydata'); assert_equal (yd(:)', [-1, -10, NaN, 1, 0, NaN, 0, 10, NaN], -1e-14); h.DataNormalization = 'none'; assert_equal (get (ax, 'ylim'), [1, 30]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## A variable of categories places its levels evenly along its ruler hf = figure ('visible', 'off'); unwind_protect t = table ([1; 2; 3], categorical ({'lo'; 'hi'; 'lo'}, {'lo', 'mid', ... 'hi'}), 'VariableNames', {'N', 'C'}); h = parallelplot (t, 'Jitter', 0); tag = 'stats.chart.ParallelCoordinatesPlot'; ax = findall (hf, 'type', 'axes', 'tag', tag); ln = findobj (ax, 'type', 'line'); yd = get (ln(end), 'ydata'); assert_equal (yd(:)', [0, 0, NaN, 0.5, 1, NaN, 1, 0, NaN], -1e-15); unwind_protect_cleanup close (hf); end_unwind_protect ***** shared pcS pcS = struct ('Data', magic (3), 'SourceTable', [], ... 'CoordinateData', [], 'CoordinateVariables', {{}}, ... 'GroupData', [], 'GroupVariable', ''); ***** error ... stats.chart.ParallelCoordinatesPlot ([]) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'Data', {1}}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'CoordinateData', 4}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'CoordinateVariables', 1}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'GroupData', [1; 2]}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'GroupData', ones(3, 3)}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'DataNormalization', 'norm1'}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'CoordinateTickLabels', 5}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, ... {'CoordinateTickLabels', {'x'}}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'Jitter', 2}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'Color', [2, 0, 0]}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'LineStyle', 'o'}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'LineWidth', 0}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'LineAlpha', 2}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'MarkerStyle', 'q'}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'MarkerSize', -1}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'LegendVisible', 1}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'Title', 5}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'FontSize', 0}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'Position', [0, 0, 1, 0]}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], pcS, {'Visible', 'maybe'}) ***** error ... stats.chart.ParallelCoordinatesPlot ([], ... struct ('Data', [], 'SourceTable', ... table ([1; 2], 'VariableNames', {'A'}), ... 'CoordinateData', [], 'CoordinateVariables', {{'Q'}}, ... 'GroupData', [], 'GroupVariable', '')) ***** error ... stats.chart.ParallelCoordinatesPlot ([], ... struct ('Data', [], 'SourceTable', ... table ([1; 2], 'VariableNames', {'A'}), ... 'CoordinateData', [], 'CoordinateVariables', {{}}, ... 'GroupData', [], 'GroupVariable', 'Q')) 35 tests, 35 passed, 0 known failure, 0 skipped [inst/Plotting/+stats/+chart/HeatmapChart.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/+stats/+chart/HeatmapChart.m ***** shared tbl tbl = table (categorical ({'a';'b';'a';'c';'b';'a';'c';'c'}), ... categorical ({'u';'u';'v';'v';'u';'u';'v';'u'}), ... [1;2;3;4;5;6;7;8], 'VariableNames', {'X', 'Y', 'V'}); ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap (magic (4)); assert_equal (class (h), 'stats.chart.HeatmapChart'); assert_equal (h.XData, {'1'; '2'; '3'; '4'}); assert_equal (h.YData, {'1'; '2'; '3'; '4'}); assert_equal (h.ColorData, magic (4)); assert_equal (h.ColorDisplayData, magic (4)); assert_equal (h.ColorLimits, [1, 16]); assert_equal (h.ColorMethod, 'none'); assert_equal (h.ColorScaling, 'scaled'); assert_equal (h.CellLabelFormat, '%0.4g'); assert_equal (h.CellLabelColor, 'auto'); assert_equal (h.MissingDataColor, [0.15, 0.15, 0.15]); assert_equal (h.MissingDataLabel, 'NaN'); assert_equal (h.FontSize, 10); assert_equal (h.Position, [0.13, 0.11, 0.732143, 0.815], -1e-12); assert_equal (h.OuterPosition, [0, 0, 1, 1]); assert_equal (h.Parent, hf); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap (magic (3)); assert_equal (size (h.Colormap), [256, 3]); assert_equal (h.Colormap(1,:), [0.9, 0.9447, 0.9741]); assert_equal (h.Colormap(2,:), ... [0.896470588235294, 0.942748235294118, ... 0.973185882352941], -1e-14); assert_equal (h.Colormap(end,:), [0, 0.447, 0.741], -1e-15); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap ({'a', 'b', 'c'}, {'r1', 'r2'}, [1, 2, 3; 4, 5, 6]); assert_equal (h.XData, {'a'; 'b'; 'c'}); assert_equal (h.YData, {'r1'; 'r2'}); assert_equal (h.XDisplayLabels, {'a'; 'b'; 'c'}); assert_equal (h.XLimits, {'a', 'c'}); assert_equal (h.ColorLimits, [1, 6]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap ([1, 2, 3], [10, 20], [1, 2, 3; 4, 5, 6]); assert_equal (h.XData, {'1'; '2'; '3'}); assert_equal (h.YData, {'10'; '20'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap (tbl, 'X', 'Y'); assert_equal (h.ColorData, [2, 2, 1; 1, 0, 2]); assert_equal (h.XData, {'a'; 'b'; 'c'}); assert_equal (h.YData, {'u'; 'v'}); assert_equal (h.Title, 'Count of Y vs. X'); assert_equal (h.XLabel, 'X'); assert_equal (h.YLabel, 'Y'); assert_equal (h.ColorMethod, 'count'); assert_equal (h.ColorVariable, ''); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap (tbl, 'X', 'Y', 'ColorVariable', 'V'); assert_equal (h.ColorData, [3.5, 3.5, 8; 3, NaN, 5.5]); assert_equal (h.Title, 'Mean of V'); assert_equal (h.ColorMethod, 'mean'); h.ColorMethod = 'sum'; assert_equal (h.ColorData, [7, 7, 8; 3, 0, 11]); assert_equal (h.Title, 'Sum of V'); h.ColorMethod = 'median'; assert_equal (h.ColorData, [3.5, 3.5, 8; 3, NaN, 5.5]); assert_equal (h.Title, 'Median of V'); h.ColorMethod = 'max'; assert_equal (h.ColorData, [6, 5, 8; 3, NaN, 7]); assert_equal (h.Title, 'Maximum of V'); h.ColorMethod = 'min'; assert_equal (h.Title, 'Minimum of V'); h.ColorMethod = 'count'; assert_equal (h.Title, 'Count of Y vs. X'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect t = table (categorical ({'a';'b';'c';'a'}), ... categorical ({'u';'u';'v';'v'}), [1;2;3;4], ... 'VariableNames', {'X', 'Y', 'V'}); h = heatmap (t, 'X', 'Y', 'ColorVariable', 'V', 'ColorMethod', 'none'); assert_equal (h.ColorData, [1, 2, NaN; 4, NaN, 3]); assert_equal (h.Title, 'V'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect t = table ({'a';'a';'a';'b';'b'}, {'u';'u';'u';'u';'u'}, ... [1;NaN;5;2;4], 'VariableNames', {'X', 'Y', 'V'}); h = heatmap (t, 'X', 'Y', 'ColorVariable', 'V'); assert_equal (h.ColorData, [3, 3]); h.ColorMethod = 'count'; assert_equal (h.ColorData, [3, 2]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect t = table (categorical ({'lo';'hi';'lo'}, {'lo', 'mid', 'hi'}), ... categorical ({'u';'u';'v'}), [1;2;3], ... 'VariableNames', {'X', 'Y', 'V'}); h = heatmap (t, 'X', 'Y'); assert_equal (h.XData, {'lo'; 'mid'; 'hi'}); assert_equal (h.ColorData, [1, 0, 1; 1, 0, 0]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect t = table ([0.5; -2; 1e6; NaN; 3], {'u';'v';'u';'u';''}, ... [1;2;3;4;5], 'VariableNames', {'X', 'Y', 'V'}); h = heatmap (t, 'X', 'Y'); assert_equal (h.XData, {'-2'; '0.5'; '3'; '1e+06'}); assert_equal (h.YData, {'u'; 'v'}); assert_equal (h.ColorData, [0, 1, 0, 1; 1, 0, 0, 0]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect t = table ([3;1;2;1;3], {'p';'q';'p';'p';'q'}, [true; false; true; ... true; false], 'VariableNames', {'N', 'S', 'L'}); h = heatmap (t, 'N', 'S'); assert_equal (h.XData, {'1'; '2'; '3'}); assert_equal (h.ColorData, [1, 1, 1; 1, 0, 1]); h.XVariable = 'L'; assert_equal (h.XData, {'false'; 'true'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap ([1, NaN, 3; 4, 5, NaN]); assert_equal (h.ColorLimits, [1, 5]); assert_equal (h.ColorDisplayData, [1, NaN, 3; 4, 5, NaN]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap ([1, 2, 3; 4, 5, 16]); h.ColorScaling = 'scaledcolumns'; assert_equal (h.ColorDisplayData, [1, 2, 3; 4, 5, 16]); assert_equal (h.ColorLimits, [0, 1]); h.ColorScaling = 'scaledrows'; assert_equal (h.ColorLimits, [0, 1]); h.ColorScaling = 'log'; assert_equal (h.ColorLimits, [0, log(16)], -1e-15); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap ([2, 2; 2, 2]); assert_equal (h.ColorLimits, [1, 3]); h.ColorData = [NaN, NaN; NaN, NaN]; assert_equal (h.ColorLimits, [0, 1]); h.ColorData = [5, 6; 7, 50]; assert_equal (h.ColorLimits, [5, 50]); h.ColorLimits = [0, 20]; h.ColorData = [1, 100; 2, 3]; assert_equal (h.ColorLimits, [0, 20]); h.ColorScaling = 'scaledcolumns'; assert_equal (h.ColorLimits, [0, 20]); unwind_protect_cleanup close (hf); end_unwind_protect ***** warning ... hf = figure ('visible', 'off'); unwind_protect h = heatmap ([1, -2, 3; 4, 5, 6]); h.ColorScaling = 'log'; assert_equal (h.ColorLimits, [0, log(6)], -1e-15); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap ({'c', 'a', 'b'}, {'y', 'x'}, [3, 1, 2; 6, 4, 5]); sortx (h); assert_equal (h.XDisplayData, {'a'; 'b'; 'c'}); assert_equal (h.ColorDisplayData, [1, 2, 3; 4, 5, 6]); sortx (h, 'x', 'descend'); assert_equal (h.XDisplayData, {'c'; 'b'; 'a'}); assert_equal (h.ColorDisplayData, [3, 2, 1; 6, 5, 4]); sorty (h, 'a'); assert_equal (h.YDisplayData, {'y'; 'x'}); sorty (h); assert_equal (h.YDisplayData, {'x'; 'y'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap ({'c', 'a', 'b'}, {'y', 'x'}, [3, NaN, 2; 6, 4, 5]); sortx (h, 'y'); assert_equal (h.XDisplayData, {'b'; 'c'; 'a'}); sortx (h, 'y', 'descend'); assert_equal (h.XDisplayData, {'a'; 'c'; 'b'}); sortx (h, 'y', 'ascend', 'MissingPlacement', 'first'); assert_equal (h.XDisplayData, {'a'; 'b'; 'c'}); sortx (h, {'y', 'x'}); assert_equal (h.XDisplayData, {'b'; 'c'; 'a'}); sorty (h, 'b', 'descend'); assert_equal (h.YDisplayData, {'x'; 'y'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap ({'a', 'b', 'c'}, {'r1', 'r2'}, [1, 2, 3; 4, 5, 6]); h.XDisplayData = {'c'; 'a'}; assert_equal (h.ColorDisplayData, [3, 1; 6, 4]); h.XDisplayLabels = {'C'; 'A'}; assert_equal (h.XDisplayLabels, {'C'; 'A'}); assert_equal (h.XDisplayData, {'c'; 'a'}); h.XDisplayData = {'a'; 'c'; 'b'}; assert_equal (h.XDisplayLabels, {'A'; 'C'; 'b'}); h.XDisplayData = {'9'}; assert_equal (h.ColorDisplayData, [NaN; NaN]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap ({'c', 'a', 'b'}, {'y', 'x'}, [3, 1, 2; 6, 4, 5]); assert_equal (xlim (h), {'c', 'b'}); xlim (h, {'a', 'b'}); assert_equal (h.XLimits, {'a', 'b'}); assert_equal (h.XDisplayData, {'c'; 'a'; 'b'}); assert_equal (ylim (h), {'y', 'x'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** warning ... hf = figure ('visible', 'off'); unwind_protect h = heatmap ({'c', 'a', 'b'}, {'y', 'x'}, [3, 1, 2; 6, 4, 5]); xlim (h, {'a', 'b'}); h.XDisplayData = {'b'; 'c'; 'a'}; assert_equal (h.XLimits, {'b', 'a'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap ({'c', 'a', 'b'}, {'y', 'x'}, [3, 1, 2; 6, 4, 5]); sortx (h); sorty (h); lastwarn (''); sortx (h, 'x', 'descend'); sorty (h, 'a'); assert_equal (isempty (strfind (lastwarn (), 'HeatmapChart')), true); assert_equal (h.XLimits, {'c', 'a'}); assert_equal (h.YLimits, {'y', 'x'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap ([1, 2; 3, 4]); h.ColorData = [1, 2, 3; 4, 5, 6]; assert_equal (h.XData, {'1'; '2'; '3'}); h.XData = {'p'; 'q'; 'r'}; assert_equal (h.XDisplayData, {'p'; 'q'; 'r'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap (tbl, 'X', 'Y', 'ColorVariable', 'V'); h.Title = 'Mine'; h.ColorMethod = 'sum'; assert_equal (h.Title, 'Mine'); h.XLabel = 'XX'; h.XVariable = 'V'; assert_equal (h.XLabel, 'XX'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap (magic (3), 'Colormap', gray (5), 'ColorbarVisible', 'off', ... 'CellLabelColor', 'none', 'GridVisible', 'off', ... 'Title', 'T', 'XLabel', 'XL', 'YLabel', 'YL', ... 'FontSize', 14, 'CellLabelFormat', '%.2f'); assert_equal (h.Colormap, gray (5)); assert_equal (h.ColorbarVisible, 'off'); assert_equal (h.CellLabelColor, 'none'); assert_equal (h.GridVisible, 'off'); assert_equal (h.Title, 'T'); assert_equal (h.FontSize, 14); assert_equal (h.CellLabelFormat, '%.2f'); h.Title = {'one', 'two'}; assert_equal (h.Title, {'one'; 'two'}); h.MissingDataColor = 'r'; assert_equal (h.MissingDataColor, [1, 0, 0]); h.FontColor = 'g'; assert_equal (h.FontColor, [0, 1, 0]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap (magic (3)); ax = findall (hf, 'type', 'axes', 'tag', 'stats.chart.HeatmapChart'); assert_equal (numel (ax), 1); assert_equal (gca (), ax); im = findall (ax, 'type', 'image'); assert_equal (get (im, 'cdata'), magic (3)); assert_equal (get (ax, 'clim'), [1, 9]); assert_equal (numel (findall (ax, 'type', 'text', 'string', '5')), 1); delete (h); tag = 'stats.chart.HeatmapChart'; assert_equal (isempty (findall (hf, 'tag', tag)), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect hp = uipanel (hf); h = heatmap (hp, magic (3)); assert_equal (h.Parent, hp); unwind_protect_cleanup close (hf); end_unwind_protect ***** shared hmS, hmT hmS = struct ('ColorData', magic (3), 'XData', {{}}, 'YData', {{}}, ... 'SourceTable', [], 'XVariable', '', 'YVariable', '', ... 'ColorVariable', ''); hmT = struct ('ColorData', [], 'XData', {{}}, 'YData', {{}}, ... 'SourceTable', table ({'a'; 'a'}, {'u'; 'u'}, [1; 2], ... 'VariableNames', {'X', 'Y', 'V'}), ... 'XVariable', 'X', 'YVariable', 'Y', 'ColorVariable', 'V'); ***** error ... stats.chart.HeatmapChart ([]) ***** error ... stats.chart.HeatmapChart ([], hmS, {'ColorData', ones(2, 2, 2)}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'XData', {'a', 'a', 'b'}}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'XData', {1, 2}}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'XDisplayLabels', {'a'}}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'XLimits', {'1'}}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'XLimits', {'3', '1'}}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'SourceTable', 5}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'ColorVariable', 5}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'ColorMethod', 'mode'}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'ColorScaling', 'foo'}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'ColorLimits', [5, 1]}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'Colormap', 'jet'}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'ColorbarVisible', 'yes'}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'MissingDataColor', 'auto'}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'MissingDataLabel', 5}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'CellLabelFormat', 5}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'CellLabelColor', [2, 0, 0]}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'GridVisible', 1}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'Title', 5}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'FontSize', 0}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'FontColor', 'none'}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'Interpreter', 'html'}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'Position', [0, 0, 0, 1]}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'Units', 'miles'}) ***** error ... stats.chart.HeatmapChart ([], hmS, {'Visible', 'no'}) ***** error ... stats.chart.HeatmapChart ([], hmT, {'XVariable', 'Q'}) ***** error ... stats.chart.HeatmapChart ([], hmT, {'ColorMethod', 'none'}) ***** error ... stats.chart.HeatmapChart ([], hmT, {'ColorVariable', 'X'}) 55 tests, 55 passed, 0 known failure, 0 skipped [inst/Plotting/heatmap.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/heatmap.m ***** demo ## A matrix as a heatmap: each cell carries its value and its colour. heatmap (magic (5)); ***** demo ## Columns and rows may be named, and the colours changed. h = heatmap ({'Mon', 'Tue', 'Wed', 'Thu', 'Fri'}, {'am', 'pm'}, ... [12, 15, 9, 20, 18; 7, 11, 14, 6, 9]); h.Title = 'Calls answered'; h.Colormap = gray (64); ***** demo ## From a table: the cars of each origin and number of cylinders, and ## then their mean mileage. load carsmall t = table (categorical (cellstr (Origin)), Cylinders, MPG, ... 'VariableNames', {'Origin', 'Cylinders', 'MPG'}); subplot (1, 2, 1); heatmap (t, 'Cylinders', 'Origin'); subplot (1, 2, 2); heatmap (t, 'Cylinders', 'Origin', 'ColorVariable', 'MPG'); ***** test hf = figure ('visible', 'off'); unwind_protect heatmap (magic (3)); ax = findall (hf, 'tag', 'stats.chart.HeatmapChart'); assert_equal (numel (ax), 1); assert_equal (gca (), ax); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = heatmap ({'a', 'b'}, [1, 2, 3], [1, 2; 3, 4; 5, 6], 'Title', 'T', ... 'colormap', gray (4)); assert_equal (h.XData, {'a'; 'b'}); assert_equal (h.YData, {'1'; '2'; '3'}); assert_equal (h.Title, 'T'); assert_equal (h.Colormap, gray (4)); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect t = table (categorical ({'a';'b';'a'}), categorical ({'u';'u';'v'}), ... [1;2;3], 'VariableNames', {'X', 'Y', 'V'}); h = heatmap (t, "X", "Y", 'ColorVariable', 'V', 'ColorMethod', 'sum'); assert_equal (h.ColorData, [1, 2; 3, 0]); assert_equal (h.Title, 'Sum of V'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect plot (1:3); pax = gca (); h = heatmap (magic (3)); assert_equal (ishghandle (pax), false); h2 = heatmap (magic (4)); assert_equal (numel (findall (hf, 'tag', 'stats.chart.HeatmapChart')), 1); assert_equal (isempty (h.Parent), true); plot (1:3); assert_equal (isempty (h2.Parent), true); tag = 'stats.chart.HeatmapChart'; assert_equal (isempty (findall (hf, 'tag', tag)), true); assert_equal (numel (findall (gca (), 'type', 'line')), 1); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect left = subplot (1, 2, 1); plot (1:3); subplot (1, 2, 2); outer = get (gca (), 'outerposition'); h = heatmap (magic (3)); assert_equal (h.OuterPosition, outer, -1e-12); assert_equal (ishghandle (left), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** error heatmap () ***** error ... hf = figure ('visible', 'off'); unwind_protect heatmap (axes (hf), magic (3)); unwind_protect_cleanup close (hf); end_unwind_protect ***** error ... heatmap (table ([1; 2]), 'Var1') ***** error ... heatmap ([1, 2], [1, 2]) ***** error ... heatmap ('abc') ***** error ... heatmap ({1, 2}) ***** error ... heatmap (ones (2, 2, 2)) ***** error ... heatmap ({'a', 'b'}, {'r1'}, [1, 2, 3]) ***** error ... heatmap ({'a', 'b', 'c'}, {'r1', 'r2'}, [1, 2, 3]) ***** error ... heatmap (magic (3), 'Title') ***** error ... heatmap (magic (3), 'Foo', 1) ***** error ... heatmap (magic (3), 'ColorVariable', 'V') ***** error ... hf = figure ('visible', 'off'); unwind_protect plot (1:3); hold on; heatmap (magic (3)); unwind_protect_cleanup close (hf); end_unwind_protect 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Plotting/scatterhist.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/scatterhist.m ***** demo ## Scatter plot of two iris measurements with marginal histograms by species. load fisheriris; scatterhist (meas(:,1), meas(:,2), "Group", species); ***** demo ## Marginal kernel density estimates instead of histograms. load fisheriris; scatterhist (meas(:,3), meas(:,4), "Group", species, "Kernel", "on"); ***** test # LineWidth and LineStyle apply to the marginals and cycle over groups hf = figure ("visible", "off"); unwind_protect x = [1 2 3 4 5 6 7 8]'; y = [2 1 4 3 6 5 8 7]'; g = [1 1 1 1 2 2 2 2]'; h = scatterhist (x, y, "Group", g, "LineWidth", 3); ch = get (h(2), "children"); assert_equal (get (ch(1), "linewidth"), 3); assert_equal (get (ch(2), "linewidth"), 3); h = scatterhist (x, y, "Group", g, "LineStyle", {"--", ":"}); ch = get (h(2), "children"); assert_equal (get (ch(2), "linestyle"), "--"); assert_equal (get (ch(1), "linestyle"), ":"); unwind_protect_cleanup close (hf); end_unwind_protect warning: legend: 'best' not yet implemented for location specifier, using 'northeast' instead warning: legend: 'best' not yet implemented for location specifier, using 'northeast' instead ***** test # Bandwidth is passed to the kernel density hf = figure ("visible", "off"); unwind_protect x = [1 2 3 4 5 6 7 8]'; y = [2 1 4 3 6 5 8 7]'; h = scatterhist (x, y, "Kernel", "on", "Bandwidth", 2); wide = get (get (h(2), "children")(1), "ydata"); h = scatterhist (x, y, "Kernel", "on"); auto = get (get (h(2), "children")(1), "ydata"); assert_equal (! isequal (wide, auto), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** error ... scatterhist ([1 2 3]', [1 2 3]', "LineWidth", -1) ***** error ... scatterhist ([1 2 3]', [1 2 3]', "LineStyle", 5) ***** error ... scatterhist ([1 2 3]', [1 2 3]', "Bandwidth", 0) ***** test # Parent draws into a supplied container without clearing it hf = figure ("visible", "off"); unwind_protect x = [1 2 3 4 5 6 7 8]'; y = [2 1 4 3 6 5 8 7]'; pre = axes ("parent", hf, "position", [0.01, 0.01, 0.05, 0.05]); h = scatterhist (x, y, "Parent", hf); assert_equal (all (arrayfun (@(a) get (a, "parent"), h) == hf, 'all'), ... true); ## the caller's own axes are left alone assert_equal (ishghandle (pre), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a uipanel is a container too hf = figure ("visible", "off"); unwind_protect x = [1 2 3 4 5 6 7 8]'; y = [2 1 4 3 6 5 8 7]'; hp = uipanel ("parent", hf, "position", [0, 0, 1, 1]); h = scatterhist (x, y, "Parent", hp); assert_equal (all (arrayfun (@(a) get (a, "parent"), h) == hp, 'all'), ... true); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # without Parent the current figure is still claimed and cleared hf = figure ("visible", "off"); unwind_protect x = [1 2 3 4 5 6 7 8]'; y = [2 1 4 3 6 5 8 7]'; old = axes ("parent", hf); h = scatterhist (x, y); assert_equal (ishghandle (old), false); unwind_protect_cleanup close (hf); end_unwind_protect ***** error ... scatterhist ([1 2 3]', [1 2 3]', "Parent", 0) ***** error ... scatterhist ([1 2 3]', [1 2 3]', "Parent", -5) ***** test # Location names the marginals' corner, so the scatter takes the other hf = figure ("visible", "off"); unwind_protect x = [1 2 3 4 5 6 7 8]'; y = [2 1 4 3 6 5 8 7]'; ## Offsets and size are R2024a's own, measured. h = scatterhist (x, y, "Location", "SouthWest"); ps = get (h(1), "position"); px = get (h(2), "position"); assert_equal (ps(1:2), [0.35, 0.35], 1e-12); assert_equal (ps(3:4), [0.55, 0.55], 1e-12); assert_equal (px(2) < ps(2), true); # x marginal below the scatter h = scatterhist (x, y, "Location", "NorthEast"); ps = get (h(1), "position"); px = get (h(2), "position"); assert_equal (ps(1:2), [0.10, 0.10], 1e-12); assert_equal (px(2) > ps(2), true); # and above it here ## The y marginal follows the named corner in the same way. h = scatterhist (x, y, "Location", "SouthEast"); ps = get (h(1), "position"); py = get (h(3), "position"); assert_equal (ps(1:2), [0.10, 0.35], 1e-12); assert_equal (py(1) > ps(1), true); # y marginal right of scatter h = scatterhist (x, y, "Location", "NorthWest"); ps = get (h(1), "position"); py = get (h(3), "position"); assert_equal (ps(1:2), [0.35, 0.10], 1e-12); assert_equal (py(1) < ps(1), true); # and left of it here unwind_protect_cleanup close (hf); end_unwind_protect ***** test # Direction is relative to where Location put each marginal hf = figure ("visible", "off"); unwind_protect x = [1 2 3 4 5 6 7 8]'; y = [2 1 4 3 6 5 8 7]'; ## "in" points the bars at the scatter from whichever side they sit on. ## The x marginal's ydir is R2024a's, measured in all four corners; the y ## marginal's xdir is ours, MATLAB rotating that axes instead (see the ## note in the file header). h = scatterhist (x, y, "Location", "SouthWest"); assert_equal (get (h(2), "ydir"), "normal"); assert_equal (get (h(3), "xdir"), "normal"); h = scatterhist (x, y, "Location", "NorthEast"); assert_equal (get (h(2), "ydir"), "reverse"); assert_equal (get (h(3), "xdir"), "reverse"); h = scatterhist (x, y, "Location", "SouthEast"); assert_equal (get (h(2), "ydir"), "normal"); assert_equal (get (h(3), "xdir"), "reverse"); h = scatterhist (x, y, "Location", "NorthWest"); assert_equal (get (h(2), "ydir"), "reverse"); assert_equal (get (h(3), "xdir"), "normal"); ## and "out" inverts each of them h = scatterhist (x, y, "Location", "NorthEast", "Direction", "out"); assert_equal (get (h(2), "ydir"), "normal"); assert_equal (get (h(3), "xdir"), "normal"); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # Direction points the marginals toward the scatter by default hf = figure ("visible", "off"); unwind_protect x = [1 2 3 4 5 6 7 8]'; y = [2 1 4 3 6 5 8 7]'; h = scatterhist (x, y); assert_equal (get (h(2), "ydir"), "normal"); assert_equal (get (h(3), "xdir"), "normal"); h = scatterhist (x, y, "Direction", "out"); assert_equal (get (h(2), "ydir"), "reverse"); assert_equal (get (h(3), "xdir"), "reverse"); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # Color sets the group colours, cycling if fewer than the groups hf = figure ("visible", "off"); unwind_protect x = [1 2 3 4 5 6 7 8]'; y = [2 1 4 3 6 5 8 7]'; g = [1 1 1 1 2 2 2 2]'; h = scatterhist (x, y, "Group", g, "Color", "rb"); c = get (get (h(1), "children"), "color"); assert_equal (c{2}, [1, 0, 0]); assert_equal (c{1}, [0, 0, 1]); unwind_protect_cleanup close (hf); end_unwind_protect warning: legend: 'best' not yet implemented for location specifier, using 'northeast' instead ***** test # PlotGroup pools the marginals when off hf = figure ("visible", "off"); unwind_protect x = [1 2 3 4 5 6 7 8]'; y = [2 1 4 3 6 5 8 7]'; g = [1 1 1 1 2 2 2 2]'; h = scatterhist (x, y, "Group", g, "PlotGroup", "off"); assert_equal (numel (get (h(2), "children")), 1); h = scatterhist (x, y, "Group", g, "PlotGroup", "on"); assert_equal (numel (get (h(2), "children")), 2); unwind_protect_cleanup close (hf); end_unwind_protect warning: legend: 'best' not yet implemented for location specifier, using 'northeast' instead warning: legend: 'best' not yet implemented for location specifier, using 'northeast' instead ***** error ... scatterhist ([1 2 3]', [1 2 3]', "NBins", 0) ***** error ... scatterhist ([1 2 3]', [1 2 3]', "NBins", 2.5) ***** error ... scatterhist ([1 2 3]', [1 2 3]', "NBins", [2, 3, 4]) ***** error ... scatterhist ([1 2 3]', [1 2 3]', "Kernel", "sometimes") ***** error ... scatterhist ([1 2 3]', [1 2 3]', "Kernel", 1) ***** error ... scatterhist ([1 2 3]', [1 2 3]', "Location", "middle") ***** error ... scatterhist ([1 2 3]', [1 2 3]', "Legend", "maybe") ***** error ... scatterhist ([1 2 3]', [1 2 3]', "Marker", 7) ***** error ... scatterhist ([1 2 3]', [1 2 3]', "MarkerSize", 0) ***** error ... scatterhist ([1 2 3]', [1 2 3]', "Color", [1, 2]) ***** error ... scatterhist ([1 2 3]', [1 2 3]', "Color", "q") ***** error ... scatterhist ([1 2 3]', [1 2 3]', "Direction", "sideways") ***** error ... scatterhist ([1 2 3]', [1 2 3]', "Style", "curvy") ***** error ... scatterhist ([1 2 3]', [1 2 3]', "PlotGroup", "maybe") ***** test hf = figure ("visible", "off"); unwind_protect x = [2.1 3.4 1.9 5.6 4.2 3.3 2.8 6.1 4.9 3.7 2.2 5.1 4.4 3.9 2.6]'; y = [1.2 2.4 3.1 2.6 4.5 3.3 5.1 2.8 4.0 3.6 1.9 4.4 3.2 2.1 5.0]'; h = scatterhist (x, y); assert_equal (numel (h), 3); assert_equal (all (isaxes (h), 'all'), true); ## the scatter axes hold the data sc = get (h(1), "children"); assert_equal (get (sc(1), "xdata")(:), x, 1e-12); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # grouped scatterhist runs and returns three axes hf = figure ("visible", "off"); unwind_protect x = [1 2 3 4 5 6]'; y = [2 1 4 3 6 5]'; g = [1 1 1 2 2 2]'; h = scatterhist (x, y, "Group", g); assert_equal (numel (h), 3); assert_equal (all (isaxes (h), 'all'), true); unwind_protect_cleanup close (hf); end_unwind_protect warning: legend: 'best' not yet implemented for location specifier, using 'northeast' instead ***** test # kernel option runs hf = figure ("visible", "off"); unwind_protect x = randn (50, 1); y = randn (50, 1); h = scatterhist (x, y, "Kernel", "on"); assert_equal (numel (h), 3); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # NBins accepts a two-element specification hf = figure ("visible", "off"); unwind_protect x = randn (40, 1); y = randn (40, 1); h = scatterhist (x, y, "NBins", [5 8]); assert_equal (numel (h), 3); unwind_protect_cleanup close (hf); end_unwind_protect ***** error scatterhist (1) ***** error ... scatterhist ({1}, {2}) ***** error ... scatterhist ([1 2 3], [1 2]) ***** error ... scatterhist ([1 2 3], [1 2 3], "Group") ***** error ... scatterhist ([1 2 3], [1 2 3], "bogus", 1) ***** error ... scatterhist ([1 2 3], [1 2 3], "Group", [1 2]) 39 tests, 39 passed, 0 known failure, 0 skipped [inst/Plotting/einstein.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/einstein.m ***** demo einstein (0.4, 0.6) ***** demo einstein (0.2, 0.5) ***** demo einstein (0.6, 0.1) ***** test hf = figure ('visible', 'off'); unwind_protect tiles = einstein (0.4, 0.6); assert_equal (isstruct (tiles), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** error einstein ***** error einstein (0.5) ***** error einstein (0, 0.9) ***** error einstein (0.4, 1) ***** error einstein (-0.4, 1) 6 tests, 6 passed, 0 known failure, 0 skipped [inst/Plotting/boxchart.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/boxchart.m ***** demo ## One box over a sample: the box spans the quartiles with the median ## across it, the whiskers reach the furthest values within one and a half ## interquartile ranges, and the rest are drawn as markers. load fisheriris boxchart (meas(:,1)); ylabel ('sepal length'); ***** demo ## One box per group, and a notch about each median. Two notches that do ## not overlap mark medians that differ at roughly the five per cent level. load fisheriris g = grp2idx (species); boxchart (g, meas(:,1), 'Notch', 'on'); xlabel ('species'); ylabel ('sepal length'); ***** demo ## The chart keeps what it was drawn from, so its properties may be set ## afterwards and it redraws itself. load fisheriris b = boxchart (meas(:,1)); b.Orientation = 'horizontal'; b.BoxFaceColor = [0.85, 0.325, 0.098]; b.JitterOutliers = 'on'; ***** shared bcY, bcG, bcC, bcT bcY = [1; 2; 3; 4; 5; 6; 7; 8; 9; 100]; bcG = [1; 1; 1; 1; 1; 2; 2; 2; 2; 2]; bcC = {'a'; 'b'; 'a'; 'b'; 'a'; 'b'; 'a'; 'b'; 'a'; 'b'}; bcT = table (bcG, bcY, 'VariableNames', {'grp', 'val'}); ***** test hf = figure ('visible', 'off'); unwind_protect b = boxchart (bcY); assert_equal (class (b), 'stats.chart.BoxChart'); assert_equal (quantile (bcY, 0.25), 3); assert_equal (quantile (bcY, 0.75), 8); assert_equal (median (bcY), 5.5); assert_equal (sum (isoutlier (bcY, 'quartiles')), 1); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # MATLAB parity: the defaults are the ones R2026a reports hf = figure ('visible', 'off'); unwind_protect b = boxchart (bcY); assert_equal (b.BoxWidth, 0.5); assert_equal (b.BoxFaceAlpha, 0.2); assert_equal (b.CapWidth, 0.25); assert_equal (b.LineWidth, 1); assert_equal (b.MarkerSize, 6); assert_equal (b.MarkerStyle, 'o'); assert_equal (b.Notch, 'off'); assert_equal (b.JitterOutliers, 'off'); assert_equal (b.Orientation, 'vertical'); assert_equal (b.WhiskerLineStyle, '-'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a group per distinct value, each with its own box hf = figure ('visible', 'off'); unwind_protect one = boxchart (bcY); n1 = numel (get (gca (), 'children')); clf (hf); two = boxchart (bcG, bcY); n2 = numel (get (gca (), 'children')); assert_equal (n2 > n1, true); assert_equal (two.XDataMode, 'manual'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect b = boxchart (bcT, 'grp', 'val'); assert_equal (b.YVariable, 'val'); assert_equal (b.XVariable, 'grp'); assert_equal (b.XDataMode, 'auto'); assert_equal (b.YDataMode, 'auto'); assert_equal (b.YData, bcY); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a table may name the observations alone hf = figure ('visible', 'off'); unwind_protect b = boxchart (bcT, 'val'); assert_equal (b.YVariable, 'val'); assert_equal (isempty (b.XVariable), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect b = boxchart (bcT, 'grp', 'val'); t = bcT; t.val(1) = 999; b.SourceTable = t; assert_equal (b.YData(1), 999); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect b = boxchart (bcG, bcY, 'GroupByColor', bcC); assert_equal (numel (b), 2); assert_equal (class (b), 'stats.chart.BoxChart'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # setting a property redraws rather than draws again over the old hf = figure ('visible', 'off'); unwind_protect b = boxchart (bcY); before = numel (get (gca (), 'children')); b.Notch = 'on'; assert_equal (numel (get (gca (), 'children')), before); b.BoxFaceColor = 'r'; assert_equal (numel (get (gca (), 'children')), before); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # setting a colour records that it was chosen hf = figure ('visible', 'off'); unwind_protect b = boxchart (bcY); assert_equal (b.BoxFaceColorMode, 'auto'); b.BoxFaceColor = [1, 0, 0]; assert_equal (b.BoxFaceColorMode, 'manual'); assert_equal (b.BoxFaceColor, [1, 0, 0]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a horizontal chart draws the same pieces the other way about hf = figure ('visible', 'off'); unwind_protect b = boxchart (bcY); before = numel (get (gca (), 'children')); b.Orientation = 'horizontal'; assert_equal (b.Orientation, 'horizontal'); assert_equal (numel (get (gca (), 'children')), before); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # the axes to draw into may be given first, as for any plot hf = figure ('visible', 'off'); unwind_protect a1 = subplot (1, 2, 1); a2 = subplot (1, 2, 2); b = boxchart (a2, bcY); assert_equal (b.Parent, a2); assert_equal (isempty (get (a1, 'children')), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** error boxchart () ***** error ... boxchart (bcT, 'grp', 'val', 'GroupByColor', bcC) ***** error ... boxchart (bcT, 'nope') ***** error ... boxchart ([1; 2], bcY) ***** error ... boxchart (bcG, bcY, 'GroupByColor', {'a'; 'b'}) ***** error ... boxchart (bcY, 'Notch') ***** error ... boxchart (bcY, 'BoxWidth', -1) ***** error ... boxchart (bcY, 'Notch', 'maybe') ***** error ... boxchart (bcY, 'BoxFaceAlpha', 2) 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Plotting/hist3.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/hist3.m ***** demo X = [ 1 1 1 1 1 10 1 10 5 5 5 5 5 5 5 5 5 5 7 3 7 3 7 3 10 10 10 10]; hist3 (X) ***** test N_exp = [ 0 0 0 5 20 0 0 10 15 0 0 15 10 0 0 20 5 0 0 0]; n = 100; x = [1:n]'; y = [n:-1:1]'; D = [x y]; N = hist3 (D, [4 5]); assert_equal (N, N_exp); ***** test N_exp = [0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1 1 1 1 93]; n = 100; x = [1:n]'; y = [n:-1:1]'; D = [x y]; C{1} = [1 1.7 3 4]; C{2} = [1:5]; N = hist3 (D, C); assert_equal (N, N_exp); ***** test D = [1 1; 3 1; 3 3; 3 1]; [c, nn] = hist3 (D, {0:4, 0:4}); exp_c = zeros (5); exp_c([7 9 19]) = [1 2 1]; assert_equal (c, exp_c); assert_equal (nn, {0:4, 0:4}); ***** test for i = 10 assert_equal (size (hist3 (rand (9, 2), 'Edges', {[0:.2:1]; [0:.2:1]})), [6 6]) endfor ***** test edge_1 = linspace (0, 10, 10); edge_2 = linspace (0, 50, 10); [c, nn] = hist3 ([1:10; 1:5:50]', 'Edges', {edge_1, edge_2}); exp_c = zeros (10, 10); exp_c([1 12 13 24 35 46 57 68 79 90]) = 1; assert_equal (c, exp_c); assert_equal (nn{1}, edge_1 + edge_1(2)/2, eps*10^4) assert_equal (nn{2}, edge_2 + edge_2(2)/2, eps*10^4) ***** shared X X = [ 5 2 5 3 1 4 5 3 4 4 1 2 2 3 3 3 5 4 5 3]; ***** test N = zeros (10); N([1 10 53 56 60 91 98 100]) = [1 1 1 1 3 1 1 1]; C = {(1.2:0.4:4.8), (2.1:0.2:3.9)}; assert_equal (nthargout ([1 2], @hist3, X), {N C}, eps*10^3) ***** test N = zeros (5, 7); N([1 5 17 18 20 31 34 35]) = [1 1 1 1 3 1 1 1]; C = {(1.4:0.8:4.6), ((2+(1/7)):(2/7):(4-(1/7)))}; assert_equal (nthargout ([1 2], @hist3, X, [5 7]), {N C}, eps*10^3) assert_equal (nthargout ([1 2], @hist3, X, 'Nbins', [5 7]), {N C}, eps*10^3) ***** test N = [0 1 0; 0 1 0; 0 0 1; 0 0 0]; C = {(2:5), (2.5:1:4.5)}; assert_equal (nthargout ([1 2], @hist3, X, 'Edges', {(1.5:4.5), (2:4)}), {N C}) ***** test N = [0 0 1 0 1 0; 0 0 0 1 0 0; 0 0 1 4 2 0]; C = {(1.2:3.2), (0:5)}; assert_equal (nthargout ([1 2], @hist3, X, 'Ctrs', C), {N C}) assert_equal (nthargout ([1 2], @hist3, X, C), {N C}) ***** test [~, C] = hist3 (rand (10, 2), 'Edges', {[0 .05 .15 .35 .55 .95], [-1 .05 .07 .2 .3 .5 .89 1.2]}); C_exp = {[ 0.025 0.1 0.25 0.45 0.75 1.15], ... [-0.475 0.06 0.135 0.25 0.4 0.695 1.045 1.355]}; assert_equal (C, C_exp, eps*10^2) ***** test Xv = repmat ([1:10]', [1 2]); ## Test Centers assert_equal (hist3 (Xv, 'Ctrs', {1:10, 1:10}), eye (10)) N_exp = eye (6); N_exp([1 end]) = 3; assert_equal (hist3 (Xv, 'Ctrs', {3:8, 3:8}), N_exp) N_exp = zeros (8, 6); N_exp([1 2 11 20 29 38 47 48]) = [2 1 1 1 1 1 1 2]; assert_equal (hist3 (Xv, 'Ctrs', {2:9, 3:8}), N_exp) ## Test Edges assert_equal (hist3 (Xv, 'Edges', {1:10, 1:10}), eye (10)) assert_equal (hist3 (Xv, 'Edges', {3:8, 3:8}), eye (6)) assert_equal (hist3 (Xv, 'Edges', {2:9, 3:8}), [zeros(1, 6); eye(6); zeros(1, 6)]) N_exp = zeros (14); N_exp(3:12, 3:12) = eye (10); assert_equal (hist3 (Xv, 'Edges', {-1:12, -1:12}), N_exp) ## Test for Nbins assert_equal (hist3 (Xv), eye (10)) assert_equal (hist3 (Xv, [10 10]), eye (10)) assert_equal (hist3 (Xv, 'nbins', [10 10]), eye (10)) assert_equal (hist3 (Xv, [5 5]), eye (5) * 2) N_exp = zeros (7, 5); N_exp([1 9 10 18 26 27 35]) = [2 1 1 2 1 1 2]; assert_equal (hist3 (Xv, [7 5]), N_exp) ***** test # bug #51059 D = [1 1; NaN 2; 3 1; 3 3; 1 NaN; 3 1]; [c, nn] = hist3 (D, {0:4, 0:4}); exp_c = zeros (5); exp_c([7 9 19]) = [1 2 1]; assert_equal (c, exp_c) assert_equal (nn, {0:4, 0:4}) ***** test [c, nn] = hist3 ([1 8]); exp_c = zeros (10, 10); exp_c(6, 6) = 1; exp_nn = {-4:5, 3:12}; assert_equal (c, exp_c) assert_equal (nn, exp_nn, eps) [c, nn] = hist3 ([1 8], [10 11]); exp_c = zeros (10, 11); exp_c(6, 6) = 1; exp_nn = {-4:5, 3:13}; assert_equal (c, exp_c) assert_equal (nn, exp_nn, eps) ***** test [c, nn] = hist3 ([1 NaN; 2 3; 6 9; 8 NaN]); exp_c = zeros (10, 10); exp_c(2, 1) = 1; exp_c(8, 10) = 1; exp_nn = {linspace(1.35, 7.65, 10) linspace(3.3, 8.7, 10)}; assert_equal (c, exp_c) assert_equal (nn, exp_nn, eps*100) ***** test [c, nn] = hist3 ([1 NaN; 2 NaN; 6 NaN; 8 NaN]); exp_c = zeros (10, 10); exp_nn = {linspace(1.35, 7.65, 10) NaN(1, 10)}; assert_equal (c, exp_c) assert_equal (nn, exp_nn, eps*100) ***** test [c, nn] = hist3 ([1 NaN; NaN 3; NaN 9; 8 NaN]); exp_c = zeros (10, 10); exp_nn = {linspace(1.35, 7.65, 10) linspace(3.3, 8.7, 10)}; assert_equal (c, exp_c) assert_equal (nn, exp_nn, eps*100) 16 tests, 16 passed, 0 known failure, 0 skipped [inst/Plotting/histfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/histfit.m ***** demo rng (42); histfit (randn (100, 1)) ***** demo rng (42); randp ('state', 42); histfit (poissrnd (2, 1000, 1), 10, 'Poisson') ***** demo randg ('state', 42); histfit (betarnd (3, 10, 1000, 1), 10, 'beta') ***** test hf = figure ('visible', 'off'); unwind_protect x = [2, 4, 3, 2, 4, 3, 2, 5, 6, 4, 7, 5, 9, 8, 10, 4, 11]; histfit (x); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect x = [2, 4, 3, 2, NaN, 3, 2, 5, 6, 4, 7, 5, 9, 8, 10, 4, 11]; histfit (x); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect x = [2, 4, 3, 2, NaN, 3, 2, 5, 6, 4, 7, 5, 9, 8, 10, 4, 11]; histfit (x, 3); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect histfit (randn (100, 1)); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect histfit (poissrnd (2, 1000, 1), 10, 'Poisson'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect histfit (betarnd (3, 10, 1000, 1), 10, 'beta'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect ax = gca (); histfit (ax, randn (100, 1)); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect ax = gca (); histfit (ax, poissrnd (2, 1000, 1), 10, 'Poisson'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect ax = gca (); histfit (ax, betarnd (3, 10, 1000, 1), 10, 'beta'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect ax = axes ('parent', hf); fail ('histfit (ax)', 'histfit: too few input arguments.'); unwind_protect_cleanup close (hf); end_unwind_protect ***** error ... histfit ('wer') ***** error histfit ([NaN, NaN, NaN]); ***** error ... histfit (randn (100, 1), 5.6) ***** error ... histfit (randn (100, 1), 8, 5) ***** error ... histfit (randn (100, 1), 8, {'normal'}) ***** error ... histfit (randn (100, 1), 8, 'Kernel') ***** error ... histfit (randn (100, 1), 8, 'ASDASDASD') 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Plotting/gplotmatrix.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/gplotmatrix.m ***** demo ## Grouped scatter-plot matrix of Fisher's iris measurements. load fisheriris; gplotmatrix (meas, [], species); ***** demo ## Two sets of variables plotted against each other by group. load fisheriris; gplotmatrix (meas(:,1:2), meas(:,3:4), species); ***** test hf = figure ("visible", "off"); unwind_protect X = [10 20; 11 25; 12 21; 13 28; 14 23; 15 29]; g = [1 1 1 2 2 2]'; [h, ax, bigax] = gplotmatrix (X, [], g); assert_equal (size (h), [2, 2, 2]); assert_equal (size (ax), [3, 2]); assert_equal (isscalar (bigax) && isaxes (bigax), true); assert_equal (get (h(1,2,1), "xdata"), [20 25 21]); assert_equal (get (h(1,2,1), "ydata"), [10 11 12]); assert_equal (get (h(2,1,1), "xdata"), [10 11 12]); assert_equal (get (h(2,1,1), "ydata"), [20 25 21]); unwind_protect_cleanup close (hf); end_unwind_protect warning: legend: 'best' not yet implemented for location specifier, using 'northeast' instead ***** test hf = figure ("visible", "off"); unwind_protect X = [10 20; 11 25; 12 21; 13 28; 14 23; 15 29]; Y = [100 200 300; 110 250 280; 120 210 260; ... 130 280 240; 140 230 220; 150 290 210]; g = [1 1 1 2 2 2]'; [h, ax] = gplotmatrix (X, Y, g); assert_equal (size (h), [3, 2, 2]); assert_equal (size (ax), [3, 2]); assert_equal (get (h(1,2,1), "xdata"), [20 25 21]); assert_equal (get (h(1,2,1), "ydata"), [100 110 120]); unwind_protect_cleanup close (hf); end_unwind_protect warning: legend: 'best' not yet implemented for location specifier, using 'northeast' instead ***** test # runs without a grouping variable hf = figure ("visible", "off"); unwind_protect [h, ax] = gplotmatrix (randn (20, 3), [], []); assert_equal (size (h), [3, 3]); assert_equal (size (ax), [4, 3]); unwind_protect_cleanup close (hf); end_unwind_protect ***** error gplotmatrix () ***** error gplotmatrix ({1}) ***** error ... gplotmatrix (ones (5, 2), ones (4, 2), ones (5, 1)) ***** error ... gplotmatrix (ones (5, 2), [], ones (4, 1)) ***** error ... gplotmatrix (ones (5, 2), [], ones (5, 1), "r", ".", 6, "on", "hist", ... "a", "b", "c") 8 tests, 8 passed, 0 known failure, 0 skipped [inst/Plotting/ecdfhist.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/ecdfhist.m ***** demo ## Histogram (density estimate) from the empirical cdf of a random sample. rng (42); x = randn (100, 1); [f, xx] = ecdf (x); ecdfhist (f, xx); title ("ecdfhist of a standard normal sample"); ***** demo ## Compare the empirical density with a finer set of bins. rande ('state', 42); x = exprnd (2, 200, 1); [f, xx] = ecdf (x); ecdfhist (f, xx, 20); title ("ecdfhist of an exponential sample (20 bins)"); ***** test f = [0 0.1 0.3 0.6 0.8 0.9 1.0]'; x = [1 1 2 3 4 5 8]'; [n, c] = ecdfhist (f, x); assert_equal (c, 1.35:0.7:7.65, 1e-12); assert_equal (n, [0.1 0.2 0.3 0 0.2 0.1 0 0 0 0.1] / 0.7, 1e-12); assert_equal (sum (n .* 0.7), 1, 1e-12); ***** test f = [0 0.1 0.3 0.6 0.8 0.9 1.0]'; x = [1 1 2 3 4 5 8]'; [n, c] = ecdfhist (f, x, 5); assert_equal (c, [1.7 3.1 4.5 5.9 7.3], 1e-12); assert_equal (n, [0.3 0.3 0.3 0 0.1] / 1.4, 1e-12); ***** test f = [0 0.1 0.3 0.6 0.8 0.9 1.0]'; x = [1 1 2 3 4 5 8]'; [n, c] = ecdfhist (f, x, [1.5 2.5 3.5 4.5 5.5 6.5 7.5]); assert_equal (c, [1.5 2.5 3.5 4.5 5.5 6.5 7.5], 1e-12); assert_equal (n, [0.3 0.3 0.2 0.1 0 0 0.1], 1e-12); ***** test # returns only the heights when a single output is requested f = [0 0.1 0.3 0.6 0.8 0.9 1.0]'; x = [1 1 2 3 4 5 8]'; n = ecdfhist (f, x, 5); assert_equal (n, [0.3 0.3 0.3 0 0.1] / 1.4, 1e-12); ***** test hf = figure ("visible", "off"); unwind_protect f = [0 0.1 0.3 0.6 0.8 0.9 1.0]'; x = [1 1 2 3 4 5 8]'; ecdfhist (f, x); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ("visible", "off"); unwind_protect ax = axes ("parent", hf); f = [0 0.1 0.3 0.6 0.8 0.9 1.0]'; x = [1 1 2 3 4 5 8]'; ecdfhist (ax, f, x); unwind_protect_cleanup close (hf); end_unwind_protect ***** error ecdfhist () ***** error ecdfhist ([0 1]) ***** error ecdfhist ([0 1], {1 2}) ***** error ecdfhist ([0 1], [1 2 3]) ***** error ecdfhist (1, 1) ***** error ecdfhist ([0 1], [1 2], 0) ***** error ecdfhist ([0 1], [1 2], 2.5) 13 tests, 13 passed, 0 known failure, 0 skipped [inst/Plotting/silhouette.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/silhouette.m ***** demo load fisheriris; X = meas(:,3:4); cidcs = kmeans (X, 3, 'Replicates', 5); silhouette (X, cidcs); y_labels(cidcs([1 51 101])) = unique (species); set (gca, 'yticklabel', y_labels); title ('Fisher''s iris data'); ***** error silhouette (); ***** error silhouette ([1 2; 1 1]); ***** error silhouette ([1 2; 1 1], [1 2 3]'); ***** error silhouette ([1 2; 1 1], [1 2]', 'xxx'); 4 tests, 4 passed, 0 known failure, 0 skipped [inst/Plotting/gardnerAltmanPlot.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/gardnerAltmanPlot.m ***** demo ## Petal length of two iris species. The swarms show every flower, and ## the error bar on the right the difference between the mean lengths, ## read on the right axis, whose zero is level with the mean of the ## second species. load fisheriris x = meas(51:100,3); y = meas(101:150,3); rng (42); gardnerAltmanPlot (x, y); ***** demo ## The same comparison as Cohen's d, the difference in units of the ## pooled standard deviation. The right axis is scaled so that the ## effect still sits level with the mean of the first species. load fisheriris x = meas(51:100,3); y = meas(101:150,3); rng (42); gardnerAltmanPlot (x, y, 'Effect', 'cohen'); ***** demo ## Paired samples: two exam grades of the same students. Each line joins ## one student's two grades, coloured by whether the second is higher, ## lower or equal. load examgrades gardnerAltmanPlot (grades(:,1), grades(:,2), 'Paired', true); ***** shared x, y, yp, isScatter x = [2.1; 3.4; 1.9; 5.6; 4.4; 3.8; 2.7; 6.1; 3.3; 4.9]; y = [1.2; 2.8; 0.9; 2.2; 3.1; 1.7; 2.5; 0.4; 1.9; 3.6; 2.0; 1.1]; yp = [1.8; 2.9; 2.2; 4.1; 4.9; 2.6; 3.0; 4.8; 2.1; 4.0]; ## Octave's scatter builds an hggroup under the gnuplot toolkit isScatter = ! strcmp (graphics_toolkit (), 'gnuplot'); ***** test hf = figure ('visible', 'off'); unwind_protect H = gardnerAltmanPlot (x, y); assert_equal (size (H), [1, 5]); if (isScatter) assert_equal (get (H(1:2), 'type'), {'scatter'; 'scatter'}); endif assert_equal (get (H(3:5), 'type'), {'hggroup'; 'line'; 'line'}); assert_equal (get (H(1), 'ydata'), x); assert_equal (get (H(2), 'ydata'), y); assert_equal (get (H(3), 'xdata'), 3); assert_equal (get (H(3), 'ydata'), 1.87, -1e-14); assert_equal (get (H(3), 'ldata'), 1.0606770309586725, -1e-13); assert_equal (get (H(3), 'udata'), 1.0606770309586709, -1e-13); assert_equal (get (H(4), 'xdata'), [1, 3]); assert_equal (get (H(4), 'ydata'), [3.82, 3.82], -1e-14); assert_equal (get (H(5), 'xdata'), [2, 3]); assert_equal (get (H(5), 'ydata'), [1.95, 1.95], -1e-14); assert_equal (get (H(5), 'linestyle'), '--'); ax = gca (); assert_equal (get (ax, 'xticklabel'), {'X'; 'Y'; 'Mean Difference'}); assert_equal (get (get (ax, 'title'), 'string'), 'Gardner-Altman Plot'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect H = gardnerAltmanPlot (x, y); ax = gca (); ax2 = get (H(3), 'parent'); assert_equal (get (ax2, 'ylim'), get (ax, 'ylim') - 1.95, -1e-14); set (ax, 'ylim', [-2, 9]); assert_equal (get (ax2, 'ylim'), [-3.95, 7.05], -1e-14); assert_equal (get (ax2, 'position'), get (ax, 'position')); assert_equal (get (ax2, 'yaxislocation'), 'right'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect H = gardnerAltmanPlot (x, y, 'Effect', 'cohen'); ax = gca (); ax2 = get (H(3), 'parent'); assert_equal (get (H(3), 'ydata'), 1.51473229411906, -1e-13); assert_equal (get (ax2, 'ylim'), (get (ax, 'ylim') - 1.95) ... * 1.51473229411906 / 1.87, -1e-13); assert_equal (get (ax, 'xticklabel'), {'X'; 'Y'; 'Cohen''s d'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect H = gardnerAltmanPlot (x, y, 'Effect', 'cliff'); assert_equal (size (H), [1, 4]); assert_equal (get (H(3), 'ydata'), 0.725, -1e-14); assert_equal (get (H(4), 'xdata'), [2.5, 3.5]); assert_equal (get (H(4), 'ydata'), [0, 0]); assert_equal (get (get (H(3), 'parent'), 'ylim'), [-1.1, 1.1]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect rand ('state', 1); H = gardnerAltmanPlot (x, y, 'Effect', 'kstest', 'NumBootstraps', 100); assert_equal (size (H), [1, 4]); assert_equal (get (get (H(3), 'parent'), 'ylim'), [-0.1, 1.1]); assert_equal (get (gca (), 'xticklabel'), ... {'X'; 'Y'; 'Kolmogorov-Smirnov Statistic'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect rand ('state', 1); H = gardnerAltmanPlot (x, y, 'Effect', 'mediandiff', 'NumBootstraps', 100); assert_equal (get (H(4), 'ydata'), [3.6, 3.6], -1e-14); assert_equal (get (H(5), 'ydata'), [1.95, 1.95], -1e-14); assert_equal (get (H(3), 'ydata'), 1.65, -1e-14); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect H = gardnerAltmanPlot (x, yp, 'Paired', true); assert_equal (get (H, 'type'), {'line'; 'line'; 'hggroup'}); assert_equal (get (H(1), 'xdata'), [1, 2, NaN, 1, 2, NaN, 1, 2, NaN]); assert_equal (get (H(1), 'ydata'), ... [1.9, 2.2, NaN, 4.4, 4.9, NaN, 2.7, 3, NaN]); assert_equal (numel (get (H(2), 'ydata')), 21); assert_equal (get (H(3), 'ydata'), 0.58, -1e-13); ax2 = get (H(3), 'parent'); assert_equal (get (ax2, 'ylim'), get (gca (), 'ylim') - 3.24, -1e-14); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect H = gardnerAltmanPlot ([1; 2; 3; 4], [1; 3; 2; 4], 'Paired', true); assert_equal (get (H, 'type'), {'line'; 'line'; 'line'; 'hggroup'}); assert_equal (get (H(3), 'ydata'), [1, 1, NaN, 4, 4, NaN]); co = get (gca (), 'colororder'); assert_equal (get (H(4), 'color'), co(4,:)); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect H = gardnerAltmanPlot ([1; 2; 3; 4], [2; 3; 4; 5], 'Paired', true); assert_equal (get (H, 'type'), {'line'; 'hggroup'}); co = get (gca (), 'colororder'); assert_equal (get (H(2), 'color'), co(2,:)); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect H = gardnerAltmanPlot (x, y, 'ConfidenceIntervalType', 'none'); assert_equal (get (H(3), 'type'), 'line'); assert_equal (get (H(3), 'marker'), 'square'); assert_equal (get (H(3), 'ydata'), 1.87, -1e-14); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect H = gardnerAltmanPlot (x, [y; NaN]); assert_equal (get (H(2), 'ydata'), y); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect ax = subplot (1, 2, 2); H = gardnerAltmanPlot (ax, x, y); assert_equal (get (H(1), 'parent'), ax); assert_equal (get (get (H(3), 'parent'), 'position'), ... get (ax, 'position')); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect gardnerAltmanPlot (x, y); gardnerAltmanPlot (x, yp, 'Paired', true); assert_equal (numel (findobj (hf, 'type', 'axes')), 2); plot (1:3); assert_equal (numel (findobj (hf, 'type', 'axes')), 1); unwind_protect_cleanup close (hf); end_unwind_protect ***** error ... gardnerAltmanPlot ([1; 2; 3]) ***** error ... gardnerAltmanPlot ([1; 2; 3], 'Effect', 'cohen') ***** error ... gardnerAltmanPlot ([1; 2; 3], [2; 3; 4], 'Mean', 3) ***** error ... gardnerAltmanPlot ([1; 2; 3], [2; 3; 4], 'Effect', {'cohen', 'glass'}) ***** error ... gardnerAltmanPlot ([1, 2; 3, 4], [2; 3; 4]) ***** error ... gardnerAltmanPlot ([1; 2; 3], [2; 3; 4], 'Paired', true, 'Effect', 'glass') 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Plotting/cdfplot.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/cdfplot.m ***** demo rng (42); x = randn (100,1); cdfplot (x); ***** test hf = figure ('visible', 'off'); unwind_protect x = [2, 4, 3, 2, 4, 3, 2, 5, 6, 4]; [hCDF, stats] = cdfplot (x); assert_equal (stats.min, 2); assert_equal (stats.max, 6); assert_equal (stats.median, 3.5); assert_equal (stats.std, 1.35400640077266, 1e-14); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect x = randn (100,1); cdfplot (x); unwind_protect_cleanup close (hf); end_unwind_protect ***** error cdfplot (); ***** error cdfplot ([x',x']); ***** error cdfplot ([NaN, NaN, NaN, NaN]); 5 tests, 5 passed, 0 known failure, 0 skipped [inst/Plotting/manovacluster.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/manovacluster.m ***** demo load carbig X = [MPG Acceleration Weight Displacement]; [d, p, stats] = manova1 (X, Origin); manovacluster (stats) ***** test hf = figure ('visible', 'off'); unwind_protect load carbig X = [MPG Acceleration Weight Displacement]; [d, p, stats] = manova1 (X, Origin); manovacluster (stats); unwind_protect_cleanup close (hf); end_unwind_protect ***** error manovacluster (stats, 'some'); 2 tests, 2 passed, 0 known failure, 0 skipped [inst/Plotting/qqplot.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/qqplot.m ***** test hf = figure ('visible', 'off'); unwind_protect qqplot ([2 3 3 4 4 5 6 5 6 7 8 9 8 7 8 9 0 8 7 6 5 4 6 13 8 15 9 9]); unwind_protect_cleanup close (hf); end_unwind_protect ***** error qqplot () ***** error qqplot ({1}) ***** error qqplot (ones (2,2)) ***** error qqplot (1, 'foobar') ***** error qqplot ([1 2 3], 'foobar') 6 tests, 6 passed, 0 known failure, 0 skipped [inst/Plotting/swarmchart.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/swarmchart.m ***** demo ## A swarm chart spreads the points of each column sideways, so the shape ## of a column shows where its values gather. A crowded part spreads ## wide and a lone point hardly moves. load fisheriris g = grp2idx (species); swarmchart (g, meas(:,1)); xlabel ('species'); ylabel ('sepal length'); ***** demo ## A swarm sits over a box chart readily, the one showing the summary and ## the other every observation behind it. load fisheriris g = grp2idx (species); boxchart (g, meas(:,1)); hold on swarmchart (g, meas(:,1), 10, [0.3, 0.3, 0.3]); hold off xlabel ('species'); ylabel ('sepal length'); ***** demo ## How far the points are spread, and by what rule, may be set afterwards. load fisheriris g = grp2idx (species); s = swarmchart (g, meas(:,1)); set (s, 'XJitterWidth', 0.3); ***** shared scX, scY scX = [ones(8, 1); 2 * ones(8, 1)]; scY = [1; 1; 1; 2; 2; 3; 4; 9; 5; 5; 5; 6; 6; 7; 8; 20]; ***** test hf = figure ('visible', 'off'); unwind_protect s = swarmchart (scX, scY); assert_equal (size (get (s, 'cdata')), [1, 3]); ## Octave's scatter builds an hggroup under the gnuplot toolkit if (! strcmp (graphics_toolkit (), 'gnuplot')) assert_equal (get (s, 'type'), 'scatter'); endif assert_equal (get (s, 'XJitter'), 'density'); assert_equal (get (s, 'YJitter'), 'none'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # MATLAB parity: the default width is nine tenths of the smallest gap hf = figure ('visible', 'off'); unwind_protect s = swarmchart (scX, scY); assert_equal (get (s, 'XJitterWidth'), 0.9, 1e-12); s2 = swarmchart ([1; 1; 3; 3], [1; 2; 3; 4]); assert_equal (get (s2, 'XJitterWidth'), 1.8, 1e-12); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # a column with one value alone falls back to the fixed width hf = figure ('visible', 'off'); unwind_protect s = swarmchart (ones (5, 1), (1:5)'); assert_equal (get (s, 'XJitterWidth'), 0.9, 1e-12); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect s = swarmchart (scX, scY); xd = get (s, 'XData')(:); w = get (s, 'XJitterWidth'); assert_equal (numel (xd), numel (scX)); assert_equal (all (abs (xd - scX) <= w / 2 + 1e-12), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # the other axis is left alone where it is not jittered hf = figure ('visible', 'off'); unwind_protect s = swarmchart (scX, scY); assert_equal (get (s, 'YData')(:), scY); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # the points really are spread rather than left in two lines hf = figure ('visible', 'off'); unwind_protect s = swarmchart (scX, scY); xd = get (s, 'XData')(:); assert_equal (numel (unique (xd)) > 2, true); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # asking for no jitter leaves the values exactly as they came hf = figure ('visible', 'off'); unwind_protect s = swarmchart (scX, scY, 'XJitter', 'none'); assert_equal (get (s, 'XData')(:), scX); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # setting the width spreads them again, into the narrower band hf = figure ('visible', 'off'); unwind_protect s = swarmchart (scX, scY); set (s, 'XJitterWidth', 0.2); xd = get (s, 'XData')(:); assert_equal (all (abs (xd - scX) <= 0.1 + 1e-12), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # and setting the kind to none puts them back where they started hf = figure ('visible', 'off'); unwind_protect s = swarmchart (scX, scY); set (s, 'XJitter', 'none'); assert_equal (get (s, 'XData')(:), scX); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # the y values may be spread instead, and then they move hf = figure ('visible', 'off'); unwind_protect s = swarmchart (scX, scY, 'XJitter', 'none', 'YJitter', 'rand', ... 'YJitterWidth', 0.5); assert_equal (get (s, 'XData')(:), scX); assert_equal (isequal (get (s, 'YData')(:), scY), false); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # the marker size and colour reach scatter as they would on their own hf = figure ('visible', 'off'); unwind_protect s = swarmchart (scX, scY, 25, [1, 0, 0]); assert_equal (get (s, 'SizeData'), 25); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # the axes to draw into may be given first, as for any plot hf = figure ('visible', 'off'); unwind_protect a1 = subplot (1, 2, 1); a2 = subplot (1, 2, 2); s = swarmchart (a2, scX, scY); assert_equal (get (s, 'parent'), a2); assert_equal (isempty (get (a1, 'children')), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** error swarmchart (1) ***** error ... swarmchart ([1; 2], [1; 2; 3]) ***** error ... swarmchart ({1, 2}, [1; 2]) ***** error ... swarmchart ([1; 2], [1; 2], 'XJitter', 'sideways') ***** error ... swarmchart ([1; 2], [1; 2], 'XJitterWidth', -1) ***** error ... swarmchart ([1; 2], [1; 2], 'XJitter') 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Plotting/boxplot.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/boxplot.m ***** demo rng (42); axis ([0, 3]); girls = randn (10, 1) * 5 + 140; boys = randn (13, 1) * 8 + 135; boxplot ({girls, boys}); set (gca (), 'xtick', [1 2], 'xticklabel', {'girls', 'boys'}) title ('Grade 3 heights'); ***** demo rng (42); A = randn (10, 1) * 5 + 140; B = randn (25, 1) * 8 + 135; C = randn (20, 1) * 6 + 165; data = [A; B; C]; groups = [(ones (10, 1)); (ones (25, 1) * 2); (ones (20, 1) * 3)]; labels = {'Team A', 'Team B', 'Team C'}; pos = [2, 1, 3]; boxplot (data, groups, 'Notch', 'on', 'Labels', labels, 'Positions', pos, ... 'OutlierTags', 'on', 'BoxStyle', 'filled'); title ('Example of Group splitting with paired vectors'); ***** demo rng (42); data = randn (100, 9); boxplot (data, 'notch', 'on', 'boxstyle', 'filled', ... 'colors', 'ygcwkmb', 'whisker', 1.2); title ('Example of different colors specified with characters'); ***** demo rng (42); data = randn (100, 13); colors = [0.7 0.7 0.7; ... 0.0 0.4 0.9; ... 0.7 0.4 0.3; ... 0.7 0.1 0.7; ... 0.8 0.7 0.4; ... 0.1 0.8 0.5; ... 0.9 0.9 0.2]; boxplot (data, 'notch', 'on', 'boxstyle', 'filled', ... 'colors', colors, 'whisker', 1.3, 'boxwidth', 'proportional'); title ('Example of different colors specified as RGB values'); ***** demo rng (42); data = randn (30, 1); ## Using modern string arrays str_groups = string (repmat (['Control'; 'TreatmentA'; 'TreatmentB'], 10, 1)); boxplot (data, str_groups, 'colors', 'rgb'); title ('Example using modern string arrays for grouping'); ***** demo rng (42); data = randn (40, 1) * 5 + 50; ## Create two different grouping variables group1 = repmat ({'Alpha'; 'Beta'}, 20, 1); group2 = repmat ([2022; 2022; 2023; 2023], 10, 1); ## Pass them together as a cell array boxplot (data, {group1, group2}); title ('Example of Multiple Grouping Variables (Model & Year)'); ***** error boxplot ('a') ***** error boxplot ({[1 2 3], 'a'}) ***** error boxplot ([1 2 3], 1, {2, 3}) ***** error boxplot ([1 2 3], {'a', 'b'}) ***** error <'Notch' input argument accepts> boxplot ([1:10], 'notch', 'any') ***** error boxplot ([1:10], 'notch', i) ***** error boxplot ([1:10], 'notch', {}) ***** error boxplot (1, 'symbol', 1) ***** error <'Orientation' input argument accepts only> boxplot (1, 'orientation', 'diagonal') ***** error boxplot (1, 'orientation', {}) ***** error <'Whisker' input argument accepts only> boxplot (1, 'whisker', 'a') ***** error <'Whisker' input argument accepts only> boxplot (1, 'whisker', [1 3]) ***** error <'OutlierTags' input argument accepts only> boxplot (3, 'OutlierTags', 'maybe') ***** error boxplot (3, 'OutlierTags', {}) ***** error <'Sample_IDs' input argument accepts only> boxplot (1, 'sample_IDs', 1) ***** error <'BoxWidth' input argument accepts only> boxplot (1, 'boxwidth', 2) ***** error <'BoxWidth' input argument accepts only> boxplot (1, 'boxwidth', 'anything') ***** error <'Widths' input argument accepts only> boxplot (5, 'widths', 'a') ***** error <'Widths' input argument accepts only> boxplot (5, 'widths', [1:4]) ***** error <'Widths' input argument accepts only> boxplot (5, 'widths', []) ***** error <'CapWidths' input argument accepts only> boxplot (5, 'capwidths', 'a') ***** error <'CapWidths' input argument accepts only> boxplot (5, 'capwidths', [1:4]) ***** error <'CapWidths' input argument accepts only> boxplot (5, 'capwidths', []) ***** error <'BoxStyle' input argument accepts only> boxplot (1, 'Boxstyle', 1) ***** error <'BoxStyle' input argument accepts only> boxplot (1, 'Boxstyle', 'garbage') ***** error <'Positions' input argument accepts only> boxplot (1, 'positions', 'aa') ***** error <'Labels' input argument accepts only> boxplot (3, 'labels', [1 5]) ***** error <'Colors' input argument accepts only> boxplot (1, 'colors', {}) ***** error <'Colors' input argument accepts only> boxplot (2, 'colors', [1 2 3 4]) ***** error boxplot (randn (10, 3), 'Sample_IDs', {'a', 'b'}) ***** error boxplot (rand (3, 3), [1 2]) ***** test hf = figure ('visible', 'off'); unwind_protect [a, b] = boxplot (rand (10, 3)); assert_equal (size (a), [7, 3]); assert_equal (numel (b.box), 3); assert_equal (numel (b.whisker), 12); assert_equal (numel (b.median), 3); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect [~, b] = boxplot (rand (10, 3), 'BoxStyle', 'filled', 'colors', 'ybc'); assert_equal (numel (b.box_fill), 3); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect hold on [a, b] = boxplot (rand (10, 3)); assert_equal (ishold, true); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## Test multi-variable grouping. hf = figure ('visible', 'off'); unwind_protect data = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12]; g1 = [1; 1; 2; 2; 3; 3; 1; 1; 2; 2; 3; 3]; g2 = string ({'A'; 'B'; 'A'; 'B'; 'A'; 'B'; 'A'; 'B'; 'A'; 'B'; 'A'; 'B'}); g3 = categorical ({'X'; 'X'; 'Y'; 'Y'; 'Z'; 'Z'; 'X'; 'X'; 'Y'; 'Y'; 'Z'; 'Z'}); [a, b] = boxplot (data, {g1, g2, g3}); assert_equal (size (a, 2), 6); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## Test multi-variable grouping with empty intersections dropping correctly. hf = figure ('visible', 'off'); unwind_protect data = [1; 2; 3; 4]; g1 = [1; 1; 2; 2]; g2 = string ({'A'; 'A'; 'B'; 'B'}); [a, b] = boxplot (data, {g1, g2}); assert_equal (size (a, 2), 2); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## A single observation is plotted, not an internal subscript error. Every ## statistic collapses to the value, as it does in MATLAB. hf = figure ('visible', 'off'); unwind_protect [s, hs] = boxplot (5); assert_equal (s, 5 * ones (7, 1)); assert_equal (isempty (hs.box), true); assert_equal (numel (hs.outliers), 1); assert_equal (get (hs.outliers, 'YData'), 5); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## An empty input draws nothing and returns no statistics, as in MATLAB, ## rather than indexing an empty handle list at zero. hf = figure ('visible', 'off'); unwind_protect [s, hs] = boxplot ([]); assert_equal (size (s, 2), 0); assert_equal (isempty (hs.box), true); assert_equal (isempty (hs.whisker), true); assert_equal (isempty (hs.median), true); assert_equal (isempty (hs.outliers), true); clf; [s, hs] = boxplot ({}); assert_equal (size (s, 2), 0); assert_equal (isempty (hs.box), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## A variable that is entirely missing leaves no box, which used to take the ## handle bookkeeping with it. hf = figure ('visible', 'off'); unwind_protect [s, hs] = boxplot ([NaN; NaN; NaN]); assert_equal (all (isnan (s)), true); assert_equal (isempty (hs.box), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## Integer observations are accepted and agree with the same numbers in ## double; the internal call to var used to refuse them outright. hf = figure ('visible', 'off'); unwind_protect sd = boxplot ([1; 2; 3; 4; 5; 6; 7]); clf; si = boxplot (int32 ([1; 2; 3; 4; 5; 6; 7])); clf; su = boxplot (uint8 ([1; 2; 3; 4; 5; 6; 7])); assert_equal (si, sd); assert_equal (su, sd); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## The same holds for an integer variable inside a cell. hf = figure ('visible', 'off'); unwind_protect sd = boxplot ({[1; 2; 3; 4; 5], [2; 3; 4; 5; 6]}); clf; si = boxplot ({int32([1; 2; 3; 4; 5]), int32([2; 3; 4; 5; 6])}); assert_equal (si, sd); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## A group holding a single observation leaves fewer boxes than groups. The ## cap widths were built from the full-length widths vector against the ## chopped box vector, so the subtraction did not conform. hf = figure ('visible', 'off'); unwind_protect data = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 42]; grp = [1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 2]; [s, hs] = boxplot (data, grp); assert_equal (size (s, 2), 2); assert_equal (s(:, 2), 42 * ones (7, 1)); assert_equal (numel (hs.box), 1); assert_equal (numel (hs.median), 1); assert_equal (numel (hs.whisker), 4); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## The box fill follows the boxes actually drawn, not the number of groups. hf = figure ('visible', 'off'); unwind_protect data = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 42]; grp = [1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 2]; [s, hs] = boxplot (data, grp, 'BoxStyle', 'filled'); assert_equal (numel (hs.box_fill), numel (hs.box)); assert_equal (get (hs.box_fill(1), 'Type'), 'patch'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## Both kinds of outlier keep their own handles, and the ones after them ## stay in step. hf = figure ('visible', 'off'); unwind_protect data = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 42]; grp = [1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 2]; [s, hs] = boxplot ([data; 60], [grp; 1]); assert_equal (numel (hs.outliers), 1); assert_equal (numel (hs.outliers2), 1); assert_equal (get (hs.median, 'Type'), 'line'); unwind_protect_cleanup close (hf); end_unwind_protect ***** error ... boxplot ([true; false; true; true]) ***** error ... boxplot ('abcde') ***** test ## The box edges are the 25th and 75th percentiles, for odd and even counts ## alike, and agree with prctile called on the same data. hf = figure ('visible', 'off'); unwind_protect s = boxplot ((1:7)'); assert_equal (s(1:5)', [1, 2.25, 4, 5.75, 7]); clf; s = boxplot ((1:8)'); assert_equal (s(1:5)', [1, 2.5, 4.5, 6.5, 8]); clf; x = [2; 4; 4; 4; 5; 5; 7; 9]; s = boxplot (x); assert_equal (s(1:5)', [2, 4, 4.5, 6, 9]); assert_equal (s(2:4)', [prctile(x, 25), median(x), prctile(x, 75)]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## Small samples, where the two quantile definitions differ most. hf = figure ('visible', 'off'); unwind_protect s = boxplot ([1; 2]); assert_equal (s(1:5)', [1, 1, 1.5, 2, 2]); clf; s = boxplot ([1; 2; 3]); assert_equal (s(1:5)', [1, 1.25, 2, 2.75, 3]); clf; s = boxplot ([1; 2; 3; 4]); assert_equal (s(1:5)', [1, 1.5, 2.5, 3.5, 4]); clf; s = boxplot ([1; 2; 3; 4; 5]); assert_equal (s(1:5)', [1, 1.75, 3, 4.25, 5]); clf; s = boxplot ([1; 2; 3; 4; 5; 6]); assert_equal (s(1:5)', [1, 2, 3.5, 5, 6]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## Missing values are dropped before the quartiles are taken. hf = figure ('visible', 'off'); unwind_protect s = boxplot ([1; 2; NaN; 4; 5; 6; 7]); assert_equal (s(1:5)', [1, 2, 4.5, 6, 7]); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## The inter-quartile range sets the fences, so the quartile definition ## decides which points are outliers. 33 lies beyond the fence and 31.5 ## does not; the old quartiles put the fence between them and called both ## outliers. hf = figure ('visible', 'off'); unwind_protect [s, hs] = boxplot ([(1:20)'; 31.5]); assert_equal (s(1:5)', [1, 5.75, 11, 16.25, 31.5]); assert_equal (isempty (hs.outliers), true); assert_equal (isempty (hs.outliers2), true); clf; [s, hs] = boxplot ([(1:20)'; 33]); assert_equal (s(1:5)', [1, 5.75, 11, 16.25, 33]); assert_equal (isempty (hs.outliers) && isempty (hs.outliers2), false); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## When no observation lies between a quartile and its fence the whisker ## collapses onto the quartile instead of being drawn back into the box. hf = figure ('visible', 'off'); unwind_protect [s, hs] = boxplot ([1; 1; 2; 2; 3; 3; 4; 40; 50]); assert_equal (s(1:5)', [1, 1.75, 3, 13, 50]); yd = get (hs.whisker, 'YData'); assert_equal (max ([yd{3}, yd{4}]), 13); clf; [s, hs] = boxplot ([-50; -40; -4; -3; -3; -2; -2; -1; -1]); assert_equal (s(1:5)', [-50, -13, -3, -1.75, -1]); yd = get (hs.whisker, 'YData'); assert_equal (min ([yd{1}, yd{2}]), -13); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## A whisker that does reach real data is not clamped. hf = figure ('visible', 'off'); unwind_protect [s, hs] = boxplot ([-50; -40; -4; -3; -3; -2; -2; 40; 50]); assert_equal (s(1:5)', [-50, -13, -3, 8.5, 50]); yd = get (hs.whisker, 'YData'); assert_equal (min ([yd{1}, yd{2}]), -40); assert_equal (max ([yd{3}, yd{4}]), 40); unwind_protect_cleanup close (hf); end_unwind_protect 52 tests, 52 passed, 0 known failure, 0 skipped [inst/Plotting/biplot.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/biplot.m ***** demo ## Biplot of the first two principal components of Fisher's iris data. load fisheriris; [coefs, score] = pca (zscore (meas)); biplot (coefs(:,1:2), "Scores", score(:,1:2), ... "VarLabels", {"SL", "SW", "PL", "PW"}); ***** demo ## Three-component biplot of the same data. load fisheriris; coefs = pca (zscore (meas)); biplot (coefs(:,1:3), "VarLabels", {"SL", "SW", "PL", "PW"}); ***** test hf = figure ("visible", "off"); unwind_protect coefs = [0.6 -0.3; -0.2 0.7; 0.5 0.5]; score = [1 2; -3 1; 0.5 -2; 4 0]; h = biplot (coefs, "Scores", score); assert_equal (numel (h), 11); ## variable vector lines (origin to coefficient) assert_equal (get (h(1), "xdata"), [0 0.6], 1e-12); assert_equal (get (h(1), "ydata"), [0 -0.3], 1e-12); assert_equal (get (h(2), "xdata"), [0 -0.2], 1e-12); ## variable tip markers ## the trailing NaN is MATLAB's own, and draws nothing assert_equal (get (h(4), "xdata"), [0.6 NaN], 1e-12); assert_equal (get (h(4), "ydata"), [-0.3 NaN], 1e-12); ## observation markers (scaled scores) assert_equal (get (h(7), "xdata"), [0.182 NaN], 1e-4); assert_equal (get (h(7), "ydata"), [0.364 NaN], 1e-4); assert_equal (get (h(10), "xdata"), [0.728 NaN], 1e-4); ## reference axis extent assert_equal (get (h(11), "xdata"), [-0.77 0.77 NaN 0 0], 1e-12); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # 3-D biplot without scores hf = figure ("visible", "off"); unwind_protect coefs = [0.6 -0.3 0.2; -0.2 0.7 0.1; 0.5 0.5 -0.6]; h = biplot (coefs); assert_equal (numel (h), 7); ## column 3 has its largest-magnitude element (-0.6) forced positive, ## so the whole column is negated: [0.2 0.1 -0.6] -> [-0.2 -0.1 0.6] assert_equal (get (h(1), "zdata"), [0 -0.2], 1e-12); assert_equal (get (h(6), "zdata"), [0.6 NaN], 1e-12); assert_equal (get (h(7), "zdata"), [0 0 NaN 0 0 NaN -0.77 0.77], 1e-12); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # sign convention flips a column with a negative largest element hf = figure ("visible", "off"); unwind_protect coefs = [-0.8 0.1; 0.2 0.9; -0.5 0.5]; h = biplot (coefs); assert_equal (get (h(1), "xdata"), [0 0.8], 1e-12); assert_equal (get (h(2), "xdata"), [0 -0.2], 1e-12); assert_equal (get (h(3), "xdata"), [0 0.5], 1e-12); assert_equal (get (h(1), "ydata"), [0 0.1], 1e-12); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # labels add text handles in the documented order hf = figure ("visible", "off"); unwind_protect coefs = [0.6 -0.3; -0.2 0.7]; score = [1 2; -3 1]; h = biplot (coefs, "Scores", score, "VarLabels", {"a", "b"}, ... "ObsLabels", {"x", "y"}); ## 2 varlines + 2 varmarks + 2 vartext + 2 obsmarks + 2 obstext + 1 axis assert_equal (numel (h), 11); assert_equal (strcmp (get (h(5), "string"), "a"), true); assert_equal (strcmp (get (h(9), "string"), "x"), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** error biplot () ***** error ... biplot (ones (3, 4)) ***** error biplot ({1}) ***** error ... biplot ([0.6 0.3; 0.2 0.7], "Scores", [1 2 3]) ***** error ... biplot ([0.6 0.3; 0.2 0.7], "Scores") 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Plotting/andrewsplot.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/andrewsplot.m ***** demo ## Andrews plot of Fisher's iris data, grouped by species. load fisheriris; andrewsplot (meas, "Group", species); ***** demo ## The same data with median and quartile curves per species. load fisheriris; andrewsplot (meas, "Group", species, "Quantile", 0.25); ***** test hf = figure ("visible", "off"); unwind_protect X = [1 2 3 4; 5 6 7 8; 2 3 1 4]; h = andrewsplot (X); assert_equal (numel (h), 3); t = get (h(1), "xdata"); assert_equal (numel (t), 1001); assert_equal (t([1, 501, 1001]), [0, 0.5, 1], 1e-12); y1 = get (h(1), "ydata"); assert_equal (y1([1, 501, 1001]), [3.70711, -2.29289, 3.70711], 1e-4); y3 = get (h(3), "ydata"); assert_equal (y3([1, 501, 1001]), [2.41421, 0.41421, 2.41421], 1e-4); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # Standardize "on" (z-score each column) hf = figure ("visible", "off"); unwind_protect X = [1 2 3 4; 5 6 7 8; 2 3 1 4]; h = andrewsplot (X, "Standardize", "on"); y1 = get (h(1), "ydata"); assert_equal (y1([1, 501, 1001]), [-0.78436, -0.34792, -0.78436], 1e-4); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # Standardize "pca" hf = figure ("visible", "off"); unwind_protect X = [1 2 3 4; 5 6 7 8; 2 3 1 4]; h = andrewsplot (X, "Standardize", "pca"); y1 = get (h(1), "ydata"); assert_equal (y1([1, 501, 1001]), [-1.76701, -1.76701, -1.76701], 1e-4); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # grouping and quantile mode give three curves per group hf = figure ("visible", "off"); unwind_protect X = [1 2 3 4; 5 6 7 8; 2 3 1 4; 3 1 4 1; 5 9 2 6; 4 2 1 3]; g = [1 1 1 2 2 2]'; h = andrewsplot (X, "Group", g, "Quantile", 0.25); assert_equal (numel (h), 6); unwind_protect_cleanup close (hf); end_unwind_protect warning: legend: 'best' not yet implemented for location specifier, using 'northeast' instead ***** error andrewsplot () ***** error andrewsplot ({1}) ***** error ... andrewsplot (ones (3, 2), "Group") ***** error ... andrewsplot (ones (3, 2), "bogus", 1) ***** error ... andrewsplot (ones (3, 2), "Standardize", "xxx") ***** error ... andrewsplot (ones (3, 2), "Group", [1 2]) ***** error ... andrewsplot (ones (3, 2), "Quantile", 1.5) ***** test nfig = numel (get (0, "children")); fail ('andrewsplot (ones (3, 2), "Quantile", 1.5)', ... 'andrewsplot: Quantile ALPHA must be a scalar in .0,1..'); assert_equal (numel (get (0, "children")), nfig); 12 tests, 12 passed, 0 known failure, 0 skipped [inst/Plotting/bar3h.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/bar3h.m ***** demo ## Plotting 5 bars in the same series. y = [50; 40; 30; 20; 10]; bar3h (y); ***** demo ## Plotting 5 bars in different groups. y = [50, 40, 30, 20, 10]; bar3h (y); ***** demo ## A 3D bar graph with each series corresponding to a column in y. y = [1, 4, 7; 2, 5, 8; 3, 6, 9; 4, 7, 10]; bar3h (y); ***** demo ## Specify z-axis locations as tick names. z must be a column vector! z = [1950, 1960, 1970, 1980, 1990]'; y = [16, 8, 4, 2, 1]'; bar3h (z, y); ***** demo ## Plot 3 series as a grouped plot without any space between the grouped bars y = [70 50 33 10; 75 55 35 15; 80 60 40 20]; bar3h (y, 1, 'grouped'); ***** demo ## Plot a stacked style 3D bar graph y = [19, 30, 21, 30; 40, 16, 32, 12]; b = bar3h (y, 0.5, 'stacked'); ***** error bar3h ('A') ***** error bar3h ({2,3,4,5}) ***** error ... bar3h ([1,2,3]', ones (2)) ***** error ... bar3h ([1:5], 1.2) ***** error ... bar3h ([1:5]', ones (5), 1.2) ***** error ... bar3h ([1:5]', ones (5), [0.8, 0.7]) ***** error ... bar3h (ones (5), 'width') ***** error ... bar3h (ones (5), 'width', 1.2) ***** error ... bar3h (ones (5), 'width', [0.8, 0.8, 0.8]) ***** error ... bar3h (ones (5), 'color') ***** error ... bar3h (ones (5), 'color', [0.8, 0.8]) ***** error ... bar3h (ones (5), 'color', 'brown') ***** error ... bar3h (ones (5), 'color', {'r', 'k', 'c', 'm', 'brown'}) ***** error ... bar3h (ones (5), 'xlabel') ***** error ... bar3h (ones (5), 'xlabel', 4) ***** error ... bar3h (ones (5), 'zlabel') ***** error ... bar3h (ones (5), 'zlabel', 4) ***** error bar3h (ones (5), 'this', 4) ***** error ... bar3h (ones (5), 'xlabel', {'A', 'B', 'C'}) ***** error ... bar3h (ones (5), 'zlabel', {'A', 'B', 'C'}) 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Plotting/violin.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/violin.m ***** demo rng (42); clf x = zeros (9e2, 10); for i=1:10 x(:,i) = (0.1 * randn (3e2, 3) * (randn (3,1) + 1) + 2 * randn (1,3))(:); endfor h = violin (x, 'color', 'c'); axis tight set (h.violin, 'linewidth', 2); set (gca, 'xgrid', 'on'); xlabel ('Variables') ylabel ('Values') ***** demo rng (42); clf data = {randn(100,1)*5+140, randn(130,1)*8+135}; subplot (1,2,1) title ('Grade 3 heights - vertical'); set (gca, 'xtick', 1:2, 'xticklabel', {'girls'; 'boys'}); violin (data, 'Nbins', 10); axis tight subplot (1,2,2) title ('Grade 3 heights - horizontal'); set (gca, 'ytick', 1:2, 'yticklabel', {'girls'; 'boys'}); violin (data, 'horizontal', 'Nbins', 10); axis tight ***** demo rng (42); rande ('state', 42); clf data = exprnd (0.1, 500,4); violin (data, 'nbins', {5,10,50,100}); axis ([0 5 0 max(data(:))]) ***** demo rng (42); rande ('state', 42); clf data = exprnd (0.1, 500,4); violin (data, 'color', jet (4)); axis ([0 5 0 max(data(:))]) ***** demo rng (42); rande ('state', 42); clf data = repmat (exprnd (0.1, 500,1), 1, 4); violin (data, 'width', linspace (0.1,0.5,4)); axis ([0 5 0 max(data(:))]) ***** demo rng (42); rande ('state', 42); clf data = repmat (exprnd (0.1, 500,1), 1, 4); violin (data, 'nbins', [5,10,50,100], 'smoothfactor', [4 4 8 10]); axis ([0 5 0 max(data(:))]) ***** test hf = figure ('visible', 'off'); unwind_protect data = exprnd (0.1, 500,4); violin (data, 'color', jet (4)); axis ([0 5 0 max(data(:))]) unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect data = {randn(100,1)*5+140, randn(130,1)*8+135}; subplot (1,2,1) title ('Grade 3 heights - vertical'); set (gca, 'xtick', 1:2, 'xticklabel', {'girls'; 'boys'}); violin (data, 'Nbins', 10); axis tight unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect data = {randn(100,1)*5+140, randn(130,1)*8+135}; subplot (1,2,1) title ('Grade 3 heights - vertical'); set (gca, 'xtick', 1:2, 'xticklabel', {'girls'; 'boys'}); violin (data, 'Nbins', 10); axis tight subplot (1,2,2) title ('Grade 3 heights - horizontal'); set (gca, 'ytick', 1:2, 'yticklabel', {'girls'; 'boys'}); violin (data, 'horizontal', 'Nbins', 10); axis tight unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect data = repmat (exprnd (0.1, 500,1), 1, 4); violin (data, 'nbins', [5,10,50,100], 'smoothfactor', [4 4 8 10]); axis ([0 5 0 max(data(:))]) unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect data = repmat (exprnd (0.1, 500,1), 1, 4); violin (data, 'width', linspace (0.1,0.5,4)); axis ([0 5 0 max(data(:))]) unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ("visible", "off"); unwind_protect r = violin (randn (1, 60)); nrow = numel (findobj (gca (), "Type", "patch")); clf; c = violin (randn (60, 1)); ncol = numel (findobj (gca (), "Type", "patch")); assert_equal (nrow, 1); assert_equal (ncol, 1); assert_equal (numel (r.violin), numel (c.violin)); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ("visible", "off"); unwind_protect h = violin (randn (40, 3)); assert_equal (numel (findobj (gca (), "Type", "patch")), 3); assert_equal (numel (h.violin), 3); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ("visible", "off"); unwind_protect violin ({[1, 2, 3, 4], [3, 4, 5, 6]}); assert_equal (numel (findobj (gca (), "Type", "patch")), 2); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ("visible", "off"); unwind_protect v = [1 2 3 4 5 4 3 2 1 2 3]; violin (int32 (v)); ni = numel (findobj (gca (), "Type", "patch")); clf; violin (double (v)); nd = numel (findobj (gca (), "Type", "patch")); assert_equal (ni, nd); clf; violin (logical ([1 0 1 1 0 0 1 0 1 1])); assert_equal (numel (findobj (gca (), "Type", "patch")), 1); unwind_protect_cleanup close (hf); end_unwind_protect ***** error violin () ***** error violin ([]) ***** error violin ({}) ***** error ... violin (5) ***** error ... violin ({[1, 2, 3], 4}) ***** error violin ('abcdef') 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Plotting/bar3.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/bar3.m ***** demo ## Plotting 5 bars in the same series. z = [50; 40; 30; 20; 10]; bar3 (z); ***** demo ## Plotting 5 bars in different groups. z = [50, 40, 30, 20, 10]; bar3 (z); ***** demo ## A 3D bar graph with each series corresponding to a column in z. z = [1, 4, 7; 2, 5, 8; 3, 6, 9; 4, 7, 10]; bar3 (z); ***** demo ## Specify y-axis locations as tick names. y must be a column vector! y = [1950, 1960, 1970, 1980, 1990]'; z = [16, 8, 4, 2, 1]'; bar3 (y, z); ***** demo ## Plot 3 series as a grouped plot without any space between the grouped bars z = [70 50 33 10; 75 55 35 15; 80 60 40 20]; bar3 (z, 1, 'grouped'); ***** demo ## Plot a stacked style 3D bar graph z = [19, 30, 21, 30; 40, 16, 32, 12]; b = bar3 (z, 0.5, 'stacked'); ***** error bar3 ('A') ***** error bar3 ({2,3,4,5}) ***** error ... bar3 ([1,2,3]', ones (2)) ***** error ... bar3 ([1:5], 1.2) ***** error ... bar3 ([1:5]', ones (5), 1.2) ***** error ... bar3 ([1:5]', ones (5), [0.8, 0.7]) ***** error ... bar3 (ones (5), 'width') ***** error ... bar3 (ones (5), 'width', 1.2) ***** error ... bar3 (ones (5), 'width', [0.8, 0.8, 0.8]) ***** error ... bar3 (ones (5), 'color') ***** error ... bar3 (ones (5), 'color', [0.8, 0.8]) ***** error ... bar3 (ones (5), 'color', 'brown') ***** error ... bar3 (ones (5), 'color', {'r', 'k', 'c', 'm', 'brown'}) ***** error ... bar3 (ones (5), 'xlabel') ***** error ... bar3 (ones (5), 'xlabel', 4) ***** error ... bar3 (ones (5), 'ylabel') ***** error ... bar3 (ones (5), 'ylabel', 4) ***** error bar3 (ones (5), 'this', 4) ***** error ... bar3 (ones (5), 'xlabel', {'A', 'B', 'C'}) ***** error ... bar3 (ones (5), 'ylabel', {'A', 'B', 'C'}) 20 tests, 20 passed, 0 known failure, 0 skipped [inst/Plotting/wblplot.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/wblplot.m ***** demo x = [16 34 53 75 93 120]; wblplot (x); ***** demo x = [2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67]'; c = [0 1 0 1 0 1 1 1 0 0 1 0 1 0 1 1 0 1 1]'; [h, p] = wblplot (x, c); p ***** demo x = [16, 34, 53, 75, 93, 120, 150, 191, 240 ,339]; [h, p] = wblplot (x, [], [], 0.05); p ## Benchmark Reliasoft eta = 146.2545 beta 1.1973 rho = 0.9999 ***** demo x = [46 64 83 105 123 150 150]; c = [0 0 0 0 0 0 1]; f = [1 1 1 1 1 1 4]; wblplot (x, c, f, 0.05); ***** demo x = [46 64 83 105 123 150 150]; c = [0 0 0 0 0 0 1]; f = [1 1 1 1 1 1 4]; ## Subtract 30.92 from x to simulate a 3 parameter wbl with gamma = 30.92 wblplot (x - 30.92, c, f, 0.05); ***** test hf = figure ('visible', 'off'); unwind_protect x = [16, 34, 53, 75, 93, 120, 150, 191, 240 ,339]; [h, p] = wblplot (x, [], [], 0.05); assert_equal (numel (h), 4) assert_equal (p(1), 146.2545, 1E-4) assert_equal (p(2), 1.1973, 1E-4) assert_equal (p(3), 0.9999, 5E-5) unwind_protect_cleanup close (hf); end_unwind_protect ***** error ... wblplot ([1, Inf, 2, 3]) ***** error ... wblplot ([1, NaN, 2, 3]) ***** error ... wblplot ([1, 0, 2, 3]) ***** error ... wblplot ([1, 2, 3, -Inf]) ***** error ... wblplot (ones (3, 3)) 6 tests, 6 passed, 0 known failure, 0 skipped [inst/Plotting/scatterhistogram.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Plotting/scatterhistogram.m ***** demo ## Two measurements of the same flowers, and how each is spread. load fisheriris scatterhistogram (meas(:,1), meas(:,2)); xlabel (''); ***** demo ## Grouped by species, each with its own histograms and colour. load fisheriris scatterhistogram (meas(:,3), meas(:,4), 'GroupData', species, ... 'XLabel', 'Petal length', 'YLabel', 'Petal width'); ***** demo ## The same as kernel density estimates, the histograms below and to the ## left of the scatter plot. load fisheriris scatterhistogram (meas(:,3), meas(:,4), 'GroupData', species, ... 'HistogramDisplayStyle', 'smooth', ... 'ScatterPlotLocation', 'NorthEast'); ***** test hf = figure ('visible', 'off'); unwind_protect scatterhistogram ([1, 2, 3], [4, 5, 7]); tag = 'stats.chart.ScatterHistogramChart'; ax = findall (hf, 'type', 'axes', 'tag', tag); assert_equal (numel (ax), 3); assert_equal (ismember (gca (), ax), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect t = table ([1; 2; 3; 4], [2; 4; 1; 3], {'a'; 'b'; 'a'; 'b'}, ... 'VariableNames', {'X', 'Y', 'G'}); h = scatterhistogram (t, 'X', 'Y', 'GroupVariable', 'G'); assert_equal (h.XLabel, 'X'); assert_equal (h.YLabel, 'Y'); assert_equal (h.LegendTitle, 'G'); assert_equal (h.GroupData, {'a'; 'b'; 'a'; 'b'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect plot (1:3); pax = gca (); h = scatterhistogram ([1, 2, 3], [4, 5, 7]); assert_equal (ishghandle (pax), false); plot (1:3); assert_equal (isempty (h.Parent), true); tag = 'stats.chart.ScatterHistogramChart'; assert_equal (isempty (findall (hf, 'tag', tag)), true); unwind_protect_cleanup close (hf); end_unwind_protect ***** error scatterhistogram () ***** error ... scatterhistogram ([1, 2, 3]) ***** error ... scatterhistogram ('a', 'b') ***** error ... scatterhistogram ([1, 2, 3], [1, 2]) ***** error ... scatterhistogram (table ([1; 2]), 'Var1') ***** error ... scatterhistogram ([1, 2, 3], [4, 5, 6], 'Title') ***** error ... scatterhistogram ([1, 2, 3], [4, 5, 6], 'Foo', 1) ***** error ... scatterhistogram ([1, 2, 3], [4, 5, 6], 'GroupVariable', 'G') ***** error ... hf = figure ('visible', 'off'); unwind_protect scatterhistogram (axes (hf), [1, 2, 3], [4, 5, 6]); unwind_protect_cleanup close (hf); end_unwind_protect ***** error ... hf = figure ('visible', 'off'); unwind_protect plot (1:3); hold on; scatterhistogram ([1, 2, 3], [4, 5, 6]); unwind_protect_cleanup close (hf); end_unwind_protect 13 tests, 13 passed, 0 known failure, 0 skipped [inst/logit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/logit.m ***** test p = [0.01:0.01:0.99]; assert_equal (logit (p), log (p ./ (1-p)), 25*eps); ***** assert_equal (logit ([-1, 0, 0.5, 1, 2]), [NaN, -Inf, 0, +Inf, NaN]) ***** error logit () ***** error logit (1, 2) 4 tests, 4 passed, 0 known failure, 0 skipped [inst/Regression/mvregresslike.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/mvregresslike.m ***** demo ## Negative log-likelihood of a two-response regression at the true params. rng (42); X = [ones(20,1), (1:20)'/20]; B = [1 -2; 0.5 3]; Y = X * B + 0.3 * randn (20, 2); nll = mvregresslike (X, Y, B, cov (Y - X*B)) ***** test # complete data: nll agrees across algorithms X = [ones(15,1), linspace(-1,1,15)']; B = [2 -1 0.5; 1 0.3 -0.4]; Y = X * B + 0.1 * cos ((1:15)' * [1 2 3]); S = cov (Y - X*B); n1 = mvregresslike (X, Y, B, S, "ecm"); n2 = mvregresslike (X, Y, B, S, "cwls"); n3 = mvregresslike (X, Y, B, S, "mvn"); assert_equal (n1, n2, 1e-12); assert_equal (n1, n3, 1e-12); ***** test # COVB of complete common design equals kron (Sigma, inv (X'X)) X = [ones(15,1), linspace(-1,1,15)']; B = [2 -1 0.5; 1 0.3 -0.4]; Y = X * B + 0.1 * cos ((1:15)' * [1 2 3]); S = cov (Y - X*B); [~, COVB] = mvregresslike (X, Y, B, S, "ecm"); assert_equal (COVB, kron (S, inv (X'*X)), 1e-10); ***** test # cell and numeric designs give the same nll X = [ones(10,1), (1:10)']; B = [1 2; -1 0.5]; Y = X * B + 0.2 * sin ((1:10)' * [1 2]); S = cov (Y - X*B); Xc = cell (10, 1); for i = 1:10, Xc{i} = kron (eye (2), X(i,:)); end assert_equal (mvregresslike (Xc, Y, B(:), S), ... mvregresslike (X, Y, B, S), 1e-12); ***** shared Xc, Yc, Ym, anch Xc = [1 -0.5382438937; ... 1 0.8672321576; ... 1 0.9759864635; ... 1 0.3373902524; ... 1 -0.9960940966; ... 1 -0.5232140317; ... 1 -1.297447477; ... 1 0.9173885891; ... 1 0.1766016286; ... 1 0.7551799357; ... 1 -0.5914999598; ... 1 1.844389637; ... 1 1.816922249; ... 1 -0.1238333503; ... 1 -1.110601355; ... 1 -0.6809058803; ... 1 0.0141693264; ... 1 -0.05955061046; ... 1 -0.6610110145; ... 1 0.3059509151; ... 1 -0.4090578458; ... 1 -1.281854823; ... 1 -0.2849028295; ... 1 -0.06478685589; ... 1 1.000383189]; Yc = [0.03719753357 -1.298719829 2.592641544; ... -0.8732979121 0.2860080857 0.07019509407; ... 0.9664790872 2.93781363 2.07467313; ... 1.928227972 0.000735060807 1.023278991; ... 1.099525737 -1.790260694 1.621821039; ... 0.8212389245 -1.973919957 3.698786362; ... 0.1466274959 -1.562219847 2.319552949; ... 1.316125907 0.7610511082 0.9228417259; ... 3.19879516 1.119205548 3.035118373; ... 3.324100363 1.40533639 2.521210797; ... -0.5492763312 -2.535610011 -0.009321693727; ... 0.7506317092 1.042220218 -0.1580843947; ... 2.65978063 1.200673839 0.1312316546; ... 1.060827996 -1.429695245 2.854978118; ... 0.3193218045 -0.6292560647 3.238543733; ... 0.08284787504 -0.7632940769 3.223147972; ... 1.943818586 -2.359810723 2.132345279; ... -1.007337725 0.4325819195 1.790333779; ... 0.5483627737 -2.463255725 2.103406495; ... 0.4463418718 0.4193706852 1.806900862; ... 2.151700093 -0.6796218054 0.2488978108; ... 1.601013282 -0.7661239912 3.004258316; ... 1.51658466 -0.6677671869 2.37476419; ... 0.8655905179 -1.911105684 1.609121594; ... -1.036725518 0.3884447934 0.2753353942]; Ym = [0.03719753357 -1.298719829 2.592641544; ... -0.8732979121 NaN 0.07019509407; ... 0.9664790872 2.93781363 2.07467313; ... 1.928227972 0.000735060807 1.023278991; ... 1.099525737 -1.790260694 NaN; ... 0.8212389245 -1.973919957 3.698786362; ... 0.1466274959 NaN 2.319552949; ... 1.316125907 0.7610511082 0.9228417259; ... 3.19879516 1.119205548 3.035118373; ... 3.324100363 1.40533639 2.521210797; ... -0.5492763312 -2.535610011 -0.009321693727; ... 0.7506317092 1.042220218 -0.1580843947; ... 2.65978063 1.200673839 0.1312316546; ... 1.060827996 NaN 2.854978118; ... 0.3193218045 -0.6292560647 3.238543733; ... 0.08284787504 -0.7632940769 3.223147972; ... 1.943818586 -2.359810723 2.132345279; ... -1.007337725 0.4325819195 1.790333779; ... 0.5483627737 -2.463255725 NaN; ... 0.4463418718 0.4193706852 1.806900862; ... 2.151700093 -0.6796218054 0.2488978108; ... 1.601013282 -0.7661239912 3.004258316; ... 1.51658466 -0.6677671869 2.37476419; ... 0.8655905179 -1.911105684 1.609121594; ... -1.036725518 0.3884447934 0.2753353942]; Bt = [1 -0.5 2; ... 0.3 1.2 -0.8]; S0 = cov (Yc); anch = {Bt(:), S0; Bt(:)*0, eye(3); ... Bt(:)+0.25, 1.5*S0; Bt(:)-0.4, S0+0.2*eye(3)}; ***** test # nll vs MATLAB, complete data (all three algorithms agree) ref = [111.8681339; 179.5391646; 120.2543928; 116.9416069]; for k = 1:4 for alg = {"ecm", "cwls", "mvn"} assert_equal (mvregresslike (Xc, Yc, anch{k,1}, anch{k,2}, alg{1}), ... ref(k), 1e-6); endfor endfor ***** test # nll vs MATLAB, missing data: ecm/cwls use all observed, mvn is listwise ref_ecm = [105.2323495; 169.1339808; 112.8053693; 110.1131617]; ref_mvn = [91.35955956; 146.830606; 97.1466466; 96.69358201]; for k = 1:4 assert_equal (mvregresslike (Xc, Ym, anch{k,1}, anch{k,2}, "ecm"), ... ref_ecm(k), 1e-6); assert_equal (mvregresslike (Xc, Ym, anch{k,1}, anch{k,2}, "cwls"), ... ref_ecm(k), 1e-6); assert_equal (mvregresslike (Xc, Ym, anch{k,1}, anch{k,2}, "mvn"), ... ref_mvn(k), 1e-6); endfor ***** test # COVB vs MATLAB (complete data) = kron (Sigma, inv (X'X)) for k = 1:4 [~, COVB] = mvregresslike (Xc, Yc, anch{k,1}, anch{k,2}, "ecm"); assert_equal (COVB, kron (anch{k,2}, inv (Xc'*Xc)), 1e-8); endfor ***** error mvregresslike (1, 2, 3) ***** error mvregresslike ([1;2], [1;2], 1, 1, "xxx") ***** error mvregresslike (ones(3,2), ones(3,2), ones(2,2), 1) 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Regression/regress_gp.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/regress_gp.m ***** demo ## Linear fitting of 1D Data rng (42); X = 2 * rand (5, 1) - 1; Y = 2 * X - 1 + 0.3 * randn (5, 1); ## Points for interpolation/extrapolation Xfit = linspace (-2, 2, 10)'; ## Fit regression model [Yfit, Yint, m] = regress_gp (X, Y, Xfit); ## Plot fitted data plot (X, Y, 'xk', Xfit, Yfit, 'r-', Xfit, Yint, 'b-'); title ('Gaussian process regression with linear kernel'); ***** demo ## Linear fitting of 2D Data rng (42); X = 2 * rand (4, 2) - 1; Y = 2 * X(:,1) - 3 * X(:,2) - 1 + 1 * randn (4, 1); ## Mesh for interpolation/extrapolation [x1, x2] = meshgrid (linspace (-1, 1, 10)); Xfit = [x1(:), x2(:)]; ## Fit regression model [Ypred, Yint, m] = regress_gp (X, Y, Xfit); Ypred = reshape (Ypred, 10, 10); YintL = reshape (Yint(:,1), 10, 10); YintU = reshape (Yint(:,2), 10, 10); ## Plot fitted data plot3 (X(:,1), X(:,2), Y, '.k', 'markersize', 16); hold on; h = mesh (x1, x2, Ypred, zeros (10, 10)); set (h, 'facecolor', 'none', 'edgecolor', 'yellow'); h = mesh (x1, x2, YintU, ones (10, 10)); set (h, 'facecolor', 'none', 'edgecolor', 'cyan'); h = mesh (x1, x2, YintL, ones (10, 10)); set (h, 'facecolor', 'none', 'edgecolor', 'cyan'); hold off axis tight view (75, 25) title ('Gaussian process regression with linear kernel'); ***** demo ## Projection over basis function with linear kernel rng (42); pp = [2, 2, 0.3, 1]; n = 10; X = 2 * rand (n, 1) - 1; Y = polyval (pp, X) + 0.3 * randn (n, 1); ## Powers px = [sqrt(abs(X)), X, X.^2, X.^3]; ## Points for interpolation/extrapolation Xfit = linspace (-1, 1, 100)'; pxi = [sqrt(abs(Xfit)), Xfit, Xfit.^2, Xfit.^3]; ## Define a prior covariance assuming that the sqrt component is not present Sp = 100 * eye (size (px, 2) + 1); Sp(2,2) = 1; # We don't believe the sqrt(abs(X)) is present ## Fit regression model [Yfit, Yint, m] = regress_gp (px, Y, pxi, Sp); ## Plot fitted data plot (X, Y, 'xk;Data;', Xfit, Yfit, 'r-;Estimation;', ... Xfit, polyval (pp, Xfit), 'g-;True;'); axis tight axis manual hold on plot (Xfit, Yint(:,1), 'b-;Lower bound;', ... Xfit, Yint(:,2), 'm-;Upper bound;'); hold off title ('Linear kernel over basis function with prior covariance'); ***** demo ## Projection over basis function with linear kernel rng (42); pp = [2, 2, 0.3, 1]; n = 10; X = 2 * rand (n, 1) - 1; Y = polyval (pp, X) + 0.3 * randn (n, 1); ## Powers px = [sqrt(abs(X)), X, X.^2, X.^3]; ## Points for interpolation/extrapolation Xfit = linspace (-1, 1, 100)'; pxi = [sqrt(abs(Xfit)), Xfit, Xfit.^2, Xfit.^3]; ## Fit regression model without any assumption on prior covariance [Yfit, Yint, m] = regress_gp (px, Y, pxi); ## Plot fitted data plot (X, Y, 'xk;Data;', Xfit, Yfit, 'r-;Estimation;', ... Xfit, polyval (pp, Xfit), 'g-;True;'); axis tight axis manual hold on plot (Xfit, Yint(:,1), 'b-;Lower bound;', ... Xfit, Yint(:,2), 'm-;Upper bound;'); hold off title ('Linear kernel over basis function without prior covariance'); ***** demo ## Projection over basis function with rbf kernel rng (42); pp = [2, 2, 0.3, 1]; n = 10; X = 2 * rand (n, 1) - 1; Y = polyval (pp, X) + 0.3 * randn (n, 1); ## Powers px = [sqrt(abs(X)), X, X.^2, X.^3]; ## Points for interpolation/extrapolation Xfit = linspace (-1, 1, 100)'; pxi = [sqrt(abs(Xfit)), Xfit, Xfit.^2, Xfit.^3]; ## Fit regression model with RBF kernel (standard parameters) [Yfit, Yint, Ysd] = regress_gp (px, Y, pxi, 'rbf'); ## Plot fitted data plot (X, Y, 'xk;Data;', Xfit, Yfit, 'r-;Estimation;', ... Xfit, polyval (pp, Xfit), 'g-;True;'); axis tight axis manual hold on plot (Xfit, Yint(:,1), 'b-;Lower bound;', ... Xfit, Yint(:,2), 'm-;Upper bound;'); hold off title ('RBF kernel over basis function with standard parameters'); text (-0.5, 4, "theta = 5\n g = 0.01"); ***** demo ## Projection over basis function with rbf kernel rng (42); pp = [2, 2, 0.3, 1]; n = 10; X = 2 * rand (n, 1) - 1; Y = polyval (pp, X) + 0.3 * randn (n, 1); ## Powers px = [sqrt(abs(X)), X, X.^2, X.^3]; ## Points for interpolation/extrapolation Xfit = linspace (-1, 1, 100)'; pxi = [sqrt(abs(Xfit)), Xfit, Xfit.^2, Xfit.^3]; ## Fit regression model with RBF kernel with different parameters [Yfit, Yint, Ysd] = regress_gp (px, Y, pxi, 'rbf', 10, 0.01); ## Plot fitted data plot (X, Y, 'xk;Data;', Xfit, Yfit, 'r-;Estimation;', ... Xfit, polyval (pp, Xfit), 'g-;True;'); axis tight axis manual hold on plot (Xfit, Yint(:,1), 'b-;Lower bound;', ... Xfit, Yint(:,2), 'm-;Upper bound;'); hold off title ('GP regression with RBF kernel and non default parameters'); text (-0.5, 4, "theta = 10\n g = 0.01"); ## Fit regression model with RBF kernel with different parameters [Yfit, Yint, Ysd] = regress_gp (px, Y, pxi, 'rbf', 50, 0.01); ## Plot fitted data figure plot (X, Y, 'xk;Data;', Xfit, Yfit, 'r-;Estimation;', ... Xfit, polyval (pp, Xfit), 'g-;True;'); axis tight axis manual hold on plot (Xfit, Yint(:,1), 'b-;Lower bound;', ... Xfit, Yint(:,2), 'm-;Upper bound;'); hold off title ('GP regression with RBF kernel and non default parameters'); text (-0.5, 4, "theta = 50\n g = 0.01"); ## Fit regression model with RBF kernel with different parameters [Yfit, Yint, Ysd] = regress_gp (px, Y, pxi, 'rbf', 50, 0.001); ## Plot fitted data figure plot (X, Y, 'xk;Data;', Xfit, Yfit, 'r-;Estimation;', ... Xfit, polyval (pp, Xfit), 'g-;True;'); axis tight axis manual hold on plot (Xfit, Yint(:,1), 'b-;Lower bound;', ... Xfit, Yint(:,2), 'm-;Upper bound;'); hold off title ('GP regression with RBF kernel and non default parameters'); text (-0.5, 4, "theta = 50\n g = 0.001"); ## Fit regression model with RBF kernel with different parameters [Yfit, Yint, Ysd] = regress_gp (px, Y, pxi, 'rbf', 50, 0.05); ## Plot fitted data figure plot (X, Y, 'xk;Data;', Xfit, Yfit, 'r-;Estimation;', ... Xfit, polyval (pp, Xfit), 'g-;True;'); axis tight axis manual hold on plot (Xfit, Yint(:,1), 'b-;Lower bound;', ... Xfit, Yint(:,2), 'm-;Upper bound;'); hold off title ('GP regression with RBF kernel and non default parameters'); text (-0.5, 4, "theta = 50\n g = 0.05"); ***** demo ## RBF fitting on noiseless 1D Data rng (42); x = [0:2*pi/7:2*pi]'; y = 5 * sin (x); ## Predictive grid of 500 equally spaced locations xi = [-0.5:(2*pi+1)/499:2*pi+0.5]'; ## Fit regression model with RBF kernel [Yfit, Yint, Ysd] = regress_gp (x, y, xi, 'rbf'); ## Plot fitted data r = mvnrnd (Yfit, diag (Ysd)', 50); plot (xi, r', 'c-'); hold on plot (xi, Yfit, 'r-;Estimation;', xi, Yint, 'b-;Confidence interval;'); plot (x, y, '.k;Predictor points;', 'markersize', 20) plot (xi, 5 * sin (xi), '-y;True Function;'); xlim ([-0.5,2*pi+0.5]); ylim ([-10,10]); hold off title ('GP regression with RBF kernel on noiseless 1D data'); text (0, -7, "theta = 5\n g = 0.01"); ***** demo ## RBF fitting on noisy 1D Data rng (42); x = [0:2*pi/7:2*pi]'; x = [x; x]; y = 5 * sin (x) + randn (size (x)); ## Predictive grid of 500 equally spaced locations xi = [-0.5:(2*pi+1)/499:2*pi+0.5]'; ## Fit regression model with RBF kernel [Yfit, Yint, Ysd] = regress_gp (x, y, xi, 'rbf'); ## Plot fitted data r = mvnrnd (Yfit, diag (Ysd)', 50); plot (xi, r', 'c-'); hold on plot (xi, Yfit, 'r-;Estimation;', xi, Yint, 'b-;Confidence interval;'); plot (x, y, '.k;Predictor points;', 'markersize', 20) plot (xi, 5 * sin (xi), '-y;True Function;'); xlim ([-0.5,2*pi+0.5]); ylim ([-10,10]); hold off title ('GP regression with RBF kernel on noisy 1D data'); text (0, -7, "theta = 5\n g = 0.01"); ***** test ## The RBF mean is the Gaussian process posterior mean, which RegressionGP ## computes too. Matching the parameterisations: this function writes the ## kernel as exp (-d2 / theta) with a noise variance g added, where ## RegressionGP writes it as SigmaF^2 * exp (-0.5 * d2 / SigmaL^2) with a ## noise standard deviation, so SigmaL = sqrt (theta/2), SigmaF = 1 and ## Sigma = sqrt (g). x = linspace (0, 1, 20)'; y = sin (2*pi*x); xq = [0.15; 0.45; 0.75]; theta = 0.5; g = 0.01; yf = regress_gp (x, y, xq, 'rbf', theta, g); Mdl = RegressionGP (x, y, 'KernelFunction', 'squaredexponential', ... 'KernelParameters', [sqrt(theta/2); 1], ... 'Sigma', sqrt (g), 'BasisFunction', 'none', ... 'FitMethod', 'none'); assert_equal (yf, predict (Mdl, xq), 1e-10); ***** test ## The RBF interval is the normal quantile of the level times the standard ## deviation, on both sides of the fit x = linspace (0, 1, 20)'; y = sin (2*pi*x); xq = [0.2; 0.5; 0.8]; [yf, yi, ys] = regress_gp (x, y, xq, 'rbf'); sd = sqrt (diag (ys)); assert_equal (yi(:,1), yf - norminv (0.975) * sd, 1e-12); assert_equal (yi(:,2), yf + norminv (0.975) * sd, 1e-12); ***** test ## A looser level gives a narrower interval, and the level reaches the ## interval at all, which it did not before x = linspace (0, 1, 20)'; y = sin (2*pi*x); xq = [0.2; 0.5; 0.8]; [~, yi95] = regress_gp (x, y, xq, 'rbf', 5, 0.01, 0.05); [~, yi80] = regress_gp (x, y, xq, 'rbf', 5, 0.01, 0.20); assert (all (yi80(:,2) - yi80(:,1) < yi95(:,2) - yi95(:,1))); ***** test ## The linear mean is the Bayesian linear regression posterior mean x = linspace (0, 1, 15)'; y = 2 * x + 0.5; xq = [0.25; 0.75]; Sp = 100 * eye (2); yf = regress_gp (x, y, xq); Xd = [ones(1, 15); x']; wm = inv (Xd * Xd' + inv (Sp)) * Xd * y; assert_equal (yf, [ones(2, 1), xq] * wm, 1e-12); ***** test ## The linear interval is built from a standard deviation and carries the ## confidence level, where it used to be a bare variance x = linspace (0, 1, 15)'; y = 2 * x + 0.5; xq = [0.25; 0.75]; [yf, yi, wm, K] = regress_gp (x, y, xq); sd = sqrt (diag ([ones(2, 1), xq] * K * [ones(2, 1), xq]')); assert_equal (yi(:,1), yf - norminv (0.975) * sd, 1e-12); assert_equal (yi(:,2), yf + norminv (0.975) * sd, 1e-12); ***** test ## Both branches order the interval the same way, lower bound first, as ## every other prediction interval in the package does x = linspace (0, 1, 15)'; y = sin (3*x); xq = [0.3; 0.6]; [~, yiL] = regress_gp (x, y, xq, 'linear'); [~, yiR] = regress_gp (x, y, xq, 'rbf'); assert (all (yiL(:,1) < yiL(:,2))); assert (all (yiR(:,1) < yiR(:,2))); ***** test rand ('seed', 91); x = 2 * rand (12, 1) - 1; y = sin (3 * x); xq = linspace (-1, 1, 6)'; [yf, yi, S] = regress_gp (x, y, xq, 'rbf'); assert_equal (yi(:,2) - yf, norminv (0.975) * sqrt (diag (S)), 1e-12); assert_equal (yf - yi(:,1), norminv (0.975) * sqrt (diag (S)), 1e-12); ***** test rand ('seed', 91); x = 2 * rand (12, 1) - 1; y = sin (3 * x); xq = linspace (-1, 1, 6)'; [yf2, yi2] = regress_gp (x, y, xq, 'rbf'); [yf3, yi3, S] = regress_gp (x, y, xq, 'rbf'); assert_equal (yf2, yf3); assert_equal (yi2, yi3); ***** test rand ('seed', 3); x = sort (2 * rand (10, 1) - 1); y = sin (3 * x) + 0.1; [yf, yi] = regress_gp (x, y, x, 'rbf', 1, 0); assert_equal (yf, y, 1e-4); assert (max (abs (yi(:,2) - yf)) < 1e-2); ***** test rand ('seed', 17); x = 2 * rand (10, 2) - 1; y = x(:,1) - 2 * x(:,2) + 0.1; xq = 2 * rand (4, 2) - 1; [yf, yi, wm, K] = regress_gp (x, y, xq); xa = [ones(4, 1), xq]; assert_equal (yi(:,2) - yf, ... norminv (0.975) * sqrt (diag (xa * K * xa')), 1e-12); ***** error regress_gp (ones (20, 2)) ***** error regress_gp (ones (20, 2), ones (20, 1)) ***** error ... regress_gp (ones (20, 2, 3), ones (20, 1), ones (20, 2)) ***** error ... regress_gp (ones (20, 2), ones (20, 2), ones (20, 2)) ***** error ... regress_gp (ones (20, 2), ones (15, 1), ones (20, 2)) ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (20, 3)) ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (10, 2), {[3]}) ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (10, 2), 'kernel') ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (10, 2), 'rbf', ones (4)) ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (20, 2), 5, 'junk') ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (20, 2), zeros (3, 3)) ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (20, 2), 'linear', zeros (3, 3)) ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (20, 2), eye (4)) ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (10, 2), 'linear', 1) ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (10, 2), 'rbf', 'value') ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (10, 2), 'rbf', {5}) ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (10, 2), eye (3), 5) ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (10, 2), 'linear', 5) ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (10, 2), 'rbf', 5, {5}) ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (10, 2), 'rbf', 5, ones (2)) ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (10, 2), 5, 0.01, [1, 1]) ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (10, 2), 5, 0.01, 'f') ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (10, 2), 5, 0.01, 'f') ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (10, 2), 'rbf', 5, 0.01, 'f') ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (10, 2), 'rbf', 5, 0.01, [1, 1]) ***** error ... regress_gp (ones (20, 2), ones (20, 1), ones (10, 2), 'linear', 1) 36 tests, 36 passed, 0 known failure, 0 skipped [inst/Regression/stepwiseglm.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/stepwiseglm.m ***** demo ## Stepwise Poisson regression: start from a constant model and let the ## search add the predictors that matter. X = [0.83, -0.68; 0.22, 0.93; -0.12, 0.72; 0.55, -2.55; 1.89, 1.39; ... -1.46, -1.18; 1.06, -0.75; -0.89, 0.85; 0.19, -0.71; -0.43, -0.57]; y = [2; 2; 2; 1; 9; 0; 2; 1; 1; 1]; mdl = stepwiseglm (X, y, 'constant', 'Distribution', 'poisson', ... 'Upper', 'linear') ***** demo ## Stepwise logistic regression selected by AIC, reported from a table. X = [0.83, 1.02; 0.22, 0.29; -0.12, 0.09; 0.55, 0.56; 1.89, 1.96; ... -1.46, -0.46; 1.06, -0.87; -0.89, 1.18; 0.19, -1.00; -0.43, -0.04]; y = [1; 1; 0; 1; 1; 0; 1; 0; 1; 0]; tbl = array2table ([X, y], 'VariableNames', {'x1', 'x2', 'y'}); mdl = stepwiseglm (tbl, 'constant', 'Distribution', 'binomial', ... 'Criterion', 'aic', 'Verbose', 0) ***** shared X, yb, yp, yn, CT, CU, CN X = [ 0.83, -0.68, 1.02, 0.02; 0.22, 0.93, 0.29, -0.57; ... -0.12, 0.72, 0.09, -1.03; 0.55, -2.55, 0.56, 0.97; ... 1.89, 1.39, 1.96, 0.16; -1.46, -1.18, -0.46, 0.33; ... 1.06, -0.75, -0.87, 0.08; -0.89, 0.85, 1.18, -1.04; ... 0.19, -0.71, -1.00, 1.85; -0.43, -0.57, -0.04, 0.75; ... -0.90, -1.75, -0.61, -0.68; 1.52, -0.10, 0.43, -1.16; ... 0.58, -1.63, 0.08, -0.73; 0.11, 0.87, -0.40, -0.15; ... 1.26, -0.42, -0.95, -1.07; -0.02, 1.09, 1.03, 1.54; ... 0.80, 0.97, 0.53, 0.62; -0.40, -1.18, 2.83, -1.36; ... -0.61, -0.44, -1.85, -1.57; 1.22, -0.94, -0.26, -0.75; ... -0.84, 0.11, -0.55, -0.42; 1.66, -1.27, -1.05, -0.98; ... 0.29, 0.59, -0.36, -0.74; -1.10, -1.29, 0.40, 0.35; ... 0.08, -0.90, -0.74, -0.51; 1.48, -0.04, -0.11, -1.47; ... 0.06, 0.05, -0.09, -1.55; 0.84, 0.13, -1.11, -1.24; ... -0.72, -0.02, 0.75, -0.39; 1.11, 0.34, -1.32, -0.18; ... 1.48, -1.55, -0.06, 1.28; -0.16, -0.24, 1.34, -1.92; ... -0.67, 0.80, 1.01, -0.07; -0.26, -1.10, -0.33, -0.88; ... -0.26, -2.42, 0.77, -1.44; -0.62, -0.38, -0.38, -1.77; ... 0.41, 0.90, 0.85, 0.72; -1.16, 0.99, 0.74, -2.00; ... -0.44, -1.22, 1.06, -1.14; 1.85, 0.21, 0.65, -0.11]; yb = [1 1 0 1 1 0 1 0 1 0 0 1 0 1 1 1 1 1 0 1 0 0 0 0 0 1 0 1 0 1 ... 0 1 0 0 1 0 1 0 0 1]'; yp = [2 2 2 1 9 0 2 1 1 1 0 3 1 2 2 2 3 1 1 2 1 2 2 0 1 3 1 2 1 3 ... 2 1 1 1 0 1 3 1 0 5]'; yn = [3.17 1.66 0.99 3.87 6.22 1.34 4.8 0.58 4.05 2.06 2.81 3.97 3.84 ... 1.11 4.26 2.57 3.07 -1.07 1.7 4.58 0.47 6.41 1.55 1.02 3.29 3.81 ... 1.58 2.65 0.81 2.94 5.93 1.09 1.06 2.55 1.44 0.97 2.8 -0.47 0.81 ... 4.7]'; lev = {'A', 'B', 'C'}'; a1 = ((1:48)' - 24.5)/12; a2 = sin ((1:48)'/5); ag = lev(mod ((0:47)', 3) + 1); ay = [0 1 0 1 2 0 1 2 0 1 2 1 1 2 1 1 3 1 1 3 1 1 3 1 1 4 1 2 5 1 3 8 ... 2 4 11 3 5 15 4 7 18 4 8 20 4 8 20 5]'; CT = table (a1, a2, ag, ay, 'VariableNames', {'x1', 'x2', 'g', 'y'}); b1 = ((1:60)' - 30.5)/15; bg = lev(mod ((0:59)', 3) + 1); bh = lev(mod (floor ((0:59)'/2), 3) + 1); by = [2 0 7 2 0 6 2 0 6 2 1 5 2 1 5 2 1 5 2 1 4 3 2 4 3 2 4 3 3 3 3 4 ... 3 4 5 3 4 6 3 4 8 2 5 11 2 5 14 2 5 18 2 6 23 2 6 30 2 7 39 2]'; CU = table (b1, bg, bh, by, 'VariableNames', {'x1', 'g', 'h', 'y'}); CN = table (b1, bg, bh, by / 4, 'VariableNames', {'x1', 'g', 'h', 'y'}); ***** test ## Binomial: the Deviance criterion selects x1 and x3. mdl = stepwiseglm (X, yb, 'constant', 'Distribution', 'binomial', ... 'Upper', 'interactions', 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)', 'x1', 'x3'}); assert_equal (mdl.Coefficients.Estimate, ... [-0.567847008659897; 2.24005553968806; 1.10257647012], 1e-8); assert_equal (mdl.Deviance, 35.424118776089266, 1e-9); assert_equal (mdl.LogLikelihood, -17.712059388044633, 1e-9); ***** test ## Poisson: selects x1 and x2 (interaction not significant). mdl = stepwiseglm (X, yp, 'constant', 'Distribution', 'poisson', ... 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)', 'x1', 'x2'}); assert_equal (mdl.Coefficients.Estimate, ... [0.242293607853268; 0.672082935896644; 0.459103523205052], 1e-8); assert_equal (mdl.Deviance, 5.62441316952502, 1e-9); ***** test ## Normal (estimated dispersion, F-test): mains plus x1:x4 and x2:x3. mdl = stepwiseglm (X, yn, 'constant', 'Verbose', 0); assert_equal (mdl.CoefficientNames, ... {'(Intercept)', 'x1', 'x2', 'x3', 'x4', 'x1:x4', 'x2:x3'}); assert_equal (mdl.NumCoefficients, 7); assert_equal (any (strcmp (mdl.CoefficientNames, 'x2:x3')), true); ***** test ## The AIC criterion is greedier and also brings in x3:x4. mdl = stepwiseglm (X, yn, 'linear', 'Upper', 'interactions', ... 'Criterion', 'aic', 'Verbose', 0); assert_equal (mdl.NumCoefficients, 8); assert_equal (any (strcmp (mdl.CoefficientNames, 'x3:x4')), true); ***** test ## BIC reaches the same eight-coefficient model here. mdl = stepwiseglm (X, yn, 'constant', 'Criterion', 'bic', 'Verbose', 0); assert_equal (mdl.NumCoefficients, 8); assert_equal (any (strcmp (mdl.CoefficientNames, 'x3:x4')), true); ***** test ## A formula-valued Upper bounds the candidate universe. mdl = stepwiseglm (X, yp, 'y ~ x1', 'Distribution', 'poisson', ... 'Upper', 'y ~ x1 + x2 + x3', 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)', 'x1', 'x2'}); ***** test ## Lower/Upper keywords: search within [linear, quadratic] adds interactions. mdl = stepwiseglm (X, yn, 'linear', 'Lower', 'linear', ... 'Upper', 'quadratic', 'Verbose', 0); assert_equal (mdl.NumCoefficients, 7); assert_equal (any (strcmp (mdl.CoefficientNames, 'x2:x3')), true); assert_equal (any (strcmp (mdl.CoefficientNames, 'x1:x4')), true); ***** test ## The Steps property records the trace; History matches the deviance test. mdl = stepwiseglm (X, yb, 'constant', 'Distribution', 'binomial', ... 'Upper', 'interactions', 'Verbose', 0); assert_equal (mdl.Steps.Criterion, 'deviance_chi2'); assert_equal (size (mdl.Steps.History, 1), 3); assert_equal (mdl.Steps.History.Action{1}, 'Start'); assert_equal (mdl.Steps.History.Chi2Stat(2), 14.8398950335268, 1e-6); ***** test ## Table input, response taken from the last column by default. tbl = array2table ([X(:,1:2), yp], 'VariableNames', {'a', 'b', 'y'}); mdl = stepwiseglm (tbl, 'constant', 'Distribution', 'poisson', ... 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)', 'a', 'b'}); ***** test ## Collinear predictors are fitted, not refused; the redundant column is ## dropped rather than entering the model. mdl = stepwiseglm ([X(:,1), X(:,1)], yn, 'constant', 'Verbose', 0); assert_equal (class (mdl), 'GeneralizedLinearModel'); assert_equal (mdl.CoefficientNames, {'(Intercept)', 'x1'}); ***** test ## A cell-array column of a table is taken as categorical without being ## named, and the fit matches MATLAB R2024a. mdl = stepwiseglm (CT, 'y ~ 1', 'Upper', 'y ~ x1 + x2 + g', ... 'Distribution', 'poisson', 'Verbose', 0); assert_equal (mdl.CoefficientNames, ... {'(Intercept)', 'x1', 'x2', 'g_B', 'g_C'}); assert_equal (mdl.Coefficients.Estimate, ... [0.603329330791641; 0.796711055930047; 0.285851899335031; ... 0.915480956228751; -0.550531653341791], 1e-10); assert_equal (mdl.Deviance, 5.49511881200541, 1e-10); ***** test ## The indicators of a categorical predictor enter as one term, so the ## step is worth L-1 degrees of freedom and is named for the predictor. mdl = stepwiseglm (CT, 'y ~ 1', 'Upper', 'y ~ x1 + x2 + g', ... 'Distribution', 'poisson', 'Verbose', 0); assert_equal (mdl.Steps.History.TermName, {'1'; 'x1'; 'g'; 'x2'}); assert_equal (mdl.Steps.History.DF, [1; 2; 4; 5]); assert_equal (mdl.Steps.History.delDF, [NaN; 1; 2; 1]); ***** test ## The deviance test of a grouped term is the joint test of its indicators. mdl = stepwiseglm (CT, 'y ~ 1', 'Upper', 'y ~ x1 + x2 + g', ... 'Distribution', 'poisson', 'Verbose', 0); assert_equal (mdl.Steps.History.Deviance, ... [220.977093395079; 81.2408117834874; 10.3794318146782; ... 5.49511881200541], 1e-9); assert_equal (mdl.Steps.History.Chi2Stat, ... [NaN; 139.736281611591; 70.8613799688091; ... 4.88431300267280], 1e-9); assert_equal (mdl.Steps.History.PValue(4), 0.0271018179857880, 1e-12); ***** test ## An interaction naming a categorical predictor is also one term, and its ## coefficients are named for the indicators. mdl = stepwiseglm (CU, 'y ~ 1', 'Upper', 'y ~ x1*g', ... 'Distribution', 'poisson', 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)', 'x1', 'g_B', 'g_C', ... 'x1:g_B', 'x1:g_C'}); assert_equal (mdl.Steps.History.TermName, {'1'; 'x1'; 'g'; 'x1:g'}); assert_equal (mdl.Steps.History.delDF, [NaN; 1; 2; 2]); assert_equal (mdl.Coefficients.Estimate, ... [1.21521326020005; 0.372340711075598; -0.0523666888775920; ... 0; 0.950243386703989; -0.744681422151197], 1e-9); ***** test ## A grouped term leaves in one step too, and its delDF is negative. mdl = stepwiseglm (CU, 'y ~ x1 + g + h', 'Lower', 'y ~ 1', 'Upper', ... 'y ~ x1 + g + h', 'Distribution', 'poisson', ... 'Verbose', 0); assert_equal (mdl.Formula.LinearPredictor, '1 + x1 + g'); assert_equal (mdl.Steps.History.Action, {'Start'; 'Remove'}); assert_equal (mdl.Steps.History.TermName, {'1 + x1 + g + h'; 'h'}); assert_equal (mdl.Steps.History.DF, [6; 4]); assert_equal (mdl.Steps.History.delDF, [NaN; -2]); assert_equal (mdl.Steps.History.Chi2Stat, [NaN; 0.914420851291737], 1e-10); ***** test ## A categorical array is coded by its categories, a cell array by the ## order its labels appear; on this fixture the two agree. ct = CT; ct.g = categorical (ct.g); m1 = stepwiseglm (ct, 'y ~ 1', 'Upper', 'y ~ x1 + x2 + g', ... 'Distribution', 'poisson', 'Verbose', 0); m2 = stepwiseglm (CT, 'y ~ 1', 'Upper', 'y ~ x1 + x2 + g', ... 'Distribution', 'poisson', 'Verbose', 0); assert_equal (m1.CoefficientNames, m2.CoefficientNames); assert_equal (m1.Coefficients.Estimate, m2.Coefficients.Estimate, 1e-12); ***** test ## A column of a predictor matrix is categorical only when named, and the ## levels are then its sorted distinct values. Xm = [((1:60)' - 30.5)/15, mod((0:59)', 3) + 1, ... mod(floor((0:59)'/2), 3) + 1]; ym = CU.y; mdl = stepwiseglm (Xm, ym, 'constant', 'Upper', 'linear', ... 'Distribution', 'poisson', ... 'CategoricalVars', logical ([0, 1, 1]), 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)', 'x1', 'x2_2', 'x2_3'}); assert_equal (mdl.Steps.History.TermName, {'1'; 'x1'; 'x2'}); assert_equal (mdl.Steps.History.delDF, [NaN; 1; 2]); ***** test ## Indices and a logical vector mark the same columns. Xm = [((1:60)' - 30.5)/15, mod((0:59)', 3) + 1, ... mod(floor((0:59)'/2), 3) + 1]; ym = CU.y; m1 = stepwiseglm (Xm, ym, 'constant', 'Upper', 'linear', ... 'Distribution', 'poisson', 'CategoricalVars', [2, 3], ... 'Verbose', 0); m2 = stepwiseglm (Xm, ym, 'constant', 'Upper', 'linear', ... 'Distribution', 'poisson', ... 'CategoricalVars', logical ([0, 1, 1]), 'Verbose', 0); assert_equal (m1.Coefficients.Estimate, m2.Coefficients.Estimate, 1e-12); ***** test ## The Start row names the starting model, not the constant, and reports ## the coefficient count it was fitted with. mdl = stepwiseglm (CU, 'y ~ x1 + g', 'Lower', 'y ~ x1 + g', 'Upper', ... 'y ~ x1 + g', 'Distribution', 'poisson', 'Verbose', 0); assert_equal (mdl.Steps.History.TermName, {'1 + x1 + g'}); assert_equal (mdl.Steps.History.DF, 4); ***** test ## An estimated dispersion turns the deviance test into an F test, and the ## criterion is labelled for it. mdl = stepwiseglm (CN, 'y ~ 1', 'Upper', 'y ~ x1 + g + h', ... 'Distribution', 'normal', 'Verbose', 0); assert_equal (mdl.Steps.Criterion, 'deviance_f'); assert_equal (mdl.Steps.History.Properties.VariableNames, ... {'Action', 'TermName', 'Terms', 'DF', 'delDF', 'Deviance', ... 'FStat', 'PValue'}); assert_equal (mdl.Steps.History.FStat, ... [NaN; 15.1516937210352; 4.75429941449063], 1e-10); ***** test ## Under 'sse' the history reports the F test alone, with MATLAB's own ## lower-case column name. mdl = stepwiseglm (CN, 'y ~ 1', 'Upper', 'y ~ x1 + g + h', ... 'Distribution', 'normal', 'Criterion', 'sse', ... 'Verbose', 0); assert_equal (mdl.Steps.History.Properties.VariableNames, ... {'Action', 'TermName', 'Terms', 'DF', 'delDF', 'FStat', ... 'pValue'}); assert_equal (mdl.Steps.History.pValue, ... [NaN; 0.000258691112717; 0.012385457865093], 1e-12); ***** test ## An information criterion has no test to report, so the history carries ## its value instead, the starting model included. mdl = stepwiseglm (CU, 'y ~ 1', 'Upper', 'y ~ x1 + g + h', ... 'Distribution', 'poisson', 'Criterion', 'aic', ... 'Verbose', 0); assert_equal (mdl.Steps.History.Properties.VariableNames, ... {'Action', 'TermName', 'Terms', 'DF', 'delDF', 'AIC'}); assert_equal (mdl.Steps.History.AIC, ... [504.960173118363; 394.245450753972; 341.770323510125], 1e-9); ***** test ## A p-value far below eps is computed on the upper tail, not as one minus ## the lower, so it does not round to zero. mdl = stepwiseglm (CU, 'y ~ 1', 'Upper', 'y ~ x1*g', ... 'Distribution', 'poisson', 'Verbose', 0); assert_equal (mdl.Steps.History.PValue(2), 2.49165e-26, 1e-30); assert_equal (mdl.Steps.History.PValue(4), 1.19350e-32, 1e-36); ***** test ## Each history row carries the terms in the model's own order, not in the ## order the search added them, so the last row is the fitted model's. mdl = stepwiseglm (CT, 'y ~ 1', 'Upper', 'y ~ x1 + x2 + g', ... 'Distribution', 'poisson', 'Verbose', 0); assert_equal (mdl.Steps.History.TermName, {'1'; 'x1'; 'g'; 'x2'}); assert_equal (mdl.Steps.History.Terms{end}, mdl.Formula.Terms); assert_equal (mdl.Steps.History.Terms{end}, ... [0, 0, 0, 0; 1, 0, 0, 0; 0, 1, 0, 0; 0, 0, 1, 0]); ***** test ## Start, Lower, and Upper are formula objects carrying the link. mdl = stepwiseglm (CT, 'y ~ 1', 'Upper', 'y ~ x1 + x2 + g', ... 'Distribution', 'poisson', 'Verbose', 0); assert_equal (class (mdl.Steps.Start), 'LinearFormula'); assert_equal (char (mdl.Steps.Start), 'log(y) ~ 1'); assert_equal (char (mdl.Steps.Upper), 'log(y) ~ 1 + x1 + x2 + g'); assert_equal (mdl.Steps.Lower.LinearPredictor, '1'); ***** error stepwiseglm () ***** error stepwiseglm ("a", [1;2]) ***** error ... stepwiseglm ([1, 2; 3, 4], [1; 0], 'Distribution', 'wibble') ***** error ... stepwiseglm ([1, 2; 3, 4], [1; 0], 'Criterion', 'nope') ***** error ... stepwiseglm ([1, 2; 3, 4], [1; 0], 'linear', 'foo', 1) ***** error ... stepwiseglm ([1, 2; 3, 4], [1; 0], 'CategoricalVars', {'nope'}) ***** error ... stepwiseglm ([1, 2; 3, 4], [1; 0], 'CategoricalVars', {1}) ***** test # a two-column binomial response matches MATLAB R2024a x = (1:10)'; S = [0 1 1 2 3 4 6 7 9 9]'; mdl = stepwiseglm (x, [S, 10 * ones(10, 1)], 'constant', 'upper', ... 'linear', 'Distribution', 'binomial', 'Verbose', 0); assert_equal (mdl.Coefficients.Estimate, ... [-4.07619632416318; 0.639874139429377], 1e-10); assert_equal (mdl.Deviance, 1.37328920133713, 1e-10); ***** test # the two-column and BinomialSize forms select the same model x = (1:10)'; S = [0 1 1 2 3 4 6 7 9 9]'; N = 10 * ones (10, 1); m1 = stepwiseglm (x, [S, N], 'constant', 'upper', 'linear', ... 'Distribution', 'binomial', 'Verbose', 0); m2 = stepwiseglm (x, S, 'constant', 'upper', 'linear', ... 'Distribution', 'binomial', 'BinomialSize', N, ... 'Verbose', 0); assert_equal (m2.Coefficients.Estimate, m1.Coefficients.Estimate, 1e-12); 34 tests, 34 passed, 0 known failure, 0 skipped [inst/Regression/plsregress.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/plsregress.m ***** demo ## Perform Partial Least-Squares Regression ## Load the spectra data set and use the near infrared (NIR) spectral ## intensities (NIR) as the predictor and the corresponding octave ## ratings (octave) as the response. load spectra ## Perform PLS regression with 10 components [xload, yload, xscore, yscore, coef, ptcVar] = plsregress (NIR, octane, 10); ## Plot the percentage of explained variance in the response variable ## (PCTVAR) as a function of the number of components. plot (1:10, cumsum (100 * ptcVar(2,:)), '-ro'); xlim ([1, 10]); xlabel ('Number of PLS components'); ylabel ('Percentage of Explained Variance in octane'); title ('Explained Variance per PLS components'); ## Compute the fitted response and display the residuals. octane_fitted = [ones(size(NIR,1),1), NIR] * coef; residuals = octane - octane_fitted; figure stem (residuals, 'color', 'r', 'markersize', 4, 'markeredgecolor', 'r') xlabel ('Observations'); ylabel ('Residuals'); title ('Residuals in octane''s fitted response'); ***** demo ## Calculate Variable Importance in Projection (VIP) for PLS Regression ## Load the spectra data set and use the near infrared (NIR) spectral ## intensities (NIR) as the predictor and the corresponding octave ## ratings (octave) as the response. Variables with a VIP score greater than ## 1 are considered important for the projection of the PLS regression model. load spectra ## Perform PLS regression with 10 components [xload, yload, xscore, yscore, coef, pctVar, mse, stats] = ... plsregress (NIR, octane, 10); ## Calculate the normalized PLS weights W0 = stats.W ./ sqrt (sum (stats.W.^2,1)); ## Calculate the VIP scores for 10 components nobs = size (xload, 1); SS = sum (xscore .^ 2, 1) .* sum (yload .^ 2, 1); VIPscore = sqrt (nobs * sum (SS .* (W0 .^ 2), 2) ./ sum (SS, 2)); ## Find variables with a VIP score greater than or equal to 1 VIPidx = find (VIPscore >= 1); ## Plot the VIP scores scatter (1:length (VIPscore), VIPscore, 'xb'); hold on scatter (VIPidx, VIPscore(VIPidx), 'xr'); plot ([1, length(VIPscore)], [1, 1], '--k'); hold off axis ('tight'); xlabel ('Predictor Variables'); ylabel ('VIP scores'); title ('VIP scores for each predictor variable with 10 components'); ***** test load spectra [xload, yload, xscore, yscore, coef, pctVar] = plsregress (NIR, octane, 10); xload1_out = [-0.0170, 0.0039, 0.0095, 0.0258, 0.0025, ... -0.0075, 0.0000, 0.0018, -0.0027, 0.0020]; yload_out = [6.6384, 9.3106, 2.0505, 0.6471, 0.9625, ... 0.5905, 0.4244, 0.2437, 0.3516, 0.2548]; xscore1_out = [-0.0401, -0.1764, -0.0340, 0.1669, 0.1041, ... -0.2067, 0.0457, 0.1565, 0.0706, -0.1471]; yscore1_out = [-12.4635, -15.0003, 0.0638, 0.0652, -0.0070, ... -0.0634, 0.0062, -0.0012, -0.0151, -0.0173]; assert_equal (xload(1,:), xload1_out, 1e-4); assert_equal (yload, yload_out, 1e-4); assert_equal (xscore(1,:), xscore1_out, 1e-4); assert_equal (yscore(1,:), yscore1_out, 1e-4); ***** test load spectra [xload, yload, xscore, yscore, coef, pctVar] = plsregress (NIR, octane, 5); xload1_out = [-0.0170, 0.0039, 0.0095, 0.0258, 0.0025]; yload_out = [6.6384, 9.3106, 2.0505, 0.6471, 0.9625]; xscore1_out = [-0.0401, -0.1764, -0.0340, 0.1669, 0.1041]; yscore1_out = [-12.4635, -15.0003, 0.0638, 0.0652, -0.0070]; assert_equal (xload(1,:), xload1_out, 1e-4); assert_equal (yload, yload_out, 1e-4); assert_equal (xscore(1,:), xscore1_out, 1e-4); assert_equal (yscore(1,:), yscore1_out, 1e-4); ***** error plsregress (1) ***** error plsregress (1, 'asd') ***** error plsregress (1, {1,2,3}) ***** error plsregress ('asd', 1) ***** error plsregress ({1,2,3}, 1) ***** error ... plsregress (ones (20,3), ones (15,1)) ***** error ... plsregress (ones (20,3), ones (20,1), 0) ***** error ... plsregress (ones (20,3), ones (20,1), -5) ***** error ... plsregress (ones (20,3), ones (20,1), 3.2) ***** error ... plsregress (ones (20,3), ones (20,1), [2, 3]) ***** error ... plsregress (ones (20,3), ones (20,1), 4) ***** error ... plsregress (ones (20,3), ones (20,1), 3, 'cv', 4.5) ***** error ... plsregress (ones (20,3), ones (20,1), 3, 'cv', -1) ***** error ... plsregress (ones (20,3), ones (20,1), 3, 'cv', 'somestring') ***** error ... plsregress (ones (20,3), ones (20,1), 3, 'cv', 3, 'mcreps', 2.2) ***** error ... plsregress (ones (20,3), ones (20,1), 3, 'cv', 3, 'mcreps', -2) ***** error ... plsregress (ones (20,3), ones (20,1), 3, 'cv', 3, 'mcreps', [1, 2]) ***** error ... plsregress (ones (20,3), ones (20,1), 3, 'Name', 3, 'mcreps', 1) ***** error ... plsregress (ones (20,3), ones (20,1), 3, 'cv', 3, 'Name', 1) ***** error ... plsregress (ones (20,3), ones (20,1), 3, 'mcreps', 2) ***** error ... plsregress (ones (20,3), ones (20,1), 3, 'cv', 'resubstitution', 'mcreps', 2) ***** test ## A single output returns the predictor loadings, as MATLAB allows; ## fewer than two outputs used to be refused outright. X = [1, 2, 3; 2, 3, 5; 3, 5, 8; 4, 7, 11; 5, 11, 16; 6, 13, 19]; Y = [1; 2; 3; 4; 5; 6]; xl = plsregress (X, Y, 2); [xl2, yl2] = plsregress (X, Y, 2); assert_equal (xl, xl2); assert_equal (size (xl), [3, 2]); 24 tests, 24 passed, 0 known failure, 0 skipped [inst/Regression/logistic_regression.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/logistic_regression.m ***** test # Output compared to following MATLAB commands # [B, DEV, STATS] = mnrfit(X,Y+1,'model','ordinal'); # P = mnrval(B,X) X = [1.489381332449196, 1.1534152241851305; ... 1.8110085304863965, 0.9449666896938425; ... -0.04453299665130296, 0.34278203449678646; ... -0.36616019468850347, 1.130254275908322; ... 0.15339143291005095, -0.7921044310668951; ... -1.6031878794469698, -1.8343471035233376; ... -0.14349521143198166, -0.6762996896828459; ... -0.4403818557740143, -0.7921044310668951; ... -0.7372685001160434, -0.027793137932169563; ... -0.11875465773681024, 0.5512305689880763]; Y = [1,1,1,1,1,0,0,0,0,0]'; [INTERCEPT, SLOPE, DEV, DL, D2L, P] = logistic_regression (Y, X, false); ***** test # Output compared to following MATLAB commands # [B, DEV, STATS] = mnrfit(X,Y+1,'model','ordinal'); load carbig X = [Acceleration Displacement Horsepower Weight]; miles = [1,1,1,1,1,1,1,1,1,1,NaN,NaN,NaN,NaN,NaN,1,1,NaN,1,1,2,2,1,2,2,2, ... 2,2,2,2,2,1,1,1,1,2,2,2,2,NaN,2,1,1,2,1,1,1,1,1,1,1,1,1,2,2,1,2, ... 2,3,3,3,3,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,2,2,2,2,2, ... 2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,1,1,1,1,2,2,2,1,2,2, ... 2,1,1,3,2,2,2,1,2,2,1,2,2,2,1,3,2,3,2,1,1,1,1,1,1,1,1,3,2,2,3,3, ... 2,2,2,2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,2,2,1,3,2,2,2,2,2,2,1,3,2,2, ... 2,2,2,3,2,2,2,2,2,1,1,1,1,2,2,2,2,3,2,3,3,2,1,1,1,3,3,2,2,2,1,2, ... 2,1,1,1,1,1,3,3,3,2,3,1,1,1,1,1,2,2,1,1,1,1,1,3,2,2,2,3,3,3,3,2, ... 2,2,4,3,3,4,3,2,2,2,2,2,2,2,2,2,2,2,1,1,2,1,1,1,3,2,2,3,2,2,2,2, ... 2,1,2,1,3,3,2,2,2,2,2,1,1,1,1,1,1,2,1,3,3,3,2,2,2,2,2,3,3,3,3,2, ... 2,2,3,4,3,3,3,2,2,2,2,3,3,3,3,3,4,2,4,4,4,3,3,4,4,3,3,3,2,3,2,3, ... 2,2,2,2,3,4,4,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,NaN,3,2,2,2,2,2,1,2, ... 2,3,3,3,2,2,2,3,3,3,3,3,3,3,3,3,3,3,2,3,2,2,3,3,2,2,4,3,2,3]'; [INTERCEPT, SLOPE, DEV, DL, D2L, P] = logistic_regression (miles, X, false); assert_equal (DEV, 433.197174495549, 1e-05); assert_equal (INTERCEPT(1), -16.6895155618903, 1e-05); assert_equal (INTERCEPT(2), -11.7207818178493, 1e-05); assert_equal (INTERCEPT(3), -8.0605768506075, 1e-05); assert_equal (SLOPE(1), 0.104762463756714, 1e-05); assert_equal (SLOPE(2), 0.0103357623191891, 1e-05); assert_equal (SLOPE(3), 0.0645199313242276, 1e-05); assert_equal (SLOPE(4), 0.00166377028388103, 1e-05); 2 tests, 2 passed, 0 known failure, 0 skipped [inst/Regression/nlparci.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/nlparci.m ***** demo ## 95% confidence intervals for the coefficients of an exponential fit. x = [1:10]'; y = [2.1;2.9;4.2;5.3;7.1;9.4;12.8;16.5;22.1;29.8]; modelfun = @(b, x) b(1) .* exp (b(2) .* x); [beta, R, J, CovB] = nlinfit (x, y, modelfun, [1; 0.3]); ci = nlparci (beta, R, 'covar', CovB) ***** shared beta, R, J, CovB x = [1;2;3;4;5;6;7;8;9;10]; y = [2.1;2.9;4.2;5.3;7.1;9.4;12.8;16.5;22.1;29.8]; modelfun = @(b, xx) b(1) .* exp (b(2) .* xx); [beta, R, J, CovB] = nlinfit (x, y, modelfun, [1; 0.3]); ***** test ci = nlparci (beta, R, "covar", CovB); assert_equal (ci, [1.602587442890197, 1.764906607002551; ... 0.281489871959626, 0.292332302448227], 1e-5); ***** test ## The Jacobian and covariance forms agree. ci1 = nlparci (beta, R, "covar", CovB); ci2 = nlparci (beta, R, "jacobian", J); assert_equal (ci1, ci2, 1e-8); ***** test ## The legacy positional Jacobian form matches the named form. ci = nlparci (beta, R, J); assert_equal (ci, nlparci (beta, R, "jacobian", J), 1e-12); ***** test ## A 90% interval is narrower than the default 95% interval. ci95 = nlparci (beta, R, "covar", CovB); ci90 = nlparci (beta, R, "covar", CovB, "alpha", 0.10); assert_equal (all (diff (ci90, 1, 2) < diff (ci95, 1, 2), 'all'), true); ***** error nlparci (1, 2) ***** error ... nlparci ([1;2], [1;2;3], "foo", 1) ***** error ... nlparci ([1;2], [1;2;3], "covar", eye (2), "alpha", 2) ***** error ... nlparci ([1;2], [1;2;3], "alpha", 0.05) ***** error nlparci ([1;2], 1, "covar", eye (2)) 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Regression/invpred.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/invpred.m ***** demo ## Estimate the predictor value at which a fitted line reaches a response ## of 20, with a 95% confidence interval either side of it. x = (1:10)'; y = 2 + 3 * x + [0.5; -0.3; 0.2; 0.8; -0.6; 0.1; -0.4; 0.7; -0.2; 0.3]; [x0, dxlo, dxup] = invpred (x, y, 20) interval = [x0 - dxlo, x0 + dxup] ***** test x = (1:10)'; y = 2 + 3 * x + [0.5; -0.3; 0.2; 0.8; -0.6; 0.1; -0.4; 0.7; -0.2; 0.3]; x0 = invpred (x, y, 20); assert_equal (x0, 5.964741641337386, 1e-12); ***** test x = (1:10)'; y = 2 + 3 * x + [0.5; -0.3; 0.2; 0.8; -0.6; 0.1; -0.4; 0.7; -0.2; 0.3]; [x0, dxlo, dxup] = invpred (x, y, 20); assert_equal (x0, 5.964741641337386, 1e-12); assert_equal (dxlo, 0.408566704275405, 1e-12); assert_equal (dxup, 0.410279499114103, 1e-12); ***** test x = (1:10)'; y = 2 + 3 * x + [0.5; -0.3; 0.2; 0.8; -0.6; 0.1; -0.4; 0.7; -0.2; 0.3]; [~, dxlo, dxup] = invpred (x, y, 20); assert_equal (dxlo != dxup, true); ***** test x = (1:10)'; y = 2 + 3 * x + [0.5; -0.3; 0.2; 0.8; -0.6; 0.1; -0.4; 0.7; -0.2; 0.3]; [x0, dxlo, dxup] = invpred (x, y, [10; 20; 30]); assert_equal (x0, [2.621276595744681; 5.964741641337386; ... 9.308206686930092], 1e-12); assert_equal (dxlo, [0.432537159571881; 0.408566704275405; ... 0.433439039304474], 1e-12); assert_equal (dxup, [0.421927689383959; 0.410279499114103; ... 0.447474099169791], 1e-12); [x0r, dxlor, dxupr] = invpred (x, y, [10, 20, 30]); assert_equal (x0r, x0'); assert_equal (dxlor, dxlo'); assert_equal (dxupr, dxup'); ***** test x = (1:10)'; y = 2 + 3 * x + [0.5; -0.3; 0.2; 0.8; -0.6; 0.1; -0.4; 0.7; -0.2; 0.3]; x0 = invpred (x, y, [10, 20; 30, 40]); assert_equal (size (x0), [2, 2]); assert_equal (x0, [2.621276595744681, 5.964741641337386; ... 9.308206686930092, 12.651671732522798], 1e-12); ***** test x = (1:10)'; y = 2 + 3 * x + [0.5; -0.3; 0.2; 0.8; -0.6; 0.1; -0.4; 0.7; -0.2; 0.3]; x0 = invpred (x, y, []); assert_equal (size (x0), [0, 0]); ***** test x = (1:10)'; y = 2 + 3 * x + [0.5; -0.3; 0.2; 0.8; -0.6; 0.1; -0.4; 0.7; -0.2; 0.3]; [x0, dxlo, dxup] = invpred (x, y, 20, 'alpha', 0.01); assert_equal (x0, 5.964741641337386, 1e-12); assert_equal (dxlo, 0.594536204654897, 1e-12); assert_equal (dxup, 0.598170042325828, 1e-12); ***** test x = (1:10)'; y = 2 + 3 * x + [0.5; -0.3; 0.2; 0.8; -0.6; 0.1; -0.4; 0.7; -0.2; 0.3]; [x0, dxlo, dxup] = invpred (x, y, 20, 'predopt', 'curve'); assert_equal (x0, 5.964741641337386, 1e-12); assert_equal (dxlo, 0.124048892442359, 1e-12); assert_equal (dxup, 0.125761687281057, 1e-12); [~, obslo, obsup] = invpred (x, y, 20, 'predopt', 'observation'); assert_equal (dxlo < obslo && dxup < obsup, true); ***** test [x0, dxlo, dxup] = invpred ((1:5)', [1; 5; 2; 8; 3], 4); assert_equal (x0, 3.285714285714286, 1e-12); assert_equal (dxlo, Inf); assert_equal (dxup, Inf); ***** test x = (1:10)'; y = 2 + 3 * x + [0.5; -0.3; 0.2; 0.8; -0.6; 0.1; -0.4; 0.7; -0.2; 0.3]; [x0, dxlo, dxup] = invpred (x', y', 20); assert_equal (x0, 5.964741641337386, 1e-12); assert_equal (dxlo, 0.408566704275405, 1e-12); assert_equal (dxup, 0.410279499114103, 1e-12); ***** test x = (1:10)'; y = 2 + 3 * x + [0.5; -0.3; 0.2; 0.8; -0.6; 0.1; -0.4; 0.7; -0.2; 0.3]; xn = x; xn(3) = NaN; assert_equal (invpred (xn, y, 20), 5.967084254482929, 1e-12); yn = y; yn(4) = NaN; assert_equal (invpred (x, yn, 20), 5.988352745424295, 1e-12); ***** test [x0, dxlo, dxup] = invpred ((1:5)', [1; 5; 2; 8; 3], 100); assert_equal (x0, 140.42857142857144, 1e-12); assert_equal (dxlo, 111.30773209684287, 1e-12); assert_equal (dxup, Inf); ***** test [x0, dxlo, dxup] = invpred ((1:5)', [1; 5; 2; 8; 3], [-100; 100]); assert_equal (x0, [-145.28571428571428; 140.42857142857144], 1e-12); assert_equal (dxlo, [Inf; 111.30773209684287], 1e-12); assert_equal (dxup, [120.07306008453997; Inf], 1e-12); ***** test [x0, dxlo, dxup] = invpred ((1:5)', [1; 5; 2; 8; 3], [100; 200]); assert_equal (x0, [140.42857142857144; 283.2857142857143], 1e-12); assert_equal (dxlo, [111.30773209684287; 226.72556884927243], 1e-12); assert_equal (dxup, [Inf; Inf], 1e-12); ***** error invpred ((1:10)', (1:10)') ***** error ... invpred (ones (10, 2), (1:10)', 5) ***** error ... invpred ((1:10)', ones (10, 2), 5) ***** error ... invpred ((1:10)', (1:5)', 5) ***** error ... invpred ((1:10)', (1:10)', 5, 'alpha', 5) ***** error ... invpred ((1:10)', (1:10)', 5, 'alpha', [0.05, 0.01]) ***** error ... invpred ((1:10)', (1:10)', 5, 'predopt', 'bogus') ***** error ... invpred ((1:10)', (1:10)', 5, 'badname', 1) ***** error ... invpred ((1:10)', (1:10)', 5, 'alpha') ***** error ... invpred (ones (10, 1), (1:10)', 5) 24 tests, 24 passed, 0 known failure, 0 skipped [inst/Regression/stepwiselm.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/stepwiselm.m ***** demo ## Stepwise search from a constant model, with a custom entry threshold. ## Twenty apartments are described by their size, floor number, and ## distance from the city center, along with their monthly rent. ## Starting from an empty model, `stepwiselm` adds one predictor at a ## time as long as it improves the fit by at least `PEnter`, then checks ## whether anything already in the model should come back out. Size = [45 50 38 62 70 55 48 40 65 58 42 72 35 68 52 60 46 66 39 54]'; Floor = [3 5 2 8 10 4 1 6 9 7 3 12 2 11 5 6 4 10 1 5]'; Distance = [12 8 15 5 3 9 18 10 4 7 14 2 20 3 8 6 11 4 17 9]'; Rent = 200 + 12*Size - 15*Distance + 2*Floor + 5*sin ((1:20)'/2); X = [Size, Floor, Distance]; ## Fit with a looser entry threshold, printing every candidate examined. mdl = stepwiselm (X, Rent, 'PEnter', 0.06, 'Verbose', 2) ***** demo ## Starting from a formula, with the response, predictors, and ## categorical variable all named explicitly. ## Eighteen coffee shops report their weekly ad spend, staff count, and ## sales season, along with weekly sales. The search starts already ## containing `AdSpend`, with `Employees` and the categorical `Season` ## left to consider adding. AdSpend = [200 350 500 220 370 520 240 390 540 260 410 560 280 430 580 300 450 600]'; Employees = [4 5 6 4 5 6 4 5 6 4 5 6 4 5 6 4 5 6]'; Season = {'Low';'Mid';'Peak';'Low';'Mid';'Peak';'Low';'Mid';'Peak'; ... 'Low';'Mid';'Peak';'Low';'Mid';'Peak';'Low';'Mid';'Peak'}; SeasonEffect = [0;150;400;0;150;400;0;150;400;0;150;400;0;150;400;0;150;400]; Sales = 1000 + 0.8*AdSpend + 5*Employees + SeasonEffect + 6*sin ((1:18)'); T = table (AdSpend, Employees, Season, Sales, ... 'VariableNames', {'AdSpend','Employees','Season','Sales'}); ## Fit, treating Season as categorical and naming the response explicitly. mdl = stepwiselm (T, 'Sales ~ 1 + AdSpend', 'ResponseVar', 'Sales', ... 'PredictorVars', {'AdSpend','Employees','Season'}, ... 'CategoricalVars', {'Season'}, 'Verbose', 1) ***** demo ## Bounding the search with terms matrices instead of model-name ## keywords. ## Twelve potted plants are given varying hours of sunlight and amounts ## of water, and their growth is measured. `T_initial` is a constant ## model and `T_upper` allows the two main effects plus their ## interaction, using the same terms-matrix convention as `fitlm`. Sunlight = [2 4 6 8 3 5 7 9 2.5 4.5 6.5 8.5]'; Water = [100 150 200 250 120 170 220 270 110 160 210 260]'; Growth = 5 + 0.3*Sunlight + 0.06*Water + 0.4*sin ((1:12)'); X = [Sunlight, Water]; T_initial = [0 0 0]; T_upper = [0 0 0; 1 0 0; 0 1 0; 1 1 0]; ## Fit, printing the p-value considered for every candidate term. mdl = stepwiselm (X, Growth, T_initial, 'Upper', T_upper, 'Verbose', 2) ***** demo ## A categorical predictor is added or removed as one indicator group, ## never one indicator column at a time. ## Eighteen plots receive varying fertilizer amounts across three ## regions, and crop yield is recorded. The upper bound `poly21` allows ## a constant, `Fertilizer`, `Fertilizer^2`, `Region`, and their ## interaction; `stepwiselm` treats the two indicator columns generated ## by the three-level `Region` as a single term throughout. Fertilizer = repmat ([10;20;30;40;50;60], 3, 1); Region = [repmat({'A'},6,1); repmat({'B'},6,1); repmat({'C'},6,1)]; RegionEffect = [zeros(6,1); 15*ones(6,1); 35*ones(6,1)]; Yield = 20 + 0.5*Fertilizer + RegionEffect + 1.5*sin ((1:18)'); T = table (Fertilizer, Region, Yield); ## Fit, printing every candidate considered at each step. mdl = stepwiselm (T, 'Yield ~ Fertilizer', 'Upper', 'poly21', 'Verbose', 2) ***** demo ## Capping the search with `NSteps` before it converges on its own. ## Twenty observations depend on three predictors, all with genuine ## effects. Left alone, `stepwiselm` would add all three; limiting ## `NSteps` to 1 stops the search after only the single best addition. x1 = (1:20)'; x2 = mod ((0:19)', 5); x3 = mod ((0:19)', 3); y = 5 + 2*x1 + 1.5*x2 + 3*x3 + 2*sin ((1:20)'/1.7); X = [x1, x2, x3]; ## Fit, but stop after the very first step. mdl = stepwiselm (X, y, 'Upper', 'linear', 'NSteps', 1, 'Verbose', 1) ***** demo ## Raw matrix input with default `x1, x2, ...` naming, and custom entry ## and removal thresholds. ## Fifteen observations depend mainly on `x1`. `PEnter` and `PRemove` ## are set explicitly rather than relying on the defaults for the SSE ## criterion. x1 = (1:15)'; x2 = mod ((0:14)', 4); y = 8 + 0.5*x1 + 0.3*x2 + 2.5*sin ((1:15)'/1.2); X = [x1, x2]; ## Fit with a wider entry threshold and a stricter removal threshold. mdl = stepwiselm (X, y, 'PEnter', 0.2, 'PRemove', 0.3, 'Verbose', 1) ***** demo ## The `hald` cement data, mirroring MATLAB's own reference example for ## `stepwiselm`. ## Four chemical percentages in cement (`ingredients`) are used to ## predict heat given off while hardening (`heat`). Starting from a ## constant model, `stepwiselm` adds three terms and then removes one ## of them again once it becomes redundant. load hald ## Fit with a looser entry threshold than the default. mdl = stepwiselm (ingredients, heat, 'PEnter', 0.06, 'Verbose', 1) ***** demo ## The `carsmall` data, mirroring MATLAB's own reference example for ## `stepwiselm` with a terms-matrix bound. ## Fuel economy (`MPG`) is predicted from acceleration and weight. ## `T_initial` is a constant model and `T_upper` allows both main ## effects plus their interaction. load carsmall X = [Acceleration, Weight]; T_initial = [0 0 0]; T_upper = [0 0 0; 1 0 0; 0 1 0; 1 1 0]; ## Fit, printing the p-value considered for every candidate term. mdl = stepwiselm (X, MPG, T_initial, 'Upper', T_upper, 'Verbose', 2) ***** shared x1, x2, x3, y, X, tbl n = 24; x1 = (1:n)'/n; x2 = sin((1:n)'/4); x3 = cos((1:n)'/5); y = 4 + 2*x1 - x2 + 0.5*x3 + 0.15*sin((1:n)'*0.8); X = [x1, x2, x3]; tbl = table (x1, x2, x3, y, 'VariableNames', {'x1','x2','x3','y'}); ***** test mdl = stepwiselm (tbl, 'Verbose', 0); assert_equal (mdl.NumObservations, 24); assert_equal (mdl.NumCoefficients, 4); assert_equal (mdl.NumVariables, 4); assert_equal (mdl.NumPredictors, 3); assert_equal (mdl.DFE, 20); assert_equal (mdl.SSE, 0.237882441508, 1e-9); assert_equal (mdl.SSR, 25.3955253054, 1e-7); assert_equal (mdl.SST, 25.6334077469, 1e-7); assert_equal (mdl.MSE, 0.0118941220754, 1e-10); assert_equal (mdl.RMSE, 0.109060176395, 1e-9); assert_equal (mdl.Rsquared.Ordinary, 0.990719827662, 1e-9); assert_equal (mdl.Rsquared.Adjusted, 0.989327801811, 1e-9); assert_equal (mdl.LogLikelihood, 21.3138652143, 1e-6); assert_equal (mdl.ModelCriterion.AIC, -34.6277304285, 1e-6); assert_equal (mdl.ModelCriterion.AICc, -32.5224672707, 1e-6); assert_equal (mdl.ModelCriterion.BIC, -29.9155151072, 1e-6); assert_equal (mdl.ModelCriterion.CAIC, -25.9155151072, 1e-6); assert_equal (mdl.ModelFitVsNullModel.Fstat, 711.710796991, 1e-5); assert_equal (mdl.ModelFitVsNullModel.NullModel, 'constant'); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x3'}); assert_equal (mdl.Coefficients.Estimate, ... [4.11199897343; 1.79245385284; -1.06961941012; 0.51029628797], 1e-9); assert_equal (mdl.Coefficients.SE, ... [0.0761375845531; 0.144191944451; 0.0575954799856; 0.0489829266327], 1e-9); assert_equal (mdl.Coefficients.tStat, ... [54.007478666; 12.4310262939; -18.5712387566; 10.4178399097], 1e-6); assert_equal (mdl.Coefficients.pValue, ... [3.79220676881e-23; 7.26932473407e-11; 4.42354835071e-14; 1.58256682968e-09], 1e-9); assert_equal (mdl.ResponseName, 'y'); assert_equal (mdl.PredictorNames, {'x1';'x2';'x3'}); assert_equal (mdl.VariableNames, {'x1';'x2';'x3';'y'}); assert_equal (mdl.Formula.HasIntercept, true); assert_equal (mdl.Formula.LinearPredictor, '1 + x1 + x2 + x3'); assert_equal (mdl.Formula.NTerms, 4); ***** test mdl = stepwiselm (tbl, 'y', 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x3'}); assert_equal (mdl.SSE, 0.237882441508, 1e-9); assert_equal (mdl.ResponseName, 'y'); assert_equal (mdl.PredictorNames, {'x1';'x2';'x3'}); ***** test tt = table (x1, x2, x3, 'VariableNames', {'x1','x2','x3'}); mdl = stepwiselm (tt, y, 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x3'}); assert_equal (mdl.SSE, 0.237882441508, 1e-9); assert_equal (mdl.ResponseName, 'y'); assert_equal (mdl.VariableNames, {'x1';'x2';'x3';'y'}); ***** test mdl = stepwiselm (X, y, 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x3'}); assert_equal (mdl.Coefficients.Estimate, ... [4.11199897343; 1.79245385284; -1.06961941012; 0.51029628797], 1e-9); assert_equal (mdl.ResponseName, 'y'); assert_equal (mdl.VariableNames, {'x1';'x2';'x3';'y'}); ***** test mdl = stepwiselm (tbl, 'y ~ x1', 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x3'}); assert_equal (mdl.SSE, 0.237882441508, 1e-9); assert_equal (mdl.Formula.LinearPredictor, '1 + x1 + x2 + x3'); ***** test mdl = stepwiselm (X, y, 'constant', 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x3'}); assert_equal (mdl.SSE, 0.237882441508, 1e-9); ***** test mdl = stepwiselm (X, y, 'linear', 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x3'}); assert_equal (mdl.SSE, 0.237882441508, 1e-9); ***** test mdl = stepwiselm (X, y, 'constant', 'Upper', 'purequadratic', 'Verbose', 0); assert_equal (mdl.NumObservations, 24); assert_equal (mdl.NumCoefficients, 4); assert_equal (mdl.NumVariables, 4); assert_equal (mdl.NumPredictors, 2); assert_equal (mdl.DFE, 20); assert_equal (mdl.SSE, 0.22345826866, 1e-9); assert_equal (mdl.SSR, 25.4099494782, 1e-7); assert_equal (mdl.SST, 25.6334077469, 1e-7); assert_equal (mdl.MSE, 0.011172913433, 1e-10); assert_equal (mdl.RMSE, 0.105702002975, 1e-9); assert_equal (mdl.Rsquared.Ordinary, 0.991282537583, 1e-9); assert_equal (mdl.Rsquared.Adjusted, 0.98997491822, 1e-9); assert_equal (mdl.LogLikelihood, 22.0644883645, 1e-6); assert_equal (mdl.ModelCriterion.AIC, -36.1289767289, 1e-6); assert_equal (mdl.ModelCriterion.AICc, -34.023713571, 1e-6); assert_equal (mdl.ModelCriterion.BIC, -31.4167614075, 1e-6); assert_equal (mdl.ModelCriterion.CAIC, -27.4167614075, 1e-6); assert_equal (mdl.ModelFitVsNullModel.Fstat, 758.081874544, 1e-5); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x1^2'}); assert_equal (mdl.Coefficients.Estimate, ... [4.79002491626; -1.87038904608; -0.881529179216; 3.14370698956], 1e-9); assert_equal (mdl.Coefficients.SE, ... [0.0903999262734; 0.328540613357; 0.0534940080998; 0.290849609965], 1e-9); assert_equal (mdl.Coefficients.tStat, ... [52.9870445002; -5.6930223237; -16.4790265402; 10.8087027861], 1e-6); assert_equal (mdl.Coefficients.pValue, ... [5.53960001242e-23; 1.4288675776e-05; 4.19790256549e-13; 8.42439951369e-10], 1e-9); assert_equal (mdl.PredictorNames, {'x1';'x2'}); assert_equal (mdl.Formula.LinearPredictor, '1 + x1 + x2 + x1^2'); ***** test mdl = stepwiselm (X, y, 'constant', 'Upper', 'quadratic', 'Verbose', 0); assert_equal (mdl.NumPredictors, 2); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x1^2'}); assert_equal (mdl.SSE, 0.22345826866, 1e-9); assert_equal (mdl.PredictorNames, {'x1';'x2'}); ***** test T0 = [0 0 0]; T1 = [0 0 0; 1 0 0; 0 1 0; 1 1 0]; mdl = stepwiselm (X(:,1:2), y, T0, 'Upper', T1, 'Verbose', 0); assert_equal (mdl.NumObservations, 24); assert_equal (mdl.NumCoefficients, 4); assert_equal (mdl.NumVariables, 3); assert_equal (mdl.NumPredictors, 2); assert_equal (mdl.DFE, 20); assert_equal (mdl.SSE, 1.11546087527, 1e-8); assert_equal (mdl.SSR, 24.5179468716, 1e-7); assert_equal (mdl.SST, 25.6334077469, 1e-7); assert_equal (mdl.MSE, 0.0557730437634, 1e-10); assert_equal (mdl.RMSE, 0.236163171903, 1e-9); assert_equal (mdl.Rsquared.Ordinary, 0.956484097383, 1e-9); assert_equal (mdl.Rsquared.Adjusted, 0.94995671199, 1e-9); assert_equal (mdl.LogLikelihood, 2.77090924057, 1e-6); assert_equal (mdl.ModelCriterion.AIC, 2.45818151886, 1e-6); assert_equal (mdl.ModelCriterion.AICc, 4.56344467675, 1e-6); assert_equal (mdl.ModelCriterion.BIC, 7.17039684025, 1e-6); assert_equal (mdl.ModelCriterion.CAIC, 11.1703968402, 1e-6); assert_equal (mdl.ModelFitVsNullModel.Fstat, 146.534031599, 1e-5); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x1:x2'}); assert_equal (mdl.Coefficients.Estimate, ... [4.00100246651; 1.35895695997; -0.23206474908; -1.2780495686], 1e-9); assert_equal (mdl.Coefficients.SE, ... [0.181530230599; 0.299744817513; 0.272053305331; 0.469486828642], 1e-9); assert_equal (mdl.Coefficients.tStat, ... [22.0404196772; 4.53371294703; -0.853012055108; -2.72222667524], 1e-6); assert_equal (mdl.Coefficients.pValue, ... [1.67738549624e-15; 0.000202251230338; 0.403753045528; 0.0131231039551], 1e-9); assert_equal (mdl.PredictorNames, {'x1';'x2'}); assert_equal (mdl.VariableNames, {'x1';'x2';'y'}); ***** test mdl = stepwiselm (X, y, 'Criterion', 'aic', 'Upper', 'interactions', 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x3'}); assert_equal (mdl.ModelCriterion.AIC, -34.6277304285, 1e-6); ***** test mdl = stepwiselm (X, y, 'Criterion', 'bic', 'Upper', 'interactions', 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x3'}); assert_equal (mdl.ModelCriterion.BIC, -29.9155151072, 1e-6); ***** test mdl = stepwiselm (X, y, 'Criterion', 'rsquared', 'Upper', 'interactions', 'Verbose', 0); assert_equal (mdl.NumCoefficients, 2); assert_equal (mdl.NumPredictors, 1); assert_equal (mdl.DFE, 22); assert_equal (mdl.SSE, 2.69619594281, 1e-8); assert_equal (mdl.Rsquared.Ordinary, 0.894817108617, 1e-9); assert_equal (mdl.CoefficientNames, {'(Intercept)','x2'}); assert_equal (mdl.Coefficients.Estimate, [4.93053729606; -1.35113880263], 1e-9); assert_equal (mdl.Coefficients.SE, [0.0714593428648; 0.0987629466731], 1e-9); assert_equal (mdl.Coefficients.tStat, [68.9977978861; -13.6806246486], 1e-6); assert_equal (mdl.Coefficients.pValue, [3.2882259984e-27; 3.08475274476e-12], 1e-9); assert_equal (mdl.PredictorNames, {'x2'}); ***** test mdl = stepwiselm (X, y, 'Criterion', 'adjrsquared', 'Upper', 'interactions', 'Verbose', 0); assert_equal (mdl.NumCoefficients, 5); assert_equal (mdl.DFE, 19); assert_equal (mdl.SSE, 0.224234467489, 1e-9); assert_equal (mdl.Rsquared.Adjusted, 0.989410626691, 1e-9); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x3','x1:x3'}); assert_equal (mdl.Coefficients.Estimate, ... [4.58266504435; 1.22125846816; -1.38808827902; 0.143991325796; 1.04450806346], 1e-8); assert_equal (mdl.Coefficients.SE, ... [0.444198853188; 0.55023668447; 0.301652972275; 0.344106973415; 0.971297090441], 1e-8); assert_equal (mdl.Coefficients.tStat, ... [10.3166971537; 2.21951480632; -4.6016065035; 0.418449310593; 1.07537443872], 1e-6); assert_equal (mdl.Coefficients.pValue, ... [3.1776147586e-09; 0.0388206335538; 0.000194754077847; 0.680310511095; 0.295673895373], 1e-8); assert_equal (mdl.PredictorNames, {'x1';'x2';'x3'}); ***** test p1 = (1:24)'/24; p2 = sin ((1:24)'/3.5); pr = 3 + 0.9*p1 - 0.2*p2 + 0.1*sin ((1:24)'*1.1); mdl = stepwiselm (p1, pr, 'Verbose', 0); assert_equal (mdl.NumObservations, 24); assert_equal (mdl.NumCoefficients, 2); assert_equal (mdl.DFE, 22); assert_equal (mdl.SSE, 0.422994127869, 1e-9); assert_equal (mdl.SSR, 2.71741844039, 1e-8); assert_equal (mdl.SST, 3.14041256826, 1e-8); assert_equal (mdl.Rsquared.Ordinary, 0.865306191886, 1e-9); assert_equal (mdl.Rsquared.Adjusted, 0.859183746062, 1e-9); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1'}); assert_equal (mdl.Coefficients.Estimate, [2.85858604186; 1.16664998725], 1e-9); assert_equal (mdl.Coefficients.SE, [0.0584250816201; 0.0981336947312], 1e-9); assert_equal (mdl.Coefficients.tStat, [48.9273778074; 11.8883732081], 1e-6); assert_equal (mdl.Coefficients.pValue, [6.03142199019e-24; 4.75617587395e-11], 1e-9); ***** test p1 = (1:24)'/24; p2 = sin ((1:24)'/3.5); pr = 3 + 0.9*p1 - 0.2*p2 + 0.1*sin ((1:24)'*1.1); mdl = stepwiselm (p1, pr, 'PEnter', 0.5, 'PRemove', 0.6, 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1'}); assert_equal (mdl.SSE, 0.422994127869, 1e-9); ***** test mdl = stepwiselm (X, y, 'Upper', 'interactions', 'NSteps', 1, 'Verbose', 0); assert_equal (mdl.NumCoefficients, 2); assert_equal (mdl.DFE, 22); assert_equal (mdl.SSE, 2.69619594281, 1e-8); assert_equal (mdl.CoefficientNames, {'(Intercept)','x2'}); assert_equal (mdl.Coefficients.Estimate, [4.93053729606; -1.35113880263], 1e-9); assert_equal (mdl.PredictorNames, {'x2'}); ***** test mdl = stepwiselm (X, y, 'NSteps', 0, 'Verbose', 0); assert_equal (mdl.NumCoefficients, 1); assert_equal (mdl.NumPredictors, 0); assert_equal (mdl.DFE, 23); assert_equal (mdl.SSE, 25.6334077469, 1e-7); assert_equal (mdl.SSR, 0, 1e-12); assert_equal (mdl.Rsquared.Ordinary, 0, 1e-12); assert_equal (isnan (mdl.ModelFitVsNullModel.Fstat), true); assert_equal (isnan (mdl.ModelFitVsNullModel.NullModel), true); assert_equal (mdl.CoefficientNames, {'(Intercept)'}); assert_equal (mdl.Coefficients.Estimate, 4.92948000444, 1e-9); assert_equal (mdl.Coefficients.SE, 0.215493231622, 1e-9); assert_equal (mdl.Coefficients.tStat, 22.8753356537, 1e-6); assert_equal (mdl.Coefficients.pValue, 2.53817914154e-17, 1e-9); assert_equal (isempty (mdl.PredictorNames), true); assert_equal (mdl.Formula.LinearPredictor, '1'); ***** test w = 1400 + (1:45)'*9; g = {'A','B','C'}(mod ((0:44), 3) + 1)'; m = 55 - 0.005*w + [0 5 -3](mod ((0:44), 3) + 1)' + 0.3*sin ((1:45)'/6); t = table (w, g, m, 'VariableNames', {'Weight','Group','MPG'}); mdl = stepwiselm (t, 'MPG ~ Weight', 'CategoricalVars', {'Group'}, 'Upper', 'interactions', 'Verbose', 0); assert_equal (mdl.NumObservations, 45); assert_equal (mdl.NumCoefficients, 4); assert_equal (mdl.NumVariables, 3); assert_equal (mdl.NumPredictors, 2); assert_equal (mdl.DFE, 41); assert_equal (mdl.SSE, 1.7056787721, 1e-8); assert_equal (mdl.SSR, 512.932602391, 1e-6); assert_equal (mdl.SST, 514.638281163, 1e-6); assert_equal (mdl.MSE, 0.0416019212713, 1e-10); assert_equal (mdl.RMSE, 0.203965490393, 1e-9); assert_equal (mdl.Rsquared.Ordinary, 0.996685674513, 1e-9); assert_equal (mdl.Rsquared.Adjusted, 0.996443162891, 1e-9); assert_equal (mdl.LogLikelihood, 9.78350141322, 1e-6); assert_equal (mdl.ModelCriterion.AIC, -11.5670028264, 1e-6); assert_equal (mdl.ModelCriterion.AICc, -10.5670028264, 1e-6); assert_equal (mdl.ModelCriterion.BIC, -4.34035286736, 1e-6); assert_equal (mdl.ModelCriterion.CAIC, -0.340352867356, 1e-6); assert_equal (mdl.ModelFitVsNullModel.Fstat, 4109.84706734, 1e-4); assert_equal (mdl.CoefficientNames, {'(Intercept)','Weight','Group_B','Group_C'}); assert_equal (mdl.Coefficients.Estimate, ... [56.0078644136; -0.00561620967245; 5.01185752618; -2.97710174861], 1e-8); assert_equal (mdl.Coefficients.SE, ... [0.41983060818; 0.000260647333731; 0.074514600823; 0.0746252935319], 1e-8); assert_equal (mdl.Coefficients.tStat, ... [133.40586256; -21.5471594973; 67.2600734732; -39.8940038652], 1e-5); assert_equal (mdl.Coefficients.pValue, ... [1.00643907454e-55; 5.62403610622e-24; 1.37550401987e-43; 1.97956717929e-34], 1e-8); assert_equal (mdl.ResponseName, 'MPG'); assert_equal (mdl.PredictorNames, {'Weight';'Group'}); assert_equal (mdl.Formula.LinearPredictor, '1 + Weight + Group'); ***** test w = 1400 + (1:45)'*9; code = mod ((0:44), 3)' + 1; m = 55 - 0.005*w + [0 5 -3](mod ((0:44), 3) + 1)' + 0.3*sin ((1:45)'/6); mdl = stepwiselm ([w, code], m, 'CategoricalVars', 2, 'Upper', 'interactions', 'Verbose', 0); assert_equal (mdl.NumPredictors, 2); assert_equal (mdl.DFE, 41); assert_equal (mdl.SSE, 1.7056787721, 1e-8); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2_2','x2_3'}); assert_equal (mdl.Coefficients.Estimate, ... [56.007864413564; -0.00561620967245463; 5.01185752617851; -2.97710174860745], 1e-8); assert_equal (mdl.PredictorNames, {'x1';'x2'}); ***** test ex = false (24, 1); ex([2 9 15]) = true; mdl = stepwiselm (X, y, 'Upper', 'interactions', 'Exclude', ex, 'Verbose', 0); assert_equal (mdl.NumObservations, 21); assert_equal (mdl.DFE, 17); assert_equal (mdl.SSE, 0.198175777, 1e-9); assert_equal (mdl.SSR, 23.9528827198, 1e-7); assert_equal (mdl.SST, 24.1510584968, 1e-7); assert_equal (mdl.Rsquared.Ordinary, 0.991794323341, 1e-9); assert_equal (mdl.Rsquared.Adjusted, 0.990346262754, 1e-9); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x3'}); assert_equal (mdl.Coefficients.Estimate, ... [4.10558649487; 1.78751811424; -1.08307909721; 0.499781080674], 1e-9); assert_equal (mdl.Coefficients.SE, ... [0.0832423204478; 0.15196995208; 0.0630609308312; 0.0532045604032], 1e-9); assert_equal (mdl.Coefficients.tStat, ... [49.320903992; 11.762312811; -17.1751206798; 9.39357598083], 1e-6); assert_equal (mdl.Coefficients.pValue, ... [8.57561115348e-20; 1.36568780583e-09; 3.54709582656e-12; 3.84225548219e-08], 1e-9); assert_equal (mdl.PredictorNames, {'x1';'x2';'x3'}); ***** test mdl = stepwiselm (X, y, 'Upper', 'interactions', 'Exclude', [2 9 15], 'Verbose', 0); assert_equal (mdl.NumObservations, 21); assert_equal (mdl.SSE, 0.198175777, 1e-9); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x3'}); ***** test wt = 0.6 + mod ((1:24)', 4)*0.25; mdl = stepwiselm (X, y, 'Upper', 'interactions', 'Weights', wt, 'Verbose', 0); assert_equal (mdl.NumObservations, 24); assert_equal (mdl.DFE, 20); assert_equal (mdl.SSE, 0.238797389485, 1e-9); assert_equal (mdl.SSR, 24.6325434536, 1e-7); assert_equal (mdl.SST, 24.8713408431, 1e-7); assert_equal (mdl.Rsquared.Ordinary, 0.990398692576, 1e-9); assert_equal (mdl.Rsquared.Adjusted, 0.988958496462, 1e-9); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x3'}); assert_equal (mdl.Coefficients.Estimate, ... [4.13717568894; 1.74127146188; -1.08433885985; 0.50630139226], 1e-9); assert_equal (mdl.Coefficients.SE, ... [0.0789083883313; 0.150888905488; 0.0591696809619; 0.0500332545132], 1e-9); assert_equal (mdl.Coefficients.tStat, ... [52.4301126462; 11.5400894204; -18.3259203401; 10.1192975989], 1e-6); assert_equal (mdl.Coefficients.pValue, ... [6.83329714397e-23; 2.70346109195e-10; 5.69051367149e-14; 2.59082042824e-09], 1e-9); ***** test mdl = stepwiselm (X, y, 'constant', 'Intercept', false, 'Upper', 'linear', 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x3'}); assert_equal (mdl.SSE, 0.237882441508, 1e-9); assert_equal (mdl.Formula.HasIntercept, true); ***** test mdl = stepwiselm (tbl, 'ResponseVar', 'y', 'PredictorVars', {'x1','x2'}, 'Verbose', 0); assert_equal (mdl.NumPredictors, 2); assert_equal (mdl.SSE, 1.11546087527, 1e-8); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x1:x2'}); assert_equal (mdl.PredictorNames, {'x1';'x2'}); ***** test mdl = stepwiselm (tbl, 'ResponseVar', 'y', 'PredictorVars', [1 2], 'Verbose', 0); assert_equal (mdl.NumPredictors, 2); assert_equal (mdl.SSE, 1.11546087527, 1e-8); assert_equal (mdl.PredictorNames, {'x1';'x2'}); ***** test mdl = stepwiselm (tbl, 'ResponseVar', 'y', 'Upper', 'interactions', 'Verbose', 0); assert_equal (mdl.NumPredictors, 3); assert_equal (mdl.SSE, 0.237882441508, 1e-9); assert_equal (mdl.ResponseName, 'y'); ***** test mdl = stepwiselm (X, y, 'VarNames', {'Alpha','Beta','Gamma','Score'}, 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)','Alpha','Beta','Gamma'}); assert_equal (mdl.Coefficients.Estimate, ... [4.11199897343; 1.79245385284; -1.06961941012; 0.51029628797], 1e-9); assert_equal (mdl.ResponseName, 'Score'); assert_equal (mdl.PredictorNames, {'Alpha';'Beta';'Gamma'}); assert_equal (mdl.VariableNames, {'Alpha';'Beta';'Gamma';'Score'}); assert_equal (mdl.Formula.LinearPredictor, '1 + Alpha + Beta + Gamma'); ***** test mdl = stepwiselm (tbl, 'y ~ x1 + x2', 'Lower', 'y ~ x2', 'Upper', 'y ~ x1+x2+x3', 'PRemove', 0.99, 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x3'}); assert_equal (mdl.Coefficients.Estimate, ... [4.11199897343; 1.79245385284; -1.06961941012; 0.51029628797], 1e-9); ***** test xu = (1:50)'/50; idx = mod ((1:50), 2); gu = {'Hi','Lo'}(idx + 1)'; sl = [7 1](idx + 1)'; yu = 2 + sl.*xu + 0.15*sin ((1:50)'/3); t = table (xu, gu, yu, 'VariableNames', {'X','G','Y'}); mdl = stepwiselm (t, 'Y ~ X + G', 'Upper', 'quadratic', 'Verbose', 0); assert_equal (mdl.NumObservations, 50); assert_equal (mdl.NumCoefficients, 4); assert_equal (mdl.NumVariables, 3); assert_equal (mdl.NumPredictors, 2); assert_equal (mdl.DFE, 46); assert_equal (mdl.SSE, 0.540477312442, 1e-9); assert_equal (mdl.SSR, 225.563187153, 1e-6); assert_equal (mdl.SST, 226.103664466, 1e-6); assert_equal (mdl.Rsquared.Ordinary, 0.997609603923, 1e-9); assert_equal (mdl.Rsquared.Adjusted, 0.997453708527, 1e-9); assert_equal (mdl.CoefficientNames, {'(Intercept)','X','G_Hi','X:G_Hi'}); assert_equal (mdl.Coefficients.Estimate, ... [2.02876253697; 0.971349141035; 0.0058812055616; 5.98354193726], 1e-8); assert_equal (mdl.Coefficients.SE, ... [0.0433841054684; 0.0751585081172; 0.0622864091272; 0.106290181507], 1e-8); assert_equal (mdl.Coefficients.tStat, ... [46.7628066792; 12.9240077453; 0.0944219717272; 56.2943994677], 1e-5); assert_equal (mdl.Coefficients.pValue, ... [1.96152617542e-40; 6.42479379426e-17; 0.92518406634; 4.45945899483e-44], 1e-8); assert_equal (mdl.PredictorNames, {'X';'G'}); ***** test idx3 = mod ((1:48), 3); idx2 = mod ((1:48), 2); g1 = {'A','B','C'}(idx3 + 1)'; g2 = {'P','Q'}(idx2 + 1)'; base = [0 4 -3](idx3 + 1)'; qeff = [5 0](idx2 + 1)'; cross = 6*((idx3 == 1) & (idx2 == 0))'; y2 = 10 + base + qeff + cross + 0.2*sin ((1:48)'/4); t = table (g1, g2, y2, 'VariableNames', {'G1','G2','Y'}); mdl = stepwiselm (t, 'Y ~ G1 + G2', 'Upper', 'interactions', 'Verbose', 0); assert_equal (mdl.NumObservations, 48); assert_equal (mdl.NumCoefficients, 6); assert_equal (mdl.NumPredictors, 2); assert_equal (mdl.DFE, 42); assert_equal (mdl.SSE, 1.00031269326, 1e-8); assert_equal (mdl.SSR, 1526.57402706, 1e-6); assert_equal (mdl.SST, 1527.57433975, 1e-6); assert_equal (mdl.Rsquared.Ordinary, 0.999345162676, 1e-9); assert_equal (mdl.Rsquared.Adjusted, 0.999267205851, 1e-9); assert_equal (mdl.CoefficientNames, ... {'(Intercept)','G1_C','G1_A','G2_P','G1_C:G2_P','G1_A:G2_P'}); assert_equal (mdl.Coefficients.Estimate, ... [14.0072303291; -7.00943486401; -4.00436689813; 10.9931096893; -5.98569634506; -6.00058514115], 1e-8); assert_equal (mdl.Coefficients.SE, ... [0.0545630013001; 0.0771637364424; 0.0771637364424; 0.0771637364424; 0.1091260026; 0.1091260026], 1e-8); assert_equal (mdl.Coefficients.tStat, ... [256.716639395; -90.8384584155; -51.8944141736; 142.464714594; -54.8512380408; -54.9876747811], 1e-5); assert_equal (mdl.Coefficients.pValue, ... [9.40196273084e-69; 7.64513283056e-50; 1.00685653504e-39; 5.03307771166e-58; 1.01525097736e-40; 9.15939827666e-41], 1e-8); assert_equal (mdl.PredictorNames, {'G1';'G2'}); ***** test idxb = mod ((1:48), 2); ga = {'M','F'}(idxb + 1)'; gb = ga; y3 = 50 - 10*strcmp (ga, 'F') + 0.3*sin ((1:48)'/5); t = table (ga, gb, y3, 'VariableNames', {'GA','GB','Y'}); mdl = stepwiselm (t, 'Y ~ 1 + GB', 'ResponseVar', 'Y', ... 'PredictorVars', {'GA','GB'}, 'CategoricalVars', {'GA','GB'}, 'Verbose', 0); assert_equal (mdl.NumObservations, 48); assert_equal (mdl.NumCoefficients, 2); assert_equal (mdl.NumPredictors, 1); assert_equal (mdl.DFE, 46); assert_equal (mdl.SSE, 1.94300386071, 1e-8); assert_equal (mdl.SSR, 1199.4398757, 1e-6); assert_equal (mdl.SST, 1201.38287956, 1e-6); assert_equal (mdl.Rsquared.Ordinary, 0.998382693899, 1e-9); assert_equal (mdl.Rsquared.Adjusted, 0.998347535071, 1e-9); assert_equal (mdl.CoefficientNames, {'(Intercept)','GB_M'}); assert_equal (mdl.Coefficients.Estimate, [40.0624369099; 9.99766587633], 1e-8); assert_equal (mdl.Coefficients.SE, [0.041951963781; 0.0593290361473], 1e-8); assert_equal (mdl.Coefficients.tStat, [954.959751562; 168.512191088], 1e-5); assert_equal (mdl.Coefficients.pValue, [1.70539389023e-100; 7.42606982902e-66], 1e-8); assert_equal (mdl.PredictorNames, {'GB'}); assert_equal (mdl.Formula.LinearPredictor, '1 + GB'); ***** test e1 = (1:30)'/30; e2 = sin ((1:30)'/5); e3 = e1 + e2; ye = 3 + 1.5*e1 - e2 + 0.3*sin ((1:30)'/4); mdl = stepwiselm ([e1,e2,e3], ye, 'linear', 'Upper', 'linear', 'Verbose', 0); assert_equal (mdl.NumObservations, 30); assert_equal (mdl.NumCoefficients, 3); assert_equal (mdl.NumPredictors, 2); assert_equal (mdl.DFE, 27); assert_equal (mdl.SSE, 0.736469147619, 1e-9); assert_equal (mdl.SSR, 30.2842015322, 1e-7); assert_equal (mdl.SST, 31.0206706798, 1e-7); assert_equal (mdl.Rsquared.Ordinary, 0.976258761288, 1e-9); assert_equal (mdl.Rsquared.Adjusted, 0.974500151013, 1e-9); assert_equal (mdl.CoefficientNames, {'(Intercept)','x2','x3'}); assert_equal (mdl.Coefficients.Estimate, [2.83853512391; -2.5770987124; 1.87079571697], 1e-8); assert_equal (mdl.Coefficients.SE, [0.101176877319; 0.131763778382; 0.186693438852], 1e-8); assert_equal (mdl.Coefficients.tStat, [28.0551762332; -19.5584761158; 10.0206827218], 1e-6); assert_equal (mdl.Coefficients.pValue, [1.65333811724e-21; 1.79264031168e-17; 1.35825364979e-10], 1e-9); assert_equal (mdl.PredictorNames, {'x2';'x3'}); ***** test h1 = [7;1;11;11;7;11;3;1;2;21;1;11;10]; h2 = [26;29;56;31;52;55;71;31;54;47;40;66;68]; h3 = [6;15;8;8;6;9;17;22;18;4;23;9;8]; h4 = [60;52;20;47;33;22;6;44;22;26;34;12;12]; yh = [78.5;74.3;104.3;87.6;95.9;109.2;102.7;72.5;93.1;115.9;83.8;113.3;109.4]; mdl = stepwiselm ([h1,h2,h3,h4], yh, 'PEnter', 0.06, 'Verbose', 0); assert_equal (mdl.NumObservations, 13); assert_equal (mdl.NumCoefficients, 3); assert_equal (mdl.NumPredictors, 2); assert_equal (mdl.DFE, 10); assert_equal (mdl.SSE, 57.9044831761, 1e-8); assert_equal (mdl.SSR, 2657.85859375, 1e-5); assert_equal (mdl.SST, 2715.76307692, 1e-5); assert_equal (mdl.Rsquared.Ordinary, 0.978678374536, 1e-9); assert_equal (mdl.Rsquared.Adjusted, 0.974414049443, 1e-9); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2'}); assert_equal (mdl.Coefficients.Estimate, [52.5773488821; 1.46830574222; 0.662250491275], 1e-8); assert_equal (mdl.Coefficients.SE, [2.2861743345; 0.121300923606; 0.0458547214685], 1e-8); assert_equal (mdl.Coefficients.tStat, [22.9979613053; 12.1046542645; 14.4423620963], 1e-6); assert_equal (mdl.Coefficients.pValue, [5.45657090149e-10; 2.69221217969e-07; 5.02896031564e-08], 1e-9); assert_equal (mdl.PredictorNames, {'x1';'x2'}); assert_equal (mdl.VariableNames, {'x1';'x2';'x3';'x4';'y'}); assert_equal (mdl.Formula.LinearPredictor, '1 + x1 + x2'); ***** test w = 1400 + (1:45)'*9; g = {'A','B','C'}(mod ((0:44), 3) + 1)'; m = 55 - 0.005*w + [0 5 -3](mod ((0:44), 3) + 1)' + 0.3*sin ((1:45)'/6); t = table (w, g, m, 'VariableNames', {'Weight','Group','MPG'}); mdl0 = fitlm (t, 'MPG ~ Weight'); mdl = step (mdl0, 'Verbose', 0); assert_equal (mdl.CoefficientNames, {'(Intercept)','Weight','Group_B','Group_C'}); assert_equal (mdl.SSE, 1.7056787721, 1e-8); assert_equal (mdl.Coefficients.Estimate, ... [56.0078644136; -0.00561620967245; 5.01185752618; -2.97710174861], 1e-8); ***** test w = 1400 + (1:45)'*9; g = {'A','B','C'}(mod ((0:44), 3) + 1)'; m = 55 - 0.005*w + [0 5 -3](mod ((0:44), 3) + 1)' + 0.3*sin ((1:45)'/6); t = table (w, g, m, 'VariableNames', {'Weight','Group','MPG'}); mdl0 = fitlm (t, 'MPG ~ Weight'); mdl = step (mdl0, 'Upper', 'quadratic', 'NSteps', 5, 'Verbose', 0); assert_equal (mdl.NumCoefficients, 5); assert_equal (mdl.DFE, 40); assert_equal (mdl.SSE, 0.987020309951, 1e-8); assert_equal (mdl.Rsquared.Ordinary, 0.998082108646, 1e-9); assert_equal (mdl.CoefficientNames, {'(Intercept)','Weight','Group_B','Group_C','Weight^2'}); assert_equal (mdl.Coefficients.Estimate, ... [82.5932822956; -0.0388795480431; 5.01269583682; -2.97710174861; 1.03495141166e-05], 1e-6); ***** test w = 1400 + (1:45)'*9; code = mod ((0:44), 3)' + 1; m = 55 - 0.005*w + [0 5 -3](mod ((0:44), 3) + 1)' + 0.3*sin ((1:45)'/6); mdl0 = fitlm ([w, code], m); mdl = step (mdl0, 'Criterion', 'bic', 'Upper', 'interactions', 'Verbose', 0); assert_equal (mdl.NumCoefficients, 2); assert_equal (mdl.DFE, 43); assert_equal (mdl.SSE, 443.573715939, 1e-6); assert_equal (mdl.CoefficientNames, {'(Intercept)','x2'}); assert_equal (mdl.Coefficients.Estimate, [50.739060918498; -1.53909676135581], 1e-6); ***** test tbl_noy = table (x1, x2, x3, 'VariableNames', {'x1','x2','x3'}); mdl = stepwiselm (tbl_noy, y, 'Upper', 'interactions', 'Verbose', 0); assert_equal (mdl.NumObservations, 24); assert_equal (mdl.NumCoefficients, 4); assert_equal (mdl.NumPredictors, 3); assert_equal (mdl.DFE, 20); assert_equal (mdl.SSE, 0.237882441508, 1e-9); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x3'}); assert_equal (mdl.Coefficients.Estimate, ... [4.1119989734334; 1.79245385284216; -1.06961941011697; 0.510296287970133], 1e-9); assert_equal (mdl.ResponseName, 'y'); assert_equal (mdl.PredictorNames, {'x1';'x2';'x3'}); ***** test T_initial = [0 0 0 0]; T_upper = [0 0 0 0; 1 0 0 0; 0 1 0 0; 1 1 0 0]; mdl = stepwiselm (X, y, T_initial, 'Upper', T_upper, 'Verbose', 0); assert_equal (mdl.NumCoefficients, 4); assert_equal (mdl.NumPredictors, 2); assert_equal (mdl.DFE, 20); assert_equal (mdl.SSE, 1.11546087527, 1e-8); assert_equal (mdl.SSR, 24.5179468716, 1e-6); assert_equal (mdl.Rsquared.Ordinary, 0.956484097383, 1e-9); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x1:x2'}); assert_equal (mdl.Coefficients.Estimate, ... [4.00100246650923; 1.35895695996517; -0.232064749079705; -1.27804956860349], 1e-8); assert_equal (mdl.Coefficients.SE, ... [0.181530230599361; 0.299744817513483; 0.272053305331473; 0.469486828642072], 1e-8); assert_equal (mdl.Coefficients.tStat, ... [22.0404196772024; 4.53371294702715; -0.853012055107928; -2.72222667524045], 1e-6); assert_equal (mdl.Coefficients.pValue, ... [1.67738549623508e-15; 0.000202251230338429; 0.403753045528205; 0.0131231039551409], 1e-8); assert_equal (mdl.PredictorNames, {'x1';'x2'}); ***** test mdl = stepwiselm (X, y, 'Upper', 'poly110', 'Verbose', 0); assert_equal (mdl.NumCoefficients, 3); assert_equal (mdl.NumPredictors, 2); assert_equal (mdl.DFE, 21); assert_equal (mdl.SSE, 1.52876802397, 1e-8); assert_equal (mdl.SSR, 24.1046397229, 1e-6); assert_equal (mdl.Rsquared.Ordinary, 0.940360328246, 1e-9); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2'}); assert_equal (mdl.Coefficients.Estimate, ... [4.21600780425081; 1.37121494151013; -0.897420541182461], 1e-8); assert_equal (mdl.Coefficients.SE, ... [0.186735917268724; 0.342414105749106; 0.136495702980697], 1e-8); assert_equal (mdl.Coefficients.tStat, ... [22.577380216489; 4.00455156048637; -6.57471643125185], 1e-6); assert_equal (mdl.Coefficients.pValue, ... [3.27879166781824e-16; 0.000642688076385025; 1.64115221424634e-06], 1e-8); assert_equal (mdl.PredictorNames, {'x1';'x2'}); ***** test p1 = (1:15)'/15; code = repmat ([1;2;3], 5, 1); resp = [5.18127588719375; 9.35081376514746; 3.49974949866041; 5.6242630760159; ... 9.72651388107706; 3.81411200080599; 5.89825501056437; 9.99098641713587; ... 4.10224698823349; 6.23744090586702; 10.3961126341096; 4.57205845018011; ... 6.75484533214212; 10.9323653265385; 5.09379999767747]; mdl = stepwiselm ([p1, code], resp, 'CategoricalVars', logical ([0 1]), ... 'Upper', 'interactions', 'Verbose', 0); assert_equal (mdl.NumObservations, 15); assert_equal (mdl.NumCoefficients, 4); assert_equal (mdl.NumPredictors, 2); assert_equal (mdl.DFE, 11); assert_equal (mdl.SSE, 0.0670192081399, 1e-8); assert_equal (mdl.Rsquared.Ordinary, 0.999296834962, 1e-9); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2_2','x2_3'}); assert_equal (mdl.Coefficients.Estimate, ... [5.04173312790335; 1.92317767382845; 4.01193051752317; -1.97924634508893], 1e-8); assert_equal (mdl.Coefficients.SE, ... [0.0482103221773782; 0.0712545629266561; 0.0495946318075163; 0.050272494208676], 1e-8); assert_equal (mdl.Coefficients.tStat, ... [104.577876691085; 26.990238868043; 80.8944510989422; -39.3703629836483], 1e-5); assert_equal (mdl.Coefficients.pValue, ... [7.63821769167572e-18; 2.10244709730975e-11; 1.28303158624727e-16; 3.44025340004292e-13], 1e-8); assert_equal (mdl.PredictorNames, {'x1';'x2'}); ***** test x1n = x1; yn = y; x1n(5) = NaN; yn(12) = NaN; mdl = stepwiselm ([x1n, x2, x3], yn, 'Upper', 'interactions', 'Verbose', 0); assert_equal (mdl.NumObservations, 22); assert_equal (mdl.NumCoefficients, 4); assert_equal (mdl.NumPredictors, 3); assert_equal (mdl.DFE, 18); assert_equal (mdl.SSE, 0.220518784715, 1e-8); assert_equal (mdl.SSR, 23.3502845138, 1e-6); assert_equal (mdl.Rsquared.Ordinary, 0.990644409445, 1e-9); assert_equal (mdl.CoefficientNames, {'(Intercept)','x1','x2','x3'}); assert_equal (mdl.Coefficients.Estimate, ... [4.11761577459912; 1.79579438452674; -1.05927400080053; 0.512812488395983], 1e-8); assert_equal (mdl.Coefficients.SE, ... [0.0775488744294778; 0.146527417121933; 0.0594402526920882; 0.0517068469441139], 1e-8); assert_equal (mdl.Coefficients.tStat, ... [53.0970411226747; 12.2556885243692; -17.8208192735615; 9.91769018424668], 1e-6); assert_equal (mdl.Coefficients.pValue, ... [3.09620365929824e-21; 3.59135935529609e-10; 6.98703068441474e-13; 1.01407825601795e-08], 1e-8); assert_equal (mdl.PredictorNames, {'x1';'x2';'x3'}); ***** test ## Steps carries MATLAB's seven fields, in its order. s1 = ((1:48)' - 24.5)/12; s2 = sin ((1:48)'/5); s3 = cos ((1:48)'/7); sy = 4 + 2.5*s1 - 1.1*s2 + 0.6*s1.^2 + 0.2*sin ((1:48)'/3); mdl = stepwiselm ([s1, s2, s3], sy, 'constant', 'Upper', 'quadratic', ... 'Verbose', 0); assert_equal (fieldnames (mdl.Steps), {'Start'; 'Lower'; 'Upper'; ... 'Criterion'; 'PEnter'; ... 'PRemove'; 'History'}); ***** test ## The history records every step, and matches MATLAB R2024a throughout. s1 = ((1:48)' - 24.5)/12; s2 = sin ((1:48)'/5); s3 = cos ((1:48)'/7); sy = 4 + 2.5*s1 - 1.1*s2 + 0.6*s1.^2 + 0.2*sin ((1:48)'/3); mdl = stepwiselm ([s1, s2, s3], sy, 'constant', 'Upper', 'quadratic', ... 'Verbose', 0); assert_equal (mdl.Steps.History.TermName, ... {'1'; 'x1'; 'x1^2'; 'x2'; 'x2^2'; 'x3'; 'x2:x3'; 'x1:x2'; ... 'x1:x3'}); assert_equal (mdl.Steps.History.DF, (1:9)'); assert_equal (mdl.Steps.History.FStat, ... [NaN; 685.736350968728; 12.6370657930220; ... 1231.00720701963; 124.872101651316; 13.4519287960430; ... 107.087846311142; 34.9838482569170; 420.274658550522], 1e-8); ***** test ## The default criterion is reported as MATLAB spells it, with the ## thresholds it resolved. s1 = ((1:48)' - 24.5)/12; sy = 4 + 2.5*s1 + 0.2*sin ((1:48)'/3); mdl = stepwiselm (s1, sy, 'constant', 'Upper', 'linear', 'Verbose', 0); assert_equal (mdl.Steps.Criterion, 'SSE'); assert_equal (mdl.Steps.PEnter, 0.05); assert_equal (mdl.Steps.PRemove, 0.10); ***** test ## A criterion asked for is reported as it was asked for, not canonicalised. s1 = ((1:48)' - 24.5)/12; sy = 4 + 2.5*s1 + 0.2*sin ((1:48)'/3); m1 = stepwiselm (s1, sy, 'constant', 'Upper', 'linear', 'Criterion', ... 'aic', 'Verbose', 0); m2 = stepwiselm (s1, sy, 'constant', 'Upper', 'linear', 'Criterion', ... 'AIC', 'Verbose', 0); assert_equal (m1.Steps.Criterion, 'aic'); assert_equal (m2.Steps.Criterion, 'AIC'); ***** test ## An information criterion has no test to report, so the history carries ## its value after each step, the starting model included. s1 = ((1:48)' - 24.5)/12; s2 = sin ((1:48)'/5); s3 = cos ((1:48)'/7); sy = 4 + 2.5*s1 - 1.1*s2 + 0.6*s1.^2 + 0.2*sin ((1:48)'/3); mdl = stepwiselm ([s1, s2, s3], sy, 'constant', 'Upper', 'quadratic', ... 'Criterion', 'aic', 'Verbose', 0); assert_equal (mdl.Steps.History.Properties.VariableNames, ... {'Action', 'TermName', 'Terms', 'DF', 'delDF', 'AIC'}); assert_equal (mdl.Steps.History.AIC(1), 243.691352606191, 1e-9); assert_equal (mdl.Steps.History.AIC(end), -339.898392996306, 1e-9); ***** test ## A removal takes degrees of freedom away, so its delDF is negative. s1 = ((1:48)' - 24.5)/12; s2 = sin ((1:48)'/5); s3 = cos ((1:48)'/7); sy = 4 + 2.5*s1 - 1.1*s2 + 0.6*s1.^2 + 0.2*sin ((1:48)'/3); mdl = stepwiselm ([s1, s2, s3], sy, 'constant', 'Upper', 'quadratic', ... 'Criterion', 'aic', 'Verbose', 0); assert_equal (mdl.Steps.History.Action{end}, 'Remove'); assert_equal (mdl.Steps.History.TermName{end}, 'x2^2'); assert_equal (mdl.Steps.History.delDF(end), -1); assert_equal (mdl.Steps.History.DF(end), 9); ***** test ## Under 'rsquared' the column is named for the criterion too. s1 = ((1:48)' - 24.5)/12; s2 = sin ((1:48)'/5); s3 = cos ((1:48)'/7); sy = 4 + 2.5*s1 - 1.1*s2 + 0.6*s1.^2 + 0.2*sin ((1:48)'/3); mdl = stepwiselm ([s1, s2, s3], sy, 'constant', 'Upper', 'quadratic', ... 'Criterion', 'rsquared', 'Verbose', 0); assert_equal (mdl.Steps.History.Properties.VariableNames, ... {'Action', 'TermName', 'Terms', 'DF', 'delDF', 'Rsquared'}); assert_equal (mdl.Steps.History.Rsquared, [0; 0.937135827762142], 1e-12); ***** test ## A categorical predictor is one step worth L-1 degrees of freedom, named ## for the predictor rather than for its indicators. w = 1400 + (1:45)'*9; g = {'A','B','C'}(mod ((0:44), 3) + 1)'; m = 55 - 0.005*w + [0 5 -3](mod ((0:44), 3) + 1)' + 0.3*sin ((1:45)'/6); t = table (w, g, m, 'VariableNames', {'Weight','Group','MPG'}); mdl = stepwiselm (t, 'MPG ~ 1', 'Upper', 'MPG ~ Weight + Group', ... 'Verbose', 0); assert_equal (mdl.Steps.History.TermName, {'1'; 'Group'; 'Weight'}); assert_equal (mdl.Steps.History.DF, [1; 3; 4]); assert_equal (mdl.Steps.History.delDF, [NaN; 2; 1]); assert_equal (mdl.Steps.History.FStat, ... [NaN; 493.133397072530; 464.280082409591], 1e-8); ***** test ## The Terms of the last row are the terms of the model returned. w = 1400 + (1:45)'*9; g = {'A','B','C'}(mod ((0:44), 3) + 1)'; m = 55 - 0.005*w + [0 5 -3](mod ((0:44), 3) + 1)' + 0.3*sin ((1:45)'/6); t = table (w, g, m, 'VariableNames', {'Weight','Group','MPG'}); mdl = stepwiselm (t, 'MPG ~ 1', 'Upper', 'MPG ~ Weight + Group', ... 'Verbose', 0); assert_equal (mdl.Steps.History.Terms{end}, mdl.Formula.Terms); assert_equal (mdl.Steps.History.Terms{end}, [0, 0, 0; 1, 0, 0; 0, 1, 0]); ***** test ## The Start row names the starting model, not the constant. w = 1400 + (1:45)'*9; g = {'A','B','C'}(mod ((0:44), 3) + 1)'; m = 55 - 0.005*w + [0 5 -3](mod ((0:44), 3) + 1)' + 0.3*sin ((1:45)'/6); t = table (w, g, m, 'VariableNames', {'Weight','Group','MPG'}); mdl = stepwiselm (t, 'MPG ~ Weight + Group', 'Lower', 'MPG ~ Weight', ... 'Upper', 'MPG ~ Weight + Group', 'Verbose', 0); assert_equal (mdl.Steps.History.TermName, {'1 + Weight + Group'}); assert_equal (mdl.Steps.History.DF, 4); ***** test ## Start, Lower, and Upper are formula objects over the model's variables. s1 = ((1:48)' - 24.5)/12; s2 = sin ((1:48)'/5); sy = 4 + 2.5*s1 - 1.1*s2 + 0.2*sin ((1:48)'/3); mdl = stepwiselm ([s1, s2], sy, 'constant', 'Upper', 'linear', ... 'Verbose', 0); assert_equal (class (mdl.Steps.Start), 'LinearFormula'); assert_equal (char (mdl.Steps.Start), 'y ~ 1'); assert_equal (char (mdl.Steps.Upper), 'y ~ 1 + x1 + x2'); assert_equal (mdl.Steps.Start.VariableNames, {'x1', 'x2', 'y'}); ***** test ## A power term in a starting formula survives. Folding it onto the ## all-zero row once discarded it as a duplicate intercept, so ## 'y ~ x1 + x1^2' fitted '1 + x1'. s1 = ((1:48)' - 24.5)/12; s2 = sin ((1:48)'/5); sy = 4 + 2.5*s1 - 1.1*s2 + 0.6*s1.^2 + 0.2*sin ((1:48)'/3); mdl = stepwiselm ([s1, s2], sy, 'y ~ x1 + x1^2', 'Upper', 'quadratic', ... 'NSteps', 0, 'Verbose', 0); assert_equal (mdl.Formula.LinearPredictor, '1 + x1 + x1^2'); assert_equal (mdl.Steps.History.TermName, {'1 + x1 + x1^2'}); assert_equal (mdl.Steps.History.DF, 3); ***** test ## Capping the search at no steps leaves the history with its Start row. s1 = ((1:48)' - 24.5)/12; sy = 4 + 2.5*s1 + 0.2*sin ((1:48)'/3); mdl = stepwiselm (s1, sy, 'constant', 'Upper', 'linear', 'NSteps', 0, ... 'Verbose', 0); assert_equal (size (mdl.Steps.History, 1), 1); assert_equal (mdl.Steps.History.Action{1}, 'Start'); ***** error stepwiselm () ***** error stepwiselm (X, y, 'Verbose') ***** error ... stepwiselm (X, y, 'Criterion', 'bogus') ***** error ... stepwiselm (X, y, 'RobustOpts', 'on') ***** error ... stepwiselm (X, y, [0 0], 'PredictorVars', {'x1', 'x2'}) ***** error ... stepwiselm (tbl, 'y ~ x1', 'PredictorVars', {'x2'}) ***** error ... stepwiselm (tbl, 'y ~ x1', 'ResponseVar', 'x2', 'PredictorVars', {'x1'}) ***** error stepwiselm (X, y, 'Upper', [0 0 0 0 0]) ***** error ... stepwiselm (X, y, 'Upper', {1, 2}) ***** error stepwiselm (X, y, 'Upper', 'poly1') ***** error stepwiselm (X, y, 'Upper', 'bogusmodel') ***** error stepwiselm (X, y, 'PEnter', 0.5) ***** error stepwiselm (X, y, 'PEnter', 0.1, 'PRemove', 0.1) ***** error stepwiselm (X, y, 'Criterion', 'aic', 'PEnter', 0.5, 'PRemove', 0.1) ***** error stepwiselm (X, y, 'Criterion', 'rsquared', 'PEnter', 0.001, 'PRemove', 0.5) ***** test ## sse's default thresholds, 0.05 and 0.10, do not trip the guard assert_equal (isa (stepwiselm (X, y, 'Criterion', 'sse', 'Verbose', 0), ... 'LinearModel'), true); ***** test ## aic's, 0 and 0.01 assert_equal (isa (stepwiselm (X, y, 'Criterion', 'aic', 'Verbose', 0), ... 'LinearModel'), true); ***** test ## bic's, 0 and 0.01 assert_equal (isa (stepwiselm (X, y, 'Criterion', 'bic', 'Verbose', 0), ... 'LinearModel'), true); ***** test ## rsquared's, 0.1 and 0.05, which run the other way round assert_equal (isa (stepwiselm (X, y, 'Criterion', 'rsquared', 'Verbose', 0), ... 'LinearModel'), true); ***** test ## adjrsquared's, 0 and -0.05, the negative one assert_equal (isa (stepwiselm (X, y, 'Criterion', 'adjrsquared', 'Verbose', 0), ... 'LinearModel'), true); ***** test ## a row vector Y is taken as a column Xr = [1 2; 2 1; 3 5; 4 3; 5 6; 6 4; 7 8; 8 7]; yr = [1.2 2.1 3.9 4.2 5.8 6.1 8.2 7.9]; m1 = stepwiselm (Xr, yr, 'Verbose', 0); m2 = stepwiselm (Xr, yr', 'Verbose', 0); assert_equal (m1.Coefficients.Estimate, m2.Coefficients.Estimate); 76 tests, 76 passed, 0 known failure, 0 skipped [inst/Regression/RepeatedMeasuresModel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/RepeatedMeasuresModel.m ***** shared rm, t2, W load fisheriris t = table (species, meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'species', 'meas1', 'meas2', 'meas3', 'meas4'}); Meas = table ([1, 2, 3, 4]', 'VariableNames', {'Measurements'}); rm = fitrm (t, 'meas1-meas4 ~ species', 'WithinDesign', Meas); g = categorical ([1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]'); x = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8]'; [j, i] = meshgrid (1:6, 1:12); Y = mod (7 * i .* j + 3 * i + j .^ 2, 13) + 2 * j + 3 * (double (g) == 2) ... + 0.5 * x; t2 = array2table (Y, 'VariableNames', {'y1', 'y2', 'y3', 'y4', 'y5', 'y6'}); t2.g = g; t2.x = x; W = table (categorical ([1, 1, 1, 2, 2, 2]'), ... categorical ([1, 2, 3, 1, 2, 3]'), 'VariableNames', {'A', 'B'}); ***** assert_equal (rm.ResponseNames, {'meas1', 'meas2', 'meas3', 'meas4'}) ***** assert_equal (rm.BetweenFactorNames, {'species'}) ***** assert_equal (rm.BetweenModel, '1 + species') ***** assert_equal (rm.WithinFactorNames, {'Measurements'}) ***** assert_equal (rm.WithinModel, 'separatemeans') ***** assert_equal (rm.DFE, 147) ***** assert_equal (size (rm.BetweenDesign), [150, 5]) ***** assert_equal (rm.WithinDesign.Properties.RowNames', rm.ResponseNames) ***** assert_equal (rm.Coefficients.Properties.RowNames', ... {'(Intercept)', 'species_setosa', 'species_versicolor'}) ***** assert_equal (table2array (rm.Coefficients), ... [5.84333333333334, 3.05733333333334, 3.758, 1.19933333333333; ... -0.837333333333333, 0.370666666666667, -2.296, ... -0.953333333333333; 0.0926666666666665, ... -0.287333333333334, 0.502, 0.126666666666667], -1e-12) ***** assert_equal (table2array (rm.Covariance)(:,1), ... [0.265008163265306; 0.0927210884353741; ... 0.167514285714286; 0.0384013605442177], -1e-12) ***** test tbl = ranova (rm); assert_equal (tbl.Properties.RowNames', {'(Intercept):Measurements', ... 'species:Measurements', 'Error(Measurements)'}); ***** test tbl = ranova (rm); assert_equal (tbl.SumSq, [1656.26325; 282.4665; 35.42275], -1e-12); assert_equal (tbl.DF, [3; 6; 441]); ***** test tbl = ranova (rm); assert_equal (tbl.F(1:2), [6873.28617202222; 586.100394520471], -1e-12); assert_equal (tbl.pValue(2), 1.42713829312908e-206, -1e-10); ***** test tbl = ranova (rm); assert_equal (tbl.pValueGG(1:2), [9.44912100730417e-279; ... 4.93131396537195e-156], -1e-10); assert_equal (tbl.pValueHF(1:2), [2.92129935033006e-283; ... 1.54056390379818e-158], -1e-10); assert_equal (tbl.pValueLB(1:2), [2.58714529113126e-125; ... 9.01514627639756e-71], -1e-10); ***** test [~, A, C, D] = ranova (rm); assert_equal (A, {[1, 0, 0]; [0, 1, 0; 0, 0, 1]}); assert_equal (C, [1, 0, 0; -1, 1, 0; 0, -1, 1; 0, 0, -1]); assert_equal (D, 0); ***** test tbl = ranova (rm, 'WithinModel', [1, -1, 0, 0; 0, 1, -1, 0]'); assert_equal (tbl.SumSq, [630.067244444444; 282.402488888889; ... 24.5102666666667], -1e-12); assert_equal (tbl.pValueGG(1:2), [2.73416691642378e-192; ... 3.34270901331439e-146], -1e-10); ***** test tbl = ranova (rm, 'WithinModel', 'orthogonalcontrasts'); assert_equal (tbl.SumSq, [7201.65615000052; 309.6067; 53.87465; ... 1313.01136333336; 35.9780866666667; 13.75805; ... 1.93801666666664; 0.469633333333338; 4.53985; ... 341.313870000001; 246.01878; 17.12485], -1e-11); ***** test tbl = ranova (rm, 'WithinModel', 'orthogonalcontrasts'); assert_equal (tbl.F([4, 5, 7, 8, 10, 11]), [14029.0717369107; ... 192.206698623715; 62.7528332433881; 7.60334592552624; ... 2929.84399221016; 1055.91466961754], -1e-11); ***** test tbl = ranova (rm, 'WithinModel', 'orthogonalcontrasts'); assert_equal (tbl.Properties.RowNames([4, 7, 10])', ... {'(Intercept):Measurements', '(Intercept):Measurements^2', ... '(Intercept):Measurements^3'}); ***** test tbl = mauchly (rm); assert_equal (table2array (tbl), [0.558144130896497, 84.9761726331633, ... 5, 7.61488382466235e-17], -1e-12); ***** test tbl = epsilon (rm); assert_equal (table2array (tbl), [1, 0.751790042430452, ... 0.764092317002038, 1/3], -1e-12); ***** test C = [1, -1, 0, 0; 0, 1, -1, 0; 0, 0, 1, -1]'; assert_equal (table2array (epsilon (rm, C)), ... [1, 0.751790042430453, 0.764092317002038, 1/3], -1e-12); ***** test C = [1, -1, 0, 0; 0, 1, -1, 0; 0, 0, 1, -1]'; assert_equal (mauchly (rm, C).W, 0.558144130896497, -1e-12); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W, 'WithinModel', 'A*B'); assert_equal (rm2.BetweenModel, '1 + g + x'); assert_equal (rm2.BetweenFactorNames, {'g', 'x'}); assert_equal (rm2.DFE, 9); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); assert_equal (table2array (rm2.Coefficients)(:,1), ... [9.54310344827587; -0.0402298850574699; 0.586206896551724], ... -1e-12); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W, 'WithinModel', 'A*B'); tbl = ranova (rm2); assert_equal (tbl.Properties.RowNames', {'(Intercept):Time', 'g:Time', ... 'x:Time', 'Error(Time)'}); assert_equal (tbl.SumSq, [255.837635271832; 105.120215891605; ... 106.01539408867; 651.790161466886], -1e-12); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); tbl = ranova (rm2); assert_equal (tbl.pValueGG(1:3), [0.028891532860066; 0.25048764667133; ... 0.247169589665584], -1e-12); assert_equal (tbl.pValueHF(1:3), [0.0115155408306671; 0.23038031489716; ... 0.226411224877626], -1e-12); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); tbl = ranova (rm2, 'WithinModel', 'A*B'); assert_equal (tbl.SumSq, [3499.10306228529; 40.8161242267455; ... 97.0498768472906; 63.3112342638205; 173.443725936885; ... 6.54103670312192; 3.16262999452654; 229.976258894362; ... 60.1151512858879; 32.4673167683903; 78.5480295566504; ... 145.674192665572; 22.2787580490593; 66.1118624200928; ... 24.3047345374931; 276.139709906951], -1e-11); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); tbl = ranova (rm2, 'WithinModel', 'A*B'); assert_equal (tbl.pValueGG(9:11), [0.0492037168776316; ... 0.167760677557413; 0.0238347461584444], -1e-11); assert_equal (tbl.pValueHF(13:15), [0.488916988695095; ... 0.149284419253376; 0.460679398895663], -1e-11); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); assert_equal (table2array (mauchly (rm2)), [0.109478004315118, ... 15.7054245285396, 14, 0.331692719814282], -1e-11); assert_equal (table2array (epsilon (rm2)), [1, 0.589453986170189, ... 0.907778770724919, 0.2], -1e-12); ***** test rm9 = fitrm (t2, 'y1-y6 ~ g', 'WithinDesign', W, 'WithinModel', 'A+B'); tbl = ranova (rm9, 'WithinModel', rm9.WithinModel); assert_equal (tbl.SumSq, [19900.125; 74.0138888888887; 160.361111111111; ... 583.680555555555; 5.01388888888888; 233.138888888889; ... 137.25; 58.5277777777778; 224.222222222222], -1e-12); assert_equal (tbl.pValueGG(7:8), [0.0102255822891222; ... 0.103329724488498], -1e-11); ***** test rm3 = fitrm (t2, 'y1-y6 ~ g', 'WithinDesign', [1, 2, 4, 8, 16, 32]'); assert_equal (rm3.WithinDesign.Time, [1; 2; 4; 8; 16; 32]); assert_equal (rm3.WithinFactorNames, {'Time'}); ***** test rm3 = fitrm (t2, 'y1-y6 ~ g', 'WithinDesign', [1, 2, 4, 8, 16, 32]'); tbl = ranova (rm3); assert_equal (tbl.SumSq, [722.125; 124.569444444444; 757.805555555556], ... -1e-12); assert_equal (tbl.pValueGG(1:2), [8.15757856520654e-05; ... 0.195494399896943], -1e-11); assert_equal (tbl.pValueHF(1:2), tbl.pValue(1:2)); ***** test rm3 = fitrm (t2, 'y1-y6 ~ g', 'WithinDesign', [1, 2, 4, 8, 16, 32]'); assert_equal (table2array (epsilon (rm3)), [1, 0.650731538906031, 1, ... 0.2], -1e-12); assert_equal (table2array (mauchly (rm3)), [0.172269738544646, ... 14.2454196441778, 14, 0.431591774636887], -1e-11); ***** test rm4 = fitrm (t2, 'y1-y6 ~ 1'); assert_equal (rm4.BetweenFactorNames, cell (1, 0)); assert_equal (rm4.BetweenModel, '1'); ***** test rm4 = fitrm (t2, 'y1-y6 ~ 1'); tbl = ranova (rm4); assert_equal (tbl.SumSq, [722.125; 882.375], -1e-12); assert_equal (tbl.pValueGG(1), 6.37221717220761e-05, -1e-11); assert_equal (epsilon (rm4).GreenhouseGeisser, 0.693384390469508, -1e-12); ***** test rm7 = fitrm (t2, 'y1-y6 ~ g*x', 'WithinDesign', W); assert_equal (rm7.BetweenModel, '1 + g*x'); assert_equal (rm7.Coefficients.Properties.RowNames', ... {'(Intercept)', 'g_1', 'x', 'g_1:x'}); assert_equal (table2array (rm7.Coefficients)(:,1), [10.8028790057797; ... -3.00733997232247; 0.37163867256397; 0.659959840447182], ... -1e-12); ***** test rm8 = fitrm (t2, 'y1,y2,y3 ~ g'); assert_equal (rm8.ResponseNames, {'y1', 'y2', 'y3'}); assert_equal (rm8.WithinDesign.Time, [1; 2; 3]); ***** test t3 = t2; t3.y2(3) = NaN; rm5 = fitrm (t3, 'y1-y6 ~ g + x', 'WithinDesign', W); assert_equal (rm5.DFE, 8); assert_equal (rows (rm5.BetweenDesign), 12); assert_equal (table2array (rm5.Coefficients)(:,1), [9.79152291769344; ... 0.248891079349433; 0.594627895515033], -1e-12); assert_equal (ranova (rm5).SumSq, [242.715922479748; 90.7245227703455; ... 106.321888176989; 631.122556267455], -1e-12); ***** test t4 = t2; t4.y2(12) = NaN; t4.y3(12) = NaN; assert_equal (fitrm (t4, 'y1-y6 ~ g', 'WithinDesign', W).DFE, 9); ***** test t5 = t2; t5.y2 = t5.y1 + 1; tbl = mauchly (fitrm (t5, 'y1-y6 ~ g')); assert_equal (table2array (tbl), [0, Inf, 14, 0]); ***** test tbl = anova (rm); assert_equal (cellstr (tbl.Between)', {'constant', 'species', 'Error'}); assert_equal (cellstr (tbl.Within)', {'Constant', 'Constant', 'Constant'}); ***** test tbl = anova (rm); assert_equal (tbl.SumSq, [7201.65615000065; 309.606699999999; ... 53.87465], -1e-12); assert_equal (tbl.DF, [1; 2; 147]); assert_equal (tbl.F(1:2), [19650.1221641365; 422.389610883782], -1e-12); ***** test assert_equal (anova (rm, 'WithinModel', 'separatemeans').SumSq, ... anova (rm).SumSq); ***** test tbl = anova (rm, 'WithinModel', [1, -1, 0, 0; 0, 1, -1, 0]'); assert_equal (cellstr (tbl.Within([1, 4]))', {'Contrast1', 'Contrast2'}); assert_equal (tbl.SumSq, [1164.2694; 114.4624; 28.6582; ... 73.6400666666671; 562.926933333334; 27.943], -1e-12); assert_equal (tbl.F([4, 5]), [387.39898364528; 1480.69747700676], -1e-12); ***** test tbl = anova (rm, 'WithinModel', [1, 1, 1, 1]'); assert_equal (tbl.SumSq(1), 28806.6246000026, -1e-12); ***** test tbl = anova (rm, 'WithinModel', 'orthogonalcontrasts'); assert_equal (cellstr (tbl.Within([1, 4, 7, 10]))', {'Constant', ... 'Measurements', 'Measurements^2', 'Measurements^3'}); assert_equal (tbl.SumSq([4, 7, 10]), [1313.01136333336; ... 1.93801666666664; 341.313870000001], -1e-11); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); tbl = anova (rm2, 'WithinModel', 'A*B'); assert_equal (cellstr (tbl.Within(1:4:end))', {'(Intercept)', 'A_1', ... 'B_1', 'B_2', 'A_1:B_1', 'A_1:B_2'}); assert_equal (tbl.SumSq(9:12), [10.539317448175; 0.186084518387707; ... 7.3161945812808; 73.7254720853859], -1e-12); assert_equal (tbl.pValue(22:23), [0.153846787233791; ... 0.29518761419548], -1e-11); ***** test tbl = manova (rm); assert_equal (cellstr (tbl.Statistic(1:4))', {'Pillai', 'Wilks', ... 'Hotelling', 'Roy'}); assert_equal (cellstr (tbl.Between([1, 5]))', {'(Intercept)', 'species'}); assert_equal (cellstr (tbl.Within(1)), {'Constant'}); ***** test tbl = manova (rm); assert_equal (tbl.Value(5:8), [0.969092455350808; 0.0411531658067895; ... 23.0505039998432; 23.0396981666769], -1e-12); assert_equal (tbl.RSquare(5:8), [0.484546227675404; 0.797137569257416; ... 0.920161286974006; 0.958402139949237], -1e-12); ***** test tbl = manova (rm); assert_equal (tbl.F([5, 6, 8]), [45.7485249172255; 189.92336681764; ... 1121.26531077827], -1e-11); assert_equal ([tbl.df1([5, 6, 8]), tbl.df2([5, 6, 8])], ... [6, 292; 6, 290; 3, 146]); assert_equal (tbl.pValue([5, 6, 8]), [2.47288601081631e-39; ... 2.39583203496623e-97; 1.47713689662351e-100], -1e-10); ***** test tbl = manova (rm); assert_equal (tbl.F(7), 555.166436056617, -1e-11); n = (147 - 3 - 1) / 2; b = (3 + 2 * n) * (2 + 2 * n) / (2 * (2 * n + 1) * (n - 1)); d2 = 4 + 8 / (b - 1); assert_equal ([tbl.df1(7), tbl.df2(7)], [6, d2], -1e-14); assert_equal (tbl.pValue(7), fcdf (tbl.F(7), 6, d2, 'upper'), -1e-12); ***** test tbl = manova (rm, 'By', 'species'); assert_equal (cellstr (tbl.Between(1:4:end))', {'species=setosa', ... 'species=versicolor', 'species=virginica'}); assert_equal (tbl.Value(1:4:end), [0.982302126154032; ... 0.97000070863222; 0.972606348435736], -1e-12); assert_equal (tbl.F(1), 2682.69152049929, -1e-11); ***** test tbl = manova (rm, 'WithinModel', [1, -1, 0, 0; 0, 1, -1, 0]'); assert_equal (cellstr (tbl.Within(1)), {'Specified contrast'}); assert_equal (tbl.Value(5), 0.960761007306465, -1e-12); assert_equal (tbl.F(1), 4126.8008429193, -1e-11); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W, 'WithinModel', 'A*B'); [tbl, A, C, D] = manova (rm2); assert_equal (rows (tbl), 48); assert_equal (unique (cellstr (tbl.Within), 'stable')', ... {'(Intercept)', 'A', 'B', 'A:B'}); assert_equal (A, {[1, 0, 0]; [0, 1, 0]; [0, 0, 1]}); assert_equal (cellfun (@columns, C), [1, 1, 2, 2]); assert_equal (D, 0); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W, 'WithinModel', 'A*B'); tbl = manova (rm2); assert_equal (tbl.Value(41:44), [0.486347963843071; 0.513652036156928; ... 0.946843251088535; 0.946843251088535], -1e-12); assert_equal (tbl.pValue(41), 0.069610708832983, -1e-11); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W, 'WithinModel', 'A*B'); tbl = manova (rm2, 'WithinModel', 'separatemeans'); assert_equal (tbl.Value(1), 0.786551501991551, -1e-12); assert_equal ([tbl.F(3), tbl.df1(3), tbl.df2(3)], ... [3.68497089148136, 5, 5], -1e-12); assert_equal (tbl.pValue(3), 0.0893171383745427, -1e-11); ***** test tbl = coeftest (rm, [0, 1, 0; 0, 0, 1], [1, -1, 0, 0; 0, 1, -1, 0]'); assert_equal (tbl.Value, [0.960761007306465; 0.0420065576612523; ... 22.739922777632; 22.7370251198758], -1e-12); assert_equal (tbl.F([1, 2, 4]), [67.9496579068885; 283.175722000404; ... 1671.17134631087], -1e-11); assert_equal (tbl.F(3), 828.147118575719, -1e-11); ***** test tbl = coeftest (rm, [0, 1, 0; 0, 0, 1], [1, -1, 0, 0; 0, 1, -1, 0]', ... [0.5, 0.1; -0.2, 0.3]); assert_equal (tbl.Value, [1.07175176658522; 0.0463873977279332; ... 18.0107848010586; 17.8682529938836], -1e-12); assert_equal (tbl.pValue(4), 1.71285549134517e-94, -1e-10); ***** test tbl = coeftest (rm, [1, 0, 0], [1, -1, 0, 0]', 1); assert_equal (tbl.F, 2454.27144063479 * ones (4, 1), -1e-12); assert_equal ([tbl.df1, tbl.df2], repmat ([1, 147], 4, 1)); ***** test tbl = coeftest (rm, [0, 1, 0], [1, -1, 0, 0]'); assert_equal (tbl.Value(1), 0.792486767123089, -1e-12); assert_equal (tbl.F(1), 561.38855894648, -1e-12); ***** test tbl = margmean (rm, 'species'); assert_equal (tbl.species, {'setosa'; 'versicolor'; 'virginica'}); assert_equal (tbl.Mean, [2.5355; 3.573; 4.285], -1e-13); assert_equal (tbl.StdErr, 0.0428073718935813 * ones (3, 1), -1e-12); assert_equal (tbl.Lower(1), 2.45090264579764, -1e-12); ***** test tbl = margmean (rm, 'Measurements'); assert_equal (tbl.Measurements, [1; 2; 3; 4]); assert_equal (tbl.StdErr, [0.0420323814271256; 0.0277353871557668; ... 0.0351366622491893; 0.0167096045540803], -1e-12); ***** test tbl = margmean (rm, {'species', 'Measurements'}); assert_equal (rows (tbl), 12); assert_equal (tbl.Mean(1:4), [5.006; 3.428; 1.462; 0.246], -1e-12); assert_equal (tbl.StdErr(5), 0.072802220194896, -1e-12); ***** test tbl = margmean (rm, 'species', 'Alpha', 0.01); assert_equal (tbl.Lower(1), 2.42378611949266, -1e-12); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); tbl = margmean (rm2, 'g'); assert_equal (tbl.Mean, [15.8555692391899; 17.3944307608101], -1e-12); assert_equal (tbl.StdErr, 0.446919101103406 * ones (2, 1), -1e-12); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); tbl = margmean (rm2, {'g', 'A'}); assert_equal (tbl.Mean, [13.3163656267105; 18.3947728516694; ... 14.2391899288451; 20.549671592775], -1e-12); assert_equal (tbl.StdErr(1:2), [1.12245927784633; 0.768527281387124], ... -1e-12); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); tbl = margmean (rm2, {'B', 'g'}); assert_equal (tbl.Mean([1, 4, 6]), [13.8103448275862; 16.301724137931; ... 19.6919129720854], -1e-12); assert_equal (tbl.StdErr([1, 3, 5]), [0.863939313862951; ... 0.870431298727607; 0.688406615362842], -1e-12); ***** test tbl = grpstats (rm, 'species'); assert_equal (tbl.GroupCount, [200; 200; 200]); assert_equal (tbl.mean, [2.5355; 3.573; 4.285], -1e-13); assert_equal (tbl.std, [1.84834293572383; 1.76238503313695; ... 1.91538993235446], -1e-12); ***** test tbl = grpstats (rm, 'Measurements'); assert_equal (tbl.GroupCount, 150 * ones (4, 1)); assert_equal (tbl.std, [0.828066127977863; 0.435866284936698; ... 1.76529823325947; 0.762237668960347], -1e-12); ***** test tbl = grpstats (rm, 'species', {'min', 'max'}); assert_equal (tbl.Properties.VariableNames, {'species', 'GroupCount', ... 'min', 'max'}); assert_equal ([tbl.min, tbl.max], [0.1, 5.8; 1, 7; 1.4, 7.9]); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); tbl = grpstats (rm2, {'g', 'B'}); assert_equal (tbl.GroupCount, 12 * ones (6, 1)); assert_equal (tbl.std([1, 5]), [4.56767297030297; 3.29944898981082], ... -1e-12); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); tbl = grpstats (rm2, 'g', {'mean', 'sem', 'var', 'range', 'numel', ... 'median'}); assert_equal ([tbl.sem, tbl.var], [0.797344578852233, ... 22.8873015873016; 0.874599933736397, 27.5373015873016], ... -1e-12); assert_equal ([tbl.range, tbl.numel, tbl.median], [19, 36, 16.25; ... 22, 36, 17.5]); ***** test tbl = multcompare (rm, 'species', 'ComparisonType', 'bonferroni'); assert_equal (tbl.Difference(1:2), [-1.0375; -1.7495], -1e-12); assert_equal (tbl.StdErr(1), 0.0605387659014515, -1e-12); assert_equal (tbl.pValue(1:2), [2.15970302648855e-36; ... 5.03902053290415e-62], -1e-9); assert_equal (tbl.Lower(1), -1.18410589638625, -1e-12); ***** test tbl = multcompare (rm, 'species', 'ComparisonType', 'lsd'); assert_equal (tbl.pValue(1), 7.19901008829516e-37, -1e-9); assert_equal (tbl.Lower(1), -1.15713872565386, -1e-12); ***** test tbl = multcompare (rm, 'species', 'ComparisonType', 'scheffe'); assert_equal (tbl.pValue(1), 8.97549175066402e-36, -1e-9); assert_equal (tbl.Lower(1), -1.18720639857468, -1e-12); ***** test tbl = multcompare (rm, 'species'); assert_equal (tbl.Lower(1), -1.0375 - 3.34842406186643 / sqrt (2) ... * 0.0605387659014515, -1e-10); assert_equal (all (tbl.pValue < 1e-20), true); ***** test tbl = multcompare (rm, 'Measurements', 'By', 'species'); assert_equal (rows (tbl), 36); assert_equal (tbl.Properties.VariableNames(1:3), {'species', ... 'Measurements_1', 'Measurements_2'}); assert_equal (tbl.StdErr(1:3), [0.0624425722558894; 0.047993196796791; ... 0.0678361370996215], -1e-12); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); tbl = multcompare (rm2, 'B'); assert_equal (tbl.StdErr([1, 2, 4]), [0.914225240599476; ... 0.826222282469959; 0.710493930524169], -1e-12); ## R2024a's studentized range is good to about 2e-7 here assert_equal (tbl.pValue([1, 2, 4]), [0.278857228960382; ... 0.00693824145665634; 0.0634575438808659], -1e-6); assert_equal (tbl.Lower(1:2), [-4.05252199083511; -5.68181723897677], ... -1e-7); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); tbl = multcompare (rm2, 'B', 'By', 'g'); assert_equal (tbl.Difference([1, 8]), [-2.88793103448276; ... -3.50225779967159], -1e-12); assert_equal (tbl.pValue([1, 10]), [0.122845632074643; ... 0.0214216738123368], -1e-7); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); tbl = multcompare (rm2, 'g', 'By', 'A'); assert_equal (tbl.StdErr([1, 3]), [1.60451755027924; 1.09858373946539], ... -1e-12); assert_equal (tbl.pValue([1, 3]), [0.579288143050048; ... 0.0814446080647632], -1e-7); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); tbl = multcompare (rm2, 'B', 'ComparisonType', 'dunn-sidak'); assert_equal (tbl.pValue([1, 2, 4]), [0.353395443395346; ... 0.00819161456139628; 0.0787120565287793], -1e-10); assert_equal (tbl.Lower(1), -4.17216326867877, -1e-10); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); assert_equal (predict (rm2, t2(1:2,:))(1,:), [11.2614942528736, ... 13.2783251231527, 13.1005747126437, 14.7040229885058, ... 20.3940886699507, 18.4835796387521], -1e-12); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); [~, yci] = predict (rm2, t2(1:2,:)); assert_equal (size (yci), [2, 6, 2]); assert_equal ([yci(1,1,1), yci(1,1,2)], [7.64052800884495, ... 14.8824604969022], -1e-12); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); t4 = t2(1:2,:); t4.x(1) = NaN; yp = predict (rm2, t4); assert_equal (isnan (yp(:,1)), [true; false]); ***** test rm2 = fitrm (t2, 'y1-y6 ~ g + x', 'WithinDesign', W); assert_equal (size (predict (rm2)), [12, 6]); ***** test rm3 = fitrm (t2, 'y1-y6 ~ g', 'WithinDesign', [1, 2, 4, 8, 16, 32]', ... 'WithinModel', 'orthogonalcontrasts'); assert_equal (predict (rm3, t2(1,:), 'WithinDesign', [3, 5]'), ... [13.8420137222029, 14.4827614967302], -1e-11); ***** test rm9 = fitrm (t2, 'y1-y6 ~ g', 'WithinDesign', W, 'WithinModel', 'A+B'); assert_equal (predict (rm9, t2(1,:)), [10.9166666666667, ... 14.1666666666667, 14, 16.0833333333333, 19.3333333333333, ... 19.1666666666667], -1e-12); ***** warning ... predict (rm, rm.BetweenDesign(1,:), 'WithinDesign', [1.5, 2.5]'); ***** test assert_equal (size (random (rm)), [150, 4]); assert_equal (size (random (rm, rm.BetweenDesign([1, 51, 101],:))), [3, 4]); ***** test hf = figure ('visible', 'off'); unwind_protect h = plot (rm); assert_equal (numel (h), 150); assert_equal (get (h(1), 'xdata'), [1, 2, 3, 4]); assert_equal (get (h(1), 'ydata'), [5.1, 3.5, 1.4, 0.2]); assert_equal (get (h(1), 'marker'), 's'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = plot (rm, 'Group', 'species', 'Marker', 'o', 'LineStyle', '--'); assert_equal (get (legend (), 'string')(:)', {'species=setosa', ... 'species=versicolor', 'species=virginica'}); assert_equal (isequal (get (h(1), 'color'), get (h(51), 'color')), false); assert_equal (get (h(1), 'linestyle'), '--'); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = plotprofile (rm, 'species'); assert_equal (numel (h), 1); assert_equal (get (h, 'ydata'), [2.5355, 3.573, 4.285], -1e-13); assert_equal (get (get (gca, 'xlabel'), 'string'), 'species'); assert_equal (get (get (gca, 'ylabel'), 'string'), ... 'Estimated marginal means'); assert_equal (get (gca, 'xticklabel')', {'setosa', 'versicolor', ... 'virginica'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** test hf = figure ('visible', 'off'); unwind_protect h = plotprofile (rm, 'Measurements', 'Group', 'species'); assert_equal (numel (h), 3); assert_equal (get (h(1), 'xdata'), [1, 2, 3, 4]); assert_equal (get (h(1), 'ydata'), [5.006, 3.428, 1.462, 0.246], -1e-12); assert_equal (get (legend (), 'string')(:)', {'species=setosa', ... 'species=versicolor', 'species=virginica'}); unwind_protect_cleanup close (hf); end_unwind_protect ***** error RepeatedMeasuresModel (1) ***** error fitrm ([1, 2, 3], 'y1-y6 ~ g') ***** error ... fitrm (t2, 5) ***** error ... fitrm (t2, 'y1-y6') ***** error ... fitrm (t2, 'y1-y6 ~ q') ***** error ... fitrm (t2, 'y1-y9 ~ g') ***** error ... fitrm (t2, 'y6-y1 ~ g') ***** error ... fitrm (t2, 'y1,y1 ~ g') ***** error ... fitrm (t2, 'y1-y6 ~ y1') ***** error ... fitrm (t2, 'g,y1 ~ x') ***** error ... fitrm (t2, 'y1-y6 ~ g', 'Nonsense', 1) ***** error ... fitrm (t2, 'y1-y6 ~ g', 'WithinDesign', [1, 2, 3]') ***** error ... fitrm (t2, 'y1-y6 ~ g', 'WithinDesign', {1}) ***** error ... fitrm (t2, 'y1-y6 ~ g', 'WithinDesign', W, 'WithinModel', 'C*D') ***** error ... fitrm (t2, 'y1-y6 ~ g', 'WithinDesign', W, 'WithinModel', 'orthogonalcontrasts') ***** error ... fitrm ([t2, table(2 * t2.x, 'VariableNames', {'x2'})], 'y1-y6 ~ x + x2') ***** error ... ranova (rm, 'WithinModel', ones (5, 1)) ***** error ... ranova (rm, 'WithinModel', 'C*D') ***** error ... ranova (rm, 'Nonsense', 1) ***** error ... mauchly (rm, ones (5, 1)) ***** error ... epsilon (rm, ones (5, 1)) ***** error ... anova (rm, 'WithinModel', 'C*D') ***** error ... anova (rm, 'Nonsense', 1) ***** error ... manova (rm, 'WithinModel', 'orthogonalcontrasts') ***** error ... manova (rm, 'By', 'g') ***** error ... manova (fitrm (t2, 'y1-y6 ~ x'), 'By', 'x') ***** error ... manova (rm, 'Nonsense', 1) ***** error ... coeftest (rm, [0, 1, 0]) ***** error ... coeftest (rm, [1, 0], [1, -1, 0, 0]') ***** error ... coeftest (rm, [0, 1, 0], [1, -1, 0]') ***** error ... coeftest (rm, [0, 1, 0], [1, -1, 0, 0]', [1, 2]) ***** error margmean (rm) ***** error ... margmean (rm, 'nosuch') ***** error ... margmean (fitrm (t2, 'y1-y6 ~ g + x'), 'x') ***** error ... margmean (rm, 'species', 'Alpha', 1) ***** error ... margmean (rm, 'species', 'Nonsense', 1) ***** error grpstats (rm) ***** error ... grpstats (rm, 'nosuch') ***** error ... grpstats (rm, 'species', 'mode') ***** error multcompare (rm) ***** error ... multcompare (rm, 'nosuch') ***** error ... multcompare (rm, 'species', 'ComparisonType', 'hsd') ***** error ... multcompare (rm, 'species', 'By', 'species') ***** error ... multcompare (rm, 'species', 'Alpha', 0) ***** error ... multcompare (rm, 'species', 'Nonsense', 1) ***** error ... predict (rm, table ([1; 2], 'VariableNames', {'z'})) ***** error ... predict (rm, 'Alpha', 2) ***** error ... predict (rm, 'Nonsense', 1) ***** error ... predict (fitrm (t2, 'y1-y6 ~ g', 'WithinDesign', W, 'WithinModel', 'A+B'), ... 'WithinDesign', {1}) ***** error random (rm, 1) ***** error ... random (rm, table ([1; 2], 'VariableNames', {'z'})) ***** error ... plot (rm, 'Group', 'Measurements') ***** error ... plot (rm, 'Group', 'nosuch') ***** error ... plot (rm, 'Nonsense', 1) ***** error ... plotprofile (rm) ***** error ... plotprofile (rm, {'species', 'Measurements'}) ***** error ... plotprofile (rm, 'nosuch') ***** error ... plotprofile (rm, 'species', 'Nonsense', 1) 153 tests, 153 passed, 0 known failure, 0 skipped [inst/Regression/fitglme.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/fitglme.m ***** demo ## Poisson mixed model with a random intercept per group. rng (42); randg ('state', 42); randp ('state', 42); g = reshape (repmat (1:6, 7, 1), [], 1); x = randn (42, 1); y = poissrnd (exp (0.3 + 0.5 * x + 0.2 * reshape (repmat (randn (1, 6), 7, 1), [], 1))); tbl = table (y, x, g); glme = fitglme (tbl, "y ~ x + (1 | g)", "Distribution", "poisson"); disp (glme.Coefficients); ***** shared tbl xL = [0.032760004 0.70410822 -0.8646718 -0.28869454 0.51276678 -1.4975462 ... -1.4527871 -0.80013541 -1.644209 1.5137701 0.72905543 0.20880758 1.0856145 ... 0.62862577 -0.87409978 1.9178276 0.09748204 0.50697633 1.0247569 ... -0.92789896 -0.88921018 -0.98322849 -0.031378913 0.86875961 -0.91481141 ... 0.034324163 -0.25025257 -1.0575644 -0.86131607 -0.35355444 0.82950729 ... -0.36874363 0.061580868 0.55803564 -0.1763803 1.0482413 1.0137831 ... -0.94876976 -0.010703972 -0.35149845 -1.6828735 -1.0493301]'; yBin = [0 0 0 0 1 0 0 1 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 1 1 ... 0 1 1 0 1 1 0 0]'; yPois = [3 3 1 1 1 1 1 2 1 5 2 0 5 0 1 5 0 2 0 0 1 0 0 5 3 0 1 0 0 1 1 1 2 2 ... 1 1 4 0 1 0 0 1]'; g = [1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 ... 6 1 2 3 4 5 6]'; tbl = table (yBin, yPois, xL, g); ***** test # binomial logit, MPL -- matches MATLAB fitglme glme = fitglme (tbl, "yBin ~ xL + (1 | g)", "Distribution", "binomial"); assert_equal (isa (glme, "GeneralizedLinearMixedModel"), true); assert_equal (glme.Coefficients.Estimate, [-0.55912; 0.76062], 1e-3); assert_equal (glme.Coefficients.SE, [0.33856; 0.39971], 1e-3); assert_equal (glme.LogLikelihood, -92.58872, 1e-2); ***** test # poisson log, REMPL -- non-degenerate random-effect variance glme = fitglme (tbl, "yPois ~ xL + (1 | g)", "Distribution", "poisson", ... "FitMethod", "REMPL"); assert_equal (glme.Coefficients.Estimate, [0.23092; 0.67809], 1e-3); [psi, ~] = covarianceParameters (glme); assert_equal (psi{1}, 0.015918, 1e-3); assert_equal (glme.LogLikelihood, -56.90298, 1e-2); ***** test # Laplace reports the marginal log-likelihood glme = fitglme (tbl, "yBin ~ xL + (1 | g)", "Distribution", "binomial", ... "FitMethod", "Laplace"); assert_equal (glme.LogLikelihood, -25.36010, 1e-2); ***** test # coefficient stats: DF = n - p, tStat = Estimate / SE glme = fitglme (tbl, "yPois ~ xL + (1 | g)", "Distribution", "poisson"); C = glme.Coefficients; assert_equal (C.DF, [40; 40]); assert_equal (C.tStat, C.Estimate ./ C.SE, 1e-10); ***** test # metadata glme = fitglme (tbl, "yBin ~ xL + (1 | g)", "Distribution", "binomial"); assert_equal (glme.Distribution, "binomial"); assert_equal (glme.Link, "logit"); assert_equal (glme.FitMethod, "MPL"); assert_equal (glme.ResponseName, "yBin"); ***** test # all 8 fits (binomial/poisson x MPL/REMPL/Laplace/ApproximateLaplace) fits = { "yBin", "MPL", [-0.5591172; 0.7606217], [0.3385596; 0.3997127], -92.58872; ... "yBin", "REMPL", [-0.5591172; 0.7606217], [0.3385596; 0.3997127], -92.75162; ... "yBin", "Laplace", [-0.5591172; 0.7606217], [0.3385596; 0.3997127], -25.3601; ... "yBin", "ApproximateLaplace", [-0.5591172; 0.7606217], [0.3385596; 0.3997127], -25.3601; ... "yPois", "MPL", [0.2317919; 0.6848705], [0.1450691; 0.1496462], -55.13664; ... "yPois", "REMPL", [0.2309183; 0.6780919], [0.1539524; 0.1521982], -56.90296; ... "yPois", "Laplace", [0.2317919; 0.6848705], [0.1450691; 0.1496462], -59.2123; ... "yPois", "ApproximateLaplace", [0.2317919; 0.6848705], [0.1450691; 0.1496462], -59.2123 }; for k = 1:rows (fits) dist = "binomial"; if (strcmp (fits{k,1}, "yPois")), dist = "poisson"; endif glme = fitglme (tbl, [fits{k,1} " ~ xL + (1 | g)"], "Distribution", dist, ... "FitMethod", fits{k,2}); assert_equal (glme.Coefficients.Estimate, fits{k,3}, 1e-3); assert_equal (glme.Coefficients.SE, fits{k,4}, 1e-3); assert_equal (glme.LogLikelihood, fits{k,5}, 1e-2); endfor ***** error fitglme (table ()) ***** error fitglme (magic (3), "y ~ x + (1|g)") ***** error fitglme (table ((1:3)', "VariableNames", {"y"}), "y ~ (1|y)", "Distribution", "xxx") ***** error fitglme (table ((1:3)', "VariableNames", {"y"}), "y ~ 1") ***** error fitglme (table ((1:3)', "VariableNames", {"y"}), "y ~ (1|y)", "bogus", 1) 11 tests, 11 passed, 0 known failure, 0 skipped [inst/Regression/fitglm.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/fitglm.m ***** demo ## Poisson regression of counts on two predictors. X = [0.1, 1.2; 0.4, 0.7; 1.1, 0.2; 1.5, 1.9; 0.3, 0.5; 1.8, 1.1; 0.9, 0.3]; y = [1; 0; 2; 3; 1; 4; 2]; mdl = fitglm (X, y, 'Distribution', 'poisson') ***** demo ## Logistic regression with an interaction, specified by a formula. X = [0.1, 1.2; 0.4, 0.7; 1.1, 0.2; 1.5, 1.9; 0.3, 0.5; 1.8, 1.1; 0.9, 0.3]; y = [0; 0; 1; 1; 0; 1; 1]; tbl = array2table ([X, y], 'VariableNames', {'x1', 'x2', 'y'}); mdl = fitglm (tbl, 'y ~ x1 + x2 + x1:x2', 'Distribution', 'binomial') ***** shared X, yp, yb X = [ 0.37, 0.06, 1.76; -0.76, -1.52, 0.84; 0.76, -0.19, -0.47; ... -0.80, -2.74, -0.90; 0.08, 0.39, 1.05; -0.41, -0.03, 0.74; ... 0.23, 1.21, 0.35; 0.66, 0.94, 0.13; 0.66, -0.12, -0.06; ... 2.09, 1.33, -0.71; 1.50, 0.08, -0.52; 0.59, 0.07, -1.13; ... -1.17, -0.35, -1.28; 0.68, 0.63, -0.80; -0.69, 0.08, 0.41; ... 2.04, 0.96, -0.56]; yp = [5 2 0 3 1 1 0 1 2 1 3 0 0 1 1 3]'; yb = [1 1 1 0 0 1 1 1 1 1 1 0 0 0 0 1]'; ***** test ## Poisson fit: coefficients, deviance, log-likelihood, AIC. mdl = fitglm (X, yp, "Distribution", "poisson"); assert_equal (mdl.Coefficients.Estimate, ... [-0.3420955; 1.2804868; -1.0743272; 0.8395779], 1e-6); assert_equal (mdl.Deviance, 7.403008, 1e-5); assert_equal (mdl.LogLikelihood, -18.543280, 1e-5); assert_equal (mdl.ModelCriterion.AIC, 45.086559, 1e-5); assert_equal (mdl.Rsquared.Deviance, 0.6627677, 1e-6); ***** test ## coefTest reports a Wald F statistic versus the constant model. mdl = fitglm (X, yp, "Distribution", "poisson"); [p, F, df] = coefTest (mdl); assert_equal (F, 3.685312, 1e-5); assert_equal (p, 0.04331745, 1e-7); assert_equal (df, 3); ***** test ## coefCI uses the t distribution with the error degrees of freedom. mdl = fitglm (X, yp, "Distribution", "poisson"); ci = coefCI (mdl); b = mdl.Coefficients.Estimate; se = mdl.Coefficients.SE; t = tinv (0.975, mdl.DFE); assert_equal (ci, [b - t .* se, b + t .* se], 1e-12); ***** test ## devianceTest chi-square equals the drop from the null deviance. mdl = fitglm (X, yp, "Distribution", "poisson"); dt = devianceTest (mdl); assert_equal (dt.chi2Stat(2), dt.Deviance(1) - dt.Deviance(2), 1e-10); ***** test ## An interaction model names the cross term x1:x2. mdl = fitglm (X, yp, "interactions", "Distribution", "poisson"); assert_equal (any (strcmp (mdl.CoefficientNames, "x1:x2")), true); assert_equal (mdl.NumCoefficients, 7); ***** test ## Leverage sums to the number of coefficients. mdl = fitglm (X, yb, "Distribution", "binomial"); assert_equal (sum (mdl.Diagnostics.Leverage), mdl.NumCoefficients, 1e-9); ***** test # plotting methods and random run without error mdl = fitglm (X, yp, "Distribution", "poisson"); hf = figure ("visible", "off"); unwind_protect plotResiduals (mdl); plotResiduals (mdl, "fitted", "ResidualType", "Pearson"); plotDiagnostics (mdl); plotDiagnostics (mdl, "cookd"); plotEffects (mdl); plotAdjustedResponse (mdl, 1); plotAdded (mdl, "x2"); assert_equal (numel (random (mdl)), 16); unwind_protect_cleanup close (hf); end_unwind_protect ***** error fitglm () ***** error ... fitglm ("a", [1;2]) ***** error ... fitglm ([1, 2; 3, 4], [1; 0], 'Distribution', 'wibble') ***** error ... fitglm ([1, 2; 3, 4], [1; 0], 'linear', 'foo', 1) 11 tests, 11 passed, 0 known failure, 0 skipped [inst/Regression/lasso.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/lasso.m ***** demo ## Lasso path drives coefficients to zero as the penalty grows rng (42); X = rand (50, 6); b = [3; 0; -2; 0; 1.5; 0]; y = X * b + 0.1 * randn (50, 1); [B, FitInfo] = lasso (X, y); plot (log (FitInfo.Lambda), B'); xlabel ("log (Lambda)"); ylabel ("coefficient"); ***** shared X, y n = 20; X = zeros (n, 6); for j = 1:6 X(:,j) = mod ((1:n)' * j, 7) + cos ((1:n)' * j); endfor y = X * [3;0;-2;0;1.5;0] + 0.1 * sin ((1:n)' * 3); ***** test # MATLAB parity: coefficients and intercept at explicit Lambda (lasso) lam = [2 1 0.5 0.2 0.1 0.05 0.01]; [B, I] = lasso (X, y, "Lambda", lam); assert_equal (B(:,1), [2.99553372017526; 0; -1.99263231698882; ... 0.00211715208971491; 1.49324410153201; 0], 1e-3); assert_equal (B(:,7), [2.23897682145602; 0; -0.482753193552206; ... 0.0267252048528861; 0.118128986514695; 0], 1e-3); assert_equal (I.Intercept(1), 0.00566677333597632, 1e-3); assert_equal (I.Intercept(7), 2.00069783707236, 1e-3); assert_equal (I.DF, [4 4 4 4 4 4 4]); assert_equal (I.MSE(1), 0.00590963740808093, 1e-3); ***** test # MATLAB parity: Lambda is ascending and columns follow it [B, I] = lasso (X, y, "Lambda", [2 1 0.5 0.2 0.1 0.05 0.01]); assert_equal (I.Lambda, [0.01 0.05 0.1 0.2 0.5 1 2], 1e-12); assert_equal (issorted (I.Lambda), true); ***** test # MATLAB parity: default path endpoints and length [B, I] = lasso (X, y); assert_equal (I.Lambda(end), 7.18535290566157, 1e-4); assert_equal (I.Lambda(1), 0.119858910419061, 1e-4); assert_equal (numel (I.Lambda), 45); ***** test # MATLAB parity: elastic net (Alpha = 0.5) B = lasso (X, y, "Lambda", [2 1 0.5 0.2 0.1 0.05 0.01], "Alpha", 0.5); assert_equal (B(:,1), [2.945477; -0.009332; -1.940313; ... 0.053970; 1.485977; -0.049272], 2e-3); ***** test # MATLAB parity: Standardize = false [B, I] = lasso (X, y, "Lambda", [2 1 0.5 0.2 0.1 0.05 0.01], ... "Standardize", false); assert_equal (B(:,1), [2.99774227822918; 0; -1.99668154187853; ... 0.00196231656035102; 1.49691209089871; 0], 2e-3); ***** test # at Lambda -> 0 the lasso solution approaches least squares B = lasso (X, y, "Lambda", [1 0.1 0.001]); # columns ascend in Lambda bols = regress (y - mean (y), (X - mean (X))); assert_equal (B(:,1), bols, 1e-2); # smallest Lambda ~ OLS ***** test # a large Lambda drives all coefficients to exactly zero B = lasso (X, y, "Lambda", 100); assert_equal (B, zeros (6, 1)); ***** test # DFmax limits the number of non-zero coefficients on the path [B, I] = lasso (X, y, "DFmax", 2); assert_equal (all (I.DF <= 2), true); ***** test # cross-validation adds the selection fields and they are consistent rand ("seed", 7); [B, I] = lasso (X, y, "CV", 5); assert_equal (numel (I.MSE), numel (I.Lambda)); assert_equal (numel (I.SE), numel (I.Lambda)); assert_equal (all (I.SE >= 0), true); assert_equal (I.LambdaMinMSE, I.Lambda(I.IndexMinMSE), 1e-12); assert_equal (I.Lambda1SE, I.Lambda(I.Index1SE), 1e-12); assert_equal (I.Index1SE >= I.IndexMinMSE, true); # 1-SE picks a larger Lambda assert_equal (I.MSE(I.IndexMinMSE), min (I.MSE), 1e-12); ***** test # cross-validated MSE at the min is within one SE at the 1-SE lambda rand ("seed", 3); [~, I] = lasso (X, y, "CV", 4, "MCReps", 2); thr = I.MSE(I.IndexMinMSE) + I.SE(I.IndexMinMSE); assert_equal (I.MSE(I.Index1SE) <= thr + 1e-9, true); ***** warning ... lasso (X, y, "Lambda", 0.1, "Intercept", false); ***** test # a row vector Y is taken as a column Xr = [1 2; 2 1; 3 5; 4 3; 5 6; 6 4]; yr = [1.1 1.9 3.2 3.9 5.1 6.2]; assert_equal (lasso (Xr, yr, "Lambda", 0.1), lasso (Xr, yr', "Lambda", 0.1)); ***** error lasso (1) ***** error ... lasso ([1 2; 3 4], [1 2 3]') ***** error lasso (X, y, "Alpha", 0) ***** error ... lasso (X, y, "Lambda", [-1 2]) 16 tests, 16 passed, 0 known failure, 0 skipped [inst/Regression/fitcox.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/fitcox.m ***** demo ## Fit a Cox proportional hazards model to right-censored survival times X = [2 0; 5 1; 3 0; 8 1; 4 0; 7 1; 6 0; 9 1; 5 0; 10 1]; T = [4; 6; 8; 11; 13; 16; 18; 21; 25; 30]; C = [0; 0; 1; 0; 0; 1; 0; 0; 1; 0]; mdl = fitcox (X, T, 'Censoring', C) ***** demo ## The hazard of each observation relative to the average one X = [2 0; 5 1; 3 0; 8 1; 4 0; 7 1; 6 0; 9 1; 5 0; 10 1]; T = [4; 6; 8; 11; 13; 16; 18; 21; 25; 30]; mdl = fitcox (X, T); hazardratio (mdl, X) ***** demo ## Each stratum carries its own baseline hazard X = [2 0; 5 1; 3 0; 8 1; 4 0; 7 1; 6 0; 9 1; 5 0; 10 1]; T = [4; 6; 8; 11; 13; 16; 18; 21; 25; 30]; S = [1; 1; 1; 1; 1; 2; 2; 2; 2; 2]; mdl = fitcox (X, T, 'Stratification', S); mdl.Baseline ***** shared X, T, C, S X = [2 0; 5 1; 3 0; 8 1; 4 0; 7 1; 6 0; 9 1; 5 0; 10 1]; T = [4; 6; 8; 11; 13; 16; 18; 21; 25; 30]; C = [0; 0; 1; 0; 0; 1; 0; 0; 1; 0]; S = [1; 1; 1; 1; 1; 2; 2; 2; 2; 2]; ***** test mdl = fitcox (X, T); assert_equal (class (mdl), 'CoxModel'); assert_equal (mdl.Coefficients.Beta, ... [-1.3886093196382836; 4.3814437183613322], 1e-8); ***** test mdl = fitcox (X, T, 'Censoring', C); [b, logl] = coxphfit (X, T, 'Censoring', C); assert_equal (mdl.Coefficients.Beta, b, 1e-12); assert_equal (mdl.LogLikelihood, logl, 1e-12); ***** test mdl = fitcox (X, T, 'Censoring', C, 'TieBreakMethod', 'efron'); b = coxphfit (X, T, 'Censoring', C, 'Ties', 'efron'); assert_equal (mdl.Coefficients.Beta, b, 1e-12); ***** test mdl = fitcox (X, T, 'Censoring', C, 'Stratification', S); b = coxphfit (X, T, 'Censoring', C, 'Strata', S); assert_equal (mdl.Coefficients.Beta, b, 1e-12); ***** test mdl = fitcox (X, T, 'Beta', [0.1; -0.1]); b = coxphfit (X, T, 'B0', [0.1; -0.1]); assert_equal (mdl.Coefficients.Beta, b, 1e-12); ***** test tbl = table (X(:,1), X(:,2), T, 'VariableNames', {'age', 'trt', 'time'}); mdl = fitcox (tbl, 'time'); assert_equal (mdl.PredictorNames, {'age', 'trt'}); assert_equal (mdl.ResponseName, 'time'); assert_equal (char (mdl.Formula), 'time ~ age + trt'); assert_equal (mdl.Coefficients.Beta, ... [-1.3886093196382836; 4.3814437183613322], 1e-8); ***** test g = categorical ({'a'; 'b'; 'a'; 'b'; 'a'; 'b'; 'a'; 'b'; 'a'; 'b'}); tbl = table (X(:,1), g, T, 'VariableNames', {'age', 'grp', 'time'}); mdl = fitcox (tbl, 'time'); assert_equal (mdl.PredictorNames, {'age', 'grp'}); assert_equal (mdl.Coefficients.Properties.RowNames, {'age'; 'grp_b'}); assert_equal (mdl.Coefficients.Beta, ... [-1.3886093196382836; 4.3814437183613322], 1e-8); assert_equal (mdl.Baseline, [5.9, 0], 1e-12); assert_equal (mdl.VariableInfo.IsCategorical, [false; true; false]); ***** error fitcox (1) ***** error ... fitcox (table ([1; 2], [3; 4]), 'time') 9 tests, 9 passed, 0 known failure, 0 skipped [inst/Regression/lassoglm.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/lassoglm.m ***** demo ## Logistic regression with a lasso penalty on a small binary dataset. X = [0.1, 1.2; 0.4, 0.7; 1.1, 0.2; 1.5, 1.9; 0.3, 0.5; 1.8, 1.1]; y = [0; 0; 1; 1; 0; 1]; [B, FitInfo] = lassoglm (X, y, 'binomial', 'Lambda', [0.01, 0.1]) ***** demo ## Poisson (count) regression with an elastic-net penalty. X = [0.1, 1.2; 0.4, 0.7; 1.1, 0.2; 1.5, 1.9; 0.3, 0.5; 1.8, 1.1; 0.9, 0.3]; y = [1; 0; 2; 3; 1; 4; 2]; [B, FitInfo] = lassoglm (X, y, 'poisson', 'Lambda', [0.05, 0.2], ... 'Alpha', 0.6) ***** demo ## Choosing the penalty by cross-validation. Passing a 'CV' fold count makes ## lassoglm cross-validate the deviance along the lambda path. It then ## reports the lambda with the lowest mean deviance (LambdaMinDeviance) and ## the largest lambda within one standard error of it (Lambda1SE) -- the ## sparser "one-standard-error" model that is often preferred. ## ## Here only the first two of eight predictors truly drive the response, so a ## good fit should keep few nonzero coefficients. The fold assignment is ## random; the seed below just makes the printed numbers reproducible. rng (42); X = randn (60, 8); beta = [1.5; -2; zeros(6, 1)]; y = double (rand (60, 1) < 1 ./ (1 + exp (- X * beta))); [B, FitInfo] = lassoglm (X, y, 'binomial', 'CV', 5); printf ('LambdaMinDeviance = %.4f (%d nonzero)\n', ... FitInfo.LambdaMinDeviance, FitInfo.DF(FitInfo.IndexMinDeviance)); printf ('Lambda1SE = %.4f (%d nonzero)\n', ... FitInfo.Lambda1SE, FitInfo.DF(FitInfo.Index1SE)); ## Coefficients of the one-standard-error model. coef_1SE = B(:, FitInfo.Index1SE) ***** shared X, yb, yp, yn X = [ 0.12, -0.16, 1.35, 0.48; 0.39, 0.72, -0.91, -0.12; ... 0.55, -0.11, -0.28, -0.28; -1.32, 0.80, -1.25, 2.14; ... -0.24, 0.77, -2.62, 0.66; 0.05, 0.70, -1.55, 0.06; ... 1.05, 0.84, -0.16, 0.54; 0.55, -0.50, -0.25, 0.07; ... 0.31, -0.58, -0.77, -0.50; 1.09, 0.44, -0.47, -0.26; ... 1.08, -1.67, 2.08, 0.29; -1.52, 1.51, -2.46, -1.41; ... -0.55, 1.40, -0.59, -0.17; 1.35, -0.16, -0.38, -0.26]; yb = [1 1 1 0 0 1 1 1 1 1 1 0 0 1]'; yp = [1 0 1 1 0 1 1 2 1 1 1 0 0 0]'; yn = [0.7 -0.86 0.21 -1.38 -0.81 -1.16 0.12 1.33 0.87 0.65 4.18 -4.57 ... -2.76 1.51]'; ***** test ## Gaussian lassoglm coincides with lasso and matches MATLAB. [Bg, Fg] = lassoglm (X, yn, "normal", "Lambda", [0.3, 0.1, 0.02]); [Bl, Fl] = lasso (X, yn, "Lambda", [0.3, 0.1, 0.02]); assert_equal (Bg, Bl, 1e-4); assert_equal (Fg.Intercept, Fl.Intercept, 1e-4); ***** test ## Poisson regression against R2024a's own intercept and deviance. The ## coordinate descent converges to a slightly different point, so 1e-4. [B, F] = lassoglm (X, yp, "poisson", "Lambda", [0.2, 0.05, 0.01]); assert_equal (F.Intercept, ... [-0.408479371164708, -0.318644470147402, ... -0.297271780712625], 1e-4); assert_equal (F.Deviance, ... [7.068880870474705, 7.267211985220860, ... 8.458049628150873], 1e-4); assert_equal (F.DF, [3, 3, 1]); ***** test ## Binomial (logistic) regression against R2024a's own values. The ## largest lambda is the loosest fit and agrees least closely, at 5e-4. [B, F] = lassoglm (X, yb, "binomial", "Lambda", [0.2, 0.1, 0.05, 0.01]); assert_equal (F.Intercept, ... [2.282419079745844, 1.388013352791727, ... 0.964941260795408, 0.834029178373540], 1e-3); assert_equal (F.Deviance, ... [1.146705233151688, 3.739184081182877, ... 6.057648047528616, 9.585820201838006], 1e-3); assert_equal (F.DF, [3, 3, 3, 1]); ***** test ## Default path: DF is zero at lambda_max and lambda is ascending. [B, F] = lassoglm (X, yb, "binomial"); assert_equal (F.DF(end), 0); assert_equal (issorted (F.Lambda), true); assert_equal (all (F.Deviance(1:end-1) <= F.Deviance(2:end)), true); ***** test ## Cross-validation adds the expected FitInfo fields and the 1-SE rule ## selects a lambda no smaller than the minimum-deviance lambda. cvp = cvpartition (14, "KFold", 5); [B, F] = lassoglm (X, yb, "binomial", "CV", cvp); assert_equal (isfield (F, "SE") && isfield (F, "LambdaMinDeviance"), true); assert_equal (numel (F.SE), numel (F.Lambda)); assert_equal (F.Lambda1SE >= F.LambdaMinDeviance, true); assert_equal (F.Index1SE >= F.IndexMinDeviance, true); ***** error lassoglm (1) ***** error lassoglm ("a", [1;2]) ***** error lassoglm ([1, 2; 3, 4], "a") ***** error ... lassoglm ([1, 2; 3, 4], [1; 2; 3]) ***** error ... lassoglm ([1, 2; 3, 4], [1; 0], 'wibble') ***** error ... lassoglm ([1, 2; 3, 4], [1; -1], 'poisson') ***** error ... lassoglm ([1, 2; 3, 4], [1; 0], 'gamma') ***** error ... lassoglm ([1, 2; 3, 4], [1; 3], 'binomial') ***** error ... lassoglm ([1, 2; 3, 4], [1; 0], 'binomial', 'Offset', [1, 2, 3]) ***** error ... lassoglm ([1, 2; 3, 4], [1; 0], 'binomial', 'Alpha', 0) ***** error ... lassoglm ([1, 2; 3, 4], [1; 0], 'binomial', 'Lambda', -1) ***** error ... lassoglm ([1, 2; 3, 4], [1; 0], 'binomial', 'Lambda') ***** error ... lassoglm ([1, 2; 3, 4], [1; 0], 'binomial', 'foo', 1) 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Regression/robustfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/robustfit.m ***** demo ## Robust fit is resistant to an outlier that pulls the OLS line x = (1:10)'; y = 2 * x + 1; y(10) = 0; # an outlier b_ols = regress (y, [ones(10,1), x]); b_rob = robustfit (x, y); plot (x, y, "o", x, [ones(10,1) x]*b_ols, "r-", ... x, [ones(10,1) x]*b_rob, "b-"); legend ("data", "OLS", "robust", "location", "northwest"); ***** shared X, y X = [1;2;3;4;5;6;7;8;9;10]; y = [3.1;5.2;6.9;9.1;11.0;12.9;15.2;17.1;19.0;5.0]; ***** test # MATLAB parity: bisquare coefficients and exact stats fields [b, st] = robustfit (X, y); assert_equal (b, [1.08223788958791; 1.9947584179332], 1e-8); assert_equal (st.ols_s, 4.58673317428878, 1e-8); assert_equal (st.mad_s, 0.219326216641263, 1e-8); assert_equal (st.dfe, 8); assert_equal (st.h(1), 0.345454545454545, 1e-9); assert_equal (st.w(10), 0, 1e-10); assert_equal (st.resid(10), -16.0298220689199, 1e-6); ***** test # MATLAB parity: standard errors, t, p within a fraction of a percent [b, st] = robustfit (X, y); assert_equal (st.s, 2.45430591997485, 5e-3); assert_equal (st.se, [1.67661012843903; 0.270210188642742], 2e-3); assert_equal (st.t, [0.64549168064224; 7.38224723483898], 5e-3); assert_equal (st.p, [0.536678473587217; 7.75017584465372e-05], 5e-3); assert_equal (st.covb, [2.81102152278434, -0.401574503254905; ... -0.401574503254905, 0.0730135460463465], 1e-2); ***** test # weight-function coefficients match MATLAB assert_equal (robustfit (X, y, "huber"), ... [1.13942072329047; 1.97894586334502], 1e-6); assert_equal (robustfit (X, y, "andrews"), ... [1.08226666865865; 1.99475428605778], 1e-6); assert_equal (robustfit (X, y, "cauchy"), ... [1.08721258646419; 1.99357974946387], 1e-6); assert_equal (robustfit (X, y, "fair"), ... [1.25156505474148; 1.94736889966414], 1e-6); assert_equal (robustfit (X, y, "logistic"), ... [1.14596301338789; 1.9773188568744], 1e-6); assert_equal (robustfit (X, y, "talwar"), [1.08055555555555; 1.995], 1e-6); assert_equal (robustfit (X, y, "welsch"), ... [1.08260376495793; 1.99470613677464], 1e-6); ***** test # 'ols' weight reproduces ordinary least squares assert_equal (robustfit (X, y, "ols"), regress (y, [ones(10,1), X]), 1e-10); ***** test # custom tuning constant and const='off' assert_equal (robustfit (X, y, "bisquare", 3), ... [1.08512259456964; 1.99435302345156], 1e-6); [b, st] = robustfit (X, y, "bisquare", 4.685, "off"); assert_equal (b, 2.16460032959659, 1e-6); assert_equal (st.dfe, 9); ***** test # MATLAB parity: an exactly zero residual weighs 1, not 0 ## andrews and logistic are w = sin (z) / z and tanh (z) / z, both 0/0 at ## the origin. With no constant term the middle residual is exactly zero ## whatever the coefficient, so this reaches the limit every time. xz = [-1; 0; 1]; yz = [-2; 0; 3]; [bz, sz] = robustfit (xz, yz, "andrews", [], "off"); assert_equal (sz.resid(2), 0); assert_equal (sz.w, [0.958241991423609; 1; 0.958241991423609], 1e-12); [bz, sz] = robustfit (xz, yz, "logistic", [], "off"); assert_equal (sz.resid(2), 0); assert_equal (sz.w, [0.907175968590982; 1; 0.907175968590982], 1e-12); ***** test # a planted outlier is downweighted relative to OLS x = (1:20)'; yy = 3 * x - 5; yy(7) = yy(7) + 100; b = robustfit (x, yy); assert_equal (b, [-5; 3], 0.1); ***** test # missing observations are dropped, weights padded with NaN x = (1:10)'; yy = 2*x + 1; yy(4) = NaN; [b, st] = robustfit (x, yy); assert_equal (b, [1; 2], 1e-8); assert_equal (isnan (st.w(4)), true); assert_equal (st.dfe, 7); ***** test xf = [-2; -1; 0; 1; 2]; yf = 3 * xf; [bf, stats] = robustfit (xf, yf, 'andrews', [], 'off'); assert_equal (bf, 3, 1e-12); assert_equal (stats.w, ones (5, 1), 1e-8); ***** test xf = [-2; -1; 0; 1; 2]; yf = 3 * xf + 1e-6 * [1; -1; 0; 1; -1]; [bf, stats] = robustfit (xf, yf, 'andrews', [], 'off'); assert_equal (stats.w', [0.997523, 0.993403, 1, 0.993403, 0.997523], 1e-6); ***** test xf = [-2; -1; 0; 1; 2]; yf = 3 * xf + 1e-3 * [1; -1; 0; 1; -1]; [bf, stats] = robustfit (xf, yf, 'andrews', [], 'off'); assert_equal (stats.w', [0.958242, 0.868203, 1, 0.868203, 0.958242], 1e-6); ***** test xf = [1; 2; 3; 4; 5; 6]; yf = [1.1 1.9 3.2 3.9 5.1 6.2]; assert_equal (robustfit (xf, yf), robustfit (xf, yf')); ***** error robustfit (1) ***** error ... robustfit ([1;2;3], [1;2]) ***** error ... robustfit (X, y, "foo") ***** error ... robustfit (X, y, "huber", -1) ***** error ... robustfit (X, y, "huber", 1.345, "maybe") ***** error ... robustfit ([], []) ***** error ... robustfit (zeros (0, 3), zeros (0, 1)) 19 tests, 19 passed, 0 known failure, 0 skipped [inst/Regression/LinearFormula.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/LinearFormula.m ***** demo ## The Formula property of a fitted model is a LinearFormula object. x1 = [1 2 3 4 5 6 7 8]'; x2 = [2 1 4 3 6 5 8 7]'; y = [3.1 4.2 5.3 6.4 7.5 8.6 9.7 10.8]'; mdl = fitlm ([x1, x2], y, 'interactions'); f = mdl.Formula ## Rendering it as text gives back the whole formula, response included, ## while the LinearPredictor property holds the right-hand side alone. char (f) f.LinearPredictor ## A pair of variables present both on their own and as their interaction ## is written as a product. f.TermNames f.Terms ***** demo ## A formula can also be built directly from a terms matrix. Each column is ## a variable and each entry the power it carries in that term; the all-zero ## row is the intercept and the response keeps a column of its own. terms = [0 0 0; 1 0 0; 0 1 0; 1 1 0]; f = LinearFormula (terms, {'dose', 'age', 'score'}, ... 'ResponseName', 'score') f.PredictorNames f.InModel ***** test f = LinearFormula ([0 0 0; 1 0 0; 0 1 0], {'u', 'g', 'resp'}, ... 'ResponseName', 'resp'); assert_equal (f.ResponseName, 'resp'); assert_equal (f.VariableNames, {'u', 'g', 'resp'}); assert_equal (f.PredictorNames, {'u', 'g'}); assert_equal (f.TermNames, {'(Intercept)'; 'u'; 'g'}); assert_equal (f.Terms, [0 0 0; 1 0 0; 0 1 0]); assert_equal (f.InModel, [true, true, false]); assert_equal (f.HasIntercept, true); assert_equal (f.LinearPredictor, '1 + u + g'); assert_equal (f.NTerms, 3); assert_equal (f.NVars, 3); assert_equal (f.NPredictors, 2); assert_equal (f.Link, 'identity'); assert_equal (f.FunctionCalls, cell (1, 0)); ***** test # the response takes no part in the model f = LinearFormula ([0 0 0 0; 1 0 0 0; 0 0 1 0], {'u', 'v', 'w', 'resp'}, ... 'ResponseName', 'resp'); assert_equal (f.InModel, [true, false, true, false]); assert_equal (f.PredictorNames, {'u', 'w'}); assert_equal (f.NPredictors, 2); assert_equal (f.NVars, 4); ***** test # an empty formula is renderable f = LinearFormula (); assert_equal (char (f), ''); assert_equal (f.NTerms, 0); assert_equal (f.HasIntercept, false); ***** test # char gives the whole formula, LinearPredictor the right-hand side f = LinearFormula ([0 0 0; 1 0 0; 0 1 0], {'u', 'g', 'resp'}, ... 'ResponseName', 'resp'); assert_equal (char (f), 'resp ~ 1 + u + g'); assert_equal (f.LinearPredictor, '1 + u + g'); ***** test # a pair present on its own and as an interaction reads as a product f = LinearFormula ([0 0 0; 1 0 0; 0 1 0; 1 1 0], {'u', 'v', 'resp'}, ... 'ResponseName', 'resp'); assert_equal (char (f), 'resp ~ 1 + u*v'); ***** test # a product needs both main effects; without one the term stands alone f = LinearFormula ([0 0 0; 1 0 0; 1 1 0], {'u', 'v', 'resp'}, ... 'ResponseName', 'resp'); assert_equal (char (f), 'resp ~ 1 + u + u:v'); ***** test # only pairs collapse, never a three-way interaction terms = [0 0 0 0; 1 0 0 0; 0 1 0 0; 0 0 1 0; ... 1 1 0 0; 1 0 1 0; 0 1 1 0; 1 1 1 0]; f = LinearFormula (terms, {'u', 'v', 'w', 'resp'}, ... 'ResponseName', 'resp'); assert_equal (char (f), 'resp ~ 1 + u*v + u*w + v*w + u:v:w'); ***** test # a power is never written as a product f = LinearFormula ([0 0 0; 1 0 0; 0 1 0; 1 1 0; 2 0 0; 0 2 0], ... {'u', 'v', 'resp'}, 'ResponseName', 'resp'); assert_equal (char (f), 'resp ~ 1 + u*v + u^2 + v^2'); assert_equal (f.TermNames, ... {'(Intercept)'; 'u'; 'v'; 'u:v'; 'u^2'; 'v^2'}); ***** test # dropping the intercept drops the leading 1 f = LinearFormula ([1 0 0; 0 1 0], {'u', 'g', 'resp'}, ... 'ResponseName', 'resp'); assert_equal (char (f), 'resp ~ u + g'); assert_equal (f.HasIntercept, false); ***** test # an intercept-only model f = LinearFormula ([0 0 0], {'u', 'g', 'resp'}, 'ResponseName', 'resp'); assert_equal (char (f), 'resp ~ 1'); assert_equal (f.TermNames, {'(Intercept)'}); assert_equal (f.NPredictors, 0); assert_equal (f.PredictorNames, cell (1, 0)); ***** test # string renders the same text as char f = LinearFormula ([0 0; 1 0], {'u', 'resp'}, 'ResponseName', 'resp'); s = string (f); assert_equal (class (s), 'string'); assert_equal (char (s), char (f)); ***** test # disp writes the rendered formula f = LinearFormula ([0 0; 1 0], {'u', 'resp'}, 'ResponseName', 'resp'); s = evalc ('disp (f)'); assert_equal (strtrim (s), 'resp ~ 1 + u'); ***** test # a named link f = LinearFormula ([0 0 0; 1 0 0; 0 1 0], {'u', 'g', 'yb'}, ... 'ResponseName', 'yb', 'Link', 'logit'); assert_equal (char (f), 'logit(yb) ~ 1 + u + g'); assert_equal (f.Link, 'logit'); ***** test # the identity link leaves the response alone, named or as an exponent f = LinearFormula ([0 0; 1 0], {'u', 'y'}, 'ResponseName', 'y', ... 'Link', 'identity'); assert_equal (char (f), 'y ~ 1 + u'); f = LinearFormula ([0 0; 1 0], {'u', 'y'}, 'ResponseName', 'y', 'Link', 1); assert_equal (char (f), 'y ~ 1 + u'); ***** test # a numeric link is shown as a power f = LinearFormula ([0 0; 1 0], {'u', 'y'}, 'ResponseName', 'y', 'Link', -2); assert_equal (char (f), 'power(y,-2) ~ 1 + u'); ***** test # a link given as a structure of handles is named generically lk = struct ('Link', @(x) x, 'Derivative', @(x) 1, 'Inverse', @(x) x); f = LinearFormula ([0 0; 1 0], {'u', 'y'}, 'ResponseName', 'y', ... 'Link', lk); assert_equal (char (f), 'link(y) ~ 1 + u'); ***** test # ModelFun and FunctionCalls are carried through fun = @(b, X) X * b; f = LinearFormula ([0 0; 1 0], {'u', 'y'}, 'ResponseName', 'y', ... 'ModelFun', fun, 'FunctionCalls', {'log'}); assert_equal (func2str (f.ModelFun), func2str (fun)); assert_equal (f.FunctionCalls, {'log'}); ***** test # option names are matched without regard to case f = LinearFormula ([0 0; 1 0], {'u', 'y'}, 'responsename', 'y', ... 'LINK', 'log'); assert_equal (char (f), 'log(y) ~ 1 + u'); ***** error ... LinearFormula ([0 0]) ***** error ... LinearFormula ('abc', {'u', 'y'}) ***** error ... LinearFormula ([1+2i, 0], {'u', 'y'}) ***** error ... LinearFormula ([0 0], 'uy') ***** error ... LinearFormula ([0 0], {1, 2}) ***** error ... LinearFormula ([0 0 0], {'u', 'y'}) ***** error ... LinearFormula ([0 0], {'u', 'y'}, 'Link') ***** error ... LinearFormula ([0 0], {'u', 'y'}, 5, 'log') ***** error ... LinearFormula ([0 0], {'u', 'y'}, 'bogus', 1) ***** error ... LinearFormula ([0 0], {'u', 'y'}, 'ResponseName', 5) ***** error ... LinearFormula ([0 0], {'u', 'y'}, 'ResponseName', 'z') 29 tests, 29 passed, 0 known failure, 0 skipped [inst/Regression/LinearModel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/LinearModel.m ***** demo ## Simple linear regression with a single predictor. ## Ten runners record their weekly training distance and their finish ## time in a 10k race. We fit a straight line through this data and ## look at the fitted coefficients, then use predict to estimate the ## finish time for a runner who trains a distance not in the sample. Distance = [10; 15; 20; 25; 30; 35; 40; 45; 50; 55]; Time = [58; 55; 52; 50; 47; 45; 43; 41; 40; 38]; X = Distance; y = Time; ## Fit the model and inspect the estimated slope and intercept. mdl = fitlm (X, y) ## Predict the finish time for a runner training 32 km per week. ypred = predict (mdl, 32) ***** demo ## Multiple linear regression with two predictors, followed by a ## confidence interval on the coefficients. ## Thirteen coffee shops report their weekly foot traffic and the ## number of items on their menu, along with weekly revenue. We fit a ## model with both predictors, then use coefCI to see how precisely ## each coefficient is estimated. Traffic = [120; 150; 90; 200; 175; 60; 220; 140; 100; 190; 80; 210; 130]; MenuSize = [8; 12; 6; 15; 10; 5; 18; 9; 7; 14; 6; 16; 11]; Revenue = [1450; 1820; 1010; 2400; 2050; 700; 2650; 1700; 1150; ... 2300; 900; 2500; 1600]; X = [Traffic, MenuSize]; y = Revenue; ## Fit the model with both predictors together. mdl = fitlm (X, y) ## Check how tight the 95% confidence interval is on each coefficient. ci = coefCI (mdl) ***** demo ## Growing a model with addTerms and predicting with the richer model. ## We model fuel economy from the carsmall data set using weight and ## horsepower as main effects only. addTerms then brings in the ## weight-horsepower interaction without needing to refit by hand, and ## predict shows how the estimate for a new car changes once that ## interaction is included. load carsmall X = [Weight, Horsepower]; y = MPG; ## Fit the additive model first. mdl = fitlm (X, y); ## Add the interaction between weight and horsepower. mdl2 = addTerms (mdl, 'x1:x2'); ## Compare predictions from both models for the same new car. Xnew = [3200, 120]; ypred1 = predict (mdl, Xnew) ypred2 = predict (mdl2, Xnew) ***** demo ## Simplifying a model with removeTerms and comparing fit quality. ## We fit the full Hald cement model with all four ingredients, then ## use removeTerms to drop the weakest predictor and refit ## automatically. Comparing SSE before and after shows how little ## explanatory power that ingredient was actually contributing. load hald X = ingredients; y = heat; ## Fit the model with all four ingredients. mdl = fitlm (X, y); ## Drop the third ingredient and refit on the same data. mdl2 = removeTerms (mdl, 'x3'); ## Compare how much the error sum of squares changed. sse_full = mdl.SSE sse_reduced = mdl2.SSE ***** demo ## Testing a linear hypothesis and checking residual autocorrelation. ## Twelve patients are given a drug at different doses over different ## treatment durations, and a recovery score is recorded. coefTest ## checks whether the dose and duration coefficients are actually ## equal, and dwtest separately checks whether the residuals still ## carry a leftover pattern the model failed to capture. Dose = [10; 15; 20; 25; 30; 35; 12; 18; 22; 28; 32; 38]; Duration = [5; 7; 9; 11; 13; 15; 6; 8; 10; 12; 14; 16]; Recovery = [42; 48; 55; 60; 68; 74; 45; 52; 58; 65; 71; 78]; X = [Dose, Duration]; y = Recovery; mdl = fitlm (X, y); ## Test H0: the Dose and Duration coefficients are equal. H = [0 1 -1]; [p, F, r] = coefTest (mdl, H) ## Check for autocorrelation left over in the residuals. [pdw, dw] = dwtest (mdl) ***** demo ## Checking residuals against fitted values. ## We fit a mileage model on the carsmall data set using weight and ## horsepower, then plot the raw residuals against the fitted values. ## A pattern in this plot, rather than a random scatter, would suggest ## the linear model is missing some curvature in the relationship. load carsmall X = [Weight, Horsepower]; y = MPG; mdl = fitlm (X, y); plotResiduals (mdl, 'fitted') ***** demo ## Spotting influential observations with Cook's distance. ## Sixteen houses are matched by size and age to a sale price, but one ## house was sold far above what its size and age would predict. After ## fitting the model, plotDiagnostics with the cookd option highlights ## that single observation as having outsized influence on the fit. Size = [80; 95; 110; 120; 65; 140; 100; 130; 90; 150; 75; 105; ... 115; 85; 135; 125]; Age = [5; 10; 3; 8; 20; 2; 15; 6; 12; 1; 18; 9; 4; 14; 7; 11]; Price = [200; 230; 260; 280; 150; 320; 240; 300; 210; 340; 170; ... 250; 270; 190; 500; 290]; X = [Size, Age]; y = Price; mdl = fitlm (X, y); plotDiagnostics (mdl, 'cookd') ***** demo ## Comparing the size of each predictor's effect, alongside a ## hypothesis test on the model as a whole. ## We fit a mileage model on the carsmall data set using weight and ## horsepower. plotEffects draws each coefficient's estimate with its ## confidence interval side by side, and coefTest checks whether ## weight's effect is significantly different from horsepower's. load carsmall X = [Weight, Horsepower]; y = MPG; mdl = fitlm (X, y); ## Visualize the relative size of each predictor's effect. plotEffects (mdl) ## Test whether the two coefficients differ significantly. H = [0 1 -1]; [p, F, r] = coefTest (mdl, H) ***** shared mdl, X, y, n n = 20; X = [1:n; (1:n).^2]' / n; y = X * [3; -1] + 0.2 * sin ((1:n)'); mdl = fitlm (X, y); ***** test ## scalar fit-quality assert_equal (mdl.NumObservations, 20); assert_equal (mdl.NumCoefficients, 3); assert_equal (mdl.NumVariables, 3); assert_equal (mdl.NumPredictors, 2); assert_equal (mdl.NumEstimatedCoefficients, 3); assert_equal (mdl.DFE, 17); assert_equal (mdl.SSE, 0.386545331386823, 1e-9); assert_equal (mdl.SSR, 583.523874670959, 1e-6); assert_equal (mdl.SST, 583.910420002346, 1e-6); assert_equal (mdl.MSE, 0.0227379606698351, 1e-10); assert_equal (mdl.RMSE, 0.150791116017606, 1e-10); assert_equal (mdl.Rsquared.Ordinary, 0.999338005765704, 1e-10); assert_equal (mdl.Rsquared.Adjusted, 0.999260124091081, 1e-10); assert_equal (mdl.LogLikelihood, 11.0836133807695, 1e-6); assert_equal (mdl.ModelCriterion.AIC, -16.1672267615389, 1e-6); assert_equal (mdl.ModelCriterion.AICc, -14.6672267615389, 1e-6); assert_equal (mdl.ModelCriterion.BIC, -13.180029940877, 1e-6); assert_equal (mdl.ModelCriterion.CAIC, -10.180029940877, 1e-6); assert_equal (mdl.ModelFitVsNullModel.Fstat, 12831.4909842738, 1e-4); assert_equal (strcmp (mdl.ModelFitVsNullModel.NullModel, 'constant'), true); ***** test ## Steps is empty for a non-stepwise fit, as in GeneralizedLinearModel assert_equal (size (mdl.Steps), [0, 0]); ***** test ## a table column the formula never mentions is not a predictor of the fit xa = (1:n)' / n; xb = cos ((1:n)'); gc = categorical (mod ((1:n)', 3)); Tu = table (xa, xb, gc, y, 'VariableNames', {'xa', 'xb', 'gc', 'y'}); m = fitlm (Tu, 'y ~ xa + xb'); assert_equal (m.PredictorNames, {'xa'; 'xb'}); assert_equal (m.NumPredictors, 2); assert_equal (m.VariableNames, {'xa'; 'xb'; 'gc'; 'y'}); assert_equal (m.NumVariables, 4); assert_equal (m.VariableInfo.InModel', [true, true, false, false]); ***** test ## the unused variable being categorical no longer breaks type 3 sums of ## squares, which indexed past the end of the encoded matrix xa = (1:n)' / n; xb = cos ((1:n)'); gc = categorical (mod ((1:n)', 3)); Tu = table (xa, xb, gc, y, 'VariableNames', {'xa', 'xb', 'gc', 'y'}); m = fitlm (Tu, 'y ~ xa + xb'); t = anova (m, 'components', 3); assert_equal (t.Properties.RowNames, {'xa'; 'xb'; 'Error'}); assert_equal (numel (t.SumSq), 3); ***** test ## a model fit with no predictors at all reports none mc = fitlm (X, y, 'constant'); assert_equal (isempty (mc.PredictorNames), true); assert_equal (mc.NumPredictors, 0); assert_equal (any (mc.VariableInfo.InModel), false); ***** test ## a terms matrix that zeroes a predictor out drops it, as a formula does mt = fitlm (X, y, [0 0 0; 1 0 0]); mf = fitlm (X, y, 'y ~ x1'); assert_equal (mt.PredictorNames, {'x1'}); assert_equal (mt.NumPredictors, 1); assert_equal (mt.VariableInfo.InModel', [true, false, false]); assert_equal (mf.PredictorNames, {'x1'}); assert_equal (mf.NumPredictors, 1); ***** test ## a predictor reached only through an interaction is used, and stays mi = fitlm (X, y, 'y ~ x1 + x1:x2'); assert_equal (mi.PredictorNames, {'x1'; 'x2'}); assert_equal (mi.NumPredictors, 2); assert_equal (mi.VariableInfo.InModel', [true, true, false]); ***** test ## addTerms and stepwise selection search the candidates, not the chosen mc = fitlm (X, y, 'constant'); m1 = addTerms (mc, 'x1'); assert_equal (m1.PredictorNames, {'x1'}); assert_equal (m1.NumCoefficients, 2); ***** test ## constant-only model: SSR is exactly zero, SSE equals SST mc = fitlm (X, y, 'constant'); assert_equal (mc.SSE, 583.910420002346, 1e-6); assert_equal (mc.SSR, 0, 1e-12); assert_equal (mc.SSE, mc.SST, 1e-12); ***** test ## coefficient estimates, SE, tStat, names, covariance, schema assert_equal (mdl.Coefficients.Estimate, [0.1161886778; 2.508451491; -0.9788353298], 1e-7); assert_equal (mdl.Coefficients.SE, [0.112185831; 0.4920818186; 0.02276108523], 1e-8); assert_equal (mdl.Coefficients.tStat, [1.035680502; 5.097630913; -43.00477415], 1e-6); assert_equal (all (mdl.Coefficients.pValue >= 0 & mdl.Coefficients.pValue <= 1), true); assert_equal (isequal (mdl.CoefficientNames, {'(Intercept)', 'x1', 'x2'}), true); assert_equal (isequal (mdl.CoefficientNames, mdl.Coefficients.Properties.RowNames(:)'), true); assert_equal (size (mdl.CoefficientCovariance), [3, 3]); assert_equal (diag (mdl.CoefficientCovariance), [0.0125857; 0.242145; 0.000518067], 1e-6); assert_equal (width (mdl.Coefficients), 4); assert_equal (isequal (mdl.Coefficients.Properties.VariableNames, ... {'Estimate','SE','tStat','pValue'}), true); ***** test ## fitted values, predict(), residual columns (obs 1-3), schema assert_equal (mdl.Fitted, y - mdl.Residuals.Raw, 1e-10); yp = predict (mdl, X); assert_equal (size (yp), [20, 1]); assert_equal (yp(1), 0.192669485827491, 1e-10); assert_equal (yp(2), 0.171266760882256, 1e-10); assert_equal (mdl.Residuals.Raw(1:3), [0.075624711134088; 0.110592724482880; -0.023756501342530], 1e-10); assert_equal (mdl.Residuals.Pearson(1:3), [0.501519672586403; 0.733416711830473; -0.157545762442370], 1e-9); assert_equal (mdl.Residuals.Standardized(1:3), [0.632246516521578; 0.844226394951239; -0.172381368754725], 1e-8); assert_equal (mdl.Residuals.Studentized(1:3), [0.620710275056923; 0.836747864205268; -0.167380843634378], 1e-6); assert_equal (width (mdl.Residuals), 4); assert_equal (isequal (mdl.Residuals.Properties.VariableNames, ... {'Raw','Pearson','Studentized','Standardized'}), true); ***** test ## diagnostics H = mdl.Diagnostics.HatMatrix; assert_equal (size (H), [20, 20]); assert_equal (H, H', 1e-10); assert_equal (H * H, H, 1e-8); assert_equal (H(1,1), 0.370779220779221, 1e-10); assert_equal (H(1,2), 0.298051948051948, 1e-10); assert_equal (mdl.Diagnostics.Leverage(1:3), [0.370779220779221; 0.245283663704716; 0.164718614718615], 1e-10); assert_equal (mdl.Diagnostics.CooksDistance(1:3), [0.078517048682575; 0.077211407930332; 0.001953301452841], 1e-8); assert_equal (mdl.Diagnostics.S2_i(1:3), [0.023591009857798; 0.023146223303229; 0.024116854077430], 1e-8); assert_equal (mdl.Diagnostics.CovRatio(1:3), [1.774933176573401; 1.397661919176034; 1.428481535363283], 1e-6); assert_equal (mdl.Diagnostics.Dffits(1:3), [0.476480465355394; 0.477020506700835; -0.074329411030064], 1e-6); assert_equal (size (mdl.Diagnostics.Dfbetas), [20, 3]); assert_equal (width (mdl.Diagnostics), 7); assert_equal (isequal (mdl.Diagnostics.Properties.VariableNames, ... {'Leverage','CooksDistance','Dffits','S2_i', ... 'CovRatio','Dfbetas','HatMatrix'}), true); ***** test ## ObservationInfo, VariableInfo, names, Formula, Variables assert_equal (width (mdl.ObservationInfo), 4); assert_equal (height (mdl.ObservationInfo), 20); assert_equal (isequal (mdl.ObservationInfo.Properties.VariableNames, ... {'Weights','Excluded','Missing','Subset'}), true); assert_equal (all (mdl.ObservationInfo.Weights == 1), true); assert_equal (all (mdl.ObservationInfo.Subset == ... (! mdl.ObservationInfo.Missing & ! mdl.ObservationInfo.Excluded)), true); assert_equal (width (mdl.VariableInfo), 4); assert_equal (height (mdl.VariableInfo), 3); assert_equal (isequal (mdl.VariableInfo.Properties.VariableNames, ... {'Class','Range','InModel','IsCategorical'}), true); assert_equal (mdl.VariableInfo.InModel(strcmp (mdl.VariableNames, 'y')), false); assert_equal (all (mdl.VariableInfo.InModel(! strcmp (mdl.VariableNames, 'y'))), true); assert_equal (mdl.ResponseName, 'y'); assert_equal (isequal (mdl.PredictorNames, {'x1';'x2'}), true); assert_equal (isequal (mdl.VariableNames, {'x1';'x2';'y'}), true); assert_equal (mdl.Formula.HasIntercept, true); assert_equal (mdl.Formula.LinearPredictor, '1 + x1 + x2'); assert_equal (mdl.Formula.NTerms, 3); assert_equal (strcmp (mdl.Variables.Properties.VariableNames{end}, 'y'), true); ***** test ## NaN in predictor drops the row from the fit X2 = X; X2(2,1) = NaN; m = fitlm (X2, y); assert_equal (m.NumObservations, 19); assert_equal (m.ObservationInfo.Missing(2), true); assert_equal (m.ObservationInfo.Subset(2), false); assert_equal (isnan (m.Fitted(2)), true); assert_equal (m.SSE, 0.370339572851658, 1e-9); assert_equal (m.SST, 547.616796178045, 1e-6); assert_equal (m.Coefficients.Estimate, ... [0.0641300185953764; 2.68263140079657; -0.985345792254554], 1e-7); yp = predict (m, X2); assert_equal (isnan (yp(2)), true); assert_equal (! isnan (yp(1)), true); assert_equal (size (m.Diagnostics.HatMatrix), [20, 20]); assert_equal (m.Diagnostics.Leverage(1), 0.488485648300892, 1e-8); assert_equal (m.Diagnostics.CooksDistance(1), 0.38266162627176, 1e-6); ***** test ## NaN in response drops the row but predict still works normally since X has no NaN y3 = y; y3(5) = NaN; m = fitlm (X, y3); assert_equal (m.NumObservations, 19); assert_equal (m.ObservationInfo.Missing(5), true); assert_equal (m.Fitted(5), -0.457777594993880, 1e-10); assert_equal (isnan (m.Residuals.Raw(5)), true); assert_equal (m.SSE, 0.337042910721425, 1e-9); assert_equal (m.SST, 558.654961265991, 1e-6); assert_equal (m.Coefficients.Estimate, ... [0.145131680993155; 2.4865383021829; -0.979635081226208], 1e-7); yp = predict (m, X); assert_equal (yp(5), -0.45777759499388, 1e-8); assert_equal (yp(1), 0.22047684204099, 1e-8); assert_equal (m.Fitted, yp, 1e-12); assert_equal (size (m.Diagnostics.HatMatrix), [20, 20]); assert_equal (m.Diagnostics.Leverage(1), 0.386399650026734, 1e-8); ***** test ## multiple NaN rows drop all affected observations from the fit X4 = X; X4([2,8,14],2) = NaN; m = fitlm (X4, y); assert_equal (sum (m.ObservationInfo.Missing), 3); assert_equal (m.NumObservations, 17); assert_equal (m.SSE, 0.261285495635633, 1e-9); assert_equal (m.SSR, 527.635694805749, 1e-6); assert_equal (m.SST, 527.896980301385, 1e-6); assert_equal (m.Coefficients.Estimate, ... [0.0986395043600395; 2.3735792982821; -0.97106191310122], 1e-7); assert_equal (size (m.Diagnostics.HatMatrix), [20, 20]); assert_equal (sum (m.Diagnostics.Leverage), 3, 1e-8); ***** test ## exclude by index and exclude by logical vector give identical results m = fitlm (X, y, 'Exclude', [3, 7]); excl = false (n, 1); excl([3, 7]) = true; m2 = fitlm (X, y, 'Exclude', excl); assert_equal (m.NumObservations, 18); assert_equal (sum (m.ObservationInfo.Excluded), 2); assert_equal (m.Fitted(3), 0.045673486217021, 1e-10); assert_equal (m.Fitted(7), -1.416779188276219, 1e-10); assert_equal (isnan (m.Residuals.Raw(3)), true); assert_equal (isnan (m.Residuals.Raw(7)), true); assert_equal (m.Coefficients.Estimate, m2.Coefficients.Estimate, 1e-12); assert_equal (m.Coefficients.Estimate, ... [0.118938102486219; 2.43606890944554; -0.974833228191174], 1e-7); ype = predict (m); assert_equal (size (ype), [20, 1]); assert_equal (! isnan (ype(3)) && ! isnan (ype(7)), true); [~, yci] = predict (m); assert_equal (yci(1,1), -0.0283122762458446, 1e-10); assert_equal (yci(1,2), 0.412312049343719, 1e-10); assert_equal (size (m.Diagnostics.HatMatrix), [20, 20]); assert_equal (m.Diagnostics.Leverage(1), 0.437780279893411, 1e-8); assert_equal (m.Diagnostics.CooksDistance(1), 0.110112457355807, 1e-7); ***** test ## an excluded row is fitted, but keeps neither residuals nor diagnostics m = fitlm (X, y, 'Exclude', [3, 7]); assert_equal (m.Fitted(3), predict (m, X(3,:)), 1e-12); assert_equal (isnan (m.Residuals.Pearson(3)), true); assert_equal (isnan (m.Residuals.Studentized(3)), true); assert_equal (isnan (m.Residuals.Standardized(3)), true); assert_equal (m.Diagnostics.Leverage(3), 0); assert_equal (isnan (m.Diagnostics.CooksDistance(3)), true); ***** test ## weighting does not change which rows carry a fitted value m = fitlm (X, y, 'Weights', ones (n, 1) / n, 'Exclude', [1, 3]); assert_equal (m.Fitted(1), 0.146089374212009, 1e-10); assert_equal (m.Fitted(2), 0.133765115244874, 1e-10); assert_equal (isnan (m.Residuals.Raw(1)), true); ***** test ## a missing predictor is the one case that leaves the fitted value NaN X2 = X; X2(2,1) = NaN; m = fitlm (X2, y); assert_equal (isnan (m.Fitted(2)), true); assert_equal (m.Fitted(1), 0.148994299022478, 1e-10); assert_equal (isnan (m.Residuals.Raw(2)), true); ***** test ## NaN and exclude together remove both the missing and the excluded row X6 = X; X6(1,1) = NaN; m = fitlm (X6, y, 'Exclude', [2]); assert_equal (m.NumObservations, 18); assert_equal (m.ObservationInfo.Missing(1), true); assert_equal (m.ObservationInfo.Excluded(2), true); assert_equal (m.SSE, 0.342515396265007, 1e-9); assert_equal (m.Coefficients.Estimate, ... [-0.0735450184226009; 3.17679029176988; -1.0045827469016], 1e-7); ***** test ## weighted least squares produces different SSE and stores the weights w = abs (sin ((1:n)')) + 0.1; m = fitlm (X, y, 'Weights', w); assert_equal (m.SSE, 0.363519720897775, 1e-10); assert_equal (m.ObservationInfo.Weights, w, 1e-15); assert_equal (m.SST, 4.419834786423099e+02, 1e-8); [yp, yci] = predict (m, [0.5 0.25; 1.0 1.0]); assert_equal (yp(1), 1.106748776307639, 1e-10); assert_equal (yp(2), 1.593185531572655, 1e-10); assert_equal (yci(1,1), 0.763985050242272, 1e-10); assert_equal (yci(1,2), 1.449512502373006, 1e-10); assert_equal (m.Diagnostics.Leverage(1), 0.421642939812731, 1e-8); assert_equal (m.Diagnostics.Leverage(2), 0.301314342928707, 1e-8); assert_equal (m.Diagnostics.HatMatrix(1,1), 0.421642939812731, 1e-8); assert_equal (m.Diagnostics.CooksDistance(1), 0.0728569335883748, 1e-7); assert_equal (m.Diagnostics.CovRatio(1), 1.96611264276187, 1e-6); ***** test ## uniform weights scale internals but leave point estimates unchanged m = fitlm (X, y, 'Weights', 2 * ones (n, 1)); assert_equal (m.Coefficients.Estimate, mdl.Coefficients.Estimate, 1e-10); ***** test ## the weighted log-likelihood does not depend on the scale of the weights ## (MATLAB's does, moving by n/2 * log (c); see the LogLikelihood property) xw = [1;2;3;4;5;6;7;8]; yw = [2.1;3.9;6.2;7.8;10.1;12.2;13.8;16.1]; w = [0.5;1;2;1;3;1;0.25;4]; m1 = fitlm (xw, yw, 'Weights', w); m2 = fitlm (xw, yw, 'Weights', 100 * w); assert_equal (m2.LogLikelihood, m1.LogLikelihood, 1e-12); assert_equal (m2.ModelCriterion.AIC, m1.ModelCriterion.AIC, 1e-12); ***** test ## the weighted log-likelihood is R's logLik.lm, term for term xw = [1;2;3;4;5;6;7;8]; yw = [2.1;3.9;6.2;7.8;10.1;12.2;13.8;16.1]; w = [0.5;1;2;1;3;1;0.25;4]; m = fitlm (xw, yw, 'Weights', w); nw = 8; rL = 0.5 * (sum (log (w)) - nw * (log (2*pi) + 1 - log (nw) + log (m.SSE))); assert_equal (m.LogLikelihood, rL, 1e-12); assert_equal (m.LogLikelihood, 4.55223335786031, 1e-12); ***** test ## a zero weight drops the observation from n as well as from DFE, as in R xw = [1;2;3;4;5;6;7;8]; yw = [2.1;3.9;6.2;7.8;10.1;12.2;13.8;16.1]; w = [0.5;1;0;1;3;1;0.25;4]; m = fitlm (xw, yw, 'Weights', w); wp = w(w > 0); nw = numel (wp); rL = 0.5 * (sum (log (wp)) - nw * (log (2*pi) + 1 - log (nw) + log (m.SSE))); assert_equal (m.LogLikelihood, rL, 1e-12); assert_equal (m.LogLikelihood, 4.68069254977738, 1e-12); assert_equal (m.DFE, 5); assert_equal (m.NumObservations, 8); ***** test ## an unweighted fit carries no weight term and agrees with R2024a xw = [1;2;3;4;5;6;7;8]; yw = [2.1;3.9;6.2;7.8;10.1;12.2;13.8;16.1]; m = fitlm (xw, yw); assert_equal (m.LogLikelihood, 3.51016777175681, 1e-12); assert_equal (m.ModelCriterion.AIC, -3.02033554351362, 1e-12); ***** test ## an unweighted robust fit's log-likelihood matches R2024a exactly xr = [1;2;3;4;5;6;7;8;9;10]; yr = [2.1;3.9;6.2;7.8;10.1;12.2;13.8;16.1;18.0;30.0]; m = fitlm (xr, yr, 'RobustOpts', 'bisquare'); assert_equal (m.LogLikelihood, -38.7915287023322, 1e-10); assert_equal (m.SSE, 18.9400079498975, 1e-10); ***** test ## a weighted robust fit matches R2024a in coefficients, SSE and likelihood xr = [1;2;3;4;5;6;7;8;9;10]; yr = [2.1;3.9;6.2;7.8;10.1;12.2;13.8;16.1;18.0;30.0]; w = [0.5;1;2;1;3;1;0.25;4;1;2]; m = fitlm (xr, yr, 'RobustOpts', 'bisquare', 'Weights', w); assert_equal (m.Coefficients.Estimate, ... [0.0606142999263569; 2.00273390115041], 1e-10); assert_equal (m.SSE, 19.6032720154597, 1e-10); assert_equal (m.MSE, 2.45040900193246, 1e-10); assert_equal (m.LogLikelihood, -62.7197604655733, 1e-9); ***** test ## the robust log-likelihood takes SSE and the residual sum separately xr = [1;2;3;4;5;6;7;8;9;10]; yr = [2.1;3.9;6.2;7.8;10.1;12.2;13.8;16.1;18.0;30.0]; m = fitlm (xr, yr, 'RobustOpts', 'bisquare'); r = m.Residuals.Raw; nr = 10; s2 = m.SSE / nr; assert_equal (m.LogLikelihood, ... -(nr/2) * log (2*pi*s2) - sum (r.^2) / (2*s2), 1e-12); ***** test ## constant linear and default modelspecs behave as expected m = fitlm (X, y, 'constant'); assert_equal (m.NumCoefficients, 1); assert_equal (m.CoefficientNames{1}, '(Intercept)'); m2 = fitlm (X, y, 'linear'); m3 = fitlm (X, y, []); assert_equal (m2.NumCoefficients, 3); assert_equal (m2.Coefficients.Estimate, mdl.Coefficients.Estimate, 1e-12); assert_equal (m3.Coefficients.Estimate, mdl.Coefficients.Estimate, 1e-12); ***** test ## purequadratic modelspec produces the expected term count m = fitlm (X, y, 'purequadratic'); assert_equal (m.NumCoefficients, 5); ***** test ## interactions modelspec term count and coefficients are verified m = fitlm (X, y, 'interactions'); assert_equal (m.NumCoefficients, 4); assert_equal (m.SSE, 0.383859187927621, 1e-9); assert_equal (m.Coefficients.Estimate, ... [0.157640728038039; 2.08542680311791; -0.929682701072813; -0.031208018255475], 1e-7); ***** test ## quadratic modelspec is rank deficient for this design and drops one coefficient m = fitlm (X, y, 'quadratic'); assert_equal (m.NumCoefficients, 6); assert_equal (m.SSE, 0.315784637443501, 1e-9); assert_equal (m.Coefficients.Estimate, ... [0.447436249544699; -2.44859403731902; -0.0121968798776254; ... -1.36755100280532; 0; 0.0318176901083297], 1e-7); drop = find (m.Coefficients.SE == 0); assert_equal (numel (drop), 1); assert_equal (isnan (m.Coefficients.tStat(drop)), true); ***** test ## full modelspec with two predictors matches interactions exactly m = fitlm (X, y, 'full'); m2 = fitlm (X, y, 'interactions'); assert_equal (m.NumCoefficients, 4); assert_equal (m.Coefficients.Estimate, m2.Coefficients.Estimate, 1e-10); assert_equal (m.Coefficients.Estimate, ... [0.157640728038039; 2.08542680311791; -0.929682701072813; -0.031208018255475], 1e-7); ***** test ## full modelspec with three predictors includes the three way interaction term X3 = [X, cos((1:n)' * pi / n)]; m = fitlm (X3, y, 'full'); assert_equal (m.NumCoefficients, 8); assert_equal (any (strcmp (m.CoefficientNames, 'x1:x2:x3')), true); assert_equal (m.SSE, 0.231331066631196, 1e-8); idx3 = find (strcmp (m.CoefficientNames, 'x1:x2:x3')); assert_equal (m.Coefficients.Estimate(idx3), 0.514890561912964, 1e-6); ***** test ## full modelspec without an intercept drops the intercept coefficient m = fitlm (X, y, 'full', 'Intercept', false); assert_equal (m.NumCoefficients, 3); assert_equal (! any (strcmp (m.CoefficientNames, '(Intercept)')), true); assert_equal (m.Coefficients.Estimate, ... [3.232987312533958; -1.041484635851565; 0.0324190990982863], 1e-7); ***** test ## a p column terms matrix produces a model with no intercept m = fitlm (X, y, [1 0; 0 1]); assert_equal (m.NumCoefficients, 2); assert_equal (! any (strcmp (m.CoefficientNames, '(Intercept)')), true); assert_equal (m.Coefficients.Estimate, [2.96142161317611; -0.997248749443286], 1e-7); ***** test ## a p plus one column terms matrix produces a model with an intercept m = fitlm (X, y, [0 0 0; 1 0 0; 0 1 0]); assert_equal (m.NumCoefficients, 3); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.Coefficients.Estimate, ... [0.116188677790207; 2.50845149057086; -0.978835329825186], 1e-7); ***** test ## a table with a Wilkinson formula fits the same model and predicts on a table T = table (X(:,1), X(:,2), y, 'VariableNames', {'a','b','resp'}); m = fitlm (T, 'resp ~ a + b'); assert_equal (m.NumCoefficients, 3); assert_equal (m.ResponseName, 'resp'); assert_equal (m.Coefficients.Estimate, mdl.Coefficients.Estimate, 1e-8); Xt = table ([0.5;1.0], [0.25;1.0], 'VariableNames', {'a','b'}); yp = predict (m, Xt); assert_equal (yp(1), 1.125705590619342, 1e-10); assert_equal (yp(2), 1.645804838535884, 1e-10); ***** test ## a matrix with a Wilkinson formula string fits the same model as the matrix alone m = fitlm (X, y, 'y ~ x1 + x2'); assert_equal (m.NumCoefficients, 3); assert_equal (m.Coefficients.Estimate, mdl.Coefficients.Estimate, 1e-8); ***** test ## a pure interaction formula keeps EncPredictorNames aligned with TermsMatrix mi = fitlm (X, y, 'y ~ x1:x2'); assert_equal (numel (mi.EncPredictorNames), columns (mi.TermsMatrix) - 1); assert_equal (mi.NumCoefficients, 2); assert_equal (mi.CoefficientNames, {'(Intercept)', 'x1:x2'}); assert_equal (mi.Coefficients.Estimate, ... [-0.755813941484483; -0.876953077491396], 1e-9); assert_equal (predict (mi), mi.Fitted, 1e-10); fig = figure ('visible', 'off'); h = plot (mi); assert_equal (numel (h), 3); assert_equal (get (get (gca, 'Title'), 'String'), 'Added variable plot for x1:x2'); assert_equal (get (get (gca, 'XLabel'), 'String'), 'Adjusted x1:x2'); assert_equal (get (h(2), 'DisplayName'), 'Fit: y = -0.876953*x'); close (fig); ***** test ## a table input with the default formula fits the same model as the matrix T3 = table (X(:,1), X(:,2), y, 'VariableNames', {'x1','x2','y'}); m = fitlm (T3); assert_equal (m.ResponseName, 'y'); assert_equal (m.Coefficients.Estimate, mdl.Coefficients.Estimate, 1e-8); ***** test ## VarNames sets custom names and ResponseVar overrides the response name m = fitlm (X, y, 'VarNames', {'alpha','beta','resp'}); assert_equal (m.ResponseName, 'resp'); assert_equal (isequal (m.PredictorNames, {'alpha';'beta'}), true); assert_equal (any (strcmp (m.CoefficientNames, 'alpha')), true); assert_equal (any (strcmp (m.CoefficientNames, 'beta')), true); m2 = fitlm (X, y, 'VarNames', {'a','b','r'}, 'ResponseVar', 'r'); assert_equal (m2.ResponseName, 'r'); ***** test ## a rank deficient design matrix leaves the dropped coefficients as NaN across the board X_rd = [ones(n,1), X, X(:,1)+X(:,2)]; m = fitlm (X_rd, y); assert_equal (m.NumCoefficients, 5); assert_equal (m.NumEstimatedCoefficients, 3); drop = find (m.Coefficients.SE == 0); assert_equal (numel (drop), 2); assert_equal (all (isnan (m.Coefficients.tStat(drop))), true); assert_equal (all (isnan (m.Coefficients.pValue(drop))), true); assert_equal (m.SST, 5.839104200023459e+02, 1e-8); assert_equal (all (all (m.CoefficientCovariance(drop,:) == 0)), true); yp = predict (m, X_rd); assert_equal (size (yp), [n, 1]); assert_equal (! any (isnan (yp)), true); assert_equal (size (m.Diagnostics.Dfbetas), [20, 5]); assert_equal (all (isnan (m.Diagnostics.Dfbetas(:, drop)(:))), true); assert_equal (m.Diagnostics.Leverage(1), 0.370779220779221, 1e-8); ***** test ## Intercept=false mni = fitlm (X, y, 'Intercept', false); assert_equal (mni.NumCoefficients, 2); assert_equal (mni.Formula.HasIntercept, false); assert_equal (! any (strcmp (mni.CoefficientNames, '(Intercept)')), true); [yp, yci] = predict (mni, [0.5 0.25; 1.0 1.0]); assert_equal (yp(1), 1.231398619227234, 1e-10); assert_equal (yp(2), 1.964172863732825, 1e-10); assert_equal (yci(1,1), 1.001262470857215, 1e-10); ***** test ## p-column terms matrix m_p = fitlm (X, y, [1 0; 0 1]); assert_equal (m_p.NumCoefficients, 2); assert_equal (! any (strcmp (m_p.CoefficientNames, '(Intercept)')), true); ***** test ## p+1 column terms matrix m_p1 = fitlm (X, y, [0 0 0; 1 0 0; 0 1 0]); assert_equal (m_p1.NumCoefficients, 3); assert_equal (m_p1.CoefficientNames{1}, '(Intercept)'); ***** test ## table Wilkinson formula T = table (X(:,1), X(:,2), y, 'VariableNames', {'a','b','resp'}); mf = fitlm (T, 'resp ~ a + b'); assert_equal (mf.NumCoefficients, 3); assert_equal (mf.ResponseName, 'resp'); assert_equal (mf.Coefficients.Estimate, mdl.Coefficients.Estimate, 1e-8); Xt = table ([0.5;1.0], [0.25;1.0], 'VariableNames', {'a','b'}); yp = predict (mf, Xt); assert_equal (yp(1), 1.125705590619342, 1e-10); assert_equal (yp(2), 1.645804838535884, 1e-10); ***** test ## matrix Wilkinson formula mfm = fitlm (X, y, 'y ~ x1 + x2'); assert_equal (mfm.NumCoefficients, 3); assert_equal (mfm.Coefficients.Estimate, mdl.Coefficients.Estimate, 1e-8); ***** test ## table default T3 = table (X(:,1), X(:,2), y, 'VariableNames', {'x1','x2','y'}); mt = fitlm (T3); assert_equal (mt.ResponseName, 'y'); assert_equal (mt.Coefficients.Estimate, mdl.Coefficients.Estimate, 1e-8); ***** test ## VarNames sets custom names vn = fitlm (X, y, 'VarNames', {'alpha','beta','resp'}); assert_equal (vn.ResponseName, 'resp'); assert_equal (isequal (vn.PredictorNames, {'alpha';'beta'}), true); assert_equal (any (strcmp (vn.CoefficientNames, 'alpha')), true); assert_equal (any (strcmp (vn.CoefficientNames, 'beta')), true); ***** test ## ResponseVar overrides VarNames rv = fitlm (X, y, 'VarNames', {'a','b','r'}, 'ResponseVar', 'r'); assert_equal (rv.ResponseName, 'r'); ***** test ## rank-deficient matrix X_rd = [ones(n,1), X, X(:,1)+X(:,2)]; m_rd = fitlm (X_rd, y); assert_equal (m_rd.NumCoefficients, 5); assert_equal (m_rd.NumEstimatedCoefficients, 3); drop = find (m_rd.Coefficients.SE == 0); assert_equal (numel (drop), 2); assert_equal (all (isnan (m_rd.Coefficients.tStat(drop))), true); assert_equal (all (isnan (m_rd.Coefficients.pValue(drop))), true); assert_equal (m_rd.SST, 5.839104200023459e+02, 1e-8); assert_equal (all (all (m_rd.CoefficientCovariance(drop,:) == 0)), true); yp = predict (m_rd, X_rd); assert_equal (size (yp), [n, 1]); assert_equal (! any (isnan (yp)), true); assert_equal (yp(1:5), [0.192669485827486; 0.171266760882252; ... 0.0519805029545; -0.165189287955771; ... -0.480242611848561], 1e-10); ***** test ## predict: ypred and default CI at new points [yp, yci] = predict (mdl, [0.5 0.25; 1.0 1.0]); assert_equal (yp(1), 1.125705590619347, 1e-10); assert_equal (yp(2), 1.645804838535894, 1e-10); assert_equal (yci(1,1), 0.810180780547215, 1e-10); assert_equal (yci(1,2), 1.441230400691478, 1e-10); assert_equal (yci(2,1), 0.858229321851723, 1e-10); assert_equal (yci(2,2), 2.433380355220066, 1e-10); ***** test ## predict: observation interval [~, yci] = predict (mdl, [0.5 0.25; 1.0 1.0], 'Prediction', 'observation'); assert_equal (yci(1,1), 0.677632064105988, 1e-10); assert_equal (yci(1,2), 1.573779117132706, 1e-10); ***** test ## predict: alpha 0.01 [~, yci] = predict (mdl, [0.5 0.25; 1.0 1.0], 'Alpha', 0.01); assert_equal (yci(1,1), 0.692272619570008, 1e-10); assert_equal (yci(1,2), 1.559138561668685, 1e-10); ***** test ## predict: simultaneous CI [~, yci] = predict (mdl, [0.5 0.25; 1.0 1.0], 'Simultaneous', true); assert_equal (yci(1,1), 0.662572505689338, 1e-10); assert_equal (yci(1,2), 1.588838675549355, 1e-10); ***** test ## predict: no Xnew returns all rows including training [yp, yci] = predict (mdl); assert_equal (size (yp), [20, 1]); assert_equal (size (yci), [20, 2]); assert_equal (yp(1), 0.192669485827490, 1e-10); assert_equal (yp(2), 0.171266760882255, 1e-10); assert_equal (yci(1,1), -0.001052067982566, 1e-10); assert_equal (yci(1,2), 0.386391039637546, 1e-10); ***** test ## predict: NaN predictor propagates to NaN output and CI [yp, yci] = predict (mdl, [0.5 0.25; NaN 1.0; 1.0 1.0]); assert_equal (yp(1), 1.125705590619347, 1e-10); assert_equal (isnan (yp(2)), true); assert_equal (yp(3), 1.645804838535894, 1e-10); assert_equal (isnan (yci(2,1)), true); assert_equal (isnan (yci(2,2)), true); ***** test ## predict: categorical model predictions at group centres Xc = [1;1;1;2;2;2;3;3;3]; yc = [2.1;2.3;1.9; 4.1;3.9;4.2; 6.3;5.8;6.1]; m_cat = fitlm (Xc, yc, 'linear', 'CategoricalVars', 1); [yp, yci] = predict (m_cat, [1;2;3]); assert_equal (yp(1), 2.099999999999998, 1e-10); assert_equal (yp(2), 4.066666666666667, 1e-10); assert_equal (yp(3), 6.066666666666666, 1e-10); assert_equal (yci(1,1), 1.80971256321669, 1e-10); assert_equal (yci(1,2), 2.3902874367833, 1e-10); assert_equal (yci(2,1), 3.77637922988336, 1e-10); assert_equal (yci(2,2), 4.35695410344997, 1e-10); assert_equal (yci(3,1), 5.77637922988336, 1e-10); assert_equal (yci(3,2), 6.35695410344997, 1e-10); ***** test ## predict: interaction model [yp, yci] = predict (fitlm (X, y, 'interactions'), [0.5 0.25; 1.0 1.0]); assert_equal (yp(1), 0.964032452046850, 1e-10); assert_equal (yp(2), 1.282176811827644, 1e-10); assert_equal (yci(1,1), -0.110763003580605, 1e-10); assert_equal (yci(1,2), 2.038827907674306, 1e-10); ***** test ## predict: weighted model, ypred and CI w = (1:n)' / sum (1:n); mw = fitlm (X, y, 'Weights', w); [yp, yci] = predict (mw, [0.5 0.25; 1.0 1.0]); assert_equal (yp(1), 1.15833357370544, 1e-10); assert_equal (yp(2), 1.74408669002694, 1e-10); assert_equal (yci(1,1), 0.802165170771357, 1e-10); assert_equal (yci(1,2), 1.51450197663953, 1e-10); assert_equal (yci(2,1), 0.69968979253134, 1e-10); assert_equal (yci(2,2), 2.78848358752254, 1e-10); ***** test ## predict: no-intercept model, ypred and CI mni = fitlm (X, y, 'Intercept', false); [yp, yci] = predict (mni, [0.5 0.25; 1.0 1.0]); assert_equal (yp(1), 1.23139861922723, 1e-10); assert_equal (yp(2), 1.96417286373283, 1e-10); assert_equal (yci(1,1), 1.00126247085704, 1e-10); assert_equal (yci(1,2), 1.46153476759743, 1e-10); assert_equal (yci(2,1), 1.51833851162232, 1e-10); assert_equal (yci(2,2), 2.41000721584333, 1e-10); ***** test ## predict: observation interval combined with simultaneous bound [~, yci] = predict (mdl, [0.5 0.25; 1.0 1.0], ... 'Prediction', 'observation', 'Simultaneous', true); assert_equal (yci(1,1), 0.46801507632267, 1e-10); assert_equal (yci(1,2), 1.78339610491601, 1e-10); assert_equal (yci(2,1), 0.399032373599106, 1e-10); assert_equal (yci(2,2), 2.89257730347266, 1e-10); ***** test ## output is 2x1 double column vector ysim = random (mdl, [0.5, 0.25; 1.0, 1.0]); assert_equal (size (ysim), [2, 1]); assert_equal (class (ysim), 'double'); assert_equal (iscolumn (ysim), true); ***** test ## single row input gives 1x1 output assert_equal (size (random (mdl, [0.5, 0.25])), [1, 1]); ***** test ## predict values are exact and noise added is finite ypred = predict (mdl, [0.5, 0.25; 1.0, 1.0]); ysim = random (mdl, [0.5, 0.25; 1.0, 1.0]); assert_equal (ypred(1), 1.125705590619342, 1e-10); assert_equal (ypred(2), 1.645804838535884, 1e-10); assert_equal (all (isfinite (ysim - ypred)), true); ***** test ## NaN predictor row gives NaN output, other rows stay finite ysim = random (mdl, [0.5, 0.25; NaN, 1.0; 1.0, 1.0]); assert_equal (size (ysim), [3, 1]); assert_equal (isfinite (ysim(1)), true); assert_equal (isnan (ysim(2)), true); assert_equal (isfinite (ysim(3)), true); ***** test ## two sequential calls produce different output ya = random (mdl, [0.5, 0.25]); yb = random (mdl, [0.5, 0.25]); assert_equal (! isequal (ya, yb), true); ***** test ## random: table input, full training data, weighted and no-intercept ## models all give finite output of the expected size Xt = table ([0.5;1.0], [0.25;1.0], 'VariableNames', {'x1','x2'}); mw = fitlm (X, y, 'Weights', (1:n)' / sum (1:n)); mni = fitlm (X, y, 'Intercept', false); assert_equal (size (random (mdl, Xt)), [2, 1]); assert_equal (all (isfinite (random (mdl, Xt))), true); assert_equal (size (random (mdl, X)), [20, 1]); assert_equal (sum (isnan (random (mdl, X))), 0); assert_equal (all (isfinite (random (mw, [0.5, 0.25; 1.0, 1.0]))), true); assert_equal (all (isfinite (random (mni, [0.5, 0.25; 1.0, 1.0]))), true); ***** test yf = feval (mdl, [0.5 0.25; 1.0 1.0; 0.2 0.04]); assert_equal (size (yf), [3, 1]); assert_equal (class (yf), 'double'); assert_equal (yf(1), 1.125705590619342, 1e-10); assert_equal (yf(2), 1.645804838535884, 1e-10); assert_equal (yf(3), 0.578725562711373, 1e-10); assert_equal (yf, predict (mdl, [0.5 0.25; 1.0 1.0; 0.2 0.04]), 1e-10); ***** test yf = feval (mdl, [0.5; 1.0; 0.2], [0.25; 1.0; 0.04]); assert_equal (size (yf), [3, 1]); assert_equal (iscolumn (yf), true); assert_equal (yf, predict (mdl, [0.5 0.25; 1.0 1.0; 0.2 0.04]), 1e-10); ***** test yf = feval (mdl, [0.5, 1.0, 0.2], [0.25, 1.0, 0.04]); assert_equal (size (yf), [1, 3]); assert_equal (isrow (yf), true); assert_equal (yf(:), predict (mdl, [0.5 0.25; 1.0 1.0; 0.2 0.04]), 1e-10); ***** test yf = feval (mdl, 0.5, 0.25); assert_equal (size (yf), [1, 1]); assert_equal (yf, 1.125705590619342, 1e-10); assert_equal (yf, predict (mdl, [0.5 0.25]), 1e-10); ***** test yf = feval (mdl, 0.5, [0.1; 0.2; 0.3]); assert_equal (size (yf), [3, 1]); assert_equal (yf(1), 1.272530890093120, 1e-10); assert_equal (yf(2), 1.174647357110602, 1e-10); assert_equal (yf(3), 1.076763824128083, 1e-10); assert_equal (yf, predict (mdl, [0.5 0.1; 0.5 0.2; 0.5 0.3]), 1e-10); ***** test yf = feval (mdl, [0.1; 0.5; 0.9], 0.25); assert_equal (size (yf), [3, 1]); assert_equal (yf(1), 0.122324994390997, 1e-10); assert_equal (yf(2), 1.125705590619342, 1e-10); assert_equal (yf(3), 2.129086186847688, 1e-10); assert_equal (yf, predict (mdl, [0.1 0.25; 0.5 0.25; 0.9 0.25]), 1e-10); ***** test Weight = [2000;2100;2200;2300;2400;2500;2600;2700;2800;2900;3000; ... 3100;3200;3300;3400;3500;3600;3700;3800;3900]; Year = categorical ([70;70;70;70;70;76;76;76;76;76;76;76;82;82; ... 82;82;82;82;82;82]); MPG = [30;29;28;27;26;25;24;23;22;21;20;19;18;17;16;15;14;13;12;11]; m = fitlm (table (MPG, Weight, Year), 'MPG ~ Weight + Year'); yf = feval (m, [2500;3000], '76'); assert_equal (yf(1), 25.000000000000000, 1e-9); assert_equal (yf(2), 20.000000000000004, 1e-9); yf2 = feval (m, [2500;3000], categorical (70)); assert_equal (yf2(1), 24.999999999999996, 1e-9); assert_equal (yf2(2), 20.000000000000000, 1e-9); assert_equal (feval (m, 2800, '82'), 21.999999999999996, 1e-9); assert_equal (isnan (feval (m, 2500, '99')), true); ***** test m = fitlm ((1:n)' / n, 2 * (1:n)' / n + 0.1 * sin ((1:n)')); assert_equal (size (feval (m, 0.5)), [1, 1]); assert_equal (size (feval (m, [0.3; 0.5; 0.9])), [3, 1]); assert_equal (feval (m, 0.5), predict (m, 0.5), 1e-10); assert_equal (feval (m, [0.3; 0.5; 0.9]), predict (m, [0.3; 0.5; 0.9]), 1e-10); ***** test T = table ([0.5; 1.0; 0.2], [0.25; 1.0; 0.04], 'VariableNames', {'x1', 'x2'}); yf = feval (mdl, T); assert_equal (size (yf), [3, 1]); assert_equal (yf, predict (mdl, [0.5 0.25; 1.0 1.0; 0.2 0.04]), 1e-10); ***** test yf = feval (mdl, [0.5 0.25; NaN 1.0; 1.0 1.0]); assert_equal (isfinite (yf(1)), true); assert_equal (isnan (yf(2)), true); assert_equal (isfinite (yf(3)), true); ***** test yf = feval (mdl, [0.5; NaN; 1.0], [0.25; 1.0; 1.0]); assert_equal (isnan (yf(2)), true); yf = feval (mdl, [0.5; 1.0; 1.0], [0.25; NaN; 1.0]); assert_equal (isnan (yf(2)), true); ***** test yf = feval (mdl, X); assert_equal (size (yf), [20, 1]); assert_equal (yf, mdl.Fitted, 1e-10); ***** test m = fitlm (X, y, 'Intercept', false); yf = feval (m, [0.5 0.25; 1.0 1.0]); assert_equal (yf, predict (m, [0.5 0.25; 1.0 1.0]), 1e-10); assert_equal (feval (m, [0.5; 1.0], [0.25; 1.0]), yf, 1e-10); ***** test m = fitlm (X, y, 'interactions'); yf = feval (m, [0.5 0.25; 1.0 1.0]); assert_equal (yf, predict (m, [0.5 0.25; 1.0 1.0]), 1e-10); assert_equal (feval (m, [0.5; 1.0], [0.25; 1.0]), yf, 1e-10); ***** test m = fitlm ([1;1;1;2;2;2;3;3;3], [2.1;2.3;1.9;4.1;3.9;4.2;6.3;5.8;6.1], ... 'linear', 'CategoricalVars', 1); yf = feval (m, [1; 2; 3]); assert_equal (yf(1), 2.099999999999998, 1e-10); assert_equal (yf(2), 4.066666666666667, 1e-10); assert_equal (yf(3), 6.066666666666666, 1e-10); ***** test ci = coefCI (mdl); assert_equal (size (ci), [3, 2]); assert_equal (class (ci), 'double'); assert_equal (all (ci(:,1) < ci(:,2)), true); assert_equal (ci(1,1), -0.120502736154050, 1e-10); assert_equal (ci(1,2), 0.352880091734465, 1e-10); assert_equal (ci(2,1), 1.470249604061007, 1e-10); assert_equal (ci(2,2), 3.546653377080718, 1e-10); assert_equal (ci(3,1), -1.026857022014626, 1e-10); assert_equal (ci(3,2), -0.930813637635746, 1e-10); ***** test ## midpoints equal estimates ci = coefCI (mdl); t = tinv (0.975, mdl.DFE); assert_equal ((ci(:,1) + ci(:,2)) / 2, mdl.Coefficients.Estimate, 1e-10); assert_equal (ci(:,2) - ci(:,1), 2 * t * mdl.Coefficients.SE, 1e-10); ***** test assert_equal (coefCI (mdl, 0.05), coefCI (mdl)); ***** test ci = coefCI (mdl); ci01 = coefCI (mdl, 0.01); t01 = tinv (0.995, mdl.DFE); assert_equal (size (ci01), [3, 2]); assert_equal (ci01(1,1), -0.208951721610638, 1e-10); assert_equal (ci01(1,2), 0.441329077191052, 1e-10); assert_equal (ci01(2,1), 1.08228494564489, 1e-10); assert_equal (ci01(2,2), 3.934618035496833, 1e-10); assert_equal (ci01(3,1), -1.044802201703589, 1e-10); assert_equal (ci01(3,2), -0.912868457946783, 1e-10); assert_equal (all ((ci01(:,2) - ci01(:,1)) > (ci(:,2) - ci(:,1))), true); assert_equal (ci01(:,2) - ci01(:,1), 2 * t01 * mdl.Coefficients.SE, 1e-10); ***** test ci0 = coefCI (mdl, 0); assert_equal (all (ci0(:,1) == -Inf), true); assert_equal (all (ci0(:,2) == +Inf), true); ***** test ## alpha=1 collapses to point estimates ci1 = coefCI (mdl, 1); assert_equal (ci1(:,1), mdl.Coefficients.Estimate, 1e-10); assert_equal (ci1(:,2), mdl.Coefficients.Estimate, 1e-10); ***** test m = fitlm (X, y, 'Intercept', false); ci = coefCI (m); t = tinv (0.975, m.DFE); assert_equal (size (ci), [2, 2]); assert_equal (ci(1,1), 2.486679110991696, 1e-10); assert_equal (ci(1,2), 3.436164115360526, 1e-10); assert_equal (ci(2,1), -1.027166590567854, 1e-10); assert_equal (ci(2,2), -0.967330908318718, 1e-10); assert_equal ((ci(:,1) + ci(:,2)) / 2, m.Coefficients.Estimate, 1e-10); assert_equal (ci(:,2) - ci(:,1), 2 * t * m.Coefficients.SE, 1e-10); ***** test m = fitlm (X, y, 'interactions'); ci = coefCI (m); t = tinv (0.975, m.DFE); assert_equal (size (ci), [4, 2]); assert_equal (ci(1,1), -0.201030907566802, 1e-10); assert_equal (ci(1,2), 0.516312363642881, 1e-10); assert_equal ((ci(:,1) + ci(:,2)) / 2, m.Coefficients.Estimate, 1e-10); assert_equal (ci(:,2) - ci(:,1), 2 * t * m.Coefficients.SE, 1e-10); ***** test ## constant model (1 coefficient) m = fitlm (X, y, 'constant'); ci = coefCI (m); t = tinv (0.975, m.DFE); assert_equal (size (ci), [1, 2]); assert_equal ((ci(1,1) + ci(1,2)) / 2, m.Coefficients.Estimate, 1e-10); assert_equal (ci(1,2) - ci(1,1), 2 * t * m.Coefficients.SE, 1e-10); ***** test m = fitlm (X, y, 'Weights', (1:n)' / sum (1:n)); ci = coefCI (m); t = tinv (0.975, m.DFE); assert_equal (size (ci), [3, 2]); assert_equal (ci(1,1), -0.355978167660141, 1e-10); assert_equal (ci(1,2), 0.516619434992026, 1e-10); assert_equal ((ci(:,1) + ci(:,2)) / 2, m.Coefficients.Estimate, 1e-10); assert_equal (ci(:,2) - ci(:,1), 2 * t * m.Coefficients.SE, 1e-10); ***** test ## rank-deficient: dropped rows give [0,0], active rows are finite m = fitlm ([ones(n,1), X, X(:,1)+X(:,2)], y); ci = coefCI (m); drop = find (m.Coefficients.SE == 0); assert_equal (size (ci), [5, 2]); assert_equal (all (all (ci(drop, :) == 0)), true); assert_equal (all (all (isfinite (ci(setdiff (1:5, drop'), :)))), true); ***** test m = fitlm ([1;1;1;2;2;2;3;3;3], [2.1;2.3;1.9;4.1;3.9;4.2;6.3;5.8;6.1], ... 'linear', 'CategoricalVars', 1); ci = coefCI (m); assert_equal (size (ci), [3, 2]); assert_equal (ci(1,1), 1.80971256321669, 1e-10); assert_equal (ci(1,2), 2.3902874367833, 1e-10); assert_equal (ci(2,1), 1.55613823658119, 1e-10); assert_equal (ci(2,2), 2.37719509675214, 1e-10); assert_equal (ci(3,1), 3.55613823658119, 1e-10); assert_equal (ci(3,2), 4.37719509675214, 1e-10); ***** test [p, F, r] = coefTest (mdl); assert_equal (size (p), [1, 1]); assert_equal (class (p), 'double'); assert_equal (p >= 0 && p <= 1, true); assert_equal (F >= 0, true); assert_equal (p, 9.489880832170599e-28, -1e-8); assert_equal (F, 1.283149098426142e+04, -1e-8); assert_equal (r, 2); ***** test ## formula identity [p, F] = coefTest (mdl); k = mdl.NumCoefficients; H0 = [zeros(k-1, 1), eye(k-1)]; b = mdl.Coefficients.Estimate; V = mdl.CoefficientCovariance; Hb = H0 * b; Fm = (Hb' * ((H0 * V * H0') \ Hb)) / (k - 1); pm = betainc (mdl.DFE / (mdl.DFE + (k-1) * Fm), mdl.DFE/2, (k-1)/2); assert_equal (F, Fm, -1e-10); assert_equal (p, pm, -1e-10); ***** test ## explicit H matches default k = mdl.NumCoefficients; H_exp = [zeros(k-1, 1), eye(k-1)]; [p1, F1, r1] = coefTest (mdl); [p2, F2, r2] = coefTest (mdl, H_exp); assert_equal (p2, p1, -1e-10); assert_equal (F2, F1, -1e-10); assert_equal (r2, size (H_exp, 1)); ***** test ## pinned single and joint H [p1, F1, r1] = coefTest (mdl, [1 0 0]); assert_equal (p1, 0.314859866747774, -1e-8); assert_equal (F1, 1.072634101844537, -1e-8); assert_equal (r1, 1); [p2, F2, r2] = coefTest (mdl, [0 1 0]); assert_equal (p2, 8.937794169018252e-05, -1e-8); assert_equal (F2, 25.985840929474932, -1e-8); assert_equal (r2, 1); [p3, F3, r3] = coefTest (mdl, [0 0 1]); assert_equal (p3, 8.656938305821102e-19, -1e-8); assert_equal (F3, 1.849410599855684e+03, -1e-8); assert_equal (r3, 1); [pm, Fm, rm] = coefTest (mdl, [0 1 0; 0 0 1]); assert_equal (pm, 9.489880832170599e-28, -1e-8); assert_equal (Fm, 1.283149098426142e+04, -1e-8); assert_equal (rm, 2); ***** test ## trivial hypothesis and C=0 b = mdl.Coefficients.Estimate; [p0, F0] = coefTest (mdl, [0 1 0], b(2)); assert_equal (F0 < 1e-12, true); assert_equal (p0, 1, 1e-10); [pa, Fa] = coefTest (mdl, [0 1 0], 0); [pb, Fb] = coefTest (mdl, [0 1 0]); assert_equal (pa, pb, -1e-10); assert_equal (Fa, Fb, -1e-10); ***** test ## H with C [pc, Fc, rc] = coefTest (mdl, [0 1 0; 0 0 1], [1.5; -1.0]); assert_equal (pc, 2.833788304242915e-09, -1e-8); assert_equal (Fc, 77.603887650386312, -1e-8); assert_equal (rc, 2); [pr, Fr] = coefTest (mdl, [0 1 0; 0 0 1], [1.5, -1.0]); assert_equal (pr, pc, -1e-10); assert_equal (Fr, Fc, -1e-10); [ps, Fs] = coefTest (mdl, [0 1 0], 1.5); assert_equal (ps, 0.056184159363707, -1e-8); assert_equal (Fs, 4.199865537706047, -1e-8); ***** test ## no-intercept model m = fitlm (X, y, 'Intercept', false); [p, F, r] = coefTest (m); assert_equal (p, 6.060655830723051e-32, -1e-8); assert_equal (F, 2.646694317541346e+04, -1e-8); assert_equal (r, m.NumCoefficients); [p2, F2] = coefTest (m, eye (m.NumCoefficients)); assert_equal (p2, p, -1e-10); assert_equal (F2, F, -1e-10); ***** test ## interaction model m = fitlm (X, y, 'interactions'); [p, F, r] = coefTest (m); assert_equal (p, 1.164196605688161e-25, -1e-8); assert_equal (F, 8.107508574885546e+03, -1e-8); assert_equal (r, m.NumCoefficients - 1); assert_equal (r != m.NumPredictors, true); ***** test ## weighted model m = fitlm (X, y, 'Weights', (1:n)' / sum (1:n)); [p, F, r] = coefTest (m); assert_equal (p, 1.481920976389473e-27, -1e-8); assert_equal (F, 1.217557180481257e+04, -1e-8); assert_equal (r, 2); assert_equal (p, m.ModelFitVsNullModel.Pvalue, -1e-8); ***** test ## categorical model m = fitlm ([1;1;1;2;2;2;3;3;3], [2.1;2.3;1.9;4.1;3.9;4.2;6.3;5.8;6.1], ... 'linear', 'CategoricalVars', 1); [p, F, r] = coefTest (m); assert_equal (p, 1.197590680415813e-06, -1e-8); assert_equal (F, 2.795000000000035e+02, -1e-8); assert_equal (r, 2); [p1, F1] = coefTest (m, [1 0 0]); assert_equal (F1, 3.133421052631613e+02, -1e-8); assert_equal (p1, 2.087464608380450e-06, -1e-8); [p2, F2] = coefTest (m, [0 1 0]); assert_equal (F2, 1.374078947368438e+02, -1e-8); assert_equal (p2, 2.325514143662469e-05, -1e-8); [p3, F3] = coefTest (m, [0 0 1]); assert_equal (F3, 5.589868421052698e+02, -1e-8); assert_equal (p3, 3.757733067786492e-07, -1e-8); ***** test ## constant model m = fitlm (X, y, 'constant'); [p, F, r] = coefTest (m); assert_equal (p, 0.000239936408695073, -1e-8); assert_equal (F, 20.3359164947506, -1e-8); assert_equal (r, 1); ***** test ## rank-deficient model m = fitlm ([ones(n,1), X, X(:,1)+X(:,2)], y); [p, F] = coefTest (m); assert_equal (isnan (p), true); assert_equal (isnan (F), true); drop = find (m.Coefficients.SE == 0); keep = setdiff (2:m.NumCoefficients, drop'); H = zeros (numel (keep), m.NumCoefficients); for i = 1:numel (keep) H(i, keep(i)) = 1; endfor [p2, F2, r2] = coefTest (m, H); assert_equal (p2, 6.70657058643085e-30, -1e-8); assert_equal (F2, 17716.1864263456, -1e-8); assert_equal (r2, numel (keep)); ***** test p = dwtest (mdl); assert_equal (size (p), [1, 1]); assert_equal (class (p), 'double'); [p, DW] = dwtest (mdl); assert_equal (size (DW), [1, 1]); assert_equal (p >= 0 && p <= 1, true); assert_equal (DW >= 0 && DW <= 4, true); assert_equal (p, 4.702593821571290e-04, -1e-6); assert_equal (DW, 0.870000704251173, 1e-12); ***** test [p1, DW1] = dwtest (mdl); [p2, DW2] = dwtest (mdl, 'exact', 'both'); assert_equal (p1, p2, 1e-14); assert_equal (DW1, DW2, 1e-14); ***** test ## DW is the same for all method and tail options [~, d1] = dwtest (mdl, 'exact', 'both'); [~, d2] = dwtest (mdl, 'exact', 'right'); [~, d3] = dwtest (mdl, 'exact', 'left'); [~, d4] = dwtest (mdl, 'approximate', 'both'); [~, d5] = dwtest (mdl, 'approximate', 'right'); [~, d6] = dwtest (mdl, 'approximate', 'left'); assert_equal (d1, 0.870000704251173, 1e-12); assert_equal (d2, 0.870000704251173, 1e-12); assert_equal (d3, 0.870000704251173, 1e-12); assert_equal (d4, 0.870000704251173, 1e-12); assert_equal (d5, 0.870000704251173, 1e-12); assert_equal (d6, 0.870000704251173, 1e-12); ***** test ## one-sided p-values sum to 1 and two-sided equals twice the smaller pb = dwtest (mdl, 'exact', 'both'); pr = dwtest (mdl, 'exact', 'right'); pl = dwtest (mdl, 'exact', 'left'); assert_equal (pr + pl, 1, 1e-12); assert_equal (pb, 4.702593821571290e-04, 1e-12); ***** test ## all six method and tail combinations pinned assert_equal (dwtest (mdl, 'exact', 'both'), 4.702593821571290e-04, -1e-6); assert_equal (dwtest (mdl, 'exact', 'right'), 2.351296910785645e-04, -1e-6); assert_equal (dwtest (mdl, 'exact', 'left'), 0.999764870308921, -1e-6); assert_equal (dwtest (mdl, 'approximate', 'both'), 0.001058795514879, -1e-6); assert_equal (dwtest (mdl, 'approximate', 'right'), 5.293977574395035e-04, -1e-6); assert_equal (dwtest (mdl, 'approximate', 'left'), 0.999470602242560, -1e-6); ***** test ## no-intercept model m = fitlm (X, y, 'Intercept', false); [p, DW] = dwtest (m, 'exact', 'both'); assert_equal (DW, 0.841468411374128, 1e-12); assert_equal (p, 0.001402191159200, -1e-6); assert_equal (dwtest (m, 'exact', 'right'), 7.010955795999754e-04, -1e-6); assert_equal (dwtest (m, 'approximate', 'right'), 0.001350534002321, -1e-6); ***** test ## weighted model m = fitlm (X, y, 'Weights', (1:n)' / sum (1:n)); [p, DW] = dwtest (m, 'exact', 'both'); assert_equal (DW, 0.871162354803032, 1e-12); assert_equal (p, 4.771641146603785e-04, -1e-6); assert_equal (dwtest (m, 'exact', 'right'), 2.385820573301892e-04, -1e-6); assert_equal (dwtest (m, 'approximate', 'right'), 5.346779629058873e-04, -1e-6); ***** test ## positive autocorrelation model m = fitlm ((1:n)'/n, sin (pi * (1:n)'/n)); [~, DW] = dwtest (m, 'exact', 'both'); pr = dwtest (m, 'exact', 'right'); pl = dwtest (m, 'exact', 'left'); assert_equal (DW, 0.118112272685229, 1e-10); assert_equal (DW < 1, true); assert_equal (pr < pl, true); assert_equal (pr < 1e-10, true); ***** test ## negative autocorrelation model m = fitlm ((1:n)'/n, 2*(1:n)'/n + repmat ([1; -1], n/2, 1)); [pb, DW] = dwtest (m, 'exact', 'both'); pl = dwtest (m, 'exact', 'left'); pr = dwtest (m, 'exact', 'right'); assert_equal (pb, 4.205713999283489e-09, 1e-10); assert_equal (DW, 3.825974025974026, 1e-10); assert_equal (DW > 2, true); assert_equal (pl < pr, true); assert_equal (pb, 2 * pl, 1e-10); assert_equal (pb < 1e-7, true); ***** test m = addTerms (mdl, 'x1:x2'); assert_equal (isa (m, 'LinearModel'), true); assert_equal (mdl.NumCoefficients, 3); assert_equal (m.NumCoefficients, 4); assert_equal (m.NumPredictors, 2); assert_equal (m.NumObservations, 20); assert_equal (m.DFE, 16); assert_equal (m.Coefficients.Estimate(1), 0.157640728038039, -1e-8); assert_equal (m.Coefficients.Estimate(2), 2.085426803117909, -1e-8); assert_equal (m.Coefficients.Estimate(3), -0.929682701072813, -1e-8); assert_equal (m.Coefficients.Estimate(4), -0.031208018255475, -1e-8); assert_equal (m.Coefficients.SE(1), 0.169192291625763, -1e-8); assert_equal (m.Coefficients.SE(2), 1.361534257888685, -1e-8); assert_equal (m.Coefficients.SE(3), 0.148744319911833, -1e-8); assert_equal (m.Coefficients.SE(4), 0.0932669056882381, -1e-8); assert_equal (m.Coefficients.tStat(1), 0.931725237144526, -1e-8); assert_equal (m.Coefficients.tStat(2), 1.531674132351069, -1e-8); assert_equal (m.Coefficients.tStat(3), -6.250206405353000, -1e-8); assert_equal (m.Coefficients.tStat(4), -0.334609774230031, -1e-8); assert_equal (m.Coefficients.pValue(1), 0.365325503492671, -1e-8); assert_equal (m.Coefficients.pValue(2), 0.145134783727025, -1e-8); assert_equal (m.Coefficients.pValue(3), 1.159217784590233e-05, -1e-8); assert_equal (m.Coefficients.pValue(4), 0.742265736761240, -1e-8); assert_equal (m.SSE, 0.383859187927621, -1e-8); assert_equal (m.MSE, 0.023991199245515, -1e-8); assert_equal (m.RMSE, 0.154890926930905, -1e-8); assert_equal (m.Rsquared.Ordinary, 0.999342606032059, -1e-8); assert_equal (m.Rsquared.Adjusted, 0.999219344663070, -1e-8); assert_equal (m.LogLikelihood, 11.153346988927943, -1e-8); assert_equal (m.ModelFitVsNullModel.Fstat, 8.107508574898859e+03, -1e-6); assert_equal (m.ModelFitVsNullModel.Pvalue, 1.164196605672873e-25, -1e-6); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.CoefficientNames{2}, 'x1'); assert_equal (m.CoefficientNames{3}, 'x2'); assert_equal (m.CoefficientNames{4}, 'x1:x2'); ***** test ## x1*x2 crossing gives same result as x1:x2 when main effects exist m = addTerms (mdl, 'x1*x2'); assert_equal (m.NumCoefficients, 4); assert_equal (m.DFE, 16); assert_equal (m.SSE, 0.383859187927621, -1e-8); assert_equal (m.Coefficients.Estimate(1), 0.157640728038039, -1e-8); assert_equal (m.Coefficients.Estimate(2), 2.085426803117909, -1e-8); assert_equal (m.Coefficients.Estimate(3), -0.929682701072813, -1e-8); assert_equal (m.Coefficients.Estimate(4), -0.031208018255475, -1e-8); assert_equal (m.CoefficientNames{4}, 'x1:x2'); ***** test m = addTerms (mdl, 'x1 + x1:x2'); assert_equal (m.NumCoefficients, 4); assert_equal (m.DFE, 16); assert_equal (m.SSE, 0.383859187927621, -1e-8); assert_equal (m.Coefficients.Estimate(1), 0.157640728038039, -1e-8); assert_equal (m.Coefficients.Estimate(2), 2.085426803117909, -1e-8); assert_equal (m.Coefficients.Estimate(3), -0.929682701072813, -1e-8); assert_equal (m.Coefficients.Estimate(4), -0.031208018255475, -1e-8); ***** test ## adding existing term returns equivalent model ws = warning ('off', 'all'); m = addTerms (mdl, 'x1'); warning (ws); assert_equal (m.NumCoefficients, 3); assert_equal (m.DFE, 17); assert_equal (m.Coefficients.Estimate(1), 0.116188677790207, 1e-7); assert_equal (m.Coefficients.Estimate(2), 2.508451490570863, 1e-7); assert_equal (m.Coefficients.Estimate(3), -0.978835329825186, 1e-7); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.CoefficientNames{2}, 'x1'); assert_equal (m.CoefficientNames{3}, 'x2'); ***** test m = addTerms (mdl, 'x2^2'); assert_equal (m.NumCoefficients, 4); assert_equal (m.DFE, 16); assert_equal (m.SSE, 0.386103933724971, -1e-8); assert_equal (m.Coefficients.Estimate(1), 0.130152473216993, -1e-8); assert_equal (m.Coefficients.Estimate(2), 2.380771990884563, -1e-8); assert_equal (m.Coefficients.Estimate(3), -0.967672823484773, -1e-8); assert_equal (m.Coefficients.Estimate(4), -2.991483322469043e-04, -1e-8); assert_equal (m.Coefficients.SE(1), 0.154974488176692, -1e-8); assert_equal (m.Coefficients.SE(2), 1.071554310049276, -1e-8); assert_equal (m.Coefficients.SE(3), 0.085801310569364, -1e-8); assert_equal (m.Coefficients.SE(4), 0.002211890858232, -1e-8); assert_equal (m.CoefficientNames{4}, 'x2^2'); ***** test ## x1^2 rank-deficient: DFE unchanged SE zero for dropped term m = addTerms (mdl, 'x1^2'); assert_equal (m.NumCoefficients, 4); assert_equal (m.DFE, 17); assert_equal (m.SSE, 0.386545331386823, -1e-8); assert_equal (m.Coefficients.Estimate(4), 0); assert_equal (m.Coefficients.SE(4), 0); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.CoefficientNames{2}, 'x1'); assert_equal (m.CoefficientNames{3}, 'x2'); assert_equal (m.CoefficientNames{4}, 'x1^2'); ***** test ## numeric matrix [1,1,0] same as string x1:x2 m = addTerms (mdl, [1, 1, 0]); assert_equal (m.NumCoefficients, 4); assert_equal (m.DFE, 16); assert_equal (m.SSE, 0.383859187927621, -1e-8); assert_equal (m.Coefficients.Estimate(1), 0.157640728038039, -1e-8); assert_equal (m.Coefficients.Estimate(2), 2.085426803117909, -1e-8); assert_equal (m.Coefficients.Estimate(3), -0.929682701072813, -1e-8); assert_equal (m.Coefficients.Estimate(4), -0.031208018255475, -1e-8); ***** test ## numeric matrix [1,1] auto-padded to [1,1,0] m = addTerms (mdl, [1, 1]); assert_equal (m.NumCoefficients, 4); assert_equal (m.DFE, 16); assert_equal (m.SSE, 0.383859187927621, -1e-8); assert_equal (m.Coefficients.Estimate(1), 0.157640728038039, -1e-8); assert_equal (m.Coefficients.Estimate(2), 2.085426803117909, -1e-8); assert_equal (m.Coefficients.Estimate(3), -0.929682701072813, -1e-8); assert_equal (m.Coefficients.Estimate(4), -0.031208018255475, -1e-8); ***** test m = addTerms (mdl, [1, 1, 0; 0, 2, 0]); assert_equal (m.NumCoefficients, 5); assert_equal (m.DFE, 15); assert_equal (m.SSE, 0.315784637443501, -1e-8); assert_equal (m.CoefficientNames{4}, 'x1:x2'); assert_equal (m.CoefficientNames{5}, 'x2^2'); ***** test mc = fitlm (X, y, 'constant'); m = addTerms (mc, 'x1'); assert_equal (m.NumCoefficients, 2); assert_equal (m.DFE, 18); assert_equal (m.Coefficients.Estimate(1), 3.884704697617172, -1e-8); assert_equal (m.Coefficients.Estimate(2), -18.047090435758047, -1e-8); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.CoefficientNames{2}, 'x1'); ***** test ## step from constant to full linear model mc = fitlm (X, y, 'constant'); mc1 = addTerms (mc, 'x1'); mc2 = addTerms (mc1, 'x2'); assert_equal (mc2.NumCoefficients, 3); assert_equal (mc2.DFE, 17); assert_equal (mc2.Coefficients.Estimate(1), 0.116188677790207, 1e-7); assert_equal (mc2.Coefficients.Estimate(2), 2.508451490570863, 1e-7); assert_equal (mc2.Coefficients.Estimate(3), -0.978835329825186, 1e-7); assert_equal (mc2.CoefficientNames{1}, '(Intercept)'); assert_equal (mc2.CoefficientNames{2}, 'x1'); assert_equal (mc2.CoefficientNames{3}, 'x2'); ***** test ## adding intercept to no-intercept model mni = fitlm (X, y, 'Intercept', false); m = addTerms (mni, '1'); assert_equal (m.NumCoefficients, 3); assert_equal (m.DFE, 17); assert_equal (m.Coefficients.Estimate(1), 0.116188677790207, 1e-7); assert_equal (m.Coefficients.Estimate(2), 2.508451490570863, 1e-7); assert_equal (m.Coefficients.Estimate(3), -0.978835329825186, 1e-7); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.CoefficientNames{2}, 'x1'); assert_equal (m.CoefficientNames{3}, 'x2'); ***** test ## weighted model weights preserved mw = fitlm (X, y, 'Weights', (1:n)' / sum (1:n)); m = addTerms (mw, 'x1:x2'); assert_equal (m.NumCoefficients, 4); assert_equal (m.DFE, 16); assert_equal (m.SSE, 0.019230053719402, -1e-8); assert_equal (m.Coefficients.Estimate(1), -0.122645849510537, -1e-8); assert_equal (m.Coefficients.Estimate(2), 4.125799311652051, -1e-8); assert_equal (m.Coefficients.Estimate(3), -1.128467507844852, -1e-8); assert_equal (m.Coefficients.Estimate(4), 0.081921546574140, -1e-8); assert_equal (m.Coefficients.SE(1), 0.354926338845420, -1e-8); assert_equal (m.Coefficients.SE(2), 2.205951720932299, -1e-8); assert_equal (m.Coefficients.SE(3), 0.205033663966776, -1e-8); assert_equal (m.Coefficients.SE(4), 0.115523382309399, -1e-8); assert_equal (m.CoefficientNames{4}, 'x1:x2'); ***** test ## excluded observations preserved me = fitlm (X, y, 'Exclude', [1, 2]); m = addTerms (me, 'x1:x2'); assert_equal (m.NumObservations, 18); assert_equal (m.DFE, 14); assert_equal (m.NumCoefficients, 4); assert_equal (m.Coefficients.Estimate(1), -0.345521184099998, -1e-8); assert_equal (m.Coefficients.Estimate(2), 5.139185607268283, -1e-8); assert_equal (m.Coefficients.Estimate(3), -1.198851436671170, -1e-8); assert_equal (m.Coefficients.Estimate(4), 0.112619530301200, -1e-8); assert_equal (m.CoefficientNames{4}, 'x1:x2'); ***** test ## remove two predictors by string from a 4-predictor model Xh = [7 26 6 60; 1 29 15 52; 11 56 8 20; 11 31 8 47; 7 52 6 33; ... 11 55 9 22; 3 71 17 6; 1 31 22 44; 2 54 18 22; 21 47 4 26; ... 1 40 23 34; 11 66 9 12; 10 68 8 12]; yh = [78.5;74.3;104.3;87.6;95.9;109.2;102.7;72.5;93.1;115.9;83.8;113.3;109.4]; m = removeTerms (fitlm (Xh, yh), 'x3 + x4'); assert_equal (m.NumCoefficients, 3); assert_equal (m.NumEstimatedCoefficients, 3); assert_equal (m.DFE, 10); assert_equal (m.NumObservations, 13); assert_equal (m.NumVariables, 5); assert_equal (m.Coefficients.Estimate(1), 52.577348882089481, -1e-8); assert_equal (m.Coefficients.Estimate(2), 1.468305742215555, -1e-8); assert_equal (m.Coefficients.Estimate(3), 0.662250491274645, -1e-8); assert_equal (m.Coefficients.SE(1), 2.286174334503340, -1e-8); assert_equal (m.Coefficients.SE(2), 0.121300923606266, -1e-8); assert_equal (m.Coefficients.SE(3), 0.045854721468522, -1e-8); assert_equal (m.Coefficients.tStat, m.Coefficients.Estimate ./ m.Coefficients.SE, 1e-10); assert_equal (m.Coefficients.tStat(1), 22.997961305305111, -1e-8); assert_equal (m.Coefficients.tStat(2), 12.104654264476748, -1e-8); assert_equal (m.Coefficients.tStat(3), 14.442362096327519, -1e-8); assert_equal (m.Coefficients.pValue(1), 5.456570901490983e-10, -1e-7); assert_equal (m.Coefficients.pValue(2), 2.692212179685427e-07, -1e-8); assert_equal (m.Coefficients.pValue(3), 5.028960315638413e-08, -1e-8); assert_equal (m.SSE, 57.904483176113658, -1e-8); assert_equal (m.RMSE, 2.40633503852047, -1e-8); assert_equal (m.MSE, 5.790448317611299, 1e-12); assert_equal (m.SST, 2.715763076923078e+03, 1e-8); assert_equal (m.Rsquared.Ordinary, 0.978678374535632, -1e-8); assert_equal (m.Rsquared.Adjusted, 0.974414049442758, -1e-8); assert_equal (size (m.CoefficientCovariance), [3, 3]); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.CoefficientNames{2}, 'x1'); assert_equal (m.CoefficientNames{3}, 'x2'); assert_equal (m.Formula.HasIntercept, true); assert_equal (m.Formula.LinearPredictor, '1 + x1 + x2'); assert_equal (height (m.Diagnostics), 13); assert_equal (sum (m.Diagnostics.Leverage), 3, 1e-10); assert_equal (m.Residuals.Raw, yh - m.Fitted, 1e-10); ***** test m = removeTerms (mdl, 'x2'); assert_equal (m.NumCoefficients, 2); assert_equal (m.NumEstimatedCoefficients, 2); assert_equal (m.DFE, 18); assert_equal (m.NumObservations, 20); assert_equal (m.Coefficients.Estimate(1), 3.88470469761717, -1e-8); assert_equal (m.Coefficients.Estimate(2), -18.047090435758, -1e-8); assert_equal (m.Coefficients.SE(2), 1.19086428900602, -1e-8); assert_equal (m.Coefficients.tStat, m.Coefficients.Estimate ./ m.Coefficients.SE, 1e-10); assert_equal (m.Coefficients.tStat(2), -15.1546155194741, -1e-8); assert_equal (m.SSE, 42.4383708132815, -1e-8); assert_equal (m.SST, 583.910420002346, -1e-8); assert_equal (m.Rsquared.Ordinary, 0.927320408474452, -1e-8); assert_equal (size (m.CoefficientCovariance), [2, 2]); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.CoefficientNames{2}, 'x1'); assert_equal (m.Formula.HasIntercept, true); assert_equal (m.Formula.LinearPredictor, '1 + x1'); assert_equal (height (m.Diagnostics), 20); assert_equal (m.Residuals.Raw, y - m.Fitted, 1e-10); ***** test ## removing the intercept via string '1' m = removeTerms (mdl, '1'); assert_equal (m.NumCoefficients, 2); assert_equal (m.NumEstimatedCoefficients, 2); assert_equal (m.DFE, 18); assert_equal (m.NumObservations, 20); assert_equal (m.Formula.HasIntercept, false); assert_equal (m.Formula.LinearPredictor, 'x1 + x2'); assert_equal (m.Coefficients.Estimate(1), 2.96142161317611, -1e-8); assert_equal (m.Coefficients.Estimate(2), -0.997248749443286, -1e-8); assert_equal (m.Coefficients.tStat, m.Coefficients.Estimate ./ m.Coefficients.SE, 1e-10); assert_equal (m.SSE, 0.410934843407688, -1e-8); assert_equal (size (m.CoefficientCovariance), [2, 2]); assert_equal (m.CoefficientNames{1}, 'x1'); assert_equal (m.CoefficientNames{2}, 'x2'); assert_equal (! any (strcmp (m.CoefficientNames, '(Intercept)')), true); assert_equal (height (m.Diagnostics), 20); ***** test ## removing both predictors leaves only the intercept m = removeTerms (mdl, 'x1 + x2'); assert_equal (m.NumCoefficients, 1); assert_equal (m.NumEstimatedCoefficients, 1); assert_equal (m.DFE, 19); assert_equal (m.NumObservations, 20); assert_equal (m.Formula.HasIntercept, true); assert_equal (m.Formula.LinearPredictor, '1'); assert_equal (m.Coefficients.Estimate(1), -5.5900177811558, -1e-8); assert_equal (m.Coefficients.tStat, m.Coefficients.Estimate ./ m.Coefficients.SE, 1e-10); assert_equal (m.SSE, 583.910420002346, -1e-8); assert_equal (m.SST, 583.910420002346, -1e-8); assert_equal (m.SSR, 0, 1e-20); assert_equal (size (m.CoefficientCovariance), [1, 1]); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (height (m.Diagnostics), 20); assert_equal (sum (m.Diagnostics.Leverage), 1, 1e-10); assert_equal (m.Residuals.Raw, y - m.Fitted, 1e-10); ***** test ws = warning ('off', 'all'); m = removeTerms (mdl, 'x1:x2'); warning (ws); assert_equal (m.NumCoefficients, mdl.NumCoefficients); assert_equal (m.NumEstimatedCoefficients, mdl.NumEstimatedCoefficients); assert_equal (m.DFE, mdl.DFE); assert_equal (m.SSE, mdl.SSE, 1e-15); assert_equal (m.SSR, mdl.SSR, 1e-15); assert_equal (m.SST, mdl.SST, 1e-15); assert_equal (m.RMSE, mdl.RMSE, 1e-15); assert_equal (m.Coefficients.Estimate, mdl.Coefficients.Estimate, 1e-15); assert_equal (m.Coefficients.SE, mdl.Coefficients.SE, 1e-15); assert_equal (m.CoefficientCovariance, mdl.CoefficientCovariance, 1e-15); assert_equal (isequal (m.CoefficientNames, mdl.CoefficientNames), true); assert_equal (m.Formula.LinearPredictor, mdl.Formula.LinearPredictor); assert_equal (m.Formula.HasIntercept, mdl.Formula.HasIntercept); ***** test m = removeTerms (mdl, [0 1 0]); assert_equal (m.NumCoefficients, 2); assert_equal (m.NumEstimatedCoefficients, 2); assert_equal (m.DFE, 18); assert_equal (m.NumObservations, 20); assert_equal (m.Coefficients.Estimate(1), 3.88470469761717, -1e-8); assert_equal (m.Coefficients.Estimate(2), -18.047090435758, -1e-8); assert_equal (m.Coefficients.SE(2), 1.19086428900602, -1e-8); assert_equal (m.Coefficients.tStat, m.Coefficients.Estimate ./ m.Coefficients.SE, 1e-10); assert_equal (m.Coefficients.tStat(2), -15.1546155194741, -1e-8); assert_equal (m.SSE, 42.4383708132815, -1e-8); assert_equal (m.SST, 583.910420002346, -1e-8); assert_equal (m.Rsquared.Ordinary, 0.927320408474452, -1e-8); assert_equal (size (m.CoefficientCovariance), [2, 2]); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.CoefficientNames{2}, 'x1'); assert_equal (m.Formula.HasIntercept, true); assert_equal (m.Formula.LinearPredictor, '1 + x1'); assert_equal (height (m.Diagnostics), 20); assert_equal (sum (m.Diagnostics.Leverage), 2, 1e-10); ***** test ## auto-padded matrix [0 1] gives identical result to [0 1 0] m = removeTerms (mdl, [0 1]); assert_equal (m.NumCoefficients, 2); assert_equal (m.NumEstimatedCoefficients, 2); assert_equal (m.DFE, 18); assert_equal (m.Coefficients.Estimate(1), 3.88470469761717, -1e-8); assert_equal (m.Coefficients.Estimate(2), -18.047090435758, -1e-8); assert_equal (m.Coefficients.SE(2), 1.19086428900602, -1e-8); assert_equal (m.Coefficients.tStat, m.Coefficients.Estimate ./ m.Coefficients.SE, 1e-10); assert_equal (m.SSE, 42.4383708132815, -1e-8); assert_equal (m.SST, 583.910420002346, -1e-8); assert_equal (m.Rsquared.Ordinary, 0.927320408474452, -1e-8); assert_equal (size (m.CoefficientCovariance), [2, 2]); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.CoefficientNames{2}, 'x1'); assert_equal (m.Formula.LinearPredictor, '1 + x1'); assert_equal (height (m.Diagnostics), 20); assert_equal (sum (m.Diagnostics.Leverage), 2, 1e-10); ***** test ## multi-row matrix removes two terms same as the string form Xh = [7 26 6 60; 1 29 15 52; 11 56 8 20; 11 31 8 47; 7 52 6 33; ... 11 55 9 22; 3 71 17 6; 1 31 22 44; 2 54 18 22; 21 47 4 26; ... 1 40 23 34; 11 66 9 12; 10 68 8 12]; yh = [78.5;74.3;104.3;87.6;95.9;109.2;102.7;72.5;93.1;115.9;83.8;113.3;109.4]; m = removeTerms (fitlm (Xh, yh), [0 0 1 0 0; 0 0 0 1 0]); assert_equal (m.NumCoefficients, 3); assert_equal (m.NumEstimatedCoefficients, 3); assert_equal (m.DFE, 10); assert_equal (m.NumObservations, 13); assert_equal (m.Coefficients.Estimate(1), 52.577348882089481, -1e-8); assert_equal (m.Coefficients.Estimate(2), 1.468305742215555, -1e-8); assert_equal (m.Coefficients.Estimate(3), 0.662250491274645, -1e-8); assert_equal (m.Coefficients.SE(1), 2.286174334503340, -1e-8); assert_equal (m.Coefficients.SE(2), 0.121300923606266, -1e-8); assert_equal (m.Coefficients.SE(3), 0.045854721468522, -1e-8); assert_equal (m.Coefficients.tStat, m.Coefficients.Estimate ./ m.Coefficients.SE, 1e-10); assert_equal (m.Coefficients.tStat(2), 12.104654264476748, -1e-8); assert_equal (m.Coefficients.tStat(3), 14.442362096327519, -1e-8); assert_equal (m.Coefficients.pValue(2), 2.692212179685427e-07, -1e-8); assert_equal (m.SSE, 57.904483176113658, -1e-8); assert_equal (m.Rsquared.Ordinary, 0.978678374535632, -1e-8); assert_equal (m.Rsquared.Adjusted, 0.974414049442758, -1e-8); assert_equal (size (m.CoefficientCovariance), [3, 3]); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.CoefficientNames{2}, 'x1'); assert_equal (m.CoefficientNames{3}, 'x2'); assert_equal (m.Formula.HasIntercept, true); assert_equal (m.Formula.LinearPredictor, '1 + x1 + x2'); assert_equal (height (m.Diagnostics), 13); assert_equal (sum (m.Diagnostics.Leverage), 3, 1e-10); assert_equal (m.Residuals.Raw, yh - m.Fitted, 1e-10); ***** test ## observation weights carry through to the refitted model w = (1:n)' / sum (1:n); mw = fitlm (X, y, 'Weights', w); m = removeTerms (mw, 'x2'); assert_equal (m.NumCoefficients, 2); assert_equal (m.NumEstimatedCoefficients, 2); assert_equal (m.DFE, 18); assert_equal (m.NumObservations, 20); assert_equal (m.Coefficients.Estimate(1), 6.29263960898714, -1e-8); assert_equal (m.Coefficients.Estimate(2), -21.5708976231287, -1e-8); assert_equal (m.Coefficients.tStat, m.Coefficients.Estimate ./ m.Coefficients.SE, 1e-10); assert_equal (m.SSE, 1.41763159723151, -1e-8); assert_equal (size (m.CoefficientCovariance), [2, 2]); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.CoefficientNames{2}, 'x1'); assert_equal (m.Formula.HasIntercept, true); assert_equal (m.Formula.LinearPredictor, '1 + x1'); assert_equal (m.ObservationInfo.Weights, w, 1e-15); assert_equal (sum (m.ObservationInfo.Weights), 1, 1e-12); assert_equal (height (m.Diagnostics), 20); assert_equal (sum (m.Diagnostics.Leverage), 2, 1e-10); assert_equal (m.SSE != removeTerms (mdl, 'x2').SSE, true); ***** test ## excluded rows are preserved and reduce effective sample size me = fitlm (X, y, 'Exclude', [1, 3]); m = removeTerms (me, 'x2'); assert_equal (m.NumObservations, 18); assert_equal (m.DFE, 16); assert_equal (m.NumCoefficients, 2); assert_equal (m.NumEstimatedCoefficients, 2); assert_equal (m.Coefficients.Estimate(1), 4.96609542902066, -1e-8); assert_equal (m.Coefficients.Estimate(2), -19.5618050042778, -1e-8); assert_equal (m.Coefficients.tStat, m.Coefficients.Estimate ./ m.Coefficients.SE, 1e-10); assert_equal (size (m.CoefficientCovariance), [2, 2]); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.CoefficientNames{2}, 'x1'); assert_equal (m.Formula.LinearPredictor, '1 + x1'); assert_equal (m.ObservationInfo.Excluded(1), true); assert_equal (m.ObservationInfo.Excluded(3), true); assert_equal (m.ObservationInfo.Excluded(2), false); assert_equal (m.ObservationInfo.Missing(1), false); assert_equal (height (m.Diagnostics), 20); assert_equal (m.Fitted(1), 3.988005178806767, 1e-10); assert_equal (m.Fitted(3), 2.031824678378986, 1e-10); assert_equal (m.Fitted(2), 3.009914928592877, 1e-10); assert_equal (isnan (m.Residuals.Raw(1)), true); ***** test ## removing x2 from a no-intercept model gives one slope term mni = fitlm (X, y, 'Intercept', false); m = removeTerms (mni, 'x2'); assert_equal (m.NumCoefficients, 1); assert_equal (m.NumEstimatedCoefficients, 1); assert_equal (m.DFE, 19); assert_equal (m.NumObservations, 20); assert_equal (m.Formula.HasIntercept, false); assert_equal (m.Formula.LinearPredictor, 'x1'); assert_equal (m.Coefficients.Estimate(1), -12.362156731928, -1e-8); assert_equal (m.Coefficients.tStat, m.Coefficients.Estimate ./ m.Coefficients.SE, 1e-10); assert_equal (m.SSE, 112.371951585499, -1e-8); assert_equal (size (m.CoefficientCovariance), [1, 1]); assert_equal (m.CoefficientCovariance(1,1) > 0, true); assert_equal (m.CoefficientNames{1}, 'x1'); assert_equal (! any (strcmp (m.CoefficientNames, '(Intercept)')), true); assert_equal (height (m.Diagnostics), 20); assert_equal (all (isfinite (m.Fitted)), true); assert_equal (sum (m.Diagnostics.Leverage), 1, 1e-10); ***** test ## removing the interaction term recovers the plain linear model mi = fitlm (X, y, 'interactions'); m = removeTerms (mi, 'x1:x2'); assert_equal (m.NumCoefficients, 3); assert_equal (m.NumEstimatedCoefficients, 3); assert_equal (m.DFE, 17); assert_equal (m.NumObservations, 20); assert_equal (m.Coefficients.Estimate(1), 0.116188677790207, -1e-8); assert_equal (m.Coefficients.Estimate(2), 2.508451490570863, -1e-8); assert_equal (m.Coefficients.Estimate(3), -0.978835329825186, -1e-8); assert_equal (m.Coefficients.SE(1), 0.112185831, -1e-7); assert_equal (m.Coefficients.SE(2), 0.4920818186, -1e-7); assert_equal (m.Coefficients.SE(3), 0.02276108523, -1e-7); assert_equal (m.Coefficients.tStat, m.Coefficients.Estimate ./ m.Coefficients.SE, 1e-10); assert_equal (m.Coefficients.tStat(1), 1.035680502, -1e-6); assert_equal (m.Coefficients.tStat(2), 5.097630913, -1e-6); assert_equal (m.Coefficients.tStat(3), -43.00477415, -1e-6); assert_equal (m.SSE, 0.386545331386823, -1e-8); assert_equal (size (m.CoefficientCovariance), [3, 3]); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.CoefficientNames{2}, 'x1'); assert_equal (m.CoefficientNames{3}, 'x2'); assert_equal (m.Formula.HasIntercept, true); assert_equal (m.Formula.LinearPredictor, '1 + x1 + x2'); assert_equal (height (m.Diagnostics), 20); assert_equal (sum (m.Diagnostics.Leverage), 3, 1e-10); ***** test ## removing a quadratic term refits on the remaining terms mq = fitlm (X, y, 'quadratic'); m = removeTerms (mq, 'x2^2'); assert_equal (m.NumEstimatedCoefficients, 4); assert_equal (m.DFE, 16); assert_equal (m.SSE, 0.383859187927621, -1e-8); assert_equal (size (m.CoefficientCovariance, 1), m.NumCoefficients); assert_equal (size (m.CoefficientCovariance, 2), m.NumCoefficients); assert_equal (m.Formula.HasIntercept, true); assert_equal (height (m.Diagnostics), 20); assert_equal (sum (m.Diagnostics.Leverage), 4, 1e-10); assert_equal (m.SSE >= mq.SSE, true); assert_equal (! any (strcmp (m.CoefficientNames, 'x2^2')), true); ***** test ## star notation removes main effects and interaction in one call mi = fitlm (X, y, 'interactions'); m = removeTerms (mi, 'x1*x2'); assert_equal (m.NumCoefficients, 1); assert_equal (m.NumEstimatedCoefficients, 1); assert_equal (m.DFE, 19); assert_equal (m.NumObservations, 20); assert_equal (m.Formula.HasIntercept, true); assert_equal (m.Formula.LinearPredictor, '1'); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.Coefficients.Estimate(1), -5.5900177811558, -1e-8); assert_equal (m.Coefficients.tStat, m.Coefficients.Estimate ./ m.Coefficients.SE, 1e-10); assert_equal (m.SSE, 583.910420002346, -1e-8); assert_equal (m.SST, 583.910420002346, -1e-8); assert_equal (m.SSR, 0, 1e-20); assert_equal (size (m.CoefficientCovariance), [1, 1]); assert_equal (height (m.Diagnostics), 20); assert_equal (sum (m.Diagnostics.Leverage), 1, 1e-10); ***** test ## 3-predictor model: removing one term matches a direct two-predictor fit X3 = [X, sin((1:n)' * pi / n)]; y3 = X3 * [3; -1; 2] + 0.1 * cos ((1:n)' * pi / 7); m = removeTerms (fitlm (X3, y3), 'x3'); r = fitlm (X, y3); assert_equal (m.NumCoefficients, 3); assert_equal (m.NumEstimatedCoefficients, 3); assert_equal (m.DFE, 17); assert_equal (m.NumObservations, 20); assert_equal (m.Coefficients.Estimate, r.Coefficients.Estimate, 1e-10); assert_equal (m.Coefficients.SE, r.Coefficients.SE, 1e-10); assert_equal (m.Coefficients.tStat, r.Coefficients.tStat, 1e-10); assert_equal (m.Coefficients.pValue, r.Coefficients.pValue, 1e-10); assert_equal (m.SSE, r.SSE, 1e-12); assert_equal (m.SSR, r.SSR, 1e-12); assert_equal (m.SST, r.SST, 1e-12); assert_equal (m.MSE, r.MSE, 1e-12); assert_equal (m.RMSE, r.RMSE, 1e-12); assert_equal (m.Rsquared.Ordinary, r.Rsquared.Ordinary, 1e-12); assert_equal (m.Rsquared.Adjusted, r.Rsquared.Adjusted, 1e-12); assert_equal (m.CoefficientCovariance, r.CoefficientCovariance, 1e-12); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.CoefficientNames{2}, 'x1'); assert_equal (m.CoefficientNames{3}, 'x2'); assert_equal (m.Formula.HasIntercept, true); assert_equal (m.Formula.LinearPredictor, '1 + x1 + x2'); assert_equal (height (m.Diagnostics), 20); assert_equal (sum (m.Diagnostics.Leverage), 3, 1e-10); ***** test ## 3-predictor model: removing two terms matches a direct one-predictor fit X3 = [X, sin((1:n)' * pi / n)]; y3 = X3 * [3; -1; 2] + 0.1 * cos ((1:n)' * pi / 7); m = removeTerms (fitlm (X3, y3), 'x2 + x3'); r = fitlm (X(:,1), y3); assert_equal (m.NumCoefficients, 2); assert_equal (m.NumEstimatedCoefficients, 2); assert_equal (m.DFE, 18); assert_equal (m.NumObservations, 20); assert_equal (m.Coefficients.Estimate, r.Coefficients.Estimate, 1e-10); assert_equal (m.Coefficients.SE, r.Coefficients.SE, 1e-10); assert_equal (m.Coefficients.tStat, r.Coefficients.tStat, 1e-10); assert_equal (m.Coefficients.pValue, r.Coefficients.pValue, 1e-10); assert_equal (m.SSE, r.SSE, 1e-12); assert_equal (m.SST, r.SST, 1e-12); assert_equal (m.MSE, r.MSE, 1e-12); assert_equal (m.RMSE, r.RMSE, 1e-12); assert_equal (m.Rsquared.Ordinary, r.Rsquared.Ordinary, 1e-12); assert_equal (m.Rsquared.Adjusted, r.Rsquared.Adjusted, 1e-12); assert_equal (m.CoefficientCovariance, r.CoefficientCovariance, 1e-12); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.CoefficientNames{2}, 'x1'); assert_equal (m.Formula.HasIntercept, true); assert_equal (m.Formula.LinearPredictor, '1 + x1'); assert_equal (height (m.Diagnostics), 20); assert_equal (sum (m.Diagnostics.Leverage), 2, 1e-10); ***** test Xh = [7 26 6 60; 1 29 15 52; 11 56 8 20; 11 31 8 47; 7 52 6 33; ... 11 55 9 22; 3 71 17 6; 1 31 22 44; 2 54 18 22; 21 47 4 26; ... 1 40 23 34; 11 66 9 12; 10 68 8 12]; yh = [78.5;74.3;104.3;87.6;95.9;109.2;102.7;72.5;93.1;115.9;83.8;113.3;109.4]; m = removeTerms (fitlm (Xh, yh), 'x3 + x4'); r = removeTerms (removeTerms (fitlm (Xh, yh), 'x4'), 'x3'); assert_equal (r.NumCoefficients, 3); assert_equal (r.DFE, 10); assert_equal (r.SSE, m.SSE, 1e-12); assert_equal (r.SSR, m.SSR, 1e-12); assert_equal (r.SST, m.SST, 1e-12); assert_equal (r.RMSE, m.RMSE, 1e-12); assert_equal (r.Coefficients.Estimate, m.Coefficients.Estimate, 1e-10); assert_equal (r.Coefficients.SE, m.Coefficients.SE, 1e-10); assert_equal (r.Coefficients.tStat, m.Coefficients.tStat, 1e-10); assert_equal (r.Coefficients.pValue, m.Coefficients.pValue, 1e-10); assert_equal (r.CoefficientCovariance, m.CoefficientCovariance, 1e-12); assert_equal (isequal (r.CoefficientNames, m.CoefficientNames), true); assert_equal (r.Rsquared.Ordinary, m.Rsquared.Ordinary, 1e-12); assert_equal (r.Rsquared.Adjusted, m.Rsquared.Adjusted, 1e-12); assert_equal (r.Formula.LinearPredictor, m.Formula.LinearPredictor); ***** test m = removeTerms (mdl, [0 0 0]); r = removeTerms (mdl, '1'); assert_equal (m.NumCoefficients, 2); assert_equal (m.Formula.HasIntercept, false); assert_equal (m.Formula.LinearPredictor, 'x1 + x2'); assert_equal (m.Coefficients.Estimate(1), 2.96142161317611, -1e-8); assert_equal (m.Coefficients.Estimate(2), -0.997248749443286, -1e-8); assert_equal (m.Coefficients.tStat, m.Coefficients.Estimate ./ m.Coefficients.SE, 1e-10); assert_equal (m.SSE, r.SSE, 1e-15); assert_equal (m.SSR, r.SSR, 1e-15); assert_equal (m.SST, r.SST, 1e-15); assert_equal (m.Coefficients.Estimate, r.Coefficients.Estimate, 1e-15); assert_equal (m.Coefficients.SE, r.Coefficients.SE, 1e-15); assert_equal (m.CoefficientCovariance, r.CoefficientCovariance, 1e-15); assert_equal (isequal (m.CoefficientNames, r.CoefficientNames), true); assert_equal (height (m.Diagnostics), 20); assert_equal (sum (m.Diagnostics.Leverage), 2, 1e-10); ***** test ## removing a categorical predictor drops all its indicator variables at once Xc = [1;1;1;2;2;2;3;3;3]; yc = [2.1;2.3;1.9; 4.1;3.9;4.2; 6.3;5.8;6.1]; mc = fitlm (Xc, yc, 'linear', 'CategoricalVars', 1); m = removeTerms (mc, 'x1'); assert_equal (m.NumCoefficients, 1); assert_equal (m.NumEstimatedCoefficients, 1); assert_equal (m.DFE, 8); assert_equal (m.NumObservations, 9); assert_equal (m.Formula.HasIntercept, true); assert_equal (m.Formula.LinearPredictor, '1'); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.Coefficients.Estimate(1), 4.07777777777778, -1e-8); assert_equal (m.Coefficients.tStat, m.Coefficients.Estimate ./ m.Coefficients.SE, 1e-10); assert_equal (m.SSR, 0, 1e-20); assert_equal (size (m.CoefficientCovariance), [1, 1]); assert_equal (height (m.Diagnostics), 9); assert_equal (all (isfinite (m.Fitted)), true); assert_equal (sum (m.Diagnostics.Leverage), 1, 1e-10); assert_equal (m.Residuals.Raw, yc - m.Fitted, 1e-10); ***** test ## matrix row removes x4 from hald leaving intercept plus x1 x2 x3 Xh = [7 26 6 60; 1 29 15 52; 11 56 8 20; 11 31 8 47; 7 52 6 33; ... 11 55 9 22; 3 71 17 6; 1 31 22 44; 2 54 18 22; 21 47 4 26; ... 1 40 23 34; 11 66 9 12; 10 68 8 12]; yh = [78.5;74.3;104.3;87.6;95.9;109.2;102.7;72.5;93.1;115.9;83.8;113.3;109.4]; m = removeTerms (fitlm (Xh, yh), [0 0 0 1 0]); assert_equal (m.NumCoefficients, 4); assert_equal (m.NumEstimatedCoefficients, 4); assert_equal (m.DFE, 9); assert_equal (m.NumObservations, 13); assert_equal (m.Coefficients.Estimate(1), 48.1936343180437, -1e-8); assert_equal (m.Coefficients.Estimate(2), 1.69589016748479, -1e-8); assert_equal (m.Coefficients.Estimate(3), 0.656914878270554, -1e-8); assert_equal (m.Coefficients.Estimate(4), 0.250017606680009, -1e-8); assert_equal (m.Coefficients.tStat, m.Coefficients.Estimate ./ m.Coefficients.SE, 1e-10); assert_equal (m.SSE, 48.1106140726532, -1e-8); assert_equal (size (m.CoefficientCovariance), [4, 4]); assert_equal (m.CoefficientNames{1}, '(Intercept)'); assert_equal (m.CoefficientNames{2}, 'x1'); assert_equal (m.CoefficientNames{3}, 'x2'); assert_equal (m.CoefficientNames{4}, 'x3'); assert_equal (m.Formula.HasIntercept, true); assert_equal (m.Formula.LinearPredictor, '1 + x1 + x2 + x3'); assert_equal (height (m.Diagnostics), 13); assert_equal (all (isfinite (m.Fitted)), true); assert_equal (sum (m.Diagnostics.Leverage), 4, 1e-10); assert_equal (m.Residuals.Raw, yh - m.Fitted, 1e-10); ***** test ## default call creates a histogram with correct bin count and density fig = figure ('visible', 'off'); ax = axes (fig); h = plotResiduals (ax, mdl); xd = get (h(1), 'XData'); yd = get (h(1), 'YData'); r = mdl.Residuals.Raw(! isnan (mdl.Residuals.Raw)); bw = xd(3,1) - xd(1,1); assert_equal (numel (h), 1); assert_equal (get (h(1), 'type'), 'patch'); assert_equal (size (xd, 2) > 0, true); assert_equal (sum (yd(2,:)) * bw, 1, 1e-10); assert_equal (all (yd(1,:) == 0) && all (yd(4,:) == 0), true); assert_equal (get (get (ax, 'xlabel'), 'string'), 'Residuals'); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Probability density'); assert_equal (get (get (ax, 'title'), 'string'), 'Histogram of residuals'); close (fig); ***** test ## histogram bar color changes when FaceColor is passed fig = figure ('visible', 'off'); ax = axes (fig); h = plotResiduals (ax, mdl, 'histogram', 'FaceColor', [0 1 0]); assert_equal (get (h(1), 'FaceColor'), [0 1 0], 1e-10); close (fig); ***** test ## fitted plot shows residuals against fitted values with a zero reference line fig = figure ('visible', 'off'); ax = axes (fig); h = plotResiduals (ax, mdl, 'fitted'); assert_equal (numel (h), 2); assert_equal (get (h(1), 'XData'), mdl.Fitted', 1e-15); assert_equal (get (h(1), 'YData'), mdl.Residuals.Raw', 1e-15); assert_equal (get (h(1), 'LineStyle'), 'none'); assert_equal (get (h(1), 'Marker'), 'x'); assert_equal (get (h(2), 'YData'), [0 0]); assert_equal (get (h(2), 'LineStyle'), ':'); assert_equal (get (get (ax, 'xlabel'), 'string'), 'Fitted values'); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Residuals'); assert_equal (get (get (ax, 'title'), 'string'), 'Plot of residuals vs. fitted values'); close (fig); ***** test ## custom color applies to data points but leaves the reference line unchanged fig = figure ('visible', 'off'); ax = axes (fig); h = plotResiduals (ax, mdl, 'fitted', 'Color', [1 0 0]); assert_equal (get (h(1), 'Color'), [1 0 0], 1e-10); assert_equal (get (h(2), 'Color'), [0.8510 0.8510 0.8510], 1e-4); assert_equal (get (h(2), 'LineStyle'), ':'); close (fig); ***** test ## excluded rows appear as gaps in the fitted plot me = fitlm (X, y, 'Exclude', [3, 8]); fig = figure ('visible', 'off'); ax = axes (fig); h = plotResiduals (ax, me, 'fitted'); yd = get (h(1), 'YData'); assert_equal (numel (yd), 20); assert_equal (isnan (yd(3)), true); assert_equal (isnan (yd(8)), true); assert_equal (! isnan (yd(1)), true); close (fig); ***** test ## case order plot covers all rows and shows gaps where rows were excluded me = fitlm (X, y, 'Exclude', [2, 5]); fig = figure ('visible', 'off'); ax = axes (fig); h = plotResiduals (ax, me, 'caseorder'); xd = get (h(1), 'XData'); yd = get (h(1), 'YData'); assert_equal (xd, 1:20); assert_equal (isnan (yd(2)), true); assert_equal (isnan (yd(5)), true); assert_equal (! isnan (yd(1)), true); assert_equal (get (h(2), 'YData'), [0 0]); assert_equal (get (get (ax, 'xlabel'), 'string'), 'Row number'); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Residuals'); assert_equal (get (get (ax, 'title'), 'string'), 'Case order plot of residuals'); close (fig); ***** test ## lagged plot shows each residual against the previous one with two reference lines fig = figure ('visible', 'off'); ax = axes (fig); h = plotResiduals (ax, mdl, 'lagged'); r = mdl.Residuals.Raw; assert_equal (numel (h), 3); assert_equal (get (h(1), 'XData'), r(1:end-1)', 1e-15); assert_equal (get (h(1), 'YData'), r(2:end)', 1e-15); assert_equal (get (h(2), 'YData'), [0 0]); assert_equal (get (h(3), 'XData'), [0 0]); assert_equal (get (h(2), 'LineStyle'), ':'); assert_equal (get (get (ax, 'xlabel'), 'string'), 'Residual(t-1)'); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Residual(t)'); assert_equal (get (get (ax, 'title'), 'string'), 'Plot of residuals vs. lagged residuals'); close (fig); ***** test ## probability plot uses sorted active residuals as its data fig = figure ('visible', 'off'); ax = axes (fig); h = plotResiduals (ax, mdl, 'probability'); r_s = sort (mdl.Residuals.Raw(! isnan (mdl.Residuals.Raw))); assert_equal (get (h(1), 'XData'), r_s', 1e-15); assert_equal (get (get (ax, 'xlabel'), 'string'), 'Residuals'); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Probability'); assert_equal (get (get (ax, 'title'), 'string'), 'Normal probability plot of residuals'); close (fig); ***** test ## observed plot connects each point to the reference line with a vertical segment fig = figure ('visible', 'off'); ax = axes (fig); h = plotResiduals (ax, mdl, 'observed'); obs = mdl.Variables{:, mdl.ResponseName}; assert_equal (numel (h), 3); assert_equal (get (h(1), 'XData'), mdl.Fitted', 1e-15); assert_equal (get (h(1), 'YData'), obs', 1e-15); assert_equal (isequal (get (h(2), 'XData'), get (h(2), 'YData')), true); xd3 = get (h(3), 'XData'); assert_equal (numel (xd3), 3 * mdl.NumObservations); assert_equal (sum (isnan (xd3)), mdl.NumObservations); assert_equal (get (get (ax, 'xlabel'), 'string'), 'Fitted values'); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Observed response values'); assert_equal (get (get (ax, 'title'), 'string'), 'Plot of observed vs. fitted values'); close (fig); ***** test ## symmetry plot measures distance from median in both tails fig = figure ('visible', 'off'); ax = axes (fig); h = plotResiduals (ax, mdl, 'symmetry'); r_s = sort (mdl.Residuals.Raw(! isnan (mdl.Residuals.Raw))); med = median (r_s); m = floor (numel (r_s) / 2); x_sym = sort (med - r_s(1:m)); y_sym = sort (r_s(end-m+1:end) - med); assert_equal (numel (h), 2); assert_equal (get (h(1), 'XData'), x_sym', 1e-15); assert_equal (get (h(1), 'YData'), y_sym', 1e-15); assert_equal (isequal (get (h(2), 'XData'), get (h(2), 'YData')), true); assert_equal (get (h(2), 'LineStyle'), ':'); assert_equal (get (get (ax, 'xlabel'), 'string'), 'Lower tail'); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Upper tail'); close (fig); ***** test ## switching to pearson residuals changes plotted values but not x positions fig = figure ('visible', 'off'); ax = axes (fig); h = plotResiduals (ax, mdl, 'fitted', 'ResidualType', 'pearson'); assert_equal (get (h(1), 'YData'), mdl.Residuals.Pearson', 1e-15); assert_equal (get (h(1), 'XData'), mdl.Fitted', 1e-15); assert_equal (! isequal (get (h(1), 'YData'), mdl.Residuals.Raw'), true); close (fig); ***** test ## standardized and studentized residuals produce different values fig = figure ('visible', 'off'); ax = axes (fig); h1 = plotResiduals (ax, mdl, 'caseorder', 'ResidualType', 'standardized'); h2 = plotResiduals (ax, mdl, 'caseorder', 'ResidualType', 'studentized'); assert_equal (get (h1(1), 'YData'), mdl.Residuals.Standardized', 1e-15); assert_equal (get (h2(1), 'YData'), mdl.Residuals.Studentized', 1e-15); assert_equal (! isequal (get (h1(1), 'YData'), get (h2(1), 'YData')), true); close (fig); ***** test ## marker style and size apply to data points but not to the reference line fig = figure ('visible', 'off'); ax = axes (fig); h = plotResiduals (ax, mdl, 'fitted', 'Marker', 's', 'MarkerSize', 10); assert_equal (get (h(1), 'Marker'), 's'); assert_equal (get (h(1), 'MarkerSize'), 10); assert_equal (get (h(2), 'Marker'), 'none'); close (fig); ***** test ## weighted model residuals differ from unweighted residuals in the fitted plot mw = fitlm (X, y, 'Weights', (1:n)' / sum (1:n)); fig = figure ('visible', 'off'); ax = axes (fig); h = plotResiduals (ax, mw, 'fitted'); assert_equal (get (h(1), 'YData'), mw.Residuals.Raw', 1e-15); assert_equal (! isequal (get (h(1), 'YData'), mdl.Residuals.Raw'), true); close (fig); ***** test ## calling without an axes handle plots into the current axes fig = figure ('visible', 'off'); h = plotResiduals (mdl, 'fitted'); assert_equal (isgraphics (get (h(1), 'Parent'), 'axes'), true); assert_equal (isequal (get (h(1), 'Parent'), gca ()), true); close (fig); ***** test fig = figure ('visible', 'off'); ax = axes (fig); h = plotDiagnostics (ax, mdl); yd = get (h(1), 'YData'); assert_equal (numel (h), 2); assert_equal (get (h(1), 'XData'), 1:n); assert_equal (yd(1), 0.370779220779221, -1e-10); assert_equal (yd(2), 0.245283663704716, -1e-10); assert_equal (yd(3), 0.164718614718615, -1e-10); assert_equal (yd(4), 0.118147641831852, -1e-10); assert_equal (yd(5), 0.0960013670539986, -1e-10); assert_equal (yd(6), 0.0900774663932558, -1e-10); assert_equal (yd(7), 0.0935406698564593, -1e-10); assert_equal (yd(8), 0.100922761449077, -1e-10); assert_equal (yd(9), 0.108122579175211, -1e-10); assert_equal (yd(10), 0.112406015037594, -1e-10); assert_equal (yd(11), 0.112406015037594, -1e-10); assert_equal (yd(12), 0.108122579175211, -1e-10); assert_equal (yd(13), 0.100922761449077, -1e-10); assert_equal (yd(14), 0.0935406698564592, -1e-10); assert_equal (yd(15), 0.0900774663932559, -1e-10); assert_equal (yd(16), 0.0960013670539986, -1e-10); assert_equal (yd(17), 0.118147641831852, -1e-10); assert_equal (yd(18), 0.164718614718615, -1e-10); assert_equal (yd(19), 0.245283663704716, -1e-10); assert_equal (yd(20), 0.370779220779221, -1e-10); assert_equal (get (h(2), 'YData'), [0.3, 0.3], 1e-12); assert_equal (get (h(2), 'XData'), [0, n]); assert_equal (get (h(2), 'LineStyle'), ':'); assert_equal (get (get (ax, 'xlabel'), 'string'), 'Row number'); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Leverage'); assert_equal (get (get (ax, 'title'), 'string'), 'Case order plot of leverage'); close (fig); ***** test fig = figure ('visible', 'off'); ax = axes (fig); h = plotDiagnostics (ax, mdl, 'leverage', 'Color', [1 0 0]); assert_equal (get (h(1), 'Color'), [1 0 0], 1e-10); assert_equal (get (h(2), 'Color'), [0.8510 0.8510 0.8510], 1e-4); assert_equal (get (h(2), 'LineStyle'), ':'); close (fig); ***** test fig = figure ('visible', 'off'); ax = axes (fig); h = plotDiagnostics (ax, mdl, 'cookd'); yd = get (h(1), 'YData'); assert_equal (numel (h), 2); assert_equal (yd(1), 0.078517048682575, -1e-8); assert_equal (yd(2), 0.077211407930332, -1e-8); assert_equal (yd(3), 0.001953301452841, -1e-7); assert_equal (get (h(2), 'YData'), [0.1668641787, 0.1668641787], -1e-8); assert_equal (get (h(2), 'XData'), [0, n]); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Cook''s distance'); assert_equal (get (get (ax, 'title'), 'string'), 'Case order plot of Cook''s distance'); close (fig); ***** test fig = figure ('visible', 'off'); ax = axes (fig); h = plotDiagnostics (ax, mdl, 'covratio'); yd = get (h(1), 'YData'); yv = get (h(2), 'YData'); xv = get (h(2), 'XData'); assert_equal (numel (h), 2); assert_equal (yd(1), 1.774933177, -1e-8); assert_equal (yd(2), 1.397661919, -1e-8); assert_equal (yd(3), 1.428481535, -1e-8); assert_equal (numel (xv), 5); assert_equal (sum (isnan (xv)), 1); assert_equal (yv(1), 0.55, 1e-12); assert_equal (yv(2), 0.55, 1e-12); assert_equal (yv(4), 1.45, 1e-12); assert_equal (yv(5), 1.45, 1e-12); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Covariance ratio'); assert_equal (get (get (ax, 'title'), 'string'), 'Case order plot of covariance ratio'); close (fig); ***** test fig = figure ('visible', 'off'); ax = axes (fig); h = plotDiagnostics (ax, mdl, 'dfbetas'); p = mdl.NumCoefficients; yv = get (h(p+1), 'YData'); xv = get (h(p+1), 'XData'); assert_equal (numel (h), p + 1); assert_equal (numel (get (h(1), 'YData')), n); assert_equal (numel (get (h(2), 'YData')), n); assert_equal (numel (get (h(3), 'YData')), n); assert_equal (numel (xv), 5); assert_equal (sum (isnan (xv)), 1); assert_equal (yv(1), -0.6708203932, -1e-8); assert_equal (yv(end), 0.6708203932, -1e-8); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Scaled change in coefficients'); assert_equal (get (get (ax, 'title'), 'string'), 'Case order plot of scaled change in coefficients'); close (fig); ***** test fig = figure ('visible', 'off'); ax = axes (fig); h = plotDiagnostics (ax, mdl, 'dfbetas', 'Color', [1 0 0]); p = mdl.NumCoefficients; for k = 1:p assert_equal (get (h(k), 'Color'), [1 0 0], 1e-10); endfor assert_equal (get (h(p+1), 'Color'), [0.8510 0.8510 0.8510], 1e-4); close (fig); ***** test fig = figure ('visible', 'off'); ax = axes (fig); h = plotDiagnostics (ax, mdl, 'dffits'); yd = get (h(1), 'YData'); yv = get (h(2), 'YData'); xv = get (h(2), 'XData'); assert_equal (numel (h), 2); assert_equal (yd(1), 0.476480465355394, -1e-8); assert_equal (yd(2), 0.477020506700835, -1e-8); assert_equal (yd(3), -0.074329411030064, -1e-7); assert_equal (sum (isnan (xv)), 1); assert_equal (yv(1), -0.7745966692, -1e-8); assert_equal (yv(end), 0.7745966692, -1e-8); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Scaled change in fit'); assert_equal (get (get (ax, 'title'), 'string'), 'Case order plot of scaled change in fit'); close (fig); ***** test fig = figure ('visible', 'off'); ax = axes (fig); h = plotDiagnostics (ax, mdl, 's2_i'); yd = get (h(1), 'YData'); assert_equal (numel (h), 2); assert_equal (yd(1), 0.02359100986, -1e-8); assert_equal (yd(2), 0.02314622330, -1e-8); assert_equal (yd(3), 0.02411685408, -1e-8); assert_equal (get (h(2), 'YData'), [0.02273796067, 0.02273796067], -1e-8); assert_equal (get (h(2), 'XData'), [0, n]); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Leave-one-out variance'); assert_equal (get (get (ax, 'title'), 'string'), 'Case order plot of leave-one-out variance'); close (fig); ***** test fig = figure ('visible', 'off'); ax = axes (fig); h = plotDiagnostics (ax, mdl, 'contour'); yd = get (h(1), 'YData'); xd = get (h(1), 'XData'); assert_equal (numel (h), 2); assert_equal (xd(1), 0.3707792208, -1e-8); assert_equal (xd(2), 0.2452836637, -1e-8); assert_equal (yd(1), 0.07562471113, -1e-8); assert_equal (yd(2), 0.11059272450, -1e-8); assert_equal (get (h(1), 'LineStyle'), 'none'); assert_equal (get (h(1), 'Marker'), 'x'); assert_equal (isgraphics (h(2)), true); assert_equal (get (get (ax, 'xlabel'), 'string'), 'Leverage'); assert_equal (get (get (ax, 'ylabel'), 'string'), 'Residual'); assert_equal (get (get (ax, 'title'), 'string'), 'Cook''s distance factorization'); close (fig); ***** test me = fitlm (X, y, 'Exclude', [2, 7]); fig = figure ('visible', 'off'); ax = axes (fig); h_ex = plotDiagnostics (ax, me, 'cookd'); h_un = plotDiagnostics (ax, mdl, 'cookd'); ref_ex = get (h_ex(2), 'YData'); ref_un = get (h_un(2), 'YData'); assert_equal (! isequal (ref_ex, ref_un), true); assert_equal (ref_ex(1), 3 * mean (me.Diagnostics.CooksDistance, 'omitnan'), 1e-12); close (fig); ***** test mw = fitlm (X, y, 'Weights', (1:n)' / sum (1:n)); fig = figure ('visible', 'off'); ax = axes (fig); hw = plotDiagnostics (ax, mw, 'leverage'); hu = plotDiagnostics (ax, mdl, 'leverage'); ydw = get (hw(1), 'YData'); ydu = get (hu(1), 'YData'); assert_equal (ydw(1) != ydu(1), true); assert_equal (! isequal (ydw, ydu), true); close (fig); ***** test fig = figure ('visible', 'off'); h = plotDiagnostics (mdl); assert_equal (isequal (get (h(1), 'Parent'), gca ()), true); close (fig); ***** test fig = figure ('visible', 'off'); ax = axes (fig); h = plotEffects (ax, mdl); xd1 = get (h(1), 'XData'); yd1 = get (h(1), 'YData'); xd2 = get (h(2), 'XData'); yd2 = get (h(2), 'YData'); xd3 = get (h(3), 'XData'); yd3 = get (h(3), 'YData'); ytl = get (ax, 'YTickLabel'); assert_equal (numel (h), 3); assert_equal (xd1(1), 2.38302891604232, -1e-10); assert_equal (xd1(2), -19.5277648300125, -1e-10); assert_equal (yd1, [1 2]); assert_equal (xd2(1), 1.39673712385796, -1e-10); assert_equal (xd2(2), 3.36932070822668, -1e-10); assert_equal (yd2, [1 1]); assert_equal (xd3(1), -20.4857975891918, -1e-10); assert_equal (xd3(2), -18.5697320708331, -1e-10); assert_equal (yd3, [2 2]); assert_equal (get (h(1), 'Color'), [0.1490 0.5490 0.8660], 1e-4); assert_equal (get (h(2), 'Color'), [0.1490 0.5490 0.8660], 1e-4); assert_equal (get (h(3), 'Color'), [0.1490 0.5490 0.8660], 1e-4); assert_equal (get (h(1), 'Marker'), 'o'); assert_equal (get (h(1), 'LineStyle'), 'none'); assert_equal (get (h(2), 'LineStyle'), '-'); assert_equal (get (h(2), 'Marker'), 'none'); assert_equal (get (h(3), 'LineStyle'), '-'); assert_equal (get (h(3), 'Marker'), 'none'); assert_equal (mean (xd2), xd1(1), 1e-10); assert_equal (mean (xd3), xd1(2), 1e-10); assert_equal (get (get (ax, 'xlabel'), 'string'), 'Main Effect'); assert_equal (get (get (ax, 'ylabel'), 'string'), ''); assert_equal (get (get (ax, 'title'), 'string'), 'Main Effects Plot'); assert_equal (get (ax, 'YTick'), [1 2]); assert_equal (ytl{1}, 'x1: 0.05 to 1'); assert_equal (ytl{2}, 'x2: 0.05 to 20'); close (fig); ***** test ## 3-predictor model X3 = [X, sin((1:n)' * pi / n)]; y3 = X3 * [3; -1; 2] + 0.1 * cos ((1:n)' * pi / 7); m3 = fitlm (X3, y3); fig = figure ('visible', 'off'); ax = axes (fig); h = plotEffects (ax, m3); xd1 = get (h(1), 'XData'); yd1 = get (h(1), 'YData'); xd2 = get (h(2), 'XData'); yd2 = get (h(2), 'YData'); xd3 = get (h(3), 'XData'); yd3 = get (h(3), 'YData'); xd4 = get (h(4), 'XData'); yd4 = get (h(4), 'YData'); ytl = get (ax, 'YTickLabel'); assert_equal (numel (h), 4); assert_equal (xd1(1), 8.10687671732127, -1e-10); assert_equal (xd1(2), -25.4487243632125, -1e-10); assert_equal (xd1(3), 0.661302203942261, -1e-10); assert_equal (yd1, [1 2 3]); assert_equal (xd2(1), 0.565266595687836, -1e-10); assert_equal (xd2(2), 15.6484868389547, -1e-10); assert_equal (yd2, [1 1]); assert_equal (xd3(1), -33.3368582824351, -1e-10); assert_equal (xd3(2), -17.5605904439899, -1e-10); assert_equal (yd3, [2 2]); assert_equal (xd4(1), -1.25582490831999, -1e-10); assert_equal (xd4(2), 2.57842931620451, -1e-10); assert_equal (yd4, [3 3]); assert_equal (get (ax, 'YTick'), [1 2 3]); assert_equal (ytl{1}, 'x1: 0.05 to 1'); assert_equal (ytl{2}, 'x2: 0.05 to 20'); assert_equal (ytl{3}, 'x3: 1.22465e-16 to 1'); assert_equal (mean (xd2), xd1(1), 1e-10); assert_equal (mean (xd3), xd1(2), 1e-10); assert_equal (mean (xd4), xd1(3), 1e-10); close (fig); ***** test me = fitlm (X, y, 'Exclude', [2, 7]); fig = figure ('visible', 'off'); ax = axes (fig); h = plotEffects (ax, me); xd1 = get (h(1), 'XData'); yd1 = get (h(1), 'YData'); xd2 = get (h(2), 'XData'); yd2 = get (h(2), 'YData'); xd3 = get (h(3), 'XData'); yd3 = get (h(3), 'YData'); ytl = get (ax, 'YTickLabel'); assert_equal (numel (h), 3); assert_equal (xd1(1), 2.50035744908398, -1e-10); assert_equal (xd1(2), -19.5912988214488, -1e-10); assert_equal (yd1, [1 2]); assert_equal (xd2(1), 1.40421088339552, -1e-10); assert_equal (xd2(2), 3.59650401477245, -1e-10); assert_equal (yd2, [1 1]); assert_equal (xd3(1), -20.6333076647782, -1e-10); assert_equal (xd3(2), -18.5492899781194, -1e-10); assert_equal (yd3, [2 2]); assert_equal (ytl{1}, 'x1: 0.05 to 1'); assert_equal (ytl{2}, 'x2: 0.05 to 20'); assert_equal (mean (xd2), xd1(1), 1e-10); assert_equal (mean (xd3), xd1(2), 1e-10); close (fig); ***** test mw = fitlm (X, y, 'Weights', (1:n)' / sum (1:n)); fig = figure ('visible', 'off'); ax = axes (fig); h = plotEffects (ax, mw); xd1 = get (h(1), 'XData'); yd1 = get (h(1), 'YData'); xd2 = get (h(2), 'XData'); yd2 = get (h(2), 'YData'); xd3 = get (h(3), 'XData'); yd3 = get (h(3), 'YData'); ytl = get (ax, 'YTickLabel'); assert_equal (numel (h), 3); assert_equal (xd1(1), 2.51587141860715, -1e-10); assert_equal (xd1(2), -19.6411669663483, -1e-10); assert_equal (yd1, [1 2]); assert_equal (xd2(1), 1.08491557053384, -1e-10); assert_equal (xd2(2), 3.94682726668046, -1e-10); assert_equal (yd2, [1 1]); assert_equal (xd3(1), -20.8383905241664, -1e-10); assert_equal (xd3(2), -18.4439434085302, -1e-10); assert_equal (yd3, [2 2]); assert_equal (ytl{1}, 'x1: 0.05 to 1'); assert_equal (ytl{2}, 'x2: 0.05 to 20'); assert_equal (mean (xd2), xd1(1), 1e-10); assert_equal (mean (xd3), xd1(2), 1e-10); close (fig); ***** test mni = fitlm (X, y, 'Intercept', false); fig = figure ('visible', 'off'); ax = axes (fig); h = plotEffects (ax, mni); xd1 = get (h(1), 'XData'); yd1 = get (h(1), 'YData'); xd2 = get (h(2), 'XData'); yd2 = get (h(2), 'YData'); xd3 = get (h(3), 'XData'); yd3 = get (h(3), 'YData'); ytl = get (ax, 'YTickLabel'); assert_equal (numel (h), 3); assert_equal (xd1(1), 2.81335053251731, -1e-10); assert_equal (xd1(2), -19.8951125513936, -1e-10); assert_equal (yd1, [1 2]); assert_equal (xd2(1), 2.36234515544211, -1e-10); assert_equal (xd2(2), 3.26435590959250, -1e-10); assert_equal (yd2, [1 1]); assert_equal (xd3(1), -20.4919734818287, -1e-10); assert_equal (xd3(2), -19.2982516209584, -1e-10); assert_equal (yd3, [2 2]); assert_equal (ytl{1}, 'x1: 0.05 to 1'); assert_equal (ytl{2}, 'x2: 0.05 to 20'); assert_equal (mean (xd2), xd1(1), 1e-10); assert_equal (mean (xd3), xd1(2), 1e-10); close (fig); ***** test fig = figure ('visible', 'off'); ax = axes (fig); h = plotEffects (ax, mdl); assert_equal (isequal (get (h(1), 'Parent'), ax), true); assert_equal (get (h(1), 'XData'), [2.38302891604232, -19.5277648300125], -1e-10); close (fig); ***** test fig = figure ('visible', 'off'); h = plotEffects (mdl); assert_equal (isequal (get (h(1), 'Parent'), gca ()), true); assert_equal (get (h(1), 'XData'), [2.38302891604232, -19.5277648300125], -1e-10); close (fig); ***** test ## numeric predictor adjusted data fig = figure ('visible', 'off'); h = plotAdjustedResponse (mdl, 'x1'); assert_equal (get (h(1), 'XData'), X(:,1)', 1e-10); assert_equal (get (h(1), 'YData'), ... [-6.70590752804287, -6.54551694016554, -6.5544435914624, -6.59143572669715, ... -6.49138418414686, -6.21712299745016, -5.89359961368025, -5.69299878673044, ... -5.67643670865536, -5.73777106454765, -5.70118778736348, -5.48284370035446, ... -5.16795154710756, -4.93243578806991, -4.88118846293094, -4.95163193306634, ... -4.97125247389768, -4.81620859768203, -4.52519034621851, -4.26384784484646], 1e-8); xf = get (h(2), 'XData'); yf = get (h(2), 'YData'); assert_equal (numel (xf), 100); assert_equal (xf(1:5), ... [0.05, 0.0595959595959596, 0.0691919191919192, 0.0787878787878788, 0.0883838383838384], 1e-10); assert_equal (yf(1:5), ... [-6.78153223917696, -6.75746124002502, -6.73339024087308, -6.70931924172113, -6.68524824256919], 1e-8); assert_equal (xf(end-4:end), ... [0.961616161616162, 0.971212121212121, 0.980808080808081, 0.99040404040404, 1], 1e-10); assert_equal (yf(end-4:end), ... [-4.49478731974241, -4.47071632059047, -4.44664532143853, -4.42257432228658, -4.39850332313464], 1e-8); close (fig); ***** test ## title and axis labels follow the standard convention fig = figure ('visible', 'off'); plotAdjustedResponse (mdl, 'x1'); assert_equal (get (get (gca, 'Title'), 'String'), 'Adjusted response plot'); assert_equal (get (get (gca, 'XLabel'), 'String'), 'x1'); assert_equal (get (get (gca, 'YLabel'), 'String'), 'Adjusted y'); close (fig); ***** test ## ax routing and a second predictor fig = figure ('visible', 'off'); ax = axes (fig); h = plotAdjustedResponse (ax, mdl, 'x2'); assert_equal (isequal (get (h(1), 'Parent'), ax), true); assert_equal (get (h(1), 'XData'), X(:,2)', 1e-8); assert_equal (get (h(1), 'YData'), ... [1.45980865498274, 1.34795136885775, 0.968893310576047, 0.463886235373945, ... -0.00196069502564064, -0.391481514261341, -0.829623669406342, -1.48857191435397, ... -2.42944244115883, -3.5460929349136, -4.66270932857441, -5.6954484453929, ... -6.72952302895603, -7.94085753971093, -9.43434401734702, -11.14740482324, ... -12.9075262328114, -14.5908667583184, -16.23611644156, -18.0089254078756], 1e-7); close (fig); ***** test ## name-value arguments style the data points only fig = figure ('visible', 'off'); h = plotAdjustedResponse (mdl, 'x1', 'Marker', 's', 'MarkerSize', 10, 'Color', 'r'); assert_equal (get (h(1), 'Marker'), 's'); assert_equal (get (h(1), 'MarkerSize'), 10); assert_equal (get (h(1), 'Color'), [1 0 0]); assert_equal (get (h(2), 'Marker'), 'none'); close (fig); ***** test yn = y; yn(3) = NaN; mn = fitlm (X, yn); fig = figure ('visible', 'off'); h = plotAdjustedResponse (mn, 'x1'); xd = get (h(1), 'XData'); yd = get (h(1), 'YData'); assert_equal (isnan (xd(3)), true); assert_equal (isnan (yd(3)), true); assert_equal (yd([1 2 4]), [-7.04679028889336, -6.88651148335619, -6.93287739924846], 1e-8); close (fig); ***** test w = mod ((1:n)', 3) + 1; mw = fitlm (X, y, 'Weights', w); fig = figure ('visible', 'off'); h = plotAdjustedResponse (mw, 'x1'); assert_equal (get (h(1), 'YData'), ... [-6.66184168801736, -6.5023788020353, -6.51285162315763, -6.55200839614801, ... -6.45473995928354, -6.18388034620285, -5.86437700397912, -5.66841468650568, ... -5.65710958583715, -5.72431938706618, -5.69423002314892, -5.482998317337, ... -5.17583701321739, -4.9486705712372, -4.90639103108588, -4.98642075413911, ... -5.01624601581846, -4.87202532838101, -4.59244873362587, -4.34316635689238], 1e-7); close (fig); ***** test ## robust regression mr = fitlm (X, y, 'RobustOpts', 'on'); fig = figure ('visible', 'off'); h = plotAdjustedResponse (mr, 'x1'); assert_equal (get (h(1), 'YData'), ... [-6.69986109212516, -6.53959779763556, -6.54873660457867, -6.58602575771814, ... -6.48635609533107, -6.2125616510561, -5.88958987196639, -5.68962551195529, ... -5.67378476307741, -5.7359253104254, -5.70023308695542, -5.48286491591908, ... -5.16903354090336, -4.93466342235539, -4.88464659996458, -4.95640543510664, ... -4.97742620320314, -4.82386741651113, -4.53441911682976, -4.27473142949835], 1e-7); close (fig); ***** test ## numeric predictor averaged over a categorical predictor wt = [3504;3693;3436;3433;3449;3672;3705;3288;3092;2500;2700;3100]; yr = categorical ([70;70;70;70;70;76;76;76;82;82;82;82]); mg = [18;15;18;16;17;20;22;24;30;32;28;26]; tc = table (mg, wt, yr, 'VariableNames', {'MPG','Weight','Year'}); mc = fitlm (tc, 'MPG ~ Year + Weight'); fig = figure ('visible', 'off'); h = plotAdjustedResponse (mc, 'Weight'); assert_equal (get (h(1), 'XData'), wt', 1e-10); assert_equal (get (h(1), 'YData'), ... [22.1247351073949, 19.1247351073949, 22.1247351073949, 20.1247351073949, ... 21.1247351073949, 18.6102199722546, 20.6102199722546, 22.6102199722546, ... 25.8864161365654, 27.8864161365654, 23.8864161365654, 21.8864161365654], 1e-8); xf = get (h(2), 'XData'); yf = get (h(2), 'YData'); assert_equal (xf(1:5), ... [2500, 2512.17171717172, 2524.34343434343, 2536.51515151515, 2548.68686868687], 1e-8); assert_equal (yf(1:5), ... [26.9912481948118, 26.9176291703666, 26.8440101459214, 26.7703911214761, 26.6967720970309], 1e-8); close (fig); ***** test ## categorical predictor evaluated per level wt = [3504;3693;3436;3433;3449;3672;3705;3288;3092;2500;2700;3100]; yr = categorical ([70;70;70;70;70;76;76;76;82;82;82;82]); mg = [18;15;18;16;17;20;22;24;30;32;28;26]; tc = table (mg, wt, yr, 'VariableNames', {'MPG','Weight','Year'}); mc = fitlm (tc, 'MPG ~ Year + Weight'); fig = figure ('visible', 'off'); h = plotAdjustedResponse (mc, 'Year'); assert_equal (get (h(1), 'XData'), [1 1 1 1 1 2 2 2 3 3 3 3]); assert_equal (get (h(1), 'YData'), ... [19.2479799272553, 17.3911214761304, 18.8366909043795, 16.8185458004291, ... 17.9153196881646, 22.2641057484776, 24.463701891932, 23.9415324428265, ... 28.7560523180671, 27.1754184718549, 24.3850920685482, 24.8044392619348], 1e-7); assert_equal (get (h(2), 'XData'), [1 2 3]); assert_equal (get (h(2), 'YData'), [18.0419315592718, 23.5564466944121, 26.2802505301012], 1e-8); assert_equal (get (gca, 'XTickLabel'), {'70'; '76'; '82'}); close (fig); ***** test ## added variable plot for the whole model fig = figure ('visible', 'off'); h = plotAdded (mdl); assert_equal (get (get (gca, 'Title'), 'String'), 'Added variable plot for whole model'); assert_equal (get (get (gca, 'XLabel'), 'String'), 'Adjusted whole model'); assert_equal (get (h(1), 'XData'), ... [0.0284033824838481, 0.0204548552857604, -0.0238455815942649, -0.104497928156226, ... -0.221502184400124, -0.374858350325959, -0.564566425933731, -0.79062641122344, ... -1.05303830619508, -1.35180211084867, -1.68691782518418, -2.05838544920164, ... -2.46620498290103, -2.91037642628236, -3.39089977934563, -3.90777504209083, ... -4.46100221451797, -5.05058129662704, -5.67651228841805, -6.338795189891], 1e-7); assert_equal (get (h(1), 'YData'), ... [0.268294196961578, 0.281859485365135, 0.0282240016119717, -0.351360499061586, ... -0.691784854932629, -0.955883099639786, -1.26860268025624, -1.80212835067532, ... -2.61757630295165, -3.60880422217788, -4.59999804131014, -5.50731458360009, ... -6.41596659263467, -7.50187852886103, -8.86994243196858, -10.457580663333, ... -12.0922794983759, -13.6501974493543, -15.1700245580674, -16.8174109498545], 1e-7); assert_equal (get (h(2), 'DisplayName'), 'Fit: y = 2.69267*x'); close (fig); ***** test ## added variable plot for just the intercept term fig = figure ('visible', 'off'); h = plotAdded (mdl, 1); assert_equal (get (get (gca, 'Title'), 'String'), 'Added variable plot for (Intercept)'); assert_equal (get (h(1), 'YData'), ... [-5.41993222738086, -5.40485070721962, -5.55724508427077, -5.73586360329798, ... -5.77559710257835, -5.63927961575051, -5.45185858988763, -5.38551877888305, ... -5.50137637479139, -5.6932890627053, -5.78544277558092, -5.6939943366699, ... -5.50415648955918, -5.3918536946959, -5.4619779917695, -5.65195174215564, ... -5.78926122127593, -5.75006494138741, -5.57305294428921, -5.42387535532067], 1e-7); assert_equal (get (h(2), 'DisplayName'), 'Fit: y = 0.116189*x'); close (fig); ***** test ## added variable plot for one predictor picked by index fig = figure ('visible', 'off'); h = plotAdded (mdl, 2); assert_equal (get (get (gca, 'Title'), 'String'), 'Added variable plot for x1'); assert_equal (get (h(1), 'YData'), ... [-5.90289714234183, -5.75941203626873, -5.79651449057265, -5.87295275001727, ... -5.82361765287968, -5.6113432327985, -5.36107693684693, -5.24500351891828, ... -5.32423917106718, -5.49264157838629, -5.57439667383173, -5.48566128065516, ... -5.31164814244354, -5.22828171964398, -5.34045405194592, -5.58558750072505, ... -5.79116834140295, -5.83335508623668, -5.75083777702536, -5.70926653910833], 1e-7); assert_equal (get (h(2), 'DisplayName'), 'Fit: y = 2.50845*x'); xf = get (h(2), 'XData'); yf = get (h(2), 'YData'); assert_equal (xf(1:3), [0.370121951219512, 0.372449462532903, 0.374776973846294], 1e-9); assert_equal (yf(1:3), [-5.97852185347592, -5.97268340425253, -5.96684495502913], 1e-7); close (fig); ***** test ## added variable plot for the other predictor, a negative slope this time fig = figure ('visible', 'off'); h = plotAdded (mdl, 3); assert_equal (get (get (gca, 'Title'), 'String'), 'Added variable plot for x2'); assert_equal (get (h(1), 'YData'), ... [-8.3040737600235, -7.38815394983204, -6.7394349117973, -6.21666489068295, ... -5.65473472476609, -5.01647844768535, -4.4268435065139, -4.05801465514508, ... -3.9711080856335, -4.05998148307182, -4.14882078041619, -4.15378280091823, ... -4.16008028816491, -4.34363770260337, -4.80934708392301, -5.49463079349955, ... -6.22697510675454, -6.88253853594507, -7.50001112287024, -8.2450429928694], 1e-7); assert_equal (get (h(2), 'DisplayName'), 'Fit: y = -0.978835*x'); close (fig); ***** test ## ax argument sends the plot to that axes fig = figure ('visible', 'off'); ax = axes (fig); h = plotAdded (ax, mdl, 2); assert_equal (isequal (get (h(1), 'Parent'), ax), true); close (fig); ***** test ## name-value styling only changes the data points, not the fit line fig = figure ('visible', 'off'); h = plotAdded (mdl, 2, 'Marker', 's', 'MarkerSize', 10, 'Color', 'r'); assert_equal (get (h(1), 'Marker'), 's'); assert_equal (get (h(1), 'MarkerSize'), 10); assert_equal (get (h(1), 'Color'), [1 0 0]); assert_equal (get (h(2), 'Marker'), 'none'); close (fig); ***** test ## a missing observation leaves a gap in the adjusted data yn = y; yn(3) = NaN; mn = fitlm (X, yn); fig = figure ('visible', 'off'); h = plotAdded (mn, 2); xd = get (h(1), 'XData'); yd = get (h(1), 'YData'); assert_equal (isnan (xd(3)), true); assert_equal (isnan (yd(3)), true); close (fig); ***** test ## weighted fit still gives a proper added variable plot w = mod ((1:n)', 3) + 1; mw = fitlm (X, y, 'Weights', w); fig = figure ('visible', 'off'); h = plotAdded (mw, 2); assert_equal (get (h(1), 'YData'), ... [-6.04899282212585, -5.90562605001686, -5.9429257275943, -6.01964009962184, ... -5.97066000437658, -5.75881947549715, -5.50906596005672, -5.39358421194863, ... -5.4734904232275, -5.64264227898597, -5.7252257121802, -5.63739754606181, ... -5.46437052421778, -5.38206910709522, -5.49538533438357, -5.74174156745852, ... -5.94862408174164, -5.99219138949, -5.91113353250271, -5.87110063611913], 1e-7); assert_equal (get (h(2), 'DisplayName'), 'Fit: y = 2.38836*x'); close (fig); ***** test ## robust fit still gives a proper added variable plot mr = fitlm (X, y, 'RobustOpts', 'on'); fig = figure ('visible', 'off'); h = plotAdded (mr, 2); assert_equal (get (h(1), 'YData'), ... [-5.89409568732029, -5.75060102429134, -5.78768755033552, -5.86410351021651, ... -5.81473974221138, -5.60243027995878, -5.35212257053188, -5.23600136782402, ... -5.31518286388981, -5.4835247438219, -5.56521294057644, -5.47640427740507, ... -5.30231149789475, -5.2188590624926, -5.33093901088806, -5.5759737044568, ... -5.78144941862042, -5.82352466563597, -5.74088948730258, -5.69919400895959], 1e-7); assert_equal (get (h(2), 'DisplayName'), 'Fit: y = 2.48815*x'); close (fig); ***** test ## added variable plot for the whole model load carsmall Year = categorical (Model_Year); tbl = table (MPG, Weight, Year); mdl1 = fitlm (tbl, 'MPG ~ Year + Weight^2'); fig = figure ('visible', 'off'); h = plotAdded (mdl1); assert_equal (get (get (gca, 'Title'), 'String'), 'Added variable plot for whole model'); assert_equal (get (get (gca, 'XLabel'), 'String'), 'Adjusted whole model'); xd = get (h(1), 'XData'); yd = get (h(1), 'YData'); assert_equal (xd(1:5), ... [-4.54006581304461, -4.65629283432076, -4.49502736854252, ... -4.49300111649177, -4.50376945388336], 1e-7); assert_equal (yd(1:5), [18, 15, 18, 16, 17], 1e-8); assert_equal (get (h(2), 'DisplayName'), 'Fit: y = 8.44866*x'); xf = get (h(2), 'XData'); yf = get (h(2), 'YData'); assert_equal (xf(1:3), [-5.06005142297709, -5.03050027197254, -5.000949120968], 1e-7); assert_equal (yf(1:3), [11.4556384009199, 11.7053059986795, 11.9549735964392], 1e-7); close (fig); ***** test ## selecting every non-intercept coefficient is the whole model; any ## other multi-coefficient selection is a list of specified terms X3 = [X, cos((1:n)')]; m3 = fitlm (X3, y); fig = figure ('visible', 'off'); plotAdded (m3, [2 3 4]); assert_equal (get (get (gca, 'Title'), 'String'), ... 'Added variable plot for whole model'); assert_equal (get (get (gca, 'XLabel'), 'String'), 'Adjusted whole model'); clf; plotAdded (m3, [2 3]); assert_equal (get (get (gca, 'Title'), 'String'), ... 'Added variable plot for specified terms'); close (fig); ***** test ## added variable plot for the weight terms picked as a pair load carsmall Year = categorical (Model_Year); tbl = table (MPG, Weight, Year); mdl1 = fitlm (tbl, 'MPG ~ Year + Weight^2'); fig = figure ('visible', 'off'); h = plotAdded (mdl1, [2 5]); assert_equal (get (get (gca, 'Title'), 'String'), 'Added variable plot for specified terms'); assert_equal (get (get (gca, 'XLabel'), 'String'), 'Adjusted specified terms'); xd = get (h(1), 'XData'); yd = get (h(1), 'YData'); assert_equal (xd(1:5), ... [-2181.48546848357, -2241.34798193195, -2158.28850051435, ... -2157.24488312395, -2162.79109548355], 1e-6); assert_equal (yd(1:5), ... [24.0284299339692, 21.0284299339692, 24.0284299339692, ... 22.0284299339692, 23.0284299339692], 1e-7); assert_equal (get (h(2), 'DisplayName'), 'Fit: y = 0.0164036*x'); close (fig); ***** test ## multiple predictors delegate to plotAdded fig = figure ('visible', 'off'); ax = axes (fig); h1 = plot (ax, mdl); h2 = plotAdded (ax, mdl); assert_equal (get (h1(1), 'XData'), get (h2(1), 'XData')); assert_equal (get (h1(1), 'YData'), get (h2(1), 'YData')); assert_equal (get (h1(2), 'YData'), get (h2(2), 'YData')); assert_equal (get (h1(3), 'YData'), get (h2(3), 'YData')); assert_equal (get (get (ax, 'Title'), 'String'), 'Added variable plot for whole model'); close (fig); ***** test ## no axes argument uses the current axes fig = figure ('visible', 'off'); h = plot (mdl); assert_equal (isequal (get (h(1), 'Parent'), gca ()), true); close (fig); ***** test ## no predictors delegate to plotResiduals mc = fitlm (X, y, 'constant'); fig = figure ('visible', 'off'); ax = axes (fig); h1 = plot (ax, mc); h2 = plotResiduals (ax, mc); assert_equal (get (h1(1), 'type'), 'patch'); assert_equal (get (h1(1), 'YData'), get (h2(1), 'YData')); assert_equal (get (get (ax, 'Title'), 'String'), 'Histogram of residuals'); close (fig); ***** test ## single predictor: data, fit line, and confidence bounds m1 = fitlm (X(:,1), y); fig = figure ('visible', 'off'); ax = axes (fig); h = plot (ax, m1); assert_equal (numel (h), 3); assert_equal (get (h(1), 'XData'), X(:,1)', 1e-15); assert_equal (get (h(1), 'YData'), y', 1e-15); xf = get (h(2), 'XData'); yf = get (h(2), 'YData'); assert_equal (numel (xf), 100); assert_equal (xf(1:3), [0.05, 0.0595959595959596, 0.0691919191919192], 1e-12); assert_equal (xf(end-2:end), [0.980808080808081, 0.99040404040404, 1], 1e-12); assert_equal (yf(1:3), [2.98235017582927, 2.80917102518311, 2.63599187453694], 1e-7); assert_equal (yf(end-2:end), [-13.8160274368485, -13.9892065874947, -14.1623857381409], 1e-7); yb = get (h(3), 'YData'); assert_equal (numel (yb), 201); assert_equal (isnan (yb(101)), true); assert_equal (yb(1:3), [1.59215527128182, 1.43944293975561, 1.28661387851973], 1e-7); assert_equal (yb(102:104), [4.37254508037672, 4.1788991106106, 3.98536987055415], 1e-7); assert_equal (yb(end-2:end), [-12.4666494408313, -12.6194785020672, -12.7721908335934], 1e-7); assert_equal (yb(1:100) + yb(102:201), 2 * yf, 1e-10); [yp, ~] = predict (m1, xf'); assert_equal (yf', yp, 1e-10); assert_equal (get (get (ax, 'Title'), 'String'), 'y vs. x1'); assert_equal (get (get (ax, 'XLabel'), 'String'), 'x1'); assert_equal (get (get (ax, 'YLabel'), 'String'), 'y'); close (fig); ***** test ## real dataset with missing rows leaves gaps in the data load carsmall tbl2 = table (MPG, Weight); mdl2 = fitlm (tbl2, 'MPG ~ Weight'); fig = figure ('visible', 'off'); ax = axes (fig); h = plot (ax, mdl2); xd = get (h(1), 'XData'); yd = get (h(1), 'YData'); assert_equal (numel (xd), 100); assert_equal (any (isnan (xd)), true); assert_equal (any (isnan (yd)), true); assert_equal (xd(1:3), [3504, 3693, 3436], 1e-10); assert_equal (xd(end-2:end), [2295, 2625, 2720], 1e-10); assert_equal (yd(1:3), [18, 15, 18], 1e-10); assert_equal (yd(end-2:end), [32, 28, 31], 1e-10); xf = get (h(2), 'XData'); yf = get (h(2), 'YData'); assert_equal (numel (xf), 100); assert_equal (xf(1:3), [1795, 1824.666667, 1854.333333], 1e-4); assert_equal (xf(end-2:end), [4672.666667, 4702.333333, 4732], 1e-4); assert_equal (yf(1:3), [33.77920696, 33.52371956, 33.26823216], 1e-6); assert_equal (yf(end-2:end), [8.996929296, 8.741441898, 8.485954499], 1e-6); yb = get (h(3), 'YData'); assert_equal (numel (yb), 201); assert_equal (yb(1:3), [32.2768265, 32.0472587, 31.81746955], 1e-6); assert_equal (yb(end-2:end), [11.0004001, 10.77351303, 10.54671087], 1e-6); assert_equal (get (get (ax, 'Title'), 'String'), 'MPG vs. Weight'); assert_equal (get (get (ax, 'XLabel'), 'String'), 'Weight'); assert_equal (get (get (ax, 'YLabel'), 'String'), 'MPG'); close (fig); ***** test ## categorical predictor: group codes with per-level fit and bounds yv = [4.73087805313537; 7.43361607881479; 4.48799323173627; 5.16869512618961; ... 6.50195295169252; 3.73839298415678; 4.3512762614163; 7.45869429457297; ... 4.08830081430877; 5.37758996783874; 6.70425002011403; 4.92219481850025; ... 5.90846112458998; 6.93808332486038; 3.44469932246968; 4.65954705986638; ... 7.00708466319882; 3.97022469477047; 4.66949449276983; 7.15297545753449; ... 3.79547107710474; 4.35907258855759; 6.85754858526846; 3.96760657205439; ... 5.50019159441948; 6.59933535084439; 4.04590000762589; 5.13690239596885; ... 5.93326622029102; 4.20198864027471]; grp = categorical (repmat ({'A';'B';'C'}, 10, 1)); tbl4 = table (yv, grp, 'VariableNames', {'Response','Group'}); mdl4 = fitlm (tbl4, 'Response ~ Group'); fig = figure ('visible', 'off'); ax = axes (fig); h = plot (ax, mdl4); assert_equal (numel (h), 3); assert_equal (get (h(1), 'XData'), repmat ([1 2 3], 1, 10)); assert_equal (get (h(1), 'YData'), yv', 1e-14); assert_equal (get (h(2), 'XData'), [1 2 3]); assert_equal (get (h(2), 'YData'), [4.98621086647521, 6.85868069471919, 4.0662772163002], 1e-10); assert_equal (get (h(3), 'XData'), [1 2 3 NaN 1 2 3]); assert_equal (get (h(3), 'YData'), ... [4.68577486025387, 6.55824468849784, 3.76584121007885, NaN, ... 5.28664687269656, 7.15911670094053, 4.36671322252154], 1e-10); assert_equal (get (ax, 'XTick'), [1 2 3]); assert_equal (get (ax, 'XTickLabel'), {'A'; 'B'; 'C'}); assert_equal (get (get (ax, 'Title'), 'String'), 'Response vs. Group'); assert_equal (get (get (ax, 'XLabel'), 'String'), 'Group'); assert_equal (get (get (ax, 'YLabel'), 'String'), 'Response'); close (fig); ***** test ## continuous by continuous, effects mode mi = fitlm (X, y, 'y ~ x1*x2'); fig = figure ('visible', 'off'); h = plotInteraction (mi, 'x1', 'x2'); assert_equal (numel (h), 11); assert_equal (get (h(1), 'XData'), [1.76843380852813, -18.8740348676059], 1e-9); assert_equal (get (h(1), 'YData'), [1, 7]); assert_equal (get (h(2), 'XData'), [-2.25617028020123, 5.79303789725749], 1e-9); assert_equal (get (h(3), 'XData'), [-23.1321080641968, -14.615961671015], 1e-9); assert_equal (get (h(4), 'XData'), ... [1.97967308209488, 1.68393809910143, 1.38820311610799], 1e-9); assert_equal (get (h(4), 'YData'), [2, 3, 4]); assert_equal (get (h(5), 'XData'), [-0.771057026434185, 4.73040319062394], 1e-9); assert_equal (get (h(6), 'XData'), [-2.86059582662229, 6.22847202482516], 1e-9); assert_equal (get (h(7), 'XData'), [-4.99614754441031, 7.77255377662629], 1e-9); assert_equal (get (h(8), 'XData'), ... [-18.5782998846125, -18.8740348676059, -19.1697698505994], 1e-9); assert_equal (get (h(8), 'YData'), [8, 9, 10]); assert_equal (get (h(9), 'XData'), [-24.674318784563, -12.4822809846619], 1e-9); assert_equal (get (h(10), 'XData'), [-23.1321080641968, -14.615961671015], 1e-9); assert_equal (get (h(11), 'XData'), [-21.6439971135684, -16.6955425876303], 1e-9); assert_equal (get (h(1), 'Tag'), 'main'); assert_equal (get (h(4), 'Tag'), 'conditional1'); assert_equal (get (h(8), 'Tag'), 'conditional2'); ax = gca (); assert_equal (get (get (ax, 'Title'), 'String'), 'Interaction of x1 and x2'); assert_equal (get (get (ax, 'XLabel'), 'String'), 'Effect'); assert_equal (get (ax, 'YTick'), [1, 2, 3, 4, 7, 8, 9, 10]); assert_equal (get (ax, 'YTickLabel'), ... {'x1: 0.05 to 1'; 'x2=0.05'; 'x2=10.025'; 'x2=20'; ... 'x2: 0.05 to 20'; 'x1=0.05'; 'x1=0.525'; 'x1=1'}); assert_equal (get (ax, 'YLim'), [0.5, 10.5]); close (fig); ***** test ## continuous by continuous, predictions mode mi = fitlm (X, y, 'y ~ x1*x2'); fig = figure ('visible', 'off'); h = plotInteraction (mi, 'x1', 'x2', 'predictions'); assert_equal (numel (h), 3); xd = get (h(1), 'XData'); assert_equal (numel (xd), 101); assert_equal (xd(1:3), [0.05, 0.2495, 0.449], 1e-9); assert_equal (xd(end-2:end), [19.601, 19.8005, 20], 1e-9); yd1 = get (h(1), 'YData'); assert_equal (yd1(1:3), ... [0.215349913094656, 0.0295669142485309, -0.156216084597594], 1e-9); assert_equal (yd1(end-2:end), ... [-17.9913839738256, -18.1771669726717, -18.3629499715178], 1e-9); yd2 = get (h(2), 'YData'); assert_equal (yd2(1:3), [1.20518645414209, 1.01644610546604, 0.827705756789976], 1e-9); assert_equal (yd2(end-2:end), ... [-17.2913677161117, -17.4801080647878, -17.6688484134638], 1e-9); yd3 = get (h(3), 'YData'); assert_equal (yd3(1:3), [2.19502299518953, 2.00332529668354, 1.81162759817755], 1e-9); assert_equal (yd3(end-2:end), ... [-16.5913514583978, -16.7830491569038, -16.9747468554098], 1e-9); assert_equal (get (h(1), 'DisplayName'), '0.05'); assert_equal (get (h(2), 'DisplayName'), '0.525'); assert_equal (get (h(3), 'DisplayName'), '1'); ax = gca (); assert_equal (get (get (ax, 'Title'), 'String'), 'Interaction of x1 and x2'); assert_equal (get (get (ax, 'XLabel'), 'String'), 'x2'); assert_equal (get (get (ax, 'YLabel'), 'String'), 'Adjusted y'); close (fig); ***** test ## swapping var1/var2 order swaps roles and title mi = fitlm (X, y, 'y ~ x1*x2'); fig = figure ('visible', 'off'); h = plotInteraction (mi, 'x2', 'x1'); assert_equal (numel (h), 11); assert_equal (get (h(1), 'XData'), [-18.8740348676059, 1.76843380852813], 1e-9); assert_equal (get (h(4), 'XData'), ... [-18.5782998846125, -18.8740348676059, -19.1697698505994], 1e-9); assert_equal (get (h(8), 'XData'), ... [1.97967308209488, 1.68393809910143, 1.38820311610799], 1e-9); ax = gca (); assert_equal (get (get (ax, 'Title'), 'String'), 'Interaction of x2 and x1'); assert_equal (get (ax, 'YTickLabel'), ... {'x2: 0.05 to 20'; 'x1=0.05'; 'x1=0.525'; 'x1=1'; ... 'x1: 0.05 to 1'; 'x2=0.05'; 'x2=10.025'; 'x2=20'}); close (fig); ***** test ## interaction effects: variables given as indices into VariableNames mi = fitlm (X, y, 'y ~ x1*x2'); fig = figure ('visible', 'off'); h = plotInteraction (mi, 1, 2); assert_equal (numel (h), 11); assert_equal (get (h(1), 'XData'), [1.76843380852813, -18.8740348676059], 1e-9); assert_equal (get (h(1), 'YData'), [1, 7]); ax = gca (); assert_equal (get (get (ax, 'Title'), 'String'), 'Interaction of x1 and x2'); close (fig); ***** test ## interaction effects: explicit axes argument is honored mi = fitlm (X, y, 'y ~ x1*x2'); fig = figure ('visible', 'off'); axtarget = axes (fig); h = plotInteraction (axtarget, mi, 'x1', 'x2'); assert_equal (numel (h), 11); assert_equal (isequal (get (h(1), 'Parent'), axtarget), true); assert_equal (isequal (gca (), axtarget), true); close (fig); ***** test ## no interaction term: conditional effects collapse to the main effect mn = fitlm (X, y, 'y ~ x1 + x2'); fig = figure ('visible', 'off'); h = plotInteraction (mn, 'x1', 'x2'); xd1 = get (h(1), 'XData'); eff1 = xd1(1); eff2 = xd1(2); assert_equal (eff1, 2.38302891604232, 1e-9); assert_equal (eff2, -19.5277648300125, 1e-9); assert_equal (get (h(4), 'XData'), [eff1, eff1, eff1], 1e-9); assert_equal (get (h(8), 'XData'), [eff2, eff2, eff2], 1e-9); close (fig); ***** test ## categorical by continuous, effects mode xc = (1:30)' / 30; grp = categorical (repmat ({'A';'B';'C'}, 10, 1)); yv = 2*xc + 3*double (grp == 'B') - 1*double (grp == 'C') + ... 1.5*xc.*double (grp == 'B') + 0.3*sin ((1:30)'); tblc = table (yv, xc, grp, 'VariableNames', {'Response','Xc','Group'}); mdlc = fitlm (tblc, 'Response ~ Xc*Group'); fig = figure ('visible', 'off'); h = plotInteraction (mdlc, 'Group', 'Xc'); assert_equal (numel (h), 11); assert_equal (get (h(1), 'XData'), [4.7896970899464, 2.32528157787528], 1e-9); assert_equal (get (h(2), 'XData'), [4.56862113373247, 5.01077304616034], 1e-9); assert_equal (get (h(3), 'XData'), [2.02254960835685, 2.62801354739371], 1e-9); assert_equal (get (h(4), 'XData'), ... [4.08328517685389, 4.7896970899464, 5.49610900303892], 1e-9); assert_equal (get (h(5), 'XData'), [3.64076372661607, 4.52580662709171], 1e-9); assert_equal (get (h(6), 'XData'), [4.56862113373247, 5.01077304616034], 1e-9); assert_equal (get (h(7), 'XData'), [5.07555715247022, 5.91666085360761], 1e-9); assert_equal (get (h(8), 'XData'), ... [1.88553612240401, 3.25156621870343, 1.8387423925184], 1e-9); assert_equal (get (h(9), 'XData'), [1.36118897012269, 2.40988327468532], 1e-9); assert_equal (get (h(10), 'XData'), [2.72721906642211, 3.77591337098474], 1e-9); assert_equal (get (h(11), 'XData'), [1.31439524023708, 2.36308954479972], 1e-9); ax = gca (); assert_equal (get (get (ax, 'Title'), 'String'), 'Interaction of Group and Xc'); assert_equal (get (ax, 'YTick'), [1, 2, 3, 4, 7, 8, 9, 10]); assert_equal (get (ax, 'YTickLabel'), ... {'Group: C to B'; 'Xc=0.0333333'; 'Xc=0.516667'; 'Xc=1'; ... 'Xc: 0.033333 to 1'; 'Group=A'; 'Group=B'; 'Group=C'}); close (fig); ***** test ## categorical by continuous, predictions mode xc = (1:30)' / 30; grp = categorical (repmat ({'A';'B';'C'}, 10, 1)); yv = 2*xc + 3*double (grp == 'B') - 1*double (grp == 'C') + ... 1.5*xc.*double (grp == 'B') + 0.3*sin ((1:30)'); tblc = table (yv, xc, grp, 'VariableNames', {'Response','Xc','Group'}); mdlc = fitlm (tblc, 'Response ~ Xc*Group'); fig = figure ('visible', 'off'); h = plotInteraction (mdlc, 'Group', 'Xc', 'predictions'); assert_equal (numel (h), 3); xd = get (h(1), 'XData'); assert_equal (numel (xd), 101); assert_equal (xd(1:3), [0.0333333333333333, 0.043, 0.0526666666666667], 1e-9); assert_equal (xd(end-2:end), [0.980666666666667, 0.990333333333333, 1], 1e-9); yd1 = get (h(1), 'YData'); assert_equal (yd1(1:3), [0.107201421526318, 0.126056782750359, 0.144912143974399], 1e-9); assert_equal (yd1(end-2:end), [1.95502682148225, 1.97388218270629, 1.99273754393033], 1e-9); yd2 = get (h(2), 'YData'); assert_equal (yd2(1:3), [3.18658823804771, 3.21910390023474, 3.25161956242178], 1e-9); assert_equal (yd2(end-2:end), [6.37312313237707, 6.4056387945641, 6.43815445675114], 1e-9); yd3 = get (h(3), 'YData'); assert_equal (yd3(1:3), [-0.896696938806178, -0.878309514880994, -0.85992209095581], 1e-9); assert_equal (yd3(end-2:end), [0.905270605861853, 0.923658029787037, 0.942045453712221], 1e-9); assert_equal (get (h(1), 'DisplayName'), 'A'); assert_equal (get (h(2), 'DisplayName'), 'B'); assert_equal (get (h(3), 'DisplayName'), 'C'); ax = gca (); assert_equal (get (get (ax, 'Title'), 'String'), 'Interaction of Group and Xc'); assert_equal (get (get (ax, 'XLabel'), 'String'), 'Xc'); assert_equal (get (get (ax, 'YLabel'), 'String'), 'Adjusted Response'); close (fig); ***** test ## default h on shared fixture, no polynomial hierarchy present t = anova (mdl); assert_equal (t.Properties.RowNames, {'x1'; 'x2'; 'Error'}); assert_equal (t.SumSq(1), 0.590865029026992, -1e-9); assert_equal (t.DF(1), 1); assert_equal (t.MeanSq(1), 0.590865029026992, -1e-9); assert_equal (t.F(1), 25.9858409295, -1e-8); assert_equal (t.pValue(1), 8.93779416897245e-05, -1e-8); assert_equal (t.SumSq(2), 42.0518254818947, -1e-9); assert_equal (t.DF(2), 1); assert_equal (t.MeanSq(2), 42.0518254818947, -1e-9); assert_equal (t.F(2), 1849.41059985747, -1e-7); assert_equal (t.pValue(2), 8.65693830575066e-19, -1e-8); assert_equal (t.SumSq(3), 0.386545331386823, -1e-9); assert_equal (t.DF(3), 17); assert_equal (t.MeanSq(3), 0.0227379606698131, -1e-9); assert_equal (isnan (t.F(3)), true); assert_equal (isnan (t.pValue(3)), true); ***** test ## explicit Type 2 on shared fixture reaches the identical result as h t = anova (mdl, 'components', 2); assert_equal (t.SumSq(1), 0.590865029026992, -1e-9); assert_equal (t.MeanSq(1), 0.590865029026992, -1e-9); assert_equal (t.F(1), 25.9858409295, -1e-8); assert_equal (t.pValue(1), 8.93779416897245e-05, -1e-8); assert_equal (t.SumSq(2), 42.0518254818947, -1e-9); assert_equal (t.MeanSq(2), 42.0518254818947, -1e-9); assert_equal (t.F(2), 1849.41059985747, -1e-7); assert_equal (t.pValue(2), 8.65693830575066e-19, -1e-8); assert_equal (t.SumSq(3), 0.386545331386823, -1e-9); assert_equal (t.MeanSq(3), 0.0227379606698131, -1e-9); ***** test ## explicit Type 1 on shared fixture, order-dependent x1 row differs from h t = anova (mdl, 'components', 1); assert_equal (t.SumSq(1), 541.472049189064, -1e-9); assert_equal (t.MeanSq(1), 541.472049189064, -1e-9); assert_equal (t.F(1), 23813.5713686901, -1e-7); assert_equal (t.pValue(1), 3.41699381539186e-28, -1e-8); assert_equal (t.SumSq(2), 42.0518254818947, -1e-9); assert_equal (t.F(2), 1849.41059985747, -1e-7); assert_equal (t.SumSq(3), 0.386545331386823, -1e-9); assert_equal (t.DF(3), 17); ***** test ## summary table on shared fixture, no Linear/Nonlinear split t = anova (mdl, 'summary'); assert_equal (t.Properties.RowNames, {'Total'; 'Model'; 'Residual'}); assert_equal (t.SumSq(1), 583.910420002346, -1e-9); assert_equal (t.DF(1), 19); assert_equal (t.MeanSq(1), 30.7321273685445, -1e-9); assert_equal (isnan (t.F(1)), true); assert_equal (t.SumSq(2), 583.523874670959, -1e-9); assert_equal (t.DF(2), 2); assert_equal (t.MeanSq(2), 291.761937335479, -1e-9); assert_equal (t.F(2), 12831.4909842738, -1e-7); assert_equal (t.pValue(2), 9.48988083209278e-28, -1e-8); assert_equal (t.SumSq(3), 0.386545331386823, -1e-9); assert_equal (t.DF(3), 17); assert_equal (t.MeanSq(3), 0.0227379606698131, -1e-9); ***** test ## polynomial hierarchy, h and Type 2 diverge only on the Age row Age = [25;31;42;29;55;38;46;33;27;50;41;36;48;30;44]; Sex = categorical ({'M';'F';'F';'M';'M';'F';'M';'F';'F';'M';'F';'M';'F';'M';'F'}); BP = [118;122;135;120;150;128;140;124;119;145;130;126;138;121;136]; T = table (Age, Sex, BP); m = fitlm (T, 'BP ~ Sex + Age^2'); t = anova (m); t2 = anova (m, 'components', 2); assert_equal (t.Properties.RowNames, {'Age'; 'Sex'; 'Age^2'; 'Error'}); assert_equal (t.SumSq(1), 1363.92365918468, -1e-9); assert_equal (t.DF(1), 1); assert_equal (t.MeanSq(1), 1363.92365918468, -1e-9); assert_equal (t.F(1), 707.420098987802, -1e-7); assert_equal (t.pValue(1), 2.46488912775244e-11, -1e-8); assert_equal (t.SumSq(2), 1.90509548061236, -1e-9); assert_equal (t.F(2), 0.988107233422164, -1e-9); assert_equal (t.pValue(2), 0.341568882808456, -1e-9); assert_equal (t.SumSq(3), 8.58235117456131, -1e-9); assert_equal (t.F(3), 4.45136916320193, -1e-8); assert_equal (t.pValue(3), 0.0585944334523874, -1e-9); assert_equal (t.SumSq(4), 21.2082753550521, -1e-9); assert_equal (t.DF(4), 11); assert_equal (t.MeanSq(4), 1.92802503227746, -1e-9); assert_equal (t2.SumSq(1), 0.209727728295816, -1e-8); assert_equal (t2.F(1), 0.108778529731057, -1e-9); assert_equal (t2.pValue(1), 0.747734511582268, -1e-9); assert_equal (t2.SumSq(2), 1.90509548061236, -1e-9); assert_equal (t2.SumSq(3), 8.58235117456131, -1e-9); assert_equal (t2.SumSq(4), 21.2082753550521, -1e-9); ***** test ## summary table with Linear/Nonlinear split, same polynomial model Age = [25;31;42;29;55;38;46;33;27;50;41;36;48;30;44]; Sex = categorical ({'M';'F';'F';'M';'M';'F';'M';'F';'F';'M';'F';'M';'F';'M';'F'}); BP = [118;122;135;120;150;128;140;124;119;145;130;126;138;121;136]; T = table (Age, Sex, BP); m = fitlm (T, 'BP ~ Sex + Age^2'); t = anova (m, 'summary'); assert_equal (t.Properties.RowNames, ... {'Total'; 'Model'; '. Linear'; '. Nonlinear'; 'Residual'}); assert_equal (t.SumSq(1), 1415.73333333333, -1e-9); assert_equal (t.DF(1), 14); assert_equal (t.MeanSq(1), 101.12380952381, -1e-9); assert_equal (t.SumSq(2), 1394.52505797828, -1e-9); assert_equal (t.DF(2), 3); assert_equal (t.F(2), 241.097329241452, -1e-7); assert_equal (t.pValue(2), 2.58928117898032e-10, -1e-8); assert_equal (t.SumSq(3), 1385.94270680372, -1e-9); assert_equal (t.DF(3), 2); assert_equal (t.F(3), 359.420309280577, -1e-7); assert_equal (t.pValue(3), 9.54785035758658e-11, -1e-8); assert_equal (t.SumSq(4), 8.58235117456131, -1e-9); assert_equal (t.DF(4), 1); assert_equal (t.F(4), 4.45136916320193, -1e-8); assert_equal (t.pValue(4), 0.0585944334523874, -1e-9); assert_equal (t.SumSq(5), 21.2082753550521, -1e-9); assert_equal (t.DF(5), 11); assert_equal (t.MeanSq(5), 1.92802503227746, -1e-9); ***** test ## unbalanced categorical interaction, hierarchical model, default h grpA = categorical ([1;1;2;1;2;1;1;2;1;1;2;1;2;2;1;1;2;1;1;2]); grpB = categorical ([1;2;1;1;2;2;1;1;2;1;1;2;2;1;2;1;1;2;2;1]); xv = (1:20)' / 10; yv = 2*(grpA=='2') + 1.5*(grpB=='2') + 0.7*xv + ... 0.9*(grpA=='2').*(grpB=='2') + ... [0.1;-0.2;0.05;0.15;-0.1;0.2;-0.05;0.1;0.0;-0.15; ... 0.1;0.05;-0.2;0.15;0.0;-0.1;0.05;0.2;-0.05;0.1]; T = table (grpA, grpB, xv, yv); m = fitlm (T, 'yv ~ grpA*grpB'); t = anova (m); t2 = anova (m, 'components', 1); assert_equal (t.Properties.RowNames, {'grpA'; 'grpB'; 'grpA:grpB'; 'Error'}); assert_equal (t.SumSq(1), 26.0224323327616, -1e-9); assert_equal (t.F(1), 138.504723473419, -1e-8); assert_equal (t.pValue(1), 2.72592668860896e-09, -1e-8); assert_equal (t.SumSq(2), 15.2365308176101, -1e-9); assert_equal (t.F(2), 81.0966269640544, -1e-8); assert_equal (t.pValue(2), 1.15578182042777e-07, -1e-8); assert_equal (t.SumSq(3), 0.0142868014375564, -1e-8); assert_equal (t.F(3), 0.0760416803903897, -1e-8); assert_equal (t.pValue(3), 0.786264832724038, -1e-9); assert_equal (t.SumSq(4), 3.00609904761905, -1e-9); assert_equal (t.DF(4), 16); assert_equal (t.MeanSq(4), 0.18788119047619, -1e-9); assert_equal (t2.SumSq(1), 16.3540833333333, -1e-9); assert_equal (t2.F(1), 87.0448142886652, -1e-8); assert_equal (t2.pValue(1), 7.14746180184104e-08, -1e-8); assert_equal (t2.SumSq(2), 15.2365308176101, -1e-9); assert_equal (t2.SumSq(3), 0.0142868014375564, -1e-8); ***** test ## non-hierarchical model, missing grpB main effect, h still succeeds grpA = categorical ([1;1;2;1;2;1;1;2;1;1;2;1;2;2;1;1;2;1;1;2]); grpB = categorical ([1;2;1;1;2;2;1;1;2;1;1;2;2;1;2;1;1;2;2;1]); xv = (1:20)' / 10; yv = 2*(grpA=='2') + 1.5*(grpB=='2') + 0.7*xv + ... 0.9*(grpA=='2').*(grpB=='2') + ... [0.1;-0.2;0.05;0.15;-0.1;0.2;-0.05;0.1;0.0;-0.15; ... 0.1;0.05;-0.2;0.15;0.0;-0.1;0.05;0.2;-0.05;0.1]; T = table (grpA, grpB, xv, yv); m = fitlm (T, 'yv ~ grpA + grpA:grpB'); t = anova (m); assert_equal (t.Properties.RowNames, {'grpA'; 'grpA:grpB'; 'Error'}); assert_equal (t.SumSq(1), 16.3540833333333, -1e-9); assert_equal (t.F(1), 22.0110535802411, -1e-8); assert_equal (t.pValue(1), 0.000209917579961884, -1e-8); assert_equal (t.SumSq(2), 5.62601666666667, -1e-9); assert_equal (t.F(2), 7.57208776360619, -1e-8); assert_equal (t.pValue(2), 0.0136181560209473, -1e-9); assert_equal (t.SumSq(3), 12.6309, -1e-9); assert_equal (t.DF(3), 17); assert_equal (t.MeanSq(3), 0.742994117647059, -1e-9); ***** test ## no-intercept model grpA = categorical ([1;1;2;1;2;1;1;2;1;1;2;1;2;2;1;1;2;1;1;2]); grpB = categorical ([1;2;1;1;2;2;1;1;2;1;1;2;2;1;2;1;1;2;2;1]); xv = (1:20)' / 10; yv = 2*(grpA=='2') + 1.5*(grpB=='2') + 0.7*xv + ... 0.9*(grpA=='2').*(grpB=='2') + ... [0.1;-0.2;0.05;0.15;-0.1;0.2;-0.05;0.1;0.0;-0.15; ... 0.1;0.05;-0.2;0.15;0.0;-0.1;0.05;0.2;-0.05;0.1]; T = table (grpA, grpB, xv, yv); m = fitlm (T, 'yv ~ grpA + grpB - 1'); t = anova (m); assert_equal (t.SumSq(1), 63.3745141509434, -1e-8); assert_equal (t.F(1), 178.349190204051, -1e-7); assert_equal (t.pValue(1), 3.91187977275845e-12, -1e-8); assert_equal (t.SumSq(2), 15.2365308176101, -1e-8); assert_equal (t.F(2), 85.7575941763448, -1e-7); assert_equal (t.pValue(2), 4.71596005128041e-08, -1e-8); assert_equal (t.SumSq(3), 3.02038584905660, -1e-8); assert_equal (t.DF(3), 17); assert_equal (t.MeanSq(3), 0.177669755826859, -1e-9); ***** test ## weighted fit grpA = categorical ([1;1;2;1;2;1;1;2;1;1;2;1;2;2;1;1;2;1;1;2]); grpB = categorical ([1;2;1;1;2;2;1;1;2;1;1;2;2;1;2;1;1;2;2;1]); xv = (1:20)' / 10; yv = 2*(grpA=='2') + 1.5*(grpB=='2') + 0.7*xv + ... 0.9*(grpA=='2').*(grpB=='2') + ... [0.1;-0.2;0.05;0.15;-0.1;0.2;-0.05;0.1;0.0;-0.15; ... 0.1;0.05;-0.2;0.15;0.0;-0.1;0.05;0.2;-0.05;0.1]; T = table (grpA, grpB, xv, yv); w = [1.2;0.8;1.5;1.0;0.9;1.1;1.3;0.7;1.0;1.4; ... 0.8;1.2;1.0;1.1;0.9;1.3;0.7;1.5;1.0;1.2]; m = fitlm (T, 'yv ~ grpA + grpB', 'Weights', w); t = anova (m); assert_equal (t.SumSq(1), 26.6364861423312, -1e-9); assert_equal (t.F(1), 134.770391630163, -1e-8); assert_equal (t.pValue(1), 1.66729622333192e-09, -1e-8); assert_equal (t.SumSq(2), 17.4880599694593, -1e-9); assert_equal (t.F(2), 88.4828681359069, -1e-8); assert_equal (t.pValue(2), 3.76674631526712e-08, -1e-8); assert_equal (t.SumSq(3), 3.35993877395756, -1e-9); assert_equal (t.DF(3), 17); assert_equal (t.MeanSq(3), 0.197643457291621, -1e-9); ***** test grp3 = categorical ([1;1;1;1;1;2;2;2;2;2;2;2;2;2;3;3;3;3;3;3]); yy = [2.1;1.9;2.3;2.0;1.8;4.1;4.3;3.9;4.0;4.2; ... 4.4;3.8;4.1;4.0;6.1;5.9;6.3;6.0;5.8;6.2]; T = table (grp3, yy); m = fitlm (T, 'yy ~ grp3'); t = anova (m); assert_equal (t.Properties.RowNames, {'grp3'; 'Error'}); assert_equal (t.DF(1), 2); assert_equal (t.SumSq(1), 44.3761111111111, -1e-9); assert_equal (t.MeanSq(1), 22.1880555555556, -1e-9); assert_equal (t.F(1), 616.446794988197, -1e-7); assert_equal (t.pValue(1), 1.36582477075565e-16, -1e-8); assert_equal (t.SumSq(2), 0.611888888888889, -1e-9); assert_equal (t.DF(2), 17); assert_equal (t.MeanSq(2), 0.0359934640522876, -1e-9); ***** test ## type 3 gives different numbers than type 2 here G3 = categorical ([1;1;1;1;2;2;2;3;3;3;3;1;2;3]); G2 = categorical ([1;1;2;2;1;2;2;1;1;2;2;2;1;1]); y1 = [10;12;15;14;9;11;13;16;18;20;22;17;10;19]; T1 = table (G3, G2, y1); mdl1 = fitlm (T1, 'y1 ~ G3*G2'); t1 = anova (mdl1, 'components', 3); assert_equal (t1.Properties.RowNames, {'G3'; 'G2'; 'G3:G2'; 'Error'}); assert_equal (t1.SumSq(1), 176.678431372549, -1e-9); assert_equal (t1.F(1), 44.6345510835913, -1e-8); assert_equal (t1.pValue(1), 4.57572925304662e-05, -1e-8); assert_equal (t1.SumSq(2), 38.7604166666666, -1e-9); assert_equal (t1.F(2), 19.5842105263158, -1e-8); assert_equal (t1.pValue(2), 0.00221050293676794, -1e-9); assert_equal (t1.SumSq(3), 1.85490196078431, -1e-9); assert_equal (t1.SumSq(4), 15.8333333333333, -1e-9); assert_equal (t1.DF(4), 8); assert_equal (t1.MeanSq(4), 1.97916666666667, -1e-9); ***** test ## no intercept; every level is coded, so the error row equals mdl.SSE G = categorical ([1;1;1;2;2;2;3;3;3;3]); y1 = [10;12;11;20;22;19;15;17;16;14]; T = table (G, y1); mdl1 = fitlm (T, 'y1 ~ G - 1'); t = anova (mdl1, 'components', 3); assert_equal (mdl1.SSE, 11.6666666666667, -1e-9); assert_equal (t.SumSq(1), 2564.33333333333, -1e-8); assert_equal (t.DF(1), 3); assert_equal (t.F(1), 512.866666666667, -1e-7); assert_equal (t.pValue(1), 1.45297790506045e-08, -1e-8); assert_equal (t.SumSq(2), 11.6666666666667, -1e-9); assert_equal (t.DF(2), 7); assert_equal (t.MeanSq(2), 1.66666666666667, -1e-9); ***** test y0 = [3; 4; 5; 4; 6; 5; 7; 6]; x0 = (1:8)'; t = anova (fitlm (table (x0, y0), 'y0 ~ 1'), 'summary'); assert_equal (t.DF(2), 0); assert_equal (isnan (t.F(2)), true); assert_equal (isnan (t.pValue(2)), true); ***** test # and the components table answers for it too y0 = [3; 4; 5; 4; 6; 5; 7; 6]; x0 = (1:8)'; t = anova (fitlm (table (x0, y0), 'y0 ~ 1'), 'components', 3); assert_equal (t.Properties.RowNames, {'Error'}); assert_equal (isnan (t.pValue(1)), true); ***** test G1 = categorical ([1;1;1;2;2;2;3;3;3;3]); G2 = G1; y1 = [10; 12; 11; 22; 24; 21; 15; 17; 16; 14]; t = anova (fitlm (table (G1, G2, y1), 'y1 ~ G1 + G2'), 'components', 3); assert_equal (t.SumSq(1), 0); assert_equal (t.DF(1), 0); assert_equal (isnan (t.MeanSq(1)), true); assert_equal (isnan (t.F(1)), true); assert_equal (isnan (t.pValue(1)), true); ***** test ## duplicate group column, so type 3 should show zero DF G1 = categorical ([1;1;1;2;2;2;3;3;3;3]); G2 = G1; y1 = [10;12;11;20;22;19;15;17;16;14]; T = table (G1, G2, y1); mdl1 = fitlm (T, 'y1 ~ G1 + G2'); t = anova (mdl1, 'components', 3); assert_equal (t.Properties.RowNames, {'G1'; 'G2'; 'Error'}); assert_equal (t.SumSq(1), 0, -1e-9); assert_equal (t.DF(1), 0); assert_equal (isnan (t.F(1)), true); assert_equal (isnan (t.pValue(1)), true); assert_equal (t.SumSq(2), 0, -1e-9); assert_equal (t.DF(2), 0); assert_equal (t.SumSq(3), 11.6666666666667, -1e-9); assert_equal (t.DF(3), 7); assert_equal (t.MeanSq(3), 1.66666666666667, -1e-9); ***** test ## just an intercept, so only the error row shows up y1 = [5.1;4.9;5.2;4.8;5.1;4.9;5.2;4.8;5.1;4.9]; T = table (y1); mdl1 = fitlm (T, 'y1 ~ 1'); t = anova (mdl1, 'components', 3); assert_equal (t.Properties.RowNames, {'Error'}); assert_equal (t.SumSq(1), 0.22, -1e-9); assert_equal (t.DF(1), 9); assert_equal (t.MeanSq(1), 0.0244444444444444, -1e-9); ***** test ## type 3 with a robust fit G = categorical ([1;1;1;1;2;2;2;2;3;3;3;3]); x = (1:12)' / 2; y1 = 5 + 2*(G=='2') + 4*(G=='3') + 0.3*x; y1(10) = y1(10) + 20; T = table (G, x, y1); mdl1 = fitlm (T, 'y1 ~ G + x', 'RobustOpts', 'on'); t = anova (mdl1, 'components', 3); assert_equal (t.SumSq(1), 3.35664335664336, -1e-8); assert_equal (t.F(1), 0.0801017164653529, -1e-8); assert_equal (t.pValue(1), 0.923753304031669, -1e-9); assert_equal (t.SumSq(2), 0.337499999999999, -1e-8); assert_equal (t.F(2), 0.0161079545454545, -1e-8); assert_equal (t.pValue(2), 0.902138027698746, -1e-9); assert_equal (t.SumSq(3), 167.619047619048, -1e-7); assert_equal (t.DF(3), 8); assert_equal (t.MeanSq(3), 20.9523809523809, -1e-8); ***** test ## repeated x values, so lack of fit rows should show up x = [1;1;1;2;3;3;4;5;5;5;6;7]; y1 = [10.1;9.9;10.3;12.0;15.2;14.8;17.5;20.1;19.9;20.3;22.0;25.5]; mdl1 = fitlm (x, y1); t = anova (mdl1, 'summary'); assert_equal (t.Properties.RowNames, ... {'Total'; 'Model'; 'Residual'; '. Lack of fit'; '. Pure error'}); assert_equal (t.SumSq(3), 1.03026642984015, -1e-9); assert_equal (t.DF(3), 10); assert_equal (t.SumSq(4), 0.790266429840146, -1e-9); assert_equal (t.DF(4), 5); assert_equal (t.F(4), 3.2927767910006, -1e-9); assert_equal (t.pValue(4), 0.108434644423991, -1e-9); assert_equal (t.SumSq(5), 0.24, -1e-9); assert_equal (t.DF(5), 5); assert_equal (t.MeanSq(5), 0.0480000000000001, -1e-9); ***** test ## same as above but weighted x = repmat ((1:4)', 6, 1); G = categorical (repmat ([1;1;2;2], 6, 1)); y1 = 3 + 0.7*x + 2*(G=='2') + ... [0.1;-0.1;0.2;-0.2;0.15;-0.15;0.1;-0.1;-0.05;0.05;0.2;-0.2; ... 0.1;-0.1;-0.15;0.15;0.2;-0.2;0.05;-0.05;-0.1;0.1;0.15;-0.15]; w = 1 + mod ((0:23)', 3); T = table (x, G, y1); mdl1 = fitlm (T, 'y1 ~ x + G', 'Weights', w); t = anova (mdl1, 'summary'); assert_equal (t.Properties.RowNames, ... {'Total'; 'Model'; 'Residual'; '. Lack of fit'; '. Pure error'}); assert_equal (t.SumSq(3), 0.626927083333335, -1e-9); assert_equal (t.DF(3), 21); assert_equal (t.SumSq(4), 0.00880208333333332, -1e-9); assert_equal (t.DF(4), 1); assert_equal (t.F(4), 0.284799460734748, -1e-9); assert_equal (t.pValue(4), 0.599454252702211, -1e-9); assert_equal (t.SumSq(5), 0.618125000000001, -1e-9); assert_equal (t.DF(5), 20); assert_equal (t.MeanSq(5), 0.0309062500000001, -1e-9); ***** test w = (1:n)'; mdl0 = fitlm (X, y, 'Weights', w); m = step (mdl0, 'Upper', 'quadratic', 'Verbose', 0); assert_equal (m.NumObservations, 20); assert_equal (m.NumCoefficients, 3); assert_equal (m.DFE, 17); assert_equal (m.SSE, 4.16523310465, 1e-8); assert_equal (m.CoefficientNames, {'(Intercept)','x1','x2'}); assert_equal (m.Coefficients.Estimate, [0.080321; 2.6483; -0.98452], 1e-4); assert_equal (m.Formula.LinearPredictor, '1 + x1 + x2'); ***** test mdl0 = fitlm (X, y, 'Exclude', [3 7 15]); m = step (mdl0, 'Upper', 'quadratic', 'Verbose', 0); assert_equal (m.NumObservations, 17); assert_equal (m.NumCoefficients, 3); assert_equal (m.DFE, 14); assert_equal (m.SSE, 0.340968585251, 1e-8); assert_equal (m.CoefficientNames, {'(Intercept)','x1','x2'}); assert_equal (m.Coefficients.Estimate, [0.13263; 2.3566; -0.97211], 1e-4); assert_equal (m.Formula.LinearPredictor, '1 + x1 + x2'); ***** test ## 'step' continues the history it inherits rather than beginning a new ## one, and reports the model it stepped from as the start. s1 = ((1:48)' - 24.5)/12; s2 = sin ((1:48)'/5); s3 = cos ((1:48)'/7); sy = 4 + 2.5*s1 - 1.1*s2 + 0.6*s1.^2 + 0.2*sin ((1:48)'/3); m1 = stepwiselm ([s1, s2, s3], sy, 'constant', 'Upper', 'linear', ... 'Verbose', 0); m2 = step (m1, 'Upper', 'quadratic', 'NSteps', 1, 'Verbose', 0); assert_equal (size (m1.Steps.History, 1), 4); assert_equal (size (m2.Steps.History, 1), 5); assert_equal (m2.Steps.History.TermName, ... {'1'; 'x1'; 'x2'; 'x3'; 'x1:x3'}); assert_equal (m2.Steps.History.DF, (1:5)'); assert_equal (char (m2.Steps.Start), 'y ~ 1 + x1 + x2 + x3'); ***** test ## Stepping a model that was not fitted stepwise starts the history at ## that model, and leaves the thresholds unreported. s1 = ((1:48)' - 24.5)/12; s2 = sin ((1:48)'/5); s3 = cos ((1:48)'/7); sy = 4 + 2.5*s1 - 1.1*s2 + 0.6*s1.^2 + 0.2*sin ((1:48)'/3); m0 = fitlm ([s1, s2, s3], sy); m1 = step (m0, 'Upper', 'linear', 'NSteps', 1, 'Verbose', 0); assert_equal (isempty (m0.Steps), true); assert_equal (size (m1.Steps.History, 1), 1); assert_equal (m1.Steps.History.TermName{1}, '1 + x1 + x2 + x3'); assert_equal (m1.Steps.History.DF, 4); assert_equal (isempty (m1.Steps.PEnter), true); assert_equal (isempty (m1.Steps.PRemove), true); ***** test ## An unasked-for criterion is inherited from the search being continued, ## and the appended step is scored by it. s1 = ((1:48)' - 24.5)/12; s2 = sin ((1:48)'/5); s3 = cos ((1:48)'/7); sy = 4 + 2.5*s1 - 1.1*s2 + 0.6*s1.^2 + 0.2*sin ((1:48)'/3); m1 = stepwiselm ([s1, s2, s3], sy, 'constant', 'Upper', 'linear', ... 'Criterion', 'bic', 'Verbose', 0); m2 = step (m1, 'Upper', 'quadratic', 'NSteps', 1, 'Verbose', 0); assert_equal (m2.Steps.Criterion, 'bic'); assert_equal (m2.Steps.History.Properties.VariableNames, ... {'Action', 'TermName', 'Terms', 'DF', 'delDF', 'BIC'}); assert_equal (m2.Steps.History.TermName, ... {'1'; 'x1'; 'x2'; 'x3'; 'x1:x3'}); assert_equal (m2.Steps.History.BIC, ... [245.562553617099; 116.628368564602; 109.023785194728; ... -6.28640176660815; -83.7225948440224], 1e-9); ***** test ## Stepping a model that holds a power term is not a 'PredictorVars' ## conflict: the factor 'x1^2' names the variable 'x1'. s1 = ((1:48)' - 24.5)/12; s2 = sin ((1:48)'/5); sy = 4 + 2.5*s1 - 1.1*s2 + 0.6*s1.^2 + 0.2*sin ((1:48)'/3); m1 = stepwiselm ([s1, s2], sy, 'y ~ x1 + x1^2', 'Upper', 'quadratic', ... 'NSteps', 0, 'Verbose', 0); m2 = step (m1, 'Upper', 'quadratic', 'NSteps', 1, 'Verbose', 0); assert_equal (any (strcmp (m2.CoefficientNames, 'x1^2')), true); ***** test ## So is the lower bound, which would otherwise silently widen to the ## constant model and let a protected term be dropped. s1 = ((1:48)' - 24.5)/12; s2 = sin ((1:48)'/5); s3 = cos ((1:48)'/7); sy = 4 + 2.5*s1 - 1.1*s2 + 0.6*s1.^2 + 0.2*sin ((1:48)'/3); m1 = stepwiselm ([s1, s2, s3], sy, 'y ~ x1 + x2', 'Lower', 'y ~ x2', ... 'Upper', 'quadratic', 'NSteps', 1, 'Verbose', 0); m2 = step (m1, 'Upper', 'quadratic', 'NSteps', 1, 'Verbose', 0); assert_equal (char (m1.Steps.Lower), 'y ~ 1 + x2'); assert_equal (char (m2.Steps.Lower), 'y ~ 1 + x2'); assert_equal (m2.Steps.History.TermName, {'1 + x1 + x2'; 'x1^2'; 'x2^2'}); ***** test mdl0 = fitlm (X, y, 'Intercept', false); m = step (mdl0, 'Upper', 'quadratic', 'Verbose', 0); assert_equal (m.NumObservations, 20); assert_equal (m.NumCoefficients, 2); assert_equal (m.DFE, 18); assert_equal (m.SSE, 0.410934843408, 1e-8); assert_equal (m.Formula.HasIntercept, false); assert_equal (m.CoefficientNames, {'x1','x2'}); assert_equal (m.Coefficients.Estimate, [2.9614; -0.99725], 1e-4); assert_equal (m.Formula.LinearPredictor, 'x1 + x2'); ***** test load hald Xh = ingredients; yh = heat; mdlh = fitlm (Xh, yh); assert_equal (mdlh.Coefficients.Estimate, ... [62.405369299918; 1.55110264750845; 0.510167579684912; ... 0.101909403579662; -0.144061029071018], 1e-9); assert_equal (mdlh.Coefficients.SE, ... [70.0709592085362; 0.744769867130993; 0.72378800183518; ... 0.754709045051309; 0.70905206344651], 1e-9); assert_equal (mdlh.Coefficients.tStat, ... [0.890602469336764; 2.0826603169159; 0.704857746178952; ... 0.135031379639465; -0.203174120065001], 1e-8); assert_equal (mdlh.Coefficients.pValue, ... [0.399133563385561; 0.0708216874297252; 0.500901103474289; ... 0.895922690510107; 0.844071473291884], 1e-8); assert_equal (mdlh.CoefficientNames, {'(Intercept)', 'x1', 'x2', 'x3', 'x4'}); assert_equal (mdlh.NumCoefficients, 5); assert_equal (mdlh.NumEstimatedCoefficients, 5); assert_equal (mdlh.DFE, 8); assert_equal (mdlh.SSE, 47.863639350499, 1e-8); assert_equal (mdlh.SSR, 2667.89943757258, 1e-6); assert_equal (mdlh.SST, 2715.76307692308, 1e-6); assert_equal (mdlh.MSE, 5.98295491881254, 1e-9); assert_equal (mdlh.RMSE, 2.44600795559061, 1e-9); assert_equal (mdlh.Rsquared.Ordinary, 0.98237562040768, 1e-9); assert_equal (mdlh.Rsquared.Adjusted, 0.97356343061152, 1e-9); assert_equal (mdlh.LogLikelihood, -26.918344895826, 1e-8); assert_equal (mdlh.ModelCriterion.AIC, 63.8366897916521, 1e-7); assert_equal (mdlh.ModelCriterion.AICc, 72.4081183630806, 1e-7); assert_equal (mdlh.ModelCriterion.BIC, 66.6614365789598, 1e-7); assert_equal (mdlh.ModelCriterion.CAIC, 71.6614365789598, 1e-7); assert_equal (mdlh.Fitted(1:5), ... [78.4952395815018; 72.7887993002909; 105.970937532083; ... 89.3271002550427; 95.649244438227], 1e-8); assert_equal (mdlh.Residuals.Raw(1:5), ... [0.00476041849822195; 1.51120069970906; -1.67093753208295; ... -1.72710025504266; 0.250755561773033], 1e-8); assert_equal (mdlh.Residuals.Pearson(1:5), ... [0.00194619910672879; 0.617823297040002; -0.683128412670876; ... -0.706089385807266; 0.102516249466771], 1e-8); assert_equal (mdlh.Residuals.Studentized(1:5), ... [0.00271470565323249; 0.734526653667679; -1.05809320265782; ... -0.824036396702643; 0.119767490249399], 1e-8); assert_equal (mdlh.Residuals.Standardized(1:5), ... [0.00290214088954622; 0.756624558354514; -1.05027405557414; ... -0.841081414787206; 0.127905848829164], 1e-8); assert_equal (mdlh.Diagnostics.Leverage(1:5), ... [0.550284813713987; 0.333242829857405; 0.576942476415795; ... 0.29523667959374; 0.357601364034465], 1e-8); assert_equal (mdlh.Diagnostics.CooksDistance(1:5), ... [2.06118491039641e-06; 0.0572247602223712; 0.300862709270433; ... 0.0592697490074745; 0.00182140011900327], 1e-8); assert_equal (mdlh.Diagnostics.Dffits(1:5), ... [0.00300294746488125; 0.519283016757055; -1.23563576459509; ... -0.533347058289184; 0.0893585735072963], 1e-7); assert_equal (mdlh.Diagnostics.S2_i(1:5), ... [6.83765556564705; 6.34835899957971; 5.89485540180634; ... 6.23302709557492; 6.82367982420565], 1e-7); assert_equal (mdlh.Diagnostics.CovRatio(1:5), ... [4.33530738335252; 2.01725612858557; 2.19476339013102; ... 1.74129811023362; 3.00406926806094], 1e-6); assert_equal (coefCI (mdlh), ... [-99.178552392689 223.989290992525; -0.166339745871082 3.26854504088797; ... -1.15889054555817 2.179225704928; -1.63845277518465 1.84227158234397; ... -1.77913801945372 1.49101596131168], 1e-7); assert_equal (coefCI (mdlh, 0.1), ... [-67.8949453842232 192.705683984059; 0.166167302672858 2.93603799234403; ... -0.835750978716108 1.85608613808593; -1.30150832005232 1.50532712721164; ... -1.46257740216021 1.17445534401817], 1e-7); [p, F, r] = coefTest (mdlh); assert_equal (p, 4.75618174559791e-07, 1e-12); assert_equal (F, 111.479171821258, 1e-6); assert_equal (r, 4); [dw, pdw] = dwtest (mdlh); assert_equal (dw, 0.842123108585363, 1e-9); assert_equal (pdw, 2.05259693286049, 1e-8); ***** test load hald Xq = ingredients; yq = heat; mdlq = fitlm (Xq, yq, 'purequadratic'); assert_equal (mdlq.Coefficients.Estimate, ... [-210.864812527187; 4.01775196981369; 5.27927179495849; 4.98703005469684; ... 1.18967556414545; -0.00475259718542981; -0.0278555063988026; ... -0.0885225308739459; 0.0125632231921875], 1e-8); assert_equal (mdlq.Coefficients.SE, ... [62.2492955088454; 0.709968572684776; 0.928573133899706; 1.15325562045609; ... 0.559753134550446; 0.0119258668009245; 0.00570193167405062; ... 0.0224063172978396; 0.0040139580330777], 1e-8); assert_equal (mdlq.Coefficients.tStat, ... [-3.38742488253901; 5.6590560827508; 5.68535918413584; 4.3243058748108; ... 2.12535757410437; -0.398511677579811; -4.88527537528597; ... -3.95078449069724; 3.12988404180068], 1e-7); assert_equal (mdlq.Coefficients.pValue, ... [0.0275955163014823; 0.00480588842249351; 0.00472567672152044; ... 0.0124052274432915; 0.100732674864514; 0.710609610173011; ... 0.00812965117162355; 0.0168069450605605; 0.0351891921636521], 1e-7); assert_equal (mdlq.CoefficientNames, ... {'(Intercept)', 'x1', 'x2', 'x3', 'x4', 'x1^2', 'x2^2', 'x3^2', 'x4^2'}); assert_equal (mdlq.NumCoefficients, 9); assert_equal (mdlq.DFE, 4); assert_equal (mdlq.Rsquared.Ordinary, 0.998060528051984, 1e-9); assert_equal (mdlq.Rsquared.Adjusted, 0.994181584155951, 1e-9); assert_equal (mdlq.SSE, 5.26714630515049, 1e-7); assert_equal (mdlq.SSR, 2710.49593061793, 1e-6); assert_equal (mdlq.SST, 2715.76307692308, 1e-6); Xnewq = mean (Xq, 1); [ypredq, yciq] = predict (mdlq, Xnewq); assert_equal (ypredq, 101.90428629036, 1e-7); assert_equal (yciq, [97.996264336243, 105.812308244477], 1e-6); [ypredq2, yciq2] = predict (mdlq, Xnewq, 'Alpha', 0.01); assert_equal (ypredq2, 101.90428629036, 1e-7); assert_equal (yciq2, [95.4237317847484, 108.384840795971], 1e-6); yfeq = feval (mdlq, Xnewq(1), Xnewq(2), Xnewq(3), Xnewq(4)); assert_equal (yfeq, 101.90428629036, 1e-7); ysimq = random (mdlq, Xnewq); assert_equal (isscalar (ysimq), true); assert_equal (isnumeric (ysimq), true); mdlq2 = removeTerms (mdlq, 'x1^2'); assert_equal (mdlq2.Coefficients.Estimate, ... [180.815670525319; 0.228012666917658; -2.0654020024496; -1.90840414992816; ... -0.0108001957000414; 0.0257318558607856; 0.00699693273966028], 1e-8); assert_equal (mdlq2.CoefficientNames, ... {'(Intercept)', 'x2', 'x3', 'x4', 'x2^2', 'x3^2', 'x4^2'}); assert_equal (mdlq2.NumCoefficients, 7); mdlq3 = addTerms (mdlq2, 'x1^2'); assert_equal (mdlq3.Coefficients.Estimate, mdlq.Coefficients.Estimate, 1e-8); assert_equal (mdlq3.CoefficientNames, mdlq.CoefficientNames); assert_equal (mdlq3.SSE, 5.26714630515049, 1e-7); ***** test load hald Xr = ingredients; yr = heat; mdlr = fitlm (Xr, yr, 'RobustOpts', 'bisquare'); assert_equal (mdlr.Coefficients.Estimate, ... [60.0897358816096; 1.57529551556915; 0.532199192097796; ... 0.133455378556458; -0.120521170556001], 1e-8); assert_equal (mdlr.Coefficients.SE, ... [75.8175597390933; 0.805849306629754; 0.783146694256936; ... 0.816603608044244; 0.767202244491812], 1e-8); assert_equal (mdlr.Coefficients.tStat, ... [0.792556976093573; 1.95482642053437; 0.679565138945976; ... 0.163427368238162; -0.157091785668371], 1e-7); assert_equal (mdlr.Coefficients.pValue, ... [0.450897370203866; 0.0863457969332376; 0.515957116726031; ... 0.874235088124976; 0.879064839096153], 1e-7); assert_equal (mdlr.CoefficientNames, {'(Intercept)', 'x1', 'x2', 'x3', 'x4'}); assert_equal (is_function_handle (mdlr.Robust.RobustWgtFun), true); assert_equal (mdlr.Robust.Tune, 4.685, 1e-10); assert_equal (size (mdlr.Robust.Weights), [13, 1]); assert_equal (isnumeric (mdlr.Robust.Weights), true); assert_equal (mdlr.SSE, 56.0362670671825, 1e-6); assert_equal (mdlr.MSE, 7.00453338339782, 1e-8); assert_equal (mdlr.RMSE, 2.64660790133291, 1e-8); assert_equal (mdlr.Rsquared.Ordinary, 0.97929734395902, 1e-9); assert_equal (mdlr.Rsquared.Adjusted, 0.96894601593853, 1e-9); assert_equal (mdlr.DFE, 8); H = [0 1 -1 0 0]; [p1, F1, r1] = coefTest (mdlr, H); assert_equal (p1, 0.00308748318894346, 1e-11); assert_equal (F1, 17.4568343157849, 1e-7); assert_equal (r1, 1); [pd1, dw1] = dwtest (mdlr, 'exact', 'both'); assert_equal (pd1, 0.844119247360191, 1e-9); assert_equal (dw1, 2.05387711905232, 1e-8); [pd2, dw2] = dwtest (mdlr, 'approximate', 'right'); assert_equal (pd2, 0.425180546504485, 1e-9); assert_equal (dw2, 2.05387711905232, 1e-8); Xnewr = mean (Xr, 1); [ypredr, ycir] = predict (mdlr, Xnewr, 'Simultaneous', true); assert_equal (ypredr, 95.4263340097424, 1e-7); assert_equal (ycir, [92.2744598719279, 98.5782081475569], 1e-6); [ypredr2, ycir2] = predict (mdlr, Xnewr, 'Simultaneous', true, 'Alpha', 0.1); assert_equal (ypredr2, 95.4263340097424, 1e-7); assert_equal (ycir2, [92.7161333049321, 98.1365347145527], 1e-6); ***** warning ... m = addTerms (mdl, 'x1'); ***** warning ... m = removeTerms (mdl, 'x1:x2'); ***** error fitlm (X, y, 'NotAKey', 1) ***** error fitlm (X, y, 'VarNames', {'a','b','c','d'}) ***** error fitlm (X, y, [1 2 3 4; 5 6 7 8]) ***** error fitlm (X, y, [1 2 1; 0 1 1]) ***** error fitlm (NaN (5, 2), NaN (5, 1)) ***** error fitlm (NaN (3, 2), [1; 2; 3]) ***** error fitlm ([1 2; 3 4; 5 6], NaN (3, 1)) ***** error fitlm (X, y, 'Exclude', (1:n)') ***** error fitlm () ***** error fitlm ('hello', y) ***** error fitlm ({'a';'b'}, [1; 2]) ***** error fitlm (X) ***** error fitlm (X, 'Weights', [1;1;1]) ***** error fitlm (X, [1; 2]) ***** error fitlm (X, [1 2]) ***** error mdl(1) ***** error mdl {1} ***** error predict (mdl, [0.5 0.25], 'BadOption', 1) ***** error predict (mdl, [0.5 0.25], 'Alpha', -0.1) ***** error predict (mdl, [0.5 0.25], 'Alpha', 1.5) ***** error predict (mdl, [0.5 0.25], 'Alpha', [0.01 0.05]) ***** error predict (mdl, [0.5 0.25], 'Prediction', 'bad') ***** error predict (mdl, ones (3, 5)) ***** error predict (mdl, ones (3, 1)) ***** error predict (mdl, table ([1;2], 'VariableNames', {'z'})) ***** error random (mdl) ***** error random (mdl, [0.5, 0.25], 'extra') ***** error random (mdl, ones (3, 5)) ***** error random (mdl, []) ***** error feval (mdl) ***** error feval (mdl, [0.5; 1.0], [0.25; 1.0], [0.1; 0.2]) ***** error feval (mdl, ones (3, 1)) ***** error feval (mdl, [0.5; 1.0; 0.2], [0.25; 1.0]) ***** error feval (mdl, table ([1; 2], 'VariableNames', {'z'})) ***** error feval (mdl, []) ***** error feval (mdl, '0.5', 0.25) ***** error coefCI (mdl, 0.05, 'extra') ***** error coefCI (mdl, 1.5) ***** error coefCI (mdl, -0.1) ***** error coefCI (mdl, [0.01 0.05]) ***** error coefCI (mdl, NaN) ***** error coefCI (mdl, 'abc') ***** error coefTest (mdl, [1 0]) ***** error coefTest (mdl, 'abc') ***** error coefTest (mdl, [0 1 0], 'abc') ***** error coefTest (mdl, [0 1 0; 0 0 1], [1]) ***** error coefTest (mdl, [0 NaN 0]) ***** error coefTest (mdl, [0 1 0], 0, 'extra') ***** error [a, b, c, d] = coefTest (mdl) ***** error dwtest (mdl, 'badmethod', 'both') ***** error dwtest (mdl, 123, 'both') ***** error dwtest (mdl, 'exact', 'both', 'extra') ***** error [a, b, c] = dwtest (mdl) ***** error addTerms (mdl) ***** error addTerms (mdl, 'x1:x2', 'extra') ***** error addTerms (mdl, 'z') ***** error addTerms (mdl, 'X1') ***** error addTerms (mdl, 'x1:z') ***** error addTerms (mdl, 'x1*z') ***** error addTerms (mdl, [1, 1, 1, 0]) ***** error addTerms (mdl, []) ***** error addTerms (mdl, {}) ***** error removeTerms (mdl) ***** error removeTerms (mdl, 'x1', 'extra') ***** error removeTerms (mdl, 'z1') ***** error removeTerms (mdl, [0 1 0 0]) ***** error removeTerms (mdl, []) ***** error removeTerms (mdl, {'x1'}) ***** error plotResiduals (mdl, 'badtype') ***** error plotResiduals (mdl, 'fitted', 'ResidualType', 'bad') ***** error plotDiagnostics (mdl, 'badtype') ***** error plotDiagnostics (mdl, 'leverage', 'BadProp', 1) ***** error plotEffects (mdl, 'extra') ***** error plotEffects (mdl, 'a', 'b') ***** error plotEffects (fitlm (X(:,1), y, 'constant')) ***** error fitlm (X, y, 'RobustOpts', 'notarealfunction') ***** error fitlm (X, y, 'RobustOpts', 42) ***** error plotAdjustedResponse (mdl) ***** error plotAdjustedResponse (mdl, 'z') ***** error plotAdjustedResponse (mdl, 3) ***** error plotAdjustedResponse (mdl, 99) ***** error plotAdjustedResponse (mdl, 1.5) ***** error plotAdjustedResponse (mdl, 'x1', 'BadOption', 5) ***** error plotAdded (mdl, {'x1', 'x2'}) ***** error plotResiduals (mdl, 'fitted', {1}, 5) ***** test ## a rejected plot property must not leave a figure behind: the properties ## are parsed before the axes is taken, gca creating a figure when none is ## current b = findall (0, 'type', 'figure'); try plotResiduals (mdl, 'fitted', {1}, 5); catch end assert_equal (isempty (setdiff (findall (0, 'type', 'figure'), b)), true); ***** test ## a histogram forwards its properties to patch, which takes its own fig = figure ('visible', 'off'); ax = axes (fig); h = plotResiduals (ax, mdl, 'histogram', 'FaceColor', [0 1 0]); assert_equal (get (h(1), 'FaceColor'), [0 1 0], 1e-10); close (fig); ***** error plotAdded (mdl, 99) ***** error plotAdded (mdl, 'NotACoef') ***** error plotAdded (mdl, 2, 'BadOpt', 5) ***** error mdl0 = fitlm (ones (n, 1), y, 'Intercept', false); plotAdded (mdl0) ***** error plot (mdl, 'extra') ***** error plotInteraction (mdl) ***** error plotInteraction (mdl, 'x1') ***** error plotInteraction (mdl, 'x1', 'x2', 'badtype') ***** error plotInteraction (mdl, 'x1', 'x2', 'effects', 'extra') ***** error plotInteraction (mdl, 'z', 'x2') ***** error plotInteraction (mdl, 'x1', 'z') ***** error plotInteraction (mdl, 99, 'x2') ***** error plotInteraction (mdl, 1.5, 'x2') ***** error plotInteraction (mdl, 'y', 'x2') ***** error plotInteraction (mdl, 'x1', 'y') ***** error plotInteraction (mdl, 'x1', 'x1') ***** error compact (mdl, 'extra') ***** error anova (mdl, 'components', 'h', 'extra') ***** error anova (mdl, 'bogus') ***** error anova (mdl, 'summary', 2) ***** error anova (mdl, 'components', 4) ***** error ... mdl0 = fitlm (X, y, 'RobustOpts', 'on'); step (mdl0) ***** error step (mdl, 'Verbose') ***** shared tf, tv, tr, ttbl tf = [1;2;3;4;5;6;7;8;9;10;11;12]; tv = [2;1;4;3;6;5;8;7;10;9;12;11]; tr = [3.1;4.2;5.3;6.4;7.5;8.6;9.7;10.8;11.9;13.0;14.1;15.2]; ttbl = table (tf, tv, tr, 'VariableNames', {'u', 'v', 'resp'}); ***** test # a power keeps its exponent in the variable's own column m = fitlm (ttbl, 'resp ~ 1 + u*v + u^2 + v^2'); assert_equal (char (m.Formula), 'resp ~ 1 + u*v + u^2 + v^2'); assert_equal (m.Formula.Terms, ... [0 0 0; 1 0 0; 0 1 0; 1 1 0; 2 0 0; 0 2 0]); assert_equal (m.Formula.TermNames, ... {'(Intercept)'; 'u'; 'v'; 'u:v'; 'u^2'; 'v^2'}); ***** test # an interaction survives when one factor is not a main effect m = fitlm (ttbl, 'resp ~ 1 + u + u:v'); assert_equal (char (m.Formula), 'resp ~ 1 + u + u:v'); assert_equal (m.Formula.Terms, [0 0 0; 1 0 0; 1 1 0]); assert_equal (m.Formula.TermNames, {'(Intercept)'; 'u'; 'u:v'}); assert_equal (m.CoefficientNames, {'(Intercept)', 'u', 'u:v'}); ***** test # a power alone still names the variable it belongs to m = fitlm (ttbl, 'resp ~ 1 + v^2 + u^2'); assert_equal (char (m.Formula), 'resp ~ 1 + u + v + u^2 + v^2'); assert_equal (m.Formula.NTerms, 5); assert_equal (m.Formula.PredictorNames, {'u', 'v'}); ***** shared cf, ch, cg, ct1, ct2 cf = [1;2;3;4;5;6;7;8;9;10;11;12]; ch = {'b';'c';'a';'b';'c';'a';'b';'c';'a';'b';'c';'a'}; cg = {'lo';'hi';'lo';'hi';'lo';'hi';'lo';'hi';'lo';'hi';'lo';'hi'}; ct1 = table (cf, ch, [3.1;4.2;5.3;6.4;7.5;8.6;9.7;10.8;11.9;13;14.1;15.2], ... 'VariableNames', {'u', 'h2', 'resp'}); ct2 = table (ch, cg, [3.1;4.2;5.3;6.4;7.5;8.6;9.7;10.8;11.9;13;14.1;15.2], ... 'VariableNames', {'h2', 'g', 'resp'}); ***** test # every level is coded, and the estimates are the group means m = fitlm (ct1, 'resp ~ h2 - 1'); assert_equal (m.CoefficientNames, {'h2_b', 'h2_c', 'h2_a'}); assert_equal (m.Coefficients.Estimate', [8.05, 9.15, 10.25], 1e-12); assert_equal (m.Rsquared.Ordinary > 0, true); ***** test # the keyword path codes it the same way m = fitlm (ct1, 'linear', 'Intercept', false); assert_equal (m.CoefficientNames, {'u', 'h2_b', 'h2_c', 'h2_a'}); assert_equal (m.NumCoefficients, m.NumEstimatedCoefficients); ***** test # a second categorical stays reference coded, keeping the design full rank for spec = {'resp ~ h2 + g - 1', 'linear'} if (strcmp (spec{1}, 'linear')) m = fitlm (ct2, spec{1}, 'Intercept', false); else m = fitlm (ct2, spec{1}); endif assert_equal (m.CoefficientNames, {'h2_b', 'h2_c', 'h2_a', 'g_hi'}); assert_equal (m.NumCoefficients, m.NumEstimatedCoefficients); endfor ***** test # an intercept still takes the reference level with it m = fitlm (ct1, 'resp ~ 1 + h2'); assert_equal (m.CoefficientNames, {'(Intercept)', 'h2_c', 'h2_a'}); m = fitlm (ct1, 'linear'); assert_equal (m.CoefficientNames, {'(Intercept)', 'u', 'h2_c', 'h2_a'}); ***** shared vu, vg, vb, vk, vr vu = [1;2;3;4;5;6;7;8;9;10;11;12]; vg = {'lo';'hi';'lo';'hi';'lo';'hi';'lo';'hi';'lo';'hi';'lo';'hi'}; vb = logical ([0;1;0;1;0;1;0;1;0;1;0;1]); vk = [5;3;5;3;5;3;5;3;5;3;5;3]; vr = [3.1;4.2;5.3;6.4;7.5;8.6;9.7;10.8;11.9;13;14.1;15.2]; ***** test # a logical column is coded by value, with false as the reference t = table (vu, vb, vr, 'VariableNames', {'u', 'b', 'resp'}); m = fitlm (t, 'resp ~ 1 + u + b'); assert_equal (m.CoefficientNames, {'(Intercept)', 'u', 'b_1'}); assert_equal (m.VariableInfo.IsCategorical, [false; true; false]); assert_equal (m.VariableInfo.Class, {'double'; 'logical'; 'double'}); assert_equal (m.VariableInfo.Range{2}, [false, true]); ## and the keyword path codes it identically assert_equal (fitlm (t, 'linear').CoefficientNames, ... {'(Intercept)', 'u', 'b_1'}); ***** test # 'CategoricalVars' is honoured on the formula path too t = table (vu, vk, vr, 'VariableNames', {'u', 'k', 'resp'}); m = fitlm (t, 'resp ~ 1 + u + k', 'CategoricalVars', {'k'}); assert_equal (m.CoefficientNames, {'(Intercept)', 'u', 'k_5'}); assert_equal (m.VariableInfo.IsCategorical, [false; true; false]); assert_equal (m.VariableInfo.Range{2}, [3, 5]); ## without the declaration it stays numeric m = fitlm (t, 'resp ~ 1 + u + k'); assert_equal (m.CoefficientNames, {'(Intercept)', 'u', 'k'}); ***** test # a string column groups like a cellstr one t = table (vu, string (vg), vr, 'VariableNames', {'u', 'g', 'resp'}); m = fitlm (t, 'resp ~ 1 + u + g'); assert_equal (m.CoefficientNames, {'(Intercept)', 'u', 'g_hi'}); assert_equal (m.VariableInfo.IsCategorical, [false; true; false]); assert_equal (class (m.VariableInfo.Range{2}), 'string'); ***** test # Range keeps each variable's own type and the design's level order t = table (vu, vg, vr, 'VariableNames', {'u', 'g', 'resp'}); m = fitlm (t, 'resp ~ 1 + u + g'); assert_equal (m.VariableInfo.Range{2}, {'lo', 'hi'}); assert_equal (m.VariableInfo.Range{1}, [1, 12]); t = table (vu, categorical (vg), vr, 'VariableNames', {'u', 'g', 'resp'}); m = fitlm (t, 'resp ~ 1 + u + g'); assert_equal (class (m.VariableInfo.Range{2}), 'categorical'); assert_equal (cellstr (m.VariableInfo.Range{2}), {'hi', 'lo'}); ***** test ## removeTerms names a term on a table model whose formula uses only some ## of the table's variables. The model's own terms are only as wide as the ## predictors it uses, while the refit runs against the whole table, and the ## two spaces have to be reconciled. Measured on R2024a: y ~ 1 + x1. x1 = [1; 2; 3; 4; 5; 6; 7; 8]; x2 = [2; 1; 4; 3; 6; 5; 8; 7]; x3 = [1; 1; 2; 2; 3; 3; 4; 4]; x4 = [8; 7; 6; 5; 4; 3; 2; 1]; y = 3 * x1 - 2 * x4; T = table (x1, x2, x3, x4, y); mdl = fitlm (T, "y ~ x1 + x4"); assert_equal (removeTerms (mdl, "x4").Formula.LinearPredictor, "1 + x1"); assert_equal (removeTerms (mdl, "x1").Formula.LinearPredictor, "1 + x4"); ***** test ## The intercept goes by name on such a model too. x1 = [1; 2; 3; 4; 5; 6; 7; 8]; x2 = [2; 1; 4; 3; 6; 5; 8; 7]; x4 = [8; 7; 6; 5; 4; 3; 2; 1]; y = 3 * x1 - 2 * x4; T = table (x1, x2, x4, y); mdl = fitlm (T, "y ~ x1 + x4"); assert_equal (removeTerms (mdl, "1").Formula.LinearPredictor, "x1 + x4"); ***** test ## Adding a variable the formula left out and removing it again returns ## the model to where it started. x1 = [1; 2; 3; 4; 5; 6; 7; 8]; x2 = [2; 1; 4; 3; 6; 5; 8; 7]; x4 = [8; 7; 6; 5; 4; 3; 2; 1]; y = 3 * x1 - 2 * x4; T = table (x1, x2, x4, y); mdl = fitlm (T, "y ~ x1"); grown = addTerms (mdl, "x4"); assert_equal (grown.Formula.LinearPredictor, "1 + x1 + x4"); assert_equal (removeTerms (grown, "x4").Formula.LinearPredictor, "1 + x1"); ***** test ## step reaches a variable the current model does not use, which is what ## R2024a does: a model at y ~ 1 + x1 gains x4 with no Upper given. x1 = [1; 2; 3; 4; 5; 6; 7; 8]; x2 = [2; 1; 4; 3; 6; 5; 8; 7]; x4 = [8; 7; 6; 5; 4; 3; 2; 1] + [0; 0.3; -0.2; 0.1; 0.4; -0.1; 0.2; 0]; y = 3 * x1 - 2 * x4; T = table (x1, x2, x4, y); mdl = fitlm (T, "y ~ x1"); grown = step (mdl, "Verbose", 0); assert_equal (any (strcmp (grown.PredictorNames, "x4")), true); 381 tests, 381 passed, 0 known failure, 0 skipped [inst/Regression/coxphfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/coxphfit.m ***** demo ## Fit a Cox model to right-censored survival data T = [4; 6; 8; 11; 13; 16; 18; 21; 25; 30]; X = [2 0; 5 1; 3 0; 8 1; 4 0; 7 1; 6 0; 9 1; 5 0; 10 1]; censored = [0; 0; 1; 0; 0; 1; 0; 0; 1; 0]; [b, logl] = coxphfit (X, T, 'Censoring', censored) ***** demo ## Compare the two methods of handling tied event times T = [4; 4; 6; 6; 8; 8; 11; 11; 13; 13]; X = [2 0; 5 1; 3 0; 8 1; 4 0; 7 1; 6 0; 9 1; 5 0; 10 1]; breslow = coxphfit (X, T, 'Ties', 'breslow'); efron = coxphfit (X, T, 'Ties', 'efron'); [breslow, efron] ***** shared X, T, C, Tt, F T = [4; 6; 8; 11; 13; 16; 18; 21; 25; 30]; X = [2 0; 5 1; 3 0; 8 1; 4 0; 7 1; 6 0; 9 1; 5 0; 10 1]; C = [0; 0; 1; 0; 0; 1; 0; 0; 1; 0]; Tt = [4; 4; 6; 6; 8; 8; 11; 11; 13; 13]; F = [1; 2; 1; 1; 3; 1; 1; 2; 1; 1]; ***** test [b, logl] = coxphfit (X, T); assert_equal (b, [-1.3886093196382836; 4.3814437183613322], 1e-8); assert_equal (logl, -8.8069639381632356, 1e-10); ***** test [b, logl] = coxphfit (X, T, 'Censoring', C); assert_equal (b, [-1.0422777707095543; 3.374484233216088], 1e-8); assert_equal (logl, -7.6973587461887778, 1e-10); ***** test [b, logl] = coxphfit (X, Tt, 'Censoring', C, 'Ties', 'breslow'); assert_equal (b, [-0.71807146728479765; 3.0751600100470267], 1e-8); assert_equal (logl, -9.9446106821057487, 1e-10); ***** test [b, logl] = coxphfit (X, Tt, 'Censoring', C, 'Ties', 'efron'); assert_equal (b, [-0.78425008234710136; 3.3784787697856826], 1e-8); assert_equal (logl, -9.2459071792218612, 1e-10); ***** test [b, logl] = coxphfit (X, T, 'Censoring', C, 'Frequency', F); assert_equal (b, [-1.1439301196172516; 3.7057550554856507], 1e-8); assert_equal (logl, -15.957308443384392, 1e-10); ***** test b = coxphfit (X(:,1), T, 'Censoring', C); assert_equal (b, -0.28958528273410233, 1e-8); ***** test assert_equal (coxphfit (X, Tt, 'Censoring', C), ... coxphfit (X, Tt, 'Censoring', C, 'Ties', 'breslow')); ***** test b = coxphfit (X, T, 'Censoring', C, 'Baseline', 0); assert_equal (b, [-1.0422777707095543; 3.374484233216088], 1e-8); ***** test b = coxphfit (X, T, 'Censoring', C, 'B0', [0.1; -0.1]); assert_equal (b, [-1.0422777707095543; 3.374484233216088], 1e-8); ***** test [b, logl, H] = coxphfit (X, T, 'Censoring', C); assert_equal (size (H), [8, 2]); assert_equal (H(1,:), [4, 0]); assert_equal (H(:,1)', [4, 4, 6, 11, 13, 18, 21, 30]); assert_equal (H(end,2), 16.21202553, 1e-6); ***** test Cc = [1; 0; 1; 0; 0; 1; 0; 0; 1; 0]; [b, logl, H] = coxphfit (X, T, 'Censoring', Cc); assert_equal (b, [-0.94457242311897405; 3.4887572101921012], 1e-8); assert_equal (logl, -6.4545533447841414, 1e-10); assert_equal (size (H), [7, 2]); assert_equal (H(1,:), [6, 0]); assert_equal (H(:,1)', [6, 6, 11, 13, 18, 21, 30]); ***** test [~, ~, Hm] = coxphfit (X, T, 'Censoring', C); [b, ~, H0] = coxphfit (X, T, 'Censoring', C, 'Baseline', 0); assert_equal (Hm(2:end,2) ./ H0(2:end,2), ... repmat (exp (mean (X) * b), 7, 1), 1e-10); ***** test [b, logl, H, stats] = coxphfit (X, T); assert_equal (stats.beta, b); assert_equal (stats.se, [0.52737766743917369; 1.8537400210498443], 1e-8); assert_equal (stats.z, [-2.6330453589001133; 2.3635696853973904], 1e-8); assert_equal (stats.p, [0.0084623045168834322; 0.018099822319697333], 1e-10); ***** test [~, ~, ~, stats] = coxphfit (X, T); assert_equal (stats.covb, [0.27812720411358371, -0.88932589928247008; ... -0.88932589928247008, 3.4363520656418767], 1e-8); ***** test [~, ~, ~, stats] = coxphfit (X, T); assert_equal (stats.LikelihoodRatioTestP, 0.0018409958426933715, 1e-10); ***** test [~, ~, ~, stats] = coxphfit (X, T); assert_equal (fieldnames (stats)', {'covb', 'beta', 'se', 'z', 'p', ... 'csres', 'devres', 'martres', 'schres', 'sschres', 'scores', 'sscores', ... 'LikelihoodRatioTestP'}); ***** test [~, ~, ~, stats] = coxphfit (X, T); assert_equal (stats.martres(1), 0.6260391348376092, 1e-8); assert_equal (stats.csres(1), 0.3739608651623908, 1e-8); ***** test [~, ~, ~, stats] = coxphfit (X, T, 'Censoring', C); assert_equal (stats.csres + stats.martres, double (! C), 1e-12); ***** test [~, ~, ~, stats] = coxphfit (X, Tt, 'Censoring', C, 'Ties', 'efron'); assert_equal (stats.csres + stats.martres, double (! C), 1e-12); ***** test [~, ~, ~, stats] = coxphfit (X, T, 'Censoring', C); assert_equal (all (isnan (stats.schres(logical (C),:))(:)), true); assert_equal (any (isnan (stats.schres(! logical (C),:))(:)), false); ***** test [~, ~, ~, stats] = coxphfit (X, Tt, 'Censoring', C, 'Ties', 'efron'); assert_equal (stats.schres(1,:), ... [-2.8979126429870807, -0.66427498564818011], 1e-8); assert_equal (stats.schres(2,:), ... [0.10208735701291927, 0.33572501435181989], 1e-8); assert_equal (stats.schres(7,:), ... [-1.438004413666758, -0.52896263729197179], 1e-8); ***** test [~, ~, ~, stats] = coxphfit (X, Tt, 'Censoring', C, 'Ties', 'efron'); assert_equal (X(1,:) - stats.schres(1,:), X(2,:) - stats.schres(2,:), 1e-12); ***** test [~, ~, ~, sb] = coxphfit (X, T, 'Censoring', C); [~, ~, ~, se] = coxphfit (X, T, 'Censoring', C, 'Ties', 'efron'); assert_equal (X - sb.schres, X - se.schres, 1e-8); ***** test [~, ~, ~, stats] = coxphfit (X, Tt, 'Censoring', C, 'Ties', 'efron'); assert_equal (stats.sschres(1,:), ... [-1.2234488884655339, 2.2036060014505958], 1e-6); ***** test for tie = {'breslow', 'efron'} [~, ~, ~, stats] = coxphfit (X, Tt, 'Censoring', C, 'Ties', tie{1}); assert_equal (sum (stats.scores, 1), [0, 0], 1e-8); endfor ***** test [~, ~, ~, stats] = coxphfit (X, Tt, 'Censoring', C, 'Ties', 'efron', ... 'Frequency', F); assert_equal (sum (F .* stats.scores, 1), [0, 0], 1e-8); ***** test S = [1; 1; 1; 1; 1; 2; 2; 2; 2; 2]; [~, ~, ~, stats] = coxphfit (X, Tt, 'Censoring', C, 'Ties', 'efron', ... 'Strata', S); assert_equal (sum (stats.scores, 1), [0, 0], 1e-8); ***** test T2 = [0 4; 0 4; 2 6; 0 6; 3 8; 0 8; 5 11; 0 11; 7 13; 0 13]; [~, ~, ~, stats] = coxphfit (X, T2, 'Censoring', C, 'Ties', 'efron'); assert_equal (sum (stats.scores, 1), [0, 0], 1e-8); assert_equal (stats.schres(1,:), ... [-2.9010414762242362, -0.66966185365223341], 1e-6); ***** error coxphfit (X) ***** error ... coxphfit (X, T(1:5)) ***** error ... coxphfit (X, T, 'Ties', 'nosuch') ***** error ... coxphfit (X, T, 'NoSuchOption', 1) ***** error ... coxphfit (X, T, 'Censoring', C(1:5)) ***** error ... coxphfit (X, T, 'Frequency', -ones (10, 1)) ***** error ... coxphfit (X, T, 'B0', [1; 2; 3]) ***** error ... coxphfit (X, T, 'Options', 5) ***** error ... coxphfit (X, T, 'Ties') ***** error ... coxphfit (X, T, 'Strata', ones (5, 1)) ***** error ... coxphfit (X, [T, T]) ***** error ... coxphfit (X, ones (10, 3)) ***** test S = [1; 1; 1; 1; 1; 2; 2; 2; 2; 2]; [b, logl, H] = coxphfit (X, T, 'Censoring', C, 'Strata', S); assert_equal (b, [-0.77050463891752163; 3.118196154424218], 1e-8); assert_equal (logl, -5.1821575033369704, 1e-10); assert_equal (size (H), [9, 3]); ***** test S = [1; 1; 1; 1; 1; 2; 2; 2; 2; 2]; [~, ~, H] = coxphfit (X, T, 'Censoring', C, 'Strata', S); assert_equal (H(1,:), [4, 0, 1]); assert_equal (H(6,:), [18, 0, 2]); assert_equal (H(:,3)', [1, 1, 1, 1, 1, 2, 2, 2, 2]); ***** test Sa = [2; 1; 2; 1; 2; 1; 2; 1; 2; 1]; warning ('off', 'Octave:coxphfit-nostratvar', 'local'); [b, logl, H] = coxphfit (X, T, 'Censoring', C, 'Strata', Sa); assert_equal (H(:,3)', [1, 1, 1, 1, 1, 2, 2, 2, 2]); assert_equal (H(1,1), 6); assert_equal (H(6,1), 4); warning: coxphfit: a column of X is constant within every stratum and cannot be estimated. warning: called from coxphfit at line 325 column 5 __test__ at line 5 column 3 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 4838 column 2 ***** test Sa = [2; 1; 2; 1; 2; 1; 2; 1; 2; 1]; [b, logl] = coxphfit (X, T, 'Censoring', C, 'Strata', Sa); assert_equal (b(2), 0); assert_equal (isfinite (logl), true); warning: coxphfit: a column of X is constant within every stratum and cannot be estimated. warning: called from coxphfit at line 325 column 5 __test__ at line 4 column 3 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 4838 column 2 ***** warning ... coxphfit (X, T, 'Censoring', C, 'Strata', [2;1;2;1;2;1;2;1;2;1]); ***** test S = [1; 1; 1; 1; 1; 2; 2; 2; 2; 2]; Call = [0; 0; 1; 0; 0; 1; 1; 1; 1; 1]; [b, logl, H] = coxphfit (X, T, 'Censoring', Call, 'Strata', S); assert_equal (b, [-1.0429819735537043; 4.1236894294226589], 1e-6); assert_equal (size (H), [6, 3]); assert_equal (isnan (H(6,1:2)), [true, true]); assert_equal (H(6,3), 2); ***** test S = [1; 1; 1; 1; 1; 2; 2; 2; 2; 2]; [b, logl] = coxphfit (X, Tt, 'Censoring', C, 'Strata', S, 'Ties', 'efron'); assert_equal (b, [-0.55718778093112831; 3.2450469646639726], 1e-8); assert_equal (logl, -5.9561243977816423, 1e-10); ***** test T2 = [0 4; 0 6; 2 8; 0 11; 3 13; 0 16; 5 18; 0 21; 7 25; 0 30]; [b, logl, H] = coxphfit (X, T2, 'Censoring', C); assert_equal (b, [-1.0103738367681818; 3.2523078880768508], 1e-8); assert_equal (logl, -7.6542119934420016, 1e-10); assert_equal (size (H), [8, 2]); ***** test T3 = [0 4; 1 6; 2 8; 3 11; 4 13; 5 16; 6 18; 7 21; 8 25; 9 30]; [b, logl] = coxphfit (X, T3, 'Censoring', C); assert_equal (b, [-0.91180514501458609; 2.9397105827259509], 1e-6); assert_equal (logl, -7.4995427161575758, 1e-10); ***** test T3 = [0 4; 1 6; 2 8; 3 11; 4 13; 5 16; 6 18; 7 21; 8 25; 9 30]; S = [1; 1; 1; 1; 1; 2; 2; 2; 2; 2]; [b, logl, H] = coxphfit (X, T3, 'Censoring', C, 'Strata', S); assert_equal (b, [-0.72488691909164049; 2.9281191508655646], 1e-8); assert_equal (logl, -5.1261267996693967, 1e-10); assert_equal (size (H), [9, 3]); ***** test [b1, l1, H1] = coxphfit (X, T, 'Censoring', C); [b2, l2, H2] = coxphfit (X, T, 'Censoring', C, 'Strata', ones (10, 1)); assert_equal (b2, b1, 1e-12); assert_equal (l2, l1, 1e-12); assert_equal (H2, H1, 1e-12); ***** test T2 = [0 4; 0 6; 2 8; 0 11; 3 13; 0 16; 5 18; 0 21; 7 25; 0 30]; [~, ~, ~, stats] = coxphfit (X, T2, 'Censoring', C); assert_equal (stats.csres + stats.martres, double (! C), 1e-12); ***** test [b1, l1, H1, s1] = coxphfit (X, T, 'Censoring', C); [b2, l2, H2, s2] = coxphfit (X, [zeros(10,1), T], 'Censoring', C); assert_equal (b2, b1, 1e-12); assert_equal (l2, l1, 1e-12); assert_equal (H2, H1, 1e-12); assert_equal (s2.csres, s1.csres, 1e-12); ***** test S = [1; 1; 1; 1; 1; 2; 2; 2; 2; 2]; [~, ~, Ha] = coxphfit (X, T, 'Censoring', C, 'Strata', S); [~, ~, Hb] = coxphfit (X, T, 'Censoring', C, 'Strata', S, 'Baseline', 0); assert_equal (size (Ha), size (Hb)); assert_equal (any (abs (Ha(:,2) - Hb(:,2)) > 1e-12), true); ***** warning ... coxphfit ([X, ones(10,1)], T); ***** error ... coxphfit ([], []) ***** error ... coxphfit (zeros (0, 3), zeros (0, 1)) 57 tests, 57 passed, 0 known failure, 0 skipped [inst/Regression/GeneralizedLinearModel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/GeneralizedLinearModel.m ***** demo ## Fit a Poisson regression and inspect the model object. X = [0.1, 1.2; 0.4, 0.7; 1.1, 0.2; 1.5, 1.9; 0.3, 0.5; 1.8, 1.1; 0.9, 0.3]; y = [1; 0; 2; 3; 1; 4; 2]; mdl = fitglm (X, y, 'Distribution', 'poisson'); disp (mdl.Coefficients) printf ("Deviance = %g, AIC = %g\n", mdl.Deviance, mdl.ModelCriterion.AIC); ***** test X = [1 2; 2 1; 3 4; 4 3; 5 6; 6 5; 1 3; 4 2]; y = [1; 0; 2; 3; 2; 4; 1; 3]; mdl = GeneralizedLinearModel (X, y, "linear", "Distribution", "poisson"); assert_equal (class (mdl), "GeneralizedLinearModel"); assert_equal (mdl.Distribution.Name, "Poisson"); assert_equal (mdl.Link.Name, "log"); ***** test ## Below the resolution of 1 - fcdf, values from MATLAB R2024a u = (1:30)'; m = fitglm (u, 2 * u + 0.01 * sin (u)); assert_equal (coefTest (m), 2.48569519842047e-96, -1e-8); ***** test ## Below the resolution of 1 - chi2cdf u = (1:20)'; N = 30 * ones (20, 1); m = fitglm (u, [round(N ./ (1 + exp (5 - 0.5 * u))), N], ... 'Distribution', 'binomial'); D = devianceTest (m); assert_equal (D.pValue(2), gammainc (D.chi2Stat(2) / 2, 1/2, 'upper'), ... -1e-12); ***** error GeneralizedLinearModel (1) ***** error ... GeneralizedLinearModel ("a", [1;2], "linear") ***** error ... GeneralizedLinearModel ([1 2; 3 4], "a", "linear") ***** error ... GeneralizedLinearModel ([1 2; 3 4], [1;0], "linear", ... "Distribution", "wibble") ***** error ... mdl = GeneralizedLinearModel ([1 2; 2 1; 3 4; 4 3; 5 6; 6 5], ... [1;0;2;3;2;4], "linear", ... "Distribution", "poisson"); mdl(1); ***** shared X, yp, yb, yn X = [ 0.37, 0.06, 1.76; -0.76, -1.52, 0.84; 0.76, -0.19, -0.47; ... -0.80, -2.74, -0.90; 0.08, 0.39, 1.05; -0.41, -0.03, 0.74; ... 0.23, 1.21, 0.35; 0.66, 0.94, 0.13; 0.66, -0.12, -0.06; ... 2.09, 1.33, -0.71; 1.50, 0.08, -0.52; 0.59, 0.07, -1.13; ... -1.17, -0.35, -1.28; 0.68, 0.63, -0.80; -0.69, 0.08, 0.41; ... 2.04, 0.96, -0.56]; yp = [5 2 0 3 1 1 0 1 2 1 3 0 0 1 1 3]'; yb = [1 1 1 0 0 1 1 1 1 1 1 0 0 0 0 1]'; yn = [2.1 -0.3 1.2 -1.1 0.8 0.4 1.5 1.1 0.6 2.9 2.0 0.7 -1.3 0.9 -0.2 2.5]'; ***** test # a normal-distribution GLM with identity link reproduces OLS exactly mdl = fitglm (X, yn, "Distribution", "normal"); b_ols = [ones(16, 1), X] \ yn; assert_equal (mdl.Coefficients.Estimate, b_ols, 1e-10); assert_equal (mdl.Fitted.Response, [ones(16, 1), X] * b_ols, 1e-10); assert_equal (mdl.Residuals.Raw, yn - [ones(16, 1), X] * b_ols, 1e-10); assert_equal (mdl.Deviance, sum ((yn - [ones(16, 1), X] * b_ols) .^ 2), 1e-10); assert_equal (mdl.Link.Name, "identity"); ***** test # the normal-GLM standard errors match those from regress mdl = fitglm (X, yn, "Distribution", "normal"); [~, bint] = regress (yn, [ones(16, 1), X], 0.05); se_reg = (bint(:,1) - bint(:,2)) / 2 / tinv (0.025, 12); assert_equal (mdl.Coefficients.SE, se_reg, 1e-9); ***** test # normal-GLM dispersion is estimated as SSE/DFE; log-likelihood closed form mdl = fitglm (X, yn, "Distribution", "normal"); rss = mdl.Deviance; assert_equal (mdl.DispersionEstimated, true); assert_equal (mdl.Dispersion, rss / mdl.DFE, 1e-12); assert_equal (mdl.LogLikelihood, -8 * (log (2 * pi * rss / 16) + 1), 1e-6); ***** test # Poisson coefficients and fit statistics (verified against MATLAB) mdl = fitglm (X, yp, "Distribution", "poisson"); assert_equal (mdl.Coefficients.Estimate, ... [-0.3420955; 1.2804868; -1.0743272; 0.8395779], 1e-6); assert_equal (mdl.Deviance, 7.403008, 1e-5); assert_equal (mdl.LogLikelihood, -18.543280, 1e-5); assert_equal (mdl.ModelCriterion.AIC, 45.086559, 1e-5); assert_equal (mdl.Rsquared.Deviance, 0.6627677, 1e-6); ***** test # scalar count/size properties of the Poisson fit mdl = fitglm (X, yp, "Distribution", "poisson"); assert_equal (mdl.NumCoefficients, 4); assert_equal (mdl.NumEstimatedCoefficients, 4); assert_equal (mdl.NumPredictors, 3); assert_equal (mdl.NumObservations, 16); assert_equal (mdl.DFE, 12); assert_equal (mdl.ResponseName, "y"); assert_equal (mdl.CoefficientNames, {'(Intercept)', 'x1', 'x2', 'x3'}); ***** test # Poisson has a fixed unit dispersion (not estimated) mdl = fitglm (X, yp, "Distribution", "poisson"); assert_equal (mdl.Dispersion, 1); assert_equal (mdl.DispersionEstimated, false); assert_equal (mdl.Distribution.Name, "Poisson"); assert_equal (mdl.Link.Name, "log"); ***** test # the coefficient covariance is symmetric with SE^2 on its diagonal mdl = fitglm (X, yp, "Distribution", "poisson"); C = mdl.CoefficientCovariance; assert_equal (size (C), [4, 4]); assert_equal (C, C', 1e-14); assert_equal (diag (C), mdl.Coefficients.SE .^ 2, 1e-12); ***** test # predict at the training data reproduces the fitted response mdl = fitglm (X, yp, "Distribution", "poisson"); [yhat, yci] = predict (mdl, X); assert_equal (yhat, mdl.Fitted.Response, 1e-10); assert_equal (size (yci), [16, 2]); assert_equal (all (yci(:,1) <= yhat & yhat <= yci(:,2)), true); ***** test # feval evaluates the model and agrees with predict mdl = fitglm (X, yp, "Distribution", "poisson"); assert_equal (feval (mdl, X(:,1), X(:,2), X(:,3)), predict (mdl, X), 1e-12); ***** test # coefCI matches the t-interval and honours a custom alpha mdl = fitglm (X, yp, "Distribution", "poisson"); b = mdl.Coefficients.Estimate; se = mdl.Coefficients.SE; t95 = tinv (0.975, mdl.DFE); assert_equal (coefCI (mdl), [b - t95 * se, b + t95 * se], 1e-12); t90 = tinv (0.95, mdl.DFE); assert_equal (coefCI (mdl, 0.10), [b - t90 * se, b + t90 * se], 1e-12); ***** test # coefTest gives the Wald F statistic against the constant model mdl = fitglm (X, yp, "Distribution", "poisson"); [p, F, df] = coefTest (mdl); assert_equal (F, 3.685312, 1e-5); assert_equal (p, 0.04331745, 1e-7); assert_equal (df, 3); ***** test ## devianceTest, gamma, the dispersion estimated; values from MATLAB R2024a u = (1:30)'; yg = exp (0.1 * u) .* (1 + 0.2 * sin (u)); D = devianceTest (fitglm (u, yg, 'Distribution', 'gamma')); assert_equal ([D.FStat(2), D.pValue(2)], ... [165.431140860884, 2.85011734507204e-13], -1e-12); ***** test ## devianceTest, inverse Gaussian with a log link u = (1:30)'; yg = exp (0.1 * u) .* (1 + 0.2 * sin (u)); D = devianceTest (fitglm (u, yg, 'Distribution', 'inverse gaussian', ... 'Link', 'log')); assert_equal ([D.FStat(2), D.pValue(2)], ... [704.235449350226, 2.17509777893856e-21], -1e-12); ***** test ## devianceTest, Poisson with an estimated dispersion u = (1:30)'; yc = round (5 * exp (0.05 * u) .* (1 + 0.3 * sin (u))); D = devianceTest (fitglm (u, yc, 'Distribution', 'poisson', ... 'DispersionFlag', true)); assert_equal ([D.FStat(2), D.pValue(2)], ... [91.127051941481, 2.65696346522055e-10], -1e-12); ***** test ## devianceTest, binomial with an estimated dispersion u = (1:30)'; N = 40 * ones (30, 1); ybn = round (N ./ (1 + exp (3 - 0.15 * u + 0.8 * sin (u)))); D = devianceTest (fitglm (u, [ybn, N], 'Distribution', 'binomial', ... 'DispersionFlag', true)); assert_equal ([D.FStat(2), D.pValue(2)], ... [144.333237422448, 1.44965237553984e-12], -1e-12); ***** test ## devianceTest, Poisson, the dispersion fixed u = (1:30)'; yc = round (5 * exp (0.05 * u) .* (1 + 0.3 * sin (u))); D = devianceTest (fitglm (u, yc, 'Distribution', 'poisson')); assert_equal ([D.chi2Stat(2), D.pValue(2)], ... [54.3584716312125, 1.67056245094831e-13], -1e-12); ***** test ## devianceTest, normal with the dispersion fixed u = (1:30)'; yg = exp (0.1 * u) .* (1 + 0.2 * sin (u)); D = devianceTest (fitglm (u, yg, 'Distribution', 'normal', ... 'DispersionFlag', false)); assert_equal ([D.chi2Stat(2), D.pValue(2)], ... [713.497289579326, 3.47271763963398e-157], -1e-12); ***** test # devianceTest chi-square equals the drop from the null deviance mdl = fitglm (X, yp, "Distribution", "poisson"); dt = devianceTest (mdl); assert_equal (class (dt), "table"); assert_equal (dt.chi2Stat(2), dt.Deviance(1) - dt.Deviance(2), 1e-10); ***** test # information criteria satisfy their defining identities mdl = fitglm (X, yp, "Distribution", "poisson"); k = mdl.NumEstimatedCoefficients; ll = mdl.LogLikelihood; assert_equal (mdl.ModelCriterion.AIC, -2 * ll + 2 * k, 1e-9); assert_equal (mdl.ModelCriterion.BIC, -2 * ll + k * log (16), 1e-9); ***** test # raw residuals are response minus fit; random draws match the response size mdl = fitglm (X, yp, "Distribution", "poisson"); assert_equal (mdl.Residuals.Raw, yp - mdl.Fitted.Response, 1e-12); ysim = random (mdl); assert_equal (size (ysim), [16, 1]); assert_equal (all (ysim == round (ysim) & ysim >= 0), true); ***** test # binomial/logistic fit: coefficients agree with the glmfit engine mdl = fitglm (X, yb, "Distribution", "binomial"); assert_equal (mdl.Coefficients.Estimate, glmfit (X, yb, "binomial"), 1e-8); assert_equal (mdl.Link.Name, "logit"); assert_equal (all (mdl.Fitted.Response >= 0 & mdl.Fitted.Response <= 1), true); assert_equal (mdl.Deviance, 10.997099, 1e-5); ***** test # an interaction model adds the cross term and one coefficient mdl = fitglm (X, yp, "interactions", "Distribution", "poisson"); assert_equal (any (strcmp (mdl.CoefficientNames, "x1:x2")), true); assert_equal (mdl.NumCoefficients, 7); ***** test # an offset is stored and applied mdl = fitglm (X, yp, "Distribution", "poisson", "Offset", log (2 * ones (16, 1))); assert_equal (numel (mdl.Offset), 16); ***** test # disp prints the model header and the coefficient table mdl = fitglm (X, yp, "Distribution", "poisson"); s = evalc ("disp (mdl)"); assert_equal (isempty (strfind (s, "Generalized linear regression model")), false); assert_equal (isempty (strfind (s, "Estimate")), false); ***** test # chained subsref reaches property -> table column -> element mdl = fitglm (X, yp, "Distribution", "poisson"); assert_equal (numel (mdl.Coefficients.Estimate), 4); assert_equal (mdl.Coefficients.Estimate(1), -0.3420955, 1e-6); assert_equal (mdl.Coefficients.Estimate(2), mdl.Coefficients{2, "Estimate"}, 1e-12); ***** test # the diagnostic and effect plots run without error mdl = fitglm (X, yp, "Distribution", "poisson"); hf = figure ("visible", "off"); unwind_protect plotResiduals (mdl); plotResiduals (mdl, "fitted", "ResidualType", "Pearson"); plotDiagnostics (mdl); plotDiagnostics (mdl, "cookd"); plotEffects (mdl); plotAdjustedResponse (mdl, 1); plotAdded (mdl, "x2"); unwind_protect_cleanup close (hf); end_unwind_protect ***** test # each family reports its MATLAB display name and its own functions names = {'Normal', 'Binomial', 'Poisson', 'Gamma', 'Inverse Gaussian'}; dists = {'normal', 'binomial', 'poisson', 'gamma', 'inverse gaussian'}; resp = {yn, yb, yp, abs(yn) + 1, abs(yn) + 1}; for k = 1:numel (dists) mdl = fitglm (X, resp{k}, "Distribution", dists{k}); assert_equal (mdl.Distribution.Name, names{k}); dev = mdl.Distribution.DevianceFunction; var = mdl.Distribution.VarianceFunction; assert_equal (is_function_handle (dev), true); assert_equal (is_function_handle (var), true); endfor ***** test # the variance function is the family's variance, not its scale mdl = fitglm (X, yp, "Distribution", "poisson"); v = mdl.Distribution.VarianceFunction; assert_equal (v ([1; 4; 9]), [1; 4; 9]); mdl = fitglm (X, abs (yn) + 1, "Distribution", "gamma"); v = mdl.Distribution.VarianceFunction; assert_equal (v ([1; 2; 3]), [1; 4; 9]); ***** test # the deviance function reproduces the reported deviance mdl = fitglm (X, yp, "Distribution", "poisson"); d = mdl.Distribution.DevianceFunction; assert_equal (sum (d (mdl.Fitted.Response, yp)), mdl.Deviance, 1e-10); ***** test # sums of squares match MATLAB and reproduce Rsquared.Ordinary mdl = fitglm (X, yp, "Distribution", "poisson"); assert_equal (mdl.SSE, 5.878748587925331, 1e-12); assert_equal (mdl.SSR, 22.693546014008586, 1e-11); assert_equal (mdl.SST, 30, 1e-12); assert_equal (mdl.Rsquared.Ordinary, 1 - mdl.SSE / mdl.SST, 1e-14); ***** test # SSE + SSR closes to SST only for the identity link mdl = fitglm (X, yn); assert_equal (mdl.SSE, 1.007522513007451, 1e-12); assert_equal (mdl.SSR, 20.549977486992557, 1e-11); assert_equal (mdl.SST, 21.557500000000005, 1e-12); assert_equal (mdl.SSE + mdl.SSR, mdl.SST, 1e-12); mdl = fitglm (X, yp, "Distribution", "poisson"); assert_equal (mdl.SSE + mdl.SSR < mdl.SST, true); ***** test # binomial and gamma sums of squares mdl = fitglm (X, yb, "Distribution", "binomial"); assert_equal ([mdl.SSE, mdl.SSR, mdl.SST], ... [1.529775270428043, 2.016466154627350, 3.75], 1e-11); mdl = fitglm (X, abs (yn) + 1, "Distribution", "gamma"); assert_equal ([mdl.SSE, mdl.SSR, mdl.SST], ... [3.537122914639216, 5.173700107311616, 9.45], 1e-9); ***** test # counts, penalty, and observation names mdl = fitglm (X, yp, "Distribution", "poisson"); assert_equal (mdl.NumVariables, 4); assert_equal (char (mdl.LikelihoodPenalty), "none"); assert_equal (mdl.ObservationNames, {}); assert_equal (size (mdl.Steps), [0, 0]); ***** test # Variables holds the data the model was built from mdl = fitglm (X, yp, "Distribution", "poisson"); assert_equal (class (mdl.Variables), "table"); assert_equal (size (mdl.Variables), [16, 4]); assert_equal (mdl.Variables.Properties.VariableNames, ... {'x1', 'x2', 'x3', 'y'}); assert_equal (mdl.Variables{:, 'x2'}, X(:,2)); assert_equal (mdl.Variables{:, 'y'}, yp); ***** test # ObservationInfo spans the input rows and records why each was used mdl = fitglm (X, yn); assert_equal (size (mdl.ObservationInfo), [16, 4]); assert_equal (mdl.ObservationInfo.Properties.VariableNames, ... {'Weights', 'Excluded', 'Missing', 'Subset'}); assert_equal (mdl.ObservationInfo.Weights, ones (16, 1)); assert_equal (any (mdl.ObservationInfo.Excluded), false); assert_equal (all (mdl.ObservationInfo.Subset), true); ***** test # excluded rows keep their weight and drop out of the fit mdl = fitglm (X, yn, "Exclude", [2 5], "Weights", (1:16)' / 16); assert_equal (mdl.NumObservations, 14); assert_equal (mdl.DFE, 10); assert_equal (mdl.ObservationInfo.Weights, (1:16)' / 16); assert_equal (find (mdl.ObservationInfo.Excluded), [2; 5]); assert_equal (any (mdl.ObservationInfo.Missing), false); assert_equal (find (! mdl.ObservationInfo.Subset), [2; 5]); assert_equal (mdl.SSE, 0.376329223083291, 1e-11); assert_equal (mdl.SST, 12.408120155038763, 1e-10); assert_equal (mdl.Dispersion, 0.037632922308329, 1e-12); ***** test # an excluded row still gets a fitted value; a missing row does not mdl = fitglm (X, yn, "Exclude", [2 5], "Weights", (1:16)' / 16); assert_equal (size (mdl.Fitted), [16, 2]); assert_equal (mdl.Fitted.Response(1:3), ... [1.452778236704902; -0.409857651323262; 1.021905387197724], 1e-11); assert_equal (mdl.Residuals.Raw(2), 0.109857651323262, 1e-11); Xm = X; Xm(3,2) = NaN; mdl = fitglm (Xm, yn); assert_equal (mdl.NumObservations, 15); assert_equal (find (mdl.ObservationInfo.Missing), 3); assert_equal (isnan (mdl.Fitted.Response(3)), true); assert_equal (isnan (mdl.Residuals.Raw(3)), true); assert_equal (mdl.Fitted.Response(1), 1.675087141815260, 1e-11); assert_equal (mdl.SSE, 0.990693655817047, 1e-11); ***** test # the binomial family adds a Probability column to Fitted mdl = fitglm (X, yb, "Distribution", "binomial"); assert_equal (mdl.Fitted.Properties.VariableNames, ... {'Response', 'LinearPredictor', 'Probability'}); assert_equal (mdl.Fitted.Probability(1), 0.998111791212415, 1e-9); assert_equal (mdl.Fitted.Response, mdl.Fitted.Probability, 1e-14); mdl = fitglm (X, yp, "Distribution", "poisson"); assert_equal (mdl.Fitted.Properties.VariableNames, ... {'Response', 'LinearPredictor'}); ***** test # with BinomialSize the response is a count and so is the fit N = 5 * ones (16, 1); y = [3 4 5 1 0 4 3 5 4 5 5 1 0 2 1 5]'; mdl = fitglm (X, y, "Distribution", "binomial", "BinomialSize", N); assert_equal (mdl.Fitted.Response, N .* mdl.Fitted.Probability, 1e-12); assert_equal (mdl.Residuals.Raw, y - mdl.Fitted.Response, 1e-12); ***** test # a two-column response and BinomialSize describe the same model N = 5 * ones (16, 1); y = [3 4 5 1 0 4 3 5 4 5 5 1 0 2 1 5]'; m1 = fitglm (X, [y, N], "Distribution", "binomial"); m2 = fitglm (X, y, "Distribution", "binomial", "BinomialSize", N); assert_equal (m1.Coefficients.Estimate, m2.Coefficients.Estimate, 1e-12); assert_equal (m1.Deviance, m2.Deviance, 1e-12); ***** test # the two-column fit matches MATLAB R2024a x = (1:10)'; S = [0 1 1 2 3 4 6 7 9 9]'; mdl = fitglm (x, [S, 10 * ones(10, 1)], "Distribution", "binomial"); assert_equal (mdl.Coefficients.Estimate, ... [-4.07619632416318; 0.639874139429377], 1e-10); assert_equal (mdl.Deviance, 1.37328920133713, 1e-10); assert_equal (mdl.LogLikelihood, -11.0853057442458, 1e-10); assert_equal (mdl.Fitted.Probability(1), 0.0311793894382727, 1e-10); assert_equal (mdl.Fitted.Response(1), 0.311793894382727, 1e-10); assert_equal (mdl.Residuals.Raw(1), -0.311793894382727, 1e-10); ***** test # a two-column fit over the shared predictors matches MATLAB R2024a N = 5 * ones (16, 1); y = [3 4 5 1 0 4 3 5 4 5 5 1 0 2 1 5]'; mdl = fitglm (X, [y, N], "Distribution", "binomial"); assert_equal (mdl.Coefficients.Estimate, ... [-0.130914595525068; 2.08707009838652; ... -0.640296111095014; 0.746404482784674], 1e-10); assert_equal (mdl.Deviance, 30.7821361135612, 1e-10); assert_equal (mdl.LogLikelihood, -23.9339330144783, 1e-10); assert_equal (mdl.Fitted.Response(1), 4.35876915277425, 1e-10); assert_equal (mdl.Residuals.Raw(1), -1.35876915277425, 1e-10); ***** test # the trials given with the response win over BinomialSize x = (1:10)'; S = [0 1 1 2 3 4 6 7 9 9]'; N = 10 * ones (10, 1); mdl = fitglm (x, [S, N], "Distribution", "binomial", "BinomialSize", (2:2:20)'); assert_equal (mdl.Coefficients.Estimate, ... [-4.07619632416318; 0.639874139429377], 1e-10); ***** test # a binomial prediction is a probability, not a count x = (1:10)'; S = [0 1 1 2 3 4 6 7 9 9]'; mdl = fitglm (x, [S, 10 * ones(10, 1)], "Distribution", "binomial"); assert_equal (predict (mdl, [2; 5; 8]), ... [0.0575164189082781; 0.293836018581318; ... 0.739389288247498], 1e-10); ***** test # Variables reports the successes, not the proportion fitted x = (1:10)'; S = [0 1 1 2 3 4 6 7 9 9]'; mdl = fitglm (x, [S, 10 * ones(10, 1)], "Distribution", "binomial"); assert_equal (mdl.Variables{:, 'y'}, S); ***** test # a missing success count drops its observation x = (1:10)'; S = [0 1 NaN 2 3 4 6 7 9 9]'; mdl = fitglm (x, [S, 10 * ones(10, 1)], "Distribution", "binomial"); assert_equal (mdl.NumObservations, 9); ***** test # the successes need not be whole numbers, as in MATLAB x = (1:10)'; S = [0 1 1 2 3 4 6 7 9 9]' + 0.5; mdl = fitglm (x, [S, 10 * ones(10, 1)], "Distribution", "binomial"); assert_equal (mdl.Coefficients.Estimate, ... [-3.55186660705826; 0.609271573628808], 1e-10); ***** warning ... N = 5 * ones (16, 1); fitglm (X, [3 4 5 1 0 4 3 5 4 5 5 1 0 2 1 5]' ./ N, ... "Distribution", "binomial", "BinomialSize", N); ***** error ... fitglm ((1:4)', [1 1 1 1]', "Distribution", "binomial", ... "BinomialSize", [2 2 2 2.5]') ***** error ... fitglm ((1:4)', [1 1 1 1; 2 2 2 0]', "Distribution", "binomial") ***** error ... fitglm ((1:4)', [1 1 1 5; 2 2 2 2]', "Distribution", "binomial") ***** error ... fitglm ((1:4)', [1 1 1 1]', "Distribution", "binomial", ... "BinomialSize", [2 2]') ***** error ... fitglm ((1:4)', [1 1 1 1; 2 2 2 2; 3 3 3 3]', "Distribution", "binomial") ***** error ... fitglm ((1:4)', [1 1 1 1; 2 2 2 2]', "Distribution", "poisson") ***** test # residuals gain the linear-predictor column, in MATLAB's order mdl = fitglm (X, yp, "Distribution", "poisson"); assert_equal (mdl.Residuals.Properties.VariableNames, ... {'Raw', 'LinearPredictor', 'Pearson', 'Anscombe', 'Deviance'}); assert_equal (mdl.Residuals.LinearPredictor(1), 0.066685156329760, 1e-12); ## For the log link the working residual is the raw one over the mean. assert_equal (mdl.Residuals.LinearPredictor, ... mdl.Residuals.Raw ./ mdl.Fitted.Response, 1e-12); ***** test # the identity link leaves the linear-predictor residual raw mdl = fitglm (X, yn); assert_equal (mdl.Residuals.LinearPredictor, mdl.Residuals.Raw, 1e-14); mdl = fitglm (X, yb, "Distribution", "binomial"); assert_equal (mdl.Residuals.LinearPredictor(1), 1.001891780864838, 1e-7); ***** test # leverage, Cook's distance, and the hat matrix mdl = fitglm (X, yp, "Distribution", "poisson"); assert_equal (mdl.Diagnostics.Properties.VariableNames, ... {'Leverage', 'CooksDistance', 'HatMatrix'}); assert_equal (mdl.Diagnostics.Leverage(1), 0.768034312650850, 1e-7); assert_equal (mdl.Diagnostics.CooksDistance(1), 0.074381550609974, 1e-7); assert_equal (size (mdl.Diagnostics.HatMatrix), [16, 16]); assert_equal (diag (mdl.Diagnostics.HatMatrix), mdl.Diagnostics.Leverage, ... 1e-14); assert_equal (sum (mdl.Diagnostics.Leverage), mdl.NumCoefficients, 1e-8); ***** test # the GLM hat matrix is the asymmetric IRLS form, so H(i,j) != H(j,i) mdl = fitglm (X, yp, "Distribution", "poisson"); H = mdl.Diagnostics.HatMatrix; assert_equal (H(1,2), 0.198729950284820, 1e-7); assert_equal (H(2,1), 0.334913252272241, 1e-7); ## The identity link with unit weights makes it symmetric again. H = fitglm (X, yn).Diagnostics.HatMatrix; assert_equal (H, H', 1e-12); ***** test # normal-family diagnostics match MATLAB mdl = fitglm (X, yn); assert_equal (mdl.Diagnostics.Leverage(1:3), ... [0.392783227704423; 0.308688028422869; 0.103894702431155], 1e-12); assert_equal (mdl.Diagnostics.CooksDistance(1), 0.562165139840681, 1e-11); ***** test # rows outside the fit have no leverage and no Cook's distance mdl = fitglm (X, yn, "Exclude", [2 5], "Weights", (1:16)' / 16); assert_equal (mdl.Diagnostics.Leverage([2, 5]), [0; 0]); assert_equal (isnan (mdl.Diagnostics.CooksDistance([2, 5])), [true; true]); assert_equal (mdl.Diagnostics.Leverage(1), 0.116937877466335, 1e-11); assert_equal (mdl.Diagnostics.CooksDistance(1), 0.026081406006346, 1e-10); assert_equal (mdl.Diagnostics.HatMatrix([2, 5], :), zeros (2, 16)); ***** test # VariableInfo carries the class and range of every variable mdl = fitglm (X, yp, "Distribution", "poisson"); assert_equal (mdl.VariableInfo.Properties.VariableNames, ... {'Class', 'Range', 'InModel', 'IsCategorical'}); assert_equal (size (mdl.VariableInfo), [4, 4]); assert_equal (mdl.VariableInfo.Range{1}, [-1.17, 2.09], 1e-14); assert_equal (mdl.VariableInfo.Range{2}, [-2.74, 1.33], 1e-14); assert_equal (mdl.VariableInfo.Range{4}, [0, 5]); assert_equal (mdl.VariableInfo.InModel, [true; true; true; false]); assert_equal (mdl.VariableInfo.IsCategorical, false (4, 1)); assert_equal (mdl.VariableInfo.Class, repmat ({'double'}, 4, 1)); ***** test # a range spans the fitted rows, not the whole variable, as in MATLAB mdl = fitglm (X, yn, "Exclude", [1, 10]); assert_equal (mdl.VariableInfo.Range{1}, [-1.17, 2.04], 1e-14); assert_equal (mdl.VariableInfo.Range{4}, [-1.3, 2.5], 1e-14); ## the excluded rows carry the extremes that no longer appear assert_equal ([min(X(:,1)), max(X(:,1))], [-1.17, 2.09], 1e-14); assert_equal ([min(yn), max(yn)], [-1.3, 2.9], 1e-14); ***** test # a category appearing only in excluded rows drops out of the range u = (1:20)'; g = categorical ([repmat({'a'}, 5, 1); repmat({'b'}, 5, 1); ... repmat({'c'}, 5, 1); repmat({'d'}, 5, 1)]); resp = u + 0.5; mdl = fitglm (table (u, g, resp), 'resp ~ u + g', 'Exclude', (16:20)'); assert_equal (cellstr (mdl.VariableInfo.Range{2}), {'a', 'b', 'c'}); assert_equal (mdl.VariableInfo.Range{1}, [1, 15], 1e-14); warning: glmfit: X is ill-conditioned. warning: called from glmfit at line 320 column 5 GeneralizedLinearModel at line 1065 column 8 fitglm at line 104 column 5 __test__ at line 7 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 4846 column 2 warning: matrix singular to machine precision warning: called from GeneralizedLinearModel at line 1226 column 7 fitglm at line 104 column 5 __test__ at line 7 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 4846 column 2 ***** test # the offset spans the input rows and is zero when none was given mdl = fitglm (X, yp, "Distribution", "poisson"); assert_equal (mdl.Offset, zeros (16, 1)); mdl = fitglm (X, yp, "Distribution", "poisson", ... "Offset", log (2 * ones (16, 1))); assert_equal (mdl.Offset, log (2) * ones (16, 1), 1e-14); ***** test # the formula is a structure describing the model over its variables mdl = fitglm (X, yp, "Distribution", "poisson"); f = mdl.Formula; assert_equal (f.ResponseName, "y"); assert_equal (f.LinearPredictor, "1 + x1 + x2 + x3"); assert_equal (f.PredictorNames, {'x1', 'x2', 'x3'}); assert_equal (f.VariableNames, {'x1', 'x2', 'x3', 'y'}); assert_equal (f.TermNames, {'(Intercept)'; 'x1'; 'x2'; 'x3'}); assert_equal (f.Terms, [0 0 0 0; 1 0 0 0; 0 1 0 0; 0 0 1 0]); assert_equal (f.Link, "log"); assert_equal (f.InModel, [true, true, true, false]); assert_equal (f.HasIntercept, true); assert_equal ([f.NTerms, f.NVars, f.NPredictors], [4, 4, 3]); assert_equal (f.FunctionCalls, cell (1, 0)); assert_equal (f.ModelFun ([1; 2], [1, 3]), 7); ***** test # a term whose parts are all present is written as a product f = fitglm (X, yn, "interactions").Formula; assert_equal (f.LinearPredictor, "1 + x1*x2 + x1*x3 + x2*x3"); assert_equal (f.NTerms, 7); assert_equal (f.TermNames, ... {'(Intercept)'; 'x1'; 'x2'; 'x3'; 'x1:x2'; 'x1:x3'; 'x2:x3'}); f = fitglm (X(:,1:2), yn, "quadratic").Formula; assert_equal (f.LinearPredictor, "1 + x1*x2 + x1^2 + x2^2"); assert_equal (f.TermNames, ... {'(Intercept)'; 'x1'; 'x2'; 'x1:x2'; 'x1^2'; 'x2^2'}); assert_equal (f.Terms, [0 0 0; 1 0 0; 0 1 0; 1 1 0; 2 0 0; 0 2 0]); ***** test # only pairs collapse into a product, never a three-way interaction f = fitglm (X, yn, "full").Formula; assert_equal (f.LinearPredictor, "1 + x1*x2 + x1*x3 + x2*x3 + x1:x2:x3"); ***** test # dropping the intercept drops the leading 1 f = fitglm (X, yn, "Intercept", false).Formula; assert_equal (f.LinearPredictor, "x1 + x2 + x3"); assert_equal (f.HasIntercept, false); assert_equal (f.Terms, [1 0 0 0; 0 1 0 0; 0 0 1 0]); ***** test # disp names the link alongside the response s = evalc ("disp (fitglm (X, yp, 'Distribution', 'poisson'))"); assert_equal (isempty (strfind (s, "log(y) ~ 1 + x1 + x2 + x3")), false); s = evalc ("disp (fitglm (X, yb, 'Distribution', 'binomial'))"); assert_equal (isempty (strfind (s, "logit(y) ~ 1 + x1 + x2 + x3")), false); s = evalc ("disp (fitglm (X, yn))"); assert_equal (isempty (strfind (s, "y ~ 1 + x1 + x2 + x3")), false); ***** test # a numeric link is named by its exponent and shown as a power mdl = fitglm (X, abs (yn) + 1, "Distribution", "inverse gaussian"); assert_equal (mdl.Link.Name, "-2"); s = evalc ("disp (mdl)"); assert_equal (isempty (strfind (s, "power(y,-2) ~ 1 + x1")), false); ***** test # a table model keeps every column but only models what it names tbl = array2table ([X, yn], "VariableNames", {'a', 'b', 'c', 'resp'}); mdl = fitglm (tbl, "resp ~ 1 + a + b"); assert_equal (mdl.NumPredictors, 2); assert_equal (mdl.NumVariables, 4); assert_equal (mdl.PredictorNames, {'a'; 'b'}); assert_equal (mdl.VariableNames, {'a'; 'b'; 'c'; 'resp'}); assert_equal (mdl.Formula.LinearPredictor, "1 + a + b"); assert_equal (mdl.Formula.InModel, [true, true, false, false]); assert_equal (mdl.VariableInfo.InModel, [true; true; false; false]); assert_equal (size (mdl.Variables), [16, 4]); ***** test # a column the model does not use cannot cost an observation tbl = array2table ([X, yn], "VariableNames", {'a', 'b', 'c', 'resp'}); tbl.c(4) = NaN; mdl = fitglm (tbl, "resp ~ 1 + a + b"); assert_equal (mdl.NumObservations, 16); assert_equal (any (mdl.ObservationInfo.Missing), false); ***** test # a grouping column is reported by its own class and its levels g = {'lo'; 'hi'; 'lo'; 'hi'; 'lo'; 'hi'; 'lo'; 'hi'; ... 'lo'; 'hi'; 'lo'; 'hi'; 'lo'; 'hi'; 'lo'; 'hi'}; tbl = table (X(:,1), g, yn, "VariableNames", {'u', 'grp', 'resp'}); mdl = fitglm (tbl, "resp ~ 1 + u + grp"); assert_equal (mdl.VariableInfo.Class, {'double'; 'cell'; 'double'}); assert_equal (mdl.VariableInfo.IsCategorical, [false; true; false]); ## The levels are listed as the design codes them: first seen first. assert_equal (mdl.VariableInfo.Range{2}, {'lo', 'hi'}); assert_equal (mdl.NumPredictors, 2); assert_equal (mdl.NumVariables, 3); ## The indicator columns fold back onto the variable they came from. assert_equal (mdl.Formula.NTerms, 3); assert_equal (sort (mdl.Formula.TermNames), {'(Intercept)'; 'grp'; 'u'}); ***** test # devianceTest labels both rows with their rendered formula mdl = fitglm (X, yp, "Distribution", "poisson"); dt = devianceTest (mdl); assert_equal (dt.Properties.RowNames, ... {'log(y) ~ 1'; 'log(y) ~ 1 + x1 + x2 + x3'}); mdl = fitglm (X, yn); dt = devianceTest (mdl); assert_equal (dt.Properties.RowNames, ... {'y ~ 1'; 'y ~ 1 + x1 + x2 + x3'}); ***** test # a power keeps its exponent in the variable's own column u = [1;2;3;4;5;6;7;8;9;10;11;12]; v = [2;1;4;3;6;5;8;7;10;9;12;11]; cnt = [2;5;3;7;4;6;8;3;5;9;4;6]; tbl = table (u, v, cnt); f = fitglm (tbl, 'cnt ~ 1 + u*v + u^2', 'Distribution', 'poisson').Formula; assert_equal (char (f), 'log(cnt) ~ 1 + u*v + u^2'); assert_equal (f.Terms, [0 0 0; 1 0 0; 0 1 0; 1 1 0; 2 0 0]); assert_equal (f.TermNames, {'(Intercept)'; 'u'; 'v'; 'u:v'; 'u^2'}); ***** test # an interaction survives when one factor is not a main effect u = [1;2;3;4;5;6;7;8;9;10;11;12]; v = [2;1;4;3;6;5;8;7;10;9;12;11]; cnt = [2;5;3;7;4;6;8;3;5;9;4;6]; tbl = table (u, v, cnt); f = fitglm (tbl, 'cnt ~ 1 + u + u:v', 'Distribution', 'poisson').Formula; assert_equal (char (f), 'log(cnt) ~ 1 + u + u:v'); assert_equal (f.Terms, [0 0 0; 1 0 0; 1 1 0]); ***** test # dropping the intercept codes the first categorical in full, both paths u = [1;2;3;4;5;6;7;8;9;10;11;12]; h2 = {'b';'c';'a';'b';'c';'a';'b';'c';'a';'b';'c';'a'}; cnt = [2;5;3;7;4;6;8;3;5;9;4;6]; tbl = table (u, h2, cnt); m = fitglm (tbl, 'cnt ~ h2 - 1', 'Distribution', 'poisson'); assert_equal (m.CoefficientNames, {'h2_b', 'h2_c', 'h2_a'}); m = fitglm (tbl, 'linear', 'Distribution', 'poisson', 'Intercept', false); assert_equal (m.CoefficientNames, {'u', 'h2_b', 'h2_c', 'h2_a'}); 85 tests, 85 passed, 0 known failure, 0 skipped [inst/Regression/monotone_smooth.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/monotone_smooth.m ***** error ... monotone_smooth (1) ***** error ... monotone_smooth ('char', 1) ***** error ... monotone_smooth ({1,2,3}, 1) ***** error ... monotone_smooth (ones (20,3), 1) ***** error ... monotone_smooth (1, 'char') ***** error ... monotone_smooth (1, {1,2,3}) ***** error ... monotone_smooth (1, ones (20,3)) ***** error monotone_smooth (ones (10,1), ones (10,1), [1, 2]) ***** error monotone_smooth (ones (10,1), ones (10,1), {2}) ***** error monotone_smooth (ones (10,1), ones (10,1), 'char') 10 tests, 10 passed, 0 known failure, 0 skipped [inst/Regression/fitrm.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/fitrm.m ***** demo ## Four measurements on each iris, and whether they differ by species load fisheriris t = table (species, meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'species', 'meas1', 'meas2', 'meas3', 'meas4'}); Meas = table ([1 2 3 4]', 'VariableNames', {'Measurements'}); rm = fitrm (t, 'meas1-meas4 ~ species', 'WithinDesign', Meas) ranova (rm) mauchly (rm) epsilon (rm) ***** test load fisheriris t = table (species, meas(:,1), meas(:,2), meas(:,3), meas(:,4), ... 'VariableNames', {'species', 'meas1', 'meas2', 'meas3', 'meas4'}); rm = fitrm (t, 'meas1-meas4 ~ species'); assert_equal (class (rm), 'RepeatedMeasuresModel'); ***** error fitrm () ***** error fitrm (1) 3 tests, 3 passed, 0 known failure, 0 skipped [inst/Regression/regress.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/regress.m ***** test % Longley data from the NIST Statistical Reference Dataset Z = [ 60323 83.0 234289 2356 1590 107608 1947 61122 88.5 259426 2325 1456 108632 1948 60171 88.2 258054 3682 1616 109773 1949 61187 89.5 284599 3351 1650 110929 1950 63221 96.2 328975 2099 3099 112075 1951 63639 98.1 346999 1932 3594 113270 1952 64989 99.0 365385 1870 3547 115094 1953 63761 100.0 363112 3578 3350 116219 1954 66019 101.2 397469 2904 3048 117388 1955 67857 104.6 419180 2822 2857 118734 1956 68169 108.4 442769 2936 2798 120445 1957 66513 110.8 444546 4681 2637 121950 1958 68655 112.6 482704 3813 2552 123366 1959 69564 114.2 502601 3931 2514 125368 1960 69331 115.7 518173 4806 2572 127852 1961 70551 116.9 554894 4007 2827 130081 1962 ]; % Results certified by NIST using 500 digit arithmetic % b and standard error in b V = [ -3482258.63459582 890420.383607373 15.0618722713733 84.9149257747669 -0.358191792925910E-01 0.334910077722432E-01 -2.02022980381683 0.488399681651699 -1.03322686717359 0.214274163161675 -0.511041056535807E-01 0.226073200069370 1829.15146461355 455.478499142212 ]; Rsq = 0.995479004577296; F = 330.285339234588; y = Z(:,1); X = [ones(rows(Z),1), Z(:,2:end)]; alpha = 0.05; [b, bint, r, rint, stats] = regress (y, X, alpha); assert_equal (b,V(:,1),4e-6); assert_equal (stats(1),Rsq,1e-12); assert_equal (stats(2),F,3e-8); assert_equal (((bint(:,1)-bint(:,2))/2)/tinv (alpha/2,9),V(:,2),-1e-11); ***** test X = [ones(6, 1), (1:6)']; y = [1.1 1.9 3.2 3.9 5.1 6.2]; assert_equal (regress (y, X), regress (y', X)); ***** test ## Below the resolution of 1 - fcdf, values from MATLAB R2024a u = (1:30)'; [~, ~, ~, ~, st] = regress (2 * u + 0.01 * sin (u), [ones(30, 1), u]); assert_equal (st(3), 2.48569519842005e-96, -1e-8); ***** error regress (ones (3, 2), ones (3, 2)) 4 tests, 4 passed, 0 known failure, 0 skipped [inst/Regression/fitlmematrix.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/fitlmematrix.m ***** demo ## A random-intercept model on a small balanced data set: five subjects ## measured at four values of a predictor x. x = repmat ([1 2 3 4]', 5, 1); subject = reshape (repmat (1:5, 4, 1), [], 1); y = 2 + 0.8 * x + reshape (repmat ([1 -1 0.5 -0.5 0]', 1, 4)', [], 1) ... + 0.1 * sin (1:20)'; X = [ones(20,1), x]; lme = fitlmematrix (X, y, ones (20, 1), subject, "FitMethod", "REML"); beta = fixedEffects (lme); [psi, mse] = covarianceParameters (lme); printf ("intercept = %.4f, slope = %.4f\n", beta); printf ("between-subject var = %.4f, residual var = %.4f\n", psi{1}, mse); ***** test a = 5; r = 6; n = a*r; grp = reshape (repmat (1:a, r, 1), [], 1); yv = [ 4.1 4.5 3.8 4.3 4.0 4.2, 6.0 5.7 6.3 5.9 6.1 6.2, ... 2.2 2.5 2.0 2.4 2.1 2.3, 5.1 4.9 5.3 5.0 5.2 4.8, ... 3.3 3.6 3.1 3.4 3.2 3.5 ]'; X = ones (n, 1); lme = fitlmematrix (X, yv, ones (n, 1), grp, "FitMethod", "REML"); gm = mean (yv); gmeans = accumarray (grp, yv, [], @mean); SSB = r * sum ((gmeans - gm) .^ 2); MSB = SSB / (a - 1); SSE = sum ((yv - gmeans(grp)) .^ 2); MSE = SSE / (n - a); tau2 = (MSB - MSE) / r; [psi, mse] = covarianceParameters (lme); assert_equal (fixedEffects (lme), gm, 1e-8); assert_equal (mse, MSE, 1e-6); assert_equal (psi{1}, tau2, 1e-6); ***** test a = 4; r = 5; n = a*r; grp = reshape (repmat (1:a, r, 1), [], 1); x = (1:n)' / n; yv = 1 + 2*x + reshape (repmat ([0.5 -0.5 0.2 -0.2], r, 1), [], 1) ... + 0.05 * cos (1:n)'; X = [ones(n,1), x]; lme = fitlmematrix (X, yv, ones (n, 1), grp, "FitMethod", "REML"); ## rebuild V = Psi over groups + sigma2 I and check the GLS identities [psi, mse] = covarianceParameters (lme); Zx = zeros (n, a); for l = 1:a, Zx(grp==l, l) = 1; end V = psi{1} * (Zx * Zx') + mse * eye (n); Vi = inv (V); beta = (X' * Vi * X) \ (X' * Vi * yv); assert_equal (fixedEffects (lme), beta, 1e-6); assert_equal (lme.CoefficientCovariance, inv (X' * Vi * X), 1e-5); ***** shared X, yL, grp, xL, x2 xL = [0.032760004 0.70410822 -0.8646718 -0.28869454 0.51276678 -1.4975462 ... -1.4527871 -0.80013541 -1.644209 1.5137701 0.72905543 0.20880758 1.0856145 ... 0.62862577 -0.87409978 1.9178276 0.09748204 0.50697633 1.0247569 ... -0.92789896 -0.88921018 -0.98322849 -0.031378913 0.86875961 -0.91481141 ... 0.034324163 -0.25025257 -1.0575644 -0.86131607 -0.35355444 0.82950729 ... -0.36874363 0.061580868 0.55803564 -0.1763803 1.0482413 1.0137831 ... -0.94876976 -0.010703972 -0.35149845 -1.6828735 -1.0493301]'; x2 = [0.68979276 0.0074354814 -0.45697437 -0.5636481 1.4567202 -0.97829955 ... -1.12922 -0.030542479 1.5847779 -0.87837755 0.24121762 0.68747601 ... -0.56728765 0.98895053 -0.39350661 0.85326015 0.36524343 0.15824977 ... -1.7665212 0.59808246 -0.55763708 -1.1982294 -2.1473319 0.22521416 ... 0.37034398 -1.880586 0.052941033 -0.70016994 0.2174853 -1.7797082 ... 0.51971317 -0.35551286 1.9845963 -1.3498848 -0.63514097 -0.78794714 ... 1.3681179 1.4423152 -0.51233905 0.30238864 2.0458136 0.17326323]'; yL = [3.5635971 -0.36763498 1.4192715 3.4471073 2.2760668 3.6420287 ... 4.4481522 1.5292777 5.437158 0.44016873 0.7259756 2.9771749 1.2941347 ... 0.26407508 1.9673466 0.77589984 1.2176078 0.8528384 -0.86522876 2.8651388 ... 2.0127931 3.1242841 -0.49164361 1.3192295 5.3782287 -0.40680701 2.3989882 ... 3.606108 1.9193197 1.6713765 2.4383124 1.9314844 3.5112706 0.91644553 ... 0.034923706 -0.15510033 2.1765206 2.5327412 3.1421219 3.3472574 5.343425 ... 3.8775899]'; grp = [1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 ... 5 6 1 2 3 4 5 6]'; X = [ones(42,1), xL, x2]; ***** test # returns a LinearMixedModel object lme = fitlmematrix (X, yL, ones (42, 1), grp, "FitMethod", "ML"); assert_equal (isa (lme, "LinearMixedModel"), true); ***** test # random intercept, ML -- matches MATLAB fitlmematrix lme = fitlmematrix (X, yL, ones (42, 1), grp, "FitMethod", "ML"); [psi, mse] = covarianceParameters (lme); assert_equal (fixedEffects (lme), [1.9685543; -1.3771207; 0.81016147], 1e-4); assert_equal (mse, 0.36422151, 1e-4); assert_equal (psi{1}, 0.65265828, 1e-4); assert_equal (lme.LogLikelihood, -46.203282, 1e-4); ***** test # correlated random intercept + slope, REML -- matches MATLAB Z = [ones(42,1), xL]; lme = fitlmematrix (X, yL, Z, grp, "FitMethod", "REML"); [psi, mse] = covarianceParameters (lme); assert_equal (fixedEffects (lme), [2.0034354; -1.3374715; 0.83788802], 1e-3); assert_equal (mse, 0.36649172, 1e-3); assert_equal (lme.LogLikelihood, -48.280962, 1e-3); assert_equal (psi{1}, ... [0.7846112, -0.14287556; -0.14287556, 0.026017248], 1e-3); ***** test # ML and REML give different (both sensible) variance components lme_ml = fitlmematrix (X, yL, ones (42, 1), grp, "FitMethod", "ML"); lme_re = fitlmematrix (X, yL, ones (42, 1), grp, "FitMethod", "REML"); pml = covarianceParameters (lme_ml); pre = covarianceParameters (lme_re); assert_equal (pre{1} > pml{1}, true); # close, not equal assert_equal (fixedEffects (lme_ml), fixedEffects (lme_re), 5e-3); ***** test # default FitMethod is ML l1 = fitlmematrix (X, yL, ones (42, 1), grp); l2 = fitlmematrix (X, yL, ones (42, 1), grp, "FitMethod", "ML"); assert_equal (l1.LogLikelihood, l2.LogLikelihood, 1e-10); ***** test # names propagate to the fitted object lme = fitlmematrix (X, yL, ones (42, 1), grp, ... "FixedEffectPredictors", {"Int", "x", "x2"}); assert_equal (lme.CoefficientNames, {"Int", "x", "x2"}); ***** error fitlmematrix (1, 2) ***** error fitlmematrix ({1}, 1, 1, 1) ***** error fitlmematrix (ones (3), {1}, 1, 1) ***** error fitlmematrix (ones (3, 2), [1 2], ones (3, 1), [1 2 3]) ***** error fitlmematrix (ones (3, 2), [1;2;3], {ones(3,1), ones(3,1)}, {[1;2;3]}) ***** error fitlmematrix (ones (3, 2), [1;2;3], ones (2, 1), [1;2;3]) ***** error fitlmematrix (ones (3, 2), [1;2;3], ones (3, 1), [1;2;3], "FitMethod", "xxx") ***** error fitlmematrix (ones (3, 2), [1;2;3], ones (3, 1), [1;2;3], "FitMethod") ***** error fitlmematrix (ones (3, 2), [1;2;3], ones (3, 1), [1;2;3], "bogus", 1) ***** error fitlmematrix (ones (3, 2), [1;2;3], ones (3, 1), [1;2;3], "CovariancePattern", "Diagonal") 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Regression/fitlme.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/fitlme.m ***** demo ## Random-intercept model: sleep-study-like data with per-subject intercepts. subject = reshape (repmat (1:6, 5, 1), [], 1); days = repmat ((0:4)', 6, 1); b0 = reshape (repmat ([1 -1 0.5 -0.5 0.2 -0.2], 5, 1), [], 1); y = 250 + 10 * days + 15 * b0 + 3 * sin (1:30)'; tbl = table (y, days, subject); lme = fitlme (tbl, "y ~ days + (1 | subject)", "FitMethod", "REML"); disp (lme.Coefficients); ***** shared tbl, xL xL = [0.032760004 0.70410822 -0.8646718 -0.28869454 0.51276678 -1.4975462 ... -1.4527871 -0.80013541 -1.644209 1.5137701 0.72905543 0.20880758 1.0856145 ... 0.62862577 -0.87409978 1.9178276 0.09748204 0.50697633 1.0247569 ... -0.92789896 -0.88921018 -0.98322849 -0.031378913 0.86875961 -0.91481141 ... 0.034324163 -0.25025257 -1.0575644 -0.86131607 -0.35355444 0.82950729 ... -0.36874363 0.061580868 0.55803564 -0.1763803 1.0482413 1.0137831 ... -0.94876976 -0.010703972 -0.35149845 -1.6828735 -1.0493301]'; x2 = [0.68979276 0.0074354814 -0.45697437 -0.5636481 1.4567202 -0.97829955 ... -1.12922 -0.030542479 1.5847779 -0.87837755 0.24121762 0.68747601 ... -0.56728765 0.98895053 -0.39350661 0.85326015 0.36524343 0.15824977 ... -1.7665212 0.59808246 -0.55763708 -1.1982294 -2.1473319 0.22521416 ... 0.37034398 -1.880586 0.052941033 -0.70016994 0.2174853 -1.7797082 ... 0.51971317 -0.35551286 1.9845963 -1.3498848 -0.63514097 -0.78794714 ... 1.3681179 1.4423152 -0.51233905 0.30238864 2.0458136 0.17326323]'; yL = [3.5635971 -0.36763498 1.4192715 3.4471073 2.2760668 3.6420287 ... 4.4481522 1.5292777 5.437158 0.44016873 0.7259756 2.9771749 1.2941347 ... 0.26407508 1.9673466 0.77589984 1.2176078 0.8528384 -0.86522876 2.8651388 ... 2.0127931 3.1242841 -0.49164361 1.3192295 5.3782287 -0.40680701 2.3989882 ... 3.606108 1.9193197 1.6713765 2.4383124 1.9314844 3.5112706 0.91644553 ... 0.034923706 -0.15510033 2.1765206 2.5327412 3.1421219 3.3472574 5.343425 ... 3.8775899]'; g = [1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 ... 5 6 1 2 3 4 5 6]'; g2 = [1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 ... 2 3 1 2 3 1 2 3]'; tbl = table (yL, xL, x2, g, g2); ***** test # every random-effects syntax form reproduces MATLAB's log-likelihood forms = { "yL ~ xL + x2 + (1|g)", -49.016009; ... "yL ~ xL + x2 + (1 + xL|g)", -48.280962; ... "yL ~ xL + x2 + (1|g) + (xL-1|g)", -48.947341; ... "yL ~ xL + x2 + (xL-1|g)", -61.635296; ... "yL ~ xL + x2 + (-1 + xL|g)", -61.635296; ... "yL ~ xL + x2 + (1|g) + (1|g2)", -45.924711; ... "yL ~ xL + x2 + (1|g) + (1|g:g2)", -49.016009; ... "yL ~ xL*x2 + (1|g)", -50.366415; ... "yL ~ xL + x2 + (1 + xL + x2|g)", -48.162461 }; for k = 1:rows (forms) lme = fitlme (tbl, forms{k,1}, "FitMethod", "REML"); assert_equal (lme.LogLikelihood, forms{k,2}, 1e-4); endfor ***** test # random intercept via formula -- matches MATLAB fitlme lme = fitlme (tbl, "yL ~ xL + x2 + (1 | g)", "FitMethod", "REML"); assert_equal (isa (lme, "LinearMixedModel"), true); assert_equal (lme.Coefficients.Estimate, ... [1.96839; -1.37926; 0.811747], 1e-4); assert_equal (lme.Coefficients.SE, [0.376509; 0.113264; 0.0966571], 1e-5); assert_equal (lme.LogLikelihood, -49.016009, 1e-4); [psi, mse] = covarianceParameters (lme); assert_equal (psi{1}, 0.79429917, 1e-3); assert_equal (mse, 0.38539058, 1e-3); ***** test # correlated random intercept + slope via formula -- matches MATLAB lme = fitlme (tbl, "yL ~ xL + x2 + (1 + xL | g)", "FitMethod", "REML"); assert_equal (lme.Coefficients.Estimate, ... [2.0034354; -1.3374715; 0.83788802], 1e-3); assert_equal (lme.LogLikelihood, -48.280962, 1e-3); psi = covarianceParameters (lme); assert_equal (psi{1}, ... [0.7846112, -0.14287556; -0.14287556, 0.026017248], 1e-3); ***** test # formula fit equals the equivalent fitlmematrix fit lme_f = fitlme (tbl, "yL ~ xL + x2 + (1 | g)", "FitMethod", "REML"); X = [ones(42,1), xL, tbl.x2]; lme_m = fitlmematrix (X, tbl.yL, ones (42, 1), tbl.g, "FitMethod", "REML"); assert_equal (lme_f.Coefficients.Estimate, ... lme_m.Coefficients.Estimate, 1e-8); assert_equal (lme_f.LogLikelihood, lme_m.LogLikelihood, 1e-8); ***** test # slope-only random term (no random intercept) lme = fitlme (tbl, "yL ~ xL + x2 + (xL - 1 | g)", "FitMethod", "REML"); [psi, ~] = covarianceParameters (lme); assert_equal (isscalar (psi{1}), true); # 1x1 covariance (slope only) ***** test # metadata: Formula and ResponseName are stored lme = fitlme (tbl, "yL ~ xL + (1 | g)"); assert_equal (lme.Formula, "yL ~ xL + (1 | g)"); assert_equal (lme.ResponseName, "yL"); assert_equal (lme.FitMethod, "ML"); # default ***** test # rows with missing values are dropped before fitting t2 = tbl; t2.yL(3) = NaN; t2.xL(10) = NaN; lme = fitlme (t2, "yL ~ xL + x2 + (1 | g)"); assert_equal (lme.NumObservations, 40); ***** error fitlme (table ()) ***** error fitlme (magic (3), "y ~ x + (1|g)") ***** error fitlme (table (), 5) ***** error fitlme (table ((1:3)', "VariableNames", {"y"}), "y ~ 1") ***** error fitlme (table ((1:3)', "VariableNames", {"y"}), "y ~ (1|y)", "bogus", 1) ***** error fitlme (table ((1:3)', "VariableNames", {"y"}), "y ~ (1|y)", "FitMethod", "xxx") 13 tests, 13 passed, 0 known failure, 0 skipped [inst/Regression/fitnlm.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/fitnlm.m ***** demo ## Fit an exponential growth model and inspect the summary. x = [1:10]'; y = [2.1;2.9;4.2;5.3;7.1;9.4;12.8;16.5;22.1;29.8]; modelfun = @(b, x) b(1) .* exp (b(2) .* x); mdl = fitnlm (x, y, modelfun, [1; 0.3]) ***** demo ## Predictions with 95% confidence intervals on the fitted curve. x = [1:10]'; y = [2.1;2.9;4.2;5.3;7.1;9.4;12.8;16.5;22.1;29.8]; modelfun = @(b, x) b(1) .* exp (b(2) .* x); mdl = fitnlm (x, y, modelfun, [1; 0.3]); [ypred, yci] = predict (mdl, [2.5; 5.5; 8.5]) ***** shared X, y, modelfun, beta0 X = [1;2;3;4;5;6;7;8;9;10]; y = [2.1;2.9;4.2;5.3;7.1;9.4;12.8;16.5;22.1;29.8]; modelfun = @(b, x) b(1) .* exp (b(2) .* x); beta0 = [1; 0.3]; ***** test mdl = fitnlm (X, y, modelfun, beta0); assert_equal (mdl.Coefficients.Estimate, ... [1.683747025; 0.286911087], 1e-6); assert_equal (mdl.Coefficients.SE, [0.035194899; 0.002350913], 1e-6); assert_equal (mdl.Coefficients.tStat, [47.8406555; 122.042406], -1e-4); assert_equal (mdl.RMSE, 0.170942956, 1e-7); assert_equal (mdl.SSE, 0.233771954, 1e-7); assert_equal (mdl.SST, 750.976, 1e-3); ***** test mdl = fitnlm (X, y, modelfun, beta0); assert_equal (mdl.Rsquared.Ordinary, 0.999688709, 1e-8); assert_equal (mdl.Rsquared.Adjusted, 0.999649798, 1e-8); assert_equal (mdl.LogLikelihood, 4.590586096, 1e-6); assert_equal (mdl.ModelCriterion.AIC, -5.181172193, 1e-6); assert_equal (mdl.ModelCriterion.BIC, -4.576002007, 1e-6); ***** test ## coefCI matches beta +/- t * SE with the error degrees of freedom. mdl = fitnlm (X, y, modelfun, beta0); ci = coefCI (mdl); b = mdl.Coefficients.Estimate; se = mdl.Coefficients.SE; t = tinv (0.975, mdl.DFE); assert_equal (ci, [b - t .* se, b + t .* se], 1e-12); ***** test ## Table input gives the same fit as matrix input. tbl = table (X, y, "VariableNames", {"x", "y"}); mdl = fitnlm (tbl, modelfun, beta0); assert_equal (mdl.Coefficients.Estimate, [1.683747025; 0.286911087], 1e-6); assert_equal (mdl.CoefficientNames, {"b1", "b2"}); ***** test ## Custom coefficient names. mdl = fitnlm (X, y, modelfun, beta0, "CoefficientNames", {"A", "k"}); assert_equal (mdl.CoefficientNames, {"A", "k"}); ***** test ## coefTest reports a Wald F statistic versus the zero model. mdl = fitnlm (X, y, modelfun, beta0); [p, F, df] = coefTest (mdl); assert_equal (df, 2); assert_equal (F > 1e5, true); assert_equal (p < 1e-10, true); ***** test ## predict returns the fitted values and confidence intervals. mdl = fitnlm (X, y, modelfun, beta0); [yp, yci] = predict (mdl, [2.5; 5.5; 8.5]); assert_equal (yp, [3.449741842; 8.158274281; 19.293455074], 1e-6); assert_equal (yci(:,1), [3.329126146; 7.997938483; 19.121921613], 1e-5); assert_equal (yci(:,2), [3.570357538; 8.318610079; 19.464988535], 1e-5); ***** test # plotting methods, feval, and random run without error mdl = fitnlm (X, y, modelfun, beta0); assert_equal (feval (mdl, [2.5; 5.5]), predict (mdl, [2.5; 5.5]), 1e-12); assert_equal (numel (random (mdl)), 10); hf = figure ("visible", "off"); unwind_protect plotResiduals (mdl); plotResiduals (mdl, "fitted"); plotDiagnostics (mdl); plotSlice (mdl); unwind_protect_cleanup close (hf); end_unwind_protect ***** error fitnlm () ***** error fitnlm ([1, 2], [1; 2]) ***** error ... fitnlm ([1;2], [1;2], "bad", [1]) ***** error ... fitnlm ([1;2;3], [1;2;3], @(b, x) b(1) * x, 1, "foo", 1) 12 tests, 12 passed, 0 known failure, 0 skipped [inst/Regression/nlpredci.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/nlpredci.m ***** demo ## Prediction intervals for an exponential fit at three new x-values. x = [1:10]'; y = [2.1;2.9;4.2;5.3;7.1;9.4;12.8;16.5;22.1;29.8]; modelfun = @(b, x) b(1) .* exp (b(2) .* x); [beta, R, J] = nlinfit (x, y, modelfun, [1; 0.3]); [ypred, delta] = nlpredci (modelfun, [2.5; 5.5; 8.5], beta, R, 'Jacobian', J) ***** shared modelfun, beta, R, J, CovB, MSE, xp x = [1;2;3;4;5;6;7;8;9;10]; y = [2.1;2.9;4.2;5.3;7.1;9.4;12.8;16.5;22.1;29.8]; modelfun = @(b, xx) b(1) .* exp (b(2) .* xx); [beta, R, J, CovB, MSE] = nlinfit (x, y, modelfun, [1; 0.3]); xp = [2.5; 5.5; 8.5]; ***** test [yp, dc] = nlpredci (modelfun, xp, beta, R, "Jacobian", J); assert_equal (yp, [3.449741734; 8.158274148; 19.293455050], 1e-6); assert_equal (dc, [0.120614865; 0.160334882; 0.171532624], 1e-6); ***** test ## Observation (prediction) intervals exceed the curve intervals by MSE. [yp, dc] = nlpredci (modelfun, xp, beta, R, "Jacobian", J); [yp, dp] = nlpredci (modelfun, xp, beta, R, "Jacobian", J, ... "PredOpt", "observation"); assert_equal (dp, [0.412235094; 0.425555051; 0.429899138], 1e-6); assert_equal (all (dp > dc, 'all'), true); ***** test ## Simultaneous (Scheffe) intervals are wider than the pointwise ones. [yp, dc] = nlpredci (modelfun, xp, beta, R, "Jacobian", J); [yp, ds] = nlpredci (modelfun, xp, beta, R, "Jacobian", J, "SimOpt", "on"); assert_equal (ds, [0.156197123; 0.207634833; 0.222135990], 1e-6); assert_equal (all (ds > dc, 'all'), true); ***** test ## The covariance form matches the Jacobian form. [yp, dj] = nlpredci (modelfun, xp, beta, R, "Jacobian", J); [yp, dv] = nlpredci (modelfun, xp, beta, R, "Covar", CovB, "MSE", MSE); assert_equal (dj, dv, 1e-8); ***** error nlpredci (@(b, x) x, [1;2], [1;2], [1;2]) ***** error ... nlpredci (1, [1;2], [1;2], [1;2;3], "Jacobian", eye (2)) ***** error ... nlpredci (@(b, x) x, [1;2], [1;2], [1;2;3], "Jacobian", eye (2), ... "PredOpt", "bad") ***** error ... nlpredci (@(b, x) x, [1;2], [1;2], [1;2;3], "foo", 1) 8 tests, 8 passed, 0 known failure, 0 skipped [inst/Regression/GeneralizedLinearMixedModel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/GeneralizedLinearMixedModel.m ***** shared glme, tbl xL = [0.032760004 0.70410822 -0.8646718 -0.28869454 0.51276678 -1.4975462 ... -1.4527871 -0.80013541 -1.644209 1.5137701 0.72905543 0.20880758 1.0856145 ... 0.62862577 -0.87409978 1.9178276 0.09748204 0.50697633 1.0247569 ... -0.92789896 -0.88921018 -0.98322849 -0.031378913 0.86875961 -0.91481141 ... 0.034324163 -0.25025257 -1.0575644 -0.86131607 -0.35355444 0.82950729 ... -0.36874363 0.061580868 0.55803564 -0.1763803 1.0482413 1.0137831 ... -0.94876976 -0.010703972 -0.35149845 -1.6828735 -1.0493301]'; yPois = [3 3 1 1 1 1 1 2 1 5 2 0 5 0 1 5 0 2 0 0 1 0 0 5 3 0 1 0 0 1 1 1 2 2 ... 1 1 4 0 1 0 0 1]'; g = [1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 ... 6 1 2 3 4 5 6]'; tbl = table (yPois, xL, g); glme = fitglme (tbl, "yPois ~ xL + (1 | g)", "Distribution", "poisson", ... "FitMethod", "REMPL"); ***** test # object type and basic properties assert_equal (isa (glme, "GeneralizedLinearMixedModel"), true); assert_equal (glme.NumObservations, 42); assert_equal (glme.NumCoefficients, 2); assert_equal (glme.DFE, 40); assert_equal (glme.Dispersion, 1); ***** test # Coefficients table C = glme.Coefficients; assert_equal (C.Estimate, [0.23092; 0.67809], 1e-3); assert_equal (C.SE, [0.15395; 0.15220], 1e-3); assert_equal (C.DF, [40; 40]); assert_equal (C.tStat, C.Estimate ./ C.SE, 1e-10); ***** test # effect extraction and covariance parameters [beta, names] = fixedEffects (glme); assert_equal (beta, glme.Coefficients.Estimate, 1e-12); assert_equal (names(:), {"(Intercept)"; "xL"}); b = randomEffects (glme); assert_equal (numel (b), 6); [psi, dispn] = covarianceParameters (glme); assert_equal (psi{1}, 0.015918, 1e-3); assert_equal (dispn, 1); ***** test # anova F-tests: F = tStat^2 with residual DF a = anova (glme); assert_equal (a.FStat, (glme.Coefficients.tStat) .^ 2, 1e-8); assert_equal (a.DF2, [40; 40]); ***** test # coefTest and coefCI [p, F, df1, df2] = coefTest (glme, [0 1]); assert_equal (F, glme.Coefficients.tStat(2) ^ 2, 1e-6); assert_equal (df1, 1); assert_equal (df2, 40); ci = coefCI (glme); assert_equal (ci(:,1), glme.Coefficients.Lower, 1e-12); ***** test # fitted values are positive counts (log link) and residuals sum sensibly mu = fitted (glme); assert_equal (all (mu > 0, 'all'), true); assert_equal (residuals (glme), tbl.yPois - mu, 1e-12); assert_equal (residuals (glme, "ResidualType", "Pearson"), ... (tbl.yPois - mu) ./ sqrt (mu), 1e-10); ***** test # predict: conditional (known group) and marginal (unseen group) ym = predict (glme, [1 0.5], [], [], "Conditional", false); yc = predict (glme, [1 0.5], 1, 1); yu = predict (glme, [1 0.5], 1, 99); # unseen group -> marginal assert_equal (ym, exp (glme.Coefficients.Estimate' * [1; 0.5]), 1e-10); assert_equal (yu, ym, 1e-12); ***** test # designMatrix and ModelCriterion assert_equal (size (designMatrix (glme, "Fixed")), [42, 2]); assert_equal (size (designMatrix (glme, "Random")), [42, 6]); assert_equal (issparse (designMatrix (glme, "Fixed")), false); assert_equal (issparse (designMatrix (glme, "Random")), true); assert_equal (glme.ModelCriterion.Deviance, -2 * glme.LogLikelihood, 1e-10); ***** test ## A normal response with a dispersion far from one, and p-values below ## the resolution of 1 - tcdf; values from MATLAB R2024a x = (1:30)'; g = repmat ((1:5)', 6, 1); T = table (x, g, 2 * x + g + 0.01 * sin (x), ... 'VariableNames', {'x', 'g', 'y'}); m = fitglme (T, 'y ~ x + (1|g)'); assert_equal (m.Coefficients.pValue, ... [5.4976892695175e-05; 1.12635133546576e-95], -1e-3); ***** test ## The Laplace approximation is exact for a normal response x = (1:30)'; g = repmat ((1:5)', 6, 1); T = table (x, g, 2 * x + g + 0.01 * sin (x), ... 'VariableNames', {'x', 'g', 'y'}); m = fitglme (T, 'y ~ x + (1|g)', 'FitMethod', 'Laplace'); assert_equal (m.LogLikelihood, fitlme (T, 'y ~ x + (1|g)').LogLikelihood, ... -1e-8); ***** test ## Below the resolution of 1 - fcdf, values from MATLAB R2024a u = (1:30)'; g = repmat ((1:5)', 6, 1); T = table (u, g, 2 * u + g + 0.01 * sin (u), ... 'VariableNames', {'x', 'g', 'y'}); m = fitglme (T, 'y ~ x + (1|g)'); assert_equal (coefTest (m), 1.12635133546576e-95, -1e-3); ***** test u = (1:30)'; g = repmat ((1:5)', 6, 1); T = table (u, g, 2 * u + g + 0.01 * sin (u), ... 'VariableNames', {'x', 'g', 'y'}); A = anova (fitglme (T, 'y ~ x + (1|g)')); assert_equal (A.pValue(2), 1.12635133546576e-95, -1e-3); ***** error residuals (glme, "ResidualType", "xxx") ***** error designMatrix (glme, "bogus") ***** error glme(1) 15 tests, 15 passed, 0 known failure, 0 skipped [inst/Regression/CoxModel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/CoxModel.m ***** demo ## Fit a Cox proportional hazards model and read its coefficients X = [2 0; 5 1; 3 0; 8 1; 4 0; 7 1; 6 0; 9 1; 5 0; 10 1]; T = [4; 6; 8; 11; 13; 16; 18; 21; 25; 30]; mdl = fitcox (X, T) ***** demo ## The survival function at the model's baseline X = [2 0; 5 1; 3 0; 8 1; 4 0; 7 1; 6 0; 9 1; 5 0; 10 1]; T = [4; 6; 8; 11; 13; 16; 18; 21; 25; 30]; mdl = fitcox (X, T); [s, t] = survival (mdl); [t, s] ***** shared X, T, C, Tt, S, F, T2 X = [2 0; 5 1; 3 0; 8 1; 4 0; 7 1; 6 0; 9 1; 5 0; 10 1]; T = [4; 6; 8; 11; 13; 16; 18; 21; 25; 30]; C = [0; 0; 1; 0; 0; 1; 0; 0; 1; 0]; Tt = [4; 4; 6; 6; 8; 8; 11; 11; 13; 13]; S = [1; 1; 1; 1; 1; 2; 2; 2; 2; 2]; F = [1; 2; 1; 1; 3; 1; 1; 2; 1; 1]; T2 = [0 4; 0 6; 2 8; 0 11; 3 13; 0 16; 5 18; 0 21; 7 25; 0 30]; ***** test mdl = CoxModel (X, T); assert_equal (mdl.Coefficients.Beta, ... [-1.3886093196382836; 4.3814437183613322], 1e-8); assert_equal (mdl.Coefficients.SE, ... [0.52737766743917369; 1.8537400210498443], 1e-8); assert_equal (mdl.Coefficients.zStat, ... [-2.6330453589001133; 2.3635696853973904], 1e-8); assert_equal (mdl.Coefficients.pValue, ... [0.0084623045168834322; 0.018099822319697333], 1e-10); ***** test mdl = CoxModel (X, T); assert_equal (mdl.LogLikelihood, -8.8069639381632356, 1e-10); assert_equal (mdl.LikelihoodRatioTestPValue, 0.0018409958426933715, 1e-10); assert_equal (mdl.NumPredictors, 2); ***** test mdl = CoxModel (X, T); assert_equal (mdl.Coefficients.Properties.VariableNames, ... {'Beta', 'SE', 'zStat', 'pValue'}); assert_equal (mdl.Coefficients.Properties.RowNames, {'X1'; 'X2'}); assert_equal (size (mdl.Coefficients), [2, 4]); ***** test mdl = CoxModel (X, T); assert_equal (mdl.CoefficientCovariance, ... [0.27812720411358371, -0.88932589928247008; ... -0.88932589928247008, 3.4363520656418767], 1e-8); assert_equal (mdl.StandardError, ... [0.52737766743917369; 1.8537400210498443], 1e-8); assert_equal (mdl.Baseline, [5.9, 0.5], 1e-12); ***** test mdl = CoxModel (X, T); assert_equal (size (mdl.Hazard), [11, 2]); assert_equal (mdl.Hazard(1,:), [4, 0]); assert_equal (mdl.Hazard(end,2), 39.969396549779539, 1e-6); ***** test mdl = CoxModel (X, T); assert_equal (mdl.PredictorNames, {'X1', 'X2'}); assert_equal (mdl.ResponseName, 'y'); assert_equal (char (mdl.Formula), 'y ~ X1 + X2'); ***** test mdl = CoxModel (X, T, 'PredictorNames', {'age', 'trt'}); assert_equal (mdl.PredictorNames, {'age', 'trt'}); assert_equal (mdl.ResponseName, 'y'); assert_equal (char (mdl.Formula), 'y ~ age + trt'); assert_equal (mdl.Coefficients.Properties.RowNames, {'age'; 'trt'}); ***** test mdl = CoxModel (X, T); assert_equal (mdl.VariableInfo.Properties.VariableNames, ... {'Class', 'Range', 'InModel', 'IsCategorical'}); assert_equal (mdl.VariableInfo.Properties.RowNames, {'X1'; 'X2'; 'y'}); assert_equal (mdl.VariableInfo.InModel, [true; true; false]); assert_equal (mdl.VariableInfo.IsCategorical, [false; false; false]); ***** test mdl = CoxModel (X, T); assert_equal (mdl.Residuals.Properties.VariableNames, ... {'CoxSnell', 'Deviance', 'Martingale', 'Schoenfeld', ... 'ScaledSchoenfeld', 'Score', 'ScaledScore'}); assert_equal (size (mdl.Residuals), [10, 7]); assert_equal (mdl.Residuals.Martingale(1), 0.6260391348376092, 1e-8); ***** test mdl = CoxModel (X, T); mdl = discardResiduals (mdl); assert_equal (isempty (mdl.Residuals), true); assert_equal (mdl.LogLikelihood, -8.8069639381632356, 1e-10); ***** test mdl = CoxModel (X, T); assert_equal (mdl.ProportionalHazardsPValue, ... [0.43865495271858179, 0.71413497767000234], 1e-8); assert_equal (mdl.ProportionalHazardsPValueGlobal, ... 0.53179255135825187, 1e-8); ***** test mdl = CoxModel (X, T, 'Censoring', C); assert_equal (mdl.ProportionalHazardsPValue, ... [0.38377818764906124, 0.62418297490071406], 1e-8); assert_equal (mdl.ProportionalHazardsPValueGlobal, ... 0.56302705208766479, 1e-8); ***** test mdl = CoxModel (X, Tt, 'Censoring', C); assert_equal (mdl.ProportionalHazardsPValue, ... [0.21978449883707185, 0.47185588628217012], 1e-8); assert_equal (mdl.ProportionalHazardsPValueGlobal, ... 0.33816199611424813, 1e-8); ***** test mdl = CoxModel (X, Tt, 'Censoring', C, 'TieBreakMethod', 'efron'); assert_equal (mdl.Coefficients.SE, ... [0.40807722610877606; 1.7349017938498392], 1e-8); assert_equal (mdl.ProportionalHazardsPValue, ... [0.1946475346918406, 0.44447162515215921], 1e-8); assert_equal (mdl.ProportionalHazardsPValueGlobal, ... 0.29473648771539396, 1e-8); ***** test mdl = CoxModel (X, T); assert_equal (coefci (mdl), ... [-2.422250554069806, -0.35496808520676093; ... 0.74818004040311514, 8.0147073963195492], 1e-8); assert_equal (coefci (mdl, 0.01), ... [-2.747044169465374, -0.030174469811192983; ... -0.39347414902021249, 9.1563615857428768], 1e-8); ***** test mdl = CoxModel ([X, [1;3;2;5;4;6;8;7;9;10]], T); tbl = linhyptest (mdl); assert_equal (size (tbl), [3, 2]); assert_equal (tbl.Predictor, {'Empty Model'; 'X1'; 'X1, X2'}); assert_equal (tbl.pValue, [0.11426498364159436; 0.066700738069398954; ... 0.040978941270458896], 1e-8); ***** test mdl = CoxModel ([X, [1;3;2;5;4;6;8;7;9;10]], T); tbl = linhyptest (mdl); assert_equal (tbl.pValue(end), mdl.Coefficients.pValue(end), 1e-10); ***** test mdl = CoxModel (X, T); assert_equal (hazardratio (mdl, X(1,:)), 25.149914260347884, 1e-6); assert_equal (hazardratio (mdl, X(1,:), 'Baseline', 0), ... 0.062211299031685895, 1e-8); ***** test mdl = CoxModel (X, T); hr = hazardratio (mdl, X); assert_equal (numel (hr), 10); assert_equal (hr(end), 0.030119684486042686, 1e-8); ***** test mdl = CoxModel (X, T); [s, t] = survival (mdl); assert_equal (numel (s), 11); assert_equal (s(1), 1); assert_equal (s(2), 0.98524073172292947, 1e-8); assert_equal (t, mdl.Hazard(:,1)); ***** test mdl = CoxModel (X, T); s = survival (mdl, X(1,:)); assert_equal (s(2), 0.6880038362205394, 1e-8); assert_equal (s(3), 0.37858862123606984, 1e-8); ***** test mdl = CoxModel (X, T); s = survival (mdl, 'Time', [4; 5; 6; 7]); assert_equal (s, [0.98524073172292947; 0.97367819309820003; ... 0.96211565447347058; 0.91995051472240608], 1e-8); ***** test mdl = CoxModel (X, T); s = survival (mdl, X(1,:), 'Time', [5; 12; 20]); assert_equal (s, [0.51126892454645156; 9.5014819976515837e-06; ... 1.7030500478184053e-37], 1e-8); ***** test mdl = CoxModel (X, T); tq = [1; 2; 3; 31; 40]; assert_equal (survival (mdl, 'Time', tq), ... [1; 1; 1; 4.3803784471438163e-18; ... 4.3803784471438163e-18], 1e-8); assert_equal (survival (mdl, 'Time', tq, 'ExtrapolationMethod', 'none'), ... [NaN; NaN; NaN; NaN; NaN]); ***** test mdl = CoxModel (X, T); tq = [1; 2; 3; 31; 40]; s = survival (mdl, 'Time', tq, 'ExtrapolationMethod', 'previous'); assert_equal (isnan (s(1:3)), [true; true; true]); assert_equal (s(4), 4.3803784471438163e-18, 1e-8); s = survival (mdl, 'Time', tq, 'ExtrapolationMethod', 'next'); assert_equal (s(1:3), [1; 1; 1]); assert_equal (isnan (s(4:5)), [true; true]); ***** test mdl = CoxModel (X, T, 'Censoring', C, 'Stratification', S); assert_equal (mdl.Stratification, [1; 2]); assert_equal (size (mdl.Hazard), [9, 3]); assert_equal (mdl.Coefficients.Beta, ... [-0.7705046389; 3.1181961544], 1e-6); assert_equal (mdl.ProportionalHazardsPValue, ... [0.59926200661233664, 0.7801291832899343], 1e-6); ***** test mdl = CoxModel (X, T, 'Censoring', C, 'Stratification', S); s = survival (mdl); assert_equal (iscell (s), true); assert_equal (numel (s), 2); assert_equal (numel (s{1}), 5); assert_equal (numel (s{2}), 4); ***** test mdl = CoxModel (X, T, 'Censoring', C, 'Stratification', S); assert_equal (hazardratio (mdl, X(1,:), 1), 1.825643762907144, 1e-6); ***** test mdl = CoxModel (X, T); [s, t] = survival (mdl, X(1:3,:)); assert_equal (size (s), [11, 3]); assert_equal (size (t), [11, 1]); assert_equal (s(2,1), 0.6880038362205394, 1e-8); assert_equal (s(2,2), 0.62879787425614297, 1e-8); assert_equal (s(3,3), 0.78484832904143043, 1e-8); ***** test mdl = CoxModel (X, T, 'Censoring', C, 'Stratification', S); s = survival (mdl, X(1:2,:), [2; 1]); assert_equal (iscell (s), true); assert_equal (numel (s{1}), 4); assert_equal (numel (s{2}), 5); ***** test mdl = CoxModel (X, T); assert_equal (hazardratio (mdl, X(1,:), 'Baseline', [1 1]), ... 0.0031195920528550632, 1e-8); ***** test mdl = discardResiduals (CoxModel (X, T)); s = survival (mdl, X(1,:)); assert_equal (s(2), 0.6880038362205394, 1e-8); ***** test mdl = CoxModel (X, T, 'Frequency', F'); assert_equal (mdl.Coefficients.Beta, ... [-1.4447610177189139; 4.6300103378728581], 1e-6); ***** test f = figure ('visible', 'off'); unwind_protect mdl = CoxModel (X, T, 'Censoring', C, 'Stratification', S); h = plotSurvival (mdl); assert_equal (numel (h), 2); assert_equal (all (ishghandle (h)), true); unwind_protect_cleanup close (f); end_unwind_protect ***** test f = figure ('visible', 'off'); unwind_protect mdl = CoxModel (X, T); assert_equal (numel (plotSurvival (mdl)), 1); assert_equal (numel (plotSurvival (mdl, X(1:3,:))), 3); unwind_protect_cleanup close (f); end_unwind_protect ***** test mdl = CoxModel (X, T2, 'Censoring', C); assert_equal (mdl.Coefficients.Beta, [-1.0104; 3.2523], 1e-4); ***** test mdl = CoxModel (X, T, 'Frequency', F); assert_equal (mdl.Coefficients.Beta, ... [-1.4447610177189139; 4.6300103378728581], 1e-6); ***** test mdl = CoxModel (X, T, 'Beta', [0.1; -0.1]); assert_equal (mdl.Coefficients.Beta, ... [-1.3886093196382836; 4.3814437183613322], 1e-6); ***** test mdl = CoxModel (X, T, 'OptimizationOptions', statset ('fitcox')); assert_equal (mdl.LogLikelihood, -8.8069639381632356, 1e-10); ***** error CoxModel (1) ***** error CoxModel ({1}, [1; 2]) ***** error ... CoxModel (X, T, 'Censoring') ***** error ... CoxModel (X, T, 'Ties', 'efron') ***** error ... CoxModel (X, T, 'TieBreakMethod', 'exact') ***** error ... CoxModel (X, T, 'PredictorNames', {'only_one'}) ***** error ... coefci (CoxModel (X, T), 1.5) ***** error hazardratio (CoxModel (X, T)) ***** error ... survival (CoxModel (X, T), X(1,:), 'Baseline', 0) ***** error ... hazardratio (CoxModel (X, T), X(1,:), 'Time', 5) ***** error ... survival (CoxModel (X, T), 'Time', 5, 'ExtrapolationMethod', 'cubic') ***** error ... survival (CoxModel (X, T, 'Stratification', S), X(1,:)) ***** error ... CoxModel (X, T)(1) ***** error ... CoxModel (X, T).nosuch 53 tests, 53 passed, 0 known failure, 0 skipped [inst/Regression/LinearMixedModel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/LinearMixedModel.m ***** shared X, yL, grp, xL, x2, lme xL = [0.032760004 0.70410822 -0.8646718 -0.28869454 0.51276678 -1.4975462 ... -1.4527871 -0.80013541 -1.644209 1.5137701 0.72905543 0.20880758 1.0856145 ... 0.62862577 -0.87409978 1.9178276 0.09748204 0.50697633 1.0247569 ... -0.92789896 -0.88921018 -0.98322849 -0.031378913 0.86875961 -0.91481141 ... 0.034324163 -0.25025257 -1.0575644 -0.86131607 -0.35355444 0.82950729 ... -0.36874363 0.061580868 0.55803564 -0.1763803 1.0482413 1.0137831 ... -0.94876976 -0.010703972 -0.35149845 -1.6828735 -1.0493301]'; x2 = [0.68979276 0.0074354814 -0.45697437 -0.5636481 1.4567202 -0.97829955 ... -1.12922 -0.030542479 1.5847779 -0.87837755 0.24121762 0.68747601 ... -0.56728765 0.98895053 -0.39350661 0.85326015 0.36524343 0.15824977 ... -1.7665212 0.59808246 -0.55763708 -1.1982294 -2.1473319 0.22521416 ... 0.37034398 -1.880586 0.052941033 -0.70016994 0.2174853 -1.7797082 ... 0.51971317 -0.35551286 1.9845963 -1.3498848 -0.63514097 -0.78794714 ... 1.3681179 1.4423152 -0.51233905 0.30238864 2.0458136 0.17326323]'; yL = [3.5635971 -0.36763498 1.4192715 3.4471073 2.2760668 3.6420287 ... 4.4481522 1.5292777 5.437158 0.44016873 0.7259756 2.9771749 1.2941347 ... 0.26407508 1.9673466 0.77589984 1.2176078 0.8528384 -0.86522876 2.8651388 ... 2.0127931 3.1242841 -0.49164361 1.3192295 5.3782287 -0.40680701 2.3989882 ... 3.606108 1.9193197 1.6713765 2.4383124 1.9314844 3.5112706 0.91644553 ... 0.034923706 -0.15510033 2.1765206 2.5327412 3.1421219 3.3472574 5.343425 ... 3.8775899]'; grp = [1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 ... 5 6 1 2 3 4 5 6]'; X = [ones(42,1), xL, x2]; lme = fitlmematrix (X, yL, ones (42, 1), grp, "FitMethod", "REML", ... "FixedEffectPredictors", {"(Intercept)", "x", "x2"}); ***** test # returns a LinearMixedModel and basic properties assert_equal (isa (lme, "LinearMixedModel"), true); assert_equal (lme.NumObservations, 42); assert_equal (lme.NumCoefficients, 3); assert_equal (lme.DFE, 39); assert_equal (lme.FitMethod, "REML"); ***** test # Coefficients table -- SE / tStat / DF / pValue / CI vs MATLAB C = lme.Coefficients; assert_equal (C.Estimate, [1.96839; -1.37926; 0.811747], 1e-4); assert_equal (C.SE, [0.376509; 0.113264; 0.0966571], 1e-5); assert_equal (C.tStat, [5.22801; -12.1773; 8.39822], 1e-4); assert_equal (C.DF, [39; 39; 39]); assert_equal (C.pValue, [6.08512e-06; 7.30179e-15; 2.8079e-10], 1e-8); assert_equal (C.Lower, [1.20683; -1.60835; 0.61624], 1e-4); assert_equal (C.Upper, [2.72996; -1.15016; 1.00725], 1e-4); ***** test # anova with Residual DF (default): F = t^2, DF2 = n - p a = anova (lme); assert_equal (a.FStat, [27.3321; 148.287; 70.5301], 1e-3); assert_equal (a.DF1, [1; 1; 1]); assert_equal (a.DF2, [39; 39; 39]); ***** test # anova with Satterthwaite DF vs MATLAB a = anova (lme, "DFMethod", "Satterthwaite"); assert_equal (a.DF2, [4.95056; 34.5037; 34.3302], 1e-3); assert_equal (a.pValue, [0.00348739; 4.79374e-14; 7.71731e-10], 1e-6); ***** test # coefTest: joint test of the non-intercept coefficients [p, F, df1, df2] = coefTest (lme); assert_equal (F, 106.847, 1e-2); assert_equal (df1, 2); assert_equal (df2, 39); assert_equal (p < 1e-12, true); # ~1e-16, below the precision of 1 - fcdf ***** test # coefTest with an explicit single-row hypothesis (the x coefficient) [p, F, df1] = coefTest (lme, [0 1 0]); assert_equal (F, 148.287, 1e-2); assert_equal (df1, 1); ***** test # coefCI matches the Coefficients table bounds ci = coefCI (lme); assert_equal (ci(:,1), lme.Coefficients.Lower, 1e-12); assert_equal (ci(:,2), lme.Coefficients.Upper, 1e-12); ***** test # residuals: raw, Pearson (= raw/sqrt(mse)), Standardized vs MATLAB [~, mse] = covarianceParameters (lme); raw = residuals (lme); assert_equal (raw, yL - fitted (lme), 1e-12); assert_equal (residuals (lme, "ResidualType", "Pearson"), ... raw / sqrt (mse), 1e-12); rs = residuals (lme, "ResidualType", "Standardized"); assert_equal (rs(1:3), [0.1824776; -0.4452186; -2.057201], 1e-5); ***** test # fitted: conditional includes random effects, marginal does not fc = fitted (lme); fm = fitted (lme, "Conditional", false); assert_equal (fm, X * fixedEffects (lme), 1e-12); assert_equal (any (abs (fc - fm) > 1e-3, 'all'), true); ***** test # predict: conditional (unseen group falls back to marginal) + marginal Xn = [1 0.5 0; 1 -0.5 1; 1 1 -1]; yc = predict (lme, Xn, ones (3, 1), [1; 2; 7]); ym = predict (lme, Xn, ones (3, 1), [1; 2; 7], "Conditional", false); assert_equal (yc, [2.254803; 2.351467; -0.2226094], 1e-4); assert_equal (ym, [1.278766; 3.469768; -0.2226094], 1e-4); # group 7 unseen -> conditional == marginal assert_equal (yc(3), ym(3), 1e-10); ***** test # predict confidence intervals bracket the marginal mean Xn = [1 0.5 0; 1 -0.5 1]; [yp, ci] = predict (lme, Xn, ones (2, 1), [1; 2], "Conditional", false); assert_equal (all (ci(:,1) < yp & yp < ci(:,2), 'all'), true); ***** test # effect extraction and design matrices [beta, names] = fixedEffects (lme); assert_equal (beta, lme.Coefficients.Estimate, 1e-12); assert_equal (names, {"(Intercept)", "x", "x2"}); b = randomEffects (lme); assert_equal (numel (b), 6); # 6 intercept BLUPs assert_equal (b, [0.9760378; -1.118301; -0.1922078; 0.8754252; ... -0.7955462; 0.2545924], 1e-4); # BLUPs vs MATLAB assert_equal (size (designMatrix (lme, "Fixed")), [42, 3]); assert_equal (size (designMatrix (lme, "Random")), [42, 6]); assert_equal (issparse (designMatrix (lme, "Fixed")), false); assert_equal (issparse (designMatrix (lme, "Random")), true); ***** test # R-squared and sums of squares (MATLAB SST = SSE + SSR convention) assert_equal (lme.Rsquared.Ordinary, 0.8758549, 1e-6); assert_equal (lme.Rsquared.Adjusted, 0.8694885, 1e-6); assert_equal (lme.SST, lme.SSE + lme.SSR, 1e-10); assert_equal (lme.ModelCriterion.Deviance, -2 * lme.LogLikelihood, 1e-10); ***** test ## Below the resolution of 1 - tcdf, value from MATLAB R2024a x = (1:30)'; g = repmat ((1:5)', 6, 1); T = table (x, g, 2 * x + g + 0.01 * sin (x), ... 'VariableNames', {'x', 'g', 'y'}); m = fitlme (T, 'y ~ x + (1|g)'); assert_equal (m.Coefficients.pValue(2), 1.12646802753448e-95, -1e-3); ***** test ## Below the resolution of 1 - fcdf, values from MATLAB R2024a u = (1:30)'; g = repmat ((1:5)', 6, 1); T = table (u, g, 2 * u + g + 0.01 * sin (u), ... 'VariableNames', {'x', 'g', 'y'}); m = fitlme (T, 'y ~ x + (1|g)'); assert_equal (coefTest (m), 1.12646802753448e-95, -1e-3); ***** test u = (1:30)'; g = repmat ((1:5)', 6, 1); T = table (u, g, 2 * u + g + 0.01 * sin (u), ... 'VariableNames', {'x', 'g', 'y'}); A = anova (fitlme (T, 'y ~ x + (1|g)')); assert_equal (A.pValue(2), 1.12646802753448e-95, -1e-3); ***** error residuals (lme, "ResidualType", "xxx") ***** error anova (lme, "DFMethod", "xxx") ***** error designMatrix (lme, "bogus") ***** error coefTest (lme, [1 0]) ***** error lme(1) 21 tests, 21 passed, 0 known failure, 0 skipped [inst/Regression/nlinfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/nlinfit.m ***** demo ## Fit an exponential growth model y = b1 * exp (b2 * x). x = [1:10]'; y = [2.1;2.9;4.2;5.3;7.1;9.4;12.8;16.5;22.1;29.8]; modelfun = @(b, x) b(1) .* exp (b(2) .* x); beta = nlinfit (x, y, modelfun, [1; 0.3]) ***** demo ## Robust fitting downweights a gross outlier (5th point corrupted). x = [1:10]'; y = [2.1;2.9;4.2;5.3;7.1;9.4;12.8;16.5;22.1;29.8]; y(5) = 30; modelfun = @(b, x) b(1) .* exp (b(2) .* x); beta_ols = nlinfit (x, y, modelfun, [1; 0.3]); beta_rob = nlinfit (x, y, modelfun, [1; 0.3], 'RobustWgtFun', 'bisquare'); [beta_ols, beta_rob] ***** shared x, y, modelfun, beta0 x = [1;2;3;4;5;6;7;8;9;10]; y = [2.1;2.9;4.2;5.3;7.1;9.4;12.8;16.5;22.1;29.8]; modelfun = @(b, x) b(1) .* exp (b(2) .* x); beta0 = [1; 0.3]; ***** test [beta, R, J, CovB, MSE] = nlinfit (x, y, modelfun, beta0); assert_equal (beta, [1.683747024946374; 0.286911087203926], 1e-6); assert_equal (MSE, 0.029221494299720, 1e-9); assert_equal (sqrt (diag (CovB)), ... [0.035194898750254; 0.002350913062791], 1e-6); ***** test ## The returned Jacobian equals the analytic model Jacobian. [beta, R, J] = nlinfit (x, y, modelfun, beta0); Ja = [exp(beta(2).*x), beta(1).*x.*exp(beta(2).*x)]; assert_equal (J, Ja, -1e-4); ***** test ## Proportional error model reweights by 1 / mu^2 and changes the fit. [beta, R, J, CovB, MSE, EMI] = nlinfit (x, y, modelfun, beta0, ... "ErrorModel", "proportional"); assert_equal (beta, [1.650639591; 0.289917266], 1e-6); assert_equal (MSE, 9.988359e-4, 1e-9); assert_equal (EMI.ErrorModel, "proportional"); assert_equal (EMI.ScheffeSimPred, 2); ***** test ## Constant error model: ErrorModelInfo fields. [beta, R, J, CovB, MSE, EMI] = nlinfit (x, y, modelfun, beta0); assert_equal (EMI.ErrorModel, "constant"); assert_equal (EMI.ScheffeSimPred, 3); assert_equal (EMI.ErrorParameters, 0.170942956, 1e-7); ***** test ## Observation weights. w = (1:10)'; [beta, R, J, CovB, MSE] = nlinfit (x, y, modelfun, beta0, "Weights", w); assert_equal (beta, [1.677485713; 0.287323059], 1e-6); assert_equal (MSE, 0.178838470, 1e-6); ***** test ## Robust fitting resists a gross outlier: the estimate stays close to the ## clean-data fit, far closer than ordinary least squares. Coefficients, ## MSE, and covariance match MATLAB's nlinfit (Street-Carroll-Ruppert scale). yo = y; yo(5) = 30; [br, Rr, Jr, Cr, Mr] = nlinfit (x, yo, modelfun, beta0, ... "RobustWgtFun", "bisquare"); bo = nlinfit (x, yo, modelfun, beta0); bc = nlinfit (x, y, modelfun, beta0); assert_equal (max (abs (br - bc)) < max (abs (bo - bc)), true); assert_equal (br, [1.679154218; 0.287198922], 1e-5); assert_equal (Mr, 15.892255, 1e-2); assert_equal (Cr, [0.671544, -0.044220; -0.044220, 0.003012], 1e-3); ***** test ## The huber robust fit also matches MATLAB's coefficients. yo = y; yo(5) = 30; bh = nlinfit (x, yo, modelfun, beta0, "RobustWgtFun", "huber"); assert_equal (bh, [1.716586997; 0.284865506], 1e-5); ***** error nlinfit (1, 2, @(b, x) x) ***** error nlinfit (1, 2, 3, 4) ***** error ... nlinfit ([1;2], [1;2], @(b, x) b(1) * ones (2, 1), "a") ***** error ... nlinfit ([1;2], [1;2], @(b, x) b(1) * ones (2, 1), 1, "foo", 1) ***** error ... nlinfit ([1;2], [1;2], @(b, x) b(1) * ones (2, 1), 1, "ErrorModel", "bad") ***** test x = (1:10)'; y = [2.1; 3.9; 6.2; 7.8; 10.1; 12.2; 13.8; 16.1; 18.0; 100.0]; modelfun = @(b, xx) b(1) + b(2) * xx; bols = nlinfit (x, y, modelfun, [0; 1]); bdef = nlinfit (x, y, modelfun, [0; 1], statset ("nlinfit")); boff = nlinfit (x, y, modelfun, [0; 1], statset (statset ("nlinfit"), ... "Robust", "off", ... "WgtFun", "huber")); assert_equal (bols, [-15.959999998553135; 6.359999999774407], 1e-8); assert_equal (bdef, bols, 1e-12); assert_equal (boff, bols, 1e-12); ***** test x = (1:10)'; y = [2.1; 3.9; 6.2; 7.8; 10.1; 12.2; 13.8; 16.1; 18.0; 100.0]; modelfun = @(b, xx) b(1) + b(2) * xx; opts = statset ("nlinfit"); bon = nlinfit (x, y, modelfun, [0; 1], statset (opts, "Robust", "on")); bhub = nlinfit (x, y, modelfun, [0; 1], statset (opts, "Robust", "on", ... "WgtFun", "huber")); bboth = nlinfit (x, y, modelfun, [0; 1], statset (opts, "Robust", "on", ... "WgtFun", "bisquare", ... "RobustWgtFun", "huber")); assert_equal (bon, [0.040259809225918; 1.996768212418451], 1e-7); assert_equal (bhub, [-0.032803877294096; 2.016488145372473], 1e-7); assert_equal (bboth, bhub, 1e-12); ***** error ... nlinfit ([1;2;3;4], {1, 2}, @(b, x) b(1) * x, 1) ***** error ... nlinfit ([1;2;3;4], [2;4;6;8], @(b, x) b(1) * x, 1, "RobustWgtFun", 5) ***** error ... nlinfit ([1;2;3;4], [2;4;6;8], @(b, x) b(1) * x, 1, "Weights", {1, 2, 3, 4}) ***** error ... nlinfit ([1;2;3;4], [2;4;6;8], @(b, x) b(1) * x, 1, "Weights", [1; 2]) ***** error ... nlinfit ([1;2;3;4], [2;4;6;8], @(b, x) b(1) * x, 1, "Weights", [1; -1; 1; 1]) ***** error ... nlinfit ([1;2;3;4], [2;4;6;8], @(b, x) b(1) * x, 1, ... "Weights", [1; NaN; 1; 1]) ***** error ... nlinfit ([1;2;3;4], [2;4;6;8], @(b, x) b(1) * x, 1, "Weights") ***** error ... nlinfit ([1;2;3;4], [2;4;6;8], @(b, x) b(1) * x, 1, 42, 1) ***** error ... nlinfit ([1;2;3;4], [2;4;6;8], @(b, x) b(1) * x, 1, ... struct ("MaxIter", {10, 20})) ***** error ... nlinfit (ones (4, 2), ones (2, 2), @(b, x) b(1) * x, 1) ***** error ... nlinfit ([], zeros (0, 1), @(b, x) b(1) .* x, [1]) ***** error ... nlinfit (zeros (0, 3), zeros (0, 1), @(b, x) b(1) .* x, [1]) ***** error ... nlinfit ([1;2], [1;2], @(b, x) b(1) * ones (2, 1), 1, "RobustWgtFun", "bad") 27 tests, 27 passed, 0 known failure, 0 skipped [inst/Regression/stepwisefit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/stepwisefit.m ***** test X = [7 26 6 60; 1 29 15 52; 11 56 8 20; 11 31 8 47; 7 52 6 33; 11 55 9 22; 3 71 17 6; 1 31 22 44; 2 54 18 22; 21 47 4 26; 1 40 23 34; 11 66 9 12; 10 68 8 12]; y = [78.5; 74.3; 104.3; 87.6; 95.9; 109.2; 102.7; 72.5; 93.1; 115.9; 83.8; 113.3; 109.4]; [b,se,pval,finalmodel,stats] = stepwisefit (X,y); assert_equal (finalmodel, [true false false true]); assert_equal (b, [1.4400; 0.4161; -0.4100; -0.6140], 1e-4); assert_equal (se, [0.1384; 0.1856; 0.1992; 0.0486], 1e-4); assert_equal (pval, [0; 0.0517; 0.0697; 0], 1e-4); assert_equal (stats.rmse, 2.7343, 1e-4); assert_equal (stats.SStotal, 2715.7631, 1e-3); assert_equal (stats.SSresid, 74.7621, 1e-4); assert_equal (stats.df0, 2); assert_equal (stats.dfe, 10); assert_equal (stats.intercept, 103.0974, 1e-4); ***** test X = [ 12.0 4 120 95 2600; 11.5 6 200 110 3000; 10.5 8 300 150 3600; 13.0 4 140 100 2800; 12.5 6 180 120 3200; 11.0 8 250 140 3500; 14.0 4 130 98 2700; 13.5 6 210 115 3100; 12.2 8 320 160 3800; 11.8 4 150 105 2900 ]; y = [28; 22; 18; 27; 23; 19; 29; 21; 17; 26]; [b,se,pval,finalmodel,stats] = stepwisefit (X,y); assert_equal (islogical (finalmodel), true); assert_equal (numel (finalmodel) == 5, true); assert_equal (sum (finalmodel) >= 1, true); assert_equal (isnumeric (b), true); assert_equal (isnumeric (se), true); assert_equal (isnumeric (pval), true); assert_equal (stats.rmse > 0, true); assert_equal (isfinite (stats.intercept), true); ***** test X = randn (30, 4); y = randn (30, 1); [~,~,~,~,stats] = stepwisefit (X, y); required_fields = { 'source', 'df0', 'dfe', 'SStotal', 'SSresid', 'fstat', 'pval', ... 'rmse', 'xr', 'yr', 'B', 'SE', 'TSTAT', 'PVAL', 'covb', ... 'intercept', 'wasnan' }; for k = 1:numel (required_fields) assert_equal (isfield (stats, required_fields{k}), true); endfor ***** test X = randn (40, 5); y = randn (40, 1); [b,se,pval,finalmodel,stats] = stepwisefit (X, y); p = columns (X); n = rows (X(! stats.wasnan, :)); assert_equal (size (stats.yr), [n, 1]); assert_equal (rows (stats.B) == p, true); assert_equal (rows (stats.SE) == p, true); assert_equal (rows (stats.TSTAT) == p, true); assert_equal (rows (stats.PVAL) == p, true); assert_equal (size (stats.covb), [p+1, p+1]); ***** test X = randn (25, 3); y = randn (25, 1); [~,~,~,~,stats] = stepwisefit (X, y); SSresid_calc = sum (stats.yr .^ 2); assert_equal (SSresid_calc, stats.SSresid, 1e-10); rmse_calc = sqrt (stats.SSresid / stats.dfe); assert_equal (rmse_calc, stats.rmse, 1e-10); ***** test X = randn (50, 6); y = randn (50, 1); [~,~,~,~,stats] = stepwisefit (X, y); if (stats.df0 > 0) F_calc = ((stats.SStotal - stats.SSresid) / stats.df0) ... / (stats.SSresid / stats.dfe); assert_equal (F_calc, stats.fstat, 1e-10); assert_equal (stats.pval >= 0 && stats.pval <= 1, true); else assert_equal (isnan (stats.fstat), true); assert_equal (isnan (stats.pval), true); endif ***** test X = randn (35, 4); y = randn (35, 1); [~,~,~,finalmodel,stats] = stepwisefit (X, y); p = columns (X); k = sum (finalmodel); assert_equal (size (stats.xr, 2) == p - k, true); assert_equal (all (isfinite (stats.xr(:))), true); ***** test X = randn (35, 4); y = randn (35, 1); [~,~,~,finalmodel,stats] = stepwisefit (X, y); Xc = X(! stats.wasnan, :); Xfinal = [ones(rows (Xc),1), Xc(:, finalmodel)]; for j = 1:columns (stats.xr) ortho = Xfinal' * stats.xr(:,j); assert_equal (max (abs (ortho(:))) < 1e-6, true); endfor ***** test X = randn (40, 5); y = randn (40, 1); [~,~,~,finalmodel,stats,nextstep,history] = stepwisefit (X, y); assert_equal (nextstep == 0, true); assert_equal (isstruct (history), true); assert_equal (isfield (history, 'in'), true); assert_equal (isfield (history, 'df0'), true); assert_equal (isfield (history, 'rmse'), true); assert_equal (isfield (history, 'B'), true); assert_equal (isequal (history.in, finalmodel), true); assert_equal (history.df0 == stats.df0, true); assert_equal (history.rmse == stats.rmse, true); assert_equal (rows (history.B) == columns (X), true); ***** test X = randn (20,4); y = randn (20,1); stepwisefit (X,y,'Keep',[true false true false]); ***** test X = randn (30, 4); y = randn (30, 1); keep = [true false false false]; [~,~,~,finalmodel] = stepwisefit (X, y, 'Keep', keep); assert_equal (finalmodel(1) == true, true); ***** test X = randn (40, 6); y = randn (40, 1); [~,~,~,finalmodel] = stepwisefit (X, y, 'MaxIter', 1); assert_equal (islogical (finalmodel), true); ***** test X = randn (50, 5); y = randn (50, 1); [b1] = stepwisefit (X, y); [b2] = stepwisefit (X, y, 'Scale', 'on'); assert_equal (rows (b1) == rows (b2), true); ***** test [b,se,pval,finalmodel,stats,nextstep,history] = ... stepwisefit (zeros (0, 3), zeros (0, 1), 'Display', 'off'); assert_equal (b, NaN (3, 1)); assert_equal (se, NaN (3, 1)); assert_equal (pval, NaN (3, 1)); assert_equal (finalmodel, false (1, 3)); assert_equal (nextstep, 0); assert_equal (stats.df0, -1); assert_equal (stats.dfe, 0); assert_equal (stats.intercept, 0); assert_equal (stats.covb, NaN (3, 3)); assert_equal (stats.xr, zeros (0, 3)); assert_equal (stats.wasnan, false (0, 1)); assert_equal (history.in, false (0, 3)); assert_equal (history.df0, []); assert_equal (history.rmse, []); assert_equal (history.B, zeros (3, 0)); ***** test X = [1 2; 2 1; 3 5; 4 3; 5 6; 6 4; 7 8; 8 7]; y = [1.2 2.1 3.9 4.2 5.8 6.1 8.2 7.9]; assert_equal (stepwisefit (X, y, 'Display', 'off'), ... stepwisefit (X, y', 'Display', 'off')); ***** test ## Below the resolution of 1 - tcdf, value from MATLAB R2024a x1 = (1:30)'; x2 = x1 + 0.1 * sin (1:30)'; [~, ~, pval] = stepwisefit ([x1, x2], x2 + 0.001 * cos (1:30)', ... 'Display', 'off'); assert_equal (pval(2), 3.00226579216343e-116, -1e-9); ***** test ## Below the resolution of 1 - fcdf, values from MATLAB R2024a u = (1:30)'; u2 = u + 0.1 * sin (u); [~, ~, ~, ~, st] = stepwisefit ([u, u2], u2 + 0.001 * cos (u), ... 'Display', 'off'); assert_equal (st.pval, 3.0022657921636e-116, -1e-9); ***** error ... stepwisefit (randn (20,4), randn (20,1), 'Keep', [true false]) ***** error ... stepwisefit () ***** error ... stepwisefit (ones (2,2,2), [1;2]) ***** error ... stepwisefit ([], [], 'Display', 'off') ***** error ... stepwisefit (ones (4,2), ones (4,2), 'Display', 'off') ***** error ... stepwisefit (ones (3,2), ones (2,1)) ***** error ... stepwisefit (randn (10,2), randn (10,1), 'UnknownOpt', 5) ***** error ... stepwisefit (randn (10,2), randn (10,1), 'Display', 'maybe') ***** error ... stepwisefit (randn (10,2), randn (10,1), 'Scale', 123) ***** error ... stepwisefit (randn (10,2), randn (10,1), 'PEnter', -0.1) ***** error ... stepwisefit (randn (10,2), randn (10,1), 'PRemove', 1.5) ***** error ... stepwisefit (randn (10,2), randn (10,1), ... 'PEnter', 0.05, 'PRemove', 0.01) ***** error ... stepwisefit (randn (10,2), randn (10,1), 'MaxIter', -2) ***** error ... stepwisefit (randn (10,2), randn (10,1), 'MaxIter', 2.5) ***** error ... stepwisefit (randn (10,2), randn (10,1), 'Keep', [1 0]) ***** error ... stepwisefit (randn (10,2), randn (10,1), 'InModel', [1 0]) ***** error ... stepwisefit (randn (10,4), randn (10,1), 'Keep', [true false]) ***** error ... stepwisefit (zeros (0, 3), zeros (0, 1), 'Keep', [true false]) ***** error ... stepwisefit (randn (10,4), randn (10,1), 'InModel', true) 36 tests, 36 passed, 0 known failure, 0 skipped [inst/Regression/mnrfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/mnrfit.m ***** test # nominal MLE reproduces the observed category totals X = [-2; -1; 0; 1; 2; -2; -1; 0; 1; 2; -1.5; 1.5]; Y = [1; 2; 3; 1; 2; 3; 1; 2; 3; 1; 2; 3]; [B, dev, stats] = mnrfit (X, Y, 'model', 'nominal'); assert_equal (size (B), [2, 2]); P = mnrval (B, X); assert_equal (sum (P, 2), ones (12, 1), 1e-10); assert_equal (sum (P, 1), [sum(Y == 1), sum(Y == 2), sum(Y == 3)], 1e-6); ***** test # binary nominal agrees with the ordinal cumulative-logit fit X = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10]; Y = [1; 1; 1; 1; 2; 1; 2; 2; 2; 2]; assert_equal (mnrfit (X, Y, 'model', 'nominal'), ... mnrfit (X, Y, 'model', 'ordinal'), 1e-5); ***** test # hierarchical fit yields valid probabilities through mnrval X = [-2; -1; 0; 1; 2; -2; -1; 0; 1; 2; -1.5; 1.5]; Y = [1; 2; 3; 1; 2; 3; 1; 2; 3; 1; 2; 3]; [B, dev, stats] = mnrfit (X, Y, 'model', 'hierarchical'); assert_equal (size (B), [2, 2]); P = mnrval (B, X, 'model', 'hierarchical'); assert_equal (sum (P, 2), ones (12, 1), 1e-10); assert_equal (all (P(:) >= 0 & P(:) <= 1), true); ***** test # first hierarchical stage is the binary logit of category 1 vs. rest X = [-2; -1; 0; 1; 2; -2; -1; 0; 1; 2; -1.5; 1.5]; Y = [1; 2; 3; 1; 2; 3; 1; 2; 3; 1; 2; 3]; Bh = mnrfit (X, Y, 'model', 'hierarchical'); Bb = mnrfit (X, 2 - double (Y == 1), 'model', 'nominal'); assert_equal (Bh(:,1), Bb, 1e-8); ***** test # non-logit ordinal fits round-trip through mnrval with valid probs X = [-2; -1; 0; 1; 2; -1.5; 0.5; 1.2; -0.7; 0.3; -0.4; 0.8]; Y = [1; 1; 2; 2; 3; 1; 2; 3; 3; 2; 1; 3]; for lk = {'probit', 'comploglog', 'loglog'} B = mnrfit (X, Y, 'model', 'ordinal', 'link', lk{1}); P = mnrval (B, X, 'model', 'ordinal', 'link', lk{1}); assert_equal (sum (P, 2), ones (12, 1), 1e-9); assert_equal (all (P(:) >= -1e-12 & P(:) <= 1 + 1e-12), true); endfor ***** test # non-logit hierarchical fit runs and round-trips through mnrval X = [-2; -1; 0; 1; 2; -1.5; 0.5; 1.2; -0.7; 0.3; -0.4; 0.8]; Y = [1; 1; 2; 2; 3; 1; 2; 3; 3; 2; 1; 3]; B = mnrfit (X, Y, 'model', 'hierarchical', 'link', 'probit'); P = mnrval (B, X, 'model', 'hierarchical', 'link', 'probit'); assert_equal (sum (P, 2), ones (12, 1), 1e-9); ***** test # residuals have the right shape and are internally consistent X = [-2; -1; 0; 1; 2; -2; -1; 0; 1; 2; -1.5; 1.5]; Y = [1; 2; 3; 1; 2; 3; 1; 2; 3; 1; 2; 3]; [B, dev, stats] = mnrfit (X, Y, 'model', 'nominal'); assert_equal (size (stats.resid), [12, 3]); assert_equal (size (stats.residp), [12, 3]); assert_equal (size (stats.residd), [12, 1]); assert_equal (sum (stats.resid, 2), zeros (12, 1), 1e-10); assert_equal (sum (stats.residd), dev, 1e-8); ***** test # dispersion estimate sfit = sqrt (Pearson X2 / dfe) matches MATLAB X = [-2; -1; 0; 1; 2; -2; -1; 0; 1; 2; -1.5; 1.5]; Y = [1; 2; 3; 1; 2; 3; 1; 2; 3; 1; 2; 3]; [~, ~, sn] = mnrfit (X, Y, 'model', 'nominal'); assert_equal (sn.sfit, 1.0954, 1e-3); [~, ~, so] = mnrfit (X, Y, 'model', 'ordinal'); assert_equal (so.sfit, 1.0691, 1e-3); ***** test # EstDisp on scales se/covb by the dispersion and uses t-based p-values X = [-2; -1; 0; 1; 2; -2; -1; 0; 1; 2; -1.5; 1.5]; Y = [1; 2; 3; 1; 2; 3; 1; 2; 3; 1; 2; 3]; [~, ~, s0] = mnrfit (X, Y, 'model', 'nominal'); [~, ~, s1] = mnrfit (X, Y, 'model', 'nominal', 'estdisp', 'on'); assert_equal (s0.s, 1); assert_equal (s1.s, s1.sfit); assert_equal (s1.se, s0.se * s1.sfit, 1e-12); assert_equal (s1.covb, s0.covb * s1.sfit ^ 2, 1e-10); assert_equal (s1.p, 2 * tcdf (- abs (s1.t), s1.dfe), 1e-12); ***** error mnrfit (ones (50,1)) ***** error ... mnrfit ({1 ;2 ;3 ;4 ;5}, ones (5,1)) ***** error ... mnrfit (ones (50, 4, 2), ones (50, 1)) ***** error ... mnrfit (ones (50, 4), ones (50, 1, 3)) ***** error ... mnrfit (ones (50, 4), ones (45,1)) ***** error ... mnrfit (ones (5, 4), {1 ;2 ;3 ;4 ;5}) ***** error ... mnrfit (ones (5, 4), ones (5, 1), 'model') ***** error ... mnrfit (ones (5, 4), {'q','q';'w','w';'q','q';'w','w';'q','q'}) ***** error ... mnrfit (ones (5, 4), [1, 2; 1, 2; 1, 2; 1, 2; 1, 2]) ***** error ... mnrfit (ones (5, 4), [1; -1; 1; 2; 1]) ***** error ... mnrfit (ones (5, 4), [1; 2; 3; 2; 1], 'model', 'whatever') ***** error ... mnrfit (ones (5, 4), [1; 2; 1; 2; 1], 'link', 'cauchit') ***** error ... mnrfit (ones (5, 4), [1; 2; 1; 2; 1], 'model', 'nominal', 'link', 'probit') ***** error ... mnrfit (ones (5, 4), [1; 2; 1; 2; 1], 'estdisp', 'maybe') ***** error ... mnrfit ([], []) ***** error ... mnrfit (zeros (0, 3), zeros (0, 1)) 25 tests, 25 passed, 0 known failure, 0 skipped [inst/Regression/glmfit.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/glmfit.m ***** demo x = [210, 230, 250, 270, 290, 310, 330, 350, 370, 390, 410, 430]'; n = [48, 42, 31, 34, 31, 21, 23, 23, 21, 16, 17, 21]'; y = [1, 2, 0, 3, 8, 8, 14, 17, 19, 15, 17, 21]'; b = glmfit (x, [y n], 'binomial', 'Link', 'probit'); yfit = glmval (b, x, 'probit', 'Size', n); plot (x, y./n, 'o', x, yfit ./ n, '-') ***** demo load fisheriris X = meas (51:end, :); y = strcmp ('versicolor', species(51:end)); b = glmfit (X, y, 'binomial', 'link', 'logit') ***** test load fisheriris; X = meas(51:end,:); y = strcmp ('versicolor', species(51:end)); b = glmfit (X, y, 'binomial', 'link', 'logit'); assert_equal (b, [42.6379; 2.4652; 6.6809; -9.4294; -18.2861], 1e-4); ***** test load fisheriris; X = meas(51:end,:); y = strcmp ('versicolor', species(51:end)); [b, dev, stats] = glmfit (X, y, 'binomial', 'link', 'logit'); assert_equal (b, [42.6379; 2.4652; 6.6809; -9.4294; -18.2861], 1e-4); assert_equal (numel (stats.se), numel (b)); ***** test ## For an estimated-dispersion family the coefficient covariance is scaled by ## the dispersion (not its square), so the standard errors match ordinary ## least squares for the identity-link normal case. X = [1, 2; 2, 1; 3, 4; 4, 3; 5, 6; 6, 5]; y = [2.1; 1.9; 4.2; 3.8; 6.1; 5.9]; [b, dev, stats] = glmfit (X, y, 'normal'); Xd = [ones(6, 1), X]; mse = sum ((y - Xd * b) .^ 2) / (6 - 3); se_ols = sqrt (mse * diag (inv (Xd' * Xd))); assert_equal (stats.se, se_ols, 1e-12); ***** test X = [1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, 10.1]'; y = [0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4]'; [Bnew, dev] = glmfit (X, y, 'gamma', 'link', 'log'); b_matlab = [-0.7631; 0.1113]; dev_matlab = 0.0111; assert_equal (Bnew, b_matlab, 0.001); assert_equal (dev, dev_matlab, 0.001); ***** test X = [1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, 10.1]'; y = [0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4]'; p_input = 1; [Bnew, dev] = glmfit (X, y, 'inverse gaussian', 'link', p_input); b_matlab = [0.3813; 0.0950]; dev_matlab = 0.0051; assert_equal (Bnew, b_matlab, 0.001); assert_equal (dev, dev_matlab, 0.001); ***** test ## a rank deficient design drops the redundant column: zero coefficient and ## standard error, NaN test statistics, and the rest as the reduced fit x = [1.2; 2.3; 3.4; 4.5; 5.6; 6.7; 7.8; 8.9; 9.0; 10.1]; y = [0.5; 0.6; 0.7; 0.8; 0.9; 1.0; 1.1; 1.2; 1.3; 1.4]; status = warning; warning ('off'); [b, dev, stats] = glmfit ([x, x], y, 'normal'); warning (status); [br, devr, statsr] = glmfit (x, y, 'normal'); assert_equal (b, [br; 0], -1e-12); assert_equal (dev, devr, -1e-12); assert_equal (stats.se, [statsr.se; 0], -1e-12); assert_equal (stats.t, [statsr.t; NaN], -1e-12); assert_equal (stats.p, [statsr.p; NaN], -1e-12); ***** test ## A step leaving the domain of the power link is halved back; MATLAB ## R2024a stops there at a deviance of 2.20639741059281 and computes ## 1.93529703471832 at the coefficients below u = (1:30)'; [~, dev] = glmfit (u, exp (0.1 * u) .* (1 + 0.2 * sin (u)), ... 'inverse gaussian'); assert_equal (dev, 1.93529703471832, -1e-10); ***** test u = (1:30)'; b = glmfit (u, exp (0.1 * u) .* (1 + 0.2 * sin (u)), 'inverse gaussian'); assert_equal (b, [0.1324742958; -0.004405637293], -1e-8); ***** error glmfit () ***** error glmfit (1) ***** error glmfit (1, 2) ***** error ... glmfit (rand (6, 1), rand (6, 1), 'poisson', 'link') ***** error ... glmfit ('abc', rand (6, 1), 'poisson') ***** error ... glmfit ([], rand (6, 1), 'poisson') ***** error ... glmfit (rand (5, 2), 'abc', 'poisson') ***** error ... glmfit (rand (5, 2), [], 'poisson') ***** error ... glmfit (rand (5, 2), rand (6, 1), 'poisson') ***** error ... glmfit (rand (6, 2), rand (6, 1), 3) ***** error ... glmfit (rand (6, 2), rand (6, 1), {'poisson'}) ***** error ... glmfit (rand (5, 2), rand (5, 3), 'binomial') ***** error ... glmfit (rand (2, 2), [true, true; false, false], 'binomial') ***** error ... glmfit (rand (5, 2), rand (5, 2), 'normal') ***** error ... glmfit (rand (5, 2), rand (5, 1), 'chebychev') ***** error ... glmfit (rand (5, 2), rand (5, 1), 'normal', 'B0', [1; 2; 3; 4]) ***** error ... glmfit (rand (5, 2), rand (5, 1), 'normal', 'constant', 1) ***** error ... glmfit (rand (5, 2), rand (5, 1), 'normal', 'constant', 'o') ***** error ... glmfit (rand (5, 2), rand (5, 1), 'normal', 'constant', true) ***** error ... glmfit (rand (5, 2), rand (5, 1), 'normal', 'estdisp', 1) ***** error ... glmfit (rand (5, 2), rand (5, 1), 'normal', 'estdisp', 'o') ***** error ... glmfit (rand (5, 2), rand (5, 1), 'normal', 'estdisp', true) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', struct ('Link', {1, 2})) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', struct ('Link', 'norminv')) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', struct ('Link', 'some', 'Derivative', @(x)x, 'Inverse', 'normcdf')) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', struct ('Link', 1, 'Derivative', @(x)x, 'Inverse', 'normcdf')) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', struct ('Link', @(x) [x, x], 'Derivative', @(x)x, 'Inverse', 'normcdf')) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', struct ('Link', 'what', 'Derivative', @(x)x, 'Inverse', 'normcdf')) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', struct ('Link', @(x)x, 'Derivative', 'some', 'Inverse', 'normcdf')) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', struct ('Link', @(x)x, 'Derivative', 1, 'Inverse', 'normcdf')) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', struct ('Link', @(x)x, 'Derivative', @(x) [x, x], 'Inverse', 'normcdf')) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', struct ('Link', @(x)x, 'Derivative', 'what', 'Inverse', 'normcdf')) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', struct ('Link', @(x)x, 'Derivative', 'normcdf', 'Inverse', 'some')) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', struct ('Link', @(x)x, 'Derivative', 'normcdf', 'Inverse', 1)) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', struct ('Link', @(x)x, 'Derivative', 'normcdf', 'Inverse', @(x) [x, x])) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', struct ('Link', @(x)x, 'Derivative', 'normcdf', 'Inverse', 'what')) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', {'log'}) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', {'log', 'hijy'}) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', {1, 2, 3, 4}) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', {'log', 'dfv', 'dfgvd'}) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', {@(x) [x, x], 'dfv', 'dfgvd'}) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', {@(x) what (x), 'dfv', 'dfgvd'}) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', {@(x) x, 'dfv', 'dfgvd'}) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', {@(x) x, @(x) [x, x], 'dfgvd'}) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', {@(x) x, @(x) what (x), 'dfgvd'}) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', {@(x) x, @(x) x, 'dfgvd'}) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', {@(x) x, @(x) x, @(x) [x, x]}) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', {@(x) x, @(x) x, @(x) what (x)}) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', NaN) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', [1, 2]) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', [1i]) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', ['log'; 'log1']) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', 'somelinkfunction') ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'link', true) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'options', true) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'options', struct ('MaxIter', 100)) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'options', struct ('MaxIter', 4.5, 'TolX', 1e-6)) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'options', struct ('MaxIter', 0, 'TolX', 1e-6)) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'options', struct ('MaxIter', -100, 'TolX', 1e-6)) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'options', struct ('MaxIter', [50 ,50], 'TolX', 1e-6)) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'options', struct ('MaxIter', 100, 'TolX', 0)) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'options', struct ('MaxIter', 100, 'TolX', -1e-6)) ***** error ... glmfit (rand (5,2), rand (5,1), 'poisson', 'options', struct ('MaxIter', 100, 'TolX', [1e-6, 1e-6])) ***** error ... glmfit (rand (5, 2), rand (5, 1), 'normal', 'offset', [1; 2; 3; 4]) ***** error ... glmfit (rand (5, 2), rand (5, 1), 'normal', 'offset', 'asdfg') ***** error ... glmfit (rand (5, 2), rand (5, 1), 'normal', 'weights', [1; 2; 3; 4]) ***** error ... glmfit (rand (5, 2), rand (5, 1), 'normal', 'weights', 'asdfg') 75 tests, 75 passed, 0 known failure, 0 skipped [inst/Regression/mnrval.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/mnrval.m ***** demo ## Fit an ordinal model and predict the category probabilities X = [1; 2; 3; 4; 5; 6; 7; 8]; Y = [1; 1; 1; 2; 2; 2; 3; 3]; B = mnrfit (X, Y, 'model', 'ordinal'); pihat = mnrval (B, X, 'model', 'ordinal') ***** test X = [1.489381332449196, 1.1534152241851305; ... 1.8110085304863965, 0.9449666896938425; ... -0.04453299665130296, 0.34278203449678646; ... -0.36616019468850347, 1.130254275908322; ... 0.15339143291005095, -0.7921044310668951; ... -1.6031878794469698, -1.8343471035233376; ... -0.14349521143198166, -0.6762996896828459; ... -0.4403818557740143, -0.7921044310668951; ... -0.7372685001160434, -0.027793137932169563; ... -0.11875465773681024, 0.5512305689880763]; Y = [1;1;1;1;1;0;0;0;0;0]; B = mnrfit (X, Y + 1, 'model', 'ordinal'); [~, ~, ~, ~, ~, Pref] = logistic_regression (Y, X, false); assert_equal (mnrval (B, X, 'model', 'ordinal'), Pref, 1e-10); ***** test X = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10]; Y = [1; 1; 1; 1; 1; 2; 2; 2; 2; 2]; B = mnrfit (X, Y, 'model', 'ordinal'); p_nom = mnrval (B, X); p_ord = mnrval (B, X, 'model', 'ordinal'); assert_equal (p_nom, p_ord, 1e-12); ***** test X = randn (20, 2); Bnom = [0.5, -0.2; 1.0, 0.3; -0.4, 0.1]; # (P+1)-by-(K-1), K = 3 assert_equal (sum (mnrval (Bnom, X), 2), ones (20, 1), 1e-12); assert_equal (sum (mnrval (Bnom, X, 'model', 'hierarchical'), 2), ... ones (20, 1), 1e-12); Bord = [-1; 1; 0.5; -0.3]; # (K-1+P)-by-1, K = 3, P = 2 assert_equal (sum (mnrval (Bord, X, 'model', 'ordinal'), 2), ... ones (20, 1), 1e-12); ***** test X = randn (15, 2); Bord = [-1; 0.8; 0.5; -0.3]; p = mnrval (Bord, X, 'model', 'ordinal'); assert_equal (all (p(:) >= 0 & p(:) <= 1), true); ***** test X = randn (12, 2); Bord = [-0.5; 1.2; 0.4; -0.2]; pc = mnrval (Bord, X, 'model', 'ordinal', 'type', 'category'); cu = mnrval (Bord, X, 'model', 'ordinal', 'type', 'cumulative'); assert_equal (cu, cumsum (pc(:,1:end-1), 2), 1e-12); ***** test X = randn (10, 2); Bord = [-0.5; 1.0; 0.4; -0.2]; p = mnrval (Bord, X, 'model', 'ordinal'); y = mnrval (Bord, X, 100, 'model', 'ordinal'); assert_equal (y, p * 100, 1e-10); ***** test X = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10]; Y = [1; 1; 1; 1; 1; 2; 2; 2; 2; 2]; [B, ~, stats] = mnrfit (X, Y, 'model', 'ordinal'); [p, dlo, dhi] = mnrval (B, X, stats, 'model', 'ordinal'); assert_equal (size (dlo), size (p)); assert_equal (size (dhi), size (p)); assert_equal (all (dlo(:) >= 0) && all (dhi(:) >= 0), true); ***** test X = randn (10, 1); Bord = [-0.5; 0.7; 0.4]; for lnk = {'logit', 'probit', 'comploglog', 'loglog'} p = mnrval (Bord, X, 'model', 'ordinal', 'link', lnk{1}); assert_equal (sum (p, 2), ones (10, 1), 1e-10); endfor ***** test X = randn (10, 1); Bord = [-0.5; 0.7; 0.4]; for lnk = {'logit', 'probit', 'comploglog'} p = mnrval (Bord, X, 'model', 'ordinal', 'link', lnk{1}); assert_equal (all (p(:) >= 0 & p(:) <= 1), true); endfor ***** test X = randn (10, 1); Bll = [1.0; -0.5; 0.4]; p = mnrval (Bll, X, 'model', 'ordinal', 'link', 'loglog'); assert_equal (sum (p, 2), ones (10, 1), 1e-10); assert_equal (all (p(:) >= 0 & p(:) <= 1), true); ***** error mnrval (1) ***** error mnrval ({1}, ones (3, 1)) ***** error ... mnrval ([1; 1], ones (3, 3, 3)) ***** error ... mnrval ([1; 1], ones (3, 1), 'model') ***** error ... mnrval ([1; 1], ones (3, 1), 'foo', 'bar') ***** error ... mnrval ([1; 1], ones (3, 1), 'model', 'whatever') ***** error ... mnrval ([1; 1], ones (3, 1), 'interactions', 'maybe') ***** error ... mnrval ([1; 1], ones (3, 1), 'model', 'ordinal', 'link', 'foo') ***** error ... mnrval ([1; 1], ones (3, 1), 'link', 'probit') ***** error ... mnrval ([1; 1], ones (3, 1), 'type', 'foo') ***** error ... mnrval ([1; 1], ones (3, 1), 'confidence', 2) ***** error ... mnrval ([1; 1; 1], ones (3, 1)) ***** error ... [p, dlo] = mnrval ([1; 1], ones (3, 1)); ***** error ... [p, dlo] = mnrval ([1; 1], ones (3, 1), struct ('x', 1)); 24 tests, 24 passed, 0 known failure, 0 skipped [inst/Regression/glmval.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/glmval.m ***** demo x = [210, 230, 250, 270, 290, 310, 330, 350, 370, 390, 410, 430]'; n = [48, 42, 31, 34, 31, 21, 23, 23, 21, 16, 17, 21]'; y = [1, 2, 0, 3, 8, 8, 14, 17, 19, 15, 17, 21]'; b = glmfit (x, [y n], 'binomial', 'Link', 'probit'); yfit = glmval (b, x, 'probit', 'Size', n); plot (x, y./n, 'o', x, yfit ./ n, '-') ***** error glmval () ***** error glmval (1) ***** error glmval (1, 2) ***** error ... glmval ('asd', [1; 1; 1], 'probit') ***** error ... glmval ([], [1; 1; 1], 'probit') ***** error ... glmval ([0.1; 0.3; 0.4], [], 'probit') ***** error ... glmval ([0.1; 0.3; 0.4], 'asd', 'probit') ***** error ... glmval (rand (3,1), rand (5,2), struct ('Link', {1, 2})) ***** error ... glmval (rand (3,1), rand (5,2), struct ('Link', 'norminv')) ***** error ... glmval (rand (3,1), rand (5,2), struct ('Link', 'some', 'Derivative', @(x)x, 'Inverse', 'normcdf')) ***** error ... glmval (rand (3,1), rand (5,2), struct ('Link', 1, 'Derivative', @(x)x, 'Inverse', 'normcdf')) ***** error ... glmval (rand (3,1), rand (5,2), struct ('Link', @(x) [x, x], 'Derivative', @(x)x, 'Inverse', 'normcdf')) ***** error ... glmval (rand (3,1), rand (5,2), struct ('Link', 'what', 'Derivative', @(x)x, 'Inverse', 'normcdf')) ***** error ... glmval (rand (3,1), rand (5,2), struct ('Link', @(x)x, 'Derivative', 'some', 'Inverse', 'normcdf')) ***** error ... glmval (rand (3,1), rand (5,2), struct ('Link', @(x)x, 'Derivative', 1, 'Inverse', 'normcdf')) ***** error ... glmval (rand (3,1), rand (5,2), struct ('Link', @(x)x, 'Derivative', @(x) [x, x], 'Inverse', 'normcdf')) ***** error ... glmval (rand (3,1), rand (5,2), struct ('Link', @(x)x, 'Derivative', 'what', 'Inverse', 'normcdf')) ***** error ... glmval (rand (3,1), rand (5,2), struct ('Link', @(x)x, 'Derivative', 'normcdf', 'Inverse', 'some')) ***** error ... glmval (rand (3,1), rand (5,2), struct ('Link', @(x)x, 'Derivative', 'normcdf', 'Inverse', 1)) ***** error ... glmval (rand (3,1), rand (5,2), struct ('Link', @(x)x, 'Derivative', 'normcdf', 'Inverse', @(x) [x, x])) ***** error ... glmval (rand (3,1), rand (5,2), struct ('Link', @(x)x, 'Derivative', 'normcdf', 'Inverse', 'what')) ***** error ... glmval (rand (3,1), rand (5,2), {'log'}) ***** error ... glmval (rand (3,1), rand (5,2), {'log', 'hijy'}) ***** error ... glmval (rand (3,1), rand (5,2), {1, 2, 3, 4}) ***** error ... glmval (rand (3,1), rand (5,2), {'log', 'dfv', 'dfgvd'}) ***** error ... glmval (rand (3,1), rand (5,2), {@(x) [x, x], 'dfv', 'dfgvd'}) ***** error ... glmval (rand (3,1), rand (5,2), {@(x) what (x), 'dfv', 'dfgvd'}) ***** error ... glmval (rand (3,1), rand (5,2), {@(x) x, 'dfv', 'dfgvd'}) ***** error ... glmval (rand (3,1), rand (5,2), {@(x) x, @(x) [x, x], 'dfgvd'}) ***** error ... glmval (rand (3,1), rand (5,2), {@(x) x, @(x) what (x), 'dfgvd'}) ***** error ... glmval (rand (3,1), rand (5,2), {@(x) x, @(x) x, 'dfgvd'}) ***** error ... glmval (rand (3,1), rand (5,2), {@(x) x, @(x) x, @(x) [x, x]}) ***** error ... glmval (rand (3,1), rand (5,2), {@(x) x, @(x) x, @(x) what (x)}) ***** error ... glmval (rand (3,1), rand (5,2), NaN) ***** error ... glmval (rand (3,1), rand (5,2), [1, 2]) ***** error ... glmval (rand (3,1), rand (5,2), [1i]) ***** error ... glmval (rand (3,1), rand (5,2), ['log'; 'log1']) ***** error ... glmval (rand (3,1), rand (5,2), 'somelinkfunction') ***** error ... glmval (rand (3,1), rand (5,2), true) ***** error ... glmval (rand (3,1), rand (5,2), 'probit', struct ('s', 1)) ***** error ... glmval (rand (3,1), rand (5,2), 'probit', 'confidence') ***** error ... glmval (rand (3,1), rand (5,2), 'probit', 'confidence', 0) ***** error ... glmval (rand (3,1), rand (5,2), 'probit', 'confidence', 1.2) ***** error ... glmval (rand (3,1), rand (5,2), 'probit', 'confidence', [0.9, 0.95]) ***** error ... glmval (rand (3, 1), rand (5, 2), 'probit', 'constant', 1) ***** error ... glmval (rand (3, 1), rand (5, 2), 'probit', 'constant', 'o') ***** error ... glmval (rand (3, 1), rand (5, 2), 'probit', 'constant', true) ***** error ... glmval (rand (3, 1), rand (5, 2), 'probit', 'offset', [1; 2; 3; 4]) ***** error ... glmval (rand (3, 1), rand (5, 2), 'probit', 'offset', 'asdfg') ***** test # numeric 0/1 are accepted for 'simultaneous' (MATLAB compatibility) b = [0.2; 0.5]; X = [1; 2; 3]; assert_equal (numel (glmval (b, X, 'logit', 'simultaneous', 0)), 3); assert_equal (numel (glmval (b, X, 'logit', 'simultaneous', 1)), 3); ***** test # 'BinomialSize' is accepted as an alias for 'size' b = [0.2; 0.5; -0.3]; X = [0.1 0.2; 0.3 0.4; 0.5 0.6; 0.7 0.8]; assert_equal (glmval (b, X, 'logit', 'BinomialSize', 10), ... glmval (b, X, 'logit', 'size', 10)); ***** test # CI: fixed-dispersion uses the normal quantile; rows are independent X = [1 2; 2 1; 3 3; 4 2; 5 4; 6 5]; y = [1; 0; 2; 3; 2; 4]; [b, dev, stats] = glmfit (X, y, 'poisson'); Xnew = [2 2; 4 3]; [yh, ylo, yhi] = glmval (b, Xnew, 'log', stats); Xd = [ones(2, 1), Xnew]; se_eta = sqrt (sum ((Xd * stats.covb) .* Xd, 2)); eta = Xd * b; z = norminv (0.975); lo = exp (eta) - exp (eta - z * se_eta); hi = exp (eta + z * se_eta) - exp (eta); assert_equal (ylo, lo, 1e-10); assert_equal (yhi, hi, 1e-10); [~, l1, h1] = glmval (b, Xnew(1,:), 'log', stats); assert_equal ([ylo(1); yhi(1)], [l1; h1], 1e-12); ***** error ... glmval (rand (3, 1), rand (5, 2), 'probit', 'simultaneous', 'asdfg') ***** error ... glmval (rand (3, 1), rand (5, 2), 'probit', 'simultaneous', [true, false]) ***** error ... glmval (rand (3, 1), rand (5, 2), 'probit', 'size', 'asd') ***** error ... glmval (rand (3, 1), rand (5, 2), 'probit', 'size', [2, 3, 4]) ***** error ... glmval (rand (3, 1), rand (5, 2), 'probit', 'size', [2; 3; 4]) ***** error ... glmval (rand (3, 1), rand (5, 2), 'probit', 'size', ones (3)) ***** error ... glmval (rand (3, 1), rand (5, 2), 'probit', 'someparam', 4) ***** error ... [y,lo,hi] = glmval (rand (3, 1), rand (5, 2), 'probit') 60 tests, 60 passed, 0 known failure, 0 skipped [inst/Regression/NonLinearModel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/NonLinearModel.m ***** demo ## Fit an exponential growth model y = b1 * exp (b2 * x) and inspect it. x = (1:10)'; y = [2.1; 2.9; 4.2; 5.3; 7.1; 9.4; 12.8; 16.5; 22.1; 29.8]; modelfun = @(b, x) b(1) .* exp (b(2) .* x); mdl = fitnlm (x, y, modelfun, [1; 0.3]); disp (mdl.Coefficients) printf ("RMSE = %g, R^2 = %g\n", mdl.RMSE, mdl.Rsquared.Ordinary); ***** shared X, y, modelfun, beta0 X = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10]; y = [2.1; 2.9; 4.2; 5.3; 7.1; 9.4; 12.8; 16.5; 22.1; 29.8]; modelfun = @(b, x) b(1) .* exp (b(2) .* x); beta0 = [1; 0.3]; ***** test # coefficient table (estimate, SE, tStat) verified against MATLAB mdl = fitnlm (X, y, modelfun, beta0); assert_equal (mdl.Coefficients.Estimate, [1.683747025; 0.286911087], 1e-6); assert_equal (mdl.Coefficients.SE, [0.035194899; 0.002350913], 1e-6); assert_equal (mdl.Coefficients.tStat, [47.8406555; 122.042406], -1e-4); assert_equal (mdl.Coefficients.tStat, ... mdl.Coefficients.Estimate ./ mdl.Coefficients.SE, 1e-8); ***** test # sums of squares and their internal relationships mdl = fitnlm (X, y, modelfun, beta0); bhat = mdl.Coefficients.Estimate; fit = modelfun (bhat, X); assert_equal (mdl.Fitted, fit, 1e-8); assert_equal (mdl.SSE, sum ((y - fit) .^ 2), 1e-8); assert_equal (mdl.SST, sum ((y - mean (y)) .^ 2), 1e-6); assert_equal (mdl.SSR, sum ((fit - mean (y)) .^ 2), 1e-6); assert_equal (mdl.SSE, 0.233771954, 1e-7); assert_equal (mdl.SST, 750.976, 1e-3); ***** test # MSE/RMSE/DFE and the coefficient of determination mdl = fitnlm (X, y, modelfun, beta0); assert_equal (mdl.DFE, 8); assert_equal (mdl.MSE, mdl.SSE / mdl.DFE, 1e-12); assert_equal (mdl.RMSE, sqrt (mdl.MSE), 1e-12); assert_equal (mdl.RMSE, 0.170942956, 1e-7); assert_equal (mdl.Rsquared.Ordinary, 1 - mdl.SSE / mdl.SST, 1e-12); assert_equal (mdl.Rsquared.Ordinary, 0.999688709, 1e-8); assert_equal (mdl.Rsquared.Adjusted, 0.999649798, 1e-8); ***** test # log-likelihood and information criteria (values and identities) mdl = fitnlm (X, y, modelfun, beta0); ll = mdl.LogLikelihood; k = mdl.NumEstimatedCoefficients; n = 10; assert_equal (ll, 4.590586096, 1e-6); assert_equal (mdl.ModelCriterion.AIC, -5.181172193, 1e-6); assert_equal (mdl.ModelCriterion.BIC, -4.576002007, 1e-6); assert_equal (mdl.ModelCriterion.AIC, -2 * ll + 2 * k, 1e-9); assert_equal (mdl.ModelCriterion.BIC, -2 * ll + k * log (n), 1e-9); assert_equal (mdl.ModelCriterion.AICc, ... -2 * ll + 2 * k + 2 * k * (k + 1) / (n - k - 1), 1e-9); ***** test # count/size properties and default names mdl = fitnlm (X, y, modelfun, beta0); assert_equal (mdl.NumCoefficients, 2); assert_equal (mdl.NumEstimatedCoefficients, 2); assert_equal (mdl.NumPredictors, 1); assert_equal (mdl.NumObservations, 10); assert_equal (mdl.CoefficientNames, {'b1', 'b2'}); assert_equal (mdl.ResponseName, "y"); ***** test # the coefficient covariance is symmetric with SE^2 on the diagonal mdl = fitnlm (X, y, modelfun, beta0); C = mdl.CoefficientCovariance; assert_equal (size (C), [2, 2]); assert_equal (C, C', 1e-14); assert_equal (diag (C), mdl.Coefficients.SE .^ 2, 1e-12); ***** test # raw residuals are response minus fit mdl = fitnlm (X, y, modelfun, beta0); assert_equal (class (mdl.Residuals), "table"); assert_equal (mdl.Residuals.Raw, y - mdl.Fitted, 1e-10); ***** test # predict returns fitted values (verified against MATLAB) with CIs mdl = fitnlm (X, y, modelfun, beta0); [yhat, yci] = predict (mdl, [2.5; 5.5; 8.5]); assert_equal (yhat, [3.449741842; 8.158274281; 19.293455074], 1e-6); assert_equal (yci(:,1), [3.329126146; 7.997938483; 19.121921613], 1e-5); assert_equal (yci(:,2), [3.570357538; 8.318610079; 19.464988535], 1e-5); assert_equal (all (yci(:,1) <= yhat & yhat <= yci(:,2)), true); ***** test # predict at the training data reproduces the fitted response mdl = fitnlm (X, y, modelfun, beta0); assert_equal (predict (mdl, X), mdl.Fitted, 1e-8); ***** test # feval agrees with predict; random draws match the response size mdl = fitnlm (X, y, modelfun, beta0); assert_equal (feval (mdl, [2.5; 5.5]), predict (mdl, [2.5; 5.5]), 1e-12); ysim = random (mdl); assert_equal (size (ysim), [10, 1]); ***** test # coefCI matches beta +/- t * SE and honours a custom alpha mdl = fitnlm (X, y, modelfun, beta0); b = mdl.Coefficients.Estimate; se = mdl.Coefficients.SE; t95 = tinv (0.975, mdl.DFE); assert_equal (coefCI (mdl), [b - t95 * se, b + t95 * se], 1e-12); t90 = tinv (0.95, mdl.DFE); assert_equal (coefCI (mdl, 0.10), [b - t90 * se, b + t90 * se], 1e-12); ***** test # coefTest reports a Wald F statistic versus the zero model mdl = fitnlm (X, y, modelfun, beta0); [p, F, df] = coefTest (mdl); assert_equal (df, 2); assert_equal (F > 1e5, true); assert_equal (p < 1e-10, true); ***** test # table input gives the same fit as matrix input tbl = table (X, y, "VariableNames", {'x', 'y'}); mdl = fitnlm (tbl, modelfun, beta0); assert_equal (mdl.Coefficients.Estimate, [1.683747025; 0.286911087], 1e-6); assert_equal (mdl.CoefficientNames, {'b1', 'b2'}); ***** test # custom coefficient names are stored and used mdl = fitnlm (X, y, modelfun, beta0, "CoefficientNames", {'A', 'k'}); assert_equal (mdl.CoefficientNames, {'A', 'k'}); ***** test # disp prints the model header and the coefficient table mdl = fitnlm (X, y, modelfun, beta0); s = evalc ("disp (mdl)"); assert_equal (isempty (strfind (s, "Nonlinear regression model")), false); assert_equal (isempty (strfind (s, "Estimate")), false); ***** test # chained subsref reaches property -> table column -> element mdl = fitnlm (X, y, modelfun, beta0); assert_equal (numel (mdl.Coefficients.Estimate), 2); assert_equal (mdl.Coefficients.Estimate(1), 1.683747025, 1e-6); ***** test # the residual and slice plots run without error mdl = fitnlm (X, y, modelfun, beta0); hf = figure ("visible", "off"); unwind_protect plotResiduals (mdl); plotResiduals (mdl, "fitted"); plotDiagnostics (mdl); plotSlice (mdl); unwind_protect_cleanup close (hf); end_unwind_protect ***** test ## Below the resolution of 1 - fcdf u = (1:30)'; m = fitnlm (u, 2 * u + 0.01 * sin (u), @(b, t) b(1) + b(2) * t, [1, 1]); [p, F, df] = coefTest (m); d2 = m.DFE; assert_equal (p, betainc (d2 / (d2 + df * F), d2 / 2, df / 2), -1e-12); ***** error NonLinearModel (1) ***** error ... NonLinearModel ([1; 2], [1; 2], "bad", [1]) ***** error ... mdl = fitnlm ([1;2;3;4], [1;2;3;4], @(b, x) b(1) * x, 1); mdl(1); 21 tests, 21 passed, 0 known failure, 0 skipped [inst/Regression/mvregress.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/mvregress.m ***** demo ## Two correlated responses regressed on a common predictor. rng (42); X = [ones(30,1), (1:30)'/30]; B = [1 -1; 2 0.5]; E = [0.3 0.1; 0.1 0.2]; Y = X * B + randn (30, 2) * chol (E); [beta, Sigma] = mvregress (X, Y) ***** shared X, Ycomp, Ymiss, Btrue X = [ones(12,1), linspace(-1, 1, 12)']; Btrue = [1 -0.5 2; 0.3 1.2 -0.8]; Ycomp = X * Btrue + 0.05 * cos ((1:12)' * [1 2 3]); Ymiss = Ycomp; Ymiss(3,2) = NaN; Ymiss(8,3) = NaN; ***** test # numeric design returns a p-by-d beta equal to OLS (complete data) [beta, Sigma, E] = mvregress (X, Ycomp, "algorithm", "mvn"); assert_equal (size (beta), [2, 3]); assert_equal (beta, (X'*X)\(X'*Ycomp), 1e-8); assert_equal (Sigma, E'*E/12, 1e-8); ***** test # cell design returns the vectorised (K-by-1) beta Xc = cell (12, 1); for i = 1:12, Xc{i} = kron (eye (3), X(i,:)); end bnum = mvregress (X, Ycomp); bcell = mvregress (Xc, Ycomp); assert_equal (bcell, bnum(:), 1e-8); ***** test # logL equals -mvregresslike at the fit (mvn, complete) [beta, Sigma, E, CovB, logL] = mvregress (X, Ycomp, "algorithm", "mvn"); assert_equal (logL, -mvregresslike (X, Ycomp, beta, Sigma, "mvn"), 1e-8); assert_equal (CovB, kron (Sigma, inv (X'*X)), 1e-8); ***** test # ecm uses all observed data; the log-likelihood improves on listwise b_ecm = mvregress (X, Ymiss, "algorithm", "ecm"); b_mvn = mvregress (X, Ymiss, "algorithm", "mvn"); assert_equal (! isequal (b_ecm, b_mvn), true); # different estimates ***** test # default algorithm: mvn without missing data, ecm with [b1, ~, ~, ~, L1] = mvregress (X, Ycomp); [b2, ~, ~, ~, L2] = mvregress (X, Ycomp, "algorithm", "mvn"); assert_equal (L1, L2, 1e-10); ***** test # cwls: logL and CovB use the identity weight [beta, Sigma, E, CovB, logL] = mvregress (X, Ycomp, "algorithm", "cwls"); assert_equal (logL, -mvregresslike (X, Ycomp, beta, eye (3), "cwls"), 1e-8); assert_equal (CovB, kron (eye (3), inv (X'*X)), 1e-8); ***** shared Xc, Yc, Ym Xc = [1 -0.5382438937; ... 1 0.8672321576; ... 1 0.9759864635; ... 1 0.3373902524; ... 1 -0.9960940966; ... 1 -0.5232140317; ... 1 -1.297447477; ... 1 0.9173885891; ... 1 0.1766016286; ... 1 0.7551799357; ... 1 -0.5914999598; ... 1 1.844389637; ... 1 1.816922249; ... 1 -0.1238333503; ... 1 -1.110601355; ... 1 -0.6809058803; ... 1 0.0141693264; ... 1 -0.05955061046; ... 1 -0.6610110145; ... 1 0.3059509151; ... 1 -0.4090578458; ... 1 -1.281854823; ... 1 -0.2849028295; ... 1 -0.06478685589; ... 1 1.000383189]; Yc = [0.03719753357 -1.298719829 2.592641544; ... -0.8732979121 0.2860080857 0.07019509407; ... 0.9664790872 2.93781363 2.07467313; ... 1.928227972 0.000735060807 1.023278991; ... 1.099525737 -1.790260694 1.621821039; ... 0.8212389245 -1.973919957 3.698786362; ... 0.1466274959 -1.562219847 2.319552949; ... 1.316125907 0.7610511082 0.9228417259; ... 3.19879516 1.119205548 3.035118373; ... 3.324100363 1.40533639 2.521210797; ... -0.5492763312 -2.535610011 -0.009321693727; ... 0.7506317092 1.042220218 -0.1580843947; ... 2.65978063 1.200673839 0.1312316546; ... 1.060827996 -1.429695245 2.854978118; ... 0.3193218045 -0.6292560647 3.238543733; ... 0.08284787504 -0.7632940769 3.223147972; ... 1.943818586 -2.359810723 2.132345279; ... -1.007337725 0.4325819195 1.790333779; ... 0.5483627737 -2.463255725 2.103406495; ... 0.4463418718 0.4193706852 1.806900862; ... 2.151700093 -0.6796218054 0.2488978108; ... 1.601013282 -0.7661239912 3.004258316; ... 1.51658466 -0.6677671869 2.37476419; ... 0.8655905179 -1.911105684 1.609121594; ... -1.036725518 0.3884447934 0.2753353942]; Ym = [0.03719753357 -1.298719829 2.592641544; ... -0.8732979121 NaN 0.07019509407; ... 0.9664790872 2.93781363 2.07467313; ... 1.928227972 0.000735060807 1.023278991; ... 1.099525737 -1.790260694 NaN; ... 0.8212389245 -1.973919957 3.698786362; ... 0.1466274959 NaN 2.319552949; ... 1.316125907 0.7610511082 0.9228417259; ... 3.19879516 1.119205548 3.035118373; ... 3.324100363 1.40533639 2.521210797; ... -0.5492763312 -2.535610011 -0.009321693727; ... 0.7506317092 1.042220218 -0.1580843947; ... 2.65978063 1.200673839 0.1312316546; ... 1.060827996 NaN 2.854978118; ... 0.3193218045 -0.6292560647 3.238543733; ... 0.08284787504 -0.7632940769 3.223147972; ... 1.943818586 -2.359810723 2.132345279; ... -1.007337725 0.4325819195 1.790333779; ... 0.5483627737 -2.463255725 NaN; ... 0.4463418718 0.4193706852 1.806900862; ... 2.151700093 -0.6796218054 0.2488978108; ... 1.601013282 -0.7661239912 3.004258316; ... 1.51658466 -0.6677671869 2.37476419; ... 0.8655905179 -1.911105684 1.609121594; ... -1.036725518 0.3884447934 0.2753353942]; ***** test # complete data: beta (=OLS), Sigma (ML), logL, CovB vs MATLAB [beta, Sigma, ~, CovB, logL] = mvregress (Xc, Yc, "algorithm", "mvn"); assert_equal (beta, [0.9290602475, -0.4513207572, 1.79229326; ... 0.2367436851, 1.147222011, -0.7755015141], 1e-6); assert_equal (Sigma, [1.332860184, 0.1860841493, 0.3727350368; ... 0.1860841493, 0.9491200208, 0.328607071; ... 0.3727350368, 0.328607071, 0.8648578221], 1e-6); assert_equal (logL, -104.1503454, 1e-5); assert_equal (CovB, kron (Sigma, inv (Xc'*Xc)), 1e-8); ***** test # cwls reports the log-likelihood under the identity weight [~, ~, ~, ~, logL] = mvregress (Xc, Yc, "algorithm", "cwls"); assert_equal (logL, -108.2558653, 1e-5); ***** test # missing data, ecm (uses every observed response) vs MATLAB [beta, Sigma, ~, ~, logL] = mvregress (Xc, Ym, "algorithm", "ecm"); assert_equal (beta, [0.9290602475, -0.4380875727, 1.82736137; ... 0.2367436851, 1.173891485, -0.825576035], 1e-5); assert_equal (Sigma, [1.332860184, 0.2265958964, 0.3918376495; ... 0.2265958964, 1.034602545, 0.4028401374; ... 0.3918376495, 0.4028401374, 0.8842430898], 1e-5); assert_equal (logL, -98.2574859, 1e-5); ***** test # missing data, mvn (listwise deletion) vs MATLAB [beta, ~, ~, ~, logL] = mvregress (Xc, Ym, "algorithm", "mvn"); assert_equal (beta, [1.025969216, -0.3367657906, 1.885558095; ... 0.3142894292, 1.09915421, -0.8366732999], 1e-5); assert_equal (logL, -85.21502995, 1e-5); ***** test # missing data, cwls logL under identity weight vs MATLAB [~, ~, ~, ~, logL] = mvregress (Xc, Ym, "algorithm", "cwls"); assert_equal (logL, -102.6628017, 1e-5); ***** error mvregress (1) ***** error mvregress (ones (3), {1}) ***** error mvregress (ones (2, 2), ones (3, 2)) ***** error ... mvregress ([], []) ***** error ... mvregress (zeros (0, 3), zeros (0, 1)) ***** error mvregress (ones (3, 2), ones (3, 2), "algorithm", "xxx") ***** error mvregress (ones (3, 2), ones (3, 2), "bogus", 1) 18 tests, 18 passed, 0 known failure, 0 skipped [inst/Regression/fitlm.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/fitlm.m ***** demo ## The simplest call: a matrix of predictor data and a response vector. ## Ten students study for varying numbers of hours before an exam, with ## their resulting scores recorded. With no `modelspec`, `fitlm` fits an ## intercept plus one linear term per column of the predictor matrix. Hours = [1;2;3;4;5;6;7;8;9;10]; Score = [52;55;61;64;70;73;77;81;85;90]; mdl = fitlm (Hours, Score) ***** demo ## Table input with a Wilkinson formula, and a categorical predictor ## detected automatically from its cell-array type. ## Nine stores in three regions report ad spend and sales. `Region` is ## a cell array of strings, so it is expanded into indicator columns ## without needing `'CategoricalVars'` to say so explicitly. AdSpend = [10;20;30;15;25;35;12;22;32]; Region = {'North';'North';'North';'South';'South';'South'; ... 'East';'East';'East'}; Sales = [15;18;24;20;27;33;12;19;26]; T = table (AdSpend, Region, Sales, ... 'VariableNames', {'AdSpend','Region','Sales'}); mdl = fitlm (T, 'Sales ~ AdSpend + Region') ***** demo ## A terms matrix used directly as modelspec, instead of a keyword or a ## formula string. ## Weekly sales depend on temperature and humidity. Each row of the ## terms matrix is one term, and each column is the exponent of one ## predictor in that term -- here, both main effects plus their ## interaction. Temp = [60;65;70;75;80;85;90]; Humidity = [30;35;40;45;50;55;60]; Sales = [200;230;260;300;340;370;410]; T_terms = [0 0; 1 0; 0 1; 1 1]; mdl = fitlm ([Temp, Humidity], Sales, T_terms) ***** demo ## Observation weights and an excluded observation used together. ## Ten observations follow a roughly linear trend, except one clear ## outlier. `'Exclude'` leaves that observation out of the fit ## entirely, while `'Weights'` gives the remaining observations ## unequal influence on the fit. x = [1;2;3;4;5;6;7;8;9;10]; y = [10;13;15;40;22;25;29;33;35;39]; w = [1;1;2;1;2;1;2;1;2;1]; mdl = fitlm (x, y, 'Weights', w, 'Exclude', 4) ***** demo ## Robust regression versus an ordinary fit, on data with a planted ## outlier. ## Twelve observations follow a linear trend with a small amount of ## noise, except one observation shifted far off the line. The ## ordinary fit is pulled toward the outlier; the robust fit, using ## iteratively reweighted least squares with the bisquare weighting ## function, downweights it instead. x = (1:12)'; y = 3 + 2*x + 0.5*sin (x); y(10) = y(10) + 30; mdl_ols = fitlm (x, y) mdl_robust = fitlm (x, y, 'RobustOpts', 'bisquare') ***** demo ## Selecting specific predictors and a specific response by name from a ## larger table, using the `carsmall` data set. ## `'ResponseVar'` and `'PredictorVars'` pick out exactly which ## columns of the table to use, regardless of how many other variables ## the table also contains. load carsmall T = table (Weight, Acceleration, MPG); mdl = fitlm (T, 'ResponseVar', 'MPG', ... 'PredictorVars', {'Weight', 'Acceleration'}) ***** demo y = [ 8.706 10.362 11.552 6.941 10.983 10.092 6.421 14.943 15.931 ... 22.968 18.590 16.567 15.944 21.637 14.492 17.965 18.851 22.891 ... 22.028 16.884 17.252 18.325 25.435 19.141 21.238 22.196 18.038 ... 22.628 31.163 26.053 24.419 32.145 28.966 30.207 29.142 33.212 ... 25.694 ]'; X = [1 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5]'; mdl = fitlm (X, y, 'linear', 'CategoricalVars', 1) ***** demo popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; brands = {'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'}; popper = {'oil', 'oil', 'oil'; 'oil', 'oil', 'oil'; 'oil', 'oil', 'oil'; ... 'air', 'air', 'air'; 'air', 'air', 'air'; 'air', 'air', 'air'}; T = table (brands(:), popper(:), 'VariableNames', {'brands', 'popper'}); mdl = fitlm (T, popcorn(:), 'interactions') ***** test y = [ 8.706 10.362 11.552 6.941 10.983 10.092 6.421 14.943 15.931 ... 22.968 18.590 16.567 15.944 21.637 14.492 17.965 18.851 22.891 ... 22.028 16.884 17.252 18.325 25.435 19.141 21.238 22.196 18.038 ... 22.628 31.163 26.053 24.419 32.145 28.966 30.207 29.142 33.212 ... 25.694 ]'; X = [1 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5]'; fitlm (X, y, 'CategoricalVars', 1); fitlm (X, y, 'constant', 'CategoricalVars', 1); fitlm (X, y, 'linear', 'CategoricalVars', 1); mdl = fitlm (X, y, 'linear', 'CategoricalVars', 1); assert_equal (mdl.Coefficients.Estimate(1), 10, 1e-04); assert_equal (mdl.Coefficients.Estimate(2), 7.99999999999999, 1e-09); assert_equal (mdl.Coefficients.Estimate(3), 8.99999999999999, 1e-09); assert_equal (mdl.Coefficients.Estimate(4), 11.0001428571429, 1e-09); assert_equal (mdl.Coefficients.Estimate(5), 19.0001111111111, 1e-09); assert_equal (mdl.Coefficients.SE(1), 1.01775379540949, 1e-09); assert_equal (mdl.Coefficients.SE(2), 1.64107868458008, 1e-09); assert_equal (mdl.Coefficients.SE(3), 1.43932122062479, 1e-09); assert_equal (mdl.Coefficients.SE(4), 1.48983900477565, 1e-09); assert_equal (mdl.Coefficients.SE(5), 1.3987687997822, 1e-09); assert_equal (mdl.Coefficients.tStat(1), 9.82555903510687, 1e-09); assert_equal (mdl.Coefficients.tStat(2), 4.87484242844031, 1e-09); assert_equal (mdl.Coefficients.tStat(3), 6.25294748040552, 1e-09); assert_equal (mdl.Coefficients.tStat(4), 7.38344399756088, 1e-09); assert_equal (mdl.Coefficients.tStat(5), 13.5834536158296, 1e-09); assert_equal (mdl.Coefficients.pValue(2), 2.85812420217862e-05, 1e-12); assert_equal (mdl.Coefficients.pValue(3), 5.22936741204002e-07, 1e-06); assert_equal (mdl.Coefficients.pValue(4), 2.12794763209106e-08, 1e-07); assert_equal (mdl.Coefficients.pValue(5), 7.82091664406755e-15, 1e-08); ***** test popcorn = [5.5, 4.5, 3.5; 5.5, 4.5, 4.0; 6.0, 4.0, 3.0; ... 6.5, 5.0, 4.0; 7.0, 5.5, 5.0; 7.0, 5.0, 4.5]; brands = bsxfun (@times, ones (6, 1), [1, 2, 3]); popper = bsxfun (@times, [1; 1; 1; 2; 2; 2], ones (1, 3)); X = [brands(:), popper(:)]; mdl = fitlm (X, popcorn(:), 'interactions', 'CategoricalVars', [1, 2]); assert_equal (mdl.Coefficients.Estimate(1), 5.66666666666667, 1e-09); assert_equal (mdl.Coefficients.Estimate(2), -1.33333333333333, 1e-09); assert_equal (mdl.Coefficients.Estimate(3), -2.16666666666667, 1e-09); assert_equal (mdl.Coefficients.Estimate(4), 1.16666666666667, 1e-09); assert_equal (mdl.Coefficients.Estimate(6), -0.333333333333334, 1e-09); assert_equal (mdl.Coefficients.Estimate(7), -0.166666666666667, 1e-09); assert_equal (mdl.Coefficients.SE(1), 0.215165741455965, 1e-09); assert_equal (mdl.Coefficients.SE(2), 0.304290309725089, 1e-09); assert_equal (mdl.Coefficients.SE(3), 0.304290309725089, 1e-09); assert_equal (mdl.Coefficients.SE(4), 0.304290309725089, 1e-09); assert_equal (mdl.Coefficients.SE(6), 0.43033148291193, 1e-09); assert_equal (mdl.Coefficients.SE(7), 0.43033148291193, 1e-09); assert_equal (mdl.Coefficients.tStat(1), 26.3362867542108, 1e-09); assert_equal (mdl.Coefficients.tStat(2), -4.38178046004138, 1e-09); assert_equal (mdl.Coefficients.tStat(3), -7.12039324756724, 1e-09); assert_equal (mdl.Coefficients.tStat(4), 3.83405790253621, 1e-09); assert_equal (mdl.Coefficients.tStat(6), -0.774596669241495, 1e-09); assert_equal (mdl.Coefficients.tStat(7), -0.387298334620748, 1e-09); assert_equal (mdl.Coefficients.pValue(1), 5.49841502258254e-12, 1e-09); assert_equal (mdl.Coefficients.pValue(2), 0.000893505495903642, 1e-09); assert_equal (mdl.Coefficients.pValue(3), 1.21291454302428e-05, 1e-09); assert_equal (mdl.Coefficients.pValue(4), 0.00237798044119407, 1e-09); assert_equal (mdl.Coefficients.pValue(6), 0.453570536021938, 1e-09); assert_equal (mdl.Coefficients.pValue(7), 0.705316781644046, 1e-09); brands = {'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'; ... 'Gourmet', 'National', 'Generic'}; popper = {'oil', 'oil', 'oil'; 'oil', 'oil', 'oil'; 'oil', 'oil', 'oil'; ... 'air', 'air', 'air'; 'air', 'air', 'air'; 'air', 'air', 'air'}; T = table (brands(:), popper(:), 'VariableNames', {'brands', 'popper'}); mdl = fitlm (T, popcorn(:), 'interactions'); ***** test load carsmall X = [Weight, Horsepower, Acceleration]; fitlm (X, MPG, 'constant'); mdl = fitlm (X, MPG, 'linear'); assert_equal (mdl.Coefficients.Estimate(1), 47.9767628118615, 1e-09); assert_equal (mdl.Coefficients.Estimate(2), -0.00654155878851796, 1e-09); assert_equal (mdl.Coefficients.Estimate(3), -0.0429433065881864, 1e-09); assert_equal (mdl.Coefficients.Estimate(4), -0.0115826516894871, 1e-09); assert_equal (mdl.Coefficients.SE(1), 3.87851641748551, 1e-09); assert_equal (mdl.Coefficients.SE(2), 0.00112741016370336, 1e-09); assert_equal (mdl.Coefficients.SE(3), 0.0243130608813806, 1e-09); assert_equal (mdl.Coefficients.SE(4), 0.193325043113178, 1e-09); assert_equal (mdl.Coefficients.tStat(1), 12.369874881944, 1e-09); assert_equal (mdl.Coefficients.tStat(2), -5.80228828790225, 1e-09); assert_equal (mdl.Coefficients.tStat(3), -1.76626492228599, 1e-09); assert_equal (mdl.Coefficients.tStat(4), -0.0599128364487485, 1e-09); assert_equal (mdl.Coefficients.pValue(1), 4.89570341688996e-21, 1e-09); assert_equal (mdl.Coefficients.pValue(2), 9.87424814144e-08, 1e-09); assert_equal (mdl.Coefficients.pValue(3), 0.0807803098213114, 1e-09); assert_equal (mdl.Coefficients.pValue(4), 0.952359384151778, 1e-09); ***** shared X, y, yl, T1, T2, T3, C X = [1 2; 3 4; 5 6]; y = [2; 4; 5]; yl = logical ([1; 0; 1]); T1 = table ([1;2;3], [4;5;6], 'VariableNames', {'x1','x2'}); T2 = table ([1;2;3], [4;5;6], 'VariableNames', {'x1','y'}); T3 = table ([1;2;3], [4;5;6], [2;4;5], 'VariableNames', {'x1','x2','y'}); C = categorical ({'a';'b';'a'}); ***** test assert_equal (class (fitlm (X, y)), 'LinearModel'); ***** test assert_equal (class (fitlm (X, yl)), 'LinearModel'); ***** test assert_equal (class (fitlm (X, y, 'linear')), 'LinearModel'); ***** test assert_equal (class (fitlm (X, y, [1 0; 0 1])), 'LinearModel'); ***** test assert_equal (class (fitlm (X, y, 'Intercept', false)), 'LinearModel'); ***** test assert_equal (class (fitlm (X, y, 'linear', 'Weights', [1;2;1])), 'LinearModel'); ***** test mdl = fitlm (C, y); assert_equal (class (mdl), 'LinearModel'); assert_equal (mdl.VariableNames, {'x1'; 'y'}); ***** test mdl = fitlm (C, y, 'VarNames', {'grp', 'score'}); assert_equal (mdl.VariableNames, {'grp'; 'score'}); ***** test assert_equal (class (fitlm (C, y, 'Intercept', false)), 'LinearModel'); ***** test assert_equal (class (fitlm (T2)), 'LinearModel'); ***** test assert_equal (class (fitlm (T3)), 'LinearModel'); ***** test assert_equal (class (fitlm (T3, 'Exclude', [2])), 'LinearModel'); ***** test assert_equal (class (fitlm (T2, 'y')), 'LinearModel'); ***** test assert_equal (class (fitlm (T3, 'x1')), 'LinearModel'); ***** test assert_equal (class (fitlm (T3, 'y ~ x1 + x2')), 'LinearModel'); ***** test assert_equal (class (fitlm (T1, 'linear')), 'LinearModel'); ***** test assert_equal (class (fitlm (T1, [2;4;5])), 'LinearModel'); ***** test assert_equal (class (fitlm (T2, [0 0; 1 0])), 'LinearModel'); ***** test assert_equal (class (fitlm (T2, 'y', 'linear', 'Intercept', false)), 'LinearModel'); ***** error fitlm () ***** error ... fitlm ('hello', y) ***** error ... fitlm (struct ('a', 1), [1;2]) ***** error ... fitlm (categorical ([1 2; 3 4]), y) ***** error ... fitlm (C) ***** error ... fitlm (C, 'Intercept', false) ***** error ... fitlm (C, [1;2]) ***** error fitlm (C, {'a';'b';'a'}) ***** error fitlm (X) ***** error ... fitlm (X, 'Weights', [1;1;1]) ***** error ... fitlm (X, []) ***** error ... fitlm (X, [1;2]) ***** error fitlm (X, ones (3, 2)) ***** error fitlm (X, {'1';'2';'3'}) ***** error ... fitlm (T1, []) ***** error ... fitlm (T1, ones (1, 2)) ***** error ... fitlm (T1, ones (4, 1)) ***** error ... fitlm (T1, ones (2, 3)) ***** error fitlm (T1, {1, 2}) ***** error fitlm (T2, 'y ~ x1', 'linear') ***** error fitlm (T1, 'linear', 'Weights') ***** error fitlm (T2, [0 0; 1 0], 'Weights') ***** test Xr = [1 2; 2 1; 3 5; 4 3; 5 6; 6 4]; yr = [1.1 1.9 3.2 3.9 5.1 6.2]; m1 = fitlm (Xr, yr); m2 = fitlm (Xr, yr'); assert_equal (m1.Coefficients.Estimate, m2.Coefficients.Estimate); 45 tests, 45 passed, 0 known failure, 0 skipped [inst/Regression/ridge.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/ridge.m ***** demo ## Perform ridge regression for a range of ridge parameters and observe ## how the coefficient estimates change based on the acetylene dataset. load acetylene X = [x1, x2, x3]; x1x2 = x1 .* x2; x1x3 = x1 .* x3; x2x3 = x2 .* x3; D = [x1, x2, x3, x1x2, x1x3, x2x3]; k = 0:1e-5:5e-3; b = ridge (y, D, k); figure plot (k, b, 'LineWidth', 2) ylim ([-100, 100]) grid on xlabel ('Ridge Parameter') ylabel ('Standardized Coefficient') title ('Ridge Trace') legend ('x1', 'x2', 'x3', 'x1x2', 'x1x3', 'x2x3') ***** demo rng (42); load carbig X = [Acceleration Weight Displacement Horsepower]; y = MPG; n = length (y); c = cvpartition (n,'HoldOut',0.3); idxTrain = training(c,1); idxTest = ! idxTrain; idxTrain = training(c,1); idxTest = ! idxTrain; k = 5; b = ridge (y(idxTrain),X(idxTrain,:),k,0); % Predict MPG values for the test data using the model. yhat = b(1) + X(idxTest,:)*b(2:end); scatter (y(idxTest),yhat) hold on plot (y(idxTest),y(idxTest),'r') xlabel ('Actual MPG') ylabel ('Predicted MPG') hold off ***** test b = ridge ([1 2 3 4]', [1 2 3 4; 2 3 4 5]', 1); assert_equal (b, [0.5533; 0.5533], 1e-4); ***** test b = ridge ([1 2 3 4]', [1 2 3 4; 2 3 4 5]', 2); assert_equal (b, [0.4841; 0.4841], 1e-4); ***** test load acetylene x = [x1, x2, x3]; b = ridge (y, x, 0); assert_equal (b,[10.2273;1.97128;-0.601818],1e-4); ***** test load acetylene x = [x1, x2, x3]; b = ridge (y, x, 0.0005); assert_equal (b,[10.2233;1.9712;-0.6056],1e-4); ***** test load acetylene x = [x1, x2, x3]; b = ridge (y, x, 0.001); assert_equal (b,[10.2194;1.9711;-0.6094],1e-4); ***** test load acetylene x = [x1, x2, x3]; b = ridge (y, x, 0.002); assert_equal (b,[10.2116;1.9709;-0.6169],1e-4); ***** test load acetylene x = [x1, x2, x3]; b = ridge (y, x, 0.005); assert_equal (b,[10.1882;1.9704;-0.6393],1e-4); ***** test load acetylene x = [x1, x2, x3]; b = ridge (y, x, 0.01); assert_equal (b,[10.1497;1.9695;-0.6761],1e-4); ***** error ridge (1) ***** error ridge (1, 2) ***** error ridge (ones (3), ones (3), 2) ***** error ridge ([1, 2], ones (2), 2) ***** error ridge ([], ones (3), 2) ***** error ridge (ones (5,1), [], 2) ***** error ... ridge ([1; 2; 3; 4; 5], ones (3), 3) ***** error ... ridge ([1; 2; 3], ones (3), 3, 2) ***** error ... ridge ([1; 2; 3], ones (3), 3, 'some') 17 tests, 17 passed, 0 known failure, 0 skipped [inst/Regression/CompactLinearModel.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/Regression/CompactLinearModel.m ***** shared mdl, cmdl, X, y, n n = 20; X = [(1:n); (1:n).^2]' / n; y = X * [3; -1] + 0.2 * sin ((1:n)'); mdl = fitlm (X, y); cmdl = compact (mdl); ***** test assert_equal (cmdl.NumObservations, 20); assert_equal (cmdl.NumCoefficients, 3); assert_equal (cmdl.NumVariables, 3); assert_equal (cmdl.NumPredictors, 2); assert_equal (cmdl.NumEstimatedCoefficients, 3); assert_equal (cmdl.DFE, 17); assert_equal (cmdl.SSE, 0.386545331386823, 1e-9); assert_equal (cmdl.SSR, 583.523874670959, 1e-6); assert_equal (cmdl.SST, 583.910420002346, 1e-6); assert_equal (cmdl.MSE, 0.0227379606698351, 1e-10); assert_equal (cmdl.RMSE, 0.150791116017606, 1e-10); assert_equal (cmdl.Rsquared.Ordinary, 0.999338005765704, 1e-10); assert_equal (cmdl.Rsquared.Adjusted, 0.999260124091081, 1e-10); assert_equal (cmdl.LogLikelihood, 11.0836133807695, 1e-6); assert_equal (cmdl.ModelCriterion.AIC, -16.1672267615389, 1e-6); assert_equal (cmdl.ModelCriterion.AICc, -14.6672267615389, 1e-6); assert_equal (cmdl.ModelCriterion.BIC, -13.180029940877, 1e-6); assert_equal (cmdl.ModelCriterion.CAIC, -10.180029940877, 1e-6); ***** test assert_equal (cmdl.Coefficients.Estimate, [0.1161886778; 2.508451491; -0.9788353298], 1e-7); assert_equal (cmdl.Coefficients.SE, [0.112185831; 0.4920818186; 0.02276108523], 1e-8); assert_equal (cmdl.Coefficients.tStat, [1.035680502; 5.097630913; -43.00477415], 1e-6); assert_equal (all (cmdl.Coefficients.pValue >= 0 & cmdl.Coefficients.pValue <= 1), true); assert_equal (isequal (cmdl.CoefficientNames, {'(Intercept)', 'x1', 'x2'}), true); assert_equal (isequal (cmdl.CoefficientNames, cmdl.Coefficients.Properties.RowNames(:)'), true); assert_equal (size (cmdl.CoefficientCovariance), [3, 3]); assert_equal (diag (cmdl.CoefficientCovariance), [0.0125857; 0.242145; 0.000518067], 1e-6); assert_equal (width (cmdl.Coefficients), 4); assert_equal (isequal (cmdl.Coefficients.Properties.VariableNames, ... {'Estimate','SE','tStat','pValue'}), true); ***** test assert_equal (cmdl.Formula.LinearPredictor, '1 + x1 + x2'); assert_equal (cmdl.Formula.HasIntercept, true); assert_equal (cmdl.PredictorNames, {'x1'; 'x2'}); assert_equal (cmdl.ResponseName, 'y'); assert_equal (cmdl.VariableNames, {'x1'; 'x2'; 'y'}); assert_equal (cmdl.VariableInfo.Range{1}, [0.05, 1], 1e-10); assert_equal (cmdl.VariableInfo.Range{2}, [0.05, 20], 1e-10); assert_equal (cmdl.VariableInfo.InModel, [true; true; false]); assert_equal (cmdl.Robust, []); ***** test ci = coefCI (cmdl); assert_equal (size (ci), [3, 2]); assert_equal (class (ci), 'double'); assert_equal (all (ci(:,1) < ci(:,2)), true); assert_equal (ci(1,1), -0.120502736154050, 1e-10); assert_equal (ci(1,2), 0.352880091734465, 1e-10); assert_equal (ci(2,1), 1.470249604061007, 1e-10); assert_equal (ci(2,2), 3.546653377080718, 1e-10); assert_equal (ci(3,1), -1.026857022014626, 1e-10); assert_equal (ci(3,2), -0.930813637635746, 1e-10); ***** test ci = coefCI (cmdl); t = tinv (0.975, cmdl.DFE); assert_equal ((ci(:,1) + ci(:,2)) / 2, cmdl.Coefficients.Estimate, 1e-10); assert_equal (ci(:,2) - ci(:,1), 2 * t * cmdl.Coefficients.SE, 1e-10); assert_equal (coefCI (cmdl, 0.05), ci); ***** test ci = coefCI (cmdl, 0.01); assert_equal (size (ci), [3, 2]); assert_equal (ci(1,1), -0.208951721610638, 1e-10); assert_equal (ci(1,2), 0.441329077191052, 1e-10); assert_equal (ci(2,1), 1.082284945644892, 1e-10); assert_equal (ci(2,2), 3.934618035496833, 1e-10); assert_equal (ci(3,1), -1.044802201703589, 1e-10); assert_equal (ci(3,2), -0.912868457946783, 1e-10); ***** test ## a zero alpha gives an infinite interval and a full alpha collapses it to the estimate ci = coefCI (cmdl, 0); assert_equal (all (ci(:,1) == -Inf), true); assert_equal (all (ci(:,2) == +Inf), true); ci = coefCI (cmdl, 1); assert_equal (ci(:,1), cmdl.Coefficients.Estimate, 1e-10); assert_equal (ci(:,2), cmdl.Coefficients.Estimate, 1e-10); ***** test m = fitlm (X, y, 'Intercept', false); cm = compact (m); ci = coefCI (cm); assert_equal (size (ci), [2, 2]); assert_equal (ci(1,1), 2.486679110991696, 1e-10); assert_equal (ci(1,2), 3.436164115360526, 1e-10); assert_equal (ci(2,1), -1.027166590567854, 1e-10); assert_equal (ci(2,2), -0.967330908318718, 1e-10); ***** test m = fitlm (X, y, 'Weights', (1:n)' / sum (1:n)); cm = compact (m); ci = coefCI (cm); assert_equal (size (ci), [3, 2]); assert_equal (ci(1,1), -0.355978167660141, 1e-10); assert_equal (ci(1,2), 0.516619434992026, 1e-10); assert_equal (ci(2,1), 1.142016390035618, 1e-10); assert_equal (ci(2,2), 4.154555017558383, 1e-10); assert_equal (ci(3,1), -1.044530853341675, 1e-10); assert_equal (ci(3,2), -0.924508441530335, 1e-10); ***** test m = fitlm ([ones(n,1), X, X(:,1)+X(:,2)], y); cm = compact (m); ci = coefCI (cm); drop = find (cm.Coefficients.SE == 0); keep = setdiff (1:5, drop'); assert_equal (size (ci), [5, 2]); assert_equal (numel (drop), 2); assert_equal (all (all (ci(drop, :) == 0)), true); assert_equal (all (all (isfinite (ci(keep, :)))), true); assert_equal ((ci(keep,1) + ci(keep,2)) / 2, cm.Coefficients.Estimate(keep), 1e-10); assert_equal (cm.DFE, 17); assert_equal (m.SSE, 0.386545331386824, 1e-10); assert_equal (m.Rsquared.Ordinary, 0.999338005765704, 1e-10); assert_equal (m.Rsquared.Adjusted, 0.999260124091081, 1e-10); ***** test m = fitlm ([1;1;1;2;2;2;3;3;3], [2.1;2.3;1.9;4.1;3.9;4.2;6.3;5.8;6.1], ... 'linear', 'CategoricalVars', 1); cm = compact (m); ci = coefCI (cm); assert_equal (size (ci), [3, 2]); assert_equal (ci(1,1), 1.809712563216694, 1e-10); assert_equal (ci(1,2), 2.390287436783304, 1e-10); assert_equal (ci(2,1), 1.556138236581195, 1e-10); assert_equal (ci(2,2), 2.377195096752140, 1e-10); assert_equal (ci(3,1), 3.556138236581195, 1e-10); assert_equal (ci(3,2), 4.377195096752140, 1e-10); ***** test m = fitlm (X, y, 'RobustOpts', 'bisquare'); cm = compact (m); ci = coefCI (cm); assert_equal (cm.DFE, 17); assert_equal (ci(1,1), -0.136385388374896, 1e-10); assert_equal (ci(1,2), 0.378422288262478, 1e-10); assert_equal (ci(2,1), 1.359092508160098, 1e-10); assert_equal (ci(2,2), 3.617198504352038, 1e-10); assert_equal (ci(3,1), -1.030210688187146, 1e-10); assert_equal (ci(3,2), -0.925762726293341, 1e-10); ci = coefCI (cm, 0.1); assert_equal (ci(1,1), -0.091218796364050, 1e-10); assert_equal (ci(1,2), 0.333255696251631, 1e-10); assert_equal (ci(2,1), 1.557207176755238, 1e-10); assert_equal (ci(2,2), 3.419083835756898, 1e-10); assert_equal (ci(3,1), -1.021046958321974, 1e-10); assert_equal (ci(3,2), -0.934926456158514, 1e-10); ***** test m = fitlm (X, y, 'constant'); cm = compact (m); ci = coefCI (cm); t = tinv (0.975, cm.DFE); assert_equal (size (ci), [1, 2]); assert_equal (ci(1,1), -8.184528886493887, 1e-10); assert_equal (ci(1,2), -2.995506675817716, 1e-10); assert_equal ((ci(1,1) + ci(1,2)) / 2, cm.Coefficients.Estimate, 1e-10); assert_equal (ci(1,2) - ci(1,1), 2 * t * cm.Coefficients.SE, 1e-10); ***** test [p, F, r] = coefTest (cmdl); assert_equal (size (p), [1, 1]); assert_equal (class (p), 'double'); assert_equal (p >= 0 && p <= 1, true); assert_equal (F >= 0, true); assert_equal (p, 9.489880832170599e-28, -1e-8); assert_equal (F, 1.283149098426142e+04, -1e-8); assert_equal (r, 2); ***** test k = cmdl.NumCoefficients; H = [zeros(k-1, 1), eye(k-1)]; [p, F, r] = coefTest (cmdl, H); assert_equal (p, 9.489880832170599e-28, -1e-8); assert_equal (F, 1.283149098426142e+04, -1e-8); assert_equal (r, 2); ***** test [p, F, r] = coefTest (cmdl, [1 0 0]); assert_equal (size (r), [1, 1]); assert_equal (p, 0.314859866747774, -1e-8); assert_equal (F, 1.072634101844537, -1e-8); assert_equal (r, 1); [p, F, r] = coefTest (cmdl, [0 1 0]); assert_equal (p, 8.937794169018252e-05, -1e-8); assert_equal (F, 25.985840929474932, -1e-8); assert_equal (r, 1); [p, F, r] = coefTest (cmdl, [0 0 1]); assert_equal (p, 8.656938305821102e-19, -1e-8); assert_equal (F, 1.849410599855684e+03, -1e-8); assert_equal (r, 1); [p, F, r] = coefTest (cmdl, [0 1 0; 0 0 1]); assert_equal (p, 9.489880832170599e-28, -1e-8); assert_equal (F, 1.283149098426142e+04, -1e-8); assert_equal (r, 2); ***** test b = cmdl.Coefficients.Estimate; [p, F] = coefTest (cmdl, [0 1 0], b(2)); assert_equal (p, 1, 1e-10); assert_equal (F, 0, 1e-10); [p, F] = coefTest (cmdl, [0 1 0], 0); assert_equal (p, 8.937794169018252e-05, -1e-8); assert_equal (F, 25.985840929474932, -1e-8); ***** test [p, F, r] = coefTest (cmdl, [0 1 0; 0 0 1], [1.5; -1.0]); assert_equal (p, 2.833788304242915e-09, -1e-8); assert_equal (F, 77.603887650386312, -1e-8); assert_equal (r, 2); [p, F] = coefTest (cmdl, [0 1 0], 1.5); assert_equal (p, 0.056184159363707, -1e-8); assert_equal (F, 4.199865537706047, -1e-8); ***** test m = fitlm (X, y, 'Intercept', false); cm = compact (m); [p, F, r] = coefTest (cm); assert_equal (r, cm.NumCoefficients); assert_equal (p, 6.060655830723051e-32, -1e-8); assert_equal (F, 2.646694317541346e+04, -1e-8); ***** test m = fitlm (X, y, 'interactions'); cm = compact (m); [p, F, r] = coefTest (cm); assert_equal (r, cm.NumCoefficients - 1); assert_equal (r != cm.NumPredictors, true); assert_equal (p, 1.164196605688161e-25, -1e-8); assert_equal (F, 8.107508574885546e+03, -1e-8); ***** test m = fitlm (X, y, 'Weights', (1:n)' / sum (1:n)); cm = compact (m); [p, F, r] = coefTest (cm); assert_equal (p, 1.481920976389473e-27, -1e-8); assert_equal (F, 1.217557180481257e+04, -1e-8); assert_equal (r, 2); ***** test m = fitlm ([1;1;1;2;2;2;3;3;3], [2.1;2.3;1.9;4.1;3.9;4.2;6.3;5.8;6.1], ... 'linear', 'CategoricalVars', 1); cm = compact (m); [p, F, r] = coefTest (cm); assert_equal (p, 1.197590680415813e-06, -1e-8); assert_equal (F, 2.795000000000035e+02, -1e-8); assert_equal (r, 2); [p, F] = coefTest (cm, [1 0 0]); assert_equal (p, 2.087464608380450e-06, -1e-8); assert_equal (F, 3.133421052631613e+02, -1e-8); [p, F] = coefTest (cm, [0 1 0]); assert_equal (p, 2.325514143662469e-05, -1e-8); assert_equal (F, 1.374078947368438e+02, -1e-8); [p, F] = coefTest (cm, [0 0 1]); assert_equal (p, 3.757733067786492e-07, -1e-8); assert_equal (F, 5.589868421052698e+02, -1e-8); ***** test m = fitlm (X, y, 'constant'); cm = compact (m); [p, F, r] = coefTest (cm); assert_equal (p, 2.399364086950727e-04, -1e-8); assert_equal (F, 20.335916494750592, -1e-8); assert_equal (r, 1); ***** test m = fitlm ([ones(n,1), X, X(:,1)+X(:,2)], y); cm = compact (m); [p, F] = coefTest (cm); assert_equal (size (p), [1, 1]); assert_equal (class (p), 'double'); assert_equal (isnan (p), true); assert_equal (isnan (F), true); drop = find (cm.Coefficients.SE == 0); keep = setdiff (2:cm.NumCoefficients, drop'); H = zeros (numel (keep), cm.NumCoefficients); for i = 1:numel (keep) H(i, keep(i)) = 1; endfor [p, F, r] = coefTest (cm, H); assert_equal (r, numel (keep)); assert_equal (p, 6.706570586430847e-30, -1e-8); assert_equal (F, 1.771618642634559e+04, -1e-8); ***** test m = fitlm (X, y, 'RobustOpts', 'bisquare'); cm = compact (m); [p, F, r] = coefTest (cm); assert_equal (p, 3.941715170923545e-27, -1e-8); assert_equal (F, 1.085097669445008e+04, -1e-8); assert_equal (r, 2); [p, F, r] = coefTest (cm, [0 1 -1]); assert_equal (p, 9.729154060050210e-06, -1e-8); assert_equal (F, 38.417457909307693, -1e-8); assert_equal (r, 1); ***** test yp = predict (cmdl, [0.5 0.25; 1.0 1.0; 0.2 0.04]); assert_equal (class (yp), 'double'); assert_equal (size (yp), [3, 1]); assert_equal (yp(1), 1.125705590619342, 1e-10); assert_equal (yp(2), 1.645804838535884, 1e-10); assert_equal (yp(3), 0.578725562711373, 1e-10); ***** test [yp, yci] = predict (cmdl, [0.5 0.25; 1.0 1.0; 0.2 0.04]); assert_equal (size (yci), [3, 2]); assert_equal (all (yci(:,1) < yci(:,2)), true); assert_equal (yci(1,1), 0.810180780547058, 1e-9); assert_equal (yci(1,2), 1.441230400691626, 1e-9); assert_equal (yci(2,1), 0.858229321851332, 1e-9); assert_equal (yci(2,2), 2.433380355220436, 1e-9); assert_equal (yci(3,1), 0.470499753577336, 1e-9); assert_equal (yci(3,2), 0.686951371845409, 1e-9); ***** test [~, yci] = predict (cmdl, [0.5 0.25; 1.0 1.0; 0.2 0.04], 'Alpha', 0.01); assert_equal (yci(1,1), 0.692272619569794, 1e-9); assert_equal (yci(1,2), 1.559138561668890, 1e-9); assert_equal (yci(2,1), 0.563920989071667, 1e-9); assert_equal (yci(2,2), 2.727688688000101, 1e-9); assert_equal (yci(3,1), 0.430056955680247, 1e-9); assert_equal (yci(3,2), 0.727394169742498, 1e-9); ***** test [~, yci] = predict (cmdl, [0.5 0.25; 1.0 1.0; 0.2 0.04], 'Simultaneous', true); assert_equal (yci(1,1), 0.662572505689110, 1e-9); assert_equal (yci(1,2), 1.588838675549574, 1e-9); assert_equal (yci(2,1), 0.489787095987915, 1e-9); assert_equal (yci(2,2), 2.801822581083853, 1e-9); assert_equal (yci(3,1), 0.419869741383617, 1e-9); assert_equal (yci(3,2), 0.737581384039129, 1e-9); ***** test [~, yci] = predict (cmdl, [0.5 0.25; 1.0 1.0; 0.2 0.04], 'Prediction', 'observation'); assert_equal (yci(1,1), 0.677632064105876, 1e-9); assert_equal (yci(1,2), 1.573779117132808, 1e-9); assert_equal (yci(2,1), 0.796399650258815, 1e-9); assert_equal (yci(2,2), 2.495210026812952, 1e-9); assert_equal (yci(3,1), 0.242679724835377, 1e-9); assert_equal (yci(3,2), 0.914771400587368, 1e-9); ***** test [~, yci] = predict (cmdl, [0.5 0.25; 1.0 1.0; 0.2 0.04], ... 'Alpha', 0.1, 'Simultaneous', true, 'Prediction', 'observation'); assert_equal (yci(1,1), 0.551414812037842, 1e-9); assert_equal (yci(1,2), 1.699996369200842, 1e-9); assert_equal (yci(2,1), 0.557131801540151, 1e-9); assert_equal (yci(2,2), 2.734477875531617, 1e-9); assert_equal (yci(3,1), 0.148019407463707, 1e-9); assert_equal (yci(3,2), 1.009431717959039, 1e-9); ***** test [yp, yci] = predict (cmdl, [0.5 0.25; NaN 1.0; 1.0 1.0]); assert_equal (isnan (yp(2)), true); assert_equal (all (isnan (yci(2,:))), true); assert_equal (yp(1), 1.125705590619342, 1e-10); assert_equal (yp(3), 1.645804838535884, 1e-10); assert_equal (yci(1,1), 0.810180780547058, 1e-9); assert_equal (yci(3,2), 2.433380355220436, 1e-9); ***** test Xt = table (0.5, 0.25, 'VariableNames', {'x1', 'x2'}); yp = predict (cmdl, Xt); assert_equal (yp, 1.125705590619342, 1e-10); ***** test m = fitlm ([1;1;1;2;2;2;3;3;3], [2.1;2.3;1.9;4.1;3.9;4.2;6.3;5.8;6.1], ... 'linear', 'CategoricalVars', 1); cm = compact (m); yp = predict (cm, table ([1;2;3], 'VariableNames', {'x1'})); assert_equal (yp(1), 2.099999999999999, 1e-10); assert_equal (yp(2), 4.066666666666666, 1e-10); assert_equal (yp(3), 6.066666666666666, 1e-10); ***** test m = fitlm (X, y, 'Weights', (1:n)' / sum (1:n)); cm = compact (m); [yp, yci] = predict (cm, [0.5 0.25; 1.0 1.0; 0.2 0.04], 'Alpha', 0.05); assert_equal (yp(1), 1.158333573705442, 1e-10); assert_equal (yp(2), 1.744086690026939, 1e-10); assert_equal (yp(3), 0.570596988527903, 1e-10); assert_equal (yci(1,1), 0.802165170771357, 1e-9); assert_equal (yci(2,2), 2.788483587522537, 1e-9); ***** test m = fitlm (X, y, 'RobustOpts', 'bisquare'); cm = compact (m); [yp, yci] = predict (cm, [0.5 0.25; 1.0 1.0; 0.2 0.04], 'Simultaneous', true, 'Alpha', 0.1); assert_equal (yp(1), 1.120594526261764, 1e-10); assert_equal (yp(2), 1.631177248959615, 1e-10); assert_equal (yp(3), 0.579528082905394, 1e-10); assert_equal (yci(1,1), 0.680801249227337, 1e-9); assert_equal (yci(2,2), 2.728936938016809, 1e-9); ***** test m = fitlm (X, y, 'quadratic'); cm = compact (m); [yp, yci] = predict (cm, [0.5 0.25; 1.0 1.0; 0.2 0.04]); assert_equal (yp(1), -0.948865258803113, 1e-9); assert_equal (yp(2), -3.349087980348939, 1e-9); assert_equal (yp(3), -0.053659932832480, 1e-9); assert_equal (yci(1,1), -3.431959757763334, 1e-9); assert_equal (yci(1,2), 1.534229240157108, 1e-9); ***** test ysim = random (cmdl, [0.5 0.25; 1.0 1.0]); assert_equal (size (ysim), [2, 1]); assert_equal (class (ysim), 'double'); assert_equal (iscolumn (ysim), true); ypred = predict (cmdl, [0.5 0.25; 1.0 1.0]); assert_equal (ypred(1), 1.125705590619342, 1e-10); assert_equal (ypred(2), 1.645804838535884, 1e-10); assert_equal (all (isfinite (ysim - ypred)), true); ***** test assert_equal (size (random (cmdl, [0.5 0.25])), [1, 1]); ***** test ysim = random (cmdl, [0.5 0.25; NaN 1.0; 1.0 1.0]); assert_equal (size (ysim), [3, 1]); assert_equal (isfinite (ysim(1)), true); assert_equal (isnan (ysim(2)), true); assert_equal (isfinite (ysim(3)), true); ***** test ya = random (cmdl, [0.5 0.25]); yb = random (cmdl, [0.5 0.25]); assert_equal (isequal (ya, yb), false); ***** test Xt = table (0.5, 0.25, 'VariableNames', {'x1', 'x2'}); assert_equal (size (random (cmdl, Xt)), [1, 1]); assert_equal (all (isfinite (random (cmdl, Xt))), true); ysim = random (cmdl, X); assert_equal (size (ysim), [20, 1]); assert_equal (sum (isnan (ysim)), 0); ***** test mw = compact (fitlm (X, y, 'Weights', (1:n)' / sum (1:n))); mni = compact (fitlm (X, y, 'Intercept', false)); assert_equal (all (isfinite (random (mw, [0.5 0.25; 1.0 1.0]))), true); assert_equal (all (isfinite (random (mni, [0.5 0.25; 1.0 1.0]))), true); ***** test yf = feval (cmdl, [0.5 0.25; 1.0 1.0; 0.2 0.04]); assert_equal (yf(1), 1.125705590619342, 1e-10); assert_equal (yf(2), 1.645804838535884, 1e-10); assert_equal (yf(3), 0.578725562711373, 1e-10); assert_equal (feval (cmdl, [0.5; 1.0; 0.2], [0.25; 1.0; 0.04]), yf, 1e-10); ***** test yf3 = feval (cmdl, [0.5, 1.0, 0.2], [0.25, 1.0, 0.04]); assert_equal (size (yf3), [1, 3]); assert_equal (yf3(1), 1.125705590619342, 1e-10); assert_equal (yf3(2), 1.645804838535884, 1e-10); assert_equal (yf3(3), 0.578725562711373, 1e-10); ***** test assert_equal (feval (cmdl, 0.5, 0.25), 1.125705590619342, 1e-10); yf5 = feval (cmdl, 0.5, [0.1; 0.2; 0.3]); assert_equal (yf5(1), 1.272530890093120, 1e-10); assert_equal (yf5(2), 1.174647357110602, 1e-10); assert_equal (yf5(3), 1.076763824128083, 1e-10); yf6 = feval (cmdl, [0.1; 0.5; 0.9], 0.25); assert_equal (yf6(1), 0.122324994390997, 1e-10); assert_equal (yf6(2), 1.125705590619342, 1e-10); assert_equal (yf6(3), 2.129086186847688, 1e-10); ***** test ms = compact (fitlm (X(:,1), y)); assert_equal (size (feval (ms, 0.5)), [1, 1]); assert_equal (size (feval (ms, [0.3; 0.5; 0.9])), [3, 1]); assert_equal (feval (ms, 0.5), predict (ms, 0.5), 1e-10); assert_equal (feval (ms, [0.3; 0.5; 0.9]), predict (ms, [0.3; 0.5; 0.9]), 1e-10); yf14 = feval (ms, [1; 2; 3]); assert_equal (yf14(1), -14.162385738140875, 1e-9); assert_equal (yf14(2), -32.209476173898921, 1e-9); assert_equal (yf14(3), -50.256566609656964, 1e-9); ***** test Xt = table (0.5, 0.25, 'VariableNames', {'x1', 'x2'}); assert_equal (feval (cmdl, Xt), 1.125705590619342, 1e-10); ***** test yf9 = feval (cmdl, [0.5 0.25; NaN 1.0; 1.0 1.0]); assert_equal (isnan (yf9(2)), true); assert_equal (yf9(1), 1.125705590619342, 1e-10); assert_equal (yf9(3), 1.645804838535884, 1e-10); yf10 = feval (cmdl, [0.5; NaN; 1.0], [0.25; 1.0; 1.0]); assert_equal (isnan (yf10(2)), true); yf11 = feval (cmdl, [0.5; 1.0; 1.0], [0.25; NaN; 1.0]); assert_equal (isnan (yf11(2)), true); ***** test yf12 = feval (cmdl, X); assert_equal (size (yf12), [20, 1]); assert_equal (sum (isnan (yf12)), 0); ***** test mw = compact (fitlm (X, y, 'Weights', (1:n)' / sum (1:n))); yfw = feval (mw, [0.5 0.25; 1.0 1.0]); assert_equal (yfw(1), 1.158333573705442, 1e-10); assert_equal (yfw(2), 1.744086690026939, 1e-10); assert_equal (feval (mw, [0.5; 1.0], [0.25; 1.0]), yfw, 1e-10); ***** test Weight = [2000;2100;2200;2300;2400;2500;2600;2700;2800;2900;3000; ... 3100;3200;3300;3400;3500;3600;3700;3800;3900]; Year = categorical ([70;70;70;70;70;76;76;76;76;76;76;76;82;82; ... 82;82;82;82;82;82]); MPG = [30;29;28;27;26;25;24;23;22;21;20;19;18;17;16;15;14;13;12;11]; m = fitlm (table (MPG, Weight, Year), 'MPG ~ Weight + Year'); cm = compact (m); yf = feval (cm, [2500;3000], '76'); assert_equal (yf(1), 25.000000000000000, 1e-9); assert_equal (yf(2), 20.000000000000004, 1e-9); assert_equal (yf, feval (m, [2500;3000], '76'), 1e-10); yf2 = feval (cm, [2500;3000], categorical (70)); assert_equal (yf2(1), 24.999999999999996, 1e-9); assert_equal (yf2(2), 20.000000000000000, 1e-9); assert_equal (feval (cm, 2800, '82'), 21.999999999999996, 1e-9); assert_equal (isnan (feval (cm, 2500, '99')), true); ***** test fig = figure ('visible', 'off'); ax = axes (fig); h = plotEffects (ax, cmdl); xd1 = get (h(1), 'XData'); yd1 = get (h(1), 'YData'); xd2 = get (h(2), 'XData'); yd2 = get (h(2), 'YData'); xd3 = get (h(3), 'XData'); yd3 = get (h(3), 'YData'); ytl = get (ax, 'YTickLabel'); assert_equal (numel (h), 3); assert_equal (xd1(1), 2.38302891604232, -1e-10); assert_equal (xd1(2), -19.5277648300125, -1e-10); assert_equal (yd1, [1 2]); assert_equal (xd2(1), 1.39673712385796, -1e-10); assert_equal (xd2(2), 3.36932070822668, -1e-10); assert_equal (yd2, [1 1]); assert_equal (xd3(1), -20.4857975891918, -1e-10); assert_equal (xd3(2), -18.5697320708331, -1e-10); assert_equal (yd3, [2 2]); assert_equal (get (h(1), 'Color'), [0.1490 0.5490 0.8660], 1e-4); assert_equal (get (h(2), 'Color'), [0.1490 0.5490 0.8660], 1e-4); assert_equal (get (h(3), 'Color'), [0.1490 0.5490 0.8660], 1e-4); assert_equal (get (h(1), 'Marker'), 'o'); assert_equal (get (h(1), 'LineStyle'), 'none'); assert_equal (get (h(2), 'LineStyle'), '-'); assert_equal (get (h(2), 'Marker'), 'none'); assert_equal (get (h(3), 'LineStyle'), '-'); assert_equal (get (h(3), 'Marker'), 'none'); assert_equal (mean (xd2), xd1(1), 1e-10); assert_equal (mean (xd3), xd1(2), 1e-10); assert_equal (get (get (ax, 'xlabel'), 'string'), 'Main Effect'); assert_equal (get (get (ax, 'ylabel'), 'string'), ''); assert_equal (get (get (ax, 'title'), 'string'), 'Main Effects Plot'); assert_equal (get (ax, 'YTick'), [1 2]); assert_equal (ytl{1}, 'x1: 0.05 to 1'); assert_equal (ytl{2}, 'x2: 0.05 to 20'); close (fig); ***** test ## 3-predictor model X3 = [X, sin((1:n)' * pi / n)]; y3 = X3 * [3; -1; 2] + 0.1 * cos ((1:n)' * pi / 7); cm3 = compact (fitlm (X3, y3)); fig = figure ('visible', 'off'); ax = axes (fig); h = plotEffects (ax, cm3); xd1 = get (h(1), 'XData'); yd1 = get (h(1), 'YData'); xd2 = get (h(2), 'XData'); yd2 = get (h(2), 'YData'); xd3 = get (h(3), 'XData'); yd3 = get (h(3), 'YData'); xd4 = get (h(4), 'XData'); yd4 = get (h(4), 'YData'); ytl = get (ax, 'YTickLabel'); assert_equal (numel (h), 4); assert_equal (xd1(1), 8.10687671732127, -1e-10); assert_equal (xd1(2), -25.4487243632125, -1e-10); assert_equal (xd1(3), 0.661302203942261, -1e-10); assert_equal (yd1, [1 2 3]); assert_equal (xd2(1), 0.565266595687836, -1e-10); assert_equal (xd2(2), 15.6484868389547, -1e-10); assert_equal (yd2, [1 1]); assert_equal (xd3(1), -33.3368582824351, -1e-10); assert_equal (xd3(2), -17.5605904439899, -1e-10); assert_equal (yd3, [2 2]); assert_equal (xd4(1), -1.25582490831999, -1e-10); assert_equal (xd4(2), 2.57842931620451, -1e-10); assert_equal (yd4, [3 3]); assert_equal (get (ax, 'YTick'), [1 2 3]); assert_equal (ytl{1}, 'x1: 0.05 to 1'); assert_equal (ytl{2}, 'x2: 0.05 to 20'); assert_equal (ytl{3}, 'x3: 1.22465e-16 to 1'); assert_equal (mean (xd2), xd1(1), 1e-10); assert_equal (mean (xd3), xd1(2), 1e-10); assert_equal (mean (xd4), xd1(3), 1e-10); close (fig); ***** test cme = compact (fitlm (X, y, 'Exclude', [2, 7])); fig = figure ('visible', 'off'); ax = axes (fig); h = plotEffects (ax, cme); xd1 = get (h(1), 'XData'); yd1 = get (h(1), 'YData'); xd2 = get (h(2), 'XData'); yd2 = get (h(2), 'YData'); xd3 = get (h(3), 'XData'); yd3 = get (h(3), 'YData'); ytl = get (ax, 'YTickLabel'); assert_equal (numel (h), 3); assert_equal (xd1(1), 2.50035744908398, -1e-10); assert_equal (xd1(2), -19.5912988214488, -1e-10); assert_equal (yd1, [1 2]); assert_equal (xd2(1), 1.40421088339552, -1e-10); assert_equal (xd2(2), 3.59650401477245, -1e-10); assert_equal (yd2, [1 1]); assert_equal (xd3(1), -20.6333076647782, -1e-10); assert_equal (xd3(2), -18.5492899781194, -1e-10); assert_equal (yd3, [2 2]); assert_equal (ytl{1}, 'x1: 0.05 to 1'); assert_equal (ytl{2}, 'x2: 0.05 to 20'); assert_equal (mean (xd2), xd1(1), 1e-10); assert_equal (mean (xd3), xd1(2), 1e-10); close (fig); ***** test cmw = compact (fitlm (X, y, 'Weights', (1:n)' / sum (1:n))); fig = figure ('visible', 'off'); ax = axes (fig); h = plotEffects (ax, cmw); xd1 = get (h(1), 'XData'); yd1 = get (h(1), 'YData'); xd2 = get (h(2), 'XData'); yd2 = get (h(2), 'YData'); xd3 = get (h(3), 'XData'); yd3 = get (h(3), 'YData'); ytl = get (ax, 'YTickLabel'); assert_equal (numel (h), 3); assert_equal (xd1(1), 2.51587141860715, -1e-10); assert_equal (xd1(2), -19.6411669663483, -1e-10); assert_equal (yd1, [1 2]); assert_equal (xd2(1), 1.08491557053384, -1e-10); assert_equal (xd2(2), 3.94682726668046, -1e-10); assert_equal (yd2, [1 1]); assert_equal (xd3(1), -20.8383905241664, -1e-10); assert_equal (xd3(2), -18.4439434085302, -1e-10); assert_equal (yd3, [2 2]); assert_equal (ytl{1}, 'x1: 0.05 to 1'); assert_equal (ytl{2}, 'x2: 0.05 to 20'); assert_equal (mean (xd2), xd1(1), 1e-10); assert_equal (mean (xd3), xd1(2), 1e-10); close (fig); ***** test cmni = compact (fitlm (X, y, 'Intercept', false)); fig = figure ('visible', 'off'); ax = axes (fig); h = plotEffects (ax, cmni); xd1 = get (h(1), 'XData'); yd1 = get (h(1), 'YData'); xd2 = get (h(2), 'XData'); yd2 = get (h(2), 'YData'); xd3 = get (h(3), 'XData'); yd3 = get (h(3), 'YData'); ytl = get (ax, 'YTickLabel'); assert_equal (numel (h), 3); assert_equal (xd1(1), 2.81335053251731, -1e-10); assert_equal (xd1(2), -19.8951125513936, -1e-10); assert_equal (yd1, [1 2]); assert_equal (xd2(1), 2.36234515544211, -1e-10); assert_equal (xd2(2), 3.26435590959250, -1e-10); assert_equal (yd2, [1 1]); assert_equal (xd3(1), -20.4919734818287, -1e-10); assert_equal (xd3(2), -19.2982516209584, -1e-10); assert_equal (yd3, [2 2]); assert_equal (ytl{1}, 'x1: 0.05 to 1'); assert_equal (ytl{2}, 'x2: 0.05 to 20'); assert_equal (mean (xd2), xd1(1), 1e-10); assert_equal (mean (xd3), xd1(2), 1e-10); close (fig); ***** test fig = figure ('visible', 'off'); ax = axes (fig); h = plotEffects (ax, cmdl); assert_equal (isequal (get (h(1), 'Parent'), ax), true); assert_equal (get (h(1), 'XData'), [2.38302891604232, -19.5277648300125], -1e-10); close (fig); ***** test fig = figure ('visible', 'off'); h = plotEffects (cmdl); assert_equal (isequal (get (h(1), 'Parent'), gca ()), true); assert_equal (get (h(1), 'XData'), [2.38302891604232, -19.5277648300125], -1e-10); close (fig); ***** test fig = figure ('visible', 'off'); h1 = plotEffects (mdl); h2 = plotEffects (cmdl); assert_equal (get (h1(1), 'XData'), get (h2(1), 'XData'), 1e-10); assert_equal (get (h1(2), 'XData'), get (h2(2), 'XData'), 1e-10); assert_equal (get (h1(3), 'XData'), get (h2(3), 'XData'), 1e-10); close (fig); ***** test ## continuous by continuous, effects mode cmi = compact (fitlm (X, y, 'y ~ x1*x2')); fig = figure ('visible', 'off'); h = plotInteraction (cmi, 'x1', 'x2'); assert_equal (numel (h), 11); assert_equal (get (h(1), 'XData'), [1.76843380852813, -18.8740348676059], 1e-9); assert_equal (get (h(1), 'YData'), [1, 7]); assert_equal (get (h(2), 'XData'), [-2.25617028020123, 5.79303789725749], 1e-9); assert_equal (get (h(3), 'XData'), [-23.1321080641968, -14.615961671015], 1e-9); assert_equal (get (h(4), 'XData'), ... [1.97967308209488, 1.68393809910143, 1.38820311610799], 1e-9); assert_equal (get (h(4), 'YData'), [2, 3, 4]); assert_equal (get (h(5), 'XData'), [-0.771057026434185, 4.73040319062394], 1e-9); assert_equal (get (h(6), 'XData'), [-2.86059582662229, 6.22847202482516], 1e-9); assert_equal (get (h(7), 'XData'), [-4.99614754441031, 7.77255377662629], 1e-9); assert_equal (get (h(8), 'XData'), ... [-18.5782998846125, -18.8740348676059, -19.1697698505994], 1e-9); assert_equal (get (h(8), 'YData'), [8, 9, 10]); assert_equal (get (h(9), 'XData'), [-24.674318784563, -12.4822809846619], 1e-9); assert_equal (get (h(10), 'XData'), [-23.1321080641968, -14.615961671015], 1e-9); assert_equal (get (h(11), 'XData'), [-21.6439971135684, -16.6955425876303], 1e-9); assert_equal (get (h(1), 'Tag'), 'main'); assert_equal (get (h(4), 'Tag'), 'conditional1'); assert_equal (get (h(8), 'Tag'), 'conditional2'); ax = gca (); assert_equal (get (get (ax, 'Title'), 'String'), 'Interaction of x1 and x2'); assert_equal (get (get (ax, 'XLabel'), 'String'), 'Effect'); assert_equal (get (ax, 'YTick'), [1, 2, 3, 4, 7, 8, 9, 10]); assert_equal (get (ax, 'YTickLabel'), ... {'x1: 0.05 to 1'; 'x2=0.05'; 'x2=10.025'; 'x2=20'; ... 'x2: 0.05 to 20'; 'x1=0.05'; 'x1=0.525'; 'x1=1'}); assert_equal (get (ax, 'YLim'), [0.5, 10.5]); close (fig); ***** test ## continuous by continuous, predictions mode cmi = compact (fitlm (X, y, 'y ~ x1*x2')); fig = figure ('visible', 'off'); h = plotInteraction (cmi, 'x1', 'x2', 'predictions'); assert_equal (numel (h), 3); xd = get (h(1), 'XData'); assert_equal (numel (xd), 101); assert_equal (xd(1:3), [0.05, 0.2495, 0.449], 1e-9); assert_equal (xd(end-2:end), [19.601, 19.8005, 20], 1e-9); yd1 = get (h(1), 'YData'); assert_equal (yd1(1:3), ... [0.215349913094656, 0.0295669142485309, -0.156216084597594], 1e-9); assert_equal (yd1(end-2:end), ... [-17.9913839738256, -18.1771669726717, -18.3629499715178], 1e-9); yd2 = get (h(2), 'YData'); assert_equal (yd2(1:3), [1.20518645414209, 1.01644610546604, 0.827705756789976], 1e-9); assert_equal (yd2(end-2:end), ... [-17.2913677161117, -17.4801080647878, -17.6688484134638], 1e-9); yd3 = get (h(3), 'YData'); assert_equal (yd3(1:3), [2.19502299518953, 2.00332529668354, 1.81162759817755], 1e-9); assert_equal (yd3(end-2:end), ... [-16.5913514583978, -16.7830491569038, -16.9747468554098], 1e-9); assert_equal (get (h(1), 'DisplayName'), '0.05'); assert_equal (get (h(2), 'DisplayName'), '0.525'); assert_equal (get (h(3), 'DisplayName'), '1'); ax = gca (); assert_equal (get (get (ax, 'Title'), 'String'), 'Interaction of x1 and x2'); assert_equal (get (get (ax, 'XLabel'), 'String'), 'x2'); assert_equal (get (get (ax, 'YLabel'), 'String'), 'Adjusted y'); close (fig); ***** test ## swapping var1/var2 order swaps roles and title cmi = compact (fitlm (X, y, 'y ~ x1*x2')); fig = figure ('visible', 'off'); h = plotInteraction (cmi, 'x2', 'x1'); assert_equal (numel (h), 11); assert_equal (get (h(1), 'XData'), [-18.8740348676059, 1.76843380852813], 1e-9); assert_equal (get (h(4), 'XData'), ... [-18.5782998846125, -18.8740348676059, -19.1697698505994], 1e-9); assert_equal (get (h(8), 'XData'), ... [1.97967308209488, 1.68393809910143, 1.38820311610799], 1e-9); ax = gca (); assert_equal (get (get (ax, 'Title'), 'String'), 'Interaction of x2 and x1'); assert_equal (get (ax, 'YTickLabel'), ... {'x2: 0.05 to 20'; 'x1=0.05'; 'x1=0.525'; 'x1=1'; ... 'x1: 0.05 to 1'; 'x2=0.05'; 'x2=10.025'; 'x2=20'}); close (fig); ***** test ## interaction effects: variables given as indices into VariableNames cmi = compact (fitlm (X, y, 'y ~ x1*x2')); fig = figure ('visible', 'off'); h = plotInteraction (cmi, 1, 2); assert_equal (numel (h), 11); assert_equal (get (h(1), 'XData'), [1.76843380852813, -18.8740348676059], 1e-9); assert_equal (get (h(1), 'YData'), [1, 7]); ax = gca (); assert_equal (get (get (ax, 'Title'), 'String'), 'Interaction of x1 and x2'); close (fig); ***** test ## interaction effects: explicit axes argument is honored cmi = compact (fitlm (X, y, 'y ~ x1*x2')); fig = figure ('visible', 'off'); axtarget = axes (fig); h = plotInteraction (axtarget, cmi, 'x1', 'x2'); assert_equal (numel (h), 11); assert_equal (isequal (get (h(1), 'Parent'), axtarget), true); assert_equal (isequal (gca (), axtarget), true); close (fig); ***** test ## no interaction term: conditional effects collapse to the main effect cmn = compact (fitlm (X, y, 'y ~ x1 + x2')); fig = figure ('visible', 'off'); h = plotInteraction (cmn, 'x1', 'x2'); xd1 = get (h(1), 'XData'); eff1 = xd1(1); eff2 = xd1(2); assert_equal (eff1, 2.38302891604232, 1e-9); assert_equal (eff2, -19.5277648300125, 1e-9); assert_equal (get (h(4), 'XData'), [eff1, eff1, eff1], 1e-9); assert_equal (get (h(8), 'XData'), [eff2, eff2, eff2], 1e-9); close (fig); ***** test ## categorical by continuous, effects mode xc = (1:30)' / 30; grp = categorical (repmat ({'A';'B';'C'}, 10, 1)); yv = 2*xc + 3*double (grp == 'B') - 1*double (grp == 'C') + ... 1.5*xc.*double (grp == 'B') + 0.3*sin ((1:30)'); tblc = table (yv, xc, grp, 'VariableNames', {'Response','Xc','Group'}); cmdlc = compact (fitlm (tblc, 'Response ~ Xc*Group')); fig = figure ('visible', 'off'); h = plotInteraction (cmdlc, 'Group', 'Xc'); assert_equal (numel (h), 11); assert_equal (get (h(1), 'XData'), [4.7896970899464, 2.32528157787528], 1e-9); assert_equal (get (h(2), 'XData'), [4.56862113373247, 5.01077304616034], 1e-9); assert_equal (get (h(3), 'XData'), [2.02254960835685, 2.62801354739371], 1e-9); assert_equal (get (h(4), 'XData'), ... [4.08328517685389, 4.7896970899464, 5.49610900303892], 1e-9); assert_equal (get (h(5), 'XData'), [3.64076372661607, 4.52580662709171], 1e-9); assert_equal (get (h(6), 'XData'), [4.56862113373247, 5.01077304616034], 1e-9); assert_equal (get (h(7), 'XData'), [5.07555715247022, 5.91666085360761], 1e-9); assert_equal (get (h(8), 'XData'), ... [1.88553612240401, 3.25156621870343, 1.8387423925184], 1e-9); assert_equal (get (h(9), 'XData'), [1.36118897012269, 2.40988327468532], 1e-9); assert_equal (get (h(10), 'XData'), [2.72721906642211, 3.77591337098474], 1e-9); assert_equal (get (h(11), 'XData'), [1.31439524023708, 2.36308954479972], 1e-9); ax = gca (); assert_equal (get (get (ax, 'Title'), 'String'), 'Interaction of Group and Xc'); assert_equal (get (ax, 'YTick'), [1, 2, 3, 4, 7, 8, 9, 10]); assert_equal (get (ax, 'YTickLabel'), ... {'Group: C to B'; 'Xc=0.0333333'; 'Xc=0.516667'; 'Xc=1'; ... 'Xc: 0.033333 to 1'; 'Group=A'; 'Group=B'; 'Group=C'}); close (fig); ***** test ## categorical by continuous, predictions mode xc = (1:30)' / 30; grp = categorical (repmat ({'A';'B';'C'}, 10, 1)); yv = 2*xc + 3*double (grp == 'B') - 1*double (grp == 'C') + ... 1.5*xc.*double (grp == 'B') + 0.3*sin ((1:30)'); tblc = table (yv, xc, grp, 'VariableNames', {'Response','Xc','Group'}); cmdlc = compact (fitlm (tblc, 'Response ~ Xc*Group')); fig = figure ('visible', 'off'); h = plotInteraction (cmdlc, 'Group', 'Xc', 'predictions'); assert_equal (numel (h), 3); xd = get (h(1), 'XData'); assert_equal (numel (xd), 101); assert_equal (xd(1:3), [0.0333333333333333, 0.043, 0.0526666666666667], 1e-9); assert_equal (xd(end-2:end), [0.980666666666667, 0.990333333333333, 1], 1e-9); yd1 = get (h(1), 'YData'); assert_equal (yd1(1:3), [0.107201421526318, 0.126056782750359, 0.144912143974399], 1e-9); assert_equal (yd1(end-2:end), [1.95502682148225, 1.97388218270629, 1.99273754393033], 1e-9); yd2 = get (h(2), 'YData'); assert_equal (yd2(1:3), [3.18658823804771, 3.21910390023474, 3.25161956242178], 1e-9); assert_equal (yd2(end-2:end), [6.37312313237707, 6.4056387945641, 6.43815445675114], 1e-9); yd3 = get (h(3), 'YData'); assert_equal (yd3(1:3), [-0.896696938806178, -0.878309514880994, -0.85992209095581], 1e-9); assert_equal (yd3(end-2:end), [0.905270605861853, 0.923658029787037, 0.942045453712221], 1e-9); assert_equal (get (h(1), 'DisplayName'), 'A'); close (fig); ***** test mi = fitlm (X, y, 'y ~ x1*x2'); cmi = compact (mi); fig1 = figure ('visible', 'off'); ax1 = axes (fig1); h1 = plotInteraction (ax1, mi, 'x1', 'x2'); fig2 = figure ('visible', 'off'); ax2 = axes (fig2); h2 = plotInteraction (ax2, cmi, 'x1', 'x2'); for k = 1:numel (h1) assert_equal (get (h1(k), 'XData'), get (h2(k), 'XData'), 1e-10); endfor close (fig1); close (fig2); ***** test t = anova (cmdl); assert_equal (t.Properties.RowNames, {'x1'; 'x2'; 'Error'}); assert_equal (t.SumSq(1), 0.590865029026421, -1e-9); assert_equal (t.DF(1), 1); assert_equal (t.F(1), 25.9858409294749, -1e-8); assert_equal (t.pValue(1), 8.93779416901828e-05, -1e-8); assert_equal (t.SumSq(2), 42.051825481854, -1e-8); assert_equal (t.F(2), 1849.41059985568, -1e-7); assert_equal (t.pValue(2), 8.6569383058211e-19, -1e-8); assert_equal (t.SumSq(3), 0.386545331386823, -1e-9); assert_equal (t.DF(3), 17); assert_equal (isnan (t.F(3)), true); assert_equal (isnan (t.pValue(3)), true); ***** test ## type 3 on a continuous-only model: no categorical, so deviation coding ## is a no-op and no synthetic design is needed (values from R2024a) xa = [1;2;3;4;5;6;7;8;9;10;1;2;3;4;5;6;7;8;9;10]; xb = [2;1;4;3;6;5;8;7;10;9;2;1;4;3;6;5;8;7;10;9]; yv = 3 + 2*xa - 0.5*xb + 0.4*sin ((1:20)'); c = compact (fitlm (table (xa, xb, yv), 'yv ~ xa + xb')); t = anova (c, 'components', 3); assert_equal (t.Properties.RowNames, {'xa'; 'xb'; 'Error'}); assert_equal (t.SumSq', ... [78.1451599777569, 4.93546634617531, 1.6375633770915], -1e-9); ***** test ## a model missing a lower-order relative is computed, not refused xa = [1;2;3;4;5;6;7;8;9;10;1;2;3;4;5;6;7;8;9;10]; xb = [2;1;4;3;6;5;8;7;10;9;2;1;4;3;6;5;8;7;10;9]; yv = 3 + 2*xa - 0.5*xb + 0.4*sin ((1:20)'); c = compact (fitlm (table (xa, xb, yv), 'yv ~ xa + xa:xb')); t = anova (c, 'components', 3); assert_equal (t.SumSq', ... [42.7962732581896, 1.58706426534189, 4.98596545792161], -1e-9); ***** test ## a categorical beside two numeric predictors: the synthetic design must ## cross them, or its numeric columns come out collinear xa = [1;2;3;4;5;6;7;8;9;10;1;2;3;4;5;6;7;8;9;10]; xb = [2;1;4;3;6;5;8;7;10;9;2;1;4;3;6;5;8;7;10;9]; gc = categorical ([1;1;1;1;1;2;2;2;2;2;3;3;3;3;3;1;2;3;1;2]); yv = 3 + 2*xa - 0.5*xb + 0.4*sin ((1:20)'); c = compact (fitlm (table (xa, xb, gc, yv), 'yv ~ xa + xb + gc')); t = anova (c, 'components', 3); assert_equal (t.Properties.RowNames, {'xa'; 'xb'; 'gc'; 'Error'}); assert_equal (t.SumSq', [70.9172463138446, 4.93563224639584, ... 0.0327536552228964, 1.60480972186862], -1e-9); ***** test ## a categorical interacting with a numeric predictor, beside another xa = [1;2;3;4;5;6;7;8;9;10;1;2;3;4;5;6;7;8;9;10]; xb = [2;1;4;3;6;5;8;7;10;9;2;1;4;3;6;5;8;7;10;9]; gc = categorical ([1;1;1;1;1;2;2;2;2;2;3;3;3;3;3;1;2;3;1;2]); yv = 3 + 2*xa - 0.5*xb + 0.4*sin ((1:20)'); c = compact (fitlm (table (xa, xb, gc, yv), 'yv ~ xa*gc + xb')); t = anova (c, 'components', 3); assert_equal (t.SumSq', [69.1671592639563, 4.32040128576299, ... 0.106963060253346, 0.141990871527191, 1.46281885034151], -1e-9); ***** test ## the compact table matches the full model's, term for term xa = [1;2;3;4;5;6;7;8;9;10;1;2;3;4;5;6;7;8;9;10]; xb = [2;1;4;3;6;5;8;7;10;9;2;1;4;3;6;5;8;7;10;9]; gc = categorical ([1;1;1;1;1;2;2;2;2;2;3;3;3;3;3;1;2;3;1;2]); yv = 3 + 2*xa - 0.5*xb + 0.4*sin ((1:20)'); m = fitlm (table (xa, xb, gc, yv), 'yv ~ xa + xb + gc'); assert_equal (anova (compact (m), 'components', 3).SumSq, ... anova (m, 'components', 3).SumSq, -1e-9); ***** test t = anova (cmdl, 'components', 2); assert_equal (t.SumSq(1), 0.590865029026421, -1e-9); assert_equal (t.SumSq(2), 42.051825481854, -1e-8); ***** test t = anova (cmdl, 'components', 1); assert_equal (t.SumSq(1), 541.472049188541, -1e-6); assert_equal (t.F(1), 23813.5713686671, -1e-6); assert_equal (t.pValue(1), 3.41699381541991e-28, -1e-8); assert_equal (t.SumSq(2), 42.051825481854, -1e-8); ***** test t = anova (cmdl, 'summary'); assert_equal (t.Properties.RowNames, {'Total'; 'Model'; 'Residual'}); assert_equal (t.SumSq(1), 583.910420002346, -1e-8); assert_equal (t.DF(1), 19); assert_equal (isnan (t.F(1)), true); assert_equal (t.SumSq(2), 583.523874670959, -1e-8); assert_equal (t.DF(2), 2); assert_equal (t.F(2), 12831.4909842738, -1e-6); assert_equal (t.pValue(2), 9.48988083209278e-28, -1e-8); assert_equal (t.SumSq(3), 0.386545331386823, -1e-9); assert_equal (t.DF(3), 17); ***** test t1 = anova (cmdl, 'oldcomponents'); t2 = anova (cmdl, 'newcomponents'); assert_equal (t1.SumSq(1), 0.590865029026421, -1e-9); assert_equal (t2.SumSq(2), 42.051825481854, -1e-8); ***** test t = anova (cmdl, 'summary', 2); assert_equal (t.Properties.RowNames, {'Total'; 'Model'; 'Residual'}); assert_equal (t.SumSq(2), 583.523874670959, -1e-8); ***** test a = categorical ([1;1;2;1;2;1;1;2;1;1;2;1;2;2;1;1;2;1;1;2]); b = categorical ([1;2;1;1;2;2;1;1;2;1;1;2;2;1;2;1;1;2;2;1]); z = (1:20)' / 10; w = 2*(a=='2') + 1.5*(b=='2') + 0.7*z + 0.9*(a=='2').*(b=='2') + ... [0.1;-0.2;0.05;0.15;-0.1;0.2;-0.05;0.1;0.0;-0.15; ... 0.1;0.05;-0.2;0.15;0.0;-0.1;0.05;0.2;-0.05;0.1]; t2 = table (a, b, z, w); c = compact (fitlm (t2, 'w ~ a*b')); t = anova (c); assert_equal (t.Properties.RowNames, {'a'; 'b'; 'a:b'; 'Error'}); assert_equal (t.SumSq(1), 26.0224323327611, -1e-8); assert_equal (t.F(1), 138.504723473417, -1e-7); assert_equal (t.pValue(1), 2.72592668860933e-09, -1e-8); assert_equal (t.SumSq(2), 15.2365308176098, -1e-8); assert_equal (t.SumSq(3), 0.0142868014375561, -1e-6); assert_equal (t.SumSq(4), 3.00609904761905, -1e-8); assert_equal (t.DF(4), 16); ***** test a = categorical ([1;1;2;1;2;1;1;2;1;1;2;1;2;2;1;1;2;1;1;2]); b = categorical ([1;2;1;1;2;2;1;1;2;1;1;2;2;1;2;1;1;2;2;1]); z = (1:20)' / 10; w = 2*(a=='2') + 1.5*(b=='2') + 0.7*z + 0.9*(a=='2').*(b=='2') + ... [0.1;-0.2;0.05;0.15;-0.1;0.2;-0.05;0.1;0.0;-0.15; ... 0.1;0.05;-0.2;0.15;0.0;-0.1;0.05;0.2;-0.05;0.1]; t2 = table (a, b, z, w); c = compact (fitlm (t2, 'w ~ a*b')); t = anova (c, 'components', 1); assert_equal (t.SumSq(1), 16.354083333333, -1e-7); assert_equal (t.F(1), 87.0448142886636, -1e-7); assert_equal (t.pValue(1), 7.14746180184192e-08, -1e-8); ***** test a = categorical ([1;1;2;1;2;1;1;2;1;1;2;1;2;2;1;1;2;1;1;2]); b = categorical ([1;2;1;1;2;2;1;1;2;1;1;2;2;1;2;1;1;2;2;1]); z = (1:20)' / 10; w = 2*(a=='2') + 1.5*(b=='2') + 0.7*z + 0.9*(a=='2').*(b=='2') + ... [0.1;-0.2;0.05;0.15;-0.1;0.2;-0.05;0.1;0.0;-0.15; ... 0.1;0.05;-0.2;0.15;0.0;-0.1;0.05;0.2;-0.05;0.1]; t2 = table (a, b, z, w); c = compact (fitlm (t2, 'w ~ a + a:b')); t = anova (c); assert_equal (t.Properties.RowNames, {'a'; 'a:b'; 'Error'}); assert_equal (t.SumSq(1), 16.3540833333333, -1e-8); assert_equal (t.F(1), 22.011053580241, -1e-7); assert_equal (t.SumSq(2), 5.62601666666666, -1e-8); assert_equal (t.F(2), 7.57208776360618, -1e-7); assert_equal (t.SumSq(3), 12.6309, -1e-6); assert_equal (t.DF(3), 17); ***** test a = categorical ([1;1;2;1;2;1;1;2;1;1;2;1;2;2;1;1;2;1;1;2]); b = categorical ([1;2;1;1;2;2;1;1;2;1;1;2;2;1;2;1;1;2;2;1]); z = (1:20)' / 10; w = 2*(a=='2') + 1.5*(b=='2') + 0.7*z + 0.9*(a=='2').*(b=='2') + ... [0.1;-0.2;0.05;0.15;-0.1;0.2;-0.05;0.1;0.0;-0.15; ... 0.1;0.05;-0.2;0.15;0.0;-0.1;0.05;0.2;-0.05;0.1]; t2 = table (a, b, z, w); c = compact (fitlm (t2, 'w ~ a + b - 1')); t = anova (c); assert_equal (t.SumSq(1), 63.3745141509434, -1e-8); assert_equal (t.F(1), 178.349190204051, -1e-7); assert_equal (t.SumSq(2), 15.2365308176101, -1e-8); assert_equal (t.SumSq(3), 3.02038584905660, -1e-8); assert_equal (t.DF(3), 17); ***** test a = categorical ([1;1;2;1;2;1;1;2;1;1;2;1;2;2;1;1;2;1;1;2]); b = categorical ([1;2;1;1;2;2;1;1;2;1;1;2;2;1;2;1;1;2;2;1]); z = (1:20)' / 10; w = 2*(a=='2') + 1.5*(b=='2') + 0.7*z + 0.9*(a=='2').*(b=='2') + ... [0.1;-0.2;0.05;0.15;-0.1;0.2;-0.05;0.1;0.0;-0.15; ... 0.1;0.05;-0.2;0.15;0.0;-0.1;0.05;0.2;-0.05;0.1]; wt = [1.2;0.8;1.5;1.0;0.9;1.1;1.3;0.7;1.0;1.4; ... 0.8;1.2;1.0;1.1;0.9;1.3;0.7;1.5;1.0;1.2]; t2 = table (a, b, z, w); c = compact (fitlm (t2, 'w ~ a + b', 'Weights', wt)); t = anova (c); assert_equal (t.SumSq(1), 26.6364861423312, -1e-8); assert_equal (t.F(1), 134.770391630163, -1e-7); assert_equal (t.SumSq(2), 17.4880599694592, -1e-8); assert_equal (t.SumSq(3), 3.35993877395756, -1e-8); assert_equal (t.DF(3), 17); ***** test g = categorical ([1;1;1;1;1;2;2;2;2;2;2;2;2;2;3;3;3;3;3;3]); w = [2.1;1.9;2.3;2.0;1.8;4.1;4.3;3.9;4.0;4.2; ... 4.4;3.8;4.1;4.0;6.1;5.9;6.3;6.0;5.8;6.2]; t2 = table (g, w); c = compact (fitlm (t2, 'w ~ g')); t = anova (c); assert_equal (t.Properties.RowNames, {'g'; 'Error'}); assert_equal (t.DF(1), 2); assert_equal (t.SumSq(1), 44.3761111111084, -1e-6); assert_equal (t.F(1), 616.446794988158, -1e-6); ***** test g3 = categorical ([1;1;1;1;2;2;2;3;3;3;3;1;2;3]); g2 = categorical ([1;1;2;2;1;2;2;1;1;2;2;2;1;1]); w = [10;12;15;14;9;11;13;16;18;20;22;17;10;19]; t2 = table (g3, g2, w); c = compact (fitlm (t2, 'w ~ g3*g2')); t = anova (c, 'components', 3); assert_equal (t.Properties.RowNames, {'g3'; 'g2'; 'g3:g2'; 'Error'}); assert_equal (t.SumSq(1), 176.678431372552, -1e-6); assert_equal (t.F(1), 44.6345510835922, -1e-6); assert_equal (t.SumSq(2), 38.7604166666673, -1e-6); assert_equal (t.SumSq(3), 1.85490196078435, -1e-6); assert_equal (t.SumSq(4), 15.8333333333333, -1e-8); assert_equal (t.DF(4), 8); ***** test g = categorical ([1;1;1;1;2;2;2;2;3;3;3;3]); z = (1:12)' / 2; w = 5 + 2*(g=='2') + 4*(g=='3') + 0.3*z; w(10) = w(10) + 20; t2 = table (g, z, w); c = compact (fitlm (t2, 'w ~ g + z', 'RobustOpts', 'on')); t = anova (c, 'components', 3); assert_equal (t.SumSq(1), 3.35664335664336, -1e-8); assert_equal (t.F(1), 0.0801017164653529, -1e-8); assert_equal (t.SumSq(2), 0.337499999999999, -1e-8); assert_equal (t.SumSq(3), 167.619047619048, -1e-6); assert_equal (t.DF(3), 8); ***** test z = [25;31;42;29;55;38;46;33;27;50;41;36;48;30;44]; g = categorical ({'M';'F';'F';'M';'M';'F';'M';'F';'F';'M';'F';'M';'F';'M';'F'}); w = [118;122;135;120;150;128;140;124;119;145;130;126;138;121;136]; t2 = table (z, g, w); c = compact (fitlm (t2, 'w ~ g*z')); t = anova (c, 'components', 3); assert_equal (t.Properties.RowNames, {'z'; 'g'; 'z:g'; 'Error'}); assert_equal (t.SumSq(1), 1086.93049009449, -1e-6); assert_equal (t.F(1), 525.990068941166, -1e-6); assert_equal (t.SumSq(2), 3.73180668223453, -1e-8); assert_equal (t.SumSq(3), 7.05971182791548, -1e-8); assert_equal (t.SumSq(4), 22.7309147016933, -1e-8); assert_equal (t.DF(4), 11); ***** test z = [25;31;42;29;55;38;46;33;27;50;41;36;48;30;44]; g = categorical ({'M';'F';'F';'M';'M';'F';'M';'F';'F';'M';'F';'M';'F';'M';'F'}); w = [118;122;135;120;150;128;140;124;119;145;130;126;138;121;136]; t2 = table (z, g, w); c = compact (fitlm (t2, 'w ~ g + z^2')); t = anova (c, 'summary'); assert_equal (t.Properties.RowNames, ... {'Total'; 'Model'; '. Linear'; '. Nonlinear'; 'Residual'}); assert_equal (t.SumSq(2), 1394.52505797828, -1e-6); assert_equal (t.F(2), 241.097329241452, -1e-7); assert_equal (t.SumSq(3), 1385.94270680373, -1e-6); assert_equal (t.SumSq(4), 8.58235117455061, -1e-8); assert_equal (t.SumSq(5), 21.2082753550521, -1e-8); assert_equal (t.DF(5), 11); ***** error CompactLinearModel (123) ***** error cmdl(1) ***** error cmdl{1} ***** error cmdl.NotAProperty ***** error cmdl.Fitted ***** error cmdl.ObservationInfo ***** error cmdl.Steps ***** error coefCI (cmdl, 0.05, 'extra') ***** error coefCI (cmdl, 1.5) ***** error coefCI (cmdl, -0.1) ***** error coefCI (cmdl, NaN) ***** error coefCI (cmdl, [0.01 0.05]) ***** error coefCI (cmdl, 'abc') ***** error coefTest (cmdl, [1 0]) ***** error coefTest (cmdl, 'abc') ***** error coefTest (cmdl, [0 1 0], 'abc') ***** error coefTest (cmdl, [0 1 0; 0 0 1], [1]) ***** error coefTest (cmdl, [0 NaN 0]) ***** error coefTest (cmdl, [0 1 0], 0, 'extra') ***** error [a, b, c, d] = coefTest (cmdl) ***** error predict (cmdl) ***** error predict (cmdl, [0.5 0.25], 'BadOption', 1) ***** error predict (cmdl, [0.5 0.25], 'Prediction', 'bad') ***** error predict (cmdl, ones (3, 5)) ***** error predict (cmdl, ones (3, 1)) ***** error predict (cmdl, table ([1;2], 'VariableNames', {'z'})) ***** error random (cmdl) ***** error random (cmdl, [0.5 0.25], 'extra') ***** error random (cmdl, ones (3, 5)) ***** error random (cmdl, []) ***** error feval (cmdl) ***** error feval (cmdl, [0.5;1.0], [0.25;1.0], [0.1;0.2]) ***** error feval (cmdl, ones (3, 1)) ***** error feval (cmdl, [0.5;1.0;0.2], [0.25;1.0]) ***** error feval (cmdl, table ([1;2], 'VariableNames', {'z'})) ***** error feval (cmdl, []) ***** error feval (cmdl, '2500', 0.25) ***** error plotEffects (cmdl, 'extra') ***** error plotEffects (cmdl, 'a', 'b') ***** error plotEffects (compact (fitlm (X(:,1), y, 'constant'))) ***** error plotInteraction (cmdl) ***** error plotInteraction (cmdl, 'x1') ***** error plotInteraction (cmdl, 'x1', 'x2', 'badtype') ***** error plotInteraction (cmdl, 'x1', 'x2', 'effects', 'extra') ***** error plotInteraction (cmdl, 'z', 'x2') ***** error plotInteraction (cmdl, 'x1', 'z') ***** error plotInteraction (cmdl, 99, 'x2') ***** error plotInteraction (cmdl, 1.5, 'x2') ***** error plotInteraction (cmdl, 'y', 'x2') ***** error plotInteraction (cmdl, 'x1', 'y') ***** error plotInteraction (cmdl, 'x1', 'x1') ***** error anova (cmdl, 'components', 'h', 'extra') ***** error anova (cmdl, 'bogus') ***** error anova (cmdl, 'components', 4) 144 tests, 144 passed, 0 known failure, 0 skipped [inst/makima.m] >>>>> /build/reproducible-path/octave-statistics-2.0.0/inst/makima.m ***** test ## Basic linear-like data x = [1; 2; 3; 4]; y = [2; 4; 6; 8]; xi = [1.5; 2.5; 3.5]; yi = makima (x, y, xi); assert_equal (yi, [3; 5; 7], 1e-12); ***** test ## Nonlinear dataset (finite check) x = [0; 1; 2; 3; 4]; y = [0; 1; 0; 1; 0]; xi = linspace (0,4,20)'; yi = makima (x, y, xi); assert_equal (all (isfinite (yi)), true); ***** test ## pp structure output x = [1; 2; 3; 4]; y = [2; 4; 6; 8]; pp = makima (x, y); assert_equal (isstruct (pp), true); assert_equal (strcmp (pp.form, 'pp'), true); assert_equal (pp.pieces, 3); assert_equal (pp.order, 4); ***** test ## Matrix y input. x = [1; 3; 5]; y = [1 3 2; 2 4 6]; xi = 2; yi = makima (x, y, xi); assert_equal (size (yi), [2, 1]); assert_equal (all (isfinite (yi)), true); assert_equal (yi(1), 2.304086538461538, 1e-12); assert_equal (yi(2), 3.000000000000000, 1e-12); ***** test ## Extrapolation through default method. x = [1; 2; 3]; y = [5; 10; 15]; xi = [0; 4]; yi = makima (x, y, xi); assert_equal (all (isfinite (yi)), true); assert_equal (yi, [0; 20], 1e-12); ***** test ## Complex interpolation. x = [1; 2; 4]; y = [1+2i; 2+3i; 4+8i]; xi = 3; yi = makima (x, y, xi); assert_equal (yi, 3 + 5.09767206477733i, 1e-12); assert_equal (iscomplex (yi), true); ***** test ## Two-point interpolation. x = [1; 5]; y = [10; 30]; xi = 3; yi = makima (x, y, xi); assert_equal (yi, 20, 1e-12); ***** test ## Single Precision Input. x = single ([1; 2; 3]); y = single ([10; 20; 30]); xi = single (1.5); yi = makima (x, y, xi); assert_equal (isa (yi, 'single'), true); assert_equal (yi, single (15), 1e-6); ***** test ## Row vector inputs. x = [1 2 3]; y = [4 5 6]; xi = [1.5 2.5]; yi = makima (x, y, xi); assert_equal (yi, [4.5 5.5], 1e-12); ***** test ## Step function. x = [1 2 3 4 5 6]; y = [0 0 1 1 0 0]; xi = [2.5 3.5 4.5]; yi = makima (x, y, xi); expected_11 = [0.5000, 1.1250, 0.5000]; assert_equal (yi, expected_11, 1e-12); ***** test ## Runge function (Oscillation Check) x = linspace (-1, 1, 7)'; y = 1 ./ (1 + 25 * x.^2); xi = [-0.5; 0.1; 0.5]; yi = makima (x, y, xi); expected_12 = [0.148690385982729; 0.857734549516009; 0.148690385982729]; assert_equal (yi, expected_12, 1e-12); ***** test ## Constant Slopes / Zero Weights x = [1; 2; 3; 4; 5]; y = [1; 1; 1; 1; 1]; xi = 3.5; yi = makima (x, y, xi); expected_13 = [1]; assert_equal (yi, expected_13, 1e-12); ***** test ## Empty xq input x = [1; 2; 3]; y = [4; 5; 6]; xi = []; yi = makima (x, y, xi); assert_equal (isempty (yi), true); assert_equal (! (iscolumn (yi)), true); ***** test ## Wide range of y-values x = [1e-10; 2e-10; 3e-10; 4e-10]; y = [1e10; 2e10; 3e10; 4e10]; xi = 2.5e-10; yi = makima (x, y, xi); assert_equal (yi, 2.5e10, 1e-12); ***** test ## Single column matrix input. x = [1; 2; 3]; y = [10; 20; 30]; xi = [1.5 2.5]; % Row input yi = makima (x, y, xi); assert_equal (yi, [15 25], 1e-12); assert_equal (isrow (yi), true); ***** test ## Evaluate pp structure with ppval x = [1; 2; 3; 4]; y = [2; 4; 6; 8]; xi = [1.5; 2.5; 3.5]; pp = makima (x, y); yi_ppval = ppval (pp, xi); yi_direct = makima (x, y, xi); assert_equal (yi_ppval, yi_direct, 1e-12); ***** test ## xq is a 2x2 matrix x = [1; 2; 3; 4; 5]; y = [10; 20; 15; 5; 25]; xq = [1.5, 2.5; 3.5, 4.5]; yi = makima (x, y, xq); assert_equal (size (yi), [2, 2]); expected = [16.85897435897436, 18.22916666666667; 9.81182795698925, 10.84522332506203]; assert_equal (yi, expected, 1e-12); ***** test ## xq is a 3D array x = [1; 2; 3; 4; 5]; y = [10; 20; 15; 5; 25]; xq = ones (2, 2, 2) * 2.5; yi = makima (x, y, xq); assert_equal (size (yi), [2, 2, 2]); ***** test ## pp structure with matrix y input x = [1; 3; 5]; y = [1 3 2; 2 4 6]; pp = makima (x, y); assert_equal (isstruct (pp), true); assert_equal (pp.pieces, 2); assert_equal (pp.dim, 2); yi_ppval = ppval (pp, 2); yi_direct = makima (x, y, 2); assert_equal (yi_ppval, yi_direct, 1e-12); ***** test ## y is a 3D array [2x3x4] and x is length 4 x = [1, 2, 3, 4]; xq = [1.5, 2.5, 3.5]; y3 = reshape (1:24, [2, 3, 4]); yi = makima (x, y3, xq); assert_equal (size (yi), [2, 3, 3]); ***** test ## Unsorted 'x' inputs x_unsorted = [3; 1; 2; 4]; y_unsorted = [9; 1; 4; 16]; xq = [1.5; 2.5]; x_sorted = [1; 2; 3; 4]; y_sorted = [1; 4; 9; 16]; assert_equal (makima (x_unsorted, y_unsorted, xq), makima (x_sorted, y_sorted, xq), 1e-12); ***** test ## Complex piecewise polynomial (pp) structure x = [1 2 3]; y = [1 4 9] + 1i * [2 8 18]; pp = makima (x, y); assert_equal (isstruct (pp), true); assert_equal (iscomplex (pp.coefs), true); assert_equal (ppval (pp, 1.5), makima (x, y, 1.5), 1e-12); ***** test ## N-dimensional y (3D) with N-dimensional xq (2x2 matrix) x = [1 2 3 4]; y3 = reshape (1:24, [2 3 4]); xq = [1.5 2.5; 3.5 1.5]; yi = makima (x, y3, xq); assert_equal (size (yi), [2 3 2 2]); ***** test ## 2-point pp struct x = [1; 5]; y = [10; 30]; pp = makima (x, y); assert_equal (pp.pieces, 1); assert_equal (pp.order, 4); assert_equal (ppval (pp, 3), 20, 1e-12); ***** test ## Exact Collinearity x = [1 2 3 4]; y = [2 4 6 8]; xi = 2.5; yi = makima (x, y, xi); assert_equal (yi, 5, 1e-12); ***** test ## Extrapolation check. x = [1; 2; 3]; y = [5; 10; 15]; xi = [0; 4]; yi = makima (x, y, xi, 'extrap'); assert_equal (all (isfinite (yi)), true); assert_equal (yi, [0; 20], 1e-12); ***** test ## NaN entry in y is dropped before the fit. warning ("off", "local"); x = [1; 2; 3; 4; 5]; y = [1; NaN; 3; 4; 5]; xq = [1.5; 2.5; 3.5; 4.5]; yi = makima (x, y, xq); assert_equal (yi, [1.5; 2.5; 3.5; 4.5], 1e-12); warning: makima: NaN entries in X or Y have been ignored. warning: called from makima at line 107 column 5 __test__ at line 8 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 5022 column 2 ***** warning ... makima ([1; 2; NaN; 4; 5], [1; 2; 3; 4; 5], 1.5); ***** test ## A NaN in one series drops that sample point from every series, so a ## series with no NaN of its own is refitted without it. Fitted alone, ## the first row would give 5.535714286 at both query points. warning ("off", "local"); y = [0, 0, 10, 0, 0; 1, NaN, 3, 4, 5]; yi = makima (1:5, y, [2.5, 3.5]); assert_equal (yi(1,:), [10.6399, 4.9887], 1e-4); assert_equal (yi(2,:), [2.5, 3.5], 1e-12); warning: makima: NaN entries in X or Y have been ignored. warning: called from makima at line 107 column 5 __test__ at line 8 column 2 test at line 685 column 11 /tmp/tmp.3ZzRcRi7mQ at line 5022 column 2 ***** error makima ([1 1 2], [3 4 5], 1.5) ***** error makima (1) ***** error makima (1, 2, 1.5) ***** error makima ([1 2 3 4], [1 2 3 4 5], 2) ***** error makima ([1 2 3], [1 2 3], 2, 'linear') ***** error makima ([1 2 3], [1 2 3], 2, 'extrap', 'too_many') 35 tests, 35 passed, 0 known failure, 0 skipped Checking C++ files ... [src/__knnselect__.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/__knnselect__.cc ***** test ## The result is sort's, not an approximation of it. D = [3, 1, 2, 1; 5, 5, 5, 5; 9, 8, 1, 2; 0, -1, -1, 4]; [sv, so] = sort (D, 2); for k = 1:4 [idx, dst] = __knnselect__ (D, k); assert_equal (idx, so(:,1:k)); assert_equal (dst, sv(:,1:k)); endfor ***** test ## Ties keep the lower column first, as a stable sort does. [idx, dst] = __knnselect__ ([5, 5, 5, 5], 3); assert_equal (idx, [1, 2, 3]); assert_equal (dst, [5, 5, 5]); ***** test ## A NaN sorts after every number and never displaces one. [idx, dst] = __knnselect__ ([3, NaN, 1, NaN, 2], 3); assert_equal (idx, [3, 5, 1]); assert_equal (dst, [1, 2, 3]); ***** test ## A row of nothing but NaN keeps them in column order. [idx, dst] = __knnselect__ ([NaN, NaN, NaN], 2); assert_equal (idx, [1, 2]); assert_equal (isnan (dst), [true, true]); ***** test ## Inf is a value like any other and comes before NaN. [idx, dst] = __knnselect__ ([Inf, NaN, 2, -Inf], 3); assert_equal (idx, [4, 3, 1]); assert_equal (dst, [-Inf, 2, Inf]); ***** test ## K equal to the width returns the whole row, sorted. [idx, dst] = __knnselect__ ([4, 2, 9, 1], 4); assert_equal (idx, [4, 2, 1, 3]); assert_equal (dst, [1, 2, 4, 9]); ***** test ## Single distances come back single; the indices stay double. [idx, dst] = __knnselect__ (single ([4, 2, 9, 1]), 2); assert_equal (class (dst), 'single'); assert_equal (class (idx), 'double'); assert_equal (dst, single ([1, 2])); ***** test ## It agrees with sort over random matrices at every width of K. rand ("seed", 42); for t = 1:50 A = round (rand (6, 9) * 4); k = 1 + mod (t, 9); [idx, dst] = __knnselect__ (A, k); [sv, so] = sort (A, 2); assert_equal (idx, so(:,1:k)); assert_equal (dst, sv(:,1:k)); endfor ***** error __knnselect__ (ones (2, 2)) ***** error<__knnselect__: DIST must be a real numeric matrix.> ... __knnselect__ ({1, 2}, 1) ***** error<__knnselect__: DIST must be a real numeric matrix.> ... __knnselect__ (ones (2, 2) * i, 1) ***** error<__knnselect__: K must be a real scalar.> ... __knnselect__ (ones (2, 2), [1, 2]) ***** error<__knnselect__: K must be an integer between 1 and columns \(DIST\).> ... __knnselect__ (ones (2, 3), 0) ***** error<__knnselect__: K must be an integer between 1 and columns \(DIST\).> ... __knnselect__ (ones (2, 3), 4) ***** error<__knnselect__: K must be an integer between 1 and columns \(DIST\).> ... __knnselect__ (ones (2, 3), 1.5) 15 tests, 15 passed, 0 known failure, 0 skipped [src/gamboostpairs.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/gamboostpairs.cc ***** test ## Every pair is scored once, in nchoosek order, and the grid is reported. x = randn (200, 4); r = randn (200, 1); S = gamboostpairs (x, r); assert_equal (size (S.Pairs), [6, 2]); assert_equal (S.Pairs, nchoosek (1:4, 2)); assert_equal (numel (S.F), 6); assert_equal (numel (S.BinEdges), 4); ***** test ## The detection grid is fixed at eight equal-frequency bins, so seven cut ## points, whatever the sample size. MATLAB reports seven at 60, 250, 1000 ## and 4000 observations alike. for n = [60, 250, 1000] S = gamboostpairs (randn (n, 2), randn (n, 1)); assert_equal (numel (S.BinEdges{1}), 7); endfor ***** test ## The cut points are the octiles, which is what MATLAB's coincide with. x = [(1:800)', (1:800)']; S = gamboostpairs (x, randn (800, 1)); q = linspace (0, 1, 9); assert_equal (S.BinEdges{1}, quantile (x(:,1), q(2:end-1)), 1); ***** test ## A planted interaction outscores every pair that carries none. The ## response depends on x1 * x2 alone, so that pair must rank first. rand ('seed', 7); randn ('seed', 7); x = randn (400, 4); r = x(:,1) .* x(:,2) + 0.1 * randn (400, 1); S = gamboostpairs (x, r); [~, best] = max (S.F); assert_equal (S.Pairs(best,:), [1, 2]); ***** test ## Structureless residuals score low: an F ratio near one is what a pair ## with no interaction should give, and the planted pair above is orders ## above it. randn ('seed', 11); S = gamboostpairs (randn (400, 3), randn (400, 1)); assert_equal (max (S.F) < 5, true); ***** test ## A pair with nothing to explain scores zero rather than a NaN: a constant ## residual leaves no within-cell scatter to divide by. S = gamboostpairs (randn (50, 2), ones (50, 1)); assert_equal (S.F, 0); assert_equal (S.DF1, 0); ***** test ## Degrees of freedom follow the occupied grid, not its nominal size. x = [(1:200)', (1:200)']; S = gamboostpairs (x, randn (200, 1)); assert_equal (S.DF2 > 0, true); assert_equal (S.DF1 > 0, true); ***** test ## The detection grid places cut k at the midpoint of the sorted values at ## positions ceil (k*n/8) and ceil (k*n/8) + 1, as R2024a does. k = (1:300)'; S = gamboostpairs ([sin(k), cos(2 * k)], k / 300); e = [-0.92677666250429258, -0.70864210760326785, -0.37141809543750642, ... 0.0044253079075048506, 0.38778038850556862, 0.70866977421076549, ... 0.92681284546023668]; assert_equal (S.BinEdges{1}, e, 1e-15); ***** test ## A categorical predictor keeps every level as a bin of its own. k = (1:240)'; S = gamboostpairs ([mod(k, 12) + 1, sin(k)], cos (k), [true, false]); assert_equal (S.BinEdges{1}, 1.5:11.5); assert_equal (numel (S.BinEdges{2}), 7); ***** error ... gamboostpairs ([1, 2; 3, 4; 5, 6; 7, 8], [1; 2; 3; 4], true) ***** error ... gamboostpairs ([1.5, 2; 3, 4; 5, 6; 7, 8], [1; 2; 3; 4], [true, false]) ***** error gamboostpairs (1) ***** error ... gamboostpairs ('a', [1;2]) ***** error ... gamboostpairs ([1, 2; 3, 4], [1, 2]) ***** error ... gamboostpairs ([1, 2; 3, 4], [1; 2; 3]) ***** error ... gamboostpairs ([1; 2; 3], [1; 2; 3]) 16 tests, 16 passed, 0 known failure, 0 skipped [src/treepredict.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/treepredict.cc ***** test ## Every row of the training data lands where it was counted load fisheriris y = grp2idx (species); o = struct ('NumClasses', 3, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', ... 'MergeLeaves', true, 'Prune', true); T = treetrain (meas, y, ones (150, 1) / 150, o); prob = T.ClassWeight ./ sum (T.ClassWeight, 2); [score, node] = treepredict (meas, T.Children, T.CutPredictorIndex, ... T.CutPoint, prob); assert_equal (size (score), [150, 3]); assert_equal (node(1:12)', 2 * ones (1, 12)); assert_equal (sum (score(:,1)), 50, 1e-12); leaf = T.Children(:,1) == 0; assert_equal (all (leaf(node)), true); ***** test ## A row is stopped by the first node whose predictor it is missing load fisheriris y = grp2idx (species); o = struct ('NumClasses', 3, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', ... 'MergeLeaves', true, 'Prune', true); T = treetrain (meas, y, ones (150, 1) / 150, o); prob = T.ClassWeight ./ sum (T.ClassWeight, 2); q = meas([1, 51, 101, 71], :); q(1,3) = NaN; q(2,:) = NaN; [score, node] = treepredict (q, T.Children, T.CutPredictorIndex, ... T.CutPoint, prob); assert_equal (node', [1, 1, 5, 5]); assert_equal (score(1,:), prob(1,:)); assert_equal (score(3,:), [0, 1/46, 45/46], 1e-12); ***** test ## The value of a regression leaf is its mean g = mod ((1:20)', 3); x = [(1:20)', g]; y = [ones(10,1); 5 * ones(10,1)]; o = struct ('NumClasses', 1, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 19, 'SplitCriterion', 'mse', ... 'MergeLeaves', true, 'Prune', true, 'QEToler', 1e-6); T = treetrain (x, y, ones (20, 1) / 20, o); [yfit, node] = treepredict (x, T.Children, T.CutPredictorIndex, ... T.CutPoint, T.NodeMean); assert_equal (size (yfit), [20, 1]); assert_equal (yfit, y, 1e-12); assert_equal (node', [2 * ones(1, 10), 3 * ones(1, 10)]); ***** test ## A tree of one node answers with that node for every row v = [0.25, 0.75]; [score, node] = treepredict (rand (7, 3), [0, 0], 0, NaN, v); assert_equal (node, ones (7, 1)); assert_equal (score, repmat (v, 7, 1)); ***** test ## One output returns the value alone v = [0.25, 0.75]; got = treepredict (rand (4, 2), [0, 0], 0, NaN, v); assert_equal (got, repmat (v, 4, 1)); ***** test ## A value below the cut point goes left kids = [2, 3; 0, 0; 0, 0]; score = treepredict ([1; 3], kids, [1; 0; 0], [2; NaN; NaN], [0; 10; 20]); assert_equal (score, [10; 20]); ***** test ## A categorical cut sends a row by its level, and stops an unknown one kids = [2, 3; 0, 0; 0, 0]; cats = {[1, 3], 2; [], []; [], []}; [v, node] = treepredict ([1; 2; 3; 4; NaN], kids, [1; 0; 0], ... [NaN; NaN; NaN], [0; 10; 20], cats); assert_equal (v', [10, 20, 10, 0, 0]); assert_equal (node', [2, 3, 2, 1, 1]); ***** error ... treepredict (1, 2, 3, 4); ***** error ... treepredict (1, 2, 3, 4, 5, 6, 7); ***** error ... treepredict (rand (3, 2), [0, 0], 0, NaN, 1, 2); ***** error ... treepredict (rand (3, 2), [0, 0], 0, NaN, 1, cell (2, 2)); ***** error ... treepredict (rand (3, 2), zeros (0, 2), [], [], zeros (0, 1)); ***** error ... treepredict (rand (3, 2), [0, 0, 0], 0, NaN, 1); ***** error ... treepredict (rand (3, 2), [0, 0], [0; 0], NaN, 1); ***** error ... treepredict (rand (3, 2), [0, 0], 0, NaN, [1; 2]); ***** error ... kids = [2, 3; 0, 0; 0, 0]; ... treepredict (rand (3, 2), kids, [5; 0; 0], [1; NaN; NaN], [0; 1; 2]); ***** error ... kids = [2, 9; 0, 0; 0, 0]; ... treepredict (rand (3, 2), kids, [1; 0; 0], [1; NaN; NaN], [0; 1; 2]); 17 tests, 17 passed, 0 known failure, 0 skipped [src/svmpredict.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/svmpredict.cc ***** test # Test 1: Standard C-SVC Prediction (Original Regression Test) [L, D] = libsvmread (file_in_loadpath ("heart_scale.dat")); model = svmtrain (L, D, '-c 1 -g 0.07'); [predict_label, accuracy, dec_values] = svmpredict (L, D, model); assert_equal (size (predict_label), size (dec_values)); assert_equal (accuracy, [86.666, 0.533, 0.533]', [1e-3, 1e-3, 1e-3]'); assert_equal (dec_values(1), 1.225836001973273, 1e-14); assert_equal (dec_values(2), -0.3212992933043805, 1e-14); assert_equal (predict_label(1), 1); ***** test # A single testing instance used to write through a freed pointer, since # Octave stores a 1x1 result as a scalar and matrix_value() then returns a # temporary. Every single-row query must match the batch answer. [L, D] = libsvmread (file_in_loadpath ("heart_scale.dat")); model = svmtrain (L, D, '-c 1 -g 0.07'); [bl, ~, bd] = svmpredict (L, D, model); for i = [1, 2, 7, 130, numel(L)] [l, ~, d] = svmpredict (L(i), D(i,:), model); assert_equal (size (l), [1, 1]); assert_equal (l, bl(i)); assert_equal (d, bd(i), 1e-12); endfor ***** test # Test 2: One-Class Probability (NEW LIBSVM 3.36 FEATURE) [L, D] = libsvmread (file_in_loadpath ("heart_scale.dat")); # Train One-Class (-s 2) with Probability (-b 1) model_oc = svmtrain (L, D, '-s 2 -n 0.1 -g 0.07 -b 1'); assert_equal (isstruct (model_oc), true); # Predict with Probability (-b 1) [pred, acc, probs] = svmpredict (L, D, model_oc, '-b 1'); # Detail Check A: Output must be N x 2 (Column 1: Normal, Column 2: Outlier) assert_equal (size (probs), [length(L), 2]); # Detail Check B: Probabilities must sum to 1.0 for every instance assert_equal (sum (probs, 2), ones (length(L), 1), 1e-5); # Detail Check C: Values must be valid probabilities [0, 1] assert_equal (all (probs >= 0 & probs <= 1, 'all'), true); clear model_oc ***** test # Test 3: One-Class Decision Values (Standard Check) # Verifies that the upgrade didn't break standard One-Class prediction (-b 0) [L, D] = libsvmread (file_in_loadpath ("heart_scale.dat")); model_oc = svmtrain (L, D, '-s 2 -n 0.1 -g 0.07'); [pred, acc, dec] = svmpredict (L, D, model_oc); # Standard One-Class output is N x 1 (Scalar decision values) assert_equal (size (dec), [length(L), 1]); clear model_oc ***** shared L, D, model # Test 4: Error Handling (Original Checks) [L, D] = libsvmread (file_in_loadpath ("heart_scale.dat")); model = svmtrain (L, D, '-c 1 -g 0.07'); ***** error ... [p, a] = svmpredict (L, D, model); ***** error p = svmpredict (L, D); ***** error ... p = svmpredict (single (L), D, model); ***** error p = svmpredict (L, D, 123); 8 tests, 8 passed, 0 known failure, 0 skipped [src/gamboostpredict.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/gamboostpredict.cc ***** test ## The additive prediction is the intercept plus each term's step function. E = {[1.5, 2.5]}; V = {[-1; 0; 2]}; assert_equal (gamboostpredict (E, V, [1; 2; 3], 0), [-1; 0; 2], 1e-14); assert_equal (gamboostpredict (E, V, [1; 2; 3], 0.5), [-0.5; 0.5; 2.5], ... 1e-14); ***** test ## Terms add. E = {[1.5], [10]}; V = {[1; 2], [4; 8]}; assert_equal (gamboostpredict (E, V, [1, 5; 2, 20], 0), [5; 10], 1e-14); ***** test ## A value beyond the fitted range falls in the nearest bin, so a shape ## function is constant outside its data rather than extrapolated. E = {[1.5, 2.5]}; V = {[-1; 0; 2]}; assert_equal (gamboostpredict (E, V, [-100; 100], 0), [-1; 2], 1e-14); ***** test ## A missing value costs that term only. E = {[1.5], [10]}; V = {[1; 2], [4; 8]}; assert_equal (gamboostpredict (E, V, [NaN, 5], 0), 4, 1e-14); ***** test ## A term with no cut points is a constant. E = {zeros(1,0)}; V = {3}; assert_equal (gamboostpredict (E, V, [1; 2; 3], 1), [4; 4; 4], 1e-14); ***** test ## The logistic link returns both class probabilities, and they sum to one. E = {[1.5]}; V = {[-2; 2]}; s = gamboostpredict (E, V, [1; 2], 0, 1); assert_equal (sum (s, 2), [1; 1], 1e-14); assert_equal (s(:,2), 1 ./ (1 + exp ([2; -2])), 1e-14); ***** test ## A model round-trips through its own trainer. x = [1; 2; 3; 4; 5; 6; 7; 8]; y = [0; 0; 0; 0; 1; 1; 1; 1]; M = gamboosttrain (x, y, 1, 30, 1, 1); f = gamboostpredict (M.BinEdges, M.ShapeValues, x, M.Intercept); p = 1 ./ (1 + exp (-f)); assert_equal (M.Residuals, y - p, 1e-12); ***** test ## A pair term adds the value of the cell its two predictors fall in. E = {zeros(1,0), zeros(1,0)}; V = {0, 0}; PE = {{[1.5], [10]}}; PV = {[1, 2; 3, 4]}; X = [1, 5; 1, 20; 2, 5; 2, 20]; assert_equal (gamboostpredict (E, V, X, 0, 0, PE, PV, [1, 2]), ... [1; 2; 3; 4], 1e-14); ***** test ## Interaction terms add to the additive part rather than replacing it. E = {[1.5], zeros(1,0)}; V = {[10; 20], 0}; PE = {{[1.5], [10]}}; PV = {[1, 2; 3, 4]}; X = [1, 5; 2, 20]; assert_equal (gamboostpredict (E, V, X, 100, 0, PE, PV, [1, 2]), ... [111; 124], 1e-14); ***** test ## A pair with either predictor missing contributes nothing, as a tree does ## with a value it cannot place. E = {zeros(1,0), zeros(1,0)}; V = {0, 0}; PE = {{[1.5], [10]}}; PV = {[1, 2; 3, 4]}; assert_equal (gamboostpredict (E, V, [NaN, 5], 0, 0, PE, PV, [1, 2]), 0); ***** test ## A pair with a predictor missing takes the value stored for that case: by ## cell of the other predictor, or one value when both are missing. E = {zeros(1,0), zeros(1,0)}; V = {0, 0}; PE = {{[1.5], [10]}}; PV = {[1, 2; 3, 4]}; PM = {{[5, 6], [7, 8], 9}}; X = [NaN, 5; NaN, 20; 1, NaN; 2, NaN; NaN, NaN; 2, 20]; assert_equal (gamboostpredict (E, V, X, 0, 0, PE, PV, [1, 2], PM), ... [5; 6; 7; 8; 9; 4], 1e-14); ***** test ## The assembled model reproduces what the interaction phase itself ## computed: same residuals, so the stored surfaces and the recentring ## bookkeeping are consistent with the fit they came from. randn ('seed', 42); rand ('seed', 42); X = randn (200, 3); Y = double (rand (200, 1) < 1 ./ (1 + exp (-2 * X(:,1) .* X(:,2)))); M = gamboosttrain (X, Y, 1, 50, 1, 1); f0 = gamboostpredict (M.BinEdges, M.ShapeValues, X, M.Intercept); I = gamboostinter (X, Y, f0, 1, [1, 2], 40, 1, 4); f1 = gamboostpredict (M.BinEdges, M.ShapeValues, X, ... M.Intercept + I.Intercept, 0, I.PairEdges, ... I.PairValues, [1, 2]); assert_equal (Y - 1 ./ (1 + exp (-f1)), I.Residuals, 1e-12); ***** error gamboostpredict ({1}, {1}) ***** error ... gamboostpredict (1, {1}, [1;2], 0) ***** error ... gamboostpredict ({1}, 1, [1;2], 0) ***** error ... gamboostpredict ({1, 2}, {1}, [1;2], 0) ***** error ... gamboostpredict ({[1.5]}, {[1;2]}, 'a', 0) ***** error ... gamboostpredict ({[1.5]}, {[1;2]}, [1, 2], 0) ***** error ... gamboostpredict ({[1.5]}, {[1;2]}, [1;2], [1, 2]) ***** error ... gamboostpredict ({[1.5]}, {[1;2]}, [1;2], 0, 2) ***** error ... gamboostpredict ({[1.5]}, {[1;2;3]}, [1;2], 0) ***** error ... gamboostpredict ({[1.5], [1.5]}, {[1;2], [1;2]}, [1, 1], 0, 0, 1, ... {1}, [1, 2]) ***** error ... gamboostpredict ({[1.5], [1.5]}, {[1;2], [1;2]}, [1, 1], 0, 0, {[1.5]}, ... {[1, 2; 3, 4]}, [1, 2]) ***** error ... gamboostpredict ({[1.5], [1.5]}, {[1;2], [1;2]}, [1, 1], 0, 0, ... {{[1.5], [1, 2]}}, {[1, 2; 3, 4]}, [1, 2]) ***** error ... gamboostpredict ({[1.5], [1.5]}, {[1;2], [1;2]}, [1, 1], 0, 0, ... {[1.5], [1.5]}, {[1, 2; 3, 4]}, [1, 2, 3]) ***** error ... gamboostpredict ({[1.5], [1.5]}, {[1;2], [1;2]}, [1, 1], 0, 0, ... {{[1.5], [1.5]}}, {[1, 2; 3, 4]}, [1, 2], 1) ***** error ... gamboostpredict ({[1.5], [1.5]}, {[1;2], [1;2]}, [1, 1], 0, 0, ... {{[1.5], [1.5]}}, {[1, 2; 3, 4]}, [1, 2], ... {{[1, 2, 3], [1, 2], 0}}) ***** error ... gamboostpredict ({[1.5], [1.5]}, {[1;2], [1;2]}, [1, 1], 0, 0, ... {[1.5], [1.5]}, {[1, 2; 3, 4]}, [1, 2; 1, 2]) 28 tests, 28 passed, 0 known failure, 0 skipped [src/treetrain.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/treetrain.cc ***** test ## The iris tree, grown and then merged, as MATLAB grows it load fisheriris y = grp2idx (species); o = struct ('NumClasses', 3, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', ... 'MergeLeaves', false); T = treetrain (meas, y, ones (150, 1) / 150, o); assert_equal (T.NumNodes, 11); assert_equal (T.NodeSize', [150, 50, 100, 54, 46, 48, 6, 3, 43, 47, 1]); assert_equal (T.CutPredictorIndex', [3, 0, 4, 3, 3, 4, 0, 0, 0, 0, 0]); assert_equal (T.CutPoint([1, 3, 4, 5, 6])', [2.45, 1.75, 4.95, 4.85, 1.65]); ***** test ## MergeLeaves collapses the one pair that lowers no misclassification load fisheriris y = grp2idx (species); o = struct ('NumClasses', 3, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', ... 'MergeLeaves', true); T = treetrain (meas, y, ones (150, 1) / 150, o); assert_equal (T.NumNodes, 9); assert_equal (T.NodeSize', [150, 50, 100, 54, 46, 48, 6, 47, 1]); assert_equal (T.Parent', [0, 1, 1, 3, 3, 4, 4, 6, 6]); ***** test ## A deeper tree, grown until no node can be split further load fisheriris y = grp2idx (species); o = struct ('NumClasses', 3, 'MinParent', 2, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', ... 'MergeLeaves', true); T = treetrain (meas, y, ones (150, 1) / 150, o); assert_equal (T.NumNodes, 17); assert_equal (T.NodeSize', [150, 50, 100, 54, 46, 48, 6, 3, 43, 47, 1, ... 3, 3, 1, 2, 2, 1]); ***** test ## A row missing the split predictor descends to neither child load fisheriris y = grp2idx (species); x = meas; x(51:60, 4) = NaN; o = struct ('NumClasses', 3, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', ... 'MergeLeaves', false); T = treetrain (x, y, ones (150, 1) / 150, o); assert_equal (T.NodeSize', [150, 50, 100, 45, 55, 35, 1, 8, 46, 3, 43]); assert_equal (T.NodeSize(4) - T.NodeSize(6) - T.NodeSize(7), 9); ***** test ## A row missing every predictor is dropped outright load fisheriris y = grp2idx (species); x = meas; x(1:5, :) = NaN; o = struct ('NumClasses', 3, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', ... 'MergeLeaves', false); T = treetrain (x, y, ones (150, 1) / 150, o); assert_equal (T.NodeSize(1), 145); assert_equal (T.NodeSize', [145, 45, 100, 54, 46, 48, 6, 3, 43, 47, 1]); ***** test ## A predictor that is entirely missing is simply never chosen load fisheriris y = grp2idx (species); x = meas; x(:, 2) = NaN; o = struct ('NumClasses', 3, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', ... 'MergeLeaves', false); T = treetrain (x, y, ones (150, 1) / 150, o); assert_equal (T.CutPredictorIndex', [3, 0, 4, 3, 3, 4, 0, 0, 0, 0, 0]); ***** test ## The split is judged on the rows a predictor has, scaled by their share: ## x1 is known for every row and wins, x2 is known for ten and does not y = [1;1;1;1;1;1;1;1;1;2;1;2;2;2;2;2;2;2;2;2]; x2 = NaN (20, 1); x2(1:5) = (1:5)'; x2(12:16) = (6:10)'; o = struct ('NumClasses', 2, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 19, 'SplitCriterion', 'gdi', ... 'MergeLeaves', false); T = treetrain ([(1:20)', x2], y, ones (20, 1) / 20, o); assert_equal (T.CutPredictorIndex(1), 1); assert_equal (T.CutPoint(1), 9.5); assert_equal (T.NodeSize', [20, 9, 11, 2, 9]); ***** test ## MinParent holds a node together and MaxSplits stops the tree load fisheriris y = grp2idx (species); o = struct ('NumClasses', 3, 'MinParent', 60, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', ... 'MergeLeaves', false); assert_equal (treetrain (meas, y, ones (150, 1) / 150, o).NumNodes, 5); o.MinParent = 10; o.MaxSplits = 2; assert_equal (treetrain (meas, y, ones (150, 1) / 150, o).NumNodes, 5); ***** test ## ClassCount counts rows and ClassWeight weighs them, which are the same ## thing only while the weights are load fisheriris y = grp2idx (species); o = struct ('NumClasses', 3, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', ... 'MergeLeaves', true); count = [50, 50, 0, 0, 0, 0, 0, 0, 0; ... 50, 0, 50, 49, 1, 47, 2, 47, 0; ... 50, 0, 50, 5, 45, 1, 4, 0, 1]; T = treetrain (meas, y, ones (150, 1) / 150, o); assert_equal (T.ClassCount', count); assert_equal (sum (T.ClassCount, 2), T.NodeSize); w = [3 * ones(50, 1); ones(100, 1)]; w = w / sum (w); W = treetrain (meas, y, w, o); assert_equal (W.NodeSize', [150, 50, 100, 54, 46, 48, 6, 47, 1]); assert_equal (W.ClassCount', count); prob = W.ClassWeight ./ sum (W.ClassWeight, 2); assert_equal (prob(1,:), [0.6, 0.2, 0.2], 1e-12); ***** test ## A regression carries a leaf value in place of class counts g = zeros (20, 1); x = [(1:20)', g]; y = [ones(10,1); 5 * ones(10,1)]; o = struct ('NumClasses', 1, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 19, 'SplitCriterion', 'mse', ... 'MergeLeaves', true, 'QEToler', 1e-6); T = treetrain (x, y, ones (20, 1) / 20, o); assert_equal (isempty (T.ClassCount), true); assert_equal (isempty (T.ClassWeight), true); ***** test ## A regression tree and its leaf values g = mod ((1:20)', 3); x = [(1:20)', g]; y = [ones(10,1); 5 * ones(10,1)]; o = struct ('NumClasses', 1, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 19, 'SplitCriterion', 'mse', ... 'MergeLeaves', true, 'QEToler', 1e-6); T = treetrain (x, y, ones (20, 1) / 20, o); assert_equal (T.NumNodes, 3); assert_equal (T.NodeSize', [20, 10, 10]); assert_equal (T.NodeMean', [3, 1, 5], 1e-12); assert_equal (T.NodeError', [4, 0, 0], 1e-12); ***** test ## QEToler stops a node whose squared error is a small share of the root's g = mod ((1:40)', 7); x = [(1:40)', g]; y = (1:40)'; o = struct ('NumClasses', 1, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 39, 'SplitCriterion', 'mse', ... 'MergeLeaves', true, 'QEToler', 1e-6); loose = o; loose.QEToler = 0.05; assert_equal (treetrain (x, y, ones (40, 1) / 40, loose).NumNodes ... < treetrain (x, y, ones (40, 1) / 40, o).NumNodes, true); ***** test ## A single class, a single row and identical rows are each one leaf o = struct ('NumClasses', 2, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 19, 'SplitCriterion', 'gdi', ... 'MergeLeaves', true); w = ones (20, 1) / 20; assert_equal (treetrain (rand (20, 2), ones (20, 1), w, o).NumNodes, 1); assert_equal (treetrain ([1, 2], 1, 1, o).NumNodes, 1); y = [ones(10,1); 2*ones(10,1)]; assert_equal (treetrain (ones (20, 2), y, w, o).NumNodes, 1); ***** test ## Sampling every predictor draws nothing and grows the unsampled tree load fisheriris o = struct ('NumClasses', 3, 'MinParent', 2, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', ... 'MergeLeaves', false); w = ones (150, 1) / 150; T = treetrain (meas, grp2idx (species), w, o); o.NumVariablesToSample = 4; o.Seed = 12345; assert_equal (isequaln (treetrain (meas, grp2idx (species), w, o), T), true); ***** test ## The same seed grows the same tree load fisheriris o = struct ('NumClasses', 3, 'MinParent', 2, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', ... 'MergeLeaves', false, 'NumVariablesToSample', 1, 'Seed', 7); w = ones (150, 1) / 150; A = treetrain (meas, grp2idx (species), w, o); B = treetrain (meas, grp2idx (species), w, o); assert_equal (isequaln (A, B), true); ***** test ## Different seeds grow different trees load fisheriris o = struct ('NumClasses', 3, 'MinParent', 2, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', ... 'MergeLeaves', false, 'NumVariablesToSample', 1, 'Seed', 7); w = ones (150, 1) / 150; assert_equal (treetrain (meas, grp2idx (species), w, o).NumNodes, 23); o.Seed = 8; assert_equal (treetrain (meas, grp2idx (species), w, o).NumNodes, 25); ***** test ## A node whose sampled predictor holds no split is a leaf load fisheriris o = struct ('NumClasses', 3, 'MinParent', 2, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', ... 'MergeLeaves', false, 'NumVariablesToSample', 1, 'Seed', 0); X = [ones(150, 1), meas(:, 3)]; T = treetrain (X, grp2idx (species), ones (150, 1) / 150, o); assert_equal (T.NumNodes, 1); ***** test ## A predictor that cannot split is never cut, however the draw falls load fisheriris o = struct ('NumClasses', 3, 'MinParent', 2, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', ... 'MergeLeaves', false, 'NumVariablesToSample', 1, 'Seed', 14); X = [ones(150, 1), meas(:, 3)]; T = treetrain (X, grp2idx (species), ones (150, 1) / 150, o); assert_equal (T.NumNodes, 15); cut = T.CutPredictorIndex(logical (T.IsBranchNode)); assert_equal (all (cut == 2), true); ***** test ## A sampled regression tree is reproduced by its seed load fisheriris o = struct ('NumClasses', 0, 'MinParent', 10, 'MinLeaf', 5, ... 'MaxSplits', 149, 'SplitCriterion', 'mse', ... 'MergeLeaves', false, 'NumVariablesToSample', 1, 'Seed', 3); w = ones (150, 1) / 150; A = treetrain (meas(:, 2:4), meas(:, 1), w, o); B = treetrain (meas(:, 2:4), meas(:, 1), w, o); assert_equal (isequaln (A, B), true); ***** shared o o = struct ('NumClasses', 2, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 19, 'SplitCriterion', 'gdi', ... 'MergeLeaves', true); ***** error treetrain (1, 2, 3); ***** error ... treetrain (1, 2, 3, o, 5); ***** error ... treetrain (rand (10, 2), ones (9, 1), ones (10, 1), o); ***** error ... treetrain (rand (10, 2), ones (10, 1), ones (9, 1), o); ***** error ... bad = setfield (o, 'SplitCriterion', 'twoing'); ... treetrain (rand (10, 2), ones (10, 1), ones (10, 1), bad); ***** error ... bad = setfield (o, 'MinLeaf', 0); ... treetrain (rand (10, 2), ones (10, 1), ones (10, 1), bad); ***** error ... bad = setfield (o, 'MinParent', 0); ... treetrain (rand (10, 2), ones (10, 1), ones (10, 1), bad); ***** error ... bad = setfield (o, 'NumClasses', 0); ... treetrain (rand (10, 2), ones (10, 1), ones (10, 1), bad); ***** error ... treetrain (rand (10, 2), ones (10, 1), [-1; ones(9, 1)], o); ***** error ... treetrain (rand (10, 2), 5 * ones (10, 1), ones (10, 1), o); ***** error ... treetrain (rand (10, 2), zeros (10, 1), ones (10, 1), o); ***** error ... bad = setfield (o, 'NumVariablesToSample', 0); ... treetrain (rand (10, 2), ones (10, 1), ones (10, 1), bad); ***** error ... bad = setfield (o, 'NumVariablesToSample', 1.5); ... treetrain (rand (10, 2), ones (10, 1), ones (10, 1), bad); ***** error ... bad = setfield (o, 'NumVariablesToSample', 3); ... treetrain (rand (10, 2), ones (10, 1), ones (10, 1), bad); ***** error ... bad = setfield (o, 'Seed', -1); ... treetrain (rand (10, 2), ones (10, 1), ones (10, 1), bad); ***** error ... bad = setfield (o, 'Seed', 2.5); ... treetrain (rand (10, 2), ones (10, 1), ones (10, 1), bad); ***** error ... bad = setfield (o, 'Seed', 2^32); ... treetrain (rand (10, 2), ones (10, 1), ones (10, 1), bad); ***** test ## MATLAB parity: two classes order the levels and split them in two k = (0:79)'; c = mod (k, 4) + 1; j = floor (k / 4); y = (c == 1) | (c == 2 & mod (j, 4) != 0) | (c == 3 & mod (j, 4) == 0); o = struct ('NumClasses', 2, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 79, 'SplitCriterion', 'gdi', ... 'MergeLeaves', true, 'CategoricalPredictors', 1); T = treetrain ([c, mod(k * 7, 10)], double (y) + 1, ones (80, 1) / 80, o); assert_equal (T.NumNodes, 3); assert_equal (T.CutCategories(1,:), {[1, 2], [3, 4]}); assert_equal (isnan (T.CutPoint(1)), true); ***** test ## MATLAB parity: a regression orders the levels by their mean response k = (0:99)'; c = mod (k, 5) + 1; means = [3, 1, 4, 1.5, 5]; y = means(c)' + 0.1 * sin (k); o = struct ('NumClasses', 1, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 99, 'SplitCriterion', 'mse', ... 'MergeLeaves', true, 'QEToler', 1e-6, ... 'CategoricalPredictors', 1); T = treetrain ([c, mod(k * 3, 8)], y, ones (100, 1) / 100, o); assert_equal (T.NumNodes, 39); assert_equal (T.CutCategories(1,:), {[2, 4], [1, 3, 5]}); ***** test ## Every named algorithm finds a split of three classes k = (0:119)'; c = mod (k, 6) + 1; y = mod (c + floor (k / 12), 3) + 1; for a = {'exact', 'pullleft', 'pca', 'ovabyclass'} o = struct ('NumClasses', 3, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 1, 'SplitCriterion', 'gdi', ... 'MergeLeaves', false, 'CategoricalPredictors', 1, ... 'AlgorithmForCategorical', a{1}); T = treetrain (c, y, ones (120, 1) / 120, o); assert_equal (sort ([T.CutCategories{1,:}]), 1:6); endfor ***** error ... o = struct ('NumClasses', 2, 'MinParent', 1, 'MinLeaf', 1, ... 'MaxSplits', 1, 'SplitCriterion', 'gdi', ... 'MergeLeaves', false, 'CategoricalPredictors', 3); ... treetrain (ones (4, 2), [1; 1; 2; 2], ones (4, 1), o); ***** error ... o = struct ('NumClasses', 2, 'MinParent', 1, 'MinLeaf', 1, ... 'MaxSplits', 1, 'SplitCriterion', 'gdi', ... 'MergeLeaves', false, 'MaxNumCategories', -1); ... treetrain (ones (4, 2), [1; 1; 2; 2], ones (4, 1), o); ***** error ... o = struct ('NumClasses', 2, 'MinParent', 1, 'MinLeaf', 1, ... 'MaxSplits', 1, 'SplitCriterion', 'gdi', ... 'MergeLeaves', false, 'AlgorithmForCategorical', 'bogus'); ... treetrain (ones (4, 2), [1; 1; 2; 2], ones (4, 1), o); 42 tests, 42 passed, 0 known failure, 0 skipped [src/fcnntrain.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/fcnntrain.cc ***** shared X, Y, MODEL load fisheriris X = meas; Y = grp2idx (species); ***** error ... model = fcnntrain (X, Y); ***** error ... [Q, W] = fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain (complex (X), Y, 10, "sigmoid", "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain ({X}, Y, 10, "sigmoid", "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain ([], Y, 10, "sigmoid", "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain (X, complex (Y), 10, "sigmoid", "sigmoid", 0.01, 0.025, 50, false); ***** error ... fcnntrain (X, {Y}, 10, "sigmoid", "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain (X, [], 10, "sigmoid", "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain (X, Y([1:50]), 10, "sigmoid", "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain (X, Y - 1, 10, "sigmoid", "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain (X, Y, [10; 5], "sigmoid", "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain (X, Y, "10", "sigmoid", "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain (X, Y, {10}, "sigmoid", "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain (X, Y, complex (10), "sigmoid", "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain (X, Y, 10, [1; 1], "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain (X, Y, 10, {1, 1}, "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain (X, Y, 10, complex ([1, 1]), "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain (X, Y, 10, {"sigmoid", "relu"}, "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain (X, Y, [10, 0, 5], "sigmoid", "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain (X, Y, 10, "sgmoid", "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain (X, Y, 10, {"bogus"}, "sigmoid", 1, 0.025, 50, false); ***** error ... fcnntrain (X, Y, 10, "sigmoid", 4, 1, 0.025, 50, false); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "softmx", 1, 0.025, 50, false); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 0, 0.025, 50, false); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, -0.025, 50, false); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, 0, 50, false); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, [0.025, 0.001], 50, false); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, {0.025}, 50, false); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, 0.025, 0, false); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, 0.025, [50, 25], false); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, 0.025, 50, 0); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, 0.025, 50, 1); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, 0.025, 50, [false, false]); ***** test rand ('seed', 42); randn ('seed', 42); Xs = [randn(30,2)*0.4 + 2; randn(30,2)*0.4 - 2]; Ys = [ones(30,1); 2*ones(30,1)]; M = fcnntrain (Xs, Ys, 8, "relu", "softmax", 1, 0.05, 60, false, 1); assert_equal (numel (M.Loss), 60); assert_equal (numel (M.Accuracy), 60); assert_equal (any (M.Loss != 0), true); assert_equal (M.Loss(end) < M.Loss(1), true); assert_equal (M.Accuracy(end) >= M.Accuracy(1), true); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, 0.025, 50, false, 0, struct (), 0); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, 0.025, 50, false, 0, 0); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, 0.025, 50, false, 0, ... struct ("Solver", "bogus")); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, 0.025, 50, false, 'ce'); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, 0.025, 50, false, [0, 1]); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, 0.025, 50, false, 3); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, 0.025, 50, false, -1); ***** test rand ('seed', 42); randn ('seed', 42); Xr = linspace (-2, 2, 60)'; Yr = 3 * Xr - 1; M = fcnntrain (Xr, Yr, [8, 8], "relu", "linear", 1, 0.005, 300, false, 2); assert_equal (fieldnames (M), {'LayerWeights'; 'Activations'; 'Loss'}); assert_equal (rows (M.LayerWeights{end}), 1); assert_equal (M.Loss(end) < M.Loss(1), true); ***** test rand ('seed', 42); Xr = linspace (0, 1, 40)'; Yr = 5 * Xr + 2; M = fcnntrain (Xr, Yr, 10, "relu", "linear", 1, 0.005, 200, false, 2); Wm = cellfun (@(m) m(:,1:end-1), M.LayerWeights, "UniformOutput", false); Bm = cellfun (@(m) m(:,end), M.LayerWeights, "UniformOutput", false); [~, yFit] = fcnnpredict (Wm, Bm, "relu", "linear", Xr); assert_equal (M.Loss(end), mean ((Yr - yFit) .^ 2), 1e-12); ***** test rand ('seed', 42); Xr = linspace (0, 1, 30)'; M = fcnntrain (Xr, [Xr, 2 * Xr, 3 * Xr], 6, "relu", "linear", 1, 0.005, ... 50, false, 2); assert_equal (rows (M.LayerWeights{end}), 3); Wm = cellfun (@(m) m(:,1:end-1), M.LayerWeights, "UniformOutput", false); Bm = cellfun (@(m) m(:,end), M.LayerWeights, "UniformOutput", false); [~, yFit] = fcnnpredict (Wm, Bm, "relu", "linear", Xr); assert_equal (columns (yFit), 3); ***** test rand ('seed', 42); Xr = linspace (0, 1, 20)'; Yr = linspace (-3.5, 2.25, 20)'; M = fcnntrain (Xr, Yr, 6, "relu", "linear", 1, 0.005, 50, false, 2); assert_equal (all (isfinite (M.Loss)), true); ***** error ... fcnntrain ([1; 2; 3], [1; Inf; 3], 4, "relu", "linear", 1, 0.01, 10, false, 2); ***** error ... fcnntrain ([1; 2; 3], [1; NaN; 3], 4, "relu", "linear", 1, 0.01, 10, false, 2); ***** test so = struct ("Solver", "lbfgs"); M = fcnntrain (X, Y, 10, "relu", "softmax", 1, 0.005, 100, false, 1, so); assert_equal (fieldnames (M), ... {'LayerWeights'; 'Activations'; 'Loss'; 'Gradient'; ... 'Step'; 'Criterion'}); assert_equal (M.Loss(end) < M.Loss(1), true); assert_equal (numel (M.Gradient), numel (M.Loss)); assert_equal (numel (M.Step), numel (M.Loss)); ***** test rand ("state", 3); randn ("state", 3); Ms = fcnntrain (X, Y, 10, "relu", "softmax", 1, 0.005, 200, false, 1); rand ("state", 3); randn ("state", 3); so = struct ("Solver", "lbfgs"); Ml = fcnntrain (X, Y, 10, "relu", "softmax", 1, 0.005, 200, false, 1, so); assert_equal (Ml.Loss(end) < Ms.Loss(end), true); assert_equal (numel (Ml.Loss) < numel (Ms.Loss), true); ***** test rand ("state", 5); randn ("state", 5); Ma = fcnntrain (X, Y, 10, "relu", "softmax", 1, 0.005, 30, false, 1); rand ("state", 5); randn ("state", 5); so = struct ("Solver", "sgd"); Mb = fcnntrain (X, Y, 10, "relu", "softmax", 1, 0.005, 30, false, 1, so); assert_equal (Mb.Loss, Ma.Loss); assert_equal (Mb.LayerWeights, Ma.LayerWeights); ***** test rand ("state", 9); randn ("state", 9); so = struct ("Solver", "lbfgs", "GradientTolerance", 1e3); Ma = fcnntrain (X, Y, 10, "relu", "softmax", 1, 0.005, 100, false, 1, so); rand ("state", 9); randn ("state", 9); so = struct ("Solver", "lbfgs", "GradientTolerance", 1e-8); Mb = fcnntrain (X, Y, 10, "relu", "softmax", 1, 0.005, 100, false, 1, so); assert_equal (Ma.Criterion, "Relative gradient tolerance reached."); assert_equal (numel (Ma.Loss) < numel (Mb.Loss), true); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, 0.025, 50, false, 0, ... struct ("Weights", ones (5, 1))); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, 0.025, 50, false, 0, ... struct ("Weights", -ones (150, 1))); ***** error ... fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, 0.025, 50, false, 0, ... struct ("Weights", zeros (150, 1))); ***** test ## A weight of two trains as the sample given twice w = ones (150, 1); w(1:10) = 2; so = struct ("Solver", "lbfgs"); rand ("seed", 3); A = fcnntrain (X, Y, 3, "sigmoid", "softmax", 1, 0.01, 50, false, 1, ... setfield (so, "Weights", w)); rand ("seed", 3); B = fcnntrain ([X; X(1:10,:)], [Y; Y(1:10)], 3, "sigmoid", "softmax", 1, ... 0.01, 50, false, 1, so); assert_equal (A.Loss, B.Loss, 1e-12); 55 tests, 55 passed, 0 known failure, 0 skipped [src/editDistance.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/editDistance.cc ***** error d = editDistance (1, 2, 3, 4); ***** error ... [C, IA, IC, I] = editDistance ({"AS","SD","AD"}, 1); ***** error ... [C, IA] = editDistance ({"AS","SD","AD"}); ***** error ... d = editDistance ({"AS","SD","AD"}, [1, 2]); ***** error ... d = editDistance ({"AS","SD","AD"}, -2); ***** error ... d = editDistance ({"AS","SD","AD"}, 1.25); ***** error ... d = editDistance ({"AS","SD","AD"}, {"AS","SD","AD"}, [1, 2]); ***** error ... d = editDistance ({"AS","SD","AD"}, {"AS","SD","AD"}, -2); ***** error ... d = editDistance ({"AS","SD","AD"}, {"AS","SD","AD"}, 1.25); ***** error ... d = editDistance ("string1", "string2", [1, 2]); ***** error ... d = editDistance ("string1", "string2", -2); ***** error ... d = editDistance ("string1", "string2", 1.25); ***** error ... d = editDistance ({{"string1", "string2"}, 2}); ***** error ... d = editDistance ({{"string1", "string2"}, 2}, 2); ***** error ... d = editDistance ([1, 2, 3]); ***** error ... d = editDistance (["AS","SD","AD","AS"]); ***** error ... d = editDistance (["AS","SD","AD"], 2); ***** error ... d = editDistance (logical ([1,2,3]), {"AS","AS","AD"}); ***** error ... d = editDistance ({"AS","SD","AD"}, logical ([1,2,3])); ***** error ... d = editDistance ([1,2,3], {"AS","AS","AD"}); ***** error ... d = editDistance ({1,2,3}, {"AS","SD","AD"}); ***** error ... d = editDistance ({"AS","SD","AD"}, {1,2,3}); ***** error ... d = editDistance ({"AS","SD","AD"}, {"AS", "AS"}); ***** test d = editDistance ({"AS","SD","AD"}); assert_equal (d, [2; 1; 1]); assert_equal (class (d), "double"); ***** test C = editDistance ({"AS","SD","AD"}, 1); assert_equal (iscellstr (C), true); assert_equal (C, {"AS";"SD"}); ***** test [C, IA] = editDistance ({"AS","SD","AD"}, 1); assert_equal (class (IA), "double"); assert_equal (IA, [1;2]); ***** test A = {"ASS"; "SDS"; "FDE"; "EDS"; "OPA"}; [C, IA] = editDistance (A, 2, "OutputAllIndices", false); assert_equal (class (IA), "double"); assert_equal (A(IA), C); ***** test A = {"ASS"; "SDS"; "FDE"; "EDS"; "OPA"}; [C, IA] = editDistance (A, 2, "OutputAllIndices", true); assert_equal (class (IA), "cell"); assert_equal (C, {"ASS"; "FDE"; "OPA"}); assert_equal (A(IA{1}), {"ASS"; "SDS"; "EDS"}); assert_equal (A(IA{2}), {"FDE"; "EDS"}); assert_equal (A(IA{3}), {"OPA"}); ***** test A = {"ASS"; "SDS"; "FDE"; "EDS"; "OPA"}; [C, IA, IC] = editDistance (A, 2); assert_equal (class (IA), "double"); assert_equal (A(IA), C); assert_equal (IC, [1; 1; 3; 1; 5]); ***** test d = editDistance ({"AS","SD","AD"}, {"AS", "AD", "SE"}); assert_equal (d, [0; 1; 2]); assert_equal (class (d), "double"); ***** test d = editDistance ({"AS","SD","AD"}, {"AS"}); assert_equal (d, [0; 2; 1]); assert_equal (class (d), "double"); ***** test d = editDistance ({"AS"}, {"AS","SD","AD"}); assert_equal (d, [0; 2; 1]); assert_equal (class (d), "double"); ***** test b = editDistance ("Octave", "octave"); assert_equal (b, 1); assert_equal (class (b), "double"); 33 tests, 33 passed, 0 known failure, 0 skipped [src/__nomdist__.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/__nomdist__.cc ***** shared X, W, Q X = [1, 1, 1; 1, 2, 1; 1, 1, 2; 2, 2, 2; 2, 1, 1; 3, 2, 2; 4, 1, 3]; W = [0.7, 1, 0.4]; Q = [1, 2, 2; 5, 1, 3]; ***** test D = [0.3333333333333334, 0.3333333333333334, 1, 0.3333333333333334, 1, ... 0.6666666666666667, 0.6666666666666667, 0.6666666666666667, ... 0.6666666666666667, 0.6666666666666667, 1, 0.6666666666666667, ... 0.6666666666666667, 0.6666666666666667, 0.6666666666666667, ... 0.6666666666666667, 0.3333333333333334, 1, 1, 0.6666666666666667, ... 1]; assert_equal (__nomdist__ (X, [], X, 'sm', ones (1, 3)), D, -1e-14); ***** test D = [0.125, 0.06451612903225801, 0.2638297872340427, 0.03846153846153855, ... 0.2638297872340427, 0.1082089552238805, 0.2073170731707317, ... 0.1082089552238805, 0.173913043478261, 0.1082089552238805, ... 0.2638297872340427, 0.173913043478261, 0.1082089552238805, ... 0.173913043478261, 0.1082089552238805, 0.2073170731707317, ... 0.03846153846153855, 0.2638297872340427, 0.2638297872340427, ... 0.1082089552238805, 0.2638297872340427]; assert_equal (__nomdist__ (X, [], X, 'eskin', ones (1, 3)), D, -1e-14); ***** test D = [0.3191489361702128, 0.2247191011235955, 1, 0.174757281553398, 1, ... 0.6808510638297873, 0.6756756756756757, 0.3220338983050848, ... 0.5454545454545454, 0.4117647058823529, 1, 0.5454545454545454, ... 0.4578313253012049, 0.6226415094339623, 0.6808510638297873, ... 0.4807692307692308, 0.3103448275862069, 1, 1, 0.7169811320754718, ... 1]; assert_equal (__nomdist__ (X, [], X, 'anderberg', ones (1, 3)), D, -1e-14); ***** test D = [0, 0.06142861791239795, 0.1725141049787992, 0.1110854870664012, ... 0.2158655957496493, 0.3042675674408121, 0.06142861791239795, ... 0.1725141049787992, 0.1110854870664012, 0.2158655957496493, ... 0.3042675674408121, 0.1110854870664012, 0.1725141049787992, ... 0.1544369778372513, 0.3042675674408121, 0.06142861791239795, ... 0.1764146125938005, 0.3262452021973615, 0.2378432305061988, ... 0.3262452021973615, 0.3491708712867553]; assert_equal (__nomdist__ (X, [], X, 'burnaby', ones (1, 3)), D, -1e-14); ***** test D = [0.7810604142146108, 0.7810604142146108, 1, 0.7810604142146108, 1, ... 0.8905302071073053, 0.8905302071073053, 0.8905302071073053, ... 0.8905302071073053, 0.8905302071073053, 1, 0.8905302071073053, ... 0.8905302071073053, 0.8905302071073053, 0.8905302071073053, ... 0.9040977146037077, 0.7810604142146108, 1, 1, 0.8905302071073053, ... 1]; assert_equal (__nomdist__ (X, [], X, 'gambaryan', ones (1, 3)), D, -1e-14); ***** test D = [0.4920634920634921, 0.5396825396825398, 1, 0.5714285714285715, 1, ... 0.8095238095238095, 0.7301587301587302, 0.7142857142857143, ... 0.7619047619047619, 0.7142857142857143, 1, 0.7619047619047619, ... 0.8095238095238095, 0.7619047619047619, 0.8095238095238095, ... 0.6825396825396826, 0.4761904761904762, 1, 1, 0.8095238095238095, ... 1]; assert_equal (__nomdist__ (X, [], X, 'goodall1', ones (1, 3)), D, -1e-14); ***** test D = [0.4761904761904762, 0.4761904761904762, 1, 0.5238095238095238, 1, ... 0.7619047619047619, 0.7142857142857143, 0.8095238095238095, ... 0.7619047619047619, 0.8095238095238095, 1, 0.7619047619047619, ... 0.7619047619047619, 0.7619047619047619, 0.7619047619047619, ... 0.7301587301587302, 0.5714285714285715, 1, 1, 0.7619047619047619, ... 1]; assert_equal (__nomdist__ (X, [], X, 'goodall2', ones (1, 3)), D, -1e-14); ***** test D = [0.4285714285714286, 0.4761904761904762, 1, 0.4761904761904762, 1, ... 0.7619047619047619, 0.7142857142857143, 0.7142857142857143, ... 0.7142857142857143, 0.7142857142857143, 1, 0.7142857142857143, ... 0.7619047619047619, 0.7142857142857143, 0.7619047619047619, ... 0.6825396825396826, 0.4285714285714286, 1, 1, 0.7619047619047619, ... 1]; assert_equal (__nomdist__ (X, [], X, 'goodall3', ones (1, 3)), D, -1e-14); ***** test D = [0.9047619047619048, 0.8571428571428572, 1, 0.8571428571428572, 1, ... 0.9047619047619048, 0.9523809523809523, 0.9523809523809523, ... 0.9523809523809523, 0.9523809523809523, 1, 0.9523809523809523, ... 0.9047619047619048, 0.9523809523809523, 0.9047619047619048, ... 0.9841269841269842, 0.9047619047619048, 1, 1, 0.9047619047619048, ... 1]; assert_equal (__nomdist__ (X, [], X, 'goodall4', ones (1, 3)), D, -1e-14); ***** test D = [0.2519020857326395, 0.222935300643843, 1.116901264683761, ... 0.1683617083596181, 0.6220882713463793, 0, 0.6220882713463793, ... 0.4845515922241048, 0.5274548356775992, 0.222935300643843, ... 0.2519020857326395, 0.5274548356775992, 0.4845515922241048, ... 0.2519020857326395, 0, 0.6220882713463793, 0, 0.2519020857326395, ... 0.6220882713463793, 0, 0.2519020857326395]; assert_equal (__nomdist__ (X, [], X, 'iof', ones (1, 3)), D, -1e-14); ***** test D = [0.4151177862291795, 0.4440221764476788, 4.300985770938718, ... 0.4092944562546224, 3.129303942378162, 0.9970986461666451, ... 1.394583893868549, 1.051411550470893, 1.197035645318646, ... 0.9801872797639546, 2.124165640951619, 1.197035645318646, ... 1.33941488968952, 1.094910865911154, 0.9970986461666451, ... 0.9926721560959628, 0.2958576645228652, 1.629441680424714, ... 2.145534809656081, 0.8080361706650088, 1.23240918245247]; assert_equal (__nomdist__ (X, [], X, 'lin', ones (1, 3)), D, -1e-14); ***** test ## Pair 11 shares nothing, so its similarity is exactly 0, where ## nomclust's rounding returns about 1.6e16. D = [3.789167787737098, 1.628488554759508, 4.300985770938718, ... 2.543556180472745, 18.11998502097161, 10.98259187699986, ... 3.150318732214346, 2.001980368635569, 5.288962253828324, ... 4.34995121471969, Inf, 5.288962253828324, 2.189052189432408, ... 37.23997004194317, 10.98259187699986, 2.591802852053521, ... 2.106486692231752, 5.61060225142327, 3.413335993771041, ... 3.235711272013311, 2.229638071755347]; assert_equal (__nomdist__ (X, [], X, 'lin1', ones (1, 3)), D, -1e-14); ***** test D = [0.1200918256837458, 0.1618443665773319, 0.7186603816400106, ... 0.2071986251911722, 0.8315156613470343, 0.7093347701634469, ... 0.3271674504213862, 0.4512427967395944, 0.3866778238431001, ... 0.5308967156237416, 1.092895882914944, 0.3866778238431001, ... 0.4512427967395944, 0.4592247360215442, 0.7093347701634469, ... 0.3271674504213862, 0.3095365880953216, 1.227546987265509, ... 0.933812054699924, 0.7981072047001967, 1.371908574090516]; assert_equal (__nomdist__ (X, [], X, 'of', ones (1, 3)), D, -1e-14); ***** test D = [0.519730510105871, 0.5378486055776893, 0.9473684210526315, ... 0.526829268292683, 0.9246575342465754, 0.6513872135102533, ... 0.6801007556675063, 0.6352941176470589, 0.6625766871165645, 0.625, ... 0.8723747980613893, 0.6625766871165645, 0.6923076923076923, ... 0.6513872135102533, 0.6513872135102533, 0.6101694915254238, ... 0.4778761061946903, 0.84375, 0.8925619834710745, 0.6352941176470589, ... 0.8256880733944955]; assert_equal (__nomdist__ (X, [], X, 'smirnov', ones (1, 3)), D, -1e-14); ***** test D = [0.3882378704642936, 0.3645287891257314, 1, 0.3668903239823945, 1, ... 0.6715906213219162, 0.6929381678038152, 0.6715906213219162, ... 0.6952997026604784, 0.6715906213219162, 1, 0.6952997026604784, ... 0.6715906213219162, 0.6952997026604784, 0.6715906213219162, ... 0.6929381678038152, 0.3668903239823945, 1, 1, 0.6715906213219162, ... 1]; assert_equal (__nomdist__ (X, [], X, 've', ones (1, 3)), D, -1e-14); ***** test D = [0.3854875283446713, 0.365079365079365, 1, 0.3673469387755102, 1, ... 0.673469387755102, 0.691609977324263, 0.673469387755102, ... 0.6938775510204082, 0.673469387755102, 1, 0.6938775510204082, ... 0.673469387755102, 0.6938775510204082, 0.673469387755102, ... 0.691609977324263, 0.3673469387755102, 1, 1, 0.673469387755102, 1]; assert_equal (__nomdist__ (X, [], X, 'vm', ones (1, 3)), D, -1e-14); ***** test D = [0.4761904761904762, 0.1904761904761906, 1, 0.3333333333333334, 1, ... 0.5238095238095238, 0.6666666666666667, 0.5238095238095238, ... 0.8095238095238095, 0.5238095238095238, 1, 0.8095238095238095, ... 0.5238095238095238, 0.8095238095238095, 0.5238095238095238, ... 0.6666666666666667, 0.3333333333333334, 1, 1, 0.5238095238095238, ... 1]; assert_equal (__nomdist__ (X, [], X, 'sm', W), D, -1e-14); ***** test D = [0.188679245283019, 0.03587443946188351, 0.2993750000000002, ... 0.03846153846153855, 0.2993750000000002, 0.07720207253886002, ... 0.2397137745974953, 0.07720207253886002, 0.2434210526315792, ... 0.07720207253886002, 0.2993750000000002, 0.2434210526315792, ... 0.07720207253886002, 0.2434210526315792, 0.07720207253886002, ... 0.2397137745974953, 0.03846153846153855, 0.2993750000000002, ... 0.2993750000000002, 0.07720207253886002, 0.2993750000000002]; assert_equal (__nomdist__ (X, [], X, 'eskin', W), D, -1e-14); ***** test D = [2.220446049250313e-16, 0.03510206737851329, 0.1461875544449145, ... 0.1110854870664013, 0.1895390452157646, 0.2400544576107146, ... 0.03510206737851329, 0.1461875544449145, 0.1110854870664013, ... 0.1895390452157645, 0.2400544576107146, 0.1110854870664013, ... 0.1461875544449145, 0.1544369778372515, 0.2400544576107146, ... 0.03510206737851329, 0.1764146125938008, 0.262032092367264, ... 0.2115166799723139, 0.262032092367264, 0.2849577614566577]; assert_equal (__nomdist__ (X, [], X, 'burnaby', W), D, -1e-14); ***** test D = [0.5941043083900226, 0.4580498866213153, 1, 0.5918367346938775, 1, ... 0.7278911564625851, 0.7301587301587302, 0.5918367346938775, ... 0.8639455782312925, 0.5918367346938775, 1, 0.8639455782312925, ... 0.7278911564625851, 0.8639455782312925, 0.7278911564625851, ... 0.6825396825396826, 0.45578231292517, 1, 1, 0.7278911564625851, 1]; assert_equal (__nomdist__ (X, [], X, 'goodall1', W), D, -1e-14); ***** test D = [0.5782312925170068, 0.3741496598639457, 1, 0.5238095238095238, 1, ... 0.6598639455782314, 0.7142857142857143, 0.7278911564625851, ... 0.8639455782312925, 0.7278911564625851, 1, 0.8639455782312925, ... 0.6598639455782314, 0.8639455782312925, 0.6598639455782314, ... 0.7301587301587302, 0.5918367346938775, 1, 1, 0.6598639455782314, ... 1]; assert_equal (__nomdist__ (X, [], X, 'goodall2', W), D, -1e-14); ***** test D = [0.5510204081632654, 0.3741496598639457, 1, 0.4965986394557823, 1, ... 0.6598639455782314, 0.7142857142857143, 0.5918367346938775, ... 0.8367346938775511, 0.5918367346938775, 1, 0.8367346938775511, ... 0.6598639455782314, 0.8367346938775511, 0.6598639455782314, ... 0.6825396825396826, 0.4285714285714285, 1, 1, 0.6598639455782314, ... 1]; assert_equal (__nomdist__ (X, [], X, 'goodall3', W), D, -1e-14); ***** test D = [0.9251700680272109, 0.8163265306122449, 1, 0.8367346938775511, 1, ... 0.8639455782312926, 0.9523809523809524, 0.9319727891156463, ... 0.9727891156462585, 0.9319727891156463, 1, 0.9727891156462585, ... 0.8639455782312926, 0.9727891156462585, 0.8639455782312926, ... 0.9841269841269842, 0.9047619047619048, 1, 1, 0.8639455782312926, ... 1]; assert_equal (__nomdist__ (X, [], X, 'goodall4', W), D, -1e-14); ***** test D = [0.4034116524755296, 0.1162816237598046, 1.153873045642792, ... 0.1683617083596181, 0.6437079284563265, 0, 0.6437079284563265, ... 0.3302637748244865, 0.7591738998286246, 0.1162816237598046, ... 0.4034116524755296, 0.7591738998286246, 0.3302637748244865, ... 0.4034116524755296, 0, 0.6437079284563265, 0, 0.4034116524755296, ... 0.6437079284563265, 0, 0.4034116524755296]; assert_equal (__nomdist__ (X, [], X, 'iof', W), D, -1e-14); ***** test D = [0.7547596113257813, 0.2283122503928992, 4.98065967640019, ... 0.4404425718584952, 3.455309722495803, 0.7834346505595069, ... 1.497804622067723, 0.678686996286928, 2.094086789730795, ... 0.663610211168179, 2.638407372343877, 2.094086789730795, ... 0.9065634806963383, 1.764659180935495, 0.7834346505595069, ... 1.044877050999849, 0.2958576645228654, 1.915257938793264, ... 2.301793922738517, 0.6256289159595232, 1.383977355327267]; assert_equal (__nomdist__ (X, [], X, 'lin', W), D, -1e-14); ***** test ## Pair 11 shares nothing, so its similarity is exactly 0, where ## nomclust's rounding returns about 1.6e16. D = [3.995609244135445, 1.337916967393231, 4.98065967640019, ... 1.990937661841057, 31.76013401116178, 6.490425532349926, ... 3.565656513831422, 1.66527788918046, 5.672895993089274, ... 3.458682832253068, Inf, 5.672895993089274, 1.831126193046863, ... 64.52026802232339, 6.490425532349926, 2.837642944938641, ... 1.72479913371176, 5.079768268917555, 3.768312597687203, ... 2.332335370699156, 1.992511747898871]; assert_equal (__nomdist__ (X, [], X, 'lin1', W), D, -1e-14); ***** test D = [0.1808686870497029, 0.08648381587311493, 0.6789831874074297, ... 0.2071986251911724, 0.7865248082245031, 0.4837971469738953, ... 0.3033825055232831, 0.3355336337184947, 0.4810463690758979, ... 0.4026982054804156, 0.9201937519825203, 0.4810463690758979, ... 0.3355336337184947, 0.5640991370603945, 0.4837971469738953, ... 0.3033825055232831, 0.3095365880953216, 1.032940807336712, ... 0.8837237854764428, 0.5502337057652003, 1.152503424548615]; assert_equal (__nomdist__ (X, [], X, 'of', W), D, -1e-14); ***** test D = [0.5188237121812314, 0.2237819125494098, 1, 0.3567292891230108, 1, ... 0.5308437447455945, 0.6929381678038152, 0.5308437447455945, ... 0.8258855443774162, 0.5308437447455945, 1, 0.8258855443774162, ... 0.5308437447455945, 0.8258855443774162, 0.5308437447455945, ... 0.6929381678038152, 0.3567292891230108, 1, 1, 0.5308437447455945, ... 1]; assert_equal (__nomdist__ (X, [], X, 've', W), D, -1e-14); ***** test D = [0.5166828636216392, 0.2251376741172659, 1, 0.358600583090379, 1, ... 0.5335276967930028, 0.691609977324263, 0.5335276967930028, ... 0.8250728862973761, 0.5335276967930028, 1, 0.8250728862973761, ... 0.5335276967930028, 0.8250728862973761, 0.5335276967930028, ... 0.691609977324263, 0.358600583090379, 1, 1, 0.5335276967930028, 1]; assert_equal (__nomdist__ (X, [], X, 'vm', W), D, -1e-14); ***** test ## Row against row matches the pairs, bit for bit D = squareform (__nomdist__ (X, [], X, 'goodall3', ones (1, 3))); D2 = __nomdist__ (X, X, X, 'goodall3', ones (1, 3)); assert_equal (D2(! eye (7)), D(! eye (7))); ***** test ## Identical rows need not be at 0: 1 - (3 - 24/42) / 3 D2 = __nomdist__ (X, X, X, 'goodall3', ones (1, 3)); assert_equal (D2(1,1), 4 / 21, -1e-14); ***** assert_equal (__nomdist__ ([1; 2], [1], [1; 2], 'goodall3', 1), [0; 1]) ***** assert_equal (__nomdist__ ([1; 2], [1], [], 'goodall3', 1), [0; 1]) ***** assert_equal (__nomdist__ (X, [], [], 'lin1', W), ... __nomdist__ (X, [], X, 'lin1', W)) ***** assert_equal (__nomdist__ ([1; 2], [1], [1; 1; 1; 2], 'goodall3', 1), ... [0.5; 1]) ***** assert_equal (__nomdist__ ([1 1 1], [], [1 1 1], 'sm', ones (1, 3)), ... zeros (1, 0)) ***** assert_equal (__nomdist__ (X, [], X, 'sm', [1, 0, 1]), ... __nomdist__ (X(:,[1, 3]), [], X(:,[1, 3]), 'sm', [1, 1])) ***** assert_equal (__nomdist__ ([1, 1; 2, 1; 2, 2], [3, 1; 3, 2], ... [1, 1; 2, 1; 2, 2], 'goodall3', [1, 1]), ... [2/3, 1; 2/3, 1; 1, 0.5], -1e-14) ***** test Z = [1, 1; 2, 1; 2, 2]; s = 1 / (1 + log (3) * log (3 / 2)); D = __nomdist__ (Z, [3, 1; 3, 2], Z, 'of', [1, 1]); assert_equal (D, [1, 2/s-1; 1, 2/s-1; 2/s-1, 1], -1e-14); ***** assert_equal (__nomdist__ ([1, 1; 2, 1; 2, 2], [3, 1; 3, 2], ... [1, 1; 2, 1; 2, 2], 'burnaby', [1, 1]), ... 0.5 * ones (3, 2)) ***** assert_equal (__nomdist__ ([1, 1; 2, 1; 2, 2], [3, 1; 3, 2], ... [1, 1; 2, 1; 2, 2], 'anderberg', [1, 1]), ... ones (3, 2)) ***** assert_equal (__nomdist__ ([1, 1; 2, 1; 2, 2], [3, 1; 3, 2], ... [1, 1; 2, 1; 2, 2], 'lin', [1, 1]), ... Inf (3, 2)) ***** assert_equal (__nomdist__ ([1, 1; 2, 1; 2, 2], [3, 1; 3, 2], ... [1, 1; 2, 1; 2, 2], 'lin1', [1, 1]), ... Inf (3, 2)) ***** assert_equal (__nomdist__ ([1, 1; 2, 1; 2, 2], [3, 1; 3, 2], ... [1, 1; 2, 1; 2, 2], 'lin', [0, 1]), ... [0, Inf; 0, Inf; Inf, 0]) ***** assert_equal (__nomdist__ ([1, 1; 2, 1; 2, 2], [3, 1; 3, 2], ... [1, 1; 2, 1; 2, 2], 'iof', [1, 1]), NaN (3, 2)) ***** assert_equal (__nomdist__ ([1; 1], 2, [1; 1], 'of', 1), [NaN; NaN]) ***** assert_equal (__nomdist__ ([1; 1], 2, [1; 1], 'burnaby', 1), [NaN; NaN]) ***** assert_equal (__nomdist__ ([1; 2], [], [1; 2], 'lin', 1), Inf) ***** assert_equal (__nomdist__ ([1, 1; 1, 1], [], [1, 1; 1, 1], 'lin', [1, 1]), 0) ***** assert_equal (__nomdist__ ([1, 1; 1, 1], [], [1, 1; 1, 1], 'lin1', ... [1, 1]), 1) ***** test h = - (2/3 * log2 (2/3) + 1/3 * log2 (1/3)); D = __nomdist__ ([1, 1; 1, 2; 1, 1], [], [1, 1; 1, 2; 1, 1], ... 'gambaryan', [1, 1]); assert_equal (D, [1, 1 - h / 3, 1], -1e-14); ***** assert_equal (__nomdist__ (1, 1, 1, 'goodall3', 1), 0) ***** assert_equal (__nomdist__ (1, 1, 1, 'goodall4', 1), 1) ***** test E = [__nomdist__(X, Q(1,:), [X; Q(1,:)], 'sm', W), ... __nomdist__(X, Q(2,:), [X; Q(2,:)], 'sm', W)]; assert_equal (__nomdist__ (X, Q, [], 'sm', W, true), E); ***** test E = [__nomdist__(X, Q(1,:), [X; Q(1,:)], 'eskin', W), ... __nomdist__(X, Q(2,:), [X; Q(2,:)], 'eskin', W)]; assert_equal (__nomdist__ (X, Q, [], 'eskin', W, true), E); ***** test E = [__nomdist__(X, Q(1,:), [X; Q(1,:)], 'anderberg', ones (1, 3)), ... __nomdist__(X, Q(2,:), [X; Q(2,:)], 'anderberg', ones (1, 3))]; assert_equal (__nomdist__ (X, Q, [], 'anderberg', ones (1, 3), true), E); ***** test E = [__nomdist__(X, Q(1,:), [X; Q(1,:)], 'burnaby', W), ... __nomdist__(X, Q(2,:), [X; Q(2,:)], 'burnaby', W)]; assert_equal (__nomdist__ (X, Q, [], 'burnaby', W, true), E); ***** test E = [__nomdist__(X, Q(1,:), [X; Q(1,:)], 'gambaryan', ones (1, 3)), ... __nomdist__(X, Q(2,:), [X; Q(2,:)], 'gambaryan', ones (1, 3))]; assert_equal (__nomdist__ (X, Q, [], 'gambaryan', ones (1, 3), true), E); ***** test E = [__nomdist__(X, Q(1,:), [X; Q(1,:)], 'goodall1', W), ... __nomdist__(X, Q(2,:), [X; Q(2,:)], 'goodall1', W)]; assert_equal (__nomdist__ (X, Q, [], 'goodall1', W, true), E); ***** test E = [__nomdist__(X, Q(1,:), [X; Q(1,:)], 'goodall2', W), ... __nomdist__(X, Q(2,:), [X; Q(2,:)], 'goodall2', W)]; assert_equal (__nomdist__ (X, Q, [], 'goodall2', W, true), E); ***** test E = [__nomdist__(X, Q(1,:), [X; Q(1,:)], 'goodall3', W), ... __nomdist__(X, Q(2,:), [X; Q(2,:)], 'goodall3', W)]; assert_equal (__nomdist__ (X, Q, [], 'goodall3', W, true), E); ***** test E = [__nomdist__(X, Q(1,:), [X; Q(1,:)], 'goodall4', W), ... __nomdist__(X, Q(2,:), [X; Q(2,:)], 'goodall4', W)]; assert_equal (__nomdist__ (X, Q, [], 'goodall4', W, true), E); ***** test E = [__nomdist__(X, Q(1,:), [X; Q(1,:)], 'iof', W), ... __nomdist__(X, Q(2,:), [X; Q(2,:)], 'iof', W)]; assert_equal (__nomdist__ (X, Q, [], 'iof', W, true), E); ***** test E = [__nomdist__(X, Q(1,:), [X; Q(1,:)], 'lin', W), ... __nomdist__(X, Q(2,:), [X; Q(2,:)], 'lin', W)]; assert_equal (__nomdist__ (X, Q, [], 'lin', W, true), E); ***** test E = [__nomdist__(X, Q(1,:), [X; Q(1,:)], 'lin1', W), ... __nomdist__(X, Q(2,:), [X; Q(2,:)], 'lin1', W)]; assert_equal (__nomdist__ (X, Q, [], 'lin1', W, true), E); ***** test E = [__nomdist__(X, Q(1,:), [X; Q(1,:)], 'of', W), ... __nomdist__(X, Q(2,:), [X; Q(2,:)], 'of', W)]; assert_equal (__nomdist__ (X, Q, [], 'of', W, true), E); ***** test E = [__nomdist__(X, Q(1,:), [X; Q(1,:)], 'smirnov', ones (1, 3)), ... __nomdist__(X, Q(2,:), [X; Q(2,:)], 'smirnov', ones (1, 3))]; assert_equal (__nomdist__ (X, Q, [], 'smirnov', ones (1, 3), true), E); ***** test E = [__nomdist__(X, Q(1,:), [X; Q(1,:)], 've', W), ... __nomdist__(X, Q(2,:), [X; Q(2,:)], 've', W)]; assert_equal (__nomdist__ (X, Q, [], 've', W, true), E); ***** test E = [__nomdist__(X, Q(1,:), [X; Q(1,:)], 'vm', W), ... __nomdist__(X, Q(2,:), [X; Q(2,:)], 'vm', W)]; assert_equal (__nomdist__ (X, Q, [], 'vm', W, true), E); ***** test R = [X; 2, 2, 1; 1, 1, 1]; E = [__nomdist__(X, Q(1,:), [R; Q(1,:)], 'lin1', W), ... __nomdist__(X, Q(2,:), [R; Q(2,:)], 'lin1', W)]; assert_equal (__nomdist__ (X, Q, R, 'lin1', W, true), E); ***** assert_equal (__nomdist__ (X, X, [], 'of', W, false), ... __nomdist__ (X, X, [], 'of', W)) ***** error __nomdist__ (1, [], 1, 'sm') ***** error<__nomdist__: X, Y and R must be real numeric matrices.> ... __nomdist__ ({1}, [], 1, 'sm', 1) ***** error<__nomdist__: X, Y and R must have the same number of columns.> ... __nomdist__ ([1, 1], [], 1, 'sm', [1, 1]) ***** error<__nomdist__: X, Y and R must hold positive integer codes.> ... __nomdist__ (1.5, [], 1, 'sm', 1) ***** error<__nomdist__: MEASURE must be a character vector.> ... __nomdist__ (1, [], 1, 1, 1) ***** error<__nomdist__: W must hold one weight per variable.> ... __nomdist__ (1, [], 1, 'sm', [1, 1]) ***** error<__nomdist__: unsupported MEASURE 'morlini'.> ... __nomdist__ (1, [], 1, 'morlini', 1) ***** error<__nomdist__: R must hold every level X holds.> ... __nomdist__ (2, [], 1, 'sm', 1) ***** error<__nomdist__: ADDQ must be a logical scalar.> ... __nomdist__ (1, 1, [], 'sm', 1, [true, true]) ***** error<__nomdist__: ADDQ needs a nonempty Y.> ... __nomdist__ (1, [], [], 'sm', 1, true) 81 tests, 81 passed, 0 known failure, 0 skipped [src/gamboostinter.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/gamboostinter.cc ***** test ## Every selected pair gets a surface on the grid of the cut points its ## trees used, and the phase reports the usual fields. x = randn (200, 3); y = double (x(:,1) .* x(:,2) + 0.1 * randn (200, 1) > 0); M = gamboosttrain (x, y, 1, 20, 1, 1); f0 = gamboostpredict (M.BinEdges, M.ShapeValues, x, M.Intercept); I = gamboostinter (x, y, f0, 1, [1, 2], 20, 1, 4); assert_equal (numel (I.PairValues), 1); assert_equal (numel (I.PairEdges), 1); assert_equal (size (I.PairValues{1}), ... [numel(I.PairEdges{1}{1}), numel(I.PairEdges{1}{2})] + 1); assert_equal (numel (I.PairMissing{1}{1}), numel (I.PairEdges{1}{2}) + 1); assert_equal (numel (I.PairMissing{1}{2}), numel (I.PairEdges{1}{1}) + 1); assert_equal (numel (I.PairBinEdges), 3); assert_equal (numel (I.Residuals), 200); ***** test ## A row missing a predictor of the pair still takes part in the fit. x = randn (200, 2); y = double (x(:,1) .* x(:,2) > 0); x(1:10,1) = NaN; M = gamboosttrain (x, y, 1, 20, 1, 1); f0 = gamboostpredict (M.BinEdges, M.ShapeValues, x, M.Intercept); I = gamboostinter (x, y, f0, 1, [1, 2], 5, 1, 4); assert_equal (all (isfinite (I.Residuals)), true); assert_equal (all (isfinite ([I.PairMissing{1}{1}, I.PairMissing{1}{2}, ... I.PairMissing{1}{3}])), true); ***** test ## The phase starts from the deviance the predictor phase left, so it can ## only improve on it. x = randn (200, 3); y = double (x(:,1) .* x(:,2) + 0.1 * randn (200, 1) > 0); M = gamboosttrain (x, y, 1, 20, 1, 1); f0 = gamboostpredict (M.BinEdges, M.ShapeValues, x, M.Intercept); I = gamboostinter (x, y, f0, 1, [1, 2], 30, 1, 4); assert_equal (I.Deviance <= M.Deviance, true); ***** test ## A pair term is recentred like a shape function, so what it gives up is ## reported for the intercept rather than left inside the surface. x = randn (150, 2); y = double (x(:,1) .* x(:,2) > 0); M = gamboosttrain (x, y, 1, 20, 1, 1); f0 = gamboostpredict (M.BinEdges, M.ShapeValues, x, M.Intercept); I = gamboostinter (x, y, f0, 1, [1, 2], 25, 1, 4); assert_equal (isfinite (I.Intercept), true); ***** test ## Several pairs are fitted in one call, each on its own grid. x = randn (200, 4); y = double (x(:,1) .* x(:,2) + x(:,3) .* x(:,4) > 0); M = gamboosttrain (x, y, 1, 20, 1, 1); f0 = gamboostpredict (M.BinEdges, M.ShapeValues, x, M.Intercept); I = gamboostinter (x, y, f0, 1, [1, 2; 3, 4], 20, 1, 4); assert_equal (numel (I.PairValues), 2); ***** test ## The budget is a budget here too: a phase that stops improving says so. x = randn (120, 2); y = double (x(:,1) > 0); M = gamboosttrain (x, y, 1, 100, 1, 1); f0 = gamboostpredict (M.BinEdges, M.ShapeValues, x, M.Intercept); I = gamboostinter (x, y, f0, 1, [1, 2], 100000, 1, 4); assert_equal (I.ReasonForTermination, 'Unable to improve the model fit.'); assert_equal (I.NumTrees < 100000, true); ***** test ## A regression pair term works the same way and lowers the residual sum ## of squares it was handed. x = randn (200, 2); y = x(:,1) .* x(:,2); M = gamboosttrain (x, y, 2, 20, 1, 1); f0 = gamboostpredict (M.BinEdges, M.ShapeValues, x, M.Intercept); I = gamboostinter (x, y, f0, 2, [1, 2], 40, 1, 4); assert_equal (I.Deviance < M.Deviance, true); ***** test ## A categorical predictor of a pair is split by sets of levels, and its ## grid holds every level. k = (1:300)'; c = mod (k, 4) + 1; x = sin (k); y = (c == 2 | c == 4) .* x + 0.1 * cos (k); M = gamboosttrain ([c, x], y, 2, 20, 1, 1, 0, 10, [], [], [true, false]); f = gamboostpredict (M.BinEdges, M.ShapeValues, [c, x], M.Intercept); I = gamboostinter ([c, x], y, f, 2, [1, 2], 10, 1, 4, [], [true, false]); assert_equal (I.PairEdges{1}{1}, [1.5, 2.5, 3.5]); assert_equal (I.Deviance < M.Deviance, true); ***** error gamboostinter (1, 2, 3) ***** error ... gamboostinter ('a', [1;0], [0;0], 1, [1,2], 10, 1, 4) ***** error ... gamboostinter ([1,2;3,4], [1;0], [0;0;0], 1, [1,2], 10, 1, 4) ***** error ... gamboostinter ([1,2;3,4], [1;0], [0;0], 3, [1,2], 10, 1, 4) ***** error ... gamboostinter ([1,2;3,4], [1;0], [0;0], 1, [1,2,3], 10, 1, 4) ***** error ... gamboostinter ([1,2;3,4], [1;0], [0;0], 1, [1,5], 10, 1, 4) ***** error ... gamboostinter ([1,2;3,4], [1;0], [0;0], 1, [2,2], 10, 1, 4) ***** error ... gamboostinter ([1,2;3,4], [1;0], [0;0], 1, [1,2], 0, 1, 4) ***** error ... gamboostinter ([1,2;3,4], [1;0], [0;0], 1, [1,2], 10, 2, 4) ***** error ... gamboostinter ([1,2;3,4], [1;0], [0;0], 1, [1,2], 10, 1, 0) ***** error ... gamboostinter ([1,2;3,4], [1;2], [0;0], 1, [1,2], 10, 1, 4) 19 tests, 19 passed, 0 known failure, 0 skipped [src/libsvmread.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/libsvmread.cc ***** error [L, D] = libsvmread (24); ***** error ... D = libsvmread ("filename"); ***** test [L, D] = libsvmread (file_in_loadpath ("heart_scale.dat")); assert_equal (size (L), [270, 1]); assert_equal (size (D), [270, 13]); ***** test [L, D] = libsvmread (file_in_loadpath ("heart_scale.dat")); assert_equal (issparse (L), false); assert_equal (issparse (D), true); 4 tests, 4 passed, 0 known failure, 0 skipped [src/__lbfgs__.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/__lbfgs__.cc ***** function [f, g] = __rosen__ (x) t = x(2) - x(1)^2; f = 100 * t^2 + (1 - x(1))^2; g = zeros (2, 1); g(1) = -400 * x(1) * t - 2 * (1 - x(1)); g(2) = 200 * t; ***** endfunction ***** function [f, g] = __exrosen__ (x) n = numel (x); o = (1:2:n-1)'; e = (2:2:n)'; t1 = x(e) - x(o).^2; t2 = 1 - x(o); f = sum (100 * t1.^2 + t2.^2); g = zeros (n, 1); g(o) = -400 * x(o) .* t1 - 2 * t2; g(e) = 200 * t1; ***** endfunction ***** function [f, g] = __beale__ (x) y = [1.5; 2.25; 2.625]; k = (1:3)'; t = 1 - x(2).^k; r = y - x(1) * t; f = sum (r.^2); g = zeros (2, 1); g(1) = -2 * sum (r .* t); g(2) = 2 * x(1) * sum (r .* k .* x(2).^(k - 1)); ***** endfunction ***** function [f, g] = __wood__ (x) t1 = 100 * (x(2) - x(1)^2)^2 + (1 - x(1))^2; t2 = 90 * (x(4) - x(3)^2)^2 + (1 - x(3))^2; t3 = 10.1 * ((1 - x(2))^2 + (1 - x(4))^2); t4 = 19.8 * (1 - x(2)) * (1 - x(4)); f = t1 + t2 + t3 + t4; g = zeros (4, 1); g(1) = -400 * x(1) * (x(2) - x(1)^2) - 2 * (1 - x(1)); g(2) = 200 * (x(2) - x(1)^2) - 20.2 * (1 - x(2)) - 19.8 * (1 - x(4)); g(3) = -360 * x(3) * (x(4) - x(3)^2) - 2 * (1 - x(3)); g(4) = 180 * (x(4) - x(3)^2) - 20.2 * (1 - x(4)) - 19.8 * (1 - x(2)); ***** endfunction ***** function [f, g] = __powellsq__ (x) a = x(1) + 10 * x(2); b = x(3) - x(4); c = x(2) - 2 * x(3); d = x(1) - x(4); f = a^2 + 5 * b^2 + c^4 + 10 * d^4; g = zeros (4, 1); g(1) = 2 * a + 40 * d^3; g(2) = 20 * a + 4 * c^3; g(3) = 10 * b - 8 * c^3; g(4) = -10 * b - 40 * d^3; ***** endfunction ***** function [f, g] = __quadtri__ (x) n = numel (x); A = 2 * eye (n) - diag (ones (n - 1, 1), 1) - diag (ones (n - 1, 1), -1); xs = ((1:n)' / n).^2; r = x - xs; f = 0.5 * r' * A * r; g = A * r; ***** endfunction ***** function [f, g] = __badgrad__ (x) f = sum (x.^2); g = 1; ***** endfunction ***** test opt = struct ("LossTolerance", -Inf); [x, info] = __lbfgs__ (@__rosen__, [-1.2; 1], opt); crit = info.Criterion; assert_equal (x, [1; 1], 1e-5); assert_equal (info.Fval < 1e-8, true); assert_equal (crit, "gradient"); ***** test [x, info] = __lbfgs__ (@__rosen__, [-1.2; 1]); crit = info.Criterion; assert_equal (crit, "loss"); assert_equal (info.Fval <= 1e-6, true); assert_equal (info.Gradient > 1e-6, true); ***** test n = 20; x0 = zeros (n, 1); x0(1:2:n-1) = -1.2; x0(2:2:n) = 1; opt = struct ("LossTolerance", -Inf); [x, info] = __lbfgs__ (@__exrosen__, x0, opt); assert_equal (x, ones (n, 1), 1e-4); ***** test opt = struct ("LossTolerance", -Inf); [x, info] = __lbfgs__ (@__beale__, [1; 1], opt); assert_equal (x, [3; 0.5], 1e-4); ***** test opt = struct ("LossTolerance", -Inf); [x, info] = __lbfgs__ (@__wood__, [-3; -1; -3; -1], opt); assert_equal (x, ones (4, 1), 1e-4); ***** test opt = struct ("LossTolerance", -Inf); [x, info] = __lbfgs__ (@__powellsq__, [3; -1; 0; 1], opt); assert_equal (info.Fval < 1e-8, true); ***** test n = 50; xs = ((1:n)' / n).^2; opt = struct ("GradientTolerance", 1e-10, "LossTolerance", -Inf, ... "StepTolerance", 0); [x, info] = __lbfgs__ (@__quadtri__, zeros (n, 1), opt); crit = info.Criterion; assert_equal (x, xs, 1e-6); assert_equal (crit, "gradient"); ***** test opt = struct ("HistorySize", 1, "LossTolerance", -Inf); [x, info] = __lbfgs__ (@__rosen__, [-1.2; 1], opt); assert_equal (x, [1; 1], 1e-4); ***** test opt = struct ("LossTolerance", -Inf); [x, info] = __lbfgs__ (@__rosen__, [-1.2, 1], opt); assert_equal (x, [1; 1], 1e-5); ***** test opt = struct ("InitialStepSize", 1e-3, "LossTolerance", -Inf); [x1, i1] = __lbfgs__ (@__rosen__, [-1.2; 1], opt); opt = struct ("InitialStepSize", [], "LossTolerance", -Inf); [x2, i2] = __lbfgs__ (@__rosen__, [-1.2; 1], opt); assert_equal (x1, [1; 1], 1e-5); assert_equal (x2, [1; 1], 1e-5); ***** test opt = struct ("LossTolerance", 1); [x, info] = __lbfgs__ (@__rosen__, [-1.2; 1], opt); crit = info.Criterion; assert_equal (crit, "loss"); assert_equal (info.Fval <= 1, true); ***** test opt = struct ("GradientTolerance", 1e3, "StepTolerance", 1e3); [x, info] = __lbfgs__ (@__rosen__, [-1.2; 1], opt); crit = info.Criterion; assert_equal (crit, "gradient"); assert_equal (info.Iterations, 1); ***** test opt = struct ("StepTolerance", 1e3, "LossTolerance", 1e3); [x, info] = __lbfgs__ (@__rosen__, [-1.2; 1], opt); crit = info.Criterion; assert_equal (crit, "step"); assert_equal (info.Iterations, 1); ***** test opt = struct ("IterationLimit", 4); [x, info] = __lbfgs__ (@__rosen__, [-1.2; 1], opt); crit = info.Criterion; assert_equal (crit, "iteration"); assert_equal (info.Iterations, 4); assert_equal (info.History.Iteration, (1:4)'); assert_equal (numel (info.History.Fval), 4); assert_equal (info.FuncCount >= info.Iterations, true); ***** test opt = struct ("IterationLimit", 0); [x, info] = __lbfgs__ (@__rosen__, [-1.2; 1], opt); assert_equal (x, [-1.2; 1]); assert_equal (info.Iterations, 0); assert_equal (isempty (info.History.Fval), true); ***** test opt = struct ("LossTolerance", -Inf, "IterationLimit", 5); [x, info] = __lbfgs__ (@__rosen__, [-1.2; 1], opt); assert_equal (info.RelativeChangeInBeta, NaN); assert_equal (info.History.RelativeChangeInBeta, NaN (5, 1)); ***** test n = 50; opt = struct ("LossTolerance", -Inf, "BetaTolerance", 1e-12, ... "IterationLimit", 4); [x, info] = __lbfgs__ (@__quadtri__, zeros (n, 1), opt); assert_equal (info.History.RelativeChangeInBeta(1), 1); ***** test opt = struct ("LossTolerance", -Inf, "BetaTolerance", 1e3); [x, info] = __lbfgs__ (@__rosen__, [-1.2; 1], opt); assert_equal (info.Criterion, "beta"); assert_equal (info.Iterations, 1); ***** test opt = struct ("GradientTolerance", 1e3, "BetaTolerance", 1e3, ... "StepTolerance", 1e3); [x, info] = __lbfgs__ (@__rosen__, [-1.2; 1], opt); assert_equal (info.Criterion, "beta"); ***** test opt = struct ("BetaTolerance", 1e3, "StepTolerance", 1e3, ... "LossTolerance", 1e3); [x, info] = __lbfgs__ (@__rosen__, [-1.2; 1], opt); assert_equal (info.Criterion, "beta"); ***** error __lbfgs__ (@__rosen__) ***** error <__lbfgs__: FCN must be a function handle.> ... __lbfgs__ (1, [1; 1]) ***** error <__lbfgs__: X0 must be a real numeric vector.> ... __lbfgs__ (@__rosen__, {1}) ***** error <__lbfgs__: X0 must be a real numeric vector.> ... __lbfgs__ (@__rosen__, ones (2, 2)) ***** error <__lbfgs__: X0 must be a real numeric vector.> ... __lbfgs__ (@__rosen__, []) ***** error <__lbfgs__: X0 must be a real numeric vector.> ... __lbfgs__ (@__rosen__, complex ([1; 1])) ***** error <__lbfgs__: OPTIONS must be a scalar struct.> ... __lbfgs__ (@__rosen__, [1; 1], 5) ***** error <__lbfgs__: 'IterationLimit' must be a nonnegative integer scalar.> ... __lbfgs__ (@__rosen__, [1; 1], struct ("IterationLimit", -1)) ***** error <__lbfgs__: 'IterationLimit' must be a nonnegative integer scalar.> ... __lbfgs__ (@__rosen__, [1; 1], struct ("IterationLimit", 2.5)) ***** error <__lbfgs__: 'GradientTolerance' must be a nonnegative scalar.> ... __lbfgs__ (@__rosen__, [1; 1], struct ("GradientTolerance", -1)) ***** error <__lbfgs__: 'StepTolerance' must be a nonnegative scalar.> ... __lbfgs__ (@__rosen__, [1; 1], struct ("StepTolerance", -1)) ***** error <__lbfgs__: 'LossTolerance' must be a real scalar.> ... __lbfgs__ (@__rosen__, [1; 1], struct ("LossTolerance", NaN)) ***** error <__lbfgs__: 'BetaTolerance' must be a nonnegative scalar.> ... __lbfgs__ (@__rosen__, [1; 1], struct ("BetaTolerance", -1)) ***** error <__lbfgs__: 'HistorySize' must be a positive integer scalar.> ... __lbfgs__ (@__rosen__, [1; 1], struct ("HistorySize", 0)) ***** test ## Full BFGS and a weak Wolfe search reach the minimum of a quadratic. A = [4, 1; 1, 3]; fcn = @(x) deal (0.5 * x' * A * x - [1; 2]' * x, A * x - [1; 2]); opt = struct ("Method", "bfgs", "LineSearch", "weakwolfe", ... "LossTolerance", -Inf, "GradientTolerance", 1e-10); [x, info] = __lbfgs__ (fcn, [0; 0], opt); assert_equal (x, A \ [1; 2], 1e-8); assert_equal (info.Criterion, 'gradient'); ***** error <__lbfgs__: 'Method' must be 'lbfgs' or 'bfgs'.> ... __lbfgs__ (@__rosen__, [1; 1], struct ("Method", "newton")) ***** error <__lbfgs__: 'LineSearch' must be 'strongwolfe' or 'weakwolfe'.> ... __lbfgs__ (@__rosen__, [1; 1], struct ("LineSearch", "exact")) ***** error <__lbfgs__: 'InitialStepSize' must be a positive scalar.> ... __lbfgs__ (@__rosen__, [1; 1], struct ("InitialStepSize", -1)) ***** error <__lbfgs__: 'Bogus' is not a valid option.> ... __lbfgs__ (@__rosen__, [1; 1], struct ("Bogus", 1)) ***** error <__lbfgs__: FCN must return a real gradient with as many elements as X0.> ... __lbfgs__ (@__badgrad__, [1; 1]) 40 tests, 40 passed, 0 known failure, 0 skipped [src/svmtrain.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/svmtrain.cc ***** test # Test 1: Basic C-SVC Classification and Model Structure [L, D] = libsvmread (file_in_loadpath ("heart_scale.dat")); model = svmtrain(L, D, '-c 1 -g 0.07'); [predict_label, accuracy, dec_values] = svmpredict(L, D, model); assert_equal (isstruct (model), true); assert_equal (isfield (model, "Parameters"), true); assert_equal (model.totalSV, 130); assert_equal (model.nr_class, 2); assert_equal (size (model.Label), [2, 1]); # Check prediction output sizes assert_equal (size (predict_label), [length(L), 1]); assert_equal (size (dec_values), [length(L), 1]); # Test 2: One-Class SVM Model Structure Check # Ensures training with -s 2 is functional and the model structure is valid (accommodating 3.36 changes). model_oc = svmtrain(L, D, '-s 2 -n 0.5 -g 0.07'); assert_equal (isstruct (model_oc), true); assert_equal (model_oc.Parameters(1), 2); # Check svm_type is ONE_CLASS assert_equal (model_oc.nr_class, 2); assert_equal (model_oc.totalSV > 0, true); clear model_oc # Test 3: Regression SVR Test # Check training of Epsilon SVR (-s 3) model_svr = svmtrain (L, D, '-s 3 -p 0.1 -c 10'); assert_equal (isstruct (model_svr), true); assert_equal (model_svr.Parameters(1), 3); # Check svm_type is EPSILON_SVR assert_equal (model_svr.nr_class, 2); clear model_svr # Test 4: Input Argument Error Checking ***** shared L, D [L, D] = libsvmread (file_in_loadpath ("heart_scale.dat")); # Check argument count errors ***** error [L, D, C] = svmtrain (L, D); ***** error model = svmtrain (L, D, "", ones (270, 1), 1); # Check argument type errors ***** error ... model = svmtrain (single (L), D); # Check dimension mismatch error ***** error ... model = svmtrain (L(1:end-1), D); ***** test ## Instance weights scale the box constraint: unit weights change nothing, ## and weights of 2 are the same fit as doubling C. [L, D] = libsvmread (file_in_loadpath ("heart_scale.dat")); m1 = svmtrain (L, D, '-t 0 -c 1 -q'); m2 = svmtrain (L, D, '-t 0 -c 1 -q', ones (270, 1)); assert_equal (m2.sv_coef, m1.sv_coef); assert_equal (m2.rho, m1.rho); m3 = svmtrain (L, D, '-t 0 -c 2 -q'); m4 = svmtrain (L, D, '-t 0 -c 1 -q', 2 * ones (270, 1)); assert_equal (m4.sv_coef, m3.sv_coef, 1e-12); assert_equal (m4.rho, m3.rho, 1e-12); ***** error ... svmtrain ([1; -1; 1; -1], [1; 2; 3; 4], "-q", [1, 1]) ***** error ... svmtrain ([1; -1; 1; -1], [1; 2; 3; 4], "-q", [1; -1; 1; 1]) ***** test [L, D] = libsvmread (file_in_loadpath ("heart_scale.dat")); [~, converged] = svmtrain (L, D, '-c 1 -g 0.07 -q'); assert_equal (converged, true); ***** test x = (1:20)' * 1000; [~, converged] = svmtrain (x / 100, x, '-s 3 -t 1 -g 1 -r 0 -c 1 -q'); assert_equal (converged, false); # Test 5: One-Class Probability Training (New LIBSVM 3.36 Feature) # This ensures svmtrain DOES NOT reject -s 2 combined with -b 1 # and correctly populates the new ProbDensityMarks field. ***** test [L, D] = libsvmread (file_in_loadpath ("heart_scale.dat")); model = svmtrain (L, D, '-s 2 -n 0.1 -g 0.07 -b 1'); assert_equal (isstruct (model), true); assert_equal (model.Parameters(1), 2); # Check svm_type is ONE_CLASS # CRITICAL CHECK: Verify the new field exists (Specific to upgrade) assert_equal (isfield (model, "ProbDensityMarks"), true); clear model 11 tests, 11 passed, 0 known failure, 0 skipped [src/__treeprune__.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/__treeprune__.cc ***** test ## The link of a root whose two leaves cost less than it does C = [2, 3; 0, 0; 0, 0]; P = [0; 1; 1]; [L, A] = __treeprune__ (C, P, [1; 0.4; 0.4], zeros (3, 1)); assert_equal (L', [1, 0, 0]); assert_equal (A', [0, 0.2], 1e-14); ***** test ## What a node holds back is part of its subtree's risk ## The same tree, charged 0.1 for rows that reached neither child, gives ## a link of 0.1 where it gave 0.2. C = [2, 3; 0, 0; 0, 0]; P = [0; 1; 1]; [L, A] = __treeprune__ (C, P, [1; 0.4; 0.4], [0.1; 0; 0]); assert_equal (L', [1, 0, 0]); assert_equal (A', [0, 0.1], 1e-14); ***** test ## A subtree costing nothing takes no level and no alpha C = [2, 3; 0, 0; 0, 0]; P = [0; 1; 1]; [L, A] = __treeprune__ (C, P, [0.8; 0.4; 0.4], zeros (3, 1)); assert_equal (L', [0, 0, 0]); assert_equal (A', 0); ***** test ## Deeper branches go at their own level, weakest first C = [2, 3; 4, 5; 0, 0; 0, 0; 0, 0]; P = [0; 1; 1; 2; 2]; [L, A] = __treeprune__ (C, P, [1; 0.5; 0.3; 0.2; 0.2], zeros (5, 1)); assert_equal (L', [2, 1, 0, 0, 0]); assert_equal (A', [0, 0.1, 0.2], 1e-14); ***** test ## A branch that lost an ancestor carries the ancestor's level ## Node 2 has the stronger link and never comes up on its own account, ## but it stopped being a branch when node 1 went. C = [2, 3; 4, 5; 0, 0; 0, 0; 0, 0]; P = [0; 1; 1; 2; 2]; [L, A] = __treeprune__ (C, P, [1; 0.9; 0.3; 0.25; 0.25], zeros (5, 1)); assert_equal (L', [1, 1, 0, 0, 0]); assert_equal (A', [0, 0.1], 1e-14); ***** test ## The scale is the caller's and nothing here interprets it C = [2, 3; 0, 0; 0, 0]; P = [0; 1; 1]; [~, A] = __treeprune__ (C, P, [10; 4; 4], zeros (3, 1)); assert_equal (A', [0, 2], 1e-13); ***** test ## A tree of one node has no branch to prune [L, A] = __treeprune__ ([0, 0], 0, 1, 0); assert_equal (L, 0); assert_equal (A, 0); ***** function [L, A] = seq (T) if (isempty (T.ClassWeight)) risk = T.NodeWeight .* T.NodeError; else risk = T.NodeWeight - max (T.ClassWeight, [], 2); endif held = zeros (T.NumNodes, 1); br = find (T.Children(:,1) > 0); if (! isempty (br)) kd = T.Children(br,:); wh = T.NodeWeight(br) - T.NodeWeight(kd(:,1)) - T.NodeWeight(kd(:,2)); held(br) = wh .* risk(br) ./ T.NodeWeight(br); endif [L, A] = __treeprune__ (T.Children, T.Parent, risk, held); ***** endfunction ***** test ## Levels and alphas of the merged iris tree. Measured on R2024a. load fisheriris y = grp2idx (species); o = struct ('NumClasses', 3, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', 'MergeLeaves', true); [L, A] = seq (treetrain (meas, y, ones (150, 1) / 150, o)); assert_equal (L', [4, 0, 3, 2, 0, 1, 0, 0, 0]); assert_equal (A', [0, 1/150, 2/150, 44/150, 50/150], 1e-12); ***** test ## A deeper tree, every branch pruned at its own level load fisheriris y = grp2idx (species); o = struct ('NumClasses', 3, 'MinParent', 2, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', 'MergeLeaves', true); L = seq (treetrain (meas, y, ones (150, 1) / 150, o)); assert_equal (L', [5, 0, 4, 3, 1, 2, 2, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0]); ***** test ## A subtree that costs nothing to give up opens no level of the sequence ## The pair of leaves that merging would have removed survives here, and ## giving it up costs nothing, so the eleven node tree carries the merged ## tree's five alphas rather than six. Measured on R2024a. load fisheriris y = grp2idx (species); o = struct ('NumClasses', 3, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', 'MergeLeaves', false); [L, A] = seq (treetrain (meas, y, ones (150, 1) / 150, o)); assert_equal (L', [4, 0, 3, 2, 0, 1, 0, 0, 0, 0, 0]); assert_equal (A', [0, 1/150, 2/150, 44/150, 50/150], 1e-12); ***** test ## A node holding rows back pays for them in the pruning sequence ## Twenty rows have no fourth predictor, so the node cutting on it sends ## them to neither child. A subtree's risk is its children's plus what ## the node holds back; without it the sequence came out a level short. ## Measured on R2024a, the fit fitctree makes on this fixture. load fisheriris y = grp2idx (species); x = meas; x(51:70, 4) = NaN; o = struct ('NumClasses', 3, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', 'MergeLeaves', true); [L, A] = seq (treetrain (x, y, ones (150, 1) / 150, o)); assert_equal (L', [4, 0, 3, 1, 2, 0, 0, 0, 0]); assert_equal (A', [0, 0.00385185185185185, 0.00593939393939394, ... 0.286666666666666, 0.333333333333333], 1e-14); ***** test ## A held back node keeps the free subtree rule honest ## Charged for what it holds back, such a node gives a positive link ## where an uncharged one gave zero, so the free subtree left by ## MergeLeaves off must still be the one recognised. Measured on R2024a. load fisheriris y = grp2idx (species); x = meas; x(51:70, 4) = NaN; o = struct ('NumClasses', 3, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 149, 'SplitCriterion', 'gdi', 'MergeLeaves', false); [L, A] = seq (treetrain (x, y, ones (150, 1) / 150, o)); assert_equal (L', [4, 0, 3, 1, 2, 0, 0, 0, 0, 0, 0]); assert_equal (A', [0, 0.00385185185185185, 0.00593939393939394, ... 0.286666666666666, 0.333333333333333], 1e-14); ***** test ## A regression tree, sequenced on the squared error about each mean g = mod ((1:20)', 3); x = [(1:20)', g]; y = [ones(10,1); 5 * ones(10,1)]; o = struct ('NumClasses', 1, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 19, 'SplitCriterion', 'mse', ... 'MergeLeaves', true, 'QEToler', 1e-6); L = seq (treetrain (x, y, ones (20, 1) / 20, o)); assert_equal (L', [1, 0, 0]); ***** test ## A regression node holding a row back pays for it too ## One carsmall row has no horsepower and node 2 cuts on horsepower, so ## that row stops there and is in neither child. Charging it the node's ## own error puts this alpha at 5.99 rather than 6.32. Measured on ## R2024a, the fit fitrtree makes on this fixture. load carsmall X = [Weight, Cylinders, Horsepower]; ok = ! isnan (MPG); o = struct ('NumClasses', 1, 'MinParent', 10, 'MinLeaf', 1, ... 'MaxSplits', 93, 'SplitCriterion', 'mse', ... 'MergeLeaves', true, 'QEToler', 1e-6); [L, A] = seq (treetrain (X(ok, :), MPG(ok), ones (94, 1) / 94, o)); assert_equal (L(1:5)', [17, 16, 14, 15, 13]); assert_equal (numel (A), 18); assert_equal (A(17), 5.99325416896717, 1e-12); assert_equal (A(18), 41.4954735525515, 1e-11); ***** error __treeprune__ ([0, 0], 0, 1) ***** error <__treeprune__: Children must be a non-empty N-by-2 real matrix.> ... __treeprune__ ([], [], [], []) ***** error <__treeprune__: Children must be a non-empty N-by-2 real matrix.> ... __treeprune__ ([0, 0, 0], 0, 1, 0) ***** error <__treeprune__: Parent must hold one node number per node.> ... __treeprune__ ([0, 0], [0; 0], 1, 0) ***** error <__treeprune__: risk must hold one value per node.> ... __treeprune__ ([0, 0], 0, [1; 1], 0) ***** error <__treeprune__: held must hold one value per node.> ... __treeprune__ ([0, 0], 0, 1, [0; 0]) ***** error <__treeprune__: Children must hold a node number in each row, or zero in both on a leaf.> ... __treeprune__ ([2, 0; 0, 0], [0; 1], [1; 0.5], [0; 0]) ***** error <__treeprune__: Children must hold a node number in each row, or zero in both on a leaf.> ... __treeprune__ ([2, 9; 0, 0], [0; 1], [1; 0.5], [0; 0]) ***** error <__treeprune__: Parent must hold a node number, or zero at the root.> ... __treeprune__ ([2, 3; 0, 0; 0, 0], [0; 9; 1], [1; 0.4; 0.4], zeros (3, 1)) 23 tests, 23 passed, 0 known failure, 0 skipped [src/__shapleytree__.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/__shapleytree__.cc ***** error __shapleytree__ () ***** error __shapleytree__ (1, 2, 3) ***** error __shapleytree__ ({1}, {}, 3) ***** error __shapleytree__ ({1}, [1 2], {}) ***** error __shapleytree__ ({}, [1 2], [1 2]) ***** error __shapleytree__ ({1}, [1 2], [1 2 3]) ***** test T.Children = [2, 3; 0, 0; 0, 0]; T.CutVar = [1; 0; 0]; T.CutPoint = [0.5; NaN; NaN]; T.Leaf = [0; 10; 20]; X = [0, 7; 0, 8; 1, 9; 1, 6]; phi = __shapleytree__ ({T}, X, [1, 7]); assert (size (phi), [2, 1]); assert (phi(1), 5, 1e-12); assert (phi(2), 0, 1e-12); ***** test T1.Children = [2, 3; 0, 0; 0, 0]; T1.CutVar = [1; 0; 0]; T1.CutPoint = [0.5; NaN; NaN]; T1.Leaf = [0; 10; 20]; T2.Children = [2, 3; 0, 0; 0, 0]; T2.CutVar = [2; 0; 0]; T2.CutPoint = [7.5; NaN; NaN]; T2.Leaf = [0; 1; 3]; X = [0, 7; 0, 8; 1, 9; 1, 6]; a = __shapleytree__ ({T1}, X, [1, 7]); b = __shapleytree__ ({T2}, X, [1, 7]); both = __shapleytree__ ({T1, T2}, X, [1, 7]); assert (both, a + b, 1e-12); ***** test T.Children = [2, 3; 0, 0; 0, 0]; T.CutVar = [1; 0; 0]; T.CutPoint = [NaN; NaN; NaN]; T.CatLeft = {[1, 2]; []; []}; T.CatRight = {[3]; []; []}; T.Leaf = [0; 4; 10]; X = [1; 2; 3; 3]; phi = __shapleytree__ ({T}, X, 3); assert (phi, 3, 1e-12); ***** test T.Children = [2, 3; 0, 0; 0, 0]; T.CutVar = [1; 0; 0]; T.CutPoint = [0.5; NaN; NaN]; T.Leaf = [0; 10; 20]; X = [0, 7; 0, 8; 1, 9; 1, 6]; phi = __shapleytree__ ({T}, X, [1, 7; 0, 7]); assert (size (phi), [2, 1, 2]); assert (phi(1,1,1), 5, 1e-12); assert (phi(1,1,2), -5, 1e-12); 10 tests, 10 passed, 0 known failure, 0 skipped [src/gamboosttrain.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/gamboosttrain.cc ***** test ## Every field is present and the shapes follow the predictor count. x = [1 5; 2 4; 3 3; 4 2; 5 1; 6 7; 7 8; 8 9; 9 10; 10 11]; y = [0; 0; 0; 0; 0; 1; 1; 1; 1; 1]; M = gamboosttrain (x, y, 1, 50, 1, 1); assert_equal (isstruct (M), true); assert_equal (numel (M.BinEdges), 2); assert_equal (numel (M.ShapeValues), 2); assert_equal (numel (M.ShapeValues{1}), numel (M.BinEdges{1}) + 1); assert_equal (numel (M.Residuals), 10); ***** test ## A predictor is cut at every midpoint between its distinct values. x = [1; 2; 3; 4; 2; 3]; y = [0; 0; 1; 1; 0; 1]; M = gamboosttrain (x, y, 1, 5, 1, 1); assert_equal (M.BinEdges{1}, [1.5, 2.5, 3.5], 1e-12); ***** test ## Fewer than ten observations cannot be split at all: a leaf holds at ## least five. R2024a does the same, on fitcgam and fitrgam alike. The ## rounds still run and still count, because with no shape function to fit ## they reweight the intercept alone, and it converges on the log-odds of ## the response mean rather than being seeded there. R2024a reports ## exactly log (4/5) and a flat score on this fixture. x = (1:9)'; y = [zeros(5, 1); ones(4, 1)]; M = gamboosttrain (x, y, 1, 50, 1, 1); assert_equal (max (M.ShapeValues{1}) - min (M.ShapeValues{1}), 0, 1e-12); assert_equal (M.Intercept, log (4/5), 1e-10); assert_equal (M.ReasonForTermination, 'Unable to improve the model fit.'); M10 = gamboosttrain ((1:10)', [zeros(5, 1); ones(5, 1)], 1, 50, 1, 1); assert_equal (max (M10.ShapeValues{1}) - min (M10.ShapeValues{1}) > 1, true); ***** test ## A constant predictor admits no split: one bin and no cut points. x = [2; 2; 2; 2]; y = [0; 1; 0; 1]; M = gamboosttrain (x, y, 1, 5, 1, 1); assert_equal (isempty (M.BinEdges{1}), true); assert_equal (numel (M.ShapeValues{1}), 1); ***** test ## A regression intercept is the response mean and boosting leaves it there. x = (1:16)'; y = [2; 4; 5; 4; 6; 8; 9; 10; 11; 13; 12; 15; 16; 18; 17; 20]; M = gamboosttrain (x, y, 2, 40, 1, 1); assert_equal (M.NumTrees > 0, true); assert_equal (M.Intercept, mean (y), 1e-12); ***** test ## A classifier intercept is seeded at zero, an even chance, and boosting ## moves it, so a balanced response does not stay there. ## Sixteen observations, not eight: a leaf holds at least five, so a fit ## with fewer than ten cannot split at all and its intercept never moves. x = (1:16)'; y = [zeros(8, 1); ones(8, 1)]; M = gamboosttrain (x, y, 1, 60, 1, 1); assert_equal (M.NumTrees > 0, true); assert_equal (M.Intercept != 0, true); ***** test ## The tree budget is a budget: a fit that converges reports so and stops ## short of it. x = (1:16)'; y = [zeros(8, 1); ones(8, 1)]; M = gamboosttrain (x, y, 1, 5000, 1, 1); assert_equal (M.ReasonForTermination, 'Unable to improve the model fit.'); assert_equal (M.NumTrees > 0, true); assert_equal (M.NumTrees < 5000, true); ***** test ## A budget too small to converge in reports the other reason. x = (1:16)'; y = [zeros(8, 1); ones(8, 1)]; M = gamboosttrain (x, y, 1, 2, 1, 1); assert_equal (M.ReasonForTermination, ... 'Terminated after training the requested number of trees.'); assert_equal (M.NumTrees, 2); ***** test ## A single-class response has an infinite log-odds and nothing to fit. x = [1; 2; 3; 4]; y = [1; 1; 1; 1]; M = gamboosttrain (x, y, 1, 10, 1, 1); assert_equal (M.Intercept, Inf); assert_equal (M.NumTrees, 0); ***** test ## A missing predictor value costs the observation that term, not the fit. x = [1; 2; NaN; 4; 5; 6; 7; 8; 9; 10; 11; 12]; y = [0; 0; 0; 0; 0; 0; 1; 1; 1; 1; 1; 1]; M = gamboosttrain (x, y, 1, 20, 1, 1); assert_equal (M.NumTrees > 0, true); assert_equal (isfinite (M.Intercept), true); assert_equal (any (isnan (M.ShapeValues{1})), false); ***** test ## More splits per tree reach a lower deviance on a shape one split cannot ## follow. Thirty observations, not ten: three splits make four leaves and ## a leaf holds at least five, so ten could never use the larger budget. x = (1:30)'; y = [zeros(8, 1); ones(14, 1); zeros(8, 1)]; M1 = gamboosttrain (x, y, 1, 30, 1, 1); M2 = gamboosttrain (x, y, 1, 30, 1, 3); assert_equal (M2.Deviance < M1.Deviance, true); ***** test ## Above the cap the cuts are equally spaced through the OBSERVATIONS, not ## through the distinct values, so they crowd where the data is. Values 1 ## to 50 carry 1000 of these 1450 rows and values 51 to 500 carry one row ## each: R2024a puts 49 cuts in that dense fifth of the range, one between ## each pair of neighbouring values. x = [repmat((1:50)', 20, 1); (51:500)']; y = double (mod (1:1450, 2))'; M = gamboosttrain (x, y, 1, 1, 1, 1); assert_equal (sum (M.BinEdges{1} < 50), 49); ***** test ## Ties collapse cuts: two quantile positions inside one repeated value ## give the same cut, and the repeats are dropped, so a tied predictor ends ## with fewer than the cap allows rather than with duplicate edges. R2024a ## keeps 129 here, the first at 1.5. x = [repmat((1:50)', 20, 1); (51:500)']; y = double (mod (1:1450, 2))'; M = gamboosttrain (x, y, 1, 1, 1, 1); assert_equal (numel (M.BinEdges{1}), 129); assert_equal (numel (unique (M.BinEdges{1})), 129); assert_equal (M.BinEdges{1}(1:3), [1.5, 2.5, 3.5]); ***** test ## The cap binds at 255 cut points however many distinct values there are. x = (1:2000)'; y = double (mod (1:2000, 2))'; M = gamboosttrain (x, y, 1, 1, 1, 1); assert_equal (numel (M.BinEdges{1}), 255); ***** test ## Below the cap nothing is thinned: one cut per gap between distinct ## values, which is what MATLAB, scikit-learn and the EBM all report. x = (1:200)'; y = double (mod (1:200, 2))'; M = gamboosttrain (x, y, 1, 1, 1, 1); assert_equal (numel (M.BinEdges{1}), 199); assert_equal (M.BinEdges{1}(1:3), [1.5, 2.5, 3.5], 1e-12); ***** test ## Patience looks across a window rather than at one round: a fit that has ## stopped earning its keep ends and says so, well short of its budget. x = [1; 2; 3; 4; 5; 6; 7; 8]; y = [0; 0; 0; 0; 1; 1; 1; 1]; M = gamboosttrain (x, y, 1, 100000, 1, 1); assert_equal (M.ReasonForTermination, 'Unable to improve the model fit.'); assert_equal (M.NumTrees < 1000, true); ***** test ## A verbose fit prints a trace and returns the same model as a quiet one. x = [1; 2; 3; 4; 5; 6; 7; 8]; y = [0; 0; 0; 0; 1; 1; 1; 1]; Q = gamboosttrain (x, y, 1, 20, 1, 1); V = evalc ('W = gamboosttrain (x, y, 1, 20, 1, 1, 1, 5);'); assert_equal (W.Intercept, Q.Intercept, 1e-12); assert_equal (W.NumTrees, Q.NumTrees); assert_equal (! isempty (strfind (V, 'NumTrees')), true); assert_equal (! isempty (strfind (V, 'LearnRate')), true); ***** test ## NumPrint controls how often a round is reported: the first, then every ## NumPrint after it. x = (1:16)'; y = [zeros(8, 1); ones(8, 1)]; V5 = evalc ('gamboosttrain (x, y, 1, 20, 1, 1, 1, 5);'); V1 = evalc ('gamboosttrain (x, y, 1, 20, 1, 1, 1, 1);'); assert_equal (numel (strfind (V1, '| 1D|')) > ... numel (strfind (V5, '| 1D|')), true); ***** test ## Verbose 0 prints nothing at all. x = [1; 2; 3; 4; 5; 6; 7; 8]; y = [0; 0; 0; 0; 1; 1; 1; 1]; V = evalc ('gamboosttrain (x, y, 1, 20, 1, 1, 0, 5);'); assert_equal (isempty (strfind (V, '1D')), true); ***** test ## Above 255 cuts the grid follows R2024a: cut k at the midpoint of the ## sorted values at positions ceil (k*n/256) and ceil (k*n/256) + 1. k = (1:700)'; X = [sin(k), cos(2.3 * k)]; M = gamboosttrain (X, X(:,1) + X(:,2), 2, 1, 1, 1); E = M.BinEdges{1}; assert_equal (numel (E), 255); assert_equal (E([1, 2, 3, 100, 255]), ... [-0.99991205908099445, -0.99963859878373096, ... -0.99920743414670821, -0.32997659740324592, ... 0.99995116627924441], 1e-15); ***** test ## Where the two values at a position are equal the cut moves up to the ## next larger value, and repeated cuts are dropped, as R2024a does. k = (1:1000)'; x = round (sin (1.7 * k) * 300) / 300; M = gamboosttrain ([x, sin(k)], sin (k), 2, 1, 1, 1); E = M.BinEdges{1}; assert_equal (numel (E), 231); assert_equal (E([1, 2, 3, 100, 231]), ... [-0.99833333333333329, -0.995, -0.9916666666666667, ... -0.19166666666666665, 0.99833333333333329], 1e-15); ***** test ## MATLAB parity: a categorical predictor's levels are sorted by the step ## each would take alone before a tree chooses its cut. Level codes stand ## for the levels, and a missing or unseen level is NaN. k = (0:119)'; c1 = mod (k, 3) + 1; x2 = sin (k); c3 = mod (floor (k / 2), 2) + 1; y = 5 * (c1 == 2) + 0.5 * x2 - 3 * (c3 == 2) + 0.1 * cos (k); M = gamboosttrain ([c1, x2, c3], y, 2, 1, 1, 1, 0, 10, [], [], ... [true, false, true]); assert_equal (M.BinEdges{1}, [1.5, 2.5]); assert_equal (M.Intercept, 0.1666859425, 1e-10); Q = [1, 0, 1; 2, 0, 1; 3, 0, 1; 1, 0, 2; 1, 0.5, 1; NaN, 0, 1; ... NaN, 0, 1; NaN, 0, 2]; yq = gamboostpredict (M.BinEdges, M.ShapeValues, Q, M.Intercept); assert_equal (yq', [-0.3546416246, 4.645371152, -0.3546416246, ... -3.30728817, 0.4241346437, 1.312029301, ... 1.312029301, -1.640617244], 1e-9); ***** error gamboosttrain (1, 2, 3) ***** error ... gamboosttrain ('a', [1;0], 1, 10, 1, 1) ***** error ... gamboosttrain ([1;2], [1, 0], 1, 10, 1, 1) ***** error ... gamboosttrain ([1;2;3], [1;0], 1, 10, 1, 1) ***** error ... gamboosttrain ([1;2], [1;0], 3, 10, 1, 1) ***** error ... gamboosttrain ([1;2], [1;0], 1, 0, 1, 1) ***** error ... gamboosttrain ([1;2], [1;0], 1, 10, 0, 1) ***** error ... gamboosttrain ([1;2], [1;0], 1, 10, 2, 1) ***** error ... gamboosttrain ([1;2], [1;0], 1, 10, 1, 0) ***** error ... gamboosttrain ([1;2], [1;2], 1, 10, 1, 1) ***** error ... gamboosttrain ([1;2], [1;0], 1, 10, 1, 1, -1, 5) ***** error ... gamboosttrain ([1;2], [1;0], 1, 10, 1, 1, 1, 0) 34 tests, 34 passed, 0 known failure, 0 skipped [src/gampredict.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/gampredict.cc ***** test ## The additive prediction is the intercept plus each term's spline x = linspace (0, 1, 40)'; pp = splinefit (x, cos (3*x), 5, 'order', 3); P = struct ('form', 'pp', 'breaks', pp.breaks, 'coefs', pp.coefs, ... 'pieces', pp.pieces, 'order', pp.order, 'dim', pp.dim); assert_equal (gampredict (P, x, 0), ppval (pp, x), 1e-14); assert_equal (gampredict (P, x, 2.5), ppval (pp, x) + 2.5, 1e-14); ***** test ## Two terms add x = linspace (0, 1, 30)'; p1 = splinefit (x, cos (3*x), 5, 'order', 3); p2 = splinefit (x, x.^2, 4, 'order', 2); P(1) = struct ('form', 'pp', 'breaks', p1.breaks, 'coefs', p1.coefs, ... 'pieces', p1.pieces, 'order', p1.order, 'dim', p1.dim); P(2) = struct ('form', 'pp', 'breaks', p2.breaks, 'coefs', p2.coefs, ... 'pieces', p2.pieces, 'order', p2.order, 'dim', p2.dim); y = gampredict (P, [x, x], 1); assert_equal (y, 1 + ppval (p1, x) + ppval (p2, x), 1e-13); ***** test ## Fewer columns than terms is an error, not a truncated model. A caller ## that passes the predictors alone to a model carrying interaction terms ## used to be answered with the prediction of its leading terms. x = linspace (0, 1, 30)'; p1 = splinefit (x, cos (3*x), 5, 'order', 3); p2 = splinefit (x, x.^2, 4, 'order', 2); P2(1) = struct ('form', 'pp', 'breaks', p1.breaks, 'coefs', p1.coefs, ... 'pieces', p1.pieces, 'order', p1.order, 'dim', p1.dim); P2(2) = struct ('form', 'pp', 'breaks', p2.breaks, 'coefs', p2.coefs, ... 'pieces', p2.pieces, 'order', p2.order, 'dim', p2.dim); fail ('gampredict (P2, x, 0)', ... 'gampredict: X must have one column per additive term.'); assert_equal (gampredict (P2, [x, x], 0), ... ppval (p1, x) + ppval (p2, x), 1e-13); ***** test ## The logistic link returns both class probabilities, and they sum to one x = linspace (0, 1, 20)'; pp = splinefit (x, 4*x - 2, 5, 'order', 3); P = struct ('form', 'pp', 'breaks', pp.breaks, 'coefs', pp.coefs, ... 'pieces', pp.pieces, 'order', pp.order, 'dim', pp.dim); s = gampredict (P, x, 0, 1); assert_equal (size (s), [20, 2]); assert_equal (sum (s, 2), ones (20, 1), 1e-14); assert_equal (s(:,2), 1 ./ (1 + exp (- gampredict (P, x, 0))), 1e-14); ***** test ## A point outside the fitted range is extrapolated from the nearest piece, ## exactly as ppval extrapolates x = linspace (0, 1, 30)'; pp = splinefit (x, cos (3*x), 5, 'order', 3); P = struct ('form', 'pp', 'breaks', pp.breaks, 'coefs', pp.coefs, ... 'pieces', pp.pieces, 'order', pp.order, 'dim', pp.dim); xq = [-0.5; 1.5]; assert_equal (gampredict (P, xq, 0), ppval (pp, xq), 1e-13); ***** test ## A missing predictor predicts NaN, and leaves the other rows alone x = linspace (0, 1, 10)'; pp = splinefit (x, cos (3*x), 4, 'order', 3); P = struct ('form', 'pp', 'breaks', pp.breaks, 'coefs', pp.coefs, ... 'pieces', pp.pieces, 'order', pp.order, 'dim', pp.dim); xq = [0.2; NaN; 0.8]; y = gampredict (P, xq, 0); assert (isnan (y(2))); assert_equal (y([1, 3]), ppval (pp, [0.2; 0.8]), 1e-14); ***** shared P pp = splinefit (linspace (0, 1, 20)', linspace (0, 1, 20)', 4, 'order', 3); P = struct ('form', 'pp', 'breaks', pp.breaks, 'coefs', pp.coefs, ... 'pieces', pp.pieces, 'order', pp.order, 'dim', pp.dim); ***** error gampredict () ***** error gampredict (P, ones (5, 1)) ***** error gampredict (P, ones (5, 1), 0, 1, 2) ***** error ... gampredict (5, ones (5, 1), 0) ***** error gampredict (P, 'a', 0) ***** error ... gampredict (P, ones (5, 3), 0) ***** error ... gampredict (P, ones (5, 1), [1, 2]) ***** error ... gampredict (P, ones (5, 1), 0, 'a') ***** error ... gampredict (P, ones (5, 1), 0, 2) 15 tests, 15 passed, 0 known failure, 0 skipped [src/fcnnpredict.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/fcnnpredict.cc ***** shared X, Y, MODEL, W, B load fisheriris X = meas; Y = grp2idx (species); MODEL = fcnntrain (X, Y, 10, "sigmoid", "sigmoid", 1, 0.025, 100, false); W = cellfun (@(m) m(:,1:end-1), MODEL.LayerWeights, "UniformOutput", false); B = cellfun (@(m) m(:,end), MODEL.LayerWeights, "UniformOutput", false); ***** test [Y_pred, Y_scores] = fcnnpredict (W, B, "sigmoid", "sigmoid", X); assert_equal (numel (Y_pred), numel (Y)); assert_equal (isequal (size (Y_pred), size (Y)), true); assert_equal (columns (Y_scores), numel (unique (Y))); assert_equal (rows (Y_scores), numel (Y)); ***** test rand ("seed", 42); randn ("seed", 42); Xs = [randn(40,2)*0.3 + 3; randn(40,2)*0.3 - 3]; Ys = [ones(40,1); 2*ones(40,1)]; M = fcnntrain (Xs, Ys, [8, 8], "sigmoid", "sigmoid", 1, 0.05, 400, false); Wm = cellfun (@(m) m(:,1:end-1), M.LayerWeights, "UniformOutput", false); Bm = cellfun (@(m) m(:,end), M.LayerWeights, "UniformOutput", false); [pred, scores] = fcnnpredict (Wm, Bm, "sigmoid", "sigmoid", [3, 3; -3, -3]); assert_equal (pred, [1; 2]); assert_equal (max (scores(1,:)) > 0.8, true); assert_equal (max (scores(2,:)) > 0.8, true); assert_equal (all (abs (sum (scores, 2) - 1) < 0.1), true); ***** test rand ("seed", 42); randn ("seed", 42); Xs = [randn(40,2)*0.3 + 3; randn(40,2)*0.3 - 3]; Ys = [ones(40,1); 2*ones(40,1)]; Mm = fcnntrain (Xs, Ys, [8, 8], "sigmoid", "softmax", 1, 0.05, 400, false, 0); Mc = fcnntrain (Xs, Ys, [8, 8], "sigmoid", "softmax", 1, 0.05, 400, false, 1); Wm = cellfun (@(m) m(:,1:end-1), Mm.LayerWeights, "UniformOutput", false); Bm = cellfun (@(m) m(:,end), Mm.LayerWeights, "UniformOutput", false); Wc = cellfun (@(m) m(:,1:end-1), Mc.LayerWeights, "UniformOutput", false); Bc = cellfun (@(m) m(:,end), Mc.LayerWeights, "UniformOutput", false); [pm, sm] = fcnnpredict (Wm, Bm, "sigmoid", "softmax", [3, 3; -3, -3]); [pc, sc] = fcnnpredict (Wc, Bc, "sigmoid", "softmax", [3, 3; -3, -3]); assert_equal (pm, [1; 2]); assert_equal (pc, [1; 2]); assert_equal (all (abs (sum (sc, 2) - 1) < 1e-8), true); assert_equal (min (max (sc, [], 2)) >= min (max (sm, [], 2)), true); ***** test rand ("seed", 42); randn ("seed", 42); Xs = [randn(20,2)*0.3 + 3; randn(20,2)*0.3 - 3]; Ys = [ones(20,1); 2*ones(20,1)]; rand ("seed", 1); M9 = fcnntrain (Xs, Ys, 6, "sigmoid", "sigmoid", 1, 0.05, 100, false); rand ("seed", 1); M0 = fcnntrain (Xs, Ys, 6, "sigmoid", "sigmoid", 1, 0.05, 100, false, 0); assert_equal (M9.Loss, M0.Loss, 0); ***** error ... fcnnpredict (W, B, "sigmoid", "sigmoid"); ***** error ... [Q, E, R] = fcnnpredict (W, B, "sigmoid", "sigmoid", X); ***** error ... fcnnpredict (1, B, "sigmoid", "sigmoid", X); ***** error ... fcnnpredict ({1}, B, "sigmoid", "sigmoid", X); ***** error ... fcnnpredict ({1; 2; 3}, B, "sigmoid", "sigmoid", X); ***** error ... fcnnpredict (W, 1, "sigmoid", "sigmoid", X); ***** error ... fcnnpredict (W, {1}, "sigmoid", "sigmoid", X); ***** error ... fcnnpredict (W, [B, B], "sigmoid", "sigmoid", X); ***** error ... fcnnpredict (W, {B{1}(1:end-1), B{2}}, "sigmoid", "sigmoid", X); ***** error ... fcnnpredict (W, B, 2, "sigmoid", X); ***** error ... fcnnpredict (W, B, {2, 2}, "sigmoid", X); ***** error ... fcnnpredict (W, B, {"sigmoid", "relu"}, "sigmoid", X); ***** error ... fcnnpredict (W, B, "sgmoid", "sigmoid", X); ***** error ... fcnnpredict (W, B, "sigmoid", 4, X); ***** error ... fcnnpredict (W, B, "sigmoid", "softmx", X); ***** error ... fcnnpredict (W, B, "sigmoid", "sigmoid", complex (X)); ***** error ... fcnnpredict (W, B, "sigmoid", "sigmoid", {1, 2, 3, 4}); ***** error ... fcnnpredict (W, B, "sigmoid", "sigmoid", "asd"); ***** error ... fcnnpredict (W, B, "sigmoid", "sigmoid", []); ***** error ... fcnnpredict (W, B, "sigmoid", "sigmoid", X(:,[1:3])); ***** error ... fcnnpredict (W, B, "sigmoid", "sigmoid", X, 0); 25 tests, 25 passed, 0 known failure, 0 skipped [src/libsvmwrite.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/libsvmwrite.cc ***** shared L, D [L, D] = libsvmread (file_in_loadpath ("heart_scale.dat")); ***** error libsvmwrite ("", L, D); ***** error ... libsvmwrite (tempname (), [L;L], D); ***** error ... OUT = libsvmwrite (tempname (), L, D); ***** error ... libsvmwrite (tempname (), single (L), D); ***** error libsvmwrite (13412, L, D); ***** error ... libsvmwrite (tempname (), L, full (D)); ***** error ... libsvmwrite (tempname (), L, D, D); 7 tests, 7 passed, 0 known failure, 0 skipped [src/gamtrain.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/gamtrain.cc ***** test ## The boosted model returns the fields the learners store X = [linspace(0, 1, 40)', linspace(1, 2, 40)']; Y = double ([1:40]' > 20); Mdl = gamtrain (X, Y, [5, 5], [3, 3], 1, 0.5, 0.1, 100); assert_equal (fieldnames (Mdl), ... {'Intercept'; 'Parameters'; 'Iterations'; 'Residuals'; 'RSS'}); assert_equal (size (Mdl.Parameters), [1, 2]); assert_equal (Mdl.Iterations, 100); assert_equal (size (Mdl.Residuals), [40, 1]); assert_equal (size (Mdl.RSS), [1, 1]); assert_equal (Mdl.Intercept, log (0.5 / 0.5), 1e-14); ***** test ## A spline of K pieces and degree D is a piecewise polynomial of K pieces ## and K + D coefficients per term X = linspace (0, 1, 30)'; Y = double ([1:30]' > 15); Mdl = gamtrain (X, Y, 6, 3, 1, 0.5, 0.1, 20); P = Mdl.Parameters(1); assert_equal (P.form, 'pp'); assert_equal (P.pieces, 6); assert_equal (P.order, 4); assert_equal (P.dim, 1); assert_equal (size (P.coefs), [6, 4]); assert_equal (size (P.breaks), [1, 7]); ***** test ## The engine reproduces splinefit on a single fitted term. One boosting ## round at a learning rate of one is the spline of the gradient, which for ## an intercept of one half is the response less one half. x = linspace (0, 1, 50)'; Y = double (x > 0.4); Mdl = gamtrain (x, Y, 5, 3, 1, 0.5, 1, 1); pp = splinefit (x, Y - 0.5, 5, 'order', 3); assert_equal (Mdl.Parameters(1).coefs, pp.coefs, 1e-9); assert_equal (Mdl.Parameters(1).breaks, pp.breaks, 1e-14); ***** test ## Backfitting a single term converges to the spline of the centred ## response, which is what one cycle already fits x = linspace (0, 2*pi, 60)'; Y = cos (x); Mdl = gamtrain (x, Y, 5, 3, 2, mean (Y), 1e-3, 1000); pp = splinefit (x, Y - mean (Y), 5, 'order', 3); assert_equal (Mdl.Parameters(1).coefs, pp.coefs, 1e-9); assert_equal (Mdl.Intercept, mean (Y), 1e-14); assert_equal (size (Mdl.RSS), [1, 1]); ***** test ## Backfitting stops on the tolerance, and a looser one stops sooner X = [linspace(0, 1, 50)', linspace(0, 2, 50)']; Y = cos (3 * X(:,1)) + X(:,2); M1 = gamtrain (X, Y, [5, 5], [3, 3], 2, mean (Y), 1e-12, 1000); M2 = gamtrain (X, Y, [5, 5], [3, 3], 2, mean (Y), 1, 1000); assert (M2.Iterations <= M1.Iterations); assert_equal (size (M1.RSS), [1, 2]); ***** test ## Fewer observations than the spline space has dimensions: the fit is the ## minimum norm one and does not raise x = [1; 2; 3; 4; 5]; Y = [2; 1; 4; 3; 6]; Mdl = gamtrain (x, Y, 5, 3, 2, mean (Y), 1e-3, 1000); assert_equal (size (Mdl.Parameters(1).coefs), [5, 4]); assert (all (isfinite (Mdl.Parameters(1).coefs(:)))); ***** test ## A missing predictor drops the observation from that term's fit and ## predicts NaN for it, leaving the other observations finite x = linspace (0, 1, 40)'; x(7) = NaN; Y = double ([1:40]' > 20); Mdl = gamtrain (x, Y, 5, 3, 1, 0.5, 0.1, 10); assert (isnan (Mdl.Residuals(7))); assert (all (isfinite (Mdl.Residuals([1:6, 8:40])))); ***** test ## Tied and unsorted predictor values are handled by the break placement x = [0.5; 0.5; 0.1; 0.9; 0.1; 0.7; 0.3; 0.5; 0.2; 0.6; 0.4; 0.8]; Y = [0; 0; 0; 1; 0; 1; 0; 1; 0; 1; 0; 1]; Mdl = gamtrain (x, Y, 5, 3, 1, 0.5, 0.1, 20); assert (all (isfinite (Mdl.Parameters(1).coefs(:)))); assert (issorted (Mdl.Parameters(1).breaks)); ***** error gamtrain () ***** error gamtrain (ones (5, 2), ones (5, 1)) ***** error ... gamtrain ('a', ones (5, 1), 5, 3, 1, 0.5, 0.1, 10) ***** error ... gamtrain (ones (5, 1), ones (5, 2), 5, 3, 1, 0.5, 0.1, 10) ***** error ... gamtrain (ones (5, 1), ones (4, 1), 5, 3, 1, 0.5, 0.1, 10) ***** error ... gamtrain (ones (5, 2), ones (5, 1), 5, [3, 3], 1, 0.5, 0.1, 10) ***** error ... gamtrain (ones (5, 2), ones (5, 1), [5, 5], 3, 1, 0.5, 0.1, 10) ***** error ... gamtrain (ones (5, 1), ones (5, 1), 2.5, 3, 1, 0.5, 0.1, 10) ***** error ... gamtrain (ones (5, 1), ones (5, 1), 5, -1, 1, 0.5, 0.1, 10) ***** error ... gamtrain (ones (5, 1), ones (5, 1), 5, 1.5, 1, 0.5, 0.1, 10) ***** error ... gamtrain (ones (5, 1), ones (5, 1), 5, 3, 'a', 0.5, 0.1, 10) ***** error ... gamtrain (ones (5, 1), ones (5, 1), 5, 3, 3, 0.5, 0.1, 10) ***** error ... gamtrain (ones (5, 1), ones (5, 1), 5, 3, 1, [1, 2], 0.1, 10) ***** error ... gamtrain (ones (5, 1), ones (5, 1), 5, 3, 1, 0.5, 0, 10) ***** error ... gamtrain (ones (5, 1), ones (5, 1), 5, 3, 1, 0.5, 0.1, 0) ***** test ## Order zero is piecewise constants, which the learners accept and the ## m-code fitted as splines of order one x = linspace (0, 1, 30)'; Y = double (x > 0.5); Mdl = gamtrain (x, Y, 5, 0, 1, 0.5, 0.1, 20); P = Mdl.Parameters(1); assert_equal (P.pieces, 5); assert_equal (P.order, 1); assert_equal (size (P.coefs), [5, 1]); pp = splinefit (x, Y - 0.5, 5, 'order', 0); M1 = gamtrain (x, Y, 5, 0, 1, 0.5, 1, 1); assert_equal (M1.Parameters(1).coefs, pp.coefs, 1e-12); ***** test ## A single-class response gives an infinite intercept and terms that stay ## at zero, which is what the m-code it replaces produced x = linspace (0, 1, 20)'; Mdl = gamtrain (x, ones (20, 1), 5, 3, 1, 1, 0.1, 10); assert_equal (Mdl.Intercept, Inf); assert_equal (Mdl.Parameters(1).coefs, zeros (5, 4)); assert_equal (Mdl.Residuals, zeros (20, 1)); 25 tests, 25 passed, 0 known failure, 0 skipped [src/__knnbrute__.cc] >>>>> /build/reproducible-path/octave-statistics-2.0.0/src/__knnbrute__.cc ***** test ## It answers what pdist2 followed by a sort answers, exactly. X = [1, 2; 3, 4; 5, 6; 7, 8; 2, 2; -1, 0]; Y = [2, 3; 6, 7; 0, 0]; for m = {"euclidean", "cityblock", "chebychev"} D = pdist2 (X, Y, m{1})'; [sv, so] = sort (D, 2); for k = 1:6 [idx, dst] = __knnbrute__ (X, Y, k, m{1}, []); assert_equal (idx, so(:,1:k)); assert_equal (dst, sv(:,1:k)); endfor endfor ***** test ## Minkowski takes its exponent and agrees at each of them. X = [1, 2; 3, 4; 5, 6; 7, 8]; Y = [2, 3; 6, 7]; for q = [1, 1.5, 2, 3] D = pdist2 (X, Y, "minkowski", q)'; [sv, so] = sort (D, 2); [idx, dst] = __knnbrute__ (X, Y, 3, "minkowski", q); assert_equal (idx, so(:,1:3)); assert_equal (dst, sv(:,1:3), 1e-12); endfor ***** test ## Ties keep the lower index, as a stable sort does. X = [0, 0; 0, 0; 0, 0]; [idx, dst] = __knnbrute__ (X, [1, 1], 2, "euclidean", []); assert_equal (idx, [1, 2]); assert_equal (dst, [sqrt(2), sqrt(2)], 1e-12); ***** test ## A NaN in the data puts that neighbour last, never first. X = [0, 0; NaN, 0; 1, 1]; [idx, dst] = __knnbrute__ (X, [0, 0], 3, "euclidean", []); assert_equal (idx(1:2), [1, 3]); assert_equal (idx(3), 2); assert_equal (isnan (dst(3)), true); ***** test ## Single data gives single distances; the indices stay double. [idx, dst] = __knnbrute__ (single ([1, 1; 4, 4]), single ([0, 0]), 1, ... "euclidean", []); assert_equal (class (dst), 'single'); assert_equal (class (idx), 'double'); ***** test ## K may be the whole reference set. X = [3, 0; 1, 0; 2, 0]; [idx, dst] = __knnbrute__ (X, [0, 0], 3, "euclidean", []); assert_equal (idx, [2, 3, 1]); assert_equal (dst, [1, 2, 3], 1e-12); ***** error __knnbrute__ (ones (2, 2), ones (1, 2), 1) ***** error<__knnbrute__: X must be a real numeric matrix.> ... __knnbrute__ ({1}, ones (1, 2), 1, "euclidean", []) ***** error<__knnbrute__: X and Y must have the same number of columns.> ... __knnbrute__ (ones (2, 3), ones (1, 2), 1, "euclidean", []) ***** error<__knnbrute__: K must be an integer between 1 and rows \(X\).> ... __knnbrute__ (ones (2, 2), ones (1, 2), 3, "euclidean", []) ***** error<__knnbrute__: unsupported METRIC 'cosine'.> ... __knnbrute__ (ones (2, 2), ones (1, 2), 1, "cosine", []) ***** error<__knnbrute__: PARAM must be a positive finite scalar.> ... __knnbrute__ (ones (2, 2), ones (1, 2), 1, "minkowski", -1) 12 tests, 12 passed, 0 known failure, 0 skipped Done running the unit tests. Summary: 20700 tests, 20699 passed, 0 known failures, 0 skipped Some tests failed. Giving up... make: *** [debian/rules:5: binary-arch] Error 1 dpkg-buildpackage: error: debian/rules binary-arch subprocess failed with exit status 2 -------------------------------------------------------------------------------- Build finished at 2026-10-04T23:52:10Z Finished -------- +------------------------------------------------------------------------------+ | Cleanup Sun, 04 Oct 2026 23:52:10 +0000 | +------------------------------------------------------------------------------+ Purging /build/reproducible-path Not cleaning session: cloned chroot in use E: Build failure (dpkg-buildpackage died with exit 2) +------------------------------------------------------------------------------+ | Summary Sun, 04 Oct 2026 23:52:12 +0000 | +------------------------------------------------------------------------------+ Build Architecture: amd64 Build Type: any Build-Space: 95156 Build-Time: 953 Distribution: unstable Fail-Stage: build Host Architecture: amd64 Install-Time: 3 Job: /srv/rebuilderd/tmp/rebuilderdG1cRAZ/inputs/octave-statistics_2.0.0-1.dsc Machine Architecture: amd64 Package: octave-statistics Package-Time: 964 Source-Version: 2.0.0-1 Space: 95156 Status: attempted Version: 2.0.0-1 -------------------------------------------------------------------------------- Finished at 2026-10-04T23:52:10Z Build needed 00:16:04, 95156k disk space E: Build failure (dpkg-buildpackage died with exit 2) sbuild failed